@xata.io/client 0.0.0-beta.2b5cc25 → 0.0.0-beta.343bbfe
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 +74 -0
- package/dist/api/client.d.ts +2 -2
- package/dist/api/client.js +33 -17
- package/dist/api/components.d.ts +34 -37
- package/dist/api/components.js +34 -37
- package/dist/api/fetcher.d.ts +15 -0
- package/dist/api/fetcher.js +23 -22
- package/dist/api/providers.js +3 -2
- package/dist/api/responses.d.ts +6 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.js +124 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/namespace.d.ts +7 -0
- package/dist/namespace.js +6 -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 +177 -0
- package/dist/schema/index.d.ts +17 -2
- package/dist/schema/index.js +29 -6
- package/dist/schema/operators.d.ts +26 -24
- package/dist/schema/operators.js +13 -11
- package/dist/schema/pagination.d.ts +14 -14
- package/dist/schema/pagination.js +0 -1
- package/dist/schema/query.d.ts +41 -51
- package/dist/schema/query.js +25 -37
- package/dist/schema/record.d.ts +28 -3
- package/dist/schema/record.js +11 -0
- package/dist/schema/repository.d.ts +90 -65
- package/dist/schema/repository.js +206 -202
- package/dist/schema/selection.d.ts +24 -13
- package/dist/schema/selection.spec.d.ts +1 -0
- package/dist/schema/selection.spec.js +204 -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 +11 -0
- package/dist/search/index.d.ts +20 -0
- package/dist/search/index.js +30 -0
- package/dist/util/branches.d.ts +5 -0
- package/dist/util/branches.js +7 -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 +23 -1
- package/package.json +5 -2
@@ -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;
|
@@ -1,25 +1,25 @@
|
|
1
|
-
import { XataRecord } from '..';
|
2
1
|
import { Query } from './query';
|
2
|
+
import { XataRecord } from './record';
|
3
3
|
export declare type PaginationQueryMeta = {
|
4
4
|
page: {
|
5
5
|
cursor: string;
|
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,55 +1,53 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import {
|
1
|
+
import { FilterExpression } from '../api/schemas';
|
2
|
+
import { NonEmptyArray, RequiredBy } from '../util/types';
|
3
|
+
import { Filter } from './filters';
|
4
4
|
import { Page, Paginable, PaginationOptions, PaginationQueryMeta } from './pagination';
|
5
|
-
import {
|
5
|
+
import { XataRecord } from './record';
|
6
|
+
import { Repository } from './repository';
|
7
|
+
import { SelectableColumn, SelectedPick, ValueAtColumn } from './selection';
|
8
|
+
import { SortDirection, SortFilter } from './sorting';
|
6
9
|
export declare type QueryOptions<T extends XataRecord> = {
|
7
10
|
page?: PaginationOptions;
|
8
|
-
columns?:
|
11
|
+
columns?: NonEmptyArray<SelectableColumn<T>>;
|
12
|
+
filter?: FilterExpression;
|
9
13
|
sort?: SortFilter<T> | SortFilter<T>[];
|
10
14
|
};
|
11
|
-
export declare type QueryTableOptions = {
|
12
|
-
filter: FilterExpression;
|
13
|
-
sort?: SortExpression;
|
14
|
-
page?: PageConfig;
|
15
|
-
columns?: ColumnsFilter;
|
16
|
-
};
|
17
15
|
/**
|
18
16
|
* Query objects contain the information of all filters, sorting, etc. to be included in the database query.
|
19
17
|
*
|
20
18
|
* Query objects are immutable. Any method that adds more constraints or options to the query will return
|
21
19
|
* a new Query object containing the both the previous and the new constraints and options.
|
22
20
|
*/
|
23
|
-
export declare class Query<
|
21
|
+
export declare class Query<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
|
24
22
|
#private;
|
25
23
|
readonly meta: PaginationQueryMeta;
|
26
|
-
readonly records:
|
27
|
-
constructor(repository: Repository<
|
28
|
-
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>;
|
29
27
|
/**
|
30
28
|
* Builds a new query object representing a logical OR between the given subqueries.
|
31
29
|
* @param queries An array of subqueries.
|
32
30
|
* @returns A new Query object.
|
33
31
|
*/
|
34
|
-
any(...queries: Query<
|
32
|
+
any(...queries: Query<Record, any>[]): Query<Record, Result>;
|
35
33
|
/**
|
36
34
|
* Builds a new query object representing a logical AND between the given subqueries.
|
37
35
|
* @param queries An array of subqueries.
|
38
36
|
* @returns A new Query object.
|
39
37
|
*/
|
40
|
-
all(...queries: Query<
|
38
|
+
all(...queries: Query<Record, any>[]): Query<Record, Result>;
|
41
39
|
/**
|
42
40
|
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
43
41
|
* @param queries An array of subqueries.
|
44
42
|
* @returns A new Query object.
|
45
43
|
*/
|
46
|
-
not(...queries: Query<
|
44
|
+
not(...queries: Query<Record, any>[]): Query<Record, Result>;
|
47
45
|
/**
|
48
46
|
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
49
47
|
* @param queries An array of subqueries.
|
50
48
|
* @returns A new Query object.
|
51
49
|
*/
|
52
|
-
none(...queries: Query<
|
50
|
+
none(...queries: Query<Record, any>[]): Query<Record, Result>;
|
53
51
|
/**
|
54
52
|
* Builds a new query object adding one or more constraints. Examples:
|
55
53
|
*
|
@@ -63,66 +61,58 @@ export declare class Query<T extends XataRecord, R extends XataRecord = T> imple
|
|
63
61
|
* })
|
64
62
|
* ```
|
65
63
|
*
|
66
|
-
* @param constraints
|
67
64
|
* @returns A new Query object.
|
68
65
|
*/
|
69
|
-
filter(
|
70
|
-
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>;
|
71
68
|
/**
|
72
69
|
* Builds a new query with a new sort option.
|
73
70
|
* @param column The column name.
|
74
71
|
* @param direction The direction. Either ascending or descending.
|
75
72
|
* @returns A new Query object.
|
76
73
|
*/
|
77
|
-
sort<F extends
|
74
|
+
sort<F extends SelectableColumn<Record>>(column: F, direction: SortDirection): Query<Record, Result>;
|
78
75
|
/**
|
79
76
|
* Builds a new query specifying the set of columns to be returned in the query response.
|
80
77
|
* @param columns Array of column names to be returned by the query.
|
81
78
|
* @returns A new Query object.
|
82
79
|
*/
|
83
|
-
select<K extends SelectableColumn<
|
84
|
-
getPaginated
|
85
|
-
|
86
|
-
|
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']>[]>;
|
87
88
|
/**
|
88
89
|
* Performs the query in the database and returns a set of results.
|
89
90
|
* @param options Additional options to be used when performing the query.
|
90
91
|
* @returns An array of records from the database.
|
91
92
|
*/
|
92
|
-
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']>[]>;
|
93
96
|
/**
|
94
97
|
* Performs the query in the database and returns all the results.
|
95
98
|
* Warning: If there are a large number of results, this method can have performance implications.
|
96
99
|
* @param options Additional options to be used when performing the query.
|
97
100
|
* @returns An array of records from the database.
|
98
101
|
*/
|
99
|
-
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']>[]>;
|
100
105
|
/**
|
101
106
|
* Performs the query in the database and returns the first result.
|
102
107
|
* @param options Additional options to be used when performing the query.
|
103
108
|
* @returns The first record that matches the query, or null if no record matched the query.
|
104
109
|
*/
|
105
|
-
getOne
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
113
|
-
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>>;
|
114
117
|
hasNextPage(): boolean;
|
115
118
|
}
|
116
|
-
/**
|
117
|
-
* Helper type to read options and compute the correct type for the result values
|
118
|
-
* T: Original type
|
119
|
-
* R: Default destination type
|
120
|
-
* Options: QueryOptions
|
121
|
-
*
|
122
|
-
* If the columns are overriden in the options, the result type is the pick of the original type and the columns
|
123
|
-
* If the columns are not overriden, the result type is the default destination type
|
124
|
-
*/
|
125
|
-
declare type GetWithColumnOptions<T, R, Options> = Options extends {
|
126
|
-
columns: SelectableColumn<T>[];
|
127
|
-
} ? Select<T, Options['columns'][number]> : R;
|
128
|
-
export {};
|
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;
|
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,12 +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.$
|
70
|
-
__classPrivateFieldGet(this, _Query_data, "f").filter.$
|
71
|
-
__classPrivateFieldGet(this, _Query_data, "f").filter.$
|
72
|
-
__classPrivateFieldGet(this, _Query_data, "f").
|
73
|
-
__classPrivateFieldGet(this, _Query_data, "f").
|
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;
|
74
76
|
this.any = this.any.bind(this);
|
75
77
|
this.all = this.all.bind(this);
|
76
78
|
this.not = this.not.bind(this);
|
@@ -89,7 +91,7 @@ class Query {
|
|
89
91
|
* @returns A new Query object.
|
90
92
|
*/
|
91
93
|
any(...queries) {
|
92
|
-
const $any = queries.map((query) => query.getQueryOptions().filter);
|
94
|
+
const $any = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
|
93
95
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $any } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
94
96
|
}
|
95
97
|
/**
|
@@ -98,7 +100,7 @@ class Query {
|
|
98
100
|
* @returns A new Query object.
|
99
101
|
*/
|
100
102
|
all(...queries) {
|
101
|
-
const $all = queries.map((query) => query.getQueryOptions().filter);
|
103
|
+
const $all = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
|
102
104
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
103
105
|
}
|
104
106
|
/**
|
@@ -107,7 +109,7 @@ class Query {
|
|
107
109
|
* @returns A new Query object.
|
108
110
|
*/
|
109
111
|
not(...queries) {
|
110
|
-
const $not = queries.map((query) => query.getQueryOptions().filter);
|
112
|
+
const $not = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
|
111
113
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $not } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
112
114
|
}
|
113
115
|
/**
|
@@ -116,19 +118,18 @@ class Query {
|
|
116
118
|
* @returns A new Query object.
|
117
119
|
*/
|
118
120
|
none(...queries) {
|
119
|
-
const $none = queries.map((query) => query.getQueryOptions().filter);
|
121
|
+
const $none = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
|
120
122
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $none } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
121
123
|
}
|
122
124
|
filter(a, b) {
|
125
|
+
var _a, _b;
|
123
126
|
if (arguments.length === 1) {
|
124
127
|
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
125
|
-
const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat(constraints));
|
128
|
+
const $all = (0, lang_1.compact)([(_a = __classPrivateFieldGet(this, _Query_data, "f").filter) === null || _a === void 0 ? void 0 : _a.$all].flat().concat(constraints));
|
126
129
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
127
130
|
}
|
128
131
|
else {
|
129
|
-
const
|
130
|
-
const value = b;
|
131
|
-
const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat({ [column]: value }));
|
132
|
+
const $all = (0, lang_1.compact)([(_b = __classPrivateFieldGet(this, _Query_data, "f").filter) === null || _b === void 0 ? void 0 : _b.$all].flat().concat([{ [a]: b }]));
|
132
133
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
133
134
|
}
|
134
135
|
}
|
@@ -139,7 +140,9 @@ class Query {
|
|
139
140
|
* @returns A new Query object.
|
140
141
|
*/
|
141
142
|
sort(column, direction) {
|
142
|
-
|
143
|
+
var _a;
|
144
|
+
const originalSort = [(_a = __classPrivateFieldGet(this, _Query_data, "f").sort) !== null && _a !== void 0 ? _a : []].flat();
|
145
|
+
const sort = [...originalSort, { column, direction }];
|
143
146
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { sort }, __classPrivateFieldGet(this, _Query_data, "f"));
|
144
147
|
}
|
145
148
|
/**
|
@@ -151,7 +154,8 @@ class Query {
|
|
151
154
|
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { columns }, __classPrivateFieldGet(this, _Query_data, "f"));
|
152
155
|
}
|
153
156
|
getPaginated(options = {}) {
|
154
|
-
|
157
|
+
const query = new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), options, __classPrivateFieldGet(this, _Query_data, "f"));
|
158
|
+
return __classPrivateFieldGet(this, _Query_repository, "f").query(query);
|
155
159
|
}
|
156
160
|
[(_Query_table = new WeakMap(), _Query_repository = new WeakMap(), _Query_data = new WeakMap(), Symbol.asyncIterator)]() {
|
157
161
|
return __asyncGenerator(this, arguments, function* _a() {
|
@@ -177,29 +181,20 @@ class Query {
|
|
177
181
|
let end = false;
|
178
182
|
while (!end) {
|
179
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.
|
180
185
|
yield yield __await(records);
|
181
186
|
offset += chunk;
|
182
187
|
end = !meta.page.more;
|
183
188
|
}
|
184
189
|
});
|
185
190
|
}
|
186
|
-
/**
|
187
|
-
* Performs the query in the database and returns a set of results.
|
188
|
-
* @param options Additional options to be used when performing the query.
|
189
|
-
* @returns An array of records from the database.
|
190
|
-
*/
|
191
191
|
getMany(options = {}) {
|
192
192
|
return __awaiter(this, void 0, void 0, function* () {
|
193
193
|
const { records } = yield this.getPaginated(options);
|
194
|
+
// Method overloading does not provide type inference for the return type.
|
194
195
|
return records;
|
195
196
|
});
|
196
197
|
}
|
197
|
-
/**
|
198
|
-
* Performs the query in the database and returns all the results.
|
199
|
-
* Warning: If there are a large number of results, this method can have performance implications.
|
200
|
-
* @param options Additional options to be used when performing the query.
|
201
|
-
* @returns An array of records from the database.
|
202
|
-
*/
|
203
198
|
getAll(chunk = pagination_1.PAGINATION_MAX_SIZE, options = {}) {
|
204
199
|
var e_2, _a;
|
205
200
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -217,24 +212,17 @@ class Query {
|
|
217
212
|
}
|
218
213
|
finally { if (e_2) throw e_2.error; }
|
219
214
|
}
|
215
|
+
// Method overloading does not provide type inference for the return type.
|
220
216
|
return results;
|
221
217
|
});
|
222
218
|
}
|
223
|
-
/**
|
224
|
-
* Performs the query in the database and returns the first result.
|
225
|
-
* @param options Additional options to be used when performing the query.
|
226
|
-
* @returns The first record that matches the query, or null if no record matched the query.
|
227
|
-
*/
|
228
219
|
getOne(options = {}) {
|
229
220
|
return __awaiter(this, void 0, void 0, function* () {
|
230
221
|
const records = yield this.getMany(Object.assign(Object.assign({}, options), { page: { size: 1 } }));
|
222
|
+
// Method overloading does not provide type inference for the return type.
|
231
223
|
return records[0] || null;
|
232
224
|
});
|
233
225
|
}
|
234
|
-
/**async deleteAll(): Promise<number> {
|
235
|
-
// TODO: Return number of affected rows
|
236
|
-
return 0;
|
237
|
-
}**/
|
238
226
|
nextPage(size, offset) {
|
239
227
|
return this.firstPage(size, offset);
|
240
228
|
}
|
package/dist/schema/record.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { SelectedPick } from './selection';
|
2
2
|
/**
|
3
3
|
* Represents an identifiable record from the database.
|
4
4
|
*/
|
@@ -8,6 +8,9 @@ export interface Identifiable {
|
|
8
8
|
*/
|
9
9
|
id: string;
|
10
10
|
}
|
11
|
+
export interface BaseData {
|
12
|
+
[key: string]: any;
|
13
|
+
}
|
11
14
|
/**
|
12
15
|
* Represents a persisted record from the database.
|
13
16
|
*/
|
@@ -24,14 +27,14 @@ export interface XataRecord extends Identifiable {
|
|
24
27
|
/**
|
25
28
|
* Retrieves a refreshed copy of the current record from the database.
|
26
29
|
*/
|
27
|
-
read(): Promise<this>;
|
30
|
+
read(): Promise<Readonly<SelectedPick<this, ['*']>> | null>;
|
28
31
|
/**
|
29
32
|
* Performs a partial update of the current record. On success a new object is
|
30
33
|
* returned and the current object is not mutated.
|
31
34
|
* @param data The columns and their values that have to be updated.
|
32
35
|
* @returns A new record containing the latest values for all the columns of the current record.
|
33
36
|
*/
|
34
|
-
update(
|
37
|
+
update(partialUpdate: Partial<EditableData<Omit<this, keyof XataRecord>>>): Promise<Readonly<SelectedPick<this, ['*']>>>;
|
35
38
|
/**
|
36
39
|
* Performs a deletion of the current record in the database.
|
37
40
|
*
|
@@ -39,3 +42,25 @@ export interface XataRecord extends Identifiable {
|
|
39
42
|
*/
|
40
43
|
delete(): Promise<void>;
|
41
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<Readonly<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(partialUpdate: Partial<EditableData<Omit<Record, keyof XataRecord>>>): Promise<Readonly<SelectedPick<Record, ['*']>>>;
|
57
|
+
};
|
58
|
+
export declare function isIdentifiable(x: any): x is Identifiable & Record<string, unknown>;
|
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,2 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isXataRecord = exports.isIdentifiable = void 0;
|
4
|
+
const lang_1 = require("../util/lang");
|
5
|
+
function isIdentifiable(x) {
|
6
|
+
return (0, lang_1.isObject)(x) && (0, lang_1.isString)(x === null || x === void 0 ? void 0 : x.id);
|
7
|
+
}
|
8
|
+
exports.isIdentifiable = isIdentifiable;
|
9
|
+
function isXataRecord(x) {
|
10
|
+
var _a;
|
11
|
+
return (isIdentifiable(x) && typeof (x === null || x === void 0 ? void 0 : x.xata) === 'object' && typeof ((_a = x === null || x === void 0 ? void 0 : x.xata) === null || _a === void 0 ? void 0 : _a.version) === 'number');
|
12
|
+
}
|
13
|
+
exports.isXataRecord = isXataRecord;
|