@xata.io/client 0.21.1 → 0.21.3

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,19 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.21.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#792](https://github.com/xataio/client-ts/pull/792) [`6c96da45`](https://github.com/xataio/client-ts/commit/6c96da4533500ec236547f47310e99461d5457e8) Thanks [@SferaDev](https://github.com/SferaDev)! - Update workers return type helper
8
+
9
+ ## 0.21.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#787](https://github.com/xataio/client-ts/pull/787) [`93f5beed`](https://github.com/xataio/client-ts/commit/93f5beed77785b03409c614f5e2c3eca4c69c574) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose consistency options
14
+
15
+ - [#784](https://github.com/xataio/client-ts/pull/784) [`cbe0609e`](https://github.com/xataio/client-ts/commit/cbe0609ec9d6650030efbda712a1eb243287525d) Thanks [@SferaDev](https://github.com/SferaDev)! - Update resolveBranch behaviour
16
+
3
17
  ## 0.21.1
4
18
 
5
19
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -297,7 +297,14 @@ enqueue_fn = function(task) {
297
297
  return promise;
298
298
  };
299
299
 
300
- const VERSION = "0.21.1";
300
+ function generateUUID() {
301
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
302
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
303
+ return v.toString(16);
304
+ });
305
+ }
306
+
307
+ const VERSION = "0.21.3";
301
308
 
