@xata.io/client 0.5.1 → 0.7.1
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 +35 -0
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.js +11 -9
- package/dist/api/components.d.ts +7 -6
- package/dist/api/components.js +7 -6
- 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 +26 -24
- package/dist/schema/operators.js +13 -11
- package/dist/schema/pagination.d.ts +13 -13
- package/dist/schema/pagination.js +0 -1
- package/dist/schema/query.d.ts +39 -50
- package/dist/schema/query.js +25 -37
- package/dist/schema/record.d.ts +25 -3
- package/dist/schema/record.js +11 -0
- package/dist/schema/repository.d.ts +79 -35
- package/dist/schema/repository.js +212 -114
- package/dist/schema/selection.d.ts +24 -11
- 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 +5 -2
@@ -0,0 +1,175 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
// Single column with implicit is
|
4
|
+
const singleColumnWithImplicitIs = { name: 'r2' };
|
5
|
+
// Single column with explicit is
|
6
|
+
const singleColumnWithExplicitIs = { name: { $is: 'r2' } };
|
7
|
+
// Is string
|
8
|
+
const isString = { string: 'string' };
|
9
|
+
// Is true
|
10
|
+
const isTrue = { boolean: true };
|
11
|
+
// Is false
|
12
|
+
const isFalse = { boolean: false };
|
13
|
+
// Is pos int
|
14
|
+
const isPosInt = { number: 1234567 };
|
15
|
+
// Is neg int
|
16
|
+
const isNegInt = { number: -42 };
|
17
|
+
// Is float
|
18
|
+
const isFloat = { number: 3.14 };
|
19
|
+
// with dots
|
20
|
+
const withDots = { 'settings.plan': 'free' };
|
21
|
+
// Nested columns
|
22
|
+
const nestedColumns = { settings: { plan: 'free' } };
|
23
|
+
// Nested columns array
|
24
|
+
const nestedColumnsArray = { settings: [{ dark: false }, { plan: 'free' }] };
|
25
|
+
// Nested columns any
|
26
|
+
const nestedColumnsAny = { settings: { $any: [{ plan: 'free' }, { plan: 'trial' }] } };
|
27
|
+
// Nested columns any value
|
28
|
+
const nestedColumnsAnyValue = { settings: { plan: { $any: ['free', 'trial'] } } };
|
29
|
+
// Or with $any
|
30
|
+
const orWithAny = { 'settings.plan': { $any: ['free', 'paid'] } };
|
31
|
+
// Multiple columns implicit and
|
32
|
+
const multipleColumnsImplicitAnd = { 'settings.dark': true, 'settings.plan': 'free' };
|
33
|
+
// Explicit $all with multi-key filter list
|
34
|
+
const explicitAllWithMultiKeyFilterList = {
|
35
|
+
$all: { 'settings.dark': true, 'settings.plan': 'free' }
|
36
|
+
};
|
37
|
+
// Explicit $all with filter list
|
38
|
+
const explicitAllWithFilterList = {
|
39
|
+
$all: [{ 'settings.dark': true }, { 'settings.plan': 'free' }]
|
40
|
+
};
|
41
|
+
// Explicit $any with multi-key filter list
|
42
|
+
const explicitAnyWithMultiKeyFilterList = {
|
43
|
+
$all: { 'settings.dark': true, 'settings.plan': 'free' }
|
44
|
+
};
|
45
|
+
// Explicit $any with filter list
|
46
|
+
const explicitAnyWithFilterList = {
|
47
|
+
$any: [{ 'settings.dark': true }, { 'settings.plan': 'free' }]
|
48
|
+
};
|
49
|
+
// $any with multiple values
|
50
|
+
const anyWithMultipleValues = { number: { $any: [1, 2, 3] } };
|
51
|
+
// $none with multiple values
|
52
|
+
const noneWithMultipleValues = { number: { $none: [1, 2, 3] } };
|
53
|
+
// Exists filter
|
54
|
+
const existsFilter = { $exists: 'test' };
|
55
|
+
// Not exists filter
|
56
|
+
const notExistsFilter = { $notExists: 'test' };
|
57
|
+
// Exists with all
|
58
|
+
const existsWithAll = { $all: [{ $exists: 'settings' }, { $exists: 'name' }] };
|
59
|
+
// Nest any with not
|
60
|
+
const nestAnyWithNot = { $not: { $any: { 'settings.dark': true, 'settings.plan': 'free' } } };
|
61
|
+
// Mix $all and $any with extra keys
|
62
|
+
const mixAllAndAnyWithExtraKeys = {
|
63
|
+
$all: { $any: { 'settings.dark': false, 'settings.plan': 'free' }, name: 'r1' }
|
64
|
+
};
|
65
|
+
// Range query with less first
|
66
|
+
const rangeQueryWithLessFirst = { age: { $lt: 30, $ge: 20 } };
|
67
|
+
// Range query with greater first
|
68
|
+
const rangeQueryWithGreaterFirst = { age: { $ge: 20, $lt: 30 } };
|
69
|
+
// Ordered op
|
70
|
+
const orderedOp = { age: { $lt: 30 } };
|
71
|
+
// Simple includes
|
72
|
+
const simpleIncludes = { labels: { $includes: 'test' } };
|
73
|
+
// Simple includes with op
|
74
|
+
const simpleIncludesWithOp = { labels: { $includes: { $contains: 'test' } } };
|
75
|
+
// Simple includes multiple
|
76
|
+
const simpleIncludesMultiple = { labels: { $includes: ['a', 'b', 'c'] } };
|
77
|
+
// Simple includes multiple with op
|
78
|
+
const simpleIncludesMultipleWithOp = {
|
79
|
+
labels: { $includes: [{ $is: 'a' }, { $is: 'b' }, { $is: 'c' }] }
|
80
|
+
};
|
81
|
+
// Includes with many comparisons
|
82
|
+
const includesWithManyComparisons = {
|
83
|
+
labels: { $includes: { $all: [{ $contains: 'a' }, { $contains: 'b' }] } }
|
84
|
+
};
|
85
|
+
// Simple includes multiple op and value
|
86
|
+
const simpleIncludesMultipleOpAndValue = { labels: { $includes: [{ $contains: 'a' }, 'b'] } };
|
87
|
+
// Includes with mode and array of filters
|
88
|
+
const includesWithModeAndArrayOfFilters = {
|
89
|
+
labels: { $includesNone: [{ $contains: 'test' }, 'abc', { $endsWith: 'bad' }] }
|
90
|
+
};
|
91
|
+
// Includes with mix of any and all in predicate position
|
92
|
+
const includesWithMixOfAnyAndAllInPredicatePosition = {
|
93
|
+
labels: { $includes: { $any: { $all: [{ $startsWith: 'test' }, { $contains: 'x' }], $any: ['a', 'b'] } } }
|
94
|
+
};
|
95
|
+
// Simple $includesany
|
96
|
+
const simpleIncludesAny = { labels: { $includesAny: 'test' } };
|
97
|
+
// Simple $includesall
|
98
|
+
const simpleIncludesAll = { labels: { $includesAll: 'test' } };
|
99
|
+
// Simple $includesnone
|
100
|
+
const simpleIncludesNone = { labels: { $includesNone: 'test' } };
|
101
|
+
// Exists value must be string not int
|
102
|
+
// @ts-expect-error
|
103
|
+
const existsValueMustBeStringNotInt = { $exists: 42 };
|
104
|
+
// Exists value must be string not objct
|
105
|
+
// @ts-expect-error
|
106
|
+
const existsValueMustBeStringNotObject = { $exists: { field: 'settings.unknown' } };
|
107
|
+
// Filter by one column
|
108
|
+
const filterByOneColumn = { name: 'r1' };
|
109
|
+
// Filter with the $is operator
|
110
|
+
const filterWithTheIsOperator = { name: { $is: 'r1' } };
|
111
|
+
// Filter with dot notation
|
112
|
+
const filterWithDotNotation = { 'settings.plan': 'free' };
|
113
|
+
// Filter with nested object
|
114
|
+
const filterWithNestedObject = { 'settings.plan': { $is: 'free' } };
|
115
|
+
// Filter with $any operation
|
116
|
+
const filterWithAnyOperation = { 'settings.plan': { $any: ['free', 'paid'] } };
|
117
|
+
// Filter with and operations
|
118
|
+
const filterWithAndOperations = { 'settings.dark': true, 'settings.plan': 'free' };
|
119
|
+
// Filter with both and and any operations
|
120
|
+
const filterWithBothAndAndAnyOperations = {
|
121
|
+
$any: { 'settings.dark': true, 'settings.plan': 'free' }
|
122
|
+
};
|
123
|
+
// Filter with both and and any operations in array
|
124
|
+
const filterWithBothAndAndAnyOperationsInArray = { $any: [{ name: 'r1' }, { name: 'r2' }] };
|
125
|
+
// Filter with exists operation
|
126
|
+
const filterWithExistsOperation = { $exists: 'settings' };
|
127
|
+
// Filter with exists, and and any operations
|
128
|
+
const filterWithExistsAndAndAnyOperations = {
|
129
|
+
$all: [{ $exists: 'settings' }, { $exists: 'name' }]
|
130
|
+
};
|
131
|
+
// Filter with not exists operation
|
132
|
+
const filterWithNotExistsOperation = { $notExists: 'settings' };
|
133
|
+
// Filter with partial match
|
134
|
+
const filterWithPartialMatch = { name: { $contains: 'value' } };
|
135
|
+
// Filter with pattern operator
|
136
|
+
const filterWithPatternOperator = { name: { $pattern: 'value' } };
|
137
|
+
// Filter with $startsWith and $endsWith operators
|
138
|
+
const filterWithStartsWithAndEndsWithOperators = {
|
139
|
+
name: { $startsWith: 'value', $endsWith: 'value' }
|
140
|
+
};
|
141
|
+
// Filter with numeric ranges
|
142
|
+
const filterWithNumericRanges = { age: { $lt: 30, $ge: 20 } };
|
143
|
+
// Filter with negations
|
144
|
+
const filterWithNegations = { $not: { name: 'r1' } };
|
145
|
+
// Filter with complex negations
|
146
|
+
const filterWithComplexNegations = { $not: { $any: [{ name: 'r1' }, { name: 'r2' }] } };
|
147
|
+
// Filter with arrays complex negations
|
148
|
+
const filterWithArraysComplexNegations = {
|
149
|
+
labels: {
|
150
|
+
$includes: {
|
151
|
+
$all: [{ $contains: 'label' }, { $not: { $endsWith: '-debug' } }]
|
152
|
+
}
|
153
|
+
}
|
154
|
+
};
|
155
|
+
// Filters with $includesAll
|
156
|
+
const filtersWithIncludesAll = {
|
157
|
+
'settings.labels': {
|
158
|
+
$includesAll: [{ $contains: 'label' }]
|
159
|
+
}
|
160
|
+
};
|
161
|
+
// Filter with invalid property type
|
162
|
+
// @ts-expect-error
|
163
|
+
const filterWithInvalidPropertyType = { name: 42 };
|
164
|
+
// Filter with invalid dot notation property type
|
165
|
+
// @ts-expect-error
|
166
|
+
const filterWithInvalidNestedPropertyType = { 'settings.plan': 42 };
|
167
|
+
// Filter with invalid nested object property type
|
168
|
+
// @ts-expect-error
|
169
|
+
const filterWithInvalidNestedObjectPropertyType = { settings: { plan: 42 } };
|
170
|
+
// Filter with invalid property $is type
|
171
|
+
// @ts-expect-error
|
172
|
+
const filterWithInvalidOperator = { name: { $is: 42 } };
|
173
|
+
test('fake test', () => {
|
174
|
+
// This is a fake test to make sure that the type definitions in this file are working
|
175
|
+
});
|
package/dist/schema/index.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
export * from './operators';
|
2
2
|
export * from './pagination';
|
3
3
|
export { Query } from './query';
|
4
|
+
export { isIdentifiable, isXataRecord } from './record';
|
4
5
|
export type { Identifiable, XataRecord } from './record';
|
5
6
|
export { BaseClient, Repository, RestRepository, RestRespositoryFactory } from './repository';
|
6
7
|
export type { XataClientOptions } from './repository';
|
package/dist/schema/index.js
CHANGED
@@ -14,11 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.BaseClient = exports.Query = void 0;
|
17
|
+
exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.BaseClient = exports.isXataRecord = exports.isIdentifiable = exports.Query = void 0;
|
18
18
|
__exportStar(require("./operators"), exports);
|
19
19
|
__exportStar(require("./pagination"), exports);
|
20
20
|
var query_1 = require("./query");
|
21
21
|
Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
|
22
|
+
var record_1 = require("./record");
|
23
|
+
Object.defineProperty(exports, "isIdentifiable", { enumerable: true, get: function () { return record_1.isIdentifiable; } });
|
24
|
+
Object.defineProperty(exports, "isXataRecord", { enumerable: true, get: function () { return record_1.isXataRecord; } });
|
22
25
|
var repository_1 = require("./repository");
|
23
26
|
Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
|
24
27
|
Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
|
@@ -1,72 +1,74 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import { ArrayFilter, ComparableType, ComparableTypeFilter, ExistanceFilter, PropertyFilter, StringTypeFilter } from './filters';
|
2
|
+
import { SelectableColumn } from './selection';
|
3
3
|
/**
|
4
4
|
* Operator to restrict results to only values that are greater than the given value.
|
5
5
|
*/
|
6
|
-
export declare const gt: <T extends ComparableType>(value: T) =>
|
6
|
+
export declare const gt: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
7
7
|
/**
|
8
8
|
* Operator to restrict results to only values that are greater than or equal to the given value.
|
9
9
|
*/
|
10
|
-
export declare const ge: <T extends ComparableType>(value: T) =>
|
10
|
+
export declare const ge: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
11
11
|
/**
|
12
12
|
* Operator to restrict results to only values that are greater than or equal to the given value.
|
13
13
|
*/
|
14
|
-
export declare const gte: <T extends ComparableType>(value: T) =>
|
14
|
+
export declare const gte: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
15
15
|
/**
|
16
16
|
* Operator to restrict results to only values that are lower than the given value.
|
17
17
|
*/
|
18
|
-
export declare const lt: <T extends ComparableType>(value: T) =>
|
18
|
+
export declare const lt: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
19
19
|
/**
|
20
20
|
* Operator to restrict results to only values that are lower than or equal to the given value.
|
21
21
|
*/
|
22
|
-
export declare const lte: <T extends ComparableType>(value: T) =>
|
22
|
+
export declare const lte: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
23
23
|
/**
|
24
24
|
* Operator to restrict results to only values that are lower than or equal to the given value.
|
25
25
|
*/
|
26
|
-
export declare const le: <T extends ComparableType>(value: T) =>
|
26
|
+
export declare const le: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
|
27
27
|
/**
|
28
28
|
* Operator to restrict results to only values that are not null.
|
29
29
|
*/
|
30
|
-
export declare const exists: (column:
|
30
|
+
export declare const exists: <T>(column: SelectableColumn<T, []>) => ExistanceFilter<T>;
|
31
31
|
/**
|
32
32
|
* Operator to restrict results to only values that are null.
|
33
33
|
*/
|
34
|
-
export declare const notExists: (column:
|
34
|
+
export declare const notExists: <T>(column: SelectableColumn<T, []>) => ExistanceFilter<T>;
|
35
35
|
/**
|
36
36
|
* Operator to restrict results to only values that start with the given prefix.
|
37
37
|
*/
|
38
|
-
export declare const startsWith: (value: string) =>
|
38
|
+
export declare const startsWith: (value: string) => StringTypeFilter;
|
39
39
|
/**
|
40
40
|
* Operator to restrict results to only values that end with the given suffix.
|
41
41
|
*/
|
42
|
-
export declare const endsWith: (value: string) =>
|
42
|
+
export declare const endsWith: (value: string) => StringTypeFilter;
|
43
43
|
/**
|
44
44
|
* Operator to restrict results to only values that match the given pattern.
|
45
45
|
*/
|
46
|
-
export declare const pattern: (value: string) =>
|
46
|
+
export declare const pattern: (value: string) => StringTypeFilter;
|
47
47
|
/**
|
48
48
|
* Operator to restrict results to only values that are equal to the given value.
|
49
49
|
*/
|
50
|
-
export declare const is: <T>(value: T) =>
|
50
|
+
export declare const is: <T>(value: T) => PropertyFilter<T>;
|
51
51
|
/**
|
52
52
|
* Operator to restrict results to only values that are not equal to the given value.
|
53
53
|
*/
|
54
|
-
export declare const isNot: <T>(value: T) =>
|
54
|
+
export declare const isNot: <T>(value: T) => PropertyFilter<T>;
|
55
55
|
/**
|
56
56
|
* Operator to restrict results to only values that contain the given value.
|
57
57
|
*/
|
58
|
-
export declare const contains:
|
58
|
+
export declare const contains: (value: string) => StringTypeFilter;
|
59
59
|
/**
|
60
|
-
* Operator to restrict results
|
60
|
+
* Operator to restrict results if some array items match the predicate.
|
61
61
|
*/
|
62
|
-
export declare const includes: (value:
|
62
|
+
export declare const includes: <T>(value: T) => ArrayFilter<T>;
|
63
63
|
/**
|
64
|
-
* Operator to restrict results
|
64
|
+
* Operator to restrict results if all array items match the predicate.
|
65
65
|
*/
|
66
|
-
export declare const
|
66
|
+
export declare const includesAll: <T>(value: T) => ArrayFilter<T>;
|
67
67
|
/**
|
68
|
-
* Operator to restrict results
|
68
|
+
* Operator to restrict results if none array items match the predicate.
|
69
69
|
*/
|
70
|
-
export declare const
|
71
|
-
|
72
|
-
|
70
|
+
export declare const includesNone: <T>(value: T) => ArrayFilter<T>;
|
71
|
+
/**
|
72
|
+
* Operator to restrict results if some array items match the predicate.
|
73
|
+
*/
|
74
|
+
export declare const includesAny: <T>(value: T) => ArrayFilter<T>;
|
package/dist/schema/operators.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.includesAny = exports.includesNone = exports.includesAll = exports.includes = exports.contains = exports.isNot = exports.is = exports.pattern = exports.endsWith = exports.startsWith = exports.notExists = exports.exists = exports.le = exports.lte = exports.lt = exports.gte = exports.ge = exports.gt = void 0;
|
4
4
|
/**
|
5
5
|
* Operator to restrict results to only values that are greater than the given value.
|
6
6
|
*/
|
@@ -71,21 +71,23 @@ exports.isNot = isNot;
|
|
71
71
|
*/
|
72
72
|
const contains = (value) => ({ $contains: value });
|
73
73
|
exports.contains = contains;
|
74
|
-
// TODO: these can only be applied to columns of type "multiple"
|
75
74
|
/**
|
76
|
-
* Operator to restrict results
|
75
|
+
* Operator to restrict results if some array items match the predicate.
|
77
76
|
*/
|
78
77
|
const includes = (value) => ({ $includes: value });
|
79
78
|
exports.includes = includes;
|
80
79
|
/**
|
81
|
-
* Operator to restrict results
|
80
|
+
* Operator to restrict results if all array items match the predicate.
|
82
81
|
*/
|
83
|
-
const includesSubstring = (value) => ({ $includesSubstring: value });
|
84
|
-
exports.includesSubstring = includesSubstring;
|
85
|
-
/**
|
86
|
-
* Operator to restrict results to only arrays that include a value matching the given pattern.
|
87
|
-
*/
|
88
|
-
const includesPattern = (value) => ({ $includesPattern: value });
|
89
|
-
exports.includesPattern = includesPattern;
|
90
82
|
const includesAll = (value) => ({ $includesAll: value });
|
91
83
|
exports.includesAll = includesAll;
|
84
|
+
/**
|
85
|
+
* Operator to restrict results if none array items match the predicate.
|
86
|
+
*/
|
87
|
+
const includesNone = (value) => ({ $includesNone: value });
|
88
|
+
exports.includesNone = includesNone;
|
89
|
+
/**
|
90
|
+
* Operator to restrict results if some array items match the predicate.
|
91
|
+
*/
|
92
|
+
const includesAny = (value) => ({ $includesAny: value });
|
93
|
+
exports.includesAny = includesAny;
|
@@ -6,20 +6,20 @@ export declare type PaginationQueryMeta = {
|
|
6
6
|
more: boolean;
|
7
7
|
};
|
8
8
|
};
|
9
|
-
export interface Paginable<
|
9
|
+
export interface Paginable<Record extends XataRecord, Result extends XataRecord = Record> {
|
10
10
|
meta: PaginationQueryMeta;
|
11
|
-
records:
|
12
|
-
nextPage(size?: number, offset?: number): Promise<Page<
|
13
|
-
previousPage(size?: number, offset?: number): Promise<Page<
|
14
|
-
firstPage(size?: number, offset?: number): Promise<Page<
|
15
|
-
lastPage(size?: number, offset?: number): Promise<Page<
|
11
|
+
records: Result[];
|
12
|
+
nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
13
|
+
previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
14
|
+
firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
15
|
+
lastPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
16
16
|
hasNextPage(): boolean;
|
17
17
|
}
|
18
18
|
/**
|
19
19
|
* A Page contains a set of results from a query plus metadata about the retrieved
|
20
20
|
* set of values such as the cursor, required to retrieve additional records.
|
21
21
|
*/
|
22
|
-
export declare class Page<
|
22
|
+
export declare class Page<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
|
23
23
|
#private;
|
24
24
|
/**
|
25
25
|
* Page metadata, required to retrieve additional records.
|
@@ -28,36 +28,36 @@ export declare class Page<T extends XataRecord, R extends XataRecord = T> implem
|
|
28
28
|
/**
|
29
29
|
* The set of results for this page.
|
30
30
|
*/
|
31
|
-
readonly records:
|
32
|
-
constructor(query: Query<
|
31
|
+
readonly records: Result[];
|
32
|
+
constructor(query: Query<Record, Result>, meta: PaginationQueryMeta, records?: Result[]);
|
33
33
|
/**
|
34
34
|
* Retrieves the next page of results.
|
35
35
|
* @param size Maximum number of results to be retrieved.
|
36
36
|
* @param offset Number of results to skip when retrieving the results.
|
37
37
|
* @returns The next page or results.
|
38
38
|
*/
|
39
|
-
nextPage(size?: number, offset?: number): Promise<Page<
|
39
|
+
nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
40
40
|
/**
|
41
41
|
* Retrieves the previous page of results.
|
42
42
|
* @param size Maximum number of results to be retrieved.
|
43
43
|
* @param offset Number of results to skip when retrieving the results.
|
44
44
|
* @returns The previous page or results.
|
45
45
|
*/
|
46
|
-
previousPage(size?: number, offset?: number): Promise<Page<
|
46
|
+
previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
47
47
|
/**
|
48
48
|
* Retrieves the first page of results.
|
49
49
|
* @param size Maximum number of results to be retrieved.
|
50
50
|
* @param offset Number of results to skip when retrieving the results.
|
51
51
|
* @returns The first page or results.
|
52
52
|
*/
|
53
|
-
firstPage(size?: number, offset?: number): Promise<Page<
|
53
|
+
firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
54
54
|
/**
|
55
55
|
* Retrieves the last page of results.
|
56
56
|
* @param size Maximum number of results to be retrieved.
|
57
57
|
* @param offset Number of results to skip when retrieving the results.
|
58
58
|
* @returns The last page or results.
|
59
59
|
*/
|
60
|
-
lastPage(size?: number, offset?: number): Promise<Page<
|
60
|
+
lastPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
61
61
|
/**
|
62
62
|
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
63
63
|
* @returns Whether or not there will be additional results in the next page of results.
|
@@ -77,7 +77,6 @@ class Page {
|
|
77
77
|
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
|
78
78
|
});
|
79
79
|
}
|
80
|
-
// TODO: We need to add something on the backend if we want a hasPreviousPage
|
81
80
|
/**
|
82
81
|
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
83
82
|
* @returns Whether or not there will be additional results in the next page of results.
|
package/dist/schema/query.d.ts
CHANGED
@@ -1,56 +1,53 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
1
|
+
import { FilterExpression } from '../api/schemas';
|
2
|
+
import { NonEmptyArray, RequiredBy } from '../util/types';
|
3
|
+
import { Filter } from './filters';
|
3
4
|
import { Page, Paginable, PaginationOptions, PaginationQueryMeta } from './pagination';
|
4
5
|
import { XataRecord } from './record';
|
5
6
|
import { Repository } from './repository';
|
6
|
-
import {
|
7
|
+
import { SelectableColumn, SelectedPick, ValueAtColumn } from './selection';
|
8
|
+
import { SortDirection, SortFilter } from './sorting';
|
7
9
|
export declare type QueryOptions<T extends XataRecord> = {
|
8
10
|
page?: PaginationOptions;
|
9
|
-
columns?:
|
11
|
+
columns?: NonEmptyArray<SelectableColumn<T>>;
|
12
|
+
filter?: FilterExpression;
|
10
13
|
sort?: SortFilter<T> | SortFilter<T>[];
|
11
14
|
};
|
12
|
-
export declare type QueryTableOptions = {
|
13
|
-
filter: FilterExpression;
|
14
|
-
sort?: SortExpression;
|
15
|
-
page?: PageConfig;
|
16
|
-
columns?: ColumnsFilter;
|
17
|
-
};
|
18
15
|
/**
|
19
16
|
* Query objects contain the information of all filters, sorting, etc. to be included in the database query.
|
20
17
|
*
|
21
18
|
* Query objects are immutable. Any method that adds more constraints or options to the query will return
|
22
19
|
* a new Query object containing the both the previous and the new constraints and options.
|
23
20
|
*/
|
24
|
-
export declare class Query<
|
21
|
+
export declare class Query<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
|
25
22
|
#private;
|
26
23
|
readonly meta: PaginationQueryMeta;
|
27
|
-
readonly records:
|
28
|
-
constructor(repository: Repository<
|
29
|
-
getQueryOptions():
|
24
|
+
readonly records: Result[];
|
25
|
+
constructor(repository: Repository<Record> | null, table: string, data: Partial<QueryOptions<Record>>, parent?: Partial<QueryOptions<Record>>);
|
26
|
+
getQueryOptions(): QueryOptions<Record>;
|
30
27
|
/**
|
31
28
|
* Builds a new query object representing a logical OR between the given subqueries.
|
32
29
|
* @param queries An array of subqueries.
|
33
30
|
* @returns A new Query object.
|
34
31
|
*/
|
35
|
-
any(...queries: Query<
|
32
|
+
any(...queries: Query<Record, any>[]): Query<Record, Result>;
|
36
33
|
/**
|
37
34
|
* Builds a new query object representing a logical AND between the given subqueries.
|
38
35
|
* @param queries An array of subqueries.
|
39
36
|
* @returns A new Query object.
|
40
37
|
*/
|
41
|
-
all(...queries: Query<
|
38
|
+
all(...queries: Query<Record, any>[]): Query<Record, Result>;
|
42
39
|
/**
|
43
40
|
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
44
41
|
* @param queries An array of subqueries.
|
45
42
|
* @returns A new Query object.
|
46
43
|
*/
|
47
|
-
not(...queries: Query<
|
44
|
+
not(...queries: Query<Record, any>[]): Query<Record, Result>;
|
48
45
|
/**
|
49
46
|
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
50
47
|
* @param queries An array of subqueries.
|
51
48
|
* @returns A new Query object.
|
52
49
|
*/
|
53
|
-
none(...queries: Query<
|
50
|
+
none(...queries: Query<Record, any>[]): Query<Record, Result>;
|
54
51
|
/**
|
55
52
|
* Builds a new query object adding one or more constraints. Examples:
|
56
53
|
*
|
@@ -64,66 +61,58 @@ export declare class Query<T extends XataRecord, R extends XataRecord = T> imple
|
|
64
61
|
* })
|
65
62
|
* ```
|
66
63
|
*
|
67
|
-
* @param constraints
|
68
64
|
* @returns A new Query object.
|
69
65
|
*/
|
70
|
-
filter(
|
71
|
-
filter<F extends
|
66
|
+
filter(filters: Filter<Record>): Query<Record, Result>;
|
67
|
+
filter<F extends SelectableColumn<Record>>(column: F, value: Filter<ValueAtColumn<Record, F>>): Query<Record, Result>;
|
72
68
|
/**
|
73
69
|
* Builds a new query with a new sort option.
|
74
70
|
* @param column The column name.
|
75
71
|
* @param direction The direction. Either ascending or descending.
|
76
72
|
* @returns A new Query object.
|
77
73
|
*/
|
78
|
-
sort<F extends
|
74
|
+
sort<F extends SelectableColumn<Record>>(column: F, direction: SortDirection): Query<Record, Result>;
|
79
75
|
/**
|
80
76
|
* Builds a new query specifying the set of columns to be returned in the query response.
|
81
77
|
* @param columns Array of column names to be returned by the query.
|
82
78
|
* @returns A new Query object.
|
83
79
|
*/
|
84
|
-
select<K extends SelectableColumn<
|
85
|
-
getPaginated
|
86
|
-
|
87
|
-
|
80
|
+
select<K extends SelectableColumn<Record>>(columns: NonEmptyArray<K>): Query<Record, SelectedPick<Record, NonEmptyArray<K>>>;
|
81
|
+
getPaginated(): Promise<Page<Record, Result>>;
|
82
|
+
getPaginated(options: Omit<QueryOptions<Record>, 'columns'>): Promise<Page<Record, Result>>;
|
83
|
+
getPaginated<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<Page<Record, SelectedPick<Record, typeof options['columns']>>>;
|
84
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Result>;
|
85
|
+
getIterator(chunk: number): AsyncGenerator<Result[]>;
|
86
|
+
getIterator(chunk: number, options: Omit<QueryOptions<Record>, 'columns' | 'page'>): AsyncGenerator<Result[]>;
|
87
|
+
getIterator<Options extends RequiredBy<Omit<QueryOptions<Record>, 'page'>, 'columns'>>(chunk: number, options: Options): AsyncGenerator<SelectedPick<Record, typeof options['columns']>[]>;
|
88
88
|
/**
|
89
89
|
* Performs the query in the database and returns a set of results.
|
90
90
|
* @param options Additional options to be used when performing the query.
|
91
91
|
* @returns An array of records from the database.
|
92
92
|
*/
|
93
|
-
getMany
|
93
|
+
getMany(): Promise<Result[]>;
|
94
|
+
getMany(options: Omit<QueryOptions<Record>, 'columns'>): Promise<Result[]>;
|
95
|
+
getMany<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<SelectedPick<Record, typeof options['columns']>[]>;
|
94
96
|
/**
|
95
97
|
* Performs the query in the database and returns all the results.
|
96
98
|
* Warning: If there are a large number of results, this method can have performance implications.
|
97
99
|
* @param options Additional options to be used when performing the query.
|
98
100
|
* @returns An array of records from the database.
|
99
101
|
*/
|
100
|
-
getAll
|
102
|
+
getAll(chunk?: number): Promise<Result[]>;
|
103
|
+
getAll(chunk: number | undefined, options: Omit<QueryOptions<Record>, 'columns' | 'page'>): Promise<Result[]>;
|
104
|
+
getAll<Options extends RequiredBy<Omit<QueryOptions<Record>, 'page'>, 'columns'>>(chunk: number | undefined, options: Options): Promise<SelectedPick<Record, typeof options['columns']>[]>;
|
101
105
|
/**
|
102
106
|
* Performs the query in the database and returns the first result.
|
103
107
|
* @param options Additional options to be used when performing the query.
|
104
108
|
* @returns The first record that matches the query, or null if no record matched the query.
|
105
109
|
*/
|
106
|
-
getOne
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
114
|
-
lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
110
|
+
getOne(): Promise<Result | null>;
|
111
|
+
getOne(options: Omit<QueryOptions<Record>, 'columns' | 'page'>): Promise<Result | null>;
|
112
|
+
getOne<Options extends RequiredBy<Omit<QueryOptions<Record>, 'page'>, 'columns'>>(options: Options): Promise<SelectedPick<Record, typeof options['columns']> | null>;
|
113
|
+
nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
114
|
+
previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
115
|
+
firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
116
|
+
lastPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
115
117
|
hasNextPage(): boolean;
|
116
118
|
}
|
117
|
-
/**
|
118
|
-
* Helper type to read options and compute the correct type for the result values
|
119
|
-
* T: Original type
|
120
|
-
* R: Default destination type
|
121
|
-
* Options: QueryOptions
|
122
|
-
*
|
123
|
-
* If the columns are overriden in the options, the result type is the pick of the original type and the columns
|
124
|
-
* If the columns are not overriden, the result type is the default destination type
|
125
|
-
*/
|
126
|
-
declare type GetWithColumnOptions<T, R, Options> = Options extends {
|
127
|
-
columns: SelectableColumn<T>[];
|
128
|
-
} ? Select<T, Options['columns'][number]> : R;
|
129
|
-
export {};
|