@xata.io/client 0.0.0-alpha.fed4b2b → 0.0.0-beta.036d273
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 +44 -0
- package/dist/api/client.d.ts +1 -1
- package/dist/api/client.js +32 -17
- 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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/schema/filters.d.ts +93 -18
- 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 +2 -1
- 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.js +0 -1
- package/dist/schema/query.d.ts +23 -19
- package/dist/schema/query.js +13 -19
- package/dist/schema/record.d.ts +23 -2
- package/dist/schema/record.js +2 -1
- package/dist/schema/repository.d.ts +100 -42
- package/dist/schema/repository.js +261 -154
- package/dist/schema/selection.d.ts +14 -17
- 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/config.d.ts +11 -0
- package/dist/util/config.js +121 -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 +11 -2
- 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
|
4
|
+
export { isIdentifiable, isXataRecord } from './record';
|
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;
|
@@ -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,15 +1,16 @@
|
|
1
1
|
import { FilterExpression } from '../api/schemas';
|
2
2
|
import { NonEmptyArray, RequiredBy } from '../util/types';
|
3
|
-
import {
|
3
|
+
import { Filter } from './filters';
|
4
4
|
import { Page, Paginable, PaginationOptions, PaginationQueryMeta } from './pagination';
|
5
5
|
import { XataRecord } from './record';
|
6
6
|
import { Repository } from './repository';
|
7
|
-
import { SelectableColumn,
|
7
|
+
import { SelectableColumn, SelectedPick, ValueAtColumn } from './selection';
|
8
|
+
import { SortDirection, SortFilter } from './sorting';
|
8
9
|
export declare type QueryOptions<T extends XataRecord> = {
|
9
10
|
page?: PaginationOptions;
|
10
11
|
columns?: NonEmptyArray<SelectableColumn<T>>;
|
11
12
|
filter?: FilterExpression;
|
12
|
-
sort?: SortFilter<T> |
|
13
|
+
sort?: SortFilter<T> | SortFilter<T>[];
|
13
14
|
};
|
14
15
|
/**
|
15
16
|
* Query objects contain the information of all filters, sorting, etc. to be included in the database query.
|
@@ -17,7 +18,7 @@ export declare type QueryOptions<T extends XataRecord> = {
|
|
17
18
|
* Query objects are immutable. Any method that adds more constraints or options to the query will return
|
18
19
|
* a new Query object containing the both the previous and the new constraints and options.
|
19
20
|
*/
|
20
|
-
export declare class Query<Record extends XataRecord, Result extends XataRecord> implements Paginable<Record, Result> {
|
21
|
+
export declare class Query<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
|
21
22
|
#private;
|
22
23
|
readonly meta: PaginationQueryMeta;
|
23
24
|
readonly records: Result[];
|
@@ -28,25 +29,25 @@ export declare class Query<Record extends XataRecord, Result extends XataRecord>
|
|
28
29
|
* @param queries An array of subqueries.
|
29
30
|
* @returns A new Query object.
|
30
31
|
*/
|
31
|
-
any(...queries: Query<Record,
|
32
|
+
any(...queries: Query<Record, any>[]): Query<Record, Result>;
|
32
33
|
/**
|
33
34
|
* Builds a new query object representing a logical AND between the given subqueries.
|
34
35
|
* @param queries An array of subqueries.
|
35
36
|
* @returns A new Query object.
|
36
37
|
*/
|
37
|
-
all(...queries: Query<Record,
|
38
|
+
all(...queries: Query<Record, any>[]): Query<Record, Result>;
|
38
39
|
/**
|
39
40
|
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
40
41
|
* @param queries An array of subqueries.
|
41
42
|
* @returns A new Query object.
|
42
43
|
*/
|
43
|
-
not(...queries: Query<Record,
|
44
|
+
not(...queries: Query<Record, any>[]): Query<Record, Result>;
|
44
45
|
/**
|
45
46
|
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
46
47
|
* @param queries An array of subqueries.
|
47
48
|
* @returns A new Query object.
|
48
49
|
*/
|
49
|
-
none(...queries: Query<Record,
|
50
|
+
none(...queries: Query<Record, any>[]): Query<Record, Result>;
|
50
51
|
/**
|
51
52
|
* Builds a new query object adding one or more constraints. Examples:
|
52
53
|
*
|
@@ -60,11 +61,10 @@ export declare class Query<Record extends XataRecord, Result extends XataRecord>
|
|
60
61
|
* })
|
61
62
|
* ```
|
62
63
|
*
|
63
|
-
* @param constraints
|
64
64
|
* @returns A new Query object.
|
65
65
|
*/
|
66
|
-
filter(
|
67
|
-
filter<F extends SelectableColumn<Record>>(column: F, value:
|
66
|
+
filter(filters: Filter<Record>): Query<Record, Result>;
|
67
|
+
filter<F extends SelectableColumn<Record>>(column: F, value: Filter<ValueAtColumn<Record, F>>): Query<Record, Result>;
|
68
68
|
/**
|
69
69
|
* Builds a new query with a new sort option.
|
70
70
|
* @param column The column name.
|
@@ -77,12 +77,14 @@ export declare class Query<Record extends XataRecord, Result extends XataRecord>
|
|
77
77
|
* @param columns Array of column names to be returned by the query.
|
78
78
|
* @returns A new Query object.
|
79
79
|
*/
|
80
|
-
select<K extends SelectableColumn<Record>>(columns: NonEmptyArray<K>): Query<Record,
|
80
|
+
select<K extends SelectableColumn<Record>>(columns: NonEmptyArray<K>): Query<Record, SelectedPick<Record, NonEmptyArray<K>>>;
|
81
81
|
getPaginated(): Promise<Page<Record, Result>>;
|
82
82
|
getPaginated(options: Omit<QueryOptions<Record>, 'columns'>): Promise<Page<Record, Result>>;
|
83
|
-
getPaginated<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<Page<Record,
|
84
|
-
[Symbol.asyncIterator]():
|
85
|
-
getIterator
|
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']>[]>;
|
86
88
|
/**
|
87
89
|
* Performs the query in the database and returns a set of results.
|
88
90
|
* @param options Additional options to be used when performing the query.
|
@@ -90,22 +92,24 @@ export declare class Query<Record extends XataRecord, Result extends XataRecord>
|
|
90
92
|
*/
|
91
93
|
getMany(): Promise<Result[]>;
|
92
94
|
getMany(options: Omit<QueryOptions<Record>, 'columns'>): Promise<Result[]>;
|
93
|
-
getMany<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<
|
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
110
|
getOne(): Promise<Result | null>;
|
107
|
-
getOne(options: Omit<QueryOptions<Record>, 'columns'>): Promise<Result | null>;
|
108
|
-
getOne<Options extends RequiredBy<QueryOptions<Record>, 'columns'>>(options: Options): Promise<
|
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>;
|
109
113
|
nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
110
114
|
previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
111
115
|
firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
package/dist/schema/query.js
CHANGED
@@ -51,7 +51,7 @@ const pagination_1 = require("./pagination");
|
|
51
51
|
*/
|
52
52
|
class Query {
|
53
53
|
constructor(repository, table, data, parent) {
|
54
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
54
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
55
55
|
_Query_table.set(this, void 0);
|
56
56
|
_Query_repository.set(this, void 0);
|
57
57
|
_Query_data.set(this, { filter: {} });
|
@@ -65,14 +65,14 @@ class Query {
|
|
65
65
|
else {
|
66
66
|
__classPrivateFieldSet(this, _Query_repository, this, "f");
|
67
67
|
}
|
68
|
-
__classPrivateFieldGet(this, _Query_data, "f").filter = {};
|
69
|
-
__classPrivateFieldGet(this, _Query_data, "f").filter.$any = (
|
70
|
-
__classPrivateFieldGet(this, _Query_data, "f").filter.$all = (
|
71
|
-
__classPrivateFieldGet(this, _Query_data, "f").filter.$not = (
|
72
|
-
__classPrivateFieldGet(this, _Query_data, "f").filter.$none = (
|
73
|
-
__classPrivateFieldGet(this, _Query_data, "f").sort = (
|
74
|
-
__classPrivateFieldGet(this, _Query_data, "f").columns = (
|
75
|
-
__classPrivateFieldGet(this, _Query_data, "f").page = (
|
68
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter = (_b = (_a = data.filter) !== null && _a !== void 0 ? _a : parent === null || parent === void 0 ? void 0 : parent.filter) !== null && _b !== void 0 ? _b : {};
|
69
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter.$any = (_d = (_c = data.filter) === null || _c === void 0 ? void 0 : _c.$any) !== null && _d !== void 0 ? _d : (_e = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _e === void 0 ? void 0 : _e.$any;
|
70
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter.$all = (_g = (_f = data.filter) === null || _f === void 0 ? void 0 : _f.$all) !== null && _g !== void 0 ? _g : (_h = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _h === void 0 ? void 0 : _h.$all;
|
71
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter.$not = (_k = (_j = data.filter) === null || _j === void 0 ? void 0 : _j.$not) !== null && _k !== void 0 ? _k : (_l = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _l === void 0 ? void 0 : _l.$not;
|
72
|
+
__classPrivateFieldGet(this, _Query_data, "f").filter.$none = (_o = (_m = data.filter) === null || _m === void 0 ? void 0 : _m.$none) !== null && _o !== void 0 ? _o : (_p = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _p === void 0 ? void 0 : _p.$none;
|
73
|
+
__classPrivateFieldGet(this, _Query_data, "f").sort = (_q = data.sort) !== null && _q !== void 0 ? _q : parent === null || parent === void 0 ? void 0 : parent.sort;
|
74
|
+
__classPrivateFieldGet(this, _Query_data, "f").columns = (_s = (_r = data.columns) !== null && _r !== void 0 ? _r : parent === null || parent === void 0 ? void 0 : parent.columns) !== null && _s !== void 0 ? _s : ['*'];
|
75
|
+
__classPrivateFieldGet(this, _Query_data, "f").page = (_t = data.page) !== null && _t !== void 0 ? _t : parent === null || parent === void 0 ? void 0 : parent.page;
|
76
76
|
this.any = this.any.bind(this);
|
77
77
|
this.all = this.all.bind(this);
|
78
78
|
this.not = this.not.bind(this);
|
@@ -143,7 +143,6 @@ class Query {
|
|
143
143
|
var _a;
|
144
144
|
const originalSort = [(_a = __classPrivateFieldGet(this, _Query_data, "f").sort) !== null && _a !== void 0 ? _a : []].flat();
|
145
145
|
const sort = [...originalSort, { column, direction }];
|
146
|
-
// @ts-ignore
|
147
146
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { sort }, __classPrivateFieldGet(this, _Query_data, "f"));
|
148
147
|
}
|
149
148
|
/**
|
@@ -156,7 +155,6 @@ class Query {
|
|
156
155
|
}
|
157
156
|
getPaginated(options = {}) {
|
158
157
|
const query = new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), options, __classPrivateFieldGet(this, _Query_data, "f"));
|
159
|
-
// @ts-ignore
|
160
158
|
return __classPrivateFieldGet(this, _Query_repository, "f").query(query);
|
161
159
|
}
|
162
160
|
[(_Query_table = new WeakMap(), _Query_repository = new WeakMap(), _Query_data = new WeakMap(), Symbol.asyncIterator)]() {
|
@@ -183,6 +181,7 @@ class Query {
|
|
183
181
|
let end = false;
|
184
182
|
while (!end) {
|
185
183
|
const { records, meta } = yield __await(this.getPaginated(Object.assign(Object.assign({}, options), { page: { size: chunk, offset } })));
|
184
|
+
// Method overloading does not provide type inference for the return type.
|
186
185
|
yield yield __await(records);
|
187
186
|
offset += chunk;
|
188
187
|
end = !meta.page.more;
|
@@ -192,16 +191,10 @@ class Query {
|
|
192
191
|
getMany(options = {}) {
|
193
192
|
return __awaiter(this, void 0, void 0, function* () {
|
194
193
|
const { records } = yield this.getPaginated(options);
|
195
|
-
//
|
194
|
+
// Method overloading does not provide type inference for the return type.
|
196
195
|
return records;
|
197
196
|
});
|
198
197
|
}
|
199
|
-
/**
|
200
|
-
* Performs the query in the database and returns all the results.
|
201
|
-
* Warning: If there are a large number of results, this method can have performance implications.
|
202
|
-
* @param options Additional options to be used when performing the query.
|
203
|
-
* @returns An array of records from the database.
|
204
|
-
*/
|
205
198
|
getAll(chunk = pagination_1.PAGINATION_MAX_SIZE, options = {}) {
|
206
199
|
var e_2, _a;
|
207
200
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -219,13 +212,14 @@ class Query {
|
|
219
212
|
}
|
220
213
|
finally { if (e_2) throw e_2.error; }
|
221
214
|
}
|
215
|
+
// Method overloading does not provide type inference for the return type.
|
222
216
|
return results;
|
223
217
|
});
|
224
218
|
}
|
225
219
|
getOne(options = {}) {
|
226
220
|
return __awaiter(this, void 0, void 0, function* () {
|
227
221
|
const records = yield this.getMany(Object.assign(Object.assign({}, options), { page: { size: 1 } }));
|
228
|
-
//
|
222
|
+
// Method overloading does not provide type inference for the return type.
|
229
223
|
return records[0] || null;
|
230
224
|
});
|
231
225
|
}
|
package/dist/schema/record.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { SelectedPick } from './selection';
|
1
2
|
/**
|
2
3
|
* Represents an identifiable record from the database.
|
3
4
|
*/
|
@@ -26,14 +27,14 @@ export interface XataRecord extends Identifiable {
|
|
26
27
|
/**
|
27
28
|
* Retrieves a refreshed copy of the current record from the database.
|
28
29
|
*/
|
29
|
-
read(): Promise<this>;
|
30
|
+
read(): Promise<SelectedPick<this, ['*']> | null>;
|
30
31
|
/**
|
31
32
|
* Performs a partial update of the current record. On success a new object is
|
32
33
|
* returned and the current object is not mutated.
|
33
34
|
* @param data The columns and their values that have to be updated.
|
34
35
|
* @returns A new record containing the latest values for all the columns of the current record.
|
35
36
|
*/
|
36
|
-
update(data: Partial<this
|
37
|
+
update(data: Partial<EditableData<Omit<this, keyof XataRecord>>>): Promise<SelectedPick<this, ['*']>>;
|
37
38
|
/**
|
38
39
|
* Performs a deletion of the current record in the database.
|
39
40
|
*
|
@@ -41,5 +42,25 @@ export interface XataRecord extends Identifiable {
|
|
41
42
|
*/
|
42
43
|
delete(): Promise<void>;
|
43
44
|
}
|
45
|
+
export declare type Link<Record extends XataRecord> = Omit<XataRecord, 'read' | 'update'> & {
|
46
|
+
/**
|
47
|
+
* Retrieves a refreshed copy of the current record from the database.
|
48
|
+
*/
|
49
|
+
read(): Promise<SelectedPick<Record, ['*']> | null>;
|
50
|
+
/**
|
51
|
+
* Performs a partial update of the current record. On success a new object is
|
52
|
+
* returned and the current object is not mutated.
|
53
|
+
* @param data The columns and their values that have to be updated.
|
54
|
+
* @returns A new record containing the latest values for all the columns of the current record.
|
55
|
+
*/
|
56
|
+
update(data: Partial<EditableData<Omit<Record, keyof XataRecord>>>): Promise<SelectedPick<Record, ['*']>>;
|
57
|
+
};
|
44
58
|
export declare function isIdentifiable(x: any): x is Identifiable & Record<string, unknown>;
|
45
59
|
export declare function isXataRecord(x: any): x is XataRecord & Record<string, unknown>;
|
60
|
+
export declare type EditableData<O extends BaseData> = {
|
61
|
+
[K in keyof O]: O[K] extends XataRecord ? {
|
62
|
+
id: string;
|
63
|
+
} : NonNullable<O[K]> extends XataRecord ? {
|
64
|
+
id: string;
|
65
|
+
} | null | undefined : O[K];
|
66
|
+
};
|
package/dist/schema/record.js
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.isXataRecord = exports.isIdentifiable = void 0;
|
4
|
+
const lang_1 = require("../util/lang");
|
4
5
|
function isIdentifiable(x) {
|
5
|
-
return
|
6
|
+
return (0, lang_1.isObject)(x) && (0, lang_1.isString)(x === null || x === void 0 ? void 0 : x.id);
|
6
7
|
}
|
7
8
|
exports.isIdentifiable = isIdentifiable;
|
8
9
|
function isXataRecord(x) {
|