@xata.io/client 0.23.5 → 0.24.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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @xata.io/client@0.23.5 add-version /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.24.1 add-version /home/runner/work/client-ts/client-ts/packages/client
3
3
  > node ../../scripts/add-version-file.mjs
4
4
 
@@ -1,13 +1,13 @@
1
1
 
2
- > @xata.io/client@0.23.5 build /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.24.1 build /home/runner/work/client-ts/client-ts/packages/client
3
3
  > rimraf dist && rollup -c
4
4
 
5
5
  
6
6
  src/index.ts → dist/index.cjs...
7
- created dist/index.cjs in 1.8s
7
+ created dist/index.cjs in 1.3s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 1.2s
10
+ created dist/index.mjs in 970ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 8s
13
+ created dist/index.d.ts in 5.9s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.24.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1030](https://github.com/xataio/client-ts/pull/1030) [`eaa774f5`](https://github.com/xataio/client-ts/commit/eaa774f542185ef92448155bcdff331686c4da9f) Thanks [@SferaDev](https://github.com/SferaDev)! - Make `xata` property enumerable
8
+
9
+ ## 0.24.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#1009](https://github.com/xataio/client-ts/pull/1009) [`45aa2207`](https://github.com/xataio/client-ts/commit/45aa220728e98dd716a55a9a307474732a9b2bc1) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `createdAt` and `updatedAt` properties
14
+
15
+ ### Patch Changes
16
+
17
+ - [#1008](https://github.com/xataio/client-ts/pull/1008) [`f28080f0`](https://github.com/xataio/client-ts/commit/f28080f034f02704fe00d64b8f42e1127bde30c7) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `failIfMissing` to delete transactions
18
+
19
+ - [#994](https://github.com/xataio/client-ts/pull/994) [`ac9c0604`](https://github.com/xataio/client-ts/commit/ac9c06042bb85105d9a38624676ce6ea5a27d488) Thanks [@xata-bot](https://github.com/xata-bot)! - Update internal endpoints
20
+
21
+ - [#1015](https://github.com/xataio/client-ts/pull/1015) [`c163b365`](https://github.com/xataio/client-ts/commit/c163b3658f23fb2eaad6243ebebc92624754099a) Thanks [@SferaDev](https://github.com/SferaDev)! - Add `factor` to date boosters
22
+
3
23
  ## 0.23.5
4
24
 
5
25
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -266,7 +266,7 @@ class ApiRequestPool {
266
266
  return __privateGet$8(this, _fetch);
267
267
  }
268
268
  request(url, options) {
269
- const start = new Date();
269
+ const start = /* @__PURE__ */ new Date();
270
270
  const fetch2 = this.getFetch();
271
271
  const runRequest = async (stalled = false) => {
272
272
  const response = await fetch2(url, options);
@@ -276,7 +276,7 @@ class ApiRequestPool {
276
276
  return await runRequest(true);
277
277
  }
278
278
  if (stalled) {
279
- const stalledTime = new Date().getTime() - start.getTime();
279
+ const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
280
280
  console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
281
281
  }
282
282
  return response;
@@ -492,7 +492,7 @@ function defaultOnOpen(response) {
492
492
  }
493
493
  }
494
494
 
495
- const VERSION = "0.23.5";
495
+ const VERSION = "0.24.1";
496
496
 
497
497
  class ErrorWithCause extends Error {
498
498
  constructor(message, options) {
@@ -864,6 +864,12 @@ const putFile = (variables, signal) => dataPlaneFetch({
864
864
  ...variables,
865
865
  signal
866
866
  });
867
+ const deleteFile = (variables, signal) => dataPlaneFetch({
868
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
869
+ method: "delete",
870
+ ...variables,
871
+ signal
872
+ });
867
873
  const getRecord = (variables, signal) => dataPlaneFetch({
868
874
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
869
875
  method: "get",
@@ -908,6 +914,12 @@ const askTable = (variables, signal) => dataPlaneFetch({
908
914
  });
909
915
  const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
910
916
  const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
917
+ const fileAccess = (variables, signal) => dataPlaneFetch({
918
+ url: "/file/{fileId}",
919
+ method: "get",
920
+ ...variables,
921
+ signal
922
+ });
911
923
  const operationsByTag$2 = {
912
924
  branch: {
913
925
  getBranchList,
@@ -967,7 +979,7 @@ const operationsByTag$2 = {
967
979
  deleteRecord,
968
980
  bulkInsertTableRecords
969
981
  },
970
- files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile },
982
+ files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
971
983
  searchAndFilter: {
972
984
  queryTable,
973
985
  searchBranch,
@@ -1898,6 +1910,7 @@ class FilesApi {
1898
1910
  columnName: column,
1899
1911
  fileId
1900
1912
  },
1913
+ // @ts-ignore
1901
1914
  body: file,
1902
1915
  ...this.extraProps
1903
1916
  });
@@ -1969,6 +1982,43 @@ class FilesApi {
1969
1982
  ...this.extraProps
1970
1983
  });
1971
1984
  }
1985
+ deleteFile({
1986
+ workspace,
1987
+ region,
1988
+ database,
1989
+ branch,
1990
+ table,
1991
+ record,
1992
+ column
1993
+ }) {
1994
+ return operationsByTag.files.deleteFile({
1995
+ pathParams: {
1996
+ workspace,
1997
+ region,
1998
+ dbBranchName: `${database}:${branch}`,
1999
+ tableName: table,
2000
+ recordId: record,
2001
+ columnName: column
2002
+ },
2003
+ ...this.extraProps
2004
+ });
2005
+ }
2006
+ fileAccess({
2007
+ workspace,
2008
+ region,
2009
+ fileId,
2010
+ verify
2011
+ }) {
2012
+ return operationsByTag.files.fileAccess({
2013
+ pathParams: {
2014
+ workspace,
2015
+ region,
2016
+ fileId
2017
+ },
2018
+ queryParams: { verify },
2019
+ ...this.extraProps
2020
+ });
2021
+ }
1972
2022
  }
1973
2023
  class SearchAndFilterApi {
1974
2024
  constructor(extraProps) {
@@ -2479,18 +2529,46 @@ class Page {
2479
2529
  this.meta = meta;
2480
2530
  this.records = new RecordArray(this, records);
2481
2531
  }
2532
+ /**
2533
+ * Retrieves the next page of results.
2534
+ * @param size Maximum number of results to be retrieved.
2535
+ * @param offset Number of results to skip when retrieving the results.
2536
+ * @returns The next page or results.
2537
+ */
2482
2538
  async nextPage(size, offset) {
2483
2539
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
2484
2540
  }
2541
+ /**
2542
+ * Retrieves the previous page of results.
2543
+ * @param size Maximum number of results to be retrieved.
2544
+ * @param offset Number of results to skip when retrieving the results.
2545
+ * @returns The previous page or results.
2546
+ */
2485
2547
  async previousPage(size, offset) {
2486
2548
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
2487
2549
  }
2550
+ /**
2551
+ * Retrieves the start page of results.
2552
+ * @param size Maximum number of results to be retrieved.
2553
+ * @param offset Number of results to skip when retrieving the results.
2554
+ * @returns The start page or results.
2555
+ */
2488
2556
  async startPage(size, offset) {
2489
2557
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
2490
2558
  }
2559
+ /**
2560
+ * Retrieves the end page of results.
2561
+ * @param size Maximum number of results to be retrieved.
2562
+ * @param offset Number of results to skip when retrieving the results.
2563
+ * @returns The end page or results.
2564
+ */
2491
2565
  async endPage(size, offset) {
2492
2566
  return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
2493
2567
  }
2568
+ /**
2569
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
2570
+ * @returns Whether or not there will be additional results in the next page of results.
2571
+ */
2494
2572
  hasNextPage() {
2495
2573
  return this.meta.page.more;
2496
2574
  }
@@ -2531,22 +2609,45 @@ const _RecordArray = class extends Array {
2531
2609
  map(callbackfn, thisArg) {
2532
2610
  return this.toArray().map(callbackfn, thisArg);
2533
2611
  }
2612
+ /**
2613
+ * Retrieve next page of records
2614
+ *
2615
+ * @returns A new array of objects
2616
+ */
2534
2617
  async nextPage(size, offset) {
2535
2618
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
2536
2619
  return new _RecordArray(newPage);
2537
2620
  }
2621
+ /**
2622
+ * Retrieve previous page of records
2623
+ *
2624
+ * @returns A new array of objects
2625
+ */
2538
2626
  async previousPage(size, offset) {
2539
2627
  const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
2540
2628
  return new _RecordArray(newPage);
2541
2629
  }
2630
+ /**
2631
+ * Retrieve start page of records
2632
+ *
2633
+ * @returns A new array of objects
2634
+ */
2542
2635
  async startPage(size, offset) {
2543
2636
  const newPage = await __privateGet$6(this, _page).startPage(size, offset);
2544
2637
  return new _RecordArray(newPage);
2545
2638
  }
2639
+ /**
2640
+ * Retrieve end page of records
2641
+ *
2642
+ * @returns A new array of objects
2643
+ */
2546
2644
  async endPage(size, offset) {
2547
2645
  const newPage = await __privateGet$6(this, _page).endPage(size, offset);
2548
2646
  return new _RecordArray(newPage);
2549
2647
  }
2648
+ /**
2649
+ * @returns Boolean indicating if there is a next page
2650
+ */
2550
2651
  hasNextPage() {
2551
2652
  return __privateGet$6(this, _page).meta.page.more;
2552
2653
  }
@@ -2583,6 +2684,7 @@ const _Query = class {
2583
2684
  __privateAdd$5(this, _table$1, void 0);
2584
2685
  __privateAdd$5(this, _repository, void 0);
2585
2686
  __privateAdd$5(this, _data, { filter: {} });
2687
+ // Implements pagination
2586
2688
  this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
2587
2689
  this.records = new RecordArray(this, []);
2588
2690
  __privateSet$5(this, _table$1, table);
@@ -2620,18 +2722,38 @@ const _Query = class {
2620
2722
  const key = JSON.stringify({ columns, filter, sort, pagination });
2621
2723
  return toBase64(key);
2622
2724
  }
2725
+ /**
2726
+ * Builds a new query object representing a logical OR between the given subqueries.
2727
+ * @param queries An array of subqueries.
2728
+ * @returns A new Query object.
2729
+ */
2623
2730
  any(...queries) {
2624
2731
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
2625
2732
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
2626
2733
  }
2734
+ /**
2735
+ * Builds a new query object representing a logical AND between the given subqueries.
2736
+ * @param queries An array of subqueries.
2737
+ * @returns A new Query object.
2738
+ */
2627
2739
  all(...queries) {
2628
2740
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
2629
2741
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
2630
2742
  }
2743
+ /**
2744
+ * Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
2745
+ * @param queries An array of subqueries.
2746
+ * @returns A new Query object.
2747
+ */
2631
2748
  not(...queries) {
2632
2749
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
2633
2750
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
2634
2751
  }
2752
+ /**
2753
+ * Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
2754
+ * @param queries An array of subqueries.
2755
+ * @returns A new Query object.
2756
+ */
2635
2757
  none(...queries) {
2636
2758
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
2637
2759
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
@@ -2654,6 +2776,11 @@ const _Query = class {
2654
2776
  const sort = [...originalSort, { column, direction }];
2655
2777
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
2656
2778
  }
2779
+ /**
2780
+ * Builds a new query specifying the set of columns to be returned in the query response.
2781
+ * @param columns Array of column names to be returned by the query.
2782
+ * @returns A new Query object.
2783
+ */
2657
2784
  select(columns) {
2658
2785
  return new _Query(
2659
2786
  __privateGet$5(this, _repository),
@@ -2666,6 +2793,12 @@ const _Query = class {
2666
2793
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2667
2794
  return __privateGet$5(this, _repository).query(query);
2668
2795
  }
2796
+ /**
2797
+ * Get results in an iterator
2798
+ *
2799
+ * @async
2800
+ * @returns Async interable of results
2801
+ */
2669
2802
  async *[Symbol.asyncIterator]() {
2670
2803
  for await (const [record] of this.getIterator({ batchSize: 1 })) {
2671
2804
  yield record;
@@ -2726,21 +2859,49 @@ const _Query = class {
2726
2859
  );
2727
2860
  return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
2728
2861
  }
2862
+ /**
2863
+ * Builds a new query object adding a cache TTL in milliseconds.
2864
+ * @param ttl The cache TTL in milliseconds.
2865
+ * @returns A new Query object.
2866
+ */
2729
2867
  cache(ttl) {
2730
2868
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
2731
2869
  }
2870
+ /**
2871
+ * Retrieve next page of records
2872
+ *
2873
+ * @returns A new page object.
2874
+ */
2732
2875
  nextPage(size, offset) {
2733
2876
  return this.startPage(size, offset);
2734
2877
  }
2878
+ /**
2879
+ * Retrieve previous page of records
2880
+ *
2881
+ * @returns A new page object
2882
+ */
2735
2883
  previousPage(size, offset) {
2736
2884
  return this.startPage(size, offset);
2737
2885
  }
2886
+ /**
2887
+ * Retrieve start page of records
2888
+ *
2889
+ * @returns A new page object
2890
+ */
2738
2891
  startPage(size, offset) {
2739
2892
  return this.getPaginated({ pagination: { size, offset } });
2740
2893
  }
2894
+ /**
2895
+ * Retrieve last page of records
2896
+ *
2897
+ * @returns A new page object
2898
+ */
2741
2899
  endPage(size, offset) {
2742
2900
  return this.getPaginated({ pagination: { size, offset, before: "end" } });
2743
2901
  }
2902
+ /**
2903
+ * @returns Boolean indicating if there is a next page
2904
+ */
2744
2905
  hasNextPage() {
2745
2906
  return this.meta.page.more;
2746
2907
  }
@@ -3430,7 +3591,7 @@ deleteRecords_fn = async function(recordIds) {
3430
3591
  };
3431
3592
  _setCacheQuery = new WeakSet();
3432
3593
  setCacheQuery_fn = async function(query, meta, records) {
3433
- await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
3594
+ await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
3434
3595
  };
3435
3596
  _getCacheQuery = new WeakSet();
3436
3597
  getCacheQuery_fn = async function(query) {
@@ -3514,6 +3675,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
3514
3675
  }
3515
3676
  }
3516
3677
  const record = { ...data };
3678
+ const serializable = { xata, ...transformObjectLinks(data) };
3679
+ const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
3517
3680
  record.read = function(columns2) {
3518
3681
  return db[table].read(record["id"], columns2);
3519
3682
  };
@@ -3530,14 +3693,15 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
3530
3693
  record.delete = function() {
3531
3694
  return db[table].delete(record["id"]);
3532
3695
  };
3696
+ record.xata = Object.freeze(metadata);
3533
3697
  record.getMetadata = function() {
3534
- return xata;
3698
+ return record.xata;
3535
3699
  };
3536
3700
  record.toSerializable = function() {
3537
- return JSON.parse(JSON.stringify(transformObjectLinks(data)));
3701
+ return JSON.parse(JSON.stringify(serializable));
3538
3702
  };
3539
3703
  record.toString = function() {
3540
- return JSON.stringify(transformObjectLinks(data));
3704
+ return JSON.stringify(transformObjectLinks(serializable));
3541
3705
  };
3542
3706
  for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
3543
3707
  Object.defineProperty(record, prop, { enumerable: false });
@@ -3756,6 +3920,7 @@ search_fn = async function(query, options, pluginOptions) {
3756
3920
  const { tables, fuzziness, highlight, prefix, page } = options ?? {};
3757
3921
  const { records } = await searchBranch({
3758
3922
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3923
+ // @ts-ignore https://github.com/xataio/client-ts/issues/313
3759
3924
  body: { tables, query, fuzziness, prefix, highlight, page },
3760
3925
  ...pluginOptions
3761
3926
  });
@@ -3910,6 +4075,7 @@ const buildClient = (plugins) => {
3910
4075
  fetch,
3911
4076
  apiKey,
3912
4077
  apiUrl: "",
4078
+ // Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
3913
4079
  workspacesApiUrl: (path, params) => {
3914
4080
  const hasBranch = params.dbBranchName ?? params.branch;
3915
4081
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
@@ -4062,6 +4228,7 @@ exports.deleteBranch = deleteBranch;
4062
4228
  exports.deleteColumn = deleteColumn;
4063
4229
  exports.deleteDatabase = deleteDatabase;
4064
4230
  exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
4231
+ exports.deleteFile = deleteFile;
4065
4232
  exports.deleteFileItem = deleteFileItem;
4066
4233
  exports.deleteRecord = deleteRecord;
4067
4234
  exports.deleteTable = deleteTable;
@@ -4073,6 +4240,7 @@ exports.endsWith = endsWith;
4073
4240
  exports.equals = equals;
4074
4241
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
4075
4242
  exports.exists = exists;
4243
+ exports.fileAccess = fileAccess;
4076
4244
  exports.ge = ge;
4077
4245
  exports.getAPIKey = getAPIKey;
4078
4246
  exports.getBranch = getBranch;