@xata.io/client 0.0.0-alpha.ved155c7 → 0.0.0-alpha.ved61cb2
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 +17 -1
- package/README.md +1 -1
- package/Usage.md +2 -0
- package/dist/index.cjs +123 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +982 -45
- package/dist/index.mjs +122 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
# @xata.io/client
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.18.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#562](https://github.com/xataio/client-ts/pull/562) [`699beb4`](https://github.com/xataio/client-ts/commit/699beb4bbf21cffa001d3f88a03246980e30250b) Thanks [@SferaDev](https://github.com/SferaDev)! - Return null on nullable columns
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
11
|
+
- [#583](https://github.com/xataio/client-ts/pull/583) [`330b076`](https://github.com/xataio/client-ts/commit/330b076a0781e3576c82afab76e3fb2a64f2e041) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for unique columns
|
|
12
|
+
|
|
7
13
|
- [#598](https://github.com/xataio/client-ts/pull/598) [`c3dfb4b`](https://github.com/xataio/client-ts/commit/c3dfb4babc990634b9e9747616ed93223178a2e7) Thanks [@SferaDev](https://github.com/SferaDev)! - API: Add patch database metadata endpoint
|
|
8
14
|
|
|
15
|
+
- [#602](https://github.com/xataio/client-ts/pull/602) [`74b17aa`](https://github.com/xataio/client-ts/commit/74b17aaedc0dbdd79bfdcb182b2e70b61f98f5a5) Thanks [@gimenete](https://github.com/gimenete)! - API: Make workspace slug optional on create
|
|
16
|
+
|
|
17
|
+
- [#615](https://github.com/xataio/client-ts/pull/615) [`83f20cd`](https://github.com/xataio/client-ts/commit/83f20cdbe53706c16016c4db3f318e679b24ec86) Thanks [@SferaDev](https://github.com/SferaDev)! - Make `getMany` return more items than max pagination size
|
|
18
|
+
|
|
19
|
+
- [#562](https://github.com/xataio/client-ts/pull/562) [`addfcc6`](https://github.com/xataio/client-ts/commit/addfcc67fca663defdd340111ea09c9188bad3ab) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `orThrows` methods that instead of returning null, throw an exception.
|
|
20
|
+
|
|
21
|
+
- [#583](https://github.com/xataio/client-ts/pull/583) [`eb7ba59`](https://github.com/xataio/client-ts/commit/eb7ba594be2a1f0ab90956836bbeb912e188a46d) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for non nullable columns
|
|
22
|
+
|
|
23
|
+
- [#612](https://github.com/xataio/client-ts/pull/612) [`f1a0742`](https://github.com/xataio/client-ts/commit/f1a0742a04e1aefab14f46371a04a41069faec01) Thanks [@xata-bot](https://github.com/xata-bot)! - API: Add summarize table endpoint
|
|
24
|
+
|
|
9
25
|
## 0.17.1
|
|
10
26
|
|
|
11
27
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -246,7 +246,7 @@ const api = new XataApiClient({ apiKey: process.env.XATA_API_KEY });
|
|
|
246
246
|
Once you have initialized the API client, the operations are organized following the same hiearchy as in the [official documentation](https://docs.xata.io). You have different namespaces for each entity (ie. `workspaces`, `databases`, `tables`, `branches`, `users`, `records`...).
|
|
247
247
|
|
|
248
248
|
```ts
|
|
249
|
-
const { id: workspace } = await api.workspaces.createWorkspace({ name: 'example'
|
|
249
|
+
const { id: workspace } = await api.workspaces.createWorkspace({ name: 'example' });
|
|
250
250
|
const { databaseName } = await api.databases.createDatabase(workspace, 'database');
|
|
251
251
|
|
|
252
252
|
await api.branches.createBranch(workspace, databaseName, 'branch');
|
package/Usage.md
CHANGED
|
@@ -41,6 +41,8 @@ To get a collection of records, you can use the `Query` object. It provides the
|
|
|
41
41
|
- `getAll()`: returns all the records in the query results by making multiple requests to iterate over all the pages which exist. If the query is not filtered and the table is a large dataset, this operation can affect the performance.
|
|
42
42
|
- `getMany()`: returns an array with a subset of the first results in the query. The default [pagination](#page) size (20) is used and can be customised by passing a different `{ pagination: { size: number } }` in its options. To learn more about default values, see [helper variables](#helper-variables).
|
|
43
43
|
|
|
44
|
+
Both the `getAll()` and `getMany()` will produce multiple requests to the server if the query should return more than the maximum page size. We perform the minimum number of requests to get the desired number of records.
|
|
45
|
+
|
|
44
46
|
All these methods allow customising its filters, column selection, column ordering, pagination or cache TTL. For example:
|
|
45
47
|
|
|
46
48
|
```ts
|
package/dist/index.cjs
CHANGED
|
@@ -172,7 +172,7 @@ function getFetchImplementation(userFetch) {
|
|
|
172
172
|
return fetchImpl;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
const VERSION = "0.0.0-alpha.
|
|
175
|
+
const VERSION = "0.0.0-alpha.ved61cb2";
|
|
176
176
|
|
|
177
177
|
class ErrorWithCause extends Error {
|
|
178
178
|
constructor(message, options) {
|
|
@@ -408,7 +408,7 @@ const getDatabaseMetadata = (variables) => fetch$1({
|
|
|
408
408
|
method: "get",
|
|
409
409
|
...variables
|
|
410
410
|
});
|
|
411
|
-
const
|
|
411
|
+
const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
|
412
412
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
|
413
413
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
|
414
414
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
|
@@ -552,6 +552,11 @@ const searchBranch = (variables) => fetch$1({
|
|
|
552
552
|
method: "post",
|
|
553
553
|
...variables
|
|
554
554
|
});
|
|
555
|
+
const summarizeTable = (variables) => fetch$1({
|
|
556
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
|
557
|
+
method: "post",
|
|
558
|
+
...variables
|
|
559
|
+
});
|
|
555
560
|
const operationsByTag = {
|
|
556
561
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
|
557
562
|
workspaces: {
|
|
@@ -574,7 +579,7 @@ const operationsByTag = {
|
|
|
574
579
|
createDatabase,
|
|
575
580
|
deleteDatabase,
|
|
576
581
|
getDatabaseMetadata,
|
|
577
|
-
|
|
582
|
+
updateDatabaseMetadata,
|
|
578
583
|
getGitBranchesMapping,
|
|
579
584
|
addGitBranchesEntry,
|
|
580
585
|
removeGitBranchesEntry,
|
|
@@ -632,7 +637,8 @@ const operationsByTag = {
|
|
|
632
637
|
bulkInsertTableRecords,
|
|
633
638
|
queryTable,
|
|
634
639
|
searchTable,
|
|
635
|
-
searchBranch
|
|
640
|
+
searchBranch,
|
|
641
|
+
summarizeTable
|
|
636
642
|
}
|
|
637
643
|
};
|
|
638
644
|
|
|
@@ -883,8 +889,8 @@ class DatabaseApi {
|
|
|
883
889
|
...this.extraProps
|
|
884
890
|
});
|
|
885
891
|
}
|
|
886
|
-
|
|
887
|
-
return operationsByTag.database.
|
|
892
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
|
893
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
|
888
894
|
pathParams: { workspace, dbName },
|
|
889
895
|
body: options,
|
|
890
896
|
...this.extraProps
|
|
@@ -1116,6 +1122,13 @@ class RecordsApi {
|
|
|
1116
1122
|
...this.extraProps
|
|
1117
1123
|
});
|
|
1118
1124
|
}
|
|
1125
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
|
1126
|
+
return operationsByTag.records.summarizeTable({
|
|
1127
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
|
1128
|
+
body: query,
|
|
1129
|
+
...this.extraProps
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1119
1132
|
}
|
|
1120
1133
|
class MigrationRequestsApi {
|
|
1121
1134
|
constructor(extraProps) {
|
|
@@ -1366,9 +1379,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
|
1366
1379
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1367
1380
|
return value;
|
|
1368
1381
|
};
|
|
1369
|
-
var
|
|
1382
|
+
var __privateMethod$3 = (obj, member, method) => {
|
|
1383
|
+
__accessCheck$5(obj, member, "access private method");
|
|
1384
|
+
return method;
|
|
1385
|
+
};
|
|
1386
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
|
1370
1387
|
const _Query = class {
|
|
1371
1388
|
constructor(repository, table, data, rawParent) {
|
|
1389
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
|
1372
1390
|
__privateAdd$5(this, _table$1, void 0);
|
|
1373
1391
|
__privateAdd$5(this, _repository, void 0);
|
|
1374
1392
|
__privateAdd$5(this, _data, { filter: {} });
|
|
@@ -1425,22 +1443,17 @@ const _Query = class {
|
|
|
1425
1443
|
}
|
|
1426
1444
|
filter(a, b) {
|
|
1427
1445
|
if (arguments.length === 1) {
|
|
1428
|
-
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
|
1446
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
|
1447
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
|
1448
|
+
}));
|
|
1429
1449
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
|
1430
1450
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1431
1451
|
} else {
|
|
1432
|
-
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.
|
|
1452
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
|
1433
1453
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
|
1434
1454
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1435
1455
|
}
|
|
1436
1456
|
}
|
|
1437
|
-
defaultFilter(column, value) {
|
|
1438
|
-
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
|
1439
|
-
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
|
1440
|
-
return { $includes: value };
|
|
1441
|
-
}
|
|
1442
|
-
return value;
|
|
1443
|
-
}
|
|
1444
1457
|
sort(column, direction = "asc") {
|
|
1445
1458
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
|
1446
1459
|
const sort = [...originalSort, { column, direction }];
|
|
@@ -1475,11 +1488,20 @@ const _Query = class {
|
|
|
1475
1488
|
}
|
|
1476
1489
|
}
|
|
1477
1490
|
async getMany(options = {}) {
|
|
1478
|
-
const
|
|
1491
|
+
const { pagination = {}, ...rest } = options;
|
|
1492
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
|
1493
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
|
1494
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
|
1495
|
+
const results = [...page.records];
|
|
1496
|
+
while (page.hasNextPage() && results.length < size) {
|
|
1497
|
+
page = await page.nextPage();
|
|
1498
|
+
results.push(...page.records);
|
|
1499
|
+
}
|
|
1479
1500
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
|
1480
1501
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
|
1481
1502
|
}
|
|
1482
|
-
|
|
1503
|
+
const array = new RecordArray(page, results.slice(0, size));
|
|
1504
|
+
return array;
|
|
1483
1505
|
}
|
|
1484
1506
|
async getAll(options = {}) {
|
|
1485
1507
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
|
@@ -1493,6 +1515,12 @@ const _Query = class {
|
|
|
1493
1515
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
|
1494
1516
|
return records[0] ?? null;
|
|
1495
1517
|
}
|
|
1518
|
+
async getFirstOrThrow(options = {}) {
|
|
1519
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
|
1520
|
+
if (records[0] === void 0)
|
|
1521
|
+
throw new Error("No results found.");
|
|
1522
|
+
return records[0];
|
|
1523
|
+
}
|
|
1496
1524
|
cache(ttl) {
|
|
1497
1525
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
|
1498
1526
|
}
|
|
@@ -1516,6 +1544,17 @@ let Query = _Query;
|
|
|
1516
1544
|
_table$1 = new WeakMap();
|
|
1517
1545
|
_repository = new WeakMap();
|
|
1518
1546
|
_data = new WeakMap();
|
|
1547
|
+
_cleanFilterConstraint = new WeakSet();
|
|
1548
|
+
cleanFilterConstraint_fn = function(column, value) {
|
|
1549
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
|
1550
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
|
1551
|
+
return { $includes: value };
|
|
1552
|
+
}
|
|
1553
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
|
1554
|
+
return value.id;
|
|
1555
|
+
}
|
|
1556
|
+
return value;
|
|
1557
|
+
};
|
|
1519
1558
|
function cleanParent(data, parent) {
|
|
1520
1559
|
if (isCursorPaginationOptions(data.pagination)) {
|
|
1521
1560
|
return { ...parent, sorting: void 0, filter: void 0 };
|
|
@@ -1684,6 +1723,25 @@ class RestRepository extends Query {
|
|
|
1684
1723
|
return null;
|
|
1685
1724
|
});
|
|
1686
1725
|
}
|
|
1726
|
+
async readOrThrow(a, b) {
|
|
1727
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
|
1728
|
+
const result = await this.read(a, b);
|
|
1729
|
+
if (Array.isArray(result)) {
|
|
1730
|
+
const missingIds = compact(
|
|
1731
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
1732
|
+
);
|
|
1733
|
+
if (missingIds.length > 0) {
|
|
1734
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
1735
|
+
}
|
|
1736
|
+
return result;
|
|
1737
|
+
}
|
|
1738
|
+
if (result === null) {
|
|
1739
|
+
const id = extractId(a) ?? "unknown";
|
|
1740
|
+
throw new Error(`Record with id ${id} not found`);
|
|
1741
|
+
}
|
|
1742
|
+
return result;
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1687
1745
|
async update(a, b, c) {
|
|
1688
1746
|
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
|
1689
1747
|
if (Array.isArray(a)) {
|
|
@@ -1706,6 +1764,25 @@ class RestRepository extends Query {
|
|
|
1706
1764
|
throw new Error("Invalid arguments for update method");
|
|
1707
1765
|
});
|
|
1708
1766
|
}
|
|
1767
|
+
async updateOrThrow(a, b, c) {
|
|
1768
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
|
1769
|
+
const result = await this.update(a, b, c);
|
|
1770
|
+
if (Array.isArray(result)) {
|
|
1771
|
+
const missingIds = compact(
|
|
1772
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
1773
|
+
);
|
|
1774
|
+
if (missingIds.length > 0) {
|
|
1775
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
1776
|
+
}
|
|
1777
|
+
return result;
|
|
1778
|
+
}
|
|
1779
|
+
if (result === null) {
|
|
1780
|
+
const id = extractId(a) ?? "unknown";
|
|
1781
|
+
throw new Error(`Record with id ${id} not found`);
|
|
1782
|
+
}
|
|
1783
|
+
return result;
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1709
1786
|
async createOrUpdate(a, b, c) {
|
|
1710
1787
|
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
|
1711
1788
|
if (Array.isArray(a)) {
|
|
@@ -1747,6 +1824,24 @@ class RestRepository extends Query {
|
|
|
1747
1824
|
throw new Error("Invalid arguments for delete method");
|
|
1748
1825
|
});
|
|
1749
1826
|
}
|
|
1827
|
+
async deleteOrThrow(a, b) {
|
|
1828
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
|
1829
|
+
const result = await this.delete(a, b);
|
|
1830
|
+
if (Array.isArray(result)) {
|
|
1831
|
+
const missingIds = compact(
|
|
1832
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
1833
|
+
);
|
|
1834
|
+
if (missingIds.length > 0) {
|
|
1835
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
1836
|
+
}
|
|
1837
|
+
return result;
|
|
1838
|
+
} else if (result === null) {
|
|
1839
|
+
const id = extractId(a) ?? "unknown";
|
|
1840
|
+
throw new Error(`Record with id ${id} not found`);
|
|
1841
|
+
}
|
|
1842
|
+
return result;
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1750
1845
|
async search(query, options = {}) {
|
|
1751
1846
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
|
1752
1847
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
@@ -1958,9 +2053,17 @@ const initObject = (db, schemaTables, table, object) => {
|
|
|
1958
2053
|
console.error(`Failed to parse link for field ${column.name}`);
|
|
1959
2054
|
} else if (isObject(value)) {
|
|
1960
2055
|
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
|
2056
|
+
} else {
|
|
2057
|
+
result[column.name] = null;
|
|
1961
2058
|
}
|
|
1962
2059
|
break;
|
|
1963
2060
|
}
|
|
2061
|
+
default:
|
|
2062
|
+
result[column.name] = value ?? null;
|
|
2063
|
+
if (column.notNull === true && value === null) {
|
|
2064
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
|
2065
|
+
}
|
|
2066
|
+
break;
|
|
1964
2067
|
}
|
|
1965
2068
|
}
|
|
1966
2069
|
result.read = function(columns2) {
|
|
@@ -2588,7 +2691,6 @@ exports.lte = lte;
|
|
|
2588
2691
|
exports.mergeMigrationRequest = mergeMigrationRequest;
|
|
2589
2692
|
exports.notExists = notExists;
|
|
2590
2693
|
exports.operationsByTag = operationsByTag;
|
|
2591
|
-
exports.patchDatabaseMetadata = patchDatabaseMetadata;
|
|
2592
2694
|
exports.pattern = pattern;
|
|
2593
2695
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
|
2594
2696
|
exports.queryTable = queryTable;
|
|
@@ -2601,9 +2703,11 @@ exports.searchTable = searchTable;
|
|
|
2601
2703
|
exports.serialize = serialize;
|
|
2602
2704
|
exports.setTableSchema = setTableSchema;
|
|
2603
2705
|
exports.startsWith = startsWith;
|
|
2706
|
+
exports.summarizeTable = summarizeTable;
|
|
2604
2707
|
exports.updateBranchMetadata = updateBranchMetadata;
|
|
2605
2708
|
exports.updateBranchSchema = updateBranchSchema;
|
|
2606
2709
|
exports.updateColumn = updateColumn;
|
|
2710
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
|
2607
2711
|
exports.updateMigrationRequest = updateMigrationRequest;
|
|
2608
2712
|
exports.updateRecordWithID = updateRecordWithID;
|
|
2609
2713
|
exports.updateTable = updateTable;
|