@xata.io/client 0.0.0-next.v042aeb4a059d554fba37ac7694aca9fe91a806bb → 0.0.0-next.v1f44ba4535763bf3da40b336e1de2ed58b179017

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 875ms
7
+ created dist/index.cjs in 1s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 708ms
10
+ created dist/index.mjs in 683ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 4s
13
+ created dist/index.d.ts in 4.1s
package/CHANGELOG.md CHANGED
@@ -1,12 +1,18 @@
1
1
  # @xata.io/client
2
2
 
3
- ## 0.0.0-next.v042aeb4a059d554fba37ac7694aca9fe91a806bb
3
+ ## 0.0.0-next.v1f44ba4535763bf3da40b336e1de2ed58b179017
4
4
 
5
5
  ### Major Changes
6
6
 
7
- - [`513ffd3`](https://github.com/xataio/client-ts/commit/513ffd3f9348c5a5fd0d4070a46b1fc8af60c538) Thanks [@SferaDev](https://github.com/SferaDev)! - Make XataApiClient to use ES Proxies
7
+ - [`f63c5c3`](https://github.com/xataio/client-ts/commit/f63c5c3c975bb034ebd982e9b47bb37e2c041c2b) Thanks [@SferaDev](https://github.com/SferaDev)! - Make XataApiClient to use ES Proxies
8
8
 
9
- - [`1193662`](https://github.com/xataio/client-ts/commit/11936623b65c08190e5367beac094371fdc54e46) Thanks [@SferaDev](https://github.com/SferaDev)! - Version 1.0
9
+ - [`cf77d3c`](https://github.com/xataio/client-ts/commit/cf77d3c2ac350802efbfb97d070b348e24426e2a) 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
14
+
15
+ - [#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
16
 
11
17
  ## 0.29.2
12
18
 
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
@@ -3195,19 +3199,19 @@ function prepareParams(param1, param2) {
3195
3199
  return { statement, params: param2?.map((value) => prepareValue(value)) };
3196
3200
  }
3197
3201
  if (isObject(param1)) {
3198
- const { statement, params, consistency } = param1;
3199
- return { statement, params: params?.map((value) => prepareValue(value)), consistency };
3202
+ const { statement, params, consistency, responseType } = param1;
3203
+ return { statement, params: params?.map((value) => prepareValue(value)), consistency, responseType };
3200
3204
  }
3201
3205
  throw new Error("Invalid query");
3202
3206
  }
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
  }
3210
- const { statement, params, consistency } = prepareParams(query, parameters);
3214
+ const { statement, params, consistency, responseType } = prepareParams(query, parameters);
3211
3215
  const {
3212
3216
  records,
3213
3217
  rows,
@@ -3215,11 +3219,13 @@ class SQLPlugin extends XataPlugin {
3215
3219
  columns = []
3216
3220
  } = await sqlQuery({
3217
3221
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3218
- body: { statement, params, consistency },
3222
+ body: { statement, params, consistency, responseType },
3219
3223
  ...pluginOptions
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