@xata.io/client 0.0.0-next.vdcc7247ab6c54a023e791b576c247bc20533009e → 0.0.0-next.vdf3a7b8c70c130a3e9c73decc8494a3f8c8febcb

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.
@@ -4,10 +4,10 @@
4
4
 
5
5
  
6
6
  src/index.ts → dist/index.cjs...
7
- created dist/index.cjs in 891ms
7
+ created dist/index.cjs in 977ms
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 671ms
10
+ created dist/index.mjs in 626ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 4.2s
13
+ created dist/index.d.ts in 4.4s
package/CHANGELOG.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # @xata.io/client
2
2
 
3
- ## 0.0.0-next.vdcc7247ab6c54a023e791b576c247bc20533009e
3
+ ## 0.0.0-next.vdf3a7b8c70c130a3e9c73decc8494a3f8c8febcb
4
4
 
5
5
  ### Major Changes
6
6
 
7
- - [`03882fe`](https://github.com/xataio/client-ts/commit/03882fed962b51028571bc65c82a4ecb9ed40ae6) Thanks [@SferaDev](https://github.com/SferaDev)! - Make XataApiClient to use ES Proxies
7
+ - [`eb10b5a`](https://github.com/xataio/client-ts/commit/eb10b5a5ca2167991be014273648706e223e7ec3) Thanks [@SferaDev](https://github.com/SferaDev)! - Make XataApiClient to use ES Proxies
8
8
 
9
- - [`b173601`](https://github.com/xataio/client-ts/commit/b1736015ba325ed13c7444699e454228c987a391) Thanks [@SferaDev](https://github.com/SferaDev)! - Version 1.0
9
+ - [`9d9b6fd`](https://github.com/xataio/client-ts/commit/9d9b6fd483e00f625b7f5d34bb8616b2a11e0cf1) Thanks [@SferaDev](https://github.com/SferaDev)! - Version 1.0
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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
10
14
 
11
15
  ## 0.29.2
12
16
 
package/dist/index.cjs CHANGED
@@ -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();
@@ -1259,6 +1259,8 @@ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
1259
1259
  ...variables,
1260
1260
  signal
1261
1261
  });
1262
+ const getWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "get", ...variables, signal });
1263
+ const updateWorkspaceSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/settings", method: "patch", ...variables, signal });
1262
1264
  const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
1263
1265
  const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
1264
1266
  const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
@@ -1324,6 +1326,8 @@ const operationsByTag$1 = {
1324
1326
  getWorkspace,
1325
1327
  updateWorkspace,
1326
1328
  deleteWorkspace,
1329
+ getWorkspaceSettings,
1330
+ updateWorkspaceSettings,
1327
1331
  getWorkspaceMembersList,
1328
1332
  updateWorkspaceMemberRole,
1329
1333
  removeWorkspaceMember
@@ -3203,7 +3207,7 @@ function prepareParams(param1, param2) {
3203
3207
 
3204
3208
  class SQLPlugin extends XataPlugin {
3205
3209
  build(pluginOptions) {
3206
- return async (query, ...parameters) => {
3210
+ const sqlFunction = async (query, ...parameters) => {
3207
3211
  if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
3208
3212
  throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
3209
3213
  }
@@ -3220,6 +3224,8 @@ class SQLPlugin extends XataPlugin {
3220
3224
  });
3221
3225
  return { records, rows, warning, columns };
3222
3226
  };
3227
+ sqlFunction.connectionString = buildConnectionString(pluginOptions);
3228
+ return sqlFunction;
3223
3229
  }
3224
3230
  }
3225
3231
  function isTemplateStringsArray(strings) {
@@ -3228,6 +3234,33 @@ function isTemplateStringsArray(strings) {
3228
3234
  function isParamsObject(params) {
3229
3235
  return isObject(params) && "statement" in params;
3230
3236
  }
3237
+ function buildDomain(host, region) {
3238
+ switch (host) {
3239
+ case "production":
3240
+ return `${region}.sql.xata.sh`;
3241
+ case "staging":
3242
+ return `${region}.sql.staging-xata.dev`;
3243
+ case "dev":
3244
+ return `${region}.sql.dev-xata.dev`;
3245
+ case "local":
3246
+ return "localhost:7654";
3247
+ default:
3248
+ throw new Error("Invalid host provider");
3249
+ }
3250
+ }
3251
+ function buildConnectionString({ apiKey, workspacesApiUrl, branch }) {
3252
+ const url = isString(workspacesApiUrl) ? workspacesApiUrl : workspacesApiUrl("", {});
3253
+ const parts = parseWorkspacesUrlParts(url);
3254
+ if (!parts)
3255
+ throw new Error("Invalid workspaces URL");
3256
+ const { workspace: workspaceSlug, region, database, host } = parts;
3257
+ const domain = buildDomain(host, region);
3258
+ const workspace = workspaceSlug.split("-").pop();
3259
+ if (!workspace || !region || !database || !apiKey || !branch) {
3260
+ throw new Error("Unable to build xata connection string");
3261
+ }
3262
+ return `postgresql://${workspace}:${apiKey}@${domain}/${database}:${branch}?sslmode=require`;
3263
+ }
3231
3264
 
3232
3265
  class TransactionPlugin extends XataPlugin {
3233
3266
  build(pluginOptions) {
@@ -3278,7 +3311,8 @@ const buildClient = (plugins) => {
3278
3311
  const pluginOptions = {
3279
3312
  ...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3280
3313
  host: safeOptions.host,
3281
- tables
3314
+ tables,
3315
+ branch: safeOptions.branch
3282
3316
  };
3283
3317
  const db = new SchemaPlugin().build(pluginOptions);
3284
3318
  const search = new SearchPlugin(db).build(pluginOptions);
@@ -3569,6 +3603,7 @@ exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
3569
3603
  exports.getUserOAuthClients = getUserOAuthClients;
3570
3604
  exports.getWorkspace = getWorkspace;
3571
3605
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
3606
+ exports.getWorkspaceSettings = getWorkspaceSettings;
3572
3607
  exports.getWorkspacesList = getWorkspacesList;
3573
3608
  exports.grantAuthorizationCode = grantAuthorizationCode;
3574
3609
  exports.greaterEquals = greaterEquals;
@@ -3642,6 +3677,7 @@ exports.updateUser = updateUser;
3642
3677
  exports.updateWorkspace = updateWorkspace;
3643
3678
  exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
3644
3679
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
3680
+ exports.updateWorkspaceSettings = updateWorkspaceSettings;
3645
3681
  exports.upsertRecordWithID = upsertRecordWithID;
3646
3682
  exports.vectorSearchTable = vectorSearchTable;
3647
3683
  //# sourceMappingURL=index.cjs.map