@xata.io/client 0.5.0 → 0.7.0

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.
Files changed (43) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/CHANGELOG.md +33 -0
  3. package/dist/api/client.d.ts +2 -2
  4. package/dist/api/client.js +12 -9
  5. package/dist/api/components.d.ts +27 -31
  6. package/dist/api/components.js +27 -31
  7. package/dist/api/fetcher.d.ts +15 -0
  8. package/dist/api/fetcher.js +23 -22
  9. package/dist/api/providers.js +3 -2
  10. package/dist/api/responses.d.ts +6 -0
  11. package/dist/schema/config.d.ts +4 -0
  12. package/dist/schema/config.js +83 -0
  13. package/dist/schema/filters.d.ts +93 -17
  14. package/dist/schema/filters.js +0 -22
  15. package/dist/schema/filters.spec.d.ts +1 -0
  16. package/dist/schema/filters.spec.js +175 -0
  17. package/dist/schema/index.d.ts +1 -0
  18. package/dist/schema/index.js +4 -1
  19. package/dist/schema/operators.d.ts +17 -27
  20. package/dist/schema/operators.js +1 -14
  21. package/dist/schema/pagination.d.ts +13 -13
  22. package/dist/schema/pagination.js +0 -1
  23. package/dist/schema/query.d.ts +39 -50
  24. package/dist/schema/query.js +25 -37
  25. package/dist/schema/record.d.ts +25 -3
  26. package/dist/schema/record.js +11 -0
  27. package/dist/schema/repository.d.ts +79 -35
  28. package/dist/schema/repository.js +208 -111
  29. package/dist/schema/selection.d.ts +24 -11
  30. package/dist/schema/selection.spec.d.ts +1 -0
  31. package/dist/schema/selection.spec.js +203 -0
  32. package/dist/schema/sorting.d.ts +17 -0
  33. package/dist/schema/sorting.js +28 -0
  34. package/dist/schema/sorting.spec.d.ts +1 -0
  35. package/dist/schema/sorting.spec.js +9 -0
  36. package/dist/util/environment.d.ts +5 -0
  37. package/dist/util/environment.js +68 -0
  38. package/dist/util/fetch.d.ts +2 -0
  39. package/dist/util/fetch.js +13 -0
  40. package/dist/util/lang.d.ts +3 -0
  41. package/dist/util/lang.js +13 -1
  42. package/dist/util/types.d.ts +22 -1
  43. package/package.json +2 -2
