@xata.io/client 0.0.0-next.v43b83f3e3d703ba85a9c6790259cc93a43f69e98 → 0.0.0-next.v5cfac065298489e56b1435ad10e8a947642693de

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.29.2 add-version /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.29.3 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.29.2 build /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.29.3 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 966ms
7
+ created dist/index.cjs in 890ms
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 709ms
10
+ created dist/index.mjs in 671ms
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 4.5s
package/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # @xata.io/client
2
2
 
3
- ## 0.0.0-next.v43b83f3e3d703ba85a9c6790259cc93a43f69e98
3
+ ## 0.0.0-next.v5cfac065298489e56b1435ad10e8a947642693de
4
4
 
5
5
  ### Major Changes
6
6
 
7
- - [`ef72862`](https://github.com/xataio/client-ts/commit/ef72862422aa258c01c893f93e9f5a18d89c482b) Thanks [@SferaDev](https://github.com/SferaDev)! - Make XataApiClient to use ES Proxies
7
+ - [`06ae96a`](https://github.com/xataio/client-ts/commit/06ae96adca62334482c6d4f3a402b27fda785441) Thanks [@SferaDev](https://github.com/SferaDev)! - Make XataApiClient to use ES Proxies
8
8
 
9
- - [`e2c656c`](https://github.com/xataio/client-ts/commit/e2c656c44d9cb68b2d822f23f44a516a51627528) Thanks [@SferaDev](https://github.com/SferaDev)! - Version 1.0
9
+ - [`b07ab79`](https://github.com/xataio/client-ts/commit/b07ab79374e566672b249cc7f3af68856adc4acb) Thanks [@SferaDev](https://github.com/SferaDev)! - Version 1.0
10
+
11
+ ## 0.29.3
12
+
13
+ ### Patch Changes
14
+
15
+ - [#1399](https://github.com/xataio/client-ts/pull/1399) [`02053fb`](https://github.com/xataio/client-ts/commit/02053fbb10479b8e9453691f957d3235762555aa) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose `xata.sql.connectionString` helper
16
+
17
+ - [#1398](https://github.com/xataio/client-ts/pull/1398) [`e27cb74`](https://github.com/xataio/client-ts/commit/e27cb74143aa9b6c654713878e5d3776858e5290) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for array response type
10
18
 
11
19
  ## 0.29.2
12
20
 
package/dist/index.cjs CHANGED
@@ -528,7 +528,7 @@ function defaultOnOpen(response) {
528
528
  }
529
529
  }
530
530
 
531
- const VERSION = "0.29.2";
531
+ const VERSION = "0.29.3";
532
532
 
533
533
  class ErrorWithCause extends Error {
534
534
  constructor(message, options) {
@@ -621,15 +621,15 @@ function parseWorkspacesUrlParts(url) {
621
621
  if (!isString(url))
622
622
  return null;
623
623
  const matches = {
624
- production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
625
- staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
626
- dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
627
- local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
624
+ production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh\/db\/([^:]+):?(.*)?/),
625
+ staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
626
+ dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev\/db\/([^:]+):?(.*)?/),
627
+ local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:([^:]+):?(.*)?/)
628
628
  };
629
629
  const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
630
630
  if (!isHostProviderAlias(host) || !match)
631
631
  return null;
632
- return { workspace: match[1], region: match[2], host };
632
+ return { workspace: match[1], region: match[2], database: match[3], branch: match[4], host };
633
633
  }
634
634
 
635
635
  const pool = new ApiRequestPool();
@@ -740,6 +740,8 @@ async function fetch$1({
740
740
  "X-Xata-Client-ID": clientID ?? defaultClientID,
741
741
  "X-Xata-Session-ID": sessionID ?? generateUUID(),
742
742
  "X-Xata-Agent": xataAgent,
743
+ // Force field rename to xata_ internal properties
744
+ "X-Features": compact(["feat-internal-field-rename-api=1", customHeaders?.["X-Features"]]).join(" "),
743
745
  ...customHeaders,
744
746
  ...hostHeader(fullUrl),
745
747
  Authorization: `Bearer ${apiKey}`
@@ -854,6 +856,12 @@ const adaptTable = (variables, signal) => dataPlaneFetch({
854
856
  ...variables,
855
857
  signal
856
858
  });
859
+ const adaptAllTables = (variables, signal) => dataPlaneFetch({
860
+ url: "/db/{dbBranchName}/migrations/adapt",
861
+ method: "post",
862
+ ...variables,
863
+ signal
864
+ });
857
865
  const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
858
866
  const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
859
867
  const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
@@ -1086,6 +1094,7 @@ const operationsByTag$2 = {
1086
1094
  migrations: {
1087
1095
  applyMigration,
1088
1096
  adaptTable,
1097
+ adaptAllTables,
1089
1098
  getBranchMigrationJobStatus,
1090
1099
  getMigrationJobStatus,
1091
1100
  getMigrationHistory,
@@ -1257,6 +1266,8 @@ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
1257
1266
  ...variables,
1258
1267
  signal
1259
1268
  });
1269
+ const getWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "get", ...variables, signal });
1270
+ const updateWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "patch", ...variables, signal });
1260
1271
  const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
1261
1272
  const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
1262
1273
  const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
@@ -1322,6 +1333,8 @@ const operationsByTag$1 = {
1322
1333
  getWorkspace,
1323
1334
  updateWorkspace,
1324
1335
  deleteWorkspace,
1336
+ getWorkspaceSettings,
1337
+ updateWorkspaceSettings,
1325
1338
  getWorkspaceMembersList,
1326
1339
  updateWorkspaceMemberRole,
1327
1340
  removeWorkspaceMember
@@ -2025,8 +2038,8 @@ cleanFilterConstraint_fn = function(column, value) {
2025
2038
  if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2026
2039
  return { $includes: value };
2027
2040
  }
2028
- if (columnType === "link" && isObject(value) && isString(value.id)) {
2029
- return value.id;
2041
+ if (columnType === "link" && isObject(value) && isString(value.xata_id)) {
2042
+ return value.xata_id;
2030
2043
  }
2031
2044
  return value;
2032
2045
  };
@@ -2054,12 +2067,7 @@ const RecordColumnTypes = [
2054
2067
  "json"
2055
2068
  ];
2056
2069
  function isIdentifiable(x) {
2057
- return isObject(x) && isString(x?.id);
2058
- }
2059
- function isXataRecord(x) {
2060
- const record = x;
2061
- const metadata = record?.getMetadata();
2062
- return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
2070
+ return isObject(x) && isString(x?.xata_id);
2063
2071
  }
2064
2072
 
2065
2073
  function isValidExpandedColumn(column) {
@@ -2186,11 +2194,14 @@ class RestRepository extends Query {
2186
2194
  const columns = isValidSelectableColumns(c) ? c : void 0;
2187
2195
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2188
2196
  }
2189
- if (isObject(a) && isString(a.id)) {
2190
- if (a.id === "")
2197
+ if (isObject(a) && isString(a.xata_id)) {
2198
+ if (a.xata_id === "")
2191
2199
  throw new Error("The id can't be empty");
2192
2200
  const columns = isValidSelectableColumns(b) ? b : void 0;
2193
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2201
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
2202
+ createOnly: true,
2203
+ ifVersion
2204
+ });
2194
2205
  }
2195
2206
  if (isObject(a)) {
2196
2207
  const columns = isValidSelectableColumns(b) ? b : void 0;
@@ -2206,9 +2217,9 @@ class RestRepository extends Query {
2206
2217
  if (a.length === 0)
2207
2218
  return [];
2208
2219
  const ids = a.map((item) => extractId(item));
2209
- const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
2220
+ const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
2210
2221
  const dictionary = finalObjects.reduce((acc, object) => {
2211
- acc[object.id] = object;
2222
+ acc[object.xata_id] = object;
2212
2223
  return acc;
2213
2224
  }, {});
2214
2225
  return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
@@ -2270,7 +2281,7 @@ class RestRepository extends Query {
2270
2281
  if (Array.isArray(a)) {
2271
2282
  if (a.length === 0)
2272
2283
  return [];
2273
- const existing = await this.read(a, ["id"]);
2284
+ const existing = await this.read(a, ["xata_id"]);
2274
2285
  const updates = a.filter((_item, index) => existing[index] !== null);
2275
2286
  await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2276
2287
  ifVersion,
@@ -2285,9 +2296,9 @@ class RestRepository extends Query {
2285
2296
  const columns = isValidSelectableColumns(c) ? c : void 0;
2286
2297
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2287
2298
  }
2288
- if (isObject(a) && isString(a.id)) {
2299
+ if (isObject(a) && isString(a.xata_id)) {
2289
2300
  const columns = isValidSelectableColumns(b) ? b : void 0;
2290
- return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2301
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
2291
2302
  }
2292
2303
  } catch (error) {
2293
2304
  if (error.status === 422)
@@ -2336,16 +2347,16 @@ class RestRepository extends Query {
2336
2347
  const columns = isValidSelectableColumns(c) ? c : void 0;
2337
2348
  return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2338
2349
  }
2339
- if (isObject(a) && isString(a.id)) {
2340
- if (a.id === "")
2350
+ if (isObject(a) && isString(a.xata_id)) {
2351
+ if (a.xata_id === "")
2341
2352
  throw new Error("The id can't be empty");
2342
2353
  const columns = isValidSelectableColumns(c) ? c : void 0;
2343
- return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2354
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
2344
2355
  }
2345
2356
  if (!isDefined(a) && isObject(b)) {
2346
2357
  return await this.create(b, c);
2347
2358
  }
2348
- if (isObject(a) && !isDefined(a.id)) {
2359
+ if (isObject(a) && !isDefined(a.xata_id)) {
2349
2360
  return await this.create(a, b);
2350
2361
  }
2351
2362
  throw new Error("Invalid arguments for createOrUpdate method");
@@ -2368,16 +2379,19 @@ class RestRepository extends Query {
2368
2379
  const columns = isValidSelectableColumns(c) ? c : void 0;
2369
2380
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2370
2381
  }
2371
- if (isObject(a) && isString(a.id)) {
2372
- if (a.id === "")
2382
+ if (isObject(a) && isString(a.xata_id)) {
2383
+ if (a.xata_id === "")
2373
2384
  throw new Error("The id can't be empty");
2374
2385
  const columns = isValidSelectableColumns(c) ? c : void 0;
2375
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2386
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
2387
+ createOnly: false,
2388
+ ifVersion
2389
+ });
2376
2390
  }
2377
2391
  if (!isDefined(a) && isObject(b)) {
2378
2392
  return await this.create(b, c);
2379
2393
  }
2380
- if (isObject(a) && !isDefined(a.id)) {
2394
+ if (isObject(a) && !isDefined(a.xata_id)) {
2381
2395
  return await this.create(a, b);
2382
2396
  }
2383
2397
  throw new Error("Invalid arguments for createOrReplace method");
@@ -2391,8 +2405,8 @@ class RestRepository extends Query {
2391
2405
  const ids = a.map((o) => {
2392
2406
  if (isString(o))
2393
2407
  return o;
2394
- if (isString(o.id))
2395
- return o.id;
2408
+ if (isString(o.xata_id))
2409
+ return o.xata_id;
2396
2410
  throw new Error("Invalid arguments for delete method");
2397
2411
  });
2398
2412
  const columns = isValidSelectableColumns(b) ? b : ["*"];
@@ -2403,8 +2417,8 @@ class RestRepository extends Query {
2403
2417
  if (isString(a)) {
2404
2418
  return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
2405
2419
  }
2406
- if (isObject(a) && isString(a.id)) {
2407
- return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
2420
+ if (isObject(a) && isString(a.xata_id)) {
2421
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.xata_id, b);
2408
2422
  }
2409
2423
  throw new Error("Invalid arguments for delete method");
2410
2424
  });
@@ -2666,7 +2680,7 @@ _updateRecordWithID = new WeakSet();
2666
2680
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2667
2681
  if (!recordId)
2668
2682
  return null;
2669
- const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2683
+ const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2670
2684
  try {
2671
2685
  const response = await updateRecordWithID({
2672
2686
  pathParams: {
@@ -2691,9 +2705,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2691
2705
  };
2692
2706
  _updateRecords = new WeakSet();
2693
2707
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2694
- const operations = await promiseMap(objects, async ({ id, ...object }) => {
2708
+ const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
2695
2709
  const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2696
- return { update: { table: __privateGet$2(this, _table), id, ifVersion, upsert, fields } };
2710
+ return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
2697
2711
  });
2698
2712
  const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2699
2713
  const ids = [];
@@ -2798,12 +2812,12 @@ transformObjectToApi_fn = async function(object) {
2798
2812
  throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
2799
2813
  const result = {};
2800
2814
  for (const [key, value] of Object.entries(object)) {
2801
- if (key === "xata")
2815
+ if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
2802
2816
  continue;
2803
2817
  const type = schema.columns.find((column) => column.name === key)?.type;
2804
2818
  switch (type) {
2805
2819
  case "link": {
2806
- result[key] = isIdentifiable(value) ? value.id : value;
2820
+ result[key] = isIdentifiable(value) ? value.xata_id : value;
2807
2821
  break;
2808
2822
  }
2809
2823
  case "datetime": {
@@ -2827,8 +2841,7 @@ transformObjectToApi_fn = async function(object) {
2827
2841
  };
2828
2842
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2829
2843
  const data = {};
2830
- const { xata, ...rest } = object ?? {};
2831
- Object.assign(data, rest);
2844
+ Object.assign(data, { ...object });
2832
2845
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2833
2846
  if (!columns)
2834
2847
  console.error(`Table ${table} not found in schema`);
@@ -2891,28 +2904,21 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2891
2904
  }
2892
2905
  }
2893
2906
  const record = { ...data };
2894
- const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2895
2907
  record.read = function(columns2) {
2896
- return db[table].read(record["id"], columns2);
2908
+ return db[table].read(record["xata_id"], columns2);
2897
2909
  };
2898
2910
  record.update = function(data2, b, c) {
2899
2911
  const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2900
2912
  const ifVersion = parseIfVersion(b, c);
2901
- return db[table].update(record["id"], data2, columns2, { ifVersion });
2913
+ return db[table].update(record["xata_id"], data2, columns2, { ifVersion });
2902
2914
  };
2903
2915
  record.replace = function(data2, b, c) {
2904
2916
  const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2905
2917
  const ifVersion = parseIfVersion(b, c);
2906
- return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
2918
+ return db[table].createOrReplace(record["xata_id"], data2, columns2, { ifVersion });
2907
2919
  };
2908
2920
  record.delete = function() {
2909
- return db[table].delete(record["id"]);
2910
- };
2911
- if (metadata !== void 0) {
2912
- record.xata = Object.freeze(metadata);
2913
- }
2914
- record.getMetadata = function() {
2915
- return record.xata;
2921
+ return db[table].delete(record["xata_id"]);
2916
2922
  };
2917
2923
  record.toSerializable = function() {
2918
2924
  return JSON.parse(JSON.stringify(record));
@@ -2920,7 +2926,7 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2920
2926
  record.toString = function() {
2921
2927
  return JSON.stringify(record);
2922
2928
  };
2923
- for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
2929
+ for (const prop of ["read", "update", "replace", "delete", "toSerializable", "toString"]) {
2924
2930
  Object.defineProperty(record, prop, { enumerable: false });
2925
2931
  }
2926
2932
  Object.freeze(record);
@@ -2929,8 +2935,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2929
2935
  function extractId(value) {
2930
2936
  if (isString(value))
2931
2937
  return value;
2932
- if (isObject(value) && isString(value.id))
2933
- return value.id;
2938
+ if (isObject(value) && isString(value.xata_id))
2939
+ return value.xata_id;
2934
2940
  return void 0;
2935
2941
  }
2936
2942
  function isValidColumn(columns, column) {
@@ -3118,7 +3124,7 @@ class SearchPlugin extends XataPlugin {
3118
3124
  return {
3119
3125
  totalCount,
3120
3126
  records: records.map((record) => {
3121
- const { table = "orphan" } = record.xata;
3127
+ const table = record.xata_table;
3122
3128
  return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
3123
3129
  })
3124
3130
  };
@@ -3126,7 +3132,7 @@ class SearchPlugin extends XataPlugin {
3126
3132
  byTable: async (query, options = {}) => {
3127
3133
  const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3128
3134
  const records = rawRecords.reduce((acc, record) => {
3129
- const { table = "orphan" } = record.xata;
3135
+ const table = record.xata_table;
3130
3136
  const items = acc[table] ?? [];
3131
3137
  const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
3132
3138
  return { ...acc, [table]: [...items, item] };
@@ -3200,19 +3206,19 @@ function prepareParams(param1, param2) {
3200
3206
  return { statement, params: param2?.map((value) => prepareValue(value)) };
3201
3207
  }
3202
3208
  if (isObject(param1)) {
3203
- const { statement, params, consistency } = param1;
3204
- return { statement, params: params?.map((value) => prepareValue(value)), consistency };
3209
+ const { statement, params, consistency, responseType } = param1;
3210
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency, responseType };
3205
3211
  }
3206
3212
  throw new Error("Invalid query");
3207
3213
  }
3208
3214
 
3209
3215
  class SQLPlugin extends XataPlugin {
3210
3216
  build(pluginOptions) {
3211
- return async (query, ...parameters) => {
3217
+ const sqlFunction = async (query, ...parameters) => {
3212
3218
  if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
3213
3219
  throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
3214
3220
  }
3215
- const { statement, params, consistency } = prepareParams(query, parameters);
3221
+ const { statement, params, consistency, responseType } = prepareParams(query, parameters);
3216
3222
  const {
3217
3223
  records,
3218
3224
  rows,
@@ -3220,11 +3226,13 @@ class SQLPlugin extends XataPlugin {
3220
3226
  columns = []
3221
3227
  } = await sqlQuery({
3222
3228
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3223
- body: { statement, params, consistency },
3229
+ body: { statement, params, consistency, responseType },
3224
3230
  ...pluginOptions
3225
3231
  });
3226
3232
  return { records, rows, warning, columns };
3227
3233
  };
3234
+ sqlFunction.connectionString = buildConnectionString(pluginOptions);
3235
+ return sqlFunction;
3228
3236
  }
3229
3237
  }
3230
3238
  function isTemplateStringsArray(strings) {
@@ -3233,6 +3241,33 @@ function isTemplateStringsArray(strings) {
3233
3241
  function isParamsObject(params) {
3234
3242
  return isObject(params) && "statement" in params;
3235
3243
  }
3244
+ function buildDomain(host, region) {
3245
+ switch (host) {
3246
+ case "production":
3247
+ return `${region}.sql.xata.sh`;
3248
+ case "staging":
3249
+ return `${region}.sql.staging-xata.dev`;
3250
+ case "dev":
3251
+ return `${region}.sql.dev-xata.dev`;
3252
+ case "local":
3253
+ return "localhost:7654";
3254
+ default:
3255
+ throw new Error("Invalid host provider");
3256
+ }
3257
+ }
3258
+ function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
3259
+ const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
3260
+ const parts = parseWorkspacesUrlParts(url);
3261
+ if (!parts)
3262
+ throw new Error("Invalid workspaces URL");
3263
+ const { workspace: workspaceSlug, region, database, host } = parts;
3264
+ const domain = buildDomain(host, region);
3265
+ const workspace = workspaceSlug.split("-").pop();
3266
+ if (!workspace || !region || !database || !apiKey || !branch) {
3267
+ throw new Error("Unable to build xata connection string");
3268
+ }
3269
+ return `postgresql://${workspace}:${apiKey}@${domain}/${database}:${branch}?sslmode=require`;
3270
+ }
3236
3271
 
3237
3272
  class TransactionPlugin extends XataPlugin {
3238
3273
  build(pluginOptions) {
@@ -3283,7 +3318,8 @@ const buildClient = (plugins) => {
3283
3318
  const pluginOptions = {
3284
3319
  ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3285
3320
  host: safeOptions.host,
3286
- tables
3321
+ tables,
3322
+ branch: safeOptions.branch
3287
3323
  };
3288
3324
  const db = new SchemaPlugin().build(pluginOptions);
3289
3325
  const search = new SearchPlugin(db).build(pluginOptions);
@@ -3490,6 +3526,7 @@ exports.XataError = XataError;
3490
3526
  exports.XataFile = XataFile;
3491
3527
  exports.XataPlugin = XataPlugin;
3492
3528
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
3529
+ exports.adaptAllTables = adaptAllTables;
3493
3530
  exports.adaptTable = adaptTable;
3494
3531
  exports.addGitBranchesEntry = addGitBranchesEntry;
3495
3532
  exports.addTableColumn = addTableColumn;
@@ -3574,6 +3611,7 @@ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
3574
3611
  exports.getUserOAuthClients = getUserOAuthClients;
3575
3612
  exports.getWorkspace = getWorkspace;
3576
3613
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
3614
+ exports.getWorkspaceSettings = getWorkspaceSettings;
3577
3615
  exports.getWorkspacesList = getWorkspacesList;
3578
3616
  exports.grantAuthorizationCode = grantAuthorizationCode;
3579
3617
  exports.greaterEquals = greaterEquals;
@@ -3598,7 +3636,6 @@ exports.isIdentifiable = isIdentifiable;
3598
3636
  exports.isNot = isNot;
3599
3637
  exports.isValidExpandedColumn = isValidExpandedColumn;
3600
3638
  exports.isValidSelectableColumns = isValidSelectableColumns;
3601
- exports.isXataRecord = isXataRecord;
3602
3639
  exports.le = le;
3603
3640
  exports.lessEquals = lessEquals;
3604
3641
  exports.lessThan = lessThan;
@@ -3648,6 +3685,7 @@ exports.updateUser = updateUser;
3648
3685
  exports.updateWorkspace = updateWorkspace;
3649
3686
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
3650
3687
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
3688
+ exports.updateWorkspaceSettings = updateWorkspaceSettings;
3651
3689
  exports.upsertRecordWithID = upsertRecordWithID;
3652
3690
  exports.vectorSearchTable = vectorSearchTable;
3653
3691
  //# sourceMappingURL=index.cjs.map