@xata.io/client 0.29.1 → 0.29.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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @xata.io/client@0.29.1 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.1 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 1.1s
7
+ created dist/index.cjs in 1s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 807ms
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 5s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.29.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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
8
+
9
+ - [#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
+
11
+ ## 0.29.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [#1380](https://github.com/xataio/client-ts/pull/1380) [`e8db1cd`](https://github.com/xataio/client-ts/commit/e8db1cd394ccbed32403548bf9d09a5c3973d850) Thanks [@richardgill](https://github.com/richardgill)! - Link to our docs to explain how to resolve the 'api key in browser' error message
16
+
3
17
  ## 0.29.1
4
18
 
5
19
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -528,7 +528,7 @@ function defaultOnOpen(response) {
528
528
  }
529
529
  }
530
530
 
531
- const VERSION = "0.29.1";
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();
@@ -847,26 +847,29 @@ function parseUrl(url) {
847
847
 
848
848
  const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
849
849
 
850
- const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
851
- const pgRollStatus = (variables, signal) => dataPlaneFetch({
852
- url: "/db/{dbBranchName}/pgroll/status",
853
- method: "get",
850
+ const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/apply", method: "post", ...variables, signal });
851
+ const adaptTable = (variables, signal) => dataPlaneFetch({
852
+ url: "/db/{dbBranchName}/migrations/adapt/{tableName}",
853
+ method: "post",
854
854
  ...variables,
855
855
  signal
856
856
  });
857
- const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
858
- url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
857
+ const getBranchMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/status", method: "get", ...variables, signal });
858
+ const getMigrationJobStatus = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/jobs/{jobId}", method: "get", ...variables, signal });
859
+ const getMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/history", method: "get", ...variables, signal });
860
+ const getBranchList = (variables, signal) => dataPlaneFetch({
861
+ url: "/dbs/{dbName}",
859
862
  method: "get",
860
863
  ...variables,
861
864
  signal
862
865
  });
863
- const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
864
- const getBranchList = (variables, signal) => dataPlaneFetch({
865
- url: "/dbs/{dbName}",
866
+ const getDatabaseSettings = (variables, signal) => dataPlaneFetch({
867
+ url: "/dbs/{dbName}/settings",
866
868
  method: "get",
867
869
  ...variables,
868
870
  signal
869
871
  });
872
+ const updateDatabaseSettings = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/settings", method: "patch", ...variables, signal });
870
873
  const getBranchDetails = (variables, signal) => dataPlaneFetch({
871
874
  url: "/db/{dbBranchName}",
872
875
  method: "get",
@@ -1080,11 +1083,25 @@ const sqlQuery = (variables, signal) => dataPlaneFetch({
1080
1083
  signal
1081
1084
  });
1082
1085
  const operationsByTag$2 = {
1083
- branch: {
1086
+ migrations: {
1084
1087
  applyMigration,
1085
- pgRollStatus,
1086
- pgRollJobStatus,
1087
- pgRollMigrationHistory,
1088
+ adaptTable,
1089
+ getBranchMigrationJobStatus,
1090
+ getMigrationJobStatus,
1091
+ getMigrationHistory,
1092
+ getSchema,
1093
+ getBranchMigrationHistory,
1094
+ getBranchMigrationPlan,
1095
+ executeBranchMigrationPlan,
1096
+ getBranchSchemaHistory,
1097
+ compareBranchWithUserSchema,
1098
+ compareBranchSchemas,
1099
+ updateBranchSchema,
1100
+ previewBranchSchemaEdit,
1101
+ applyBranchSchemaEdit,
1102
+ pushBranchMigrations
1103
+ },
1104
+ branch: {
1088
1105
  getBranchList,
1089
1106
  getBranchDetails,
1090
1107
  createBranch,
@@ -1098,19 +1115,7 @@ const operationsByTag$2 = {
1098
1115
  removeGitBranchesEntry,
1099
1116
  resolveBranch
1100
1117
  },
1101
- migrations: {
1102
- getSchema,
1103
- getBranchMigrationHistory,
1104
- getBranchMigrationPlan,
1105
- executeBranchMigrationPlan,
1106
- getBranchSchemaHistory,
1107
- compareBranchWithUserSchema,
1108
- compareBranchSchemas,
1109
- updateBranchSchema,
1110
- previewBranchSchemaEdit,
1111
- applyBranchSchemaEdit,
1112
- pushBranchMigrations
1113
- },
1118
+ database: { getDatabaseSettings, updateDatabaseSettings },
1114
1119
  migrationRequests: {
1115
1120
  queryMigrationRequests,
1116
1121
  createMigrationRequest,
@@ -1252,6 +1257,8 @@ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
1252
1257
  ...variables,
1253
1258
  signal
1254
1259
  });
1260
+ const getWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "get", ...variables, signal });
1261
+ const updateWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "patch", ...variables, signal });
1255
1262
  const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
1256
1263
  const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
1257
1264
  const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
@@ -1317,6 +1324,8 @@ const operationsByTag$1 = {
1317
1324
  getWorkspace,
1318
1325
  updateWorkspace,
1319
1326
  deleteWorkspace,
1327
+ getWorkspaceSettings,
1328
+ updateWorkspaceSettings,
1320
1329
  getWorkspaceMembersList,
1321
1330
  updateWorkspaceMemberRole,
1322
1331
  removeWorkspaceMember
@@ -1752,7 +1761,7 @@ class BranchApi {
1752
1761
  database,
1753
1762
  branch
1754
1763
  }) {
1755
- return operationsByTag.branch.pgRollMigrationHistory({
1764
+ return operationsByTag.migrations.getMigrationHistory({
1756
1765
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1757
1766
  ...this.extraProps
1758
1767
  });
@@ -1764,7 +1773,7 @@ class BranchApi {
1764
1773
  branch,
1765
1774
  migration
1766
1775
  }) {
1767
- return operationsByTag.branch.applyMigration({
1776
+ return operationsByTag.migrations.applyMigration({
1768
1777
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1769
1778
  body: migration,
1770
1779
  ...this.extraProps
@@ -4584,26 +4593,33 @@ function prepareParams(param1, param2) {
4584
4593
  return { statement, params: param2?.map((value) => prepareValue(value)) };
4585
4594
  }
4586
4595
  if (isObject(param1)) {
4587
- const { statement, params, consistency } = param1;
4588
- return { statement, params: params?.map((value) => prepareValue(value)), consistency };
4596
+ const { statement, params, consistency, responseType } = param1;
4597
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency, responseType };
4589
4598
  }
4590
4599
  throw new Error("Invalid query");
4591
4600
  }
4592
4601
 
4593
4602
  class SQLPlugin extends XataPlugin {
4594
4603
  build(pluginOptions) {
4595
- return async (query, ...parameters) => {
4604
+ const sqlFunction = async (query, ...parameters) => {
4596
4605
  if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
4597
4606
  throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
4598
4607
  }
4599
- const { statement, params, consistency } = prepareParams(query, parameters);
4600
- const { records, warning, columns } = await sqlQuery({
4608
+ const { statement, params, consistency, responseType } = prepareParams(query, parameters);
4609
+ const {
4610
+ records,
4611
+ rows,
4612
+ warning,
4613
+ columns = []
4614
+ } = await sqlQuery({
4601
4615
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
4602
- body: { statement, params, consistency },
4616
+ body: { statement, params, consistency, responseType },
4603
4617
  ...pluginOptions
4604
4618
  });
4605
- return { records, warning, columns };
4619
+ return { records, rows, warning, columns };
4606
4620
  };
4621
+ sqlFunction.connectionString = buildConnectionString(pluginOptions);
4622
+ return sqlFunction;
4607
4623
  }
4608
4624
  }
4609
4625
  function isTemplateStringsArray(strings) {
@@ -4612,6 +4628,33 @@ function isTemplateStringsArray(strings) {
4612
4628
  function isParamsObject(params) {
4613
4629
  return isObject(params) && "statement" in params;
4614
4630
  }
4631
+ function buildDomain(host, region) {
4632
+ switch (host) {
4633
+ case "production":
4634
+ return `${region}.sql.xata.sh`;
4635
+ case "staging":
4636
+ return `${region}.sql.staging-xata.dev`;
4637
+ case "dev":
4638
+ return `${region}.sql.dev-xata.dev`;
4639
+ case "local":
4640
+ return "localhost:7654";
4641
+ default:
4642
+ throw new Error("Invalid host provider");
4643
+ }
4644
+ }
4645
+ function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
4646
+ const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
4647
+ const parts = parseWorkspacesUrlParts(url);
4648
+ if (!parts)
4649
+ throw new Error("Invalid workspaces URL");
4650
+ const { workspace: workspaceSlug, region, database, host } = parts;
4651
+ const domain = buildDomain(host, region);
4652
+ const workspace = workspaceSlug.split("-").pop();
4653
+ if (!workspace || !region || !database || !apiKey || !branch) {
4654
+ throw new Error("Unable to build xata connection string");
4655
+ }
4656
+ return `postgresql://${workspace}:${apiKey}@${domain}/${database}:${branch}?sslmode=require`;
4657
+ }
4615
4658
 
4616
4659
  class TransactionPlugin extends XataPlugin {
4617
4660
  build(pluginOptions) {
@@ -4663,7 +4706,8 @@ const buildClient = (plugins) => {
4663
4706
  ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
4664
4707
  cache: safeOptions.cache,
4665
4708
  host: safeOptions.host,
4666
- tables
4709
+ tables,
4710
+ branch: safeOptions.branch
4667
4711
  };
4668
4712
  const db = new SchemaPlugin().build(pluginOptions);
4669
4713
  const search = new SearchPlugin(db).build(pluginOptions);
@@ -4692,7 +4736,7 @@ const buildClient = (plugins) => {
4692
4736
  const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
4693
4737
  if (isBrowser && !enableBrowser) {
4694
4738
  throw new Error(
4695
- "You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
4739
+ "You are trying to use Xata from the browser, which is potentially a non-secure environment. How to fix: https://xata.io/docs/messages/api-key-browser-error"
4696
4740
  );
4697
4741
  }
4698
4742
  const fetch = getFetchImplementation(options?.fetch);
@@ -4873,6 +4917,7 @@ exports.XataError = XataError;
4873
4917
  exports.XataFile = XataFile;
4874
4918
  exports.XataPlugin = XataPlugin;
4875
4919
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
4920
+ exports.adaptTable = adaptTable;
4876
4921
  exports.addGitBranchesEntry = addGitBranchesEntry;
4877
4922
  exports.addTableColumn = addTableColumn;
4878
4923
  exports.aggregateTable = aggregateTable;
@@ -4926,6 +4971,7 @@ exports.getBranchDetails = getBranchDetails;
4926
4971
  exports.getBranchList = getBranchList;
4927
4972
  exports.getBranchMetadata = getBranchMetadata;
4928
4973
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
4974
+ exports.getBranchMigrationJobStatus = getBranchMigrationJobStatus;
4929
4975
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
4930
4976
  exports.getBranchSchemaHistory = getBranchSchemaHistory;
4931
4977
  exports.getBranchStats = getBranchStats;
@@ -4934,11 +4980,14 @@ exports.getColumn = getColumn;
4934
4980
  exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
4935
4981
  exports.getDatabaseList = getDatabaseList;
4936
4982
  exports.getDatabaseMetadata = getDatabaseMetadata;
4983
+ exports.getDatabaseSettings = getDatabaseSettings;
4937
4984
  exports.getDatabaseURL = getDatabaseURL;
4938
4985
  exports.getFile = getFile;
4939
4986
  exports.getFileItem = getFileItem;
4940
4987
  exports.getGitBranchesMapping = getGitBranchesMapping;
4941
4988
  exports.getHostUrl = getHostUrl;
4989
+ exports.getMigrationHistory = getMigrationHistory;
4990
+ exports.getMigrationJobStatus = getMigrationJobStatus;
4942
4991
  exports.getMigrationRequest = getMigrationRequest;
4943
4992
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
4944
4993
  exports.getPreviewBranch = getPreviewBranch;
@@ -4952,6 +5001,7 @@ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
4952
5001
  exports.getUserOAuthClients = getUserOAuthClients;
4953
5002
  exports.getWorkspace = getWorkspace;
4954
5003
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
5004
+ exports.getWorkspaceSettings = getWorkspaceSettings;
4955
5005
  exports.getWorkspacesList = getWorkspacesList;
4956
5006
  exports.grantAuthorizationCode = grantAuthorizationCode;
4957
5007
  exports.greaterEquals = greaterEquals;
@@ -4992,9 +5042,6 @@ exports.operationsByTag = operationsByTag;
4992
5042
  exports.parseProviderString = parseProviderString;
4993
5043
  exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
4994
5044
  exports.pattern = pattern;
4995
- exports.pgRollJobStatus = pgRollJobStatus;
4996
- exports.pgRollMigrationHistory = pgRollMigrationHistory;
4997
- exports.pgRollStatus = pgRollStatus;
4998
5045
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
4999
5046
  exports.pushBranchMigrations = pushBranchMigrations;
5000
5047
  exports.putFile = putFile;
@@ -5020,6 +5067,7 @@ exports.updateCluster = updateCluster;
5020
5067
  exports.updateColumn = updateColumn;
5021
5068
  exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
5022
5069
  exports.updateDatabaseMetadata = updateDatabaseMetadata;
5070
+ exports.updateDatabaseSettings = updateDatabaseSettings;
5023
5071
  exports.updateMigrationRequest = updateMigrationRequest;
5024
5072
  exports.updateOAuthAccessToken = updateOAuthAccessToken;
5025
5073
  exports.updateRecordWithID = updateRecordWithID;
@@ -5028,6 +5076,7 @@ exports.updateUser = updateUser;
5028
5076
  exports.updateWorkspace = updateWorkspace;
5029
5077
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
5030
5078
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
5079
+ exports.updateWorkspaceSettings = updateWorkspaceSettings;
5031
5080
  exports.upsertRecordWithID = upsertRecordWithID;
5032
5081
  exports.vectorSearchTable = vectorSearchTable;
5033
5082
  //# sourceMappingURL=index.cjs.map