@xata.io/client 0.0.0-beta.d4fe58e → 0.0.0-beta.d76c443

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 (45) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/CHANGELOG.md +58 -0
  3. package/dist/api/client.d.ts +2 -2
  4. package/dist/api/client.js +34 -18
  5. package/dist/api/components.d.ts +34 -37
  6. package/dist/api/components.js +34 -37
  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/index.d.ts +1 -0
  12. package/dist/index.js +1 -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 +5 -3
  18. package/dist/schema/index.js +8 -4
  19. package/dist/schema/operators.d.ts +26 -24
  20. package/dist/schema/operators.js +13 -11
  21. package/dist/schema/pagination.d.ts +18 -14
  22. package/dist/schema/pagination.js +5 -2
  23. package/dist/schema/query.d.ts +48 -44
  24. package/dist/schema/query.js +46 -31
  25. package/dist/schema/record.d.ts +28 -3
  26. package/dist/schema/record.js +11 -0
  27. package/dist/schema/repository.d.ts +76 -37
  28. package/dist/schema/repository.js +214 -110
  29. package/dist/schema/selection.d.ts +24 -13
  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/config.d.ts +11 -0
  37. package/dist/util/config.js +121 -0
  38. package/dist/util/environment.d.ts +5 -0
  39. package/dist/util/environment.js +68 -0
  40. package/dist/util/fetch.d.ts +2 -0
  41. package/dist/util/fetch.js +13 -0
  42. package/dist/util/lang.d.ts +3 -0
  43. package/dist/util/lang.js +13 -1
  44. package/dist/util/types.d.ts +22 -1
  45. package/package.json +5 -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,63 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 01aef78: Fix bundle for browsers
8
+ - 56be1fd: Allow sending updates with link object
9
+ - fc51771: Add includes operator helper methods
10
+
11
+ ## 0.7.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 6ce5512: Add bulk operations for all methods
16
+ - 2a1fa4f: Introduced automatic branch resolution mechanism
17
+
18
+ ### Patch Changes
19
+
20
+ - d033f3a: Improve column selection output type with non-nullable columns
21
+ - b1e92db: Include stack trace with errors
22
+ - deed570: Improve sorting with multiple properties
23
+ - 80b5417: Improve filtering types
24
+
25
+ ## 0.6.0
26
+
27
+ ### Minor Changes
28
+
29
+ - 084f5df: Add type inference for columns
30
+ - bb73c89: Unify create and insert in a single method overload
31
+
32
+ ### Patch Changes
33
+
34
+ - 716c487: Forward nullable types on links
35
+ - bb66bb2: Fix error handling with createMany
36
+ - 084f5df: Fix circular dependencies on selectable column
37
+
38
+ ## 0.5.1
39
+
40
+ ### Patch Changes
41
+
42
+ - 12729ab: Make API client fetch implementation optional
43
+
44
+ ## 0.5.0
45
+
46
+ ### Patch Changes
47
+
48
+ - 14ec7d1: Fix in Selectable type
49
+
50
+ ## 0.4.0
51
+
52
+ ### Patch Changes
53
+
54
+ - b951331: Add support for new float column
55
+ - d470610: Add new getAll() method
56
+ - eaf92a8: Expose pagination constants (size and offset limits)
57
+ - 57fde77: Reduce subrequests for createMany
58
+ - eaf92a8: Implement schema-less client
59
+ - 97a3caa: Make createBranch from optional with empty branch
60
+
3
61
  ## 0.3.0
4
62
 
5
63
  ### Minor 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 {
@@ -10,49 +10,63 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _XataApiClient_extraProps;
13
+ var _XataApiClient_extraProps, _XataApiClient_namespaces;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.XataApiClient = void 0;
16
+ const config_1 = require("../util/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
- }
24
+ _XataApiClient_namespaces.set(this, {});
27
25
  const provider = (_a = options.host) !== null && _a !== void 0 ? _a : 'production';
26
+ const apiKey = (_b = options === null || options === void 0 ? void 0 : options.apiKey) !== null && _b !== void 0 ? _b : (0, config_1.getAPIKey)();
27
+ if (!apiKey) {
28
+ throw new Error('Could not resolve a valid apiKey');
29
+ }
28
30
  __classPrivateFieldSet(this, _XataApiClient_extraProps, {
29
31
  apiUrl: (0, providers_1.getHostUrl)(provider, 'main'),
30
32
  workspacesApiUrl: (0, providers_1.getHostUrl)(provider, 'workspaces'),
31
- fetchImpl,
32
- apiKey: options.apiKey
33
+ fetchImpl: (0, fetch_1.getFetchImplementation)(options.fetch),
34
+ apiKey
33
35
  }, "f");
