@xata.io/client 0.0.0-beta.acc33d6 → 0.0.0-beta.b4a24ff

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 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,41 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 084f5df: Add type inference for columns
8
+ - bb73c89: Unify create and insert in a single method overload
9
+
10
+ ### Patch Changes
11
+
12
+ - 716c487: Forward nullable types on links
13
+ - bb66bb2: Fix error handling with createMany
14
+ - 084f5df: Fix circular dependencies on selectable column
15
+
16
+ ## 0.5.1
17
+
18
+ ### Patch Changes
19
+
20
+ - 12729ab: Make API client fetch implementation optional
21
+
22
+ ## 0.5.0
23
+
24
+ ### Patch Changes
25
+
26
+ - 14ec7d1: Fix in Selectable type
27
+
28
+ ## 0.4.0
29
+
30
+ ### Patch Changes
31
+
32
+ - b951331: Add support for new float column
33
+ - d470610: Add new getAll() method
34
+ - eaf92a8: Expose pagination constants (size and offset limits)
35
+ - 57fde77: Reduce subrequests for createMany
36
+ - eaf92a8: Implement schema-less client
37
+ - 97a3caa: Make createBranch from optional with empty branch
38
+
3
39
  ## 0.3.0
4
40
 
5
41
  ### Minor Changes
@@ -4,7 +4,7 @@ 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;
7
+ fetch?: FetchImpl;
8
8
  apiKey: string;
9
9
  host?: HostProvider;
10
10
  }
@@ -17,14 +17,15 @@ const components_1 = require("./components");
17
17
  const providers_1 = require("./providers");
