@xata.io/client 0.18.5 → 0.18.6

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.18.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#662](https://github.com/xataio/client-ts/pull/662) [`4a41680`](https://github.com/xataio/client-ts/commit/4a416803761a1c944ef9a76b794020ead6c8f477) Thanks [@SferaDev](https://github.com/SferaDev)! - Remove wildcard columns from sorting and filtering
8
+
9
+ - [#303](https://github.com/xataio/client-ts/pull/303) [`ad0cccb`](https://github.com/xataio/client-ts/commit/ad0cccb11cd4f9bb4bd7e44672d3375821e700fe) Thanks [@gimenete](https://github.com/gimenete)! - Add profiles for host parsing
10
+
11
+ - [#662](https://github.com/xataio/client-ts/pull/662) [`e1d6add`](https://github.com/xataio/client-ts/commit/e1d6addf84c55648bc0d908887b6bd020b429801) Thanks [@SferaDev](https://github.com/SferaDev)! - Add aggregations support to the SDK
12
+
13
+ - [#662](https://github.com/xataio/client-ts/pull/662) [`4a41680`](https://github.com/xataio/client-ts/commit/4a416803761a1c944ef9a76b794020ead6c8f477) Thanks [@SferaDev](https://github.com/SferaDev)! - Add summarize endpoints to SDK
14
+
3
15
  ## 0.18.5
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -172,7 +172,7 @@ function getFetchImplementation(userFetch) {
172
172
  return fetchImpl;
173
173
  }
174
174
 
175
- const VERSION = "0.18.5";
175
+ const VERSION = "0.18.6";
176
176
 
177
177
  class ErrorWithCause extends Error {
178
178
  constructor(message, options) {
@@ -234,7 +234,7 @@ function buildBaseUrl({
234
234
  apiUrl,
235
235
  pathParams
236
236
  }) {
237
- if (pathParams?.workspace === void 0)
237
+ if (pathParams?.workspace === void 0 || !path.startsWith("/db"))
238
238
  return `${apiUrl}${path}`;
239
239
  const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
240
240
  return url.replace("{workspaceId}", String(pathParams.workspace));
@@ -256,7 +256,9 @@ async function fetch$1({
256
256
  apiUrl,
257
257
  workspacesApiUrl,
258
258
  trace,
259
- signal
259
+ signal,
260
+ clientID,
261
+ sessionID
260
262
  }) {
261
263
  return trace(
262
264
  `${method.toUpperCase()} ${path}`,
@@ -274,6 +276,8 @@ async function fetch$1({
274
276
  headers: {
275
277
  "Content-Type": "application/json",
276
278
  "User-Agent": `Xata client-ts/${VERSION}`,
279
+ "X-Xata-Client-ID": clientID ?? "",
280
+ "X-Xata-Session-ID": sessionID ?? "",
277
281
  ...headers,
278
282
  ...hostHeader(fullUrl),
279
283
  Authorization: `Bearer ${apiKey}`
@@ -607,6 +611,29 @@ const summarizeTable = (variables, signal) => fetch$1({
607
611
  ...variables,
608
612
  signal
609
613
  });
614
+ const aggregateTable = (variables, signal) => fetch$1({
615
+ url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
616
+ method: "post",
617
+ ...variables,
618
+ signal
619
+ });
620
+ const cPGetDatabaseList = (variables, signal) => fetch$1({
621
+ url: "/workspaces/{workspaceId}/dbs",
622
+ method: "get",
623
+ ...variables,
624
+ signal
625
+ });
626
+ const cPCreateDatabase = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
627
+ const cPDeleteDatabase = (variables, signal) => fetch$1({
628
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
629
+ method: "delete",
630
+ ...variables,
631
+ signal
632
+ });
633
+ const cPGetCPDatabaseMetadata = (variables, signal) => fetch$1(
634
+ { url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "get", ...variables, signal }
635
+ );
636
+ const cPUpdateCPDatabaseMetadata = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
610
637
  const operationsByTag = {
611
638
  users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
612
639
  workspaces: {
@@ -688,7 +715,15 @@ const operationsByTag = {
688
715
  queryTable,
689
716
  searchTable,
690
717
  searchBranch,
691
- summarizeTable
718
+ summarizeTable,
719
+ aggregateTable
720
+ },
721
+ databases: {
722
+ cPGetDatabaseList,
723
+ cPCreateDatabase,
724
+ cPDeleteDatabase,
725
+ cPGetCPDatabaseMetadata,
726
+ cPUpdateCPDatabaseMetadata
692
727
  }
693
728
  };
694
729
 
@@ -716,6 +751,15 @@ function isHostProviderAlias(alias) {
716
751
  function isHostProviderBuilder(builder) {
717
752
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
718
753
  }
754
+ function parseProviderString(provider = "production") {
755
+ if (isHostProviderAlias(provider)) {
756
+ return provider;
757
+ }
758
+ const [main, workspaces] = provider.split(",");
759
+ if (!main || !workspaces)
760
+ return null;
761
+ return { main, workspaces };
762
+ }
719
763
 
720
764
  var __accessCheck$7 = (obj, member, msg) => {
721
765
  if (!member.has(obj))
@@ -1179,6 +1223,13 @@ class RecordsApi {
1179
1223
  ...this.extraProps
1180
1224
  });
1181
1225
  }
1226
+ aggregateTable(workspace, database, branch, tableName, query) {
1227
+ return operationsByTag.records.aggregateTable({
1228
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1229
+ body: query,
1230
+ ...this.extraProps
1231
+ });
1232
+ }
1182
1233
  }
1183
1234
  class MigrationRequestsApi {
1184
1235
  constructor(extraProps) {
@@ -1316,6 +1367,20 @@ class XataApiPlugin {
1316
1367
  class XataPlugin {
1317
1368
  }
1318
1369
 
1370
+ function generateUUID() {
1371
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1372
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1373
+ return v.toString(16);
1374
+ });
1375
+ }
1376
+
1377
+ function cleanFilter(filter) {
1378
+ if (!filter)
1379
+ return void 0;
1380
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1381
+ return values.length > 0 ? filter : void 0;
1382
+ }
1383
+
1319
1384
  var __accessCheck$6 = (obj, member, msg) => {
1320
1385
  if (!member.has(obj))
1321
1386
  throw TypeError("Cannot " + msg);
@@ -1455,7 +1520,7 @@ const _Query = class {
1455
1520
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1456
1521
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1457
1522
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1458
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1523
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
1459
1524
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1460
1525
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1461
1526
  this.any = this.any.bind(this);
@@ -1571,6 +1636,16 @@ const _Query = class {
1571
1636
  throw new Error("No results found.");
1572
1637
  return records[0];
1573
1638
  }
1639
+ async summarize(params = {}) {
1640
+ const { summaries, summariesFilter, ...options } = params;
1641
+ const query = new _Query(
1642
+ __privateGet$5(this, _repository),
1643
+ __privateGet$5(this, _table$1),
1644
+ options,
1645
+ __privateGet$5(this, _data)
1646
+ );
1647
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
1648
+ }
1574
1649
  cache(ttl) {
1575
1650
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1576
1651
  }
@@ -1692,10 +1767,13 @@ class RestRepository extends Query {
1692
1767
  __privateAdd$4(this, _schemaTables$2, void 0);
1693
1768
  __privateAdd$4(this, _trace, void 0);
1694
1769
  __privateSet$4(this, _table, options.table);
1695
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1696
1770
  __privateSet$4(this, _db, options.db);
1697
1771
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1698
1772
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1773
+ __privateSet$4(this, _getFetchProps, async () => {
1774
+ const props = await options.pluginOptions.getFetchProps();
1775
+ return { ...props, sessionID: generateUUID() };
1776
+ });
1699
1777
  const trace = options.pluginOptions.trace ?? defaultTrace;
1700
1778
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1701
1779
  return trace(name, fn, {
@@ -1911,22 +1989,32 @@ class RestRepository extends Query {
1911
1989
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
1912
1990
  });
1913
1991
  }
1992
+ async aggregate(aggs, filter) {
1993
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
1994
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1995
+ const result = await aggregateTable({
1996
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1997
+ body: { aggs, filter },
1998
+ ...fetchProps
1999
+ });
2000
+ return result;
2001
+ });
2002
+ }
1914
2003
  async query(query) {
1915
2004
  return __privateGet$4(this, _trace).call(this, "query", async () => {
1916
2005
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1917
2006
  if (cacheQuery)
1918
2007
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1919
2008
  const data = query.getQueryOptions();
1920
- const body = {
1921
- filter: cleanFilter(data.filter),
1922
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1923
- page: data.pagination,
1924
- columns: data.columns
1925
- };
1926
2009
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1927
2010
  const { meta, records: objects } = await queryTable({
1928
2011
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1929
- body,
2012
+ body: {
2013
+ filter: cleanFilter(data.filter),
2014
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2015
+ page: data.pagination,
2016
+ columns: data.columns ?? ["*"]
2017
+ },
1930
2018
  ...fetchProps
1931
2019
  });
1932
2020
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
@@ -1937,6 +2025,24 @@ class RestRepository extends Query {
1937
2025
  return new Page(query, meta, records);
1938
2026
  });
1939
2027
  }
2028
+ async summarizeTable(query, summaries, summariesFilter) {
2029
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2030
+ const data = query.getQueryOptions();
2031
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2032
+ const result = await summarizeTable({
2033
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2034
+ body: {
2035
+ filter: cleanFilter(data.filter),
2036
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2037
+ columns: data.columns,
2038
+ summaries,
2039
+ summariesFilter
2040
+ },
2041
+ ...fetchProps
2042
+ });
2043
+ return result;
2044
+ });
2045
+ }
1940
2046
  }
1941
2047
  _table = new WeakMap();
1942
2048
  _getFetchProps = new WeakMap();
@@ -2158,12 +2264,6 @@ function extractId(value) {
2158
2264
  return value.id;
2159
2265
  return void 0;
2160
2266
  }
2161
- function cleanFilter(filter) {
2162
- if (!filter)
2163
- return void 0;
2164
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2165
- return values.length > 0 ? filter : void 0;
2166
- }
2167
2267
  function isValidColumn(columns, column) {
2168
2268
  if (columns.includes("*"))
2169
2269
  return true;
@@ -2534,8 +2634,15 @@ const buildClient = (plugins) => {
2534
2634
  if (!databaseURL) {
2535
2635
  throw new Error("Option databaseURL is required");
2536
2636
  }
2537
- return { fetch, databaseURL, apiKey, branch, cache, trace };
2538
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2637
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID() };
2638
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
2639
+ fetch,
2640
+ apiKey,
2641
+ databaseURL,
2642
+ branch,
2643
+ trace,
2644
+ clientID
2645
+ }) {
2539
2646
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2540
2647
  if (!branchValue)
2541
2648
  throw new Error("Unable to resolve branch value");
@@ -2548,7 +2655,8 @@ const buildClient = (plugins) => {
2548
2655
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2549
2656
  return databaseURL + newPath;
2550
2657
  },
2551
- trace
2658
+ trace,
2659
+ clientID
2552
2660
  };
2553
2661
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2554
2662
  if (__privateGet(this, _branch))
@@ -2682,10 +2790,16 @@ exports.XataPlugin = XataPlugin;
2682
2790
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2683
2791
  exports.addGitBranchesEntry = addGitBranchesEntry;
2684
2792
  exports.addTableColumn = addTableColumn;
2793
+ exports.aggregateTable = aggregateTable;
2685
2794
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
2686
2795
  exports.buildClient = buildClient;
2687
2796
  exports.buildWorkerRunner = buildWorkerRunner;
2688
2797
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2798
+ exports.cPCreateDatabase = cPCreateDatabase;
2799
+ exports.cPDeleteDatabase = cPDeleteDatabase;
2800
+ exports.cPGetCPDatabaseMetadata = cPGetCPDatabaseMetadata;
2801
+ exports.cPGetDatabaseList = cPGetDatabaseList;
2802
+ exports.cPUpdateCPDatabaseMetadata = cPUpdateCPDatabaseMetadata;
2689
2803
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2690
2804
  exports.compareBranchSchemas = compareBranchSchemas;
2691
2805
  exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
@@ -2726,6 +2840,7 @@ exports.getDatabaseList = getDatabaseList;
2726
2840
  exports.getDatabaseMetadata = getDatabaseMetadata;
2727
2841
  exports.getDatabaseURL = getDatabaseURL;
2728
2842
  exports.getGitBranchesMapping = getGitBranchesMapping;
2843
+ exports.getHostUrl = getHostUrl;
2729
2844
  exports.getMigrationRequest = getMigrationRequest;
2730
2845
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2731
2846
  exports.getRecord = getRecord;
@@ -2750,6 +2865,8 @@ exports.insertRecordWithID = insertRecordWithID;
2750
2865
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
2751
2866
  exports.is = is;
2752
2867
  exports.isCursorPaginationOptions = isCursorPaginationOptions;
2868
+ exports.isHostProviderAlias = isHostProviderAlias;
2869
+ exports.isHostProviderBuilder = isHostProviderBuilder;
2753
2870
  exports.isIdentifiable = isIdentifiable;
2754
2871
  exports.isNot = isNot;
2755
2872
  exports.isXataRecord = isXataRecord;
@@ -2763,6 +2880,7 @@ exports.lte = lte;
2763
2880
  exports.mergeMigrationRequest = mergeMigrationRequest;
2764
2881
  exports.notExists = notExists;
2765
2882
  exports.operationsByTag = operationsByTag;
2883
+ exports.parseProviderString = parseProviderString;
2766
2884
  exports.pattern = pattern;
2767
2885
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
2768
2886
  exports.queryMigrationRequests = queryMigrationRequests;