34
36
  }
35
37
  get user() {
36
- return new UserApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
38
+ if (!__classPrivateFieldGet(this, _XataApiClient_namespaces, "f").user)
39
+ __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").user = new UserApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
40
+ return __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").user;
37
41
  }
38
42
  get workspaces() {
39
- return new WorkspaceApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
43
+ if (!__classPrivateFieldGet(this, _XataApiClient_namespaces, "f").workspaces)
44
+ __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").workspaces = new WorkspaceApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
45
+ return __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").workspaces;
40
46
  }
41
47
  get databases() {
42
- return new DatabaseApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
48
+ if (!__classPrivateFieldGet(this, _XataApiClient_namespaces, "f").databases)
49
+ __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").databases = new DatabaseApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
50
+ return __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").databases;
43
51
  }
44
52
  get branches() {
45
- return new BranchApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
53
+ if (!__classPrivateFieldGet(this, _XataApiClient_namespaces, "f").branches)
54
+ __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").branches = new BranchApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
55
+ return __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").branches;
46
56
  }
47
57
  get tables() {
48
- return new TableApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
58
+ if (!__classPrivateFieldGet(this, _XataApiClient_namespaces, "f").tables)
59
+ __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").tables = new TableApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
60
+ return __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").tables;
49
61
  }
50
62
  get records() {
51
- return new RecordsApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
63
+ if (!__classPrivateFieldGet(this, _XataApiClient_namespaces, "f").records)
64
+ __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").records = new RecordsApi(__classPrivateFieldGet(this, _XataApiClient_extraProps, "f"));
65
+ return __classPrivateFieldGet(this, _XataApiClient_namespaces, "f").records;
52
66
  }
53
67
  }
54
68
  exports.XataApiClient = XataApiClient;
55
- _XataApiClient_extraProps = new WeakMap();
69
+ _XataApiClient_extraProps = new WeakMap(), _XataApiClient_namespaces = new WeakMap();
56
70
  class UserApi {
57
71
  constructor(extraProps) {
58
72
  this.extraProps = extraProps;
@@ -141,7 +155,7 @@ class BranchApi {
141
155
  getBranchDetails(workspace, database, branch) {
142
156
  return components_1.operationsByTag.branch.getBranchDetails(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}` } }, this.extraProps));
143
157
  }
144
- createBranch(workspace, database, branch, from, options = {}) {
158
+ createBranch(workspace, database, branch, from = '', options = {}) {
145
159
  return components_1.operationsByTag.branch.createBranch(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}` }, queryParams: { from }, body: options }, this.extraProps));
146
160
  }
147
161
  deleteBranch(workspace, database, branch) {
@@ -220,7 +234,9 @@ class RecordsApi {
220
234
  deleteRecord(workspace, database, branch, tableName, recordId) {
221
235
  return components_1.operationsByTag.records.deleteRecord(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId } }, this.extraProps));
222
236
  }
223
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
237
+ getRecord(workspace, database, branch, tableName, recordId,
238
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
239
+ options = {}) {
224
240
  return components_1.operationsByTag.records.getRecord(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId } }, this.extraProps));
225
241
  }
226
242
  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
  * {
@@ -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
- * We can also make the negation version, `$notExists` :
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/date ranges
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, we can add specific operators like `$isNot` to simplify expressions:
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:
@@ -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
  * {
@@ -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
- * We can also make the negation version, `$notExists` :
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/date ranges
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, we can add specific operators like `$isNot` to simplify expressions:
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:
@@ -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;
package/dist/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export declare class XataError extends Error {
4
4
  }
5
5
  export * from './api';
6
6
  export * from './schema';
7
+ export * from './util/config';
package/dist/index.js CHANGED
@@ -24,3 +24,4 @@ class XataError extends Error {
24
24
  exports.XataError = XataError;
25
25
  __exportStar(require("./api"), exports);
26
26
  __exportStar(require("./schema"), exports);
27
+ __exportStar(require("./util/config"), exports);