@xata.io/client 0.0.0-alpha.vfa22996 → 0.0.0-alpha.vfac764c
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/.eslintrc.cjs +3 -2
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +78 -0
- package/README.md +9 -2
- package/dist/index.cjs +129 -98
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1490 -1479
- package/dist/index.mjs +129 -95
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -8
- package/rollup.config.mjs +28 -13
package/.eslintrc.cjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module.exports = {
|
2
|
-
ignorePatterns: [
|
2
|
+
ignorePatterns: ['dist'],
|
3
3
|
parserOptions: {
|
4
4
|
ecmaVersion: 2020,
|
5
5
|
sourceType: 'module',
|
@@ -7,6 +7,7 @@ module.exports = {
|
|
7
7
|
},
|
8
8
|
rules: {
|
9
9
|
'@typescript-eslint/no-floating-promises': 'error',
|
10
|
-
|
10
|
+
'@typescript-eslint/strict-boolean-expressions': ['error', { allowNullableString: true, allowNullableObject: true }],
|
11
|
+
"@typescript-eslint/ban-types": "off",
|
11
12
|
}
|
12
13
|
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
> @xata.io/client@0.21.6 build /home/runner/work/client-ts/client-ts/packages/client
|
3
|
+
> rimraf dist && rollup -c
|
4
|
+
|
5
|
+
[36m
|
6
|
+
[1msrc/index.ts[22m → [1mdist/index.cjs[22m...[39m
|
7
|
+
[32mcreated [1mdist/index.cjs[22m in [1m1s[22m[39m
|
8
|
+
[36m
|
9
|
+
[1msrc/index.ts[22m → [1mdist/index.mjs[22m...[39m
|
10
|
+
[32mcreated [1mdist/index.mjs[22m in [1m756ms[22m[39m
|
11
|
+
[36m
|
12
|
+
[1msrc/index.ts[22m → [1mdist/index.d.ts[22m...[39m
|
13
|
+
[32mcreated [1mdist/index.d.ts[22m in [1m6.3s[22m[39m
|
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,83 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.0.0-alpha.vfac764c
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- [#852](https://github.com/xataio/client-ts/pull/852) [`b2a4def4`](https://github.com/xataio/client-ts/commit/b2a4def4baf3eb18cd323895635e0bccb7f876f4) Thanks [@SferaDev](https://github.com/SferaDev)! - [BREAKING CHANGE] Reduce column selection depth
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- Force canary build
|
12
|
+
|
13
|
+
- [#835](https://github.com/xataio/client-ts/pull/835) [`379e6144`](https://github.com/xataio/client-ts/commit/379e61446b21e7cbadd7fc59267736c6845ec566) Thanks [@SferaDev](https://github.com/SferaDev)! - Add helper methods `toSerializable` and `toString`
|
14
|
+
|
15
|
+
## 0.21.6
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- [#828](https://github.com/xataio/client-ts/pull/828) [`039e35bf`](https://github.com/xataio/client-ts/commit/039e35bf9f01149f39bca39e1867908ca3468bb5) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix enableBrowser with Deno
|
20
|
+
|
21
|
+
- [#828](https://github.com/xataio/client-ts/pull/828) [`039e35bf`](https://github.com/xataio/client-ts/commit/039e35bf9f01149f39bca39e1867908ca3468bb5) Thanks [@SferaDev](https://github.com/SferaDev)! - Add branded types to serializer
|
22
|
+
|
23
|
+
## 0.21.5
|
24
|
+
|
25
|
+
### Patch Changes
|
26
|
+
|
27
|
+
- [#825](https://github.com/xataio/client-ts/pull/825) [`41c4d29f`](https://github.com/xataio/client-ts/commit/41c4d29f9f9fc7ce87b755e447a2030fe8c10d70) Thanks [@SferaDev](https://github.com/SferaDev)! - Export fetcher error
|
28
|
+
|
29
|
+
## 0.21.4
|
30
|
+
|
31
|
+
### Patch Changes
|
32
|
+
|
33
|
+
- [#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
|
34
|
+
|
35
|
+
## 0.21.3
|
36
|
+
|
37
|
+
### Patch Changes
|
38
|
+
|
39
|
+
- [#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
|
40
|
+
|
41
|
+
## 0.21.2
|
42
|
+
|
43
|
+
### Patch Changes
|
44
|
+
|
45
|
+
- [#787](https://github.com/xataio/client-ts/pull/787) [`93f5beed`](https://github.com/xataio/client-ts/commit/93f5beed77785b03409c614f5e2c3eca4c69c574) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose consistency options
|
46
|
+
|
47
|
+
- [#784](https://github.com/xataio/client-ts/pull/784) [`cbe0609e`](https://github.com/xataio/client-ts/commit/cbe0609ec9d6650030efbda712a1eb243287525d) Thanks [@SferaDev](https://github.com/SferaDev)! - Update resolveBranch behaviour
|
48
|
+
|
49
|
+
## 0.21.1
|
50
|
+
|
51
|
+
### Patch Changes
|
52
|
+
|
53
|
+
- [#781](https://github.com/xataio/client-ts/pull/781) [`fdfa47de`](https://github.com/xataio/client-ts/commit/fdfa47de93ec772170ff00a4341fc14434347df5) Thanks [@SferaDev](https://github.com/SferaDev)! - Send header to disable encoding
|
54
|
+
|
55
|
+
## 0.21.0
|
56
|
+
|
57
|
+
### Minor Changes
|
58
|
+
|
59
|
+
- [#757](https://github.com/xataio/client-ts/pull/757) [`7da604d2`](https://github.com/xataio/client-ts/commit/7da604d27990e20ecadba6122434fca563e6a8c9) Thanks [@SferaDev](https://github.com/SferaDev)! - Add promise pool for retries
|
60
|
+
|
61
|
+
### Patch Changes
|
62
|
+
|
63
|
+
- [#764](https://github.com/xataio/client-ts/pull/764) [`b131040a`](https://github.com/xataio/client-ts/commit/b131040a2d142c4e71a2e586fbf05cd9295af9a1) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix bun
|
64
|
+
|
65
|
+
- [#759](https://github.com/xataio/client-ts/pull/759) [`7ea810dc`](https://github.com/xataio/client-ts/commit/7ea810dc083ec284447e3bd27bd0465f887481e6) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose new transaction API
|
66
|
+
|
67
|
+
- [#767](https://github.com/xataio/client-ts/pull/767) [`d124cbfb`](https://github.com/xataio/client-ts/commit/d124cbfb93d3d591e79bbe9e94c4b6304d825e71) Thanks [@SferaDev](https://github.com/SferaDev)! - Remove formatVersion from schema
|
68
|
+
|
69
|
+
- [#767](https://github.com/xataio/client-ts/pull/767) [`d124cbfb`](https://github.com/xataio/client-ts/commit/d124cbfb93d3d591e79bbe9e94c4b6304d825e71) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix null value returning on date columns
|
70
|
+
|
71
|
+
- [#775](https://github.com/xataio/client-ts/pull/775) [`fb5ccdf9`](https://github.com/xataio/client-ts/commit/fb5ccdf9fa95c37d54fbc5d9c0bb45872c831609) Thanks [@SferaDev](https://github.com/SferaDev)! - Add missing target field to search
|
72
|
+
|
73
|
+
- [#760](https://github.com/xataio/client-ts/pull/760) [`4ae00036`](https://github.com/xataio/client-ts/commit/4ae00036b53c6c89e02a1fcfdd992f1a3c22892c) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for filters in boosters
|
74
|
+
|
75
|
+
- [#766](https://github.com/xataio/client-ts/pull/766) [`bdae6668`](https://github.com/xataio/client-ts/commit/bdae6668fb571d29f1b1068a54f6866a80d9b174) Thanks [@SferaDev](https://github.com/SferaDev)! - Remove beta for Workers
|
76
|
+
|
77
|
+
- [#771](https://github.com/xataio/client-ts/pull/771) [`9486bdcc`](https://github.com/xataio/client-ts/commit/9486bdccc0af567bc5f2e8f91592b0143c539c45) Thanks [@SferaDev](https://github.com/SferaDev)! - Add modifier for numeric booster
|
78
|
+
|
79
|
+
- [#771](https://github.com/xataio/client-ts/pull/771) [`9486bdcc`](https://github.com/xataio/client-ts/commit/9486bdccc0af567bc5f2e8f91592b0143c539c45) Thanks [@SferaDev](https://github.com/SferaDev)! - Add pagination to search
|
80
|
+
|
3
81
|
## 0.20.2
|
4
82
|
|
5
83
|
### Patch Changes
|
package/README.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Xata SDK for TypeScript and JavaScript
|
2
2
|
|
3
|
-
|
3
|
+
The Xata SDK supports typescript definitions for your Xata database schema. It also works with JavaScript.
|
4
|
+
|
5
|
+
It has zero dependencies and runs in Node.js, V8, Deno and Bun.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
See our [docs](https://xata.io/docs/sdk/typescript#installation) to get started using the Xata SDK.
|
10
|
+
|
4
11
|
|
5
12
|
## Table of Contents
|
6
13
|
|
@@ -22,7 +29,7 @@ This SDK has zero dependencies, so it can be used in many JavaScript runtimes in
|
|
22
29
|
|
23
30
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
24
31
|
|
25
|
-
## Installation
|
32
|
+
## Manual Installation
|
26
33
|
|
27
34
|
```bash
|
28
35
|
npm install @xata.io/client
|
package/dist/index.cjs
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
const defaultTrace = async (
|
3
|
+
const defaultTrace = async (name, fn, _options) => {
|
4
4
|
return await fn({
|
5
|
+
name,
|
5
6
|
setAttributes: () => {
|
6
7
|
return;
|
7
8
|
}
|
@@ -174,8 +175,6 @@ async function getGitBranch() {
|
|
174
175
|
if (typeof require === "function") {
|
175
176
|
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
176
177
|
}
|
177
|
-
const { execSync } = await import(nodeModule);
|
178
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
179
178
|
} catch (err) {
|
180
179
|
}
|
181
180
|
try {
|
@@ -296,7 +295,14 @@ enqueue_fn = function(task) {
|
|
296
295
|
return promise;
|
297
296
|
};
|
298
297
|
|
299
|
-
|
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.6";
|
300
306
|
|
301
307
|
class ErrorWithCause extends Error {
|
302
308
|
constructor(message, options) {
|
@@ -307,7 +313,7 @@ class FetcherError extends ErrorWithCause {
|
|
307
313
|
constructor(status, data, requestId) {
|
308
314
|
super(getMessage(data));
|
309
315
|
this.status = status;
|
310
|
-
this.errors = isBulkError(data) ? data.errors :
|
316
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
311
317
|
this.requestId = requestId;
|
312
318
|
if (data instanceof Error) {
|
313
319
|
this.stack = data.stack;
|
@@ -372,11 +378,12 @@ function hostHeader(url) {
|
|
372
378
|
const { groups } = pattern.exec(url) ?? {};
|
373
379
|
return groups?.host ? { Host: groups.host } : {};
|
374
380
|
}
|
381
|
+
const defaultClientID = generateUUID();
|
375
382
|
async function fetch$1({
|
376
383
|
url: path,
|
377
384
|
method,
|
378
385
|
body,
|
379
|
-
headers,
|
386
|
+
headers: customHeaders,
|
380
387
|
pathParams,
|
381
388
|
queryParams,
|
382
389
|
fetchImpl,
|
@@ -388,6 +395,7 @@ async function fetch$1({
|
|
388
395
|
signal,
|
389
396
|
clientID,
|
390
397
|
sessionID,
|
398
|
+
clientName,
|
391
399
|
fetchOptions = {}
|
392
400
|
}) {
|
393
401
|
pool.setFetch(fetchImpl);
|
@@ -401,19 +409,26 @@ async function fetch$1({
|
|
401
409
|
[TraceAttributes.HTTP_URL]: url,
|
402
410
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
403
411
|
});
|
412
|
+
const xataAgent = compact([
|
413
|
+
["client", "TS_SDK"],
|
414
|
+
["version", VERSION],
|
415
|
+
isDefined(clientName) ? ["service", clientName] : void 0
|
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
|
+
};
|
404
427
|
const response = await pool.request(url, {
|
405
428
|
...fetchOptions,
|
406
429
|
method: method.toUpperCase(),
|
407
430
|
body: body ? JSON.stringify(body) : void 0,
|
408
|
-
headers
|
409
|
-
"Content-Type": "application/json",
|
410
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
411
|
-
"X-Xata-Client-ID": clientID ?? "",
|
412
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
413
|
-
...headers,
|
414
|
-
...hostHeader(fullUrl),
|
415
|
-
Authorization: `Bearer ${apiKey}`
|
416
|
-
},
|
431
|
+
headers,
|
417
432
|
signal
|
418
433
|
});
|
419
434
|
const { host, protocol } = parseUrl(response.url);
|
@@ -455,17 +470,12 @@ function parseUrl(url) {
|
|
455
470
|
|
456
471
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
457
472
|
|
458
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
459
473
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
460
474
|
url: "/dbs/{dbName}",
|
461
475
|
method: "get",
|
462
476
|
...variables,
|
463
477
|
signal
|
464
478
|
});
|
465
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
466
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
467
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
468
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
469
479
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
470
480
|
url: "/db/{dbBranchName}",
|
471
481
|
method: "get",
|
@@ -504,7 +514,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
504
514
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
505
515
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
506
516
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
507
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
508
517
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
509
518
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
510
519
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -571,6 +580,7 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
571
580
|
...variables,
|
572
581
|
signal
|
573
582
|
});
|
583
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
574
584
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
575
585
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
576
586
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
@@ -604,13 +614,6 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
604
614
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
605
615
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
606
616
|
const operationsByTag$2 = {
|
607
|
-
database: {
|
608
|
-
dEPRECATEDgetDatabaseList,
|
609
|
-
dEPRECATEDcreateDatabase,
|
610
|
-
dEPRECATEDdeleteDatabase,
|
611
|
-
dEPRECATEDgetDatabaseMetadata,
|
612
|
-
dEPRECATEDupdateDatabaseMetadata
|
613
|
-
},
|
614
617
|
branch: {
|
615
618
|
getBranchList,
|
616
619
|
getBranchDetails,
|
@@ -635,16 +638,6 @@ const operationsByTag$2 = {
|
|
635
638
|
previewBranchSchemaEdit,
|
636
639
|
applyBranchSchemaEdit
|
637
640
|
},
|
638
|
-
records: {
|
639
|
-
branchTransaction,
|
640
|
-
insertRecord,
|
641
|
-
getRecord,
|
642
|
-
insertRecordWithID,
|
643
|
-
updateRecordWithID,
|
644
|
-
upsertRecordWithID,
|
645
|
-
deleteRecord,
|
646
|
-
bulkInsertTableRecords
|
647
|
-
},
|
648
641
|
migrationRequests: {
|
649
642
|
queryMigrationRequests,
|
650
643
|
createMigrationRequest,
|
@@ -667,6 +660,16 @@ const operationsByTag$2 = {
|
|
667
660
|
updateColumn,
|
668
661
|
deleteColumn
|
669
662
|
},
|
663
|
+
records: {
|
664
|
+
branchTransaction,
|
665
|
+
insertRecord,
|
666
|
+
getRecord,
|
667
|
+
insertRecordWithID,
|
668
|
+
updateRecordWithID,
|
669
|
+
upsertRecordWithID,
|
670
|
+
deleteRecord,
|
671
|
+
bulkInsertTableRecords
|
672
|
+
},
|
670
673
|
searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
|
671
674
|
};
|
672
675
|
|
@@ -840,12 +843,12 @@ function parseProviderString(provider = "production") {
|
|
840
843
|
function parseWorkspacesUrlParts(url) {
|
841
844
|
if (!isString(url))
|
842
845
|
return null;
|
843
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
844
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))
|
846
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
847
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
|
845
848
|
const match = url.match(regex) || url.match(regexStaging);
|
846
849
|
if (!match)
|
847
850
|
return null;
|
848
|
-
return { workspace: match[1], region: match[2]
|
851
|
+
return { workspace: match[1], region: match[2] };
|
849
852
|
}
|
850
853
|
|
851
854
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -874,6 +877,7 @@ class XataApiClient {
|
|
874
877
|
const provider = options.host ?? "production";
|
875
878
|
const apiKey = options.apiKey ?? getAPIKey();
|
876
879
|
const trace = options.trace ?? defaultTrace;
|
880
|
+
const clientID = generateUUID();
|
877
881
|
if (!apiKey) {
|
878
882
|
throw new Error("Could not resolve a valid apiKey");
|
879
883
|
}
|
@@ -882,7 +886,9 @@ class XataApiClient {
|
|
882
886
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
883
887
|
fetchImpl: getFetchImplementation(options.fetch),
|
884
888
|
apiKey,
|
885
|
-
trace
|
889
|
+
trace,
|
890
|
+
clientName: options.clientName,
|
891
|
+
clientID
|
886
892
|
});
|
887
893
|
}
|
888
894
|
get user() {
|
@@ -1887,13 +1893,6 @@ class XataApiPlugin {
|
|
1887
1893
|
class XataPlugin {
|
1888
1894
|
}
|
1889
1895
|
|
1890
|
-
function generateUUID() {
|
1891
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1892
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1893
|
-
return v.toString(16);
|
1894
|
-
});
|
1895
|
-
}
|
1896
|
-
|
1897
1896
|
function cleanFilter(filter) {
|
1898
1897
|
if (!filter)
|
1899
1898
|
return void 0;
|
@@ -1970,6 +1969,12 @@ const _RecordArray = class extends Array {
|
|
1970
1969
|
toArray() {
|
1971
1970
|
return new Array(...this);
|
1972
1971
|
}
|
1972
|
+
toSerializable() {
|
1973
|
+
return JSON.parse(this.toString());
|
1974
|
+
}
|
1975
|
+
toString() {
|
1976
|
+
return JSON.stringify(this.toArray());
|
1977
|
+
}
|
1973
1978
|
map(callbackfn, thisArg) {
|
1974
1979
|
return this.toArray().map(callbackfn, thisArg);
|
1975
1980
|
}
|
@@ -2041,6 +2046,7 @@ const _Query = class {
|
|
2041
2046
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
2042
2047
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
2043
2048
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
2049
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
2044
2050
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
2045
2051
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2046
2052
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -2414,13 +2420,19 @@ class RestRepository extends Query {
|
|
2414
2420
|
const result = await this.read(a, columns);
|
2415
2421
|
return result;
|
2416
2422
|
}
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2423
|
-
|
2423
|
+
try {
|
2424
|
+
if (isString(a) && isObject(b)) {
|
2425
|
+
const columns = isStringArray(c) ? c : void 0;
|
2426
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2427
|
+
}
|
2428
|
+
if (isObject(a) && isString(a.id)) {
|
2429
|
+
const columns = isStringArray(b) ? b : void 0;
|
2430
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2431
|
+
}
|
2432
|
+
} catch (error) {
|
2433
|
+
if (error.status === 422)
|
2434
|
+
return null;
|
2435
|
+
throw error;
|
2424
2436
|
}
|
2425
2437
|
throw new Error("Invalid arguments for update method");
|
2426
2438
|
});
|
@@ -2551,7 +2563,9 @@ class RestRepository extends Query {
|
|
2551
2563
|
prefix: options.prefix,
|
2552
2564
|
highlight: options.highlight,
|
2553
2565
|
filter: options.filter,
|
2554
|
-
boosters: options.boosters
|
2566
|
+
boosters: options.boosters,
|
2567
|
+
page: options.page,
|
2568
|
+
target: options.target
|
2555
2569
|
},
|
2556
2570
|
...fetchProps
|
2557
2571
|
});
|
@@ -2593,7 +2607,8 @@ class RestRepository extends Query {
|
|
2593
2607
|
filter: cleanFilter(data.filter),
|
2594
2608
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2595
2609
|
page: data.pagination,
|
2596
|
-
columns: data.columns ?? ["*"]
|
2610
|
+
columns: data.columns ?? ["*"],
|
2611
|
+
consistency: data.consistency
|
2597
2612
|
},
|
2598
2613
|
fetchOptions: data.fetchOptions,
|
2599
2614
|
...fetchProps
|
@@ -2621,6 +2636,7 @@ class RestRepository extends Query {
|
|
2621
2636
|
filter: cleanFilter(data.filter),
|
2622
2637
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2623
2638
|
columns: data.columns,
|
2639
|
+
consistency: data.consistency,
|
2624
2640
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2625
2641
|
summaries,
|
2626
2642
|
summariesFilter
|
@@ -2857,23 +2873,23 @@ const transformObjectLinks = (object) => {
|
|
2857
2873
|
}, {});
|
2858
2874
|
};
|
2859
2875
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2860
|
-
const
|
2876
|
+
const data = {};
|
2861
2877
|
const { xata, ...rest } = object ?? {};
|
2862
|
-
Object.assign(
|
2878
|
+
Object.assign(data, rest);
|
2863
2879
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2864
2880
|
if (!columns)
|
2865
2881
|
console.error(`Table ${table} not found in schema`);
|
2866
2882
|
for (const column of columns ?? []) {
|
2867
2883
|
if (!isValidColumn(selectedColumns, column))
|
2868
2884
|
continue;
|
2869
|
-
const value =
|
2885
|
+
const value = data[column.name];
|
2870
2886
|
switch (column.type) {
|
2871
2887
|
case "datetime": {
|
2872
2888
|
const date = value !== void 0 ? new Date(value) : null;
|
2873
2889
|
if (date !== null && isNaN(date.getTime())) {
|
2874
2890
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2875
2891
|
} else {
|
2876
|
-
|
2892
|
+
data[column.name] = date;
|
2877
2893
|
}
|
2878
2894
|
break;
|
2879
2895
|
}
|
@@ -2892,44 +2908,51 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2892
2908
|
}
|
2893
2909
|
return acc;
|
2894
2910
|
}, []);
|
2895
|
-
|
2911
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2896
2912
|
} else {
|
2897
|
-
|
2913
|
+
data[column.name] = null;
|
2898
2914
|
}
|
2899
2915
|
break;
|
2900
2916
|
}
|
2901
2917
|
default:
|
2902
|
-
|
2918
|
+
data[column.name] = value ?? null;
|
2903
2919
|
if (column.notNull === true && value === null) {
|
2904
2920
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2905
2921
|
}
|
2906
2922
|
break;
|
2907
2923
|
}
|
2908
2924
|
}
|
2909
|
-
|
2910
|
-
|
2925
|
+
const record = { ...data };
|
2926
|
+
record.read = function(columns2) {
|
2927
|
+
return db[table].read(record["id"], columns2);
|
2911
2928
|
};
|
2912
|
-
|
2929
|
+
record.update = function(data2, b, c) {
|
2913
2930
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2914
2931
|
const ifVersion = parseIfVersion(b, c);
|
2915
|
-
return db[table].update(
|
2932
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2916
2933
|
};
|
2917
|
-
|
2934
|
+
record.replace = function(data2, b, c) {
|
2918
2935
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2919
2936
|
const ifVersion = parseIfVersion(b, c);
|
2920
|
-
return db[table].createOrReplace(
|
2937
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
2921
2938
|
};
|
2922
|
-
|
2923
|
-
return db[table].delete(
|
2939
|
+
record.delete = function() {
|
2940
|
+
return db[table].delete(record["id"]);
|
2924
2941
|
};
|
2925
|
-
|
2942
|
+
record.getMetadata = function() {
|
2926
2943
|
return xata;
|
2927
2944
|
};
|
2928
|
-
|
2929
|
-
|
2945
|
+
record.toSerializable = function() {
|
2946
|
+
return JSON.parse(JSON.stringify(transformObjectLinks(data)));
|
2947
|
+
};
|
2948
|
+
record.toString = function() {
|
2949
|
+
return JSON.stringify(transformObjectLinks(data));
|
2950
|
+
};
|
2951
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2952
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2930
2953
|
}
|
2931
|
-
Object.freeze(
|
2932
|
-
return
|
2954
|
+
Object.freeze(record);
|
2955
|
+
return record;
|
2933
2956
|
};
|
2934
2957
|
function extractId(value) {
|
2935
2958
|
if (isString(value))
|
@@ -3140,10 +3163,10 @@ _schemaTables = new WeakMap();
|
|
3140
3163
|
_search = new WeakSet();
|
3141
3164
|
search_fn = async function(query, options, getFetchProps) {
|
3142
3165
|
const fetchProps = await getFetchProps();
|
3143
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
3166
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3144
3167
|
const { records } = await searchBranch({
|
3145
3168
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3146
|
-
body: { tables, query, fuzziness, prefix, highlight },
|
3169
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
3147
3170
|
...fetchProps
|
3148
3171
|
});
|
3149
3172
|
return records;
|
@@ -3183,12 +3206,8 @@ const isBranchStrategyBuilder = (strategy) => {
|
|
3183
3206
|
|
3184
3207
|
async function getCurrentBranchName(options) {
|
3185
3208
|
const { branch, envBranch } = getEnvironment();
|
3186
|
-
if (branch)
|
3187
|
-
|
3188
|
-
if (details)
|
3189
|
-
return branch;
|
3190
|
-
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
3191
|
-
}
|
3209
|
+
if (branch)
|
3210
|
+
return branch;
|
3192
3211
|
const gitBranch = envBranch || await getGitBranch();
|
3193
3212
|
return resolveXataBranch(gitBranch, options);
|
3194
3213
|
}
|
@@ -3220,7 +3239,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
3220
3239
|
workspacesApiUrl: `${protocol}//${host}`,
|
3221
3240
|
pathParams: { dbName, workspace, region },
|
3222
3241
|
queryParams: { gitBranch, fallbackBranch },
|
3223
|
-
trace: defaultTrace
|
3242
|
+
trace: defaultTrace,
|
3243
|
+
clientName: options?.clientName
|
3224
3244
|
});
|
3225
3245
|
return branch;
|
3226
3246
|
}
|
@@ -3328,7 +3348,7 @@ const buildClient = (plugins) => {
|
|
3328
3348
|
}
|
3329
3349
|
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3330
3350
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3331
|
-
const isBrowser = typeof window !== "undefined";
|
3351
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3332
3352
|
if (isBrowser && !enableBrowser) {
|
3333
3353
|
throw new Error(
|
3334
3354
|
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
@@ -3339,15 +3359,29 @@ const buildClient = (plugins) => {
|
|
3339
3359
|
const apiKey = options?.apiKey || getAPIKey();
|
3340
3360
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3341
3361
|
const trace = options?.trace ?? defaultTrace;
|
3342
|
-
const
|
3362
|
+
const clientName = options?.clientName;
|
3363
|
+
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
|
3364
|
+
apiKey,
|
3365
|
+
databaseURL,
|
3366
|
+
fetchImpl: options?.fetch,
|
3367
|
+
clientName: options?.clientName
|
3368
|
+
});
|
3343
3369
|
if (!apiKey) {
|
3344
3370
|
throw new Error("Option apiKey is required");
|
3345
3371
|
}
|
3346
3372
|
if (!databaseURL) {
|
3347
3373
|
throw new Error("Option databaseURL is required");
|
3348
3374
|
}
|
3349
|
-
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
|
3350
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
3375
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser, clientName };
|
3376
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
3377
|
+
fetch,
|
3378
|
+
apiKey,
|
3379
|
+
databaseURL,
|
3380
|
+
branch,
|
3381
|
+
trace,
|
3382
|
+
clientID,
|
3383
|
+
clientName
|
3384
|
+
}) {
|
3351
3385
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3352
3386
|
if (!branchValue)
|
3353
3387
|
throw new Error("Unable to resolve branch value");
|
@@ -3361,7 +3395,8 @@ const buildClient = (plugins) => {
|
|
3361
3395
|
return databaseURL + newPath;
|
3362
3396
|
},
|
3363
3397
|
trace,
|
3364
|
-
clientID
|
3398
|
+
clientID,
|
3399
|
+
clientName
|
3365
3400
|
};
|
3366
3401
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3367
3402
|
if (__privateGet(this, _branch))
|
@@ -3452,7 +3487,7 @@ const deserialize = (json) => {
|
|
3452
3487
|
};
|
3453
3488
|
|
3454
3489
|
function buildWorkerRunner(config) {
|
3455
|
-
return function xataWorker(name,
|
3490
|
+
return function xataWorker(name, worker) {
|
3456
3491
|
return async (...args) => {
|
3457
3492
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3458
3493
|
const result = await fetch(url, {
|
@@ -3474,6 +3509,7 @@ class XataError extends Error {
|
|
3474
3509
|
}
|
3475
3510
|
|
3476
3511
|
exports.BaseClient = BaseClient;
|
3512
|
+
exports.FetcherError = FetcherError;
|
3477
3513
|
exports.Operations = operationsByTag;
|
3478
3514
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
3479
3515
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -3512,11 +3548,6 @@ exports.createMigrationRequest = createMigrationRequest;
|
|
3512
3548
|
exports.createTable = createTable;
|
3513
3549
|
exports.createUserAPIKey = createUserAPIKey;
|
3514
3550
|
exports.createWorkspace = createWorkspace;
|
3515
|
-
exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
|
3516
|
-
exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
|
3517
|
-
exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
|
3518
|
-
exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
|
3519
|
-
exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
|
3520
3551
|
exports.deleteBranch = deleteBranch;
|
3521
3552
|
exports.deleteColumn = deleteColumn;
|
3522
3553
|
exports.deleteDatabase = deleteDatabase;
|