package/.eslintrc.cjs ADDED
@@ -0,0 +1,13 @@
1
+ module.exports = {
2
+ ignorePatterns: ["dist"],
3
+ parserOptions: {
4
+ ecmaVersion: 2020,
5
+ sourceType: 'module',
6
+ project: 'client/tsconfig.json'
7
+ },
8
+ rules: {
9
+ '@typescript-eslint/no-explicit-any': 'off',
10
+ '@typescript-eslint/ban-types': 'off',
11
+ '@typescript-eslint/no-floating-promises': 'error',
12
+ }
13
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6ce5512: Add bulk operations for all methods
8
+ - 2a1fa4f: Introduced automatic branch resolution mechanism
9
+
10
+ ### Patch Changes
11
+
12
+ - d033f3a: Improve column selection output type with non-nullable columns
13
+ - b1e92db: Include stack trace with errors
14
+ - deed570: Improve sorting with multiple properties
15
+ - 80b5417: Improve filtering types
16
+
17
+ ## 0.6.0
18
+
19
+ ### Minor Changes
20
+
21
+ - 084f5df: Add type inference for columns
22
+ - bb73c89: Unify create and insert in a single method overload
23
+
24
+ ### Patch Changes
25
+
26
+ - 716c487: Forward nullable types on links
27
+ - bb66bb2: Fix error handling with createMany
28
+ - 084f5df: Fix circular dependencies on selectable column
29
+
30
+ ## 0.5.1
31
+
32
+ ### Patch Changes
33
+
34
+ - 12729ab: Make API client fetch implementation optional
35
+
3
36
  ## 0.5.0
4
37
 
5
38
  ### Patch Changes
@@ -4,8 +4,8 @@ import { HostProvider } from './providers';
4
4
  import type * as Responses from './responses';
5
5
  import type * as Schemas from './schemas';
6
6
  export interface XataApiClientOptions {
7
- fetch: FetchImpl;
8
- apiKey: string;
7
+ fetch?: FetchImpl;
8
+ apiKey?: string;
9
9
  host?: HostProvider;
10
10
  }
11
11
  export declare class XataApiClient {
@@ -13,23 +13,24 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _XataApiClient_extraProps;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.XataApiClient = void 0;
16
+ const config_1 = require("../schema/config");
17
+ const fetch_1 = require("../util/fetch");
16
18
  const components_1 = require("./components");
17
19
  const providers_1 = require("./providers");
18
20
  class XataApiClient {
19
21
  constructor(options) {
20
- var _a;
22
+ var _a, _b;
21
23
  _XataApiClient_extraProps.set(this, void 0);
22
- const fetchImpl = typeof fetch !== 'undefined' ? fetch : options.fetch;
23
- if (!fetchImpl) {
24
- /** @todo add a link after docs exist */
25
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
26
- }
27
24
  const provider = (_a = options.host) !== null && _a !== void 0 ? _a : 'production';
25
+ const apiKey = (_b = options === null || options === void 0 ? void 0 : options.apiKey) !== null && _b !== void 0 ? _b : (0, config_1.getAPIKey)();
26
+ if (!apiKey) {
27
+ throw new Error('Could not resolve a valid apiKey');
28
+ }
28
29
  __classPrivateFieldSet(this, _XataApiClient_extraProps, {
29
30
  apiUrl: (0, providers_1.getHostUrl)(provider, 'main'),
30
31
  workspacesApiUrl: (0, providers_1.getHostUrl)(provider, 'workspaces'),
31
- fetchImpl,
32
- apiKey: options.apiKey
32
+ fetchImpl: (0, fetch_1.getFetchImplementation)(options.fetch),
33
+ apiKey
33
34
  }, "f");
34
35
  }
35
36
  get user() {
@@ -220,7 +221,9 @@ class RecordsApi {
220
221
  deleteRecord(workspace, database, branch, tableName, recordId) {
221
222
  return components_1.operationsByTag.records.deleteRecord(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId } }, this.extraProps));
222
223
  }
223
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
224
+ getRecord(workspace, database, branch, tableName, recordId,
225
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
226
+ options = {}) {
224
227
  return components_1.operationsByTag.records.getRecord(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId } }, this.extraProps));
225
228
  }
