@xata.io/client 0.23.1 → 0.23.2

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.23.1 add-version /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.23.2 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.23.1 build /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.23.2 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.2s
7
+ created dist/index.cjs in 1s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 865ms
10
+ created dist/index.mjs in 851ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 5.6s
13
+ created dist/index.d.ts in 5.7s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.23.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#939](https://github.com/xataio/client-ts/pull/939) [`c477c177`](https://github.com/xataio/client-ts/commit/c477c17795c01cbf945be413217944a5a38655a5) Thanks [@SferaDev](https://github.com/SferaDev)! - Add deploy preview branch env variable loading
8
+
9
+ - [#945](https://github.com/xataio/client-ts/pull/945) [`ecdc6553`](https://github.com/xataio/client-ts/commit/ecdc6553d4628289e88953ab6296b80f60e8f757) Thanks [@xata-bot](https://github.com/xata-bot)! - Add new types
10
+
3
11
  ## 0.23.1
4
12
 
5
13
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -93,7 +93,10 @@ function getEnvironment() {
93
93
  apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
94
94
  databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
95
95
  branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
96
- envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH
96
+ deployPreview: process.env.XATA_PREVIEW,
97
+ deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
98
+ vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
99
+ vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
97
100
  };
98
101
  }
99
102
  } catch (err) {
@@ -104,7 +107,10 @@ function getEnvironment() {
104
107
  apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
105
108
  databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
106
109
  branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
107
- envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH")
110
+ deployPreview: Deno.env.get("XATA_PREVIEW"),
111
+ deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
112
+ vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
113
+ vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
108
114
  };
109
115
  }
110
116
  } catch (err) {
@@ -113,7 +119,10 @@ function getEnvironment() {
113
119
  apiKey: getGlobalApiKey(),
114
120
  databaseURL: getGlobalDatabaseURL(),
115
121
  branch: getGlobalBranch(),
116
- envBranch: void 0
122
+ deployPreview: void 0,
123
+ deployPreviewBranch: void 0,
124
+ vercelGitCommitRef: void 0,
125
+ vercelGitRepoOwner: void 0
117
126
  };
118
127
  }
119
128
  function getEnableBrowserVariable() {
@@ -174,8 +183,30 @@ function getAPIKey() {
174
183
  }
175
184
  function getBranch() {
176
185
  try {
177
- const { branch, envBranch } = getEnvironment();
178
- return branch ?? envBranch;
186
+ const { branch } = getEnvironment();
187
+ return branch ?? "main";
188
+ } catch (err) {
189
+ return void 0;
190
+ }
191
+ }
192
+ function buildPreviewBranchName({ org, branch }) {
193
+ return `preview-${org}-${branch}`;
194
+ }
195
+ function getPreviewBranch() {
196
+ try {
197
+ const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
198
+ if (deployPreviewBranch)
199
+ return deployPreviewBranch;
200
+ switch (deployPreview) {
201
+ case "vercel": {
202
+ if (!vercelGitCommitRef || !vercelGitRepoOwner) {
203
+ console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
204
+ return void 0;
205
+ }
206
+ return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
207
+ }
208
+ }
209
+ return void 0;
179
210
  } catch (err) {
180
211
  return void 0;
181
212
  }
@@ -461,7 +492,7 @@ function defaultOnOpen(response) {
461
492
  }
462
493
  }
463
494
 
464
- const VERSION = "0.23.1";
495
+ const VERSION = "0.23.2";
465
496
 
466
497
  class ErrorWithCause extends Error {
467
498
  constructor(message, options) {
@@ -3640,7 +3671,6 @@ const buildClient = (plugins) => {
3640
3671
  }
3641
3672
  const fetch = getFetchImplementation(options?.fetch);
3642
3673
  const databaseURL = options?.databaseURL || getDatabaseURL();
3643
- const branch = options?.branch || getBranch() || "main";
3644
3674
  const apiKey = options?.apiKey || getAPIKey();
3645
3675
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3646
3676
  const trace = options?.trace ?? defaultTrace;
@@ -3653,6 +3683,28 @@ const buildClient = (plugins) => {
3653
3683
  if (!databaseURL) {
3654
3684
  throw new Error("Option databaseURL is required");
3655
3685
  }
3686
+ const envBranch = getBranch();
3687
+ const previewBranch = getPreviewBranch();
3688
+ const branch = options?.branch || previewBranch || envBranch || "main";
3689
+ if (!!previewBranch && branch !== previewBranch) {
3690
+ console.warn(
3691
+ `Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
3692
+ );
3693
+ } else if (!!envBranch && branch !== envBranch) {
3694
+ console.warn(
3695
+ `Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3696
+ );
3697
+ } else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
3698
+ console.warn(
3699
+ `Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
3700
+ );
3701
+ } else if (!previewBranch && !envBranch && options?.branch === void 0) {
3702
+ console.warn(
3703
+ `No branch was passed to the client constructor. Using default branch ${branch}. You can set the branch with the environment variable XATA_BRANCH or by passing the branch option to the client constructor.`
3704
+ );
3705
+ } else {
3706
+ console.log(`Using branch ${branch}`);
3707
+ }
3656
3708
  return {
3657
3709
  fetch,
3658
3710
  databaseURL,
@@ -3812,6 +3864,7 @@ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3812
3864
  exports.askTable = askTable;
3813
3865
  exports.branchTransaction = branchTransaction;
3814
3866
  exports.buildClient = buildClient;
3867
+ exports.buildPreviewBranchName = buildPreviewBranchName;
3815
3868
  exports.buildProviderString = buildProviderString;
3816
3869
  exports.buildWorkerRunner = buildWorkerRunner;
3817
3870
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
@@ -3860,6 +3913,7 @@ exports.getGitBranchesMapping = getGitBranchesMapping;
3860
3913
  exports.getHostUrl = getHostUrl;
3861
3914
  exports.getMigrationRequest = getMigrationRequest;
3862
3915
  exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
3916
+ exports.getPreviewBranch = getPreviewBranch;
3863
3917
  exports.getRecord = getRecord;
3864
3918
  exports.getTableColumns = getTableColumns;
3865
3919
  exports.getTableSchema = getTableSchema;