@xata.io/client 0.0.0-beta.bd46af7 → 0.0.0-beta.c844f02
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.
- package/.eslintrc.cjs +13 -0
- package/CHANGELOG.md +50 -0
- package/dist/api/client.d.ts +2 -2
- package/dist/api/client.js +12 -9
- package/dist/api/components.d.ts +34 -37
- package/dist/api/components.js +34 -37
- package/dist/api/fetcher.d.ts +15 -0
- package/dist/api/fetcher.js +23 -22
- package/dist/api/providers.js +3 -2
- package/dist/api/responses.d.ts +6 -0
- package/dist/schema/config.d.ts +4 -0
- package/dist/schema/config.js +83 -0
- package/dist/schema/filters.d.ts +93 -17
- package/dist/schema/filters.js +0 -22
- package/dist/schema/filters.spec.d.ts +1 -0
- package/dist/schema/filters.spec.js +175 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +4 -1
- package/dist/schema/operators.d.ts +17 -27
- package/dist/schema/operators.js +1 -14
- package/dist/schema/pagination.d.ts +14 -14
- package/dist/schema/pagination.js +0 -1
- package/dist/schema/query.d.ts +41 -51
- package/dist/schema/query.js +25 -37
- package/dist/schema/record.d.ts +28 -3
- package/dist/schema/record.js +11 -0
- package/dist/schema/repository.d.ts +75 -36
- package/dist/schema/repository.js +208 -111
- package/dist/schema/selection.d.ts +24 -13
- package/dist/schema/selection.spec.d.ts +1 -0
- package/dist/schema/selection.spec.js +203 -0
- package/dist/schema/sorting.d.ts +17 -0
- package/dist/schema/sorting.js +28 -0
- package/dist/schema/sorting.spec.d.ts +1 -0
- package/dist/schema/sorting.spec.js +9 -0
- package/dist/util/environment.d.ts +5 -0
- package/dist/util/environment.js +68 -0
- package/dist/util/fetch.d.ts +2 -0
- package/dist/util/fetch.js +13 -0
- package/dist/util/lang.d.ts +3 -0
- package/dist/util/lang.js +13 -1
- package/dist/util/types.d.ts +22 -1
- 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,55 @@
|
|
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
|
+
|
36
|
+
## 0.5.0
|
37
|
+
|
38
|
+
### Patch Changes
|
39
|
+
|
40
|
+
- 14ec7d1: Fix in Selectable type
|
41
|
+
|
42
|
+
## 0.4.0
|
43
|
+
|
44
|
+
### Patch Changes
|
45
|
+
|
46
|
+
- b951331: Add support for new float column
|
47
|
+
- d470610: Add new getAll() method
|
48
|
+
- eaf92a8: Expose pagination constants (size and offset limits)
|
49
|
+
- 57fde77: Reduce subrequests for createMany
|
50
|
+
- eaf92a8: Implement schema-less client
|
51
|
+
- 97a3caa: Make createBranch from optional with empty branch
|
52
|
+
|
3
53
|
## 0.3.0
|
4
54
|
|
5
55
|
### Minor Changes
|
package/dist/api/client.d.ts
CHANGED
@@ -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
|
8
|
-
apiKey
|
7
|
+
fetch?: FetchImpl;
|
8
|
+
apiKey?: string;
|
9
9
|
host?: HostProvider;
|
10
10
|
}
|
11
11
|
export declare class XataApiClient {
|
package/dist/api/client.js
CHANGED
@@ -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
|
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,
|
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) {
|
package/dist/api/components.d.ts
CHANGED
@@ -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
|
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
|
-
*
|
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
|
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
|
* {
|
@@ -998,8 +990,9 @@ export declare type QueryTableVariables = {
|
|
998
990
|
* },
|
999
991
|
* {
|
1000
992
|
* "name": "r2",
|
1001
|
-
* }
|
1002
|
-
* ]
|
993
|
+
* }
|
994
|
+
* ]
|
995
|
+
* }
|
1003
996
|
* }
|
1004
997
|
* ```
|
1005
998
|
*
|
@@ -1009,7 +1002,7 @@ export declare type QueryTableVariables = {
|
|
1009
1002
|
* {
|
1010
1003
|
* "filter": {
|
1011
1004
|
* "$exists": "settings",
|
1012
|
-
* }
|
1005
|
+
* }
|
1013
1006
|
* }
|
1014
1007
|
* ```
|
1015
1008
|
*
|
@@ -1024,19 +1017,19 @@ export declare type QueryTableVariables = {
|
|
1024
1017
|
* },
|
1025
1018
|
* {
|
1026
1019
|
* "$exists": "name",
|
1027
|
-
* }
|
1028
|
-
* ]
|
1020
|
+
* }
|
1021
|
+
* ]
|
1029
1022
|
* }
|
1030
1023
|
* }
|
1031
1024
|
* ```
|
1032
1025
|
*
|
1033
|
-
*
|
1026
|
+
* Or you can use the inverse operator `$notExists`:
|
1034
1027
|
*
|
1035
1028
|
* ```json
|
1036
1029
|
* {
|
1037
1030
|
* "filter": {
|
1038
1031
|
* "$notExists": "settings",
|
1039
|
-
* }
|
1032
|
+
* }
|
1040
1033
|
* }
|
1041
1034
|
* ```
|
1042
1035
|
*
|
@@ -1083,7 +1076,7 @@ export declare type QueryTableVariables = {
|
|
1083
1076
|
* }
|
1084
1077
|
* ```
|
1085
1078
|
*
|
1086
|
-
* #### Numeric
|
1079
|
+
* #### Numeric ranges
|
1087
1080
|
*
|
1088
1081
|
* ```json
|
1089
1082
|
* {
|
@@ -1098,18 +1091,6 @@ export declare type QueryTableVariables = {
|
|
1098
1091
|
*
|
1099
1092
|
* The supported operators are `$gt`, `$lt`, `$ge`, `$le`.
|
1100
1093
|
*
|
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
1094
|
*
|
1114
1095
|
* #### Negations
|
1115
1096
|
*
|
@@ -1162,7 +1143,7 @@ export declare type QueryTableVariables = {
|
|
1162
1143
|
* }
|
1163
1144
|
* ```
|
1164
1145
|
*
|
1165
|
-
* In addition,
|
1146
|
+
* In addition, you can use operators like `$isNot` or `$notExists` to simplify expressions:
|
1166
1147
|
*
|
1167
1148
|
* ```json
|
1168
1149
|
* {
|
@@ -1213,6 +1194,22 @@ export declare type QueryTableVariables = {
|
|
1213
1194
|
* predicate. The `$includes` operator is a synonym for the `$includesAny`
|
1214
1195
|
* operator.
|
1215
1196
|
*
|
1197
|
+
* Here is an example of using the `$includesAll` operator:
|
1198
|
+
*
|
1199
|
+
* ```json
|
1200
|
+
* {
|
1201
|
+
* "filter": {
|
1202
|
+
* "settings.labels": {
|
1203
|
+
* "$includesAll": [
|
1204
|
+
* {"$contains": "label"},
|
1205
|
+
* ]
|
1206
|
+
* }
|
1207
|
+
* }
|
1208
|
+
* }
|
1209
|
+
* ```
|
1210
|
+
*
|
1211
|
+
* The above matches if all label values contain the string "labels".
|
1212
|
+
*
|
1216
1213
|
* ### Sorting
|
1217
1214
|
*
|
1218
1215
|
* Sorting by one element:
|
package/dist/api/components.js
CHANGED
@@ -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
|
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
|
-
*
|
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
|
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
|
* {
|
@@ -581,8 +573,9 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
581
573
|
* },
|
582
574
|
* {
|
583
575
|
* "name": "r2",
|
584
|
-
* }
|
585
|
-
* ]
|
576
|
+
* }
|
577
|
+
* ]
|
578
|
+
* }
|
586
579
|
* }
|
587
580
|
* ```
|
588
581
|
*
|
@@ -592,7 +585,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
592
585
|
* {
|
593
586
|
* "filter": {
|
594
587
|
* "$exists": "settings",
|
595
|
-
* }
|
588
|
+
* }
|
596
589
|
* }
|
597
590
|
* ```
|
598
591
|
*
|
@@ -607,19 +600,19 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
607
600
|
* },
|
608
601
|
* {
|
609
602
|
* "$exists": "name",
|
610
|
-
* }
|
611
|
-
* ]
|
603
|
+
* }
|
604
|
+
* ]
|
612
605
|
* }
|
613
606
|
* }
|
614
607
|
* ```
|
615
608
|
*
|
616
|
-
*
|
609
|
+
* Or you can use the inverse operator `$notExists`:
|
617
610
|
*
|
618
611
|
* ```json
|
619
612
|
* {
|
620
613
|
* "filter": {
|
621
614
|
* "$notExists": "settings",
|
622
|
-
* }
|
615
|
+
* }
|
623
616
|
* }
|
624
617
|
* ```
|
625
618
|
*
|
@@ -666,7 +659,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
666
659
|
* }
|
667
660
|
* ```
|
668
661
|
*
|
669
|
-
* #### Numeric
|
662
|
+
* #### Numeric ranges
|
670
663
|
*
|
671
664
|
* ```json
|
672
665
|
* {
|
@@ -681,18 +674,6 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
681
674
|
*
|
682
675
|
* The supported operators are `$gt`, `$lt`, `$ge`, `$le`.
|
683
676
|
*
|
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
677
|
*
|
697
678
|
* #### Negations
|
698
679
|
*
|
@@ -745,7 +726,7 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
745
726
|
* }
|
746
727
|
* ```
|
747
728
|
*
|
748
|
-
* In addition,
|
729
|
+
* In addition, you can use operators like `$isNot` or `$notExists` to simplify expressions:
|
749
730
|
*
|
750
731
|
* ```json
|
751
732
|
* {
|
@@ -796,6 +777,22 @@ exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
796
777
|
* predicate. The `$includes` operator is a synonym for the `$includesAny`
|
797
778
|
* operator.
|
798
779
|
*
|
780
|
+
* Here is an example of using the `$includesAll` operator:
|
781
|
+
*
|
782
|
+
* ```json
|
783
|
+
* {
|
784
|
+
* "filter": {
|
785
|
+
* "settings.labels": {
|
786
|
+
* "$includesAll": [
|
787
|
+
* {"$contains": "label"},
|
788
|
+
* ]
|
789
|
+
* }
|
790
|
+
* }
|
791
|
+
* }
|
792
|
+
* ```
|
793
|
+
*
|
794
|
+
* The above matches if all label values contain the string "labels".
|
795
|
+
*
|
799
796
|
* ### Sorting
|
800
797
|
*
|
801
798
|
* Sorting by one element:
|
package/dist/api/fetcher.d.ts
CHANGED
@@ -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
|
+
}
|
package/dist/api/fetcher.js
CHANGED
@@ -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
|
-
|
55
|
-
|
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 (
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
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;
|
package/dist/api/providers.js
CHANGED
@@ -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
|
26
|
+
return (0, lang_1.isString)(alias) && Object.keys(providers).includes(alias);
|
26
27
|
}
|
27
28
|
function isValidBuilder(builder) {
|
28
|
-
return
|
29
|
+
return (0, lang_1.isObject)(builder) && (0, lang_1.isString)(builder.main) && (0, lang_1.isString)(builder.workspaces);
|
29
30
|
}
|
package/dist/api/responses.d.ts
CHANGED
@@ -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;
|