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

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/dist/index.mjs CHANGED
@@ -526,7 +526,7 @@ function defaultOnOpen(response) {
526
526
  }
527
527
  }
528
528
 
529
- const VERSION = "0.29.2";
529
+ const VERSION = "0.29.3";
530
530
 
531
531
  class ErrorWithCause extends Error {
532
532
  constructor(message, options) {
@@ -619,15 +619,15 @@ function parseWorkspacesUrlParts(url) {
619
619
  if (!isString(url))
620
620
  return null;
621
621
  const matches = {
622
- production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
623
- staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
624
- dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
625
- local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
622
+ production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh\/db\/([^:]+):?(.*)?/),
623
+ staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev\/db\/([^:]+):?(.*)?/),
624
+ dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev\/db\/([^:]+):?(.*)?/),
625
+ local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:([^:]+):?(.*)?/)
626
626
  };
627
627
  const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
628
628
  if (!isHostProviderAlias(host) || !match)
629
629
  return null;
630
- return { workspace: match[1], region: match[2], host };
630
+ return { workspace: match[1], region: match[2], database: match[3], branch: match[4], host };
631
631
  }
632
632
 
633
633
  const pool = new ApiRequestPool();
@@ -738,6 +738,8 @@ async function fetch$1({
738
738
  "X-Xata-Client-ID": clientID ?? defaultClientID,
739
739
  "X-Xata-Session-ID": sessionID ?? generateUUID(),
740
740
  "X-Xata-Agent": xataAgent,
741
+ // Force field rename to xata_ internal properties
742
+ "X-Features": compact(["feat-internal-field-rename-api=1", customHeaders?.["X-Features"]]).join(" "),
741
743
  ...customHeaders,
742
744
  ...hostHeader(fullUrl),
743
745
  Authorization: `Bearer ${apiKey}`
@@ -852,6 +854,12 @@ const adaptTable = (variables, signal) => dataPlaneFetch({
852
854
  ...variables,
853
855
  signal
854
856
  });
857
+ const adaptAllTables = (variables, signal) => dataPlaneFetch({
858
+ url: "/db/{dbBranchName}/migrations/adapt",
859
+ method: "post",
860
+ ...variables,
861
+ signal
862
+ });
855
863
  const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
856
864
  const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
857
865
  const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
@@ -1084,6 +1092,7 @@ const operationsByTag$2 = {
1084
1092
  migrations: {
1085
1093
  applyMigration,
1086
1094
  adaptTable,
1095
+ adaptAllTables,
1087
1096
  getBranchMigrationJobStatus,
1088
1097
  getMigrationJobStatus,
1089
1098
  getMigrationHistory,
@@ -1255,6 +1264,8 @@ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
1255
1264
  ...variables,
1256
1265
  signal
1257
1266
  });
1267
+ const getWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "get", ...variables, signal });
1268
+ const updateWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "patch", ...variables, signal });
1258
1269
  const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
1259
1270
  const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
1260
1271
  const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
