@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/dist/index.mjs CHANGED
@@ -150,7 +150,7 @@ function getFetchImplementation(userFetch) {
150
150
  return fetchImpl;
151
151
  }
152
152
 
153
- const VERSION = "0.18.5";
153
+ const VERSION = "0.18.6";
154
154
 
155
155
  class ErrorWithCause extends Error {
156
156
  constructor(message, options) {
@@ -212,7 +212,7 @@ function buildBaseUrl({
212
212
  apiUrl,
213
213
  pathParams
214
214
  }) {
215
- if (pathParams?.workspace === void 0)
215
+ if (pathParams?.workspace === void 0 || !path.startsWith("/db"))
216
216
  return `${apiUrl}${path}`;
217
217
  const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
218
218
  return url.replace("{workspaceId}", String(pathParams.workspace));
@@ -234,7 +234,9 @@ async function fetch$1({
234
234
  apiUrl,
235
235
  workspacesApiUrl,
236
236
  trace,
237
- signal
237
+ signal,
238
+ clientID,
239
+ sessionID
238
240
  }) {
239
241
  return trace(
240
242
  `${method.toUpperCase()} ${path}`,
@@ -252,6 +254,8 @@ async function fetch$1({
252
254
  headers: {
253
255
  "Content-Type": "application/json",
254
256
  "User-Agent": `Xata client-ts/${VERSION}`,
257
+ "X-Xata-Client-ID": clientID ?? "",
258
+ "X-Xata-Session-ID": sessionID ?? "",
255
259
  ...headers,
256
260
  ...hostHeader(fullUrl),
257
261
  Authorization: `Bearer ${apiKey}`
@@ -585,6 +589,29 @@ const summarizeTable = (variables, signal) => fetch$1({
585
589
  ...variables,
586
590
  signal
587
591
  });
592
+ const aggregateTable = (variables, signal) => fetch$1({
593
+ url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
594
+ method: "post",
595
+ ...variables,
596
+ signal
597
+ });
598
+ const cPGetDatabaseList = (variables, signal) => fetch$1({
599
+ url: "/workspaces/{workspaceId}/dbs",
600
+ method: "get",
601
+ ...variables,
602
+ signal
603
+ });
604
+ const cPCreateDatabase = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
605
+ const cPDeleteDatabase = (variables, signal) => fetch$1({
606
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
607
+ method: "delete",
608
+ ...variables,
609
+ signal
610
+ });
611
+ const cPGetCPDatabaseMetadata = (variables, signal) => fetch$1(
612
+ { url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "get", ...variables, signal }
613
+ );
614
+ const cPUpdateCPDatabaseMetadata = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
588
615
  const operationsByTag = {
589
616
  users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
590
617
  workspaces: {
@@ -666,7 +693,15 @@ const operationsByTag = {
666
693
  queryTable,
667
694
  searchTable,
668
695
  searchBranch,
669
- summarizeTable
696
+ summarizeTable,
697
+ aggregateTable
698
+ },
699
+ databases: {
700
+ cPGetDatabaseList,
701
+ cPCreateDatabase,
702
+ cPDeleteDatabase,
703
+ cPGetCPDatabaseMetadata,
704
+ cPUpdateCPDatabaseMetadata
670
705
  }
671
706
  };
672
707
 
@@ -694,6 +729,15 @@ function isHostProviderAlias(alias) {
694
729
  function isHostProviderBuilder(builder) {
695
730
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
696
731
  }
732
+ function parseProviderString(provider = "production") {
733
+ if (isHostProviderAlias(provider)) {
734
+ return provider;
735
+ }
736
+ const [main, workspaces] = provider.split(",");
737
+ if (!main || !workspaces)
738
+ return null;
739
+ return { main, workspaces };
740
+ }
697
741
 
698
742
  var __accessCheck$7 = (obj, member, msg) => {
699
743
  if (!member.has(obj))
@@ -1157,6 +1201,13 @@ class RecordsApi {
1157
1201
  ...this.extraProps
1158
1202
  });
1159
1203
  }
1204
+ aggregateTable(workspace, database, branch, tableName, query) {
1205
+ return operationsByTag.records.aggregateTable({
1206
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1207
+ body: query,
1208
+ ...this.extraProps
1209
+ });
1210
+ }
1160
1211
  }
1161
1212
  class MigrationRequestsApi {
1162
1213
  constructor(extraProps) {
@@ -1294,6 +1345,20 @@ class XataApiPlugin {
1294
1345
  class XataPlugin {
1295
1346
  }
1296
1347
 
1348
+ function generateUUID() {
1349
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1350
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1351
+ return v.toString(16);
1352
+ });
1353
+ }
1354
+
1355
+ function cleanFilter(filter) {
1356
+ if (!filter)
1357
+ return void 0;
1358
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1359
+ return values.length > 0 ? filter : void 0;
1360
+ }
1361
+
1297
1362
  var __accessCheck$6 = (obj, member, msg) => {
1298
1363
  if (!member.has(obj))
1299
1364
  throw TypeError("Cannot " + msg);
@@ -1433,7 +1498,7 @@ const _Query = class {
1433
1498
  __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1434
1499
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1435
1500
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1436
- __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1501
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
1437
1502
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1438
1503
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1439
1504
  this.any = this.any.bind(this);
@@ -1549,6 +1614,16 @@ const _Query = class {
1549
1614
  throw new Error("No results found.");
1550
1615
  return records[0];
1551
1616
  }
1617
+ async summarize(params = {}) {
1618
+ const { summaries, summariesFilter, ...options } = params;
1619
+ const query = new _Query(
1620
+ __privateGet$5(this, _repository),
1621
+ __privateGet$5(this, _table$1),
1622
+ options,
1623
+ __privateGet$5(this, _data)
1624
+ );
1625
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
1626
+ }
1552
1627
  cache(ttl) {
1553
1628
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1554
1629
  }
@@ -1670,10 +1745,13 @@ class RestRepository extends Query {
1670
1745
  __privateAdd$4(this, _schemaTables$2, void 0);
1671
1746
  __privateAdd$4(this, _trace, void 0);
1672
1747
  __privateSet$4(this, _table, options.table);
1673
- __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1674
1748
  __privateSet$4(this, _db, options.db);
1675
1749
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1676
1750
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1751
+ __privateSet$4(this, _getFetchProps, async () => {
1752
+ const props = await options.pluginOptions.getFetchProps();
1753
+ return { ...props, sessionID: generateUUID() };
1754
+ });
1677
1755
  const trace = options.pluginOptions.trace ?? defaultTrace;
1678
1756
  __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1679
1757
  return trace(name, fn, {
@@ -1889,22 +1967,32 @@ class RestRepository extends Query {
1889
1967
  return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
1890
1968
  });
1891
1969
  }
1970
+ async aggregate(aggs, filter) {
1971
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
1972
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1973
+ const result = await aggregateTable({
1974
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1975
+ body: { aggs, filter },
1976
+ ...fetchProps
1977
+ });
1978
+ return result;
1979
+ });
1980
+ }
1892
1981
  async query(query) {
1893
1982
  return __privateGet$4(this, _trace).call(this, "query", async () => {
1894
1983
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1895
1984
  if (cacheQuery)
1896
1985
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1897
1986
  const data = query.getQueryOptions();
1898
- const body = {
1899
- filter: cleanFilter(data.filter),
1900
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1901
- page: data.pagination,
1902
- columns: data.columns
1903
- };
1904
1987
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1905
1988
  const { meta, records: objects } = await queryTable({
1906
1989
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1907
- body,
1990
+ body: {
1991
+ filter: cleanFilter(data.filter),
1992
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1993
+ page: data.pagination,
1994
+ columns: data.columns ?? ["*"]
1995
+ },
1908
1996
  ...fetchProps
1909
1997
  });
1910
1998
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
@@ -1915,6 +2003,24 @@ class RestRepository extends Query {
1915
2003
  return new Page(query, meta, records);
1916
2004
  });
1917
2005
  }
2006
+ async summarizeTable(query, summaries, summariesFilter) {
2007
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2008
+ const data = query.getQueryOptions();
2009
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2010
+ const result = await summarizeTable({
2011
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
2012
+ body: {
2013
+ filter: cleanFilter(data.filter),
2014
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2015
+ columns: data.columns,
2016
+ summaries,
2017
+ summariesFilter
2018
+ },
2019
+ ...fetchProps
2020
+ });
2021
+ return result;
2022
+ });
2023
+ }
1918
2024
  }
1919
2025
  _table = new WeakMap();
1920
2026
  _getFetchProps = new WeakMap();
@@ -2136,12 +2242,6 @@ function extractId(value) {
2136
2242
  return value.id;
2137
2243
  return void 0;
2138
2244
  }
2139
- function cleanFilter(filter) {
2140
- if (!filter)
2141
- return void 0;
2142
- const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2143
- return values.length > 0 ? filter : void 0;
2144
- }
2145
2245
  function isValidColumn(columns, column) {
2146
2246
  if (columns.includes("*"))
2147
2247
  return true;
@@ -2512,8 +2612,15 @@ const buildClient = (plugins) => {
2512
2612
  if (!databaseURL) {
2513
2613
  throw new Error("Option databaseURL is required");
2514
2614
  }
2515
- return { fetch, databaseURL, apiKey, branch, cache, trace };
2516
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2615
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID() };
2616
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
2617
+ fetch,
2618
+ apiKey,
2619
+ databaseURL,
2620
+ branch,
2621
+ trace,
2622
+ clientID
2623
+ }) {
2517
2624
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2518
2625
  if (!branchValue)
2519
2626
  throw new Error("Unable to resolve branch value");
@@ -2526,7 +2633,8 @@ const buildClient = (plugins) => {
2526
2633
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2527
2634
  return databaseURL + newPath;
2528
2635
  },
2529
- trace
2636
+ trace,
2637
+ clientID
2530
2638
  };
2531
2639
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2532
2640
  if (__privateGet(this, _branch))
@@ -2638,5 +2746,5 @@ class XataError extends Error {
2638
2746
  }
2639
2747
  }
2640
2748
 
2641
- 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, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2749
+ 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, aggregateTable, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cPCreateDatabase, cPDeleteDatabase, cPGetCPDatabaseMetadata, cPGetDatabaseList, cPUpdateCPDatabaseMetadata, 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, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2642
2750
  //# sourceMappingURL=index.mjs.map