226
229
  bulkInsertTableRecords(workspace, database, branch, tableName, records) {
@@ -875,7 +875,7 @@ export declare type QueryTableVariables = {
875
875
  * `$none`, etc.
876
876
  *
877
877
  * All operators start with an `$` to differentiate them from column names
878
- * (which are not allowed to start with an underscore).
878
+ * (which are not allowed to start with an dollar sign).
879
879
  *
880
880
  * #### Exact matching and control operators
881
881
  *
@@ -943,27 +943,17 @@ export declare type QueryTableVariables = {
943
943
  * }
944
944
  * ```
945
945
  *
946
- * If you want to OR together multiple values, you can use an array of values:
946
+ * If you want to OR together multiple values, you can use the `$any` operator with an array of values:
947
947
  *
948
948
  * ```json
949
949
  * {
950
950
  * "filter": {
951
- * "settings.plan": ["free", "paid"]
951
+ * "settings.plan": {"$any": ["free", "paid"]}
952
952
  * },
953
953
  * }
954
954
  * ```
955
955
  *
956
- * Same query with `$is` operator:
957
- *
958
- * ```json
959
- * {
960
- * "filter": {
961
- * "settings.plan": { "$is": ["free", "paid"]}
962
- * },
963
- * }
964
- * ```
965
- *
966
- * Specifying multiple columns, ANDs them together:
956
+ * If you specify multiple columns in the same filter, they are logically AND'ed together:
967
957
  *
968
958
  * ```json
969
959
  * {
@@ -974,6 +964,8 @@ export declare type QueryTableVariables = {
974
964
  * }
975
965
  * ```
976
966
  *
967
+ * The above matches if both conditions are met.
968
+ *
977
969
  * To be more explicit about it, you can use `$all` or `$any`:
978
970
  *
979
971
  * ```json
@@ -981,13 +973,13 @@ export declare type QueryTableVariables = {
981
973
  * "filter": {
982
974
  * "$any": {
983
975
  * "settings.dark": true,
984
- * "settings.plan": "free",
976
+ * "settings.plan": "free"
985
977
  * }
986
978
  * },
987
979
  * }
988
980
  * ```
989
981
  *
990
- * `$all` and `$any` can also receive an array of objects, which allows for repeating columns:
982
+ * The `$all` and `$any` operators can also receive an array of objects, which allows for repeating column names:
991
983
  *
992
984
  * ```json
993
985
  * {
@@ -1030,7 +1022,7 @@ export declare type QueryTableVariables = {
1030
1022
  * }
1031
1023
  * ```
1032
1024
  *
1033
- * We can also make the negation version, `$notExists` :
1025
+ * Or you can use the inverse operator `$notExists`:
1034
1026
  *
1035
1027
  * ```json
1036
1028
  * {
@@ -1083,7 +1075,7 @@ export declare type QueryTableVariables = {
1083
1075
  * }
1084
1076
  * ```
1085
1077
  *
1086
- * #### Numeric/date ranges
1078
+ * #### Numeric ranges
1087
1079
  *
1088
1080
  * ```json
1089
1081
  * {
@@ -1098,18 +1090,6 @@ export declare type QueryTableVariables = {
1098
1090
  *
1099
1091
  * The supported operators are `$gt`, `$lt`, `$ge`, `$le`.
1100
1092
  *
1101
- * Date ranges would support the same operators, with the date as string in RFC 3339:
1102
- *
1103
- * ```json
1104
- * {
1105
- * "filter": {
1106
- * "<column_name>": {
1107
- * "$gt": "2019-10-12T07:20:50.52Z",
1108
- * "$lt": "2021-10-12T07:20:50.52Z"
1109
- * }
1110
- * }
1111
- * }
1112
- * ```
1113
1093
  *
1114
1094
  * #### Negations
1115
1095
  *
@@ -1162,7 +1142,7 @@ export declare type QueryTableVariables = {
1162
1142
  * }
1163
1143
  * ```
1164
1144
  *
1165
- * In addition, we can add specific operators like `$isNot` to simplify expressions:
1145
+ * In addition, you can use operators like `$isNot` or `$notExists` to simplify expressions:
1166
1146
  *
1167
1147
  * ```json
1168
1148
  * {
@@ -1213,6 +1193,22 @@ export declare type QueryTableVariables = {
1213
1193
  * predicate. The `$includes` operator is a synonym for the `$includesAny`
1214
1194
  * operator.
1215
1195
  *
1196
+ * Here is an example of using the `$includesAll` operator:
1197
+ *
1198
+ * ```json
1199
+ * {
1200
+ * "filter": {
1201
+ * "settings.labels": {
1202
+ * "$includesAll": [
1203
+ * {"$contains": "label"},
1204
+ * ]
1205
+ * }
1206
+ * }
1207
+ * }
1208
+ * ```
1209
+ *
1210
+ * The above matches if all label values contain the string "labels".
1211
+ *
1216
1212
  * ### Sorting
1217
1213
  *
1218
1214
  * Sorting by one element:
@@ -458,7 +458,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
458
458
  * `$none`, etc.
459
459
  *
460
460
  * All operators start with an `$` to differentiate them from column names
461
- * (which are not allowed to start with an underscore).
461
+ * (which are not allowed to start with an dollar sign).
462
462
  *
463
463
  * #### Exact matching and control operators
464
464
  *
@@ -526,27 +526,17 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
526
526
  * }
527
527
  * ```
528
528
  *
529
- * If you want to OR together multiple values, you can use an array of values:
529
+ * If you want to OR together multiple values, you can use the `$any` operator with an array of values:
530
530
  *
531
531
  * ```json
532
532
  * {
533
533
  * "filter": {
534
- * "settings.plan": ["free", "paid"]
534
+ * "settings.plan": {"$any": ["free", "paid"]}
535
535
  * },
536
536
  * }
537
537
  * ```
538
538
  *
539
- * Same query with `$is` operator:
540
- *
541
- * ```json
542
- * {
543
- * "filter": {
544
- * "settings.plan": { "$is": ["free", "paid"]}
545
- * },
546
- * }
547
- * ```
548
- *
549
- * Specifying multiple columns, ANDs them together:
539
+ * If you specify multiple columns in the same filter, they are logically AND'ed together:
550
540
  *
551
541
  * ```json
552
542
  * {
@@ -557,6 +547,8 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
557
547
  * }
558
548
  * ```
559
549
  *
550
+ * The above matches if both conditions are met.
551
+ *
560
552
  * To be more explicit about it, you can use `$all` or `$any`:
561
553
  *
562
554
  * ```json
@@ -564,13 +556,13 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
564
556
  * "filter": {
565
557
  * "$any": {
566
558
  * "settings.dark": true,
567
- * "settings.plan": "free",
559
+ * "settings.plan": "free"
568
560
  * }
569
561
  * },
570
562
  * }
571
563
  * ```
572
564
  *
573
- * `$all` and `$any` can also receive an array of objects, which allows for repeating columns:
565
+ * The `$all` and `$any` operators can also receive an array of objects, which allows for repeating column names:
574
566
  *
575
567
  * ```json
576
568
  * {
@@ -613,7 +605,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
613
605
  * }
614
606
  * ```
615
607
  *
616
- * We can also make the negation version, `$notExists` :
608
+ * Or you can use the inverse operator `$notExists`:
617
609
  *
618
610
  * ```json
619
611
  * {
@@ -666,7 +658,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
666
658
  * }
667
659
  * ```
668
660
  *
669
- * #### Numeric/date ranges
661
+ * #### Numeric ranges
670
662
  *
671
663
  * ```json
672
664
  * {
@@ -681,18 +673,6 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
681
673
  *
682
674
  * The supported operators are `$gt`, `$lt`, `$ge`, `$le`.
683
675
  *
684
- * Date ranges would support the same operators, with the date as string in RFC 3339:
685
- *
686
- * ```json
687
- * {
688
- * "filter": {
689
- * "<column_name>": {
690
- * "$gt": "2019-10-12T07:20:50.52Z",
691
- * "$lt": "2021-10-12T07:20:50.52Z"
692
- * }
693
- * }
694
- * }
695
- * ```
696
676
  *
697
677
  * #### Negations
698
678
  *
@@ -745,7 +725,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
745
725
  * }
746
726
  * ```
747
727
  *
748
- * In addition, we can add specific operators like `$isNot` to simplify expressions:
728
+ * In addition, you can use operators like `$isNot` or `$notExists` to simplify expressions:
749
729
  *
750
730
  * ```json
751
731
  * {
@@ -796,6 +776,22 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
796
776
  * predicate. The `$includes` operator is a synonym for the `$includesAny`
797
777
  * operator.
798
778
  *
779
+ * Here is an example of using the `$includesAll` operator:
780
+ *
781
+ * ```json
782
+ * {
783
+ * "filter": {
784
+ * "settings.labels": {
785
+ * "$includesAll": [
786
+ * {"$contains": "label"},
787
+ * ]
788
+ * }
789
+ * }
790
+ * }
791
+ * ```
792
+ *
793
+ * The above matches if all label values contain the string "labels".
794
+ *
799
795
  * ### Sorting
800
796
  *
801
797
  * Sorting by one element:
@@ -23,3 +23,18 @@ export declare type FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> =
23
23
  pathParams?: TPathParams;
24
24
  };
25
25
  export declare function fetch<TData, TBody extends Record<string, unknown> | undefined, THeaders extends Record<string, unknown>, TQueryParams extends Record<string, unknown>, TPathParams extends Record<string, string>>({ url: path, method, body, headers, pathParams, queryParams, fetchImpl, apiKey, apiUrl, workspacesApiUrl }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> & FetcherExtraProps): Promise<TData>;
26
+ export declare class FetcherError extends Error {
27
+ status: number;
28
+ errors: Array<{
29
+ status: number;
30
+ message?: string;
31
+ }> | undefined;
32
+ constructor(data: {
33
+ message: string;
34
+ status: number;
35
+ errors?: Array<{
36
+ status: number;
37
+ message?: string;
38
+ }>;
39
+ }, parent?: Error);
40
+ }
@@ -9,13 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.fetch = void 0;
12
+ exports.FetcherError = exports.fetch = void 0;
13
+ const lang_1 = require("../util/lang");
13
14
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
14
15
  const query = new URLSearchParams(queryParams).toString();
15
16
  const queryString = query.length > 0 ? `?${query}` : '';
16
17
  return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
17
18
  };
18
- const fallbackError = { message: 'Network response was not ok' };
19
19
  function buildBaseUrl({ path, workspacesApiUrl, apiUrl, pathParams }) {
20
20
  if (!(pathParams === null || pathParams === void 0 ? void 0 : pathParams.workspace))
21
21
  return `${apiUrl}${path}`;
@@ -51,28 +51,29 @@ function fetch({ url: path, method, body, headers, pathParams, queryParams, fetc
51
51
  if (response.ok) {
52
52
  return jsonResponse;
53
53
  }
54
- if (jsonResponse.message) {
55
- throw withStatus({ message: jsonResponse.message }, response.status);
56
- }
57
- else {
58
- throw withStatus(fallbackError, response.status);
59
- }
54
+ const { message = 'Unknown error', errors } = jsonResponse;
55
+ throw new FetcherError({ message, status: response.status, errors });
60
56
  }
61
- catch (e) {
62
- if (e instanceof Error) {
63
- const error = {
64
- message: e.message
65
- };
66
- throw withStatus(error, response.status);
67
- }
68
- else if (typeof e === 'object' && typeof e.message === 'string') {
69
- throw withStatus(e, response.status);
70
- }
71
- else {
72
- throw withStatus(fallbackError, response.status);
73
- }
57
+ catch (error) {
58
+ const message = hasMessage(error) ? error.message : 'Unknown network error';
59
+ const parent = error instanceof Error ? error : undefined;
60
+ throw new FetcherError({ message, status: response.status }, parent);
74
61
  }
75
62
  });
76
63
  }
77
64
  exports.fetch = fetch;
78
- const withStatus = (error, status) => (Object.assign(Object.assign({}, error), { status }));
65
+ const hasMessage = (error) => {
66
+ return (0, lang_1.isObject)(error) && (0, lang_1.isString)(error.message);
67
+ };
68
+ class FetcherError extends Error {
69
+ constructor(data, parent) {
70
+ super(data.message);
71
+ this.status = data.status;
72
+ this.errors = data.errors;
73
+ if (parent) {
74
+ this.stack = parent.stack;
75
+ this.cause = parent.cause;
76
+ }
77
+ }
78
+ }
79
+ exports.FetcherError = FetcherError;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHostUrl = void 0;
4
+ const lang_1 = require("../util/lang");
4
5
  function getHostUrl(provider, type) {
5
6
  if (isValidAlias(provider)) {
6
7
  return providers[provider][type];
@@ -22,8 +23,8 @@ const providers = {
22
23
  }
23
24
  };
24
25
  function isValidAlias(alias) {
25
- return typeof alias === 'string' && Object.keys(providers).includes(alias);
26
+ return (0, lang_1.isString)(alias) && Object.keys(providers).includes(alias);
26
27
  }
27
28
  function isValidBuilder(builder) {
28
- return typeof builder === 'object' && typeof builder.main === 'string' && typeof builder.workspaces === 'string';
29
+ return (0, lang_1.isObject)(builder) && (0, lang_1.isString)(builder.main) && (0, lang_1.isString)(builder.workspaces);
29
30
  }
@@ -19,6 +19,12 @@ export declare type AuthError = {
19
19
  id?: string;
20
20
  message: string;
21
21
  };
22
+ export declare type BulkError = {
23
+ errors: {
24
+ message?: string;
25
+ status?: number;
26
+ }[];
27
+ };
22
28
  export declare type BranchMigrationPlan = {
23
29
  version: number;
24
30
  migration: Schemas.BranchMigration;
@@ -0,0 +1,4 @@
1
+ import { FetcherExtraProps } from '../api/fetcher';
2
+ export declare function getBranch(fetchProps: Omit<FetcherExtraProps, 'workspacesApiUrl'>): Promise<string | undefined>;
3
+ export declare function getDatabaseUrl(): string | undefined;
4
+ export declare function getAPIKey(): string | undefined;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getAPIKey = exports.getDatabaseUrl = exports.getBranch = void 0;
13
+ const api_1 = require("../api");
14
+ const environment_1 = require("../util/environment");
15
+ const lang_1 = require("../util/lang");
16
+ const envBranchNames = [
17
+ 'XATA_BRANCH',
18
+ 'VERCEL_GIT_COMMIT_REF',
19
+ 'CF_PAGES_BRANCH',
20
+ 'BRANCH' // Netlify. Putting it the last one because it is more ambiguous
21
+ ];
22
+ function getBranch(fetchProps) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const env = getBranchByEnvVariable();
25
+ if (env)
26
+ return env;
27
+ const branch = yield (0, environment_1.getGitBranch)();
28
+ if (!branch)
29
+ return undefined;
30
+ // TODO: in the future, call /resolve endpoint
31
+ // For now, call API to see if the branch exists. If not, use a default value.
32
+ const [protocol, , host, , database] = fetchProps.apiUrl.split('/');
33
+ const [workspace] = host.split('.');
34
+ const dbBranchName = `${database}:${branch}`;
35
+ try {
36
+ yield (0, api_1.getBranchDetails)(Object.assign(Object.assign({}, fetchProps), { workspacesApiUrl: `${protocol}//${host}`, pathParams: {
37
+ dbBranchName,
38
+ workspace
39
+ } }));
40
+ }
41
+ catch (err) {
42
+ if ((0, lang_1.isObject)(err) && err.status === 404)
43
+ return 'main';
44
+ throw err;
45
+ }
46
+ return branch;
47
+ });
48
+ }
49
+ exports.getBranch = getBranch;
50
+ function getBranchByEnvVariable() {
51
+ for (const name of envBranchNames) {
52
+ const value = (0, environment_1.getEnvVariable)(name);
53
+ if (value) {
54
+ return value;
55
+ }
56
+ }
57
+ try {
58
+ return XATA_BRANCH;
59
+ }
60
+ catch (err) {
61
+ // Ignore ReferenceError. Only CloudFlare workers set env variables as global variables
62
+ }
63
+ }
64
+ function getDatabaseUrl() {
65
+ var _a;
66
+ try {
67
+ return (_a = (0, environment_1.getEnvVariable)('XATA_DATABASE_URL')) !== null && _a !== void 0 ? _a : XATA_DATABASE_URL;
68
+ }
69
+ catch (err) {
70
+ return undefined;
71
+ }
72
+ }
73
+ exports.getDatabaseUrl = getDatabaseUrl;
74
+ function getAPIKey() {
75
+ var _a;
76
+ try {
77
+ return (_a = (0, environment_1.getEnvVariable)('XATA_API_KEY')) !== null && _a !== void 0 ? _a : XATA_API_KEY;
78
+ }
79
+ catch (err) {
80
+ return undefined;
81
+ }
82
+ }
83
+ exports.getAPIKey = getAPIKey;