@@ -1320,6 +1331,8 @@ const operationsByTag$1 = {
1320
1331
  getWorkspace,
1321
1332
  updateWorkspace,
1322
1333
  deleteWorkspace,
1334
+ getWorkspaceSettings,
1335
+ updateWorkspaceSettings,
1323
1336
  getWorkspaceMembersList,
1324
1337
  updateWorkspaceMemberRole,
1325
1338
  removeWorkspaceMember
@@ -2023,8 +2036,8 @@ cleanFilterConstraint_fn = function(column, value) {
2023
2036
  if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2024
2037
  return { $includes: value };
2025
2038
  }
2026
- if (columnType === "link" && isObject(value) && isString(value.id)) {
2027
- return value.id;
2039
+ if (columnType === "link" && isObject(value) && isString(value.xata_id)) {
2040
+ return value.xata_id;
2028
2041
  }
2029
2042
  return value;
2030
2043
  };
@@ -2052,12 +2065,7 @@ const RecordColumnTypes = [
2052
2065
  "json"
2053
2066
  ];
2054
2067
  function isIdentifiable(x) {
2055
- return isObject(x) && isString(x?.id);
2056
- }
2057
- function isXataRecord(x) {
2058
- const record = x;
2059
- const metadata = record?.getMetadata();
2060
- return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
2068
+ return isObject(x) && isString(x?.xata_id);
2061
2069
  }
2062
2070
 
2063
2071
  function isValidExpandedColumn(column) {
@@ -2184,11 +2192,14 @@ class RestRepository extends Query {
2184
2192
  const columns = isValidSelectableColumns(c) ? c : void 0;
2185
2193
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2186
2194
  }
2187
- if (isObject(a) && isString(a.id)) {
2188
- if (a.id === "")
2195
+ if (isObject(a) && isString(a.xata_id)) {
2196
+ if (a.xata_id === "")
2189
2197
  throw new Error("The id can't be empty");
2190
2198
  const columns = isValidSelectableColumns(b) ? b : void 0;
2191
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2199
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
2200
+ createOnly: true,
2201
+ ifVersion
2202
+ });
2192
2203
  }
2193
2204
  if (isObject(a)) {
2194
2205
  const columns = isValidSelectableColumns(b) ? b : void 0;
@@ -2204,9 +2215,9 @@ class RestRepository extends Query {
2204
2215
  if (a.length === 0)
2205
2216
  return [];
2206
2217
  const ids = a.map((item) => extractId(item));
2207
- const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
2218
+ const finalObjects = await this.getAll({ filter: { xata_id: { $any: compact(ids) } }, columns });
2208
2219
  const dictionary = finalObjects.reduce((acc, object) => {
2209
- acc[object.id] = object;
2220
+ acc[object.xata_id] = object;
2210
2221
  return acc;
2211
2222
  }, {});
2212
2223
  return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
@@ -2268,7 +2279,7 @@ class RestRepository extends Query {
2268
2279
  if (Array.isArray(a)) {
2269
2280
  if (a.length === 0)
2270
2281
  return [];
2271
- const existing = await this.read(a, ["id"]);
2282
+ const existing = await this.read(a, ["xata_id"]);
2272
2283
  const updates = a.filter((_item, index) => existing[index] !== null);
2273
2284
  await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2274
2285
  ifVersion,
@@ -2283,9 +2294,9 @@ class RestRepository extends Query {
2283
2294
  const columns = isValidSelectableColumns(c) ? c : void 0;
2284
2295
  return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2285
2296
  }
2286
- if (isObject(a) && isString(a.id)) {
2297
+ if (isObject(a) && isString(a.xata_id)) {
2287
2298
  const columns = isValidSelectableColumns(b) ? b : void 0;
2288
- return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2299
+ return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
2289
2300
  }
2290
2301
  } catch (error) {
2291
2302
  if (error.status === 422)
@@ -2334,16 +2345,16 @@ class RestRepository extends Query {
2334
2345
  const columns = isValidSelectableColumns(c) ? c : void 0;
2335
2346
  return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2336
2347
  }
2337
- if (isObject(a) && isString(a.id)) {
2338
- if (a.id === "")
2348
+ if (isObject(a) && isString(a.xata_id)) {
2349
+ if (a.xata_id === "")
2339
2350
  throw new Error("The id can't be empty");
2340
2351
  const columns = isValidSelectableColumns(c) ? c : void 0;
2341
- return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2352
+ return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, { ifVersion });
2342
2353
  }
2343
2354
  if (!isDefined(a) && isObject(b)) {
2344
2355
  return await this.create(b, c);
2345
2356
  }
2346
- if (isObject(a) && !isDefined(a.id)) {
2357
+ if (isObject(a) && !isDefined(a.xata_id)) {
2347
2358
  return await this.create(a, b);
2348
2359
  }
2349
2360
  throw new Error("Invalid arguments for createOrUpdate method");
@@ -2366,16 +2377,19 @@ class RestRepository extends Query {
2366
2377
  const columns = isValidSelectableColumns(c) ? c : void 0;
2367
2378
  return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2368
2379
  }
2369
- if (isObject(a) && isString(a.id)) {
2370
- if (a.id === "")
2380
+ if (isObject(a) && isString(a.xata_id)) {
2381
+ if (a.xata_id === "")
2371
2382
  throw new Error("The id can't be empty");
2372
2383
  const columns = isValidSelectableColumns(c) ? c : void 0;
2373
- return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2384
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.xata_id, { ...a, xata_id: void 0 }, columns, {
2385
+ createOnly: false,
2386
+ ifVersion
2387
+ });
2374
2388
  }
2375
2389
  if (!isDefined(a) && isObject(b)) {
2376
2390
  return await this.create(b, c);
2377
2391
  }
2378
- if (isObject(a) && !isDefined(a.id)) {
2392
+ if (isObject(a) && !isDefined(a.xata_id)) {
2379
2393
  return await this.create(a, b);
2380
2394
  }
2381
2395
  throw new Error("Invalid arguments for createOrReplace method");
@@ -2389,8 +2403,8 @@ class RestRepository extends Query {
2389
2403
  const ids = a.map((o) => {
2390
2404
  if (isString(o))
2391
2405
  return o;
2392
- if (isString(o.id))
2393
- return o.id;
2406
+ if (isString(o.xata_id))
2407
+ return o.xata_id;
2394
2408
  throw new Error("Invalid arguments for delete method");
2395
2409
  });
2396
2410
  const columns = isValidSelectableColumns(b) ? b : ["*"];
@@ -2401,8 +2415,8 @@ class RestRepository extends Query {
2401
2415
  if (isString(a)) {
2402
2416
  return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
2403
2417
  }
2404
- if (isObject(a) && isString(a.id)) {
2405
- return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
2418
+ if (isObject(a) && isString(a.xata_id)) {
2419
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.xata_id, b);
2406
2420
  }
2407
2421
  throw new Error("Invalid arguments for delete method");
2408
2422
  });
@@ -2664,7 +2678,7 @@ _updateRecordWithID = new WeakSet();
2664
2678
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2665
2679
  if (!recordId)
2666
2680
  return null;
2667
- const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2681
+ const { xata_id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2668
2682
  try {
2669
2683
  const response = await updateRecordWithID({
2670
2684
  pathParams: {
@@ -2689,9 +2703,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
2689
2703
  };
2690
2704
  _updateRecords = new WeakSet();
2691
2705
  updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2692
- const operations = await promiseMap(objects, async ({ id, ...object }) => {
2706
+ const operations = await promiseMap(objects, async ({ xata_id, ...object }) => {
2693
2707
  const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
2694
- return { update: { table: __privateGet$2(this, _table), id, ifVersion, upsert, fields } };
2708
+ return { update: { table: __privateGet$2(this, _table), id: xata_id, ifVersion, upsert, fields } };
2695
2709
  });
2696
2710
  const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
2697
2711
  const ids = [];
@@ -2796,12 +2810,12 @@ transformObjectToApi_fn = async function(object) {
2796
2810
  throw new Error(`Table ${__privateGet$2(this, _table)} not found in schema`);
2797
2811
  const result = {};
2798
2812
  for (const [key, value] of Object.entries(object)) {
2799
- if (key === "xata")
2813
+ if (["xata_version", "xata_createdat", "xata_updatedat"].includes(key))
2800
2814
  continue;
2801
2815
  const type = schema.columns.find((column) => column.name === key)?.type;
2802
2816
  switch (type) {
2803
2817
  case "link": {
2804
- result[key] = isIdentifiable(value) ? value.id : value;
2818
+ result[key] = isIdentifiable(value) ? value.xata_id : value;
2805
2819
  break;
2806
2820
  }
2807
2821
  case "datetime": {
@@ -2825,8 +2839,7 @@ transformObjectToApi_fn = async function(object) {
2825
2839
  };
2826
2840
  const initObject = (db, schemaTables, table, object, selectedColumns) => {
2827
2841
  const data = {};
2828
- const { xata, ...rest } = object ?? {};
2829
- Object.assign(data, rest);
2842
+ Object.assign(data, { ...object });
2830
2843
  const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2831
2844
  if (!columns)
2832
2845
  console.error(`Table ${table} not found in schema`);
@@ -2889,28 +2902,21 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2889
2902
  }
2890
2903
  }
2891
2904
  const record = { ...data };
2892
- const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
2893
2905
  record.read = function(columns2) {
2894
- return db[table].read(record["id"], columns2);
2906
+ return db[table].read(record["xata_id"], columns2);
2895
2907
  };
2896
2908
  record.update = function(data2, b, c) {
2897
2909
  const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2898
2910
  const ifVersion = parseIfVersion(b, c);
2899
- return db[table].update(record["id"], data2, columns2, { ifVersion });
2911
+ return db[table].update(record["xata_id"], data2, columns2, { ifVersion });
2900
2912
  };
2901
2913
  record.replace = function(data2, b, c) {
2902
2914
  const columns2 = isValidSelectableColumns(b) ? b : ["*"];
2903
2915
  const ifVersion = parseIfVersion(b, c);
2904
- return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
2916
+ return db[table].createOrReplace(record["xata_id"], data2, columns2, { ifVersion });
2905
2917
  };
2906
2918
  record.delete = function() {
2907
- return db[table].delete(record["id"]);
2908
- };
2909
- if (metadata !== void 0) {
2910
- record.xata = Object.freeze(metadata);
2911
- }
2912
- record.getMetadata = function() {
2913
- return record.xata;
2919
+ return db[table].delete(record["xata_id"]);
2914
2920
  };
2915
2921
  record.toSerializable = function() {
2916
2922
  return JSON.parse(JSON.stringify(record));
@@ -2918,7 +2924,7 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2918
2924
  record.toString = function() {
2919
2925
  return JSON.stringify(record);
2920
2926
  };
2921
- for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
2927
+ for (const prop of ["read", "update", "replace", "delete", "toSerializable", "toString"]) {
2922
2928
  Object.defineProperty(record, prop, { enumerable: false });
2923
2929
  }
2924
2930
  Object.freeze(record);
@@ -2927,8 +2933,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2927
2933
  function extractId(value) {
2928
2934
  if (isString(value))
2929
2935
  return value;
2930
- if (isObject(value) && isString(value.id))
2931
- return value.id;
2936
+ if (isObject(value) && isString(value.xata_id))
2937
+ return value.xata_id;
2932
2938
  return void 0;
2933
2939
  }
2934
2940
  function isValidColumn(columns, column) {
@@ -3116,7 +3122,7 @@ class SearchPlugin extends XataPlugin {
3116
3122
  return {
3117
3123
  totalCount,
3118
3124
  records: records.map((record) => {
3119
- const { table = "orphan" } = record.xata;
3125
+ const table = record.xata_table;
3120
3126
  return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
3121
3127
  })
3122
3128
  };
@@ -3124,7 +3130,7 @@ class SearchPlugin extends XataPlugin {
3124
3130
  byTable: async (query, options = {}) => {
3125
3131
  const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
3126
3132
  const records = rawRecords.reduce((acc, record) => {
3127
- const { table = "orphan" } = record.xata;
3133
+ const table = record.xata_table;
3128
3134
  const items = acc[table] ?? [];
3129
3135
  const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
3130
3136
  return { ...acc, [table]: [...items, item] };
@@ -3198,19 +3204,19 @@ function prepareParams(param1, param2) {
3198
3204
  return { statement, params: param2?.map((value) => prepareValue(value)) };
3199
3205
  }
3200
3206
  if (isObject(param1)) {
3201
- const { statement, params, consistency } = param1;
3202
- return { statement, params: params?.map((value) => prepareValue(value)), consistency };
3207
+ const { statement, params, consistency, responseType } = param1;
3208
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency, responseType };
3203
3209
  }
3204
3210
  throw new Error("Invalid query");
3205
3211
  }
3206
3212
 
3207
3213
  class SQLPlugin extends XataPlugin {
3208
3214
  build(pluginOptions) {
3209
- return async (query, ...parameters) => {
3215
+ const sqlFunction = async (query, ...parameters) => {
3210
3216
  if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
3211
3217
  throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
3212
3218
  }
3213
- const { statement, params, consistency } = prepareParams(query, parameters);
3219
+ const { statement, params, consistency, responseType } = prepareParams(query, parameters);
3214
3220
  const {
3215
3221
  records,
3216
3222
  rows,
@@ -3218,11 +3224,13 @@ class SQLPlugin extends XataPlugin {
3218
3224
  columns = []
3219
3225
  } = await sqlQuery({
3220
3226
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3221
- body: { statement, params, consistency },
3227
+ body: { statement, params, consistency, responseType },
3222
3228
  ...pluginOptions
3223
3229
  });
3224
3230
  return { records, rows, warning, columns };
3225
3231
  };
3232
+ sqlFunction.connectionString = buildConnectionString(pluginOptions);
3233
+ return sqlFunction;
3226
3234
  }
3227
3235
  }
3228
3236
  function isTemplateStringsArray(strings) {
@@ -3231,6 +3239,33 @@ function isTemplateStringsArray(strings) {
3231
3239
  function isParamsObject(params) {
3232
3240
  return isObject(params) && "statement" in params;
3233
3241
  }
3242
+ function buildDomain(host, region) {
3243
+ switch (host) {
3244
+ case "production":
3245
+ return `${region}.sql.xata.sh`;
3246
+ case "staging":
3247
+ return `${region}.sql.staging-xata.dev`;
3248
+ case "dev":
3249
+ return `${region}.sql.dev-xata.dev`;
3250
+ case "local":
3251
+ return "localhost:7654";
3252
+ default:
3253
+ throw new Error("Invalid host provider");
3254
+ }
3255
+ }
3256
+ function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
3257
+ const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
3258
+ const parts = parseWorkspacesUrlParts(url);
3259
+ if (!parts)
3260
+ throw new Error("Invalid workspaces URL");
3261
+ const { workspace: workspaceSlug, region, database, host } = parts;
3262
+ const domain = buildDomain(host, region);
3263
+ const workspace = workspaceSlug.split("-").pop();
3264
+ if (!workspace || !region || !database || !apiKey || !branch) {
3265
+ throw new Error("Unable to build xata connection string");
3266
+ }
3267
+ return `postgresql://${workspace}:${apiKey}@${domain}/${database}:${branch}?sslmode=require`;
3268
+ }
3234
3269
 
3235
3270
  class TransactionPlugin extends XataPlugin {
3236
3271
  build(pluginOptions) {
@@ -3281,7 +3316,8 @@ const buildClient = (plugins) => {
3281
3316
  const pluginOptions = {
3282
3317
  ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3283
3318
  host: safeOptions.host,
3284
- tables
3319
+ tables,
3320
+ branch: safeOptions.branch
3285
3321
  };
3286
3322
  const db = new SchemaPlugin().build(pluginOptions);
3287
3323
  const search = new SearchPlugin(db).build(pluginOptions);
@@ -3462,5 +3498,5 @@ class XataError extends Error {
3462
3498
  }
3463
3499
  }
3464
3500
 
3465
- export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, PageRecordArray, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, adaptTable, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationJobStatus, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseSettings, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationHistory, getMigrationJobStatus, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateDatabaseSettings, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
3501
+ export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, PageRecordArray, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, adaptAllTables, adaptTable, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationJobStatus, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseSettings, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationHistory, getMigrationJobStatus, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspaceSettings, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateDatabaseSettings, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, updateWorkspaceSettings, upsertRecordWithID, vectorSearchTable };
3466
3502
  //# sourceMappingURL=index.mjs.map