302
309
  class ErrorWithCause extends Error {
303
310
  constructor(message, options) {
@@ -308,7 +315,7 @@ class FetcherError extends ErrorWithCause {
308
315
  constructor(status, data, requestId) {
309
316
  super(getMessage(data));
310
317
  this.status = status;
311
- this.errors = isBulkError(data) ? data.errors : void 0;
318
+ this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
312
319
  this.requestId = requestId;
313
320
  if (data instanceof Error) {
314
321
  this.stack = data.stack;
@@ -373,11 +380,12 @@ function hostHeader(url) {
373
380
  const { groups } = pattern.exec(url) ?? {};
374
381
  return groups?.host ? { Host: groups.host } : {};
375
382
  }
383
+ const defaultClientID = generateUUID();
376
384
  async function fetch$1({
377
385
  url: path,
378
386
  method,
379
387
  body,
380
- headers,
388
+ headers: customHeaders,
381
389
  pathParams,
382
390
  queryParams,
383
391
  fetchImpl,
@@ -408,20 +416,21 @@ async function fetch$1({
408
416
  ["version", VERSION],
409
417
  isDefined(clientName) ? ["service", clientName] : void 0
410
418
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
419
+ const headers = {
420
+ "Accept-Encoding": "identity",
421
+ "Content-Type": "application/json",
422
+ "X-Xata-Client-ID": clientID ?? defaultClientID,
423
+ "X-Xata-Session-ID": sessionID ?? generateUUID(),
424
+ "X-Xata-Agent": xataAgent,
425
+ ...customHeaders,
426
+ ...hostHeader(fullUrl),
427
+ Authorization: `Bearer ${apiKey}`
428
+ };
411
429
  const response = await pool.request(url, {
412
430
  ...fetchOptions,
413
431
  method: method.toUpperCase(),
414
432
  body: body ? JSON.stringify(body) : void 0,
415
- headers: {
416
- "Accept-Encoding": "identity",
417
- "Content-Type": "application/json",
418
- "X-Xata-Client-ID": clientID ?? "",
419
- "X-Xata-Session-ID": sessionID ?? "",
420
- "X-Xata-Agent": xataAgent,
421
- ...headers,
422
- ...hostHeader(fullUrl),
423
- Authorization: `Bearer ${apiKey}`
424
- },
433
+ headers,
425
434
  signal
426
435
  });
427
436
  const { host, protocol } = parseUrl(response.url);
@@ -848,12 +857,12 @@ function parseProviderString(provider = "production") {
848
857
  function parseWorkspacesUrlParts(url) {
849
858
  if (!isString(url))
850
859
  return null;
851
- const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
852
- const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
860
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
861
+ const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
853
862
  const match = url.match(regex) || url.match(regexStaging);
854
863
  if (!match)
855
864
  return null;
856
- return { workspace: match[1], region: match[2] ?? "eu-west-1" };
865
+ return { workspace: match[1], region: match[2] };
857
866
  }
858
867
 
859
868
  var __accessCheck$7 = (obj, member, msg) => {
@@ -882,6 +891,7 @@ class XataApiClient {
882
891
  const provider = options.host ?? "production";
883
892
  const apiKey = options.apiKey ?? getAPIKey();
884
893
  const trace = options.trace ?? defaultTrace;
894
+ const clientID = generateUUID();
885
895
  if (!apiKey) {
886
896
  throw new Error("Could not resolve a valid apiKey");
887
897
  }
@@ -891,7 +901,8 @@ class XataApiClient {
891
901
  fetchImpl: getFetchImplementation(options.fetch),
892
902
  apiKey,
893
903
  trace,
894
- clientName: options.clientName
904
+ clientName: options.clientName,
905
+ clientID
895
906
  });
896
907
  }
897
908
  get user() {
@@ -1896,13 +1907,6 @@ class XataApiPlugin {
1896
1907
  class XataPlugin {
1897
1908
  }
1898
1909
 
1899
- function generateUUID() {
1900
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1901
- const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1902
- return v.toString(16);
1903
- });
1904
- }
1905
-
1906
1910
  function cleanFilter(filter) {
1907
1911
  if (!filter)
1908
1912
  return void 0;
@@ -2050,6 +2054,7 @@ const _Query = class {
2050
2054
  __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
2051
2055
  __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
2052
2056
  __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2057
+ __privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
2053
2058
  __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
2054
2059
  __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2055
2060
  __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
@@ -2610,7 +2615,8 @@ class RestRepository extends Query {
2610
2615
  filter: cleanFilter(data.filter),
2611
2616
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2612
2617
  page: data.pagination,
2613
- columns: data.columns ?? ["*"]
2618
+ columns: data.columns ?? ["*"],
2619
+ consistency: data.consistency
2614
2620
  },
2615
2621
  fetchOptions: data.fetchOptions,
2616
2622
  ...fetchProps
@@ -2638,6 +2644,7 @@ class RestRepository extends Query {
2638
2644
  filter: cleanFilter(data.filter),
2639
2645
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2640
2646
  columns: data.columns,
2647
+ consistency: data.consistency,
2641
2648
  page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2642
2649
  summaries,
2643
2650
  summariesFilter
@@ -3200,12 +3207,8 @@ const isBranchStrategyBuilder = (strategy) => {
3200
3207
 
3201
3208
  async function getCurrentBranchName(options) {
3202
3209
  const { branch, envBranch } = getEnvironment();
3203
- if (branch) {
3204
- const details = await getDatabaseBranch(branch, options);
3205
- if (details)
3206
- return branch;
3207
- console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
3208
- }
3210
+ if (branch)
3211
+ return branch;
3209
3212
  const gitBranch = envBranch || await getGitBranch();
3210
3213
  return resolveXataBranch(gitBranch, options);
3211
3214
  }
@@ -3237,7 +3240,8 @@ async function resolveXataBranch(gitBranch, options) {
3237
3240
  workspacesApiUrl: `${protocol}//${host}`,
3238
3241
  pathParams: { dbName, workspace, region },
3239
3242
  queryParams: { gitBranch, fallbackBranch },
3240
- trace: defaultTrace
3243
+ trace: defaultTrace,
3244
+ clientName: options?.clientName
3241
3245
  });
3242
3246
  return branch;
3243
3247
  }
@@ -3357,7 +3361,12 @@ const buildClient = (plugins) => {
3357
3361
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3358
3362
  const trace = options?.trace ?? defaultTrace;
3359
3363
  const clientName = options?.clientName;
3360
- const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
3364
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3365
+ apiKey,
3366
+ databaseURL,
3367
+ fetchImpl: options?.fetch,
3368
+ clientName: options?.clientName
3369
+ });
3361
3370
  if (!apiKey) {
3362
3371
  throw new Error("Option apiKey is required");
3363
3372
  }
@@ -3479,7 +3488,7 @@ const deserialize = (json) => {
3479
3488
  };
3480
3489
 
3481
3490
  function buildWorkerRunner(config) {
3482
- return function xataWorker(name, _worker) {
3491
+ return function xataWorker(name, worker) {
3483
3492
  return async (...args) => {
3484
3493
  const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
3485
3494
  const result = await fetch(url, {