@xata.io/client 0.17.1 → 0.18.0
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 +22 -0
- package/README.md +1 -1
- package/Usage.md +2 -0
- package/dist/index.cjs +107 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +314 -33
- package/dist/index.mjs +106 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -150,7 +150,7 @@ function getFetchImplementation(userFetch) {
|
|
150
150
|
return fetchImpl;
|
151
151
|
}
|
152
152
|
|
153
|
-
const VERSION = "0.
|
153
|
+
const VERSION = "0.18.0";
|
154
154
|
|
155
155
|
class ErrorWithCause extends Error {
|
156
156
|
constructor(message, options) {
|
@@ -386,6 +386,7 @@ const getDatabaseMetadata = (variables) => fetch$1({
|
|
386
386
|
method: "get",
|
387
387
|
...variables
|
388
388
|
});
|
389
|
+
const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
389
390
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
390
391
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
391
392
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -529,6 +530,11 @@ const searchBranch = (variables) => fetch$1({
|
|
529
530
|
method: "post",
|
530
531
|
...variables
|
531
532
|
});
|
533
|
+
const summarizeTable = (variables) => fetch$1({
|
534
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
535
|
+
method: "post",
|
536
|
+
...variables
|
537
|
+
});
|
532
538
|
const operationsByTag = {
|
533
539
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
534
540
|
workspaces: {
|
@@ -551,6 +557,7 @@ const operationsByTag = {
|
|
551
557
|
createDatabase,
|
552
558
|
deleteDatabase,
|
553
559
|
getDatabaseMetadata,
|
560
|
+
updateDatabaseMetadata,
|
554
561
|
getGitBranchesMapping,
|
555
562
|
addGitBranchesEntry,
|
556
563
|
removeGitBranchesEntry,
|
@@ -608,7 +615,8 @@ const operationsByTag = {
|
|
608
615
|
bulkInsertTableRecords,
|
609
616
|
queryTable,
|
610
617
|
searchTable,
|
611
|
-
searchBranch
|
618
|
+
searchBranch,
|
619
|
+
summarizeTable
|
612
620
|
}
|
613
621
|
};
|
614
622
|
|
@@ -859,6 +867,13 @@ class DatabaseApi {
|
|
859
867
|
...this.extraProps
|
860
868
|
});
|
861
869
|
}
|
870
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
871
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
872
|
+
pathParams: { workspace, dbName },
|
873
|
+
body: options,
|
874
|
+
...this.extraProps
|
875
|
+
});
|
876
|
+
}
|
862
877
|
getGitBranchesMapping(workspace, dbName) {
|
863
878
|
return operationsByTag.database.getGitBranchesMapping({
|
864
879
|
pathParams: { workspace, dbName },
|
@@ -1085,6 +1100,13 @@ class RecordsApi {
|
|
1085
1100
|
...this.extraProps
|
1086
1101
|
});
|
1087
1102
|
}
|
1103
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
1104
|
+
return operationsByTag.records.summarizeTable({
|
1105
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1106
|
+
body: query,
|
1107
|
+
...this.extraProps
|
1108
|
+
});
|
1109
|
+
}
|
1088
1110
|
}
|
1089
1111
|
class MigrationRequestsApi {
|
1090
1112
|
constructor(extraProps) {
|
@@ -1444,11 +1466,20 @@ const _Query = class {
|
|
1444
1466
|
}
|
1445
1467
|
}
|
1446
1468
|
async getMany(options = {}) {
|
1447
|
-
const
|
1469
|
+
const { pagination = {}, ...rest } = options;
|
1470
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1471
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1472
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1473
|
+
const results = [...page.records];
|
1474
|
+
while (page.hasNextPage() && results.length < size) {
|
1475
|
+
page = await page.nextPage();
|
1476
|
+
results.push(...page.records);
|
1477
|
+
}
|
1448
1478
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1449
1479
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1450
1480
|
}
|
1451
|
-
|
1481
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1482
|
+
return array;
|
1452
1483
|
}
|
1453
1484
|
async getAll(options = {}) {
|
1454
1485
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1462,6 +1493,12 @@ const _Query = class {
|
|
1462
1493
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1463
1494
|
return records[0] ?? null;
|
1464
1495
|
}
|
1496
|
+
async getFirstOrThrow(options = {}) {
|
1497
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1498
|
+
if (records[0] === void 0)
|
1499
|
+
throw new Error("No results found.");
|
1500
|
+
return records[0];
|
1501
|
+
}
|
1465
1502
|
cache(ttl) {
|
1466
1503
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1467
1504
|
}
|
@@ -1653,6 +1690,25 @@ class RestRepository extends Query {
|
|
1653
1690
|
return null;
|
1654
1691
|
});
|
1655
1692
|
}
|
1693
|
+
async readOrThrow(a, b) {
|
1694
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1695
|
+
const result = await this.read(a, b);
|
1696
|
+
if (Array.isArray(result)) {
|
1697
|
+
const missingIds = compact(
|
1698
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1699
|
+
);
|
1700
|
+
if (missingIds.length > 0) {
|
1701
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1702
|
+
}
|
1703
|
+
return result;
|
1704
|
+
}
|
1705
|
+
if (result === null) {
|
1706
|
+
const id = extractId(a) ?? "unknown";
|
1707
|
+
throw new Error(`Record with id ${id} not found`);
|
1708
|
+
}
|
1709
|
+
return result;
|
1710
|
+
});
|
1711
|
+
}
|
1656
1712
|
async update(a, b, c) {
|
1657
1713
|
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1658
1714
|
if (Array.isArray(a)) {
|
@@ -1675,6 +1731,25 @@ class RestRepository extends Query {
|
|
1675
1731
|
throw new Error("Invalid arguments for update method");
|
1676
1732
|
});
|
1677
1733
|
}
|
1734
|
+
async updateOrThrow(a, b, c) {
|
1735
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1736
|
+
const result = await this.update(a, b, c);
|
1737
|
+
if (Array.isArray(result)) {
|
1738
|
+
const missingIds = compact(
|
1739
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1740
|
+
);
|
1741
|
+
if (missingIds.length > 0) {
|
1742
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1743
|
+
}
|
1744
|
+
return result;
|
1745
|
+
}
|
1746
|
+
if (result === null) {
|
1747
|
+
const id = extractId(a) ?? "unknown";
|
1748
|
+
throw new Error(`Record with id ${id} not found`);
|
1749
|
+
}
|
1750
|
+
return result;
|
1751
|
+
});
|
1752
|
+
}
|
1678
1753
|
async createOrUpdate(a, b, c) {
|
1679
1754
|
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1680
1755
|
if (Array.isArray(a)) {
|
@@ -1716,6 +1791,24 @@ class RestRepository extends Query {
|
|
1716
1791
|
throw new Error("Invalid arguments for delete method");
|
1717
1792
|
});
|
1718
1793
|
}
|
1794
|
+
async deleteOrThrow(a, b) {
|
1795
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1796
|
+
const result = await this.delete(a, b);
|
1797
|
+
if (Array.isArray(result)) {
|
1798
|
+
const missingIds = compact(
|
1799
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1800
|
+
);
|
1801
|
+
if (missingIds.length > 0) {
|
1802
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1803
|
+
}
|
1804
|
+
return result;
|
1805
|
+
} else if (result === null) {
|
1806
|
+
const id = extractId(a) ?? "unknown";
|
1807
|
+
throw new Error(`Record with id ${id} not found`);
|
1808
|
+
}
|
1809
|
+
return result;
|
1810
|
+
});
|
1811
|
+
}
|
1719
1812
|
async search(query, options = {}) {
|
1720
1813
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1721
1814
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1927,9 +2020,17 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1927
2020
|
console.error(`Failed to parse link for field ${column.name}`);
|
1928
2021
|
} else if (isObject(value)) {
|
1929
2022
|
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
2023
|
+
} else {
|
2024
|
+
result[column.name] = null;
|
1930
2025
|
}
|
1931
2026
|
break;
|
1932
2027
|
}
|
2028
|
+
default:
|
2029
|
+
result[column.name] = value ?? null;
|
2030
|
+
if (column.notNull === true && value === null) {
|
2031
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2032
|
+
}
|
2033
|
+
break;
|
1933
2034
|
}
|
1934
2035
|
}
|
1935
2036
|
result.read = function(columns2) {
|
@@ -2453,5 +2554,5 @@ class XataError extends Error {
|
|
2453
2554
|
}
|
2454
2555
|
}
|
2455
2556
|
|
2456
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateBranchSchema, updateColumn, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2557
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2457
2558
|
//# sourceMappingURL=index.mjs.map
|