@xata.io/client 0.25.3 → 0.26.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.25.3 add-version /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.26.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.25.3 build /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.26.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 980ms
7
+ created dist/index.cjs in 1.2s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 678ms
10
+ created dist/index.mjs in 840ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 5.2s
13
+ created dist/index.d.ts in 5.8s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.26.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1139](https://github.com/xataio/client-ts/pull/1139) [`922e6e54`](https://github.com/xataio/client-ts/commit/922e6e54e8b31641770a36b6b4ff8f4fa65d304d) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix scenario with merging existing transformations
8
+
9
+ - [#1140](https://github.com/xataio/client-ts/pull/1140) [`13f6f3e4`](https://github.com/xataio/client-ts/commit/13f6f3e4b1a2f925d50a5380b62ef1057f5c3893) Thanks [@SferaDev](https://github.com/SferaDev)! - Add metadata url for transformations
10
+
11
+ - [#1136](https://github.com/xataio/client-ts/pull/1136) [`f02fc165`](https://github.com/xataio/client-ts/commit/f02fc165bf6558e4377eb9f8e1d0f4222f004c70) Thanks [@SferaDev](https://github.com/SferaDev)! - Fixes for Blob files in binary APIs
12
+
13
+ ## 0.26.0
14
+
15
+ ### Minor Changes
16
+
17
+ - [#893](https://github.com/xataio/client-ts/pull/893) [`6ec862f8`](https://github.com/xataio/client-ts/commit/6ec862f8f799eb692f62be79dd0b613b83a34780) Thanks [@SferaDev](https://github.com/SferaDev)! - Add SQL plugin
18
+
19
+ ### Patch Changes
20
+
21
+ - [#1134](https://github.com/xataio/client-ts/pull/1134) [`0c0149ad`](https://github.com/xataio/client-ts/commit/0c0149ad1ee3f7c0fe9d31030552b022c907edb0) Thanks [@SferaDev](https://github.com/SferaDev)! - Make transformImage accept object-shaped parameters
22
+
3
23
  ## 0.25.3
4
24
 
5
25
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -33,7 +33,7 @@ function compactObject(obj) {
33
33
  return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
34
34
  }
35
35
  function isObject(value) {
36
- return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
36
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof Blob);
37
37
  }
38
38
  function isDefined(value) {
39
39
  return value !== null && value !== void 0;
@@ -529,7 +529,7 @@ function defaultOnOpen(response) {
529
529
  }
530
530
  }
531
531
 
532
- const VERSION = "0.25.3";
532
+ const VERSION = "0.26.1";
533
533
 
534
534
  var __defProp$7 = Object.defineProperty;
535
535
  var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -615,11 +615,14 @@ function hostHeader(url) {
615
615
  const { groups } = pattern.exec(url) ?? {};
616
616
  return groups?.host ? { Host: groups.host } : {};
617
617
  }
618
- function parseBody(body, headers) {
618
+ async function parseBody(body, headers) {
619
619
  if (!isDefined(body))
620
620
  return void 0;
621
+ if (body instanceof Blob || typeof body.text === "function") {
622
+ return body;
623
+ }
621
624
  const { "Content-Type": contentType } = headers ?? {};
622
- if (String(contentType).toLowerCase() === "application/json") {
625
+ if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
623
626
  return JSON.stringify(body);
624
627
  }
625
628
  return body;
@@ -676,7 +679,7 @@ async function fetch$1({
676
679
  const response = await pool.request(url, {
677
680
  ...fetchOptions,
678
681
  method: method.toUpperCase(),
679
- body: parseBody(body, headers),
682
+ body: await parseBody(body, headers),
680
683
  headers,
681
684
  signal
682
685
  });
@@ -2632,7 +2635,9 @@ class FilesPlugin extends XataPlugin {
2632
2635
  },
2633
2636
  upload: async (location, file) => {
2634
2637
  const { table, record, column, fileId = "" } = location ?? {};
2638
+ const contentType = getContentType(file);
2635
2639
  return await putFileItem({
2640
+ ...pluginOptions,
2636
2641
  pathParams: {
2637
2642
  workspace: "{workspaceId}",
2638
2643
  dbBranchName: "{dbBranch}",
@@ -2643,7 +2648,7 @@ class FilesPlugin extends XataPlugin {
2643
2648
  fileId
2644
2649
  },
2645
2650
  body: file,
2646
- ...pluginOptions
2651
+ headers: { "Content-Type": contentType }
2647
2652
  });
2648
2653
  },
2649
2654
  delete: async (location) => {
@@ -2664,6 +2669,19 @@ class FilesPlugin extends XataPlugin {
2664
2669
  };
2665
2670
  }
2666
2671
  }
2672
+ function getContentType(file) {
2673
+ if (typeof file === "string") {
2674
+ return "text/plain";
2675
+ }
2676
+ if (file instanceof Blob) {
2677
+ return file.type;
2678
+ }
2679
+ try {
2680
+ return file.type;
2681
+ } catch (e) {
2682
+ }
2683
+ return "application/octet-stream";
2684
+ }
2667
2685
 
2668
2686
  function buildTransformString(transformations) {
2669
2687
  return transformations.flatMap(
@@ -2680,12 +2698,17 @@ function buildTransformString(transformations) {
2680
2698
  })
2681
2699
  ).join(",");
2682
2700
  }
2683
- function transformImage(url, transformations) {
2701
+ function transformImage(url, ...transformations) {
2684
2702
  if (!isDefined(url))
2685
2703
  return void 0;
2686
- const transformationsString = buildTransformString(transformations);
2704
+ const newTransformations = buildTransformString(transformations);
2687
2705
  const { hostname, pathname, search } = new URL(url);
2688
- return `https://${hostname}/transform/${transformationsString}${pathname}${search}`;
2706
+ const pathParts = pathname.split("/");
2707
+ const transformIndex = pathParts.findIndex((part) => part === "transform");
2708
+ const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
2709
+ const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
2710
+ const path = pathParts.join("/");
2711
+ return `https://${hostname}${transform}${path}${search}`;
2689
2712
  }
2690
2713
 
2691
2714
  var __defProp$6 = Object.defineProperty;
@@ -2736,16 +2759,16 @@ class XataFile {
2736
2759
  * Attributes of this file.
2737
2760
  */
2738
2761
  __publicField$6(this, "attributes");
2739
- this.name = file.name;
2762
+ this.name = file.name || "";
2740
2763
  this.mediaType = file.mediaType || "application/octet-stream";
2741
2764
  this.base64Content = file.base64Content;
2742
- this.enablePublicUrl = file.enablePublicUrl;
2743
- this.signedUrlTimeout = file.signedUrlTimeout;
2744
- this.size = file.size;
2745
- this.version = file.version;
2746
- this.url = file.url;
2765
+ this.enablePublicUrl = file.enablePublicUrl ?? false;
2766
+ this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
2767
+ this.size = file.size ?? 0;
2768
+ this.version = file.version ?? 1;
2769
+ this.url = file.url || "";
2747
2770
  this.signedUrl = file.signedUrl;
2748
- this.attributes = file.attributes;
2771
+ this.attributes = file.attributes || {};
2749
2772
  }
2750
2773
  static fromBuffer(buffer, options = {}) {
2751
2774
  const base64Content = buffer.toString("base64");
@@ -2797,8 +2820,12 @@ class XataFile {
2797
2820
  if (!this.base64Content) {
2798
2821
  throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
2799
2822
  }
2800
- const arrayBuffer = this.toArrayBuffer();
2801
- return new Blob([arrayBuffer], { type: this.mediaType });
2823
+ const binary = atob(this.base64Content);
2824
+ const uint8Array = new Uint8Array(binary.length);
2825
+ for (let i = 0; i < binary.length; i++) {
2826
+ uint8Array[i] = binary.charCodeAt(i);
2827
+ }
2828
+ return new Blob([uint8Array], { type: this.mediaType });
2802
2829
  }
2803
2830
  static fromString(string, options = {}) {
2804
2831
  const base64Content = btoa(string);
@@ -2821,8 +2848,9 @@ class XataFile {
2821
2848
  }
2822
2849
  transform(...options) {
2823
2850
  return {
2824
- url: transformImage(this.url, options),
2825
- signedUrl: transformImage(this.signedUrl, options)
2851
+ url: transformImage(this.url, ...options),
2852
+ signedUrl: transformImage(this.signedUrl, ...options),
2853
+ metadataUrl: transformImage(this.url, ...options, { format: "json" })
2826
2854
  };
2827
2855
  }
2828
2856
  }
@@ -4405,6 +4433,78 @@ getSchemaTables_fn = async function(pluginOptions) {
4405
4433
  return schema.tables;
4406
4434
  };
4407
4435
 
4436
+ function escapeElement(elementRepresentation) {
4437
+ const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
4438
+ return '"' + escaped + '"';
4439
+ }
4440
+ function arrayString(val) {
4441
+ let result = "{";
4442
+ for (let i = 0; i < val.length; i++) {
4443
+ if (i > 0) {
4444
+ result = result + ",";
4445
+ }
4446
+ if (val[i] === null || typeof val[i] === "undefined") {
4447
+ result = result + "NULL";
4448
+ } else if (Array.isArray(val[i])) {
4449
+ result = result + arrayString(val[i]);
4450
+ } else if (val[i] instanceof Buffer) {
4451
+ result += "\\\\x" + val[i].toString("hex");
4452
+ } else {
4453
+ result += escapeElement(prepareValue(val[i]));
4454
+ }
4455
+ }
4456
+ result = result + "}";
4457
+ return result;
4458
+ }
4459
+ function prepareValue(value) {
4460
+ if (!isDefined(value))
4461
+ return null;
4462
+ if (value instanceof Date) {
4463
+ return value.toISOString();
4464
+ }
4465
+ if (Array.isArray(value)) {
4466
+ return arrayString(value);
4467
+ }
4468
+ if (isObject(value)) {
4469
+ return JSON.stringify(value);
4470
+ }
4471
+ try {
4472
+ return value.toString();
4473
+ } catch (e) {
4474
+ return value;
4475
+ }
4476
+ }
4477
+ function prepareParams(param1, param2) {
4478
+ if (isString(param1)) {
4479
+ return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
4480
+ }
4481
+ if (isStringArray(param1)) {
4482
+ const statement = param1.reduce((acc, curr, index) => {
4483
+ return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
4484
+ }, "");
4485
+ return { statement, params: param2?.map((value) => prepareValue(value)) };
4486
+ }
4487
+ if (isObject(param1)) {
4488
+ const { statement, params, consistency } = param1;
4489
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency };
4490
+ }
4491
+ throw new Error("Invalid query");
4492
+ }
4493
+
4494
+ class SQLPlugin extends XataPlugin {
4495
+ build(pluginOptions) {
4496
+ return async (param1, ...param2) => {
4497
+ const { statement, params, consistency } = prepareParams(param1, param2);
4498
+ const { records, warning } = await sqlQuery({
4499
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4500
+ body: { statement, params, consistency },
4501
+ ...pluginOptions
4502
+ });
4503
+ return { records, warning };
4504
+ };
4505
+ }
4506
+ }
4507
+
4408
4508
  class TransactionPlugin extends XataPlugin {
4409
4509
  build(pluginOptions) {
4410
4510
  return {
@@ -4458,6 +4558,7 @@ const buildClient = (plugins) => {
4458
4558
  __publicField$2(this, "db");
4459
4559
  __publicField$2(this, "search");
4460
4560
  __publicField$2(this, "transactions");
4561
+ __publicField$2(this, "sql");
4461
4562
  __publicField$2(this, "files");
4462
4563
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
4463
4564
  __privateSet(this, _options, safeOptions);
@@ -4469,10 +4570,12 @@ const buildClient = (plugins) => {
4469
4570
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
4470
4571
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
4471
4572
  const transactions = new TransactionPlugin().build(pluginOptions);
4573
+ const sql = new SQLPlugin().build(pluginOptions);
4472
4574
  const files = new FilesPlugin().build(pluginOptions);
4473
4575
  this.db = db;
4474
4576
  this.search = search;
4475
4577
  this.transactions = transactions;
4578
+ this.sql = sql;
4476
4579
  this.files = files;
4477
4580
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
4478
4581
  if (namespace === void 0)
@@ -4686,6 +4789,7 @@ exports.RecordArray = RecordArray;
4686
4789
  exports.RecordColumnTypes = RecordColumnTypes;
4687
4790
  exports.Repository = Repository;
4688
4791
  exports.RestRepository = RestRepository;
4792
+ exports.SQLPlugin = SQLPlugin;
4689
4793
  exports.SchemaPlugin = SchemaPlugin;
4690
4794
  exports.SearchPlugin = SearchPlugin;
4691
4795
  exports.Serializer = Serializer;