18
18
  class XataApiClient {
19
19
  constructor(options) {
20
- var _a;
20
+ var _a, _b;
21
21
  _XataApiClient_extraProps.set(this, void 0);
22
- const fetchImpl = typeof fetch !== 'undefined' ? fetch : options.fetch;
22
+ const globalFetch = typeof fetch !== 'undefined' ? fetch : undefined;
23
+ const fetchImpl = (_a = options.fetch) !== null && _a !== void 0 ? _a : globalFetch;
23
24
  if (!fetchImpl) {
24
25
  /** @todo add a link after docs exist */
25
26
  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
  }
27
- const provider = (_a = options.host) !== null && _a !== void 0 ? _a : 'production';
28
+ const provider = (_b = options.host) !== null && _b !== void 0 ? _b : 'production';
28
29
  __classPrivateFieldSet(this, _XataApiClient_extraProps, {
29
30
  apiUrl: (0, providers_1.getHostUrl)(provider, 'main'),
30
31
  workspacesApiUrl: (0, providers_1.getHostUrl)(provider, 'workspaces'),
@@ -141,7 +142,7 @@ class BranchApi {
141
142
  getBranchDetails(workspace, database, branch) {
142
143
  return components_1.operationsByTag.branch.getBranchDetails(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}` } }, this.extraProps));
143
144
  }
144
- createBranch(workspace, database, branch, from, options = {}) {
145
+ createBranch(workspace, database, branch, from = '', options = {}) {
145
146
  return components_1.operationsByTag.branch.createBranch(Object.assign({ pathParams: { workspace, dbBranchName: `${database}:${branch}` }, queryParams: { from }, body: options }, this.extraProps));
146
147
  }
147
148
  deleteBranch(workspace, database, branch) {
@@ -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;
@@ -130,7 +130,7 @@ export declare type Table = {
130
130
  */
131
131
  export declare type Column = {
132
132
  name: string;
133
- type: 'bool' | 'int' | 'string' | 'text' | 'email' | 'multiple' | 'link' | 'object';
133
+ type: 'bool' | 'int' | 'float' | 'string' | 'text' | 'email' | 'multiple' | 'link' | 'object';
134
134
  link?: {
135
135
  table: string;
136
136
  };
@@ -1,20 +1,96 @@
1
- export declare type SortDirection = 'asc' | 'desc';
2
- export declare type SortFilterExtended<T> = {
3
- column: keyof T;
4
- direction?: SortDirection;
1
+ import { SingleOrArray } from '../util/types';
2
+ import { SelectableColumn, ValueAtColumn } from './selection';
3
+ /**
4
+ * PropertyMatchFilter
5
+ * Example:
6
+ {
7
+ "filter": {
8
+ "name": "value",
9
+ "name": {
10
+ "$is": "value",
11
+ "$any": [ "value1", "value2" ],
12
+ },
13
+ "settings.plan": {"$any": ["free", "paid"]},
14
+ "settings.plan": "free",
15
+ "settings": {
16
+ "plan": "free"
17
+ },
18
+ }
19
+ }
20
+ */
21
+ declare type PropertyAccessFilter<Record> = {
22
+ [key in SelectableColumn<Record>]?: NestedApiFilter<ValueAtColumn<Record, key>> | PropertyFilter<ValueAtColumn<Record, key>>;
5
23
  };
6
- export declare type SortFilter<T> = SortFilterExtended<T> | keyof T;
7
- export declare function isSortFilterObject<T>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
8
- export declare type FilterOperator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
9
- export declare function buildSortFilter<T>(filter?: SortFilter<T> | SortFilter<T>[]): {
10
- [key: string]: SortDirection;
11
- } | undefined;
12
- export declare type Constraint<T> = {
13
- [key in FilterOperator]?: T;
24
+ export declare type PropertyFilter<T> = T | {
25
+ $is: T;
26
+ } | {
27
+ $isNot: T;
28
+ } | {
29
+ $any: T[];
30
+ } | {
31
+ $none: T[];
32
+ } | ValueTypeFilters<T>;
33
+ declare type IncludesFilter<T> = PropertyFilter<T> | {
34
+ [key in '$all' | '$none' | '$any']?: IncludesFilter<T> | Array<IncludesFilter<T> | {
35
+ $not: IncludesFilter<T>;
36
+ }>;
14
37
  };
15
- export declare type DeepConstraint<T> = T extends Record<string, any> ? {
16
- [key in keyof T]?: T[key] | DeepConstraint<T[key]>;
17
- } : Constraint<T>;
18
- export declare type FilterConstraints<T> = {
19
- [key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>;
38
+ export declare type StringTypeFilter = {
39
+ [key in '$contains' | '$pattern' | '$startsWith' | '$endsWith']?: string;
20
40
  };
41
+ export declare type ComparableType = number | Date;
42
+ export declare type ComparableTypeFilter<T extends ComparableType> = {
43
+ [key in '$gt' | '$lt' | '$ge' | '$le']?: T;
44
+ };
45
+ export declare type ArrayFilter<T> = {
46
+ [key in '$includes']?: SingleOrArray<PropertyFilter<T> | ValueTypeFilters<T>> | IncludesFilter<T>;
47
+ } | {
48
+ [key in '$includesAll' | '$includesNone' | '$includesAny']?: T | Array<PropertyFilter<T> | {
49
+ $not: PropertyFilter<T>;
50
+ }>;
51
+ };
52
+ declare type ValueTypeFilters<T> = T | T extends string ? StringTypeFilter : T extends number ? ComparableTypeFilter<number> : T extends Date ? ComparableTypeFilter<Date> : T extends Array<infer T> ? ArrayFilter<T> : never;
53
+ /**
54
+ * AggregatorFilter
55
+ * Example:
56
+ {
57
+ "filter": {
58
+ "$any": {
59
+ "settings.dark": true,
60
+ "settings.plan": "free"
61
+ }
62
+ },
63
+ }
64
+ {
65
+ "filter": {
66
+ "$any": [
67
+ {
68
+ "name": "r1",
69
+ },
70
+ {
71
+ "name": "r2",
72
+ },
73
+ ],
74
+ }
75
+ */
76
+ declare type AggregatorFilter<Record> = {
77
+ [key in '$all' | '$any' | '$not' | '$none']?: SingleOrArray<Filter<Record>>;
78
+ };
79
+ /**
80
+ * Existance filter
81
+ * Example: { filter: { $exists: "settings" } }
82
+ */
83
+ export declare type ExistanceFilter<Record> = {
84
+ [key in '$exists' | '$notExists']?: SelectableColumn<Record>;
85
+ };
86
+ declare type BaseApiFilter<Record> = PropertyAccessFilter<Record> | AggregatorFilter<Record> | ExistanceFilter<Record>;
87
+ /**
88
+ * Nested filter
89
+ * Injects the Api filters on nested properties
90
+ * Example: { filter: { settings: { plan: { $any: ['free', 'trial'] } } } }
91
+ */
92
+ declare type NestedApiFilter<T> = T extends Record<string, any> ? {
93
+ [key in keyof T]?: T[key] extends Record<string, any> ? SingleOrArray<Filter<T[key]>> : PropertyFilter<T[key]>;
94
+ } : PropertyFilter<T>;
95
+ export declare type Filter<Record> = BaseApiFilter<Record> | NestedApiFilter<Record>;
96
+ export {};
@@ -1,24 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildSortFilter = exports.isSortFilterObject = void 0;
4
- function isSortFilterObject(filter) {
5
- return typeof filter === 'object' && filter.column !== undefined;
6
- }
7
- exports.isSortFilterObject = isSortFilterObject;
8
- function buildSortFilter(filter) {
9
- if (!filter)
10
- return undefined;
11
- const filters = Array.isArray(filter) ? filter : [filter];
12
- return filters.reduce((acc, item) => {
13
- if (typeof item === 'string') {
14
- return Object.assign(Object.assign({}, acc), { [item]: 'asc' });
15
- }
16
- else if (isSortFilterObject(item)) {
17
- return Object.assign(Object.assign({}, acc), { [item.column]: item.direction });
18
- }
19
- else {
20
- return acc;
21
- }
22
- }, {});
23
- }
24
- exports.buildSortFilter = buildSortFilter;
@@ -0,0 +1 @@
1
+ export {};