@xata.io/client 0.19.1 → 0.20.1

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,27 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.20.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#744](https://github.com/xataio/client-ts/pull/744) [`98298ca`](https://github.com/xataio/client-ts/commit/98298ca1312a2256ee3e9d2700a9f3d3e316abe5) Thanks [@xata-bot](https://github.com/xata-bot)! - Add deno entry point
8
+
9
+ ## 0.20.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#737](https://github.com/xataio/client-ts/pull/737) [`6cbeaa0`](https://github.com/xataio/client-ts/commit/6cbeaa00050b5aa99ab7c98052a906487263e026) Thanks [@SferaDev](https://github.com/SferaDev)! - Rename first to start and last to end in pagination
14
+
15
+ ### Patch Changes
16
+
17
+ - [#732](https://github.com/xataio/client-ts/pull/732) [`a5a9aa5`](https://github.com/xataio/client-ts/commit/a5a9aa59987faa1d3d701d7431b8a96031e01ac7) Thanks [@SferaDev](https://github.com/SferaDev)! - [Experimental] Allow passing fetch options in some queries
18
+
19
+ - [#735](https://github.com/xataio/client-ts/pull/735) [`c64b2eb`](https://github.com/xataio/client-ts/commit/c64b2eb9add70e75d419d418ab9608caac0dbfa1) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for default values
20
+
21
+ - [#730](https://github.com/xataio/client-ts/pull/730) [`485b217`](https://github.com/xataio/client-ts/commit/485b217079c4b2091d697e68622c48eddd130ceb) Thanks [@SferaDev](https://github.com/SferaDev)! - Add more summarize functions
22
+
23
+ - [#730](https://github.com/xataio/client-ts/pull/730) [`4d7499c`](https://github.com/xataio/client-ts/commit/4d7499ccbb135691350334fd8022f7a5da41c5f2) Thanks [@SferaDev](https://github.com/SferaDev)! - Add a check for browser execution
24
+
3
25
  ## 0.19.1
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -187,8 +187,8 @@ page.hasNextPage(); // Boolean
187
187
 
188
188
  const nextPage = await page.nextPage(); // Page object
189
189
  const previousPage = await page.previousPage(); // Page object
190
- const firstPage = await page.firstPage(); // Page object
191
- const lastPage = await page.lastPage(); // Page object
190
+ const startPage = await page.startPage(); // Page object
191
+ const endPage = await page.endPage(); // Page object
192
192
  ```
193
193
 
194
194
  If you want to use an iterator, both the Repository and the Query classes implement an `AsyncIterable`. Alternatively you can use `getIterator()` and customize the batch size of the iterator:
package/Usage.md CHANGED
@@ -329,8 +329,8 @@ It contains:
329
329
  - `hasNextPage`: Function that returns a boolean indicating if there is a next page.
330
330
  - `nextPage`: Async function that can be used to get the next page.
331
331
  - `previousPage`: Async function that can be used to get the previous page.
332
- - `firstPage`: Async function that can be used to get the first page.
333
- - `lastPage`: Async function that can be used to get the last page.
332
+ - `startPage`: Async function that can be used to get the start page.
333
+ - `endPage`: Async function that can be used to get the end page.
334
334
  - `meta`: Information about the current page and its cursor.
335
335
 
336
336
  ```ts
@@ -344,14 +344,14 @@ page2.records; // Array of `XataRecord` objects.
344
344
  const page1 = await page2.previousPage();
345
345
  page1.records; // Array of `XataRecord` objects.
346
346
 
347
- const firstPage = await page1.firstPage();
348
- firstPage.records; // Array of `XataRecord` objects.
347
+ const startPage = await page1.startPage();
348
+ startPage.records; // Array of `XataRecord` objects.
349
349
  ```
350
350
 
351
351
  The `Repository` class implements the `Query` interface, so you can use it to paginate the records in the table too.
352
352
 
353
353
  ```ts
354
- const page = await xata.db.users.firstPage();
354
+ const page = await xata.db.users.startPage();
355
355
  page.records; // Array of `XataRecord` objects.
356
356
  ```
357
357
 
package/dist/index.cjs CHANGED
@@ -116,6 +116,25 @@ function getEnvironment() {
116
116
  fallbackBranch: getGlobalFallbackBranch()
117
117
  };
118
118
  }
119
+ function getEnableBrowserVariable() {
120
+ try {
121
+ if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
122
+ return process.env.XATA_ENABLE_BROWSER === "true";
123
+ }
124
+ } catch (err) {
125
+ }
126
+ try {
127
+ if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
128
+ return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
129
+ }
130
+ } catch (err) {
131
+ }
132
+ try {
133
+ return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
134
+ } catch (err) {
135
+ return void 0;
136
+ }
137
+ }
119
138
  function getGlobalApiKey() {
120
139
  try {
121
140
  return XATA_API_KEY;
@@ -186,7 +205,7 @@ function getFetchImplementation(userFetch) {
186
205
  return fetchImpl;
187
206
  }
188
207
 
189
- const VERSION = "0.19.1";
208
+ const VERSION = "0.20.1";
190
209
 
191
210
  class ErrorWithCause extends Error {
192
211
  constructor(message, options) {
@@ -276,7 +295,8 @@ async function fetch$1({
276
295
  trace,
277
296
  signal,
278
297
  clientID,
279
- sessionID
298
+ sessionID,
299
+ fetchOptions = {}
280
300
  }) {
281
301
  return trace(
282
302
  `${method.toUpperCase()} ${path}`,
@@ -289,6 +309,7 @@ async function fetch$1({
289
309
  [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
290
310
  });
291
311
  const response = await fetchImpl(url, {
312
+ ...fetchOptions,
292
313
  method: method.toUpperCase(),
293
314
  body: body ? JSON.stringify(body) : void 0,
294
315
  headers: {
@@ -387,6 +408,7 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
387
408
  const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
388
409
  const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
389
410
  const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
411
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
390
412
  const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
391
413
  const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
392
414
  const getMigrationRequest = (variables, signal) => dataPlaneFetch({
@@ -517,6 +539,16 @@ const operationsByTag$2 = {
517
539
  previewBranchSchemaEdit,
518
540
  applyBranchSchemaEdit
519
541
  },
542
+ records: {
543
+ branchTransaction,
544
+ insertRecord,
545
+ getRecord,
546
+ insertRecordWithID,
547
+ updateRecordWithID,
548
+ upsertRecordWithID,
549
+ deleteRecord,
550
+ bulkInsertTableRecords
551
+ },
520
552
  migrationRequests: {
521
553
  queryMigrationRequests,
522
554
  createMigrationRequest,
@@ -539,15 +571,6 @@ const operationsByTag$2 = {
539
571
  updateColumn,
540
572
  deleteColumn
541
573
  },
542
- records: {
543
- insertRecord,
544
- getRecord,
545
- insertRecordWithID,
546
- updateRecordWithID,
547
- upsertRecordWithID,
548
- deleteRecord,
549
- bulkInsertTableRecords
550
- },
551
574
  searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
552
575
  };
553
576
 
@@ -1379,11 +1402,12 @@ class SearchAndFilterApi {
1379
1402
  filter,
1380
1403
  sort,
1381
1404
  page,
1382
- columns
1405
+ columns,
1406
+ consistency
1383
1407
  }) {
1384
1408
  return operationsByTag.searchAndFilter.queryTable({
1385
1409
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1386
- body: { filter, sort, page, columns },
1410
+ body: { filter, sort, page, columns, consistency },
1387
1411
  ...this.extraProps
1388
1412
  });
1389
1413
  }
@@ -1435,11 +1459,12 @@ class SearchAndFilterApi {
1435
1459
  summaries,
1436
1460
  sort,
1437
1461
  summariesFilter,
1438
- page
1462
+ page,
1463
+ consistency
1439
1464
  }) {
1440
1465
  return operationsByTag.searchAndFilter.summarizeTable({
1441
1466
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1442
- body: { filter, columns, summaries, sort, summariesFilter, page },
1467
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
1443
1468
  ...this.extraProps
1444
1469
  });
1445
1470
  }
@@ -1799,11 +1824,11 @@ class Page {
1799
1824
  async previousPage(size, offset) {
1800
1825
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1801
1826
  }
1802
- async firstPage(size, offset) {
1803
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
1827
+ async startPage(size, offset) {
1828
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
1804
1829
  }
1805
- async lastPage(size, offset) {
1806
- return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
1830
+ async endPage(size, offset) {
1831
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
1807
1832
  }
1808
1833
  hasNextPage() {
1809
1834
  return this.meta.page.more;
@@ -1815,7 +1840,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
1815
1840
  const PAGINATION_MAX_OFFSET = 800;
1816
1841
  const PAGINATION_DEFAULT_OFFSET = 0;
1817
1842
  function isCursorPaginationOptions(options) {
1818
- return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1843
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1819
1844
  }
1820
1845
  const _RecordArray = class extends Array {
1821
1846
  constructor(...args) {
@@ -1847,12 +1872,12 @@ const _RecordArray = class extends Array {
1847
1872
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1848
1873
  return new _RecordArray(newPage);
1849
1874
  }
1850
- async firstPage(size, offset) {
1851
- const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1875
+ async startPage(size, offset) {
1876
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1852
1877
  return new _RecordArray(newPage);
1853
1878
  }
1854
- async lastPage(size, offset) {
1855
- const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1879
+ async endPage(size, offset) {
1880
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1856
1881
  return new _RecordArray(newPage);
1857
1882
  }
1858
1883
  hasNextPage() {
@@ -1909,6 +1934,7 @@ const _Query = class {
1909
1934
  __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
1910
1935
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1911
1936
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1937
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
1912
1938
  this.any = this.any.bind(this);
1913
1939
  this.all = this.all.bind(this);
1914
1940
  this.not = this.not.bind(this);
@@ -2036,15 +2062,15 @@ const _Query = class {
2036
2062
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2037
2063
  }
2038
2064
  nextPage(size, offset) {
2039
- return this.firstPage(size, offset);
2065
+ return this.startPage(size, offset);
2040
2066
  }
2041
2067
  previousPage(size, offset) {
2042
- return this.firstPage(size, offset);
2068
+ return this.startPage(size, offset);
2043
2069
  }
2044
- firstPage(size, offset) {
2070
+ startPage(size, offset) {
2045
2071
  return this.getPaginated({ pagination: { size, offset } });
2046
2072
  }
2047
- lastPage(size, offset) {
2073
+ endPage(size, offset) {
2048
2074
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2049
2075
  }
2050
2076
  hasNextPage() {
@@ -2440,6 +2466,7 @@ class RestRepository extends Query {
2440
2466
  page: data.pagination,
2441
2467
  columns: data.columns ?? ["*"]
2442
2468
  },
2469
+ fetchOptions: data.fetchOptions,
2443
2470
  ...fetchProps
2444
2471
  });
2445
2472
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
@@ -3098,6 +3125,13 @@ const buildClient = (plugins) => {
3098
3125
  return { databaseURL, branch };
3099
3126
  }
3100
3127
  }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3128
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3129
+ const isBrowser = typeof window !== "undefined";
3130
+ if (isBrowser && !enableBrowser) {
3131
+ throw new Error(
3132
+ "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."
3133
+ );
3134
+ }
3101
3135
  const fetch = getFetchImplementation(options?.fetch);
3102
3136
  const databaseURL = options?.databaseURL || getDatabaseURL();
3103
3137
  const apiKey = options?.apiKey || getAPIKey();
@@ -3110,7 +3144,7 @@ const buildClient = (plugins) => {
3110
3144
  if (!databaseURL) {
3111
3145
  throw new Error("Option databaseURL is required");
3112
3146
  }
3113
- return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID() };
3147
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
3114
3148
  }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
3115
3149
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3116
3150
  if (!branchValue)
@@ -3261,6 +3295,7 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
3261
3295
  exports.addTableColumn = addTableColumn;
3262
3296
  exports.aggregateTable = aggregateTable;
3263
3297
  exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3298
+ exports.branchTransaction = branchTransaction;
3264
3299
  exports.buildClient = buildClient;
3265
3300
  exports.buildWorkerRunner = buildWorkerRunner;
3266
3301
  exports.bulkInsertTableRecords = bulkInsertTableRecords;