@xata.io/client 0.8.0 → 0.8.3
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 +1 -1
- package/CHANGELOG.md +21 -0
- package/dist/index.cjs +1762 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2731 -6
- package/dist/index.mjs +1667 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +9 -5
- package/rollup.config.js +33 -0
- package/tsconfig.json +2 -2
- package/dist/api/client.d.ts +0 -95
- package/dist/api/client.js +0 -251
- package/dist/api/components.d.ts +0 -1437
- package/dist/api/components.js +0 -998
- package/dist/api/fetcher.d.ts +0 -40
- package/dist/api/fetcher.js +0 -79
- package/dist/api/index.d.ts +0 -7
- package/dist/api/index.js +0 -21
- package/dist/api/parameters.d.ts +0 -16
- package/dist/api/parameters.js +0 -2
- package/dist/api/providers.d.ts +0 -8
- package/dist/api/providers.js +0 -30
- package/dist/api/responses.d.ts +0 -50
- package/dist/api/responses.js +0 -2
- package/dist/api/schemas.d.ts +0 -311
- package/dist/api/schemas.js +0 -2
- package/dist/client.d.ts +0 -39
- package/dist/client.js +0 -124
- package/dist/index.js +0 -29
- package/dist/namespace.d.ts +0 -7
- package/dist/namespace.js +0 -6
- package/dist/schema/filters.d.ts +0 -96
- package/dist/schema/filters.js +0 -2
- package/dist/schema/filters.spec.d.ts +0 -1
- package/dist/schema/filters.spec.js +0 -177
- package/dist/schema/index.d.ts +0 -21
- package/dist/schema/index.js +0 -49
- package/dist/schema/operators.d.ts +0 -74
- package/dist/schema/operators.js +0 -93
- package/dist/schema/pagination.d.ts +0 -83
- package/dist/schema/pagination.js +0 -93
- package/dist/schema/query.d.ts +0 -118
- package/dist/schema/query.js +0 -242
- package/dist/schema/record.d.ts +0 -66
- package/dist/schema/record.js +0 -13
- package/dist/schema/repository.d.ts +0 -134
- package/dist/schema/repository.js +0 -284
- package/dist/schema/selection.d.ts +0 -25
- package/dist/schema/selection.js +0 -2
- package/dist/schema/selection.spec.d.ts +0 -1
- package/dist/schema/selection.spec.js +0 -204
- package/dist/schema/sorting.d.ts +0 -17
- package/dist/schema/sorting.js +0 -28
- package/dist/schema/sorting.spec.d.ts +0 -1
- package/dist/schema/sorting.spec.js +0 -11
- package/dist/search/index.d.ts +0 -20
- package/dist/search/index.js +0 -30
- package/dist/util/branches.d.ts +0 -5
- package/dist/util/branches.js +0 -7
- package/dist/util/config.d.ts +0 -11
- package/dist/util/config.js +0 -121
- package/dist/util/environment.d.ts +0 -5
- package/dist/util/environment.js +0 -68
- package/dist/util/fetch.d.ts +0 -2
- package/dist/util/fetch.js +0 -13
- package/dist/util/lang.d.ts +0 -5
- package/dist/util/lang.js +0 -22
- package/dist/util/types.d.ts +0 -25
- package/dist/util/types.js +0 -2
package/dist/schema/operators.js
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
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
|
-
/**
|
5
|
-
* Operator to restrict results to only values that are greater than the given value.
|
6
|
-
*/
|
7
|
-
const gt = (value) => ({ $gt: value });
|
8
|
-
exports.gt = gt;
|
9
|
-
/**
|
10
|
-
* Operator to restrict results to only values that are greater than or equal to the given value.
|
11
|
-
*/
|
12
|
-
const ge = (value) => ({ $ge: value });
|
13
|
-
exports.ge = ge;
|
14
|
-
/**
|
15
|
-
* Operator to restrict results to only values that are greater than or equal to the given value.
|
16
|
-
*/
|
17
|
-
const gte = (value) => ({ $ge: value });
|
18
|
-
exports.gte = gte;
|
19
|
-
/**
|
20
|
-
* Operator to restrict results to only values that are lower than the given value.
|
21
|
-
*/
|
22
|
-
const lt = (value) => ({ $lt: value });
|
23
|
-
exports.lt = lt;
|
24
|
-
/**
|
25
|
-
* Operator to restrict results to only values that are lower than or equal to the given value.
|
26
|
-
*/
|
27
|
-
const lte = (value) => ({ $le: value });
|
28
|
-
exports.lte = lte;
|
29
|
-
/**
|
30
|
-
* Operator to restrict results to only values that are lower than or equal to the given value.
|
31
|
-
*/
|
32
|
-
const le = (value) => ({ $le: value });
|
33
|
-
exports.le = le;
|
34
|
-
/**
|
35
|
-
* Operator to restrict results to only values that are not null.
|
36
|
-
*/
|
37
|
-
const exists = (column) => ({ $exists: column });
|
38
|
-
exports.exists = exists;
|
39
|
-
/**
|
40
|
-
* Operator to restrict results to only values that are null.
|
41
|
-
*/
|
42
|
-
const notExists = (column) => ({ $notExists: column });
|
43
|
-
exports.notExists = notExists;
|
44
|
-
/**
|
45
|
-
* Operator to restrict results to only values that start with the given prefix.
|
46
|
-
*/
|
47
|
-
const startsWith = (value) => ({ $startsWith: value });
|
48
|
-
exports.startsWith = startsWith;
|
49
|
-
/**
|
50
|
-
* Operator to restrict results to only values that end with the given suffix.
|
51
|
-
*/
|
52
|
-
const endsWith = (value) => ({ $endsWith: value });
|
53
|
-
exports.endsWith = endsWith;
|
54
|
-
/**
|
55
|
-
* Operator to restrict results to only values that match the given pattern.
|
56
|
-
*/
|
57
|
-
const pattern = (value) => ({ $pattern: value });
|
58
|
-
exports.pattern = pattern;
|
59
|
-
/**
|
60
|
-
* Operator to restrict results to only values that are equal to the given value.
|
61
|
-
*/
|
62
|
-
const is = (value) => ({ $is: value });
|
63
|
-
exports.is = is;
|
64
|
-
/**
|
65
|
-
* Operator to restrict results to only values that are not equal to the given value.
|
66
|
-
*/
|
67
|
-
const isNot = (value) => ({ $isNot: value });
|
68
|
-
exports.isNot = isNot;
|
69
|
-
/**
|
70
|
-
* Operator to restrict results to only values that contain the given value.
|
71
|
-
*/
|
72
|
-
const contains = (value) => ({ $contains: value });
|
73
|
-
exports.contains = contains;
|
74
|
-
/**
|
75
|
-
* Operator to restrict results if some array items match the predicate.
|
76
|
-
*/
|
77
|
-
const includes = (value) => ({ $includes: value });
|
78
|
-
exports.includes = includes;
|
79
|
-
/**
|
80
|
-
* Operator to restrict results if all array items match the predicate.
|
81
|
-
*/
|
82
|
-
const includesAll = (value) => ({ $includesAll: value });
|
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,83 +0,0 @@
|
|
1
|
-
import { Query } from './query';
|
2
|
-
import { XataRecord } from './record';
|
3
|
-
export declare type PaginationQueryMeta = {
|
4
|
-
page: {
|
5
|
-
cursor: string;
|
6
|
-
more: boolean;
|
7
|
-
};
|
8
|
-
};
|
9
|
-
export interface Paginable<Record extends XataRecord, Result extends XataRecord = Record> {
|
10
|
-
meta: PaginationQueryMeta;
|
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
|
-
hasNextPage(): boolean;
|
17
|
-
}
|
18
|
-
/**
|
19
|
-
* A Page contains a set of results from a query plus metadata about the retrieved
|
20
|
-
* set of values such as the cursor, required to retrieve additional records.
|
21
|
-
*/
|
22
|
-
export declare class Page<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
|
23
|
-
#private;
|
24
|
-
/**
|
25
|
-
* Page metadata, required to retrieve additional records.
|
26
|
-
*/
|
27
|
-
readonly meta: PaginationQueryMeta;
|
28
|
-
/**
|
29
|
-
* The set of results for this page.
|
30
|
-
*/
|
31
|
-
readonly records: Result[];
|
32
|
-
constructor(query: Query<Record, Result>, meta: PaginationQueryMeta, records?: Result[]);
|
33
|
-
/**
|
34
|
-
* Retrieves the next page of results.
|
35
|
-
* @param size Maximum number of results to be retrieved.
|
36
|
-
* @param offset Number of results to skip when retrieving the results.
|
37
|
-
* @returns The next page or results.
|
38
|
-
*/
|
39
|
-
nextPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
40
|
-
/**
|
41
|
-
* Retrieves the previous page of results.
|
42
|
-
* @param size Maximum number of results to be retrieved.
|
43
|
-
* @param offset Number of results to skip when retrieving the results.
|
44
|
-
* @returns The previous page or results.
|
45
|
-
*/
|
46
|
-
previousPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
47
|
-
/**
|
48
|
-
* Retrieves the first page of results.
|
49
|
-
* @param size Maximum number of results to be retrieved.
|
50
|
-
* @param offset Number of results to skip when retrieving the results.
|
51
|
-
* @returns The first page or results.
|
52
|
-
*/
|
53
|
-
firstPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
54
|
-
/**
|
55
|
-
* Retrieves the last page of results.
|
56
|
-
* @param size Maximum number of results to be retrieved.
|
57
|
-
* @param offset Number of results to skip when retrieving the results.
|
58
|
-
* @returns The last page or results.
|
59
|
-
*/
|
60
|
-
lastPage(size?: number, offset?: number): Promise<Page<Record, Result>>;
|
61
|
-
/**
|
62
|
-
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
63
|
-
* @returns Whether or not there will be additional results in the next page of results.
|
64
|
-
*/
|
65
|
-
hasNextPage(): boolean;
|
66
|
-
}
|
67
|
-
export declare type CursorNavigationOptions = {
|
68
|
-
first?: string;
|
69
|
-
} | {
|
70
|
-
last?: string;
|
71
|
-
} | {
|
72
|
-
after?: string;
|
73
|
-
before?: string;
|
74
|
-
};
|
75
|
-
export declare type OffsetNavigationOptions = {
|
76
|
-
size?: number;
|
77
|
-
offset?: number;
|
78
|
-
};
|
79
|
-
export declare type PaginationOptions = CursorNavigationOptions & OffsetNavigationOptions;
|
80
|
-
export declare const PAGINATION_MAX_SIZE = 200;
|
81
|
-
export declare const PAGINATION_DEFAULT_SIZE = 200;
|
82
|
-
export declare const PAGINATION_MAX_OFFSET = 800;
|
83
|
-
export declare const PAGINATION_DEFAULT_OFFSET = 0;
|
@@ -1,93 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
16
|
-
};
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
21
|
-
};
|
22
|
-
var _Page_query;
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
24
|
-
exports.PAGINATION_DEFAULT_OFFSET = exports.PAGINATION_MAX_OFFSET = exports.PAGINATION_DEFAULT_SIZE = exports.PAGINATION_MAX_SIZE = exports.Page = void 0;
|
25
|
-
/**
|
26
|
-
* A Page contains a set of results from a query plus metadata about the retrieved
|
27
|
-
* set of values such as the cursor, required to retrieve additional records.
|
28
|
-
*/
|
29
|
-
class Page {
|
30
|
-
constructor(query, meta, records = []) {
|
31
|
-
_Page_query.set(this, void 0);
|
32
|
-
__classPrivateFieldSet(this, _Page_query, query, "f");
|
33
|
-
this.meta = meta;
|
34
|
-
this.records = records;
|
35
|
-
}
|
36
|
-
/**
|
37
|
-
* Retrieves the next page of results.
|
38
|
-
* @param size Maximum number of results to be retrieved.
|
39
|
-
* @param offset Number of results to skip when retrieving the results.
|
40
|
-
* @returns The next page or results.
|
41
|
-
*/
|
42
|
-
nextPage(size, offset) {
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
44
|
-
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
|
45
|
-
});
|
46
|
-
}
|
47
|
-
/**
|
48
|
-
* Retrieves the previous page of results.
|
49
|
-
* @param size Maximum number of results to be retrieved.
|
50
|
-
* @param offset Number of results to skip when retrieving the results.
|
51
|
-
* @returns The previous page or results.
|
52
|
-
*/
|
53
|
-
previousPage(size, offset) {
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
55
|
-
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
|
56
|
-
});
|
57
|
-
}
|
58
|
-
/**
|
59
|
-
* Retrieves the first page of results.
|
60
|
-
* @param size Maximum number of results to be retrieved.
|
61
|
-
* @param offset Number of results to skip when retrieving the results.
|
62
|
-
* @returns The first page or results.
|
63
|
-
*/
|
64
|
-
firstPage(size, offset) {
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
66
|
-
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
|
67
|
-
});
|
68
|
-
}
|
69
|
-
/**
|
70
|
-
* Retrieves the last page of results.
|
71
|
-
* @param size Maximum number of results to be retrieved.
|
72
|
-
* @param offset Number of results to skip when retrieving the results.
|
73
|
-
* @returns The last page or results.
|
74
|
-
*/
|
75
|
-
lastPage(size, offset) {
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
77
|
-
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
|
78
|
-
});
|
79
|
-
}
|
80
|
-
/**
|
81
|
-
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
82
|
-
* @returns Whether or not there will be additional results in the next page of results.
|
83
|
-
*/
|
84
|
-
hasNextPage() {
|
85
|
-
return this.meta.page.more;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
exports.Page = Page;
|
89
|
-
_Page_query = new WeakMap();
|
90
|
-
exports.PAGINATION_MAX_SIZE = 200;
|
91
|
-
exports.PAGINATION_DEFAULT_SIZE = 200;
|
92
|
-
exports.PAGINATION_MAX_OFFSET = 800;
|
93
|
-
exports.PAGINATION_DEFAULT_OFFSET = 0;
|
package/dist/schema/query.d.ts
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
import { FilterExpression } from '../api/schemas';
|
2
|
-
import { NonEmptyArray, RequiredBy } from '../util/types';
|
3
|
-
import { Filter } from './filters';
|
4
|
-
import { Page, Paginable, PaginationOptions, PaginationQueryMeta } from './pagination';
|
5
|
-
import { XataRecord } from './record';
|
6
|
-
import { Repository } from './repository';
|
7
|
-
import { SelectableColumn, SelectedPick, ValueAtColumn } from './selection';
|
8
|
-
import { SortDirection, SortFilter } from './sorting';
|
9
|
-
export declare type QueryOptions<T extends XataRecord> = {
|
10
|
-
page?: PaginationOptions;
|
11
|
-
columns?: NonEmptyArray<SelectableColumn<T>>;
|
12
|
-
filter?: FilterExpression;
|
13
|
-
sort?: SortFilter<T> | SortFilter<T>[];
|
14
|
-
};
|
15
|
-
/**
|
16
|
-
* Query objects contain the information of all filters, sorting, etc. to be included in the database query.
|
17
|
-
*
|
18
|
-
* Query objects are immutable. Any method that adds more constraints or options to the query will return
|
19
|
-
* a new Query object containing the both the previous and the new constraints and options.
|
20
|
-
*/
|
21
|
-
export declare class Query<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
|
22
|
-
#private;
|
23
|
-
readonly meta: PaginationQueryMeta;
|
24
|
-
readonly records: Result[];
|
25
|
-
constructor(repository: Repository<Record> | null, table: string, data: Partial<QueryOptions<Record>>, parent?: Partial<QueryOptions<Record>>);
|
26
|
-
getQueryOptions(): QueryOptions<Record>;
|
27
|
-
/**
|
28
|
-
* Builds a new query object representing a logical OR between the given subqueries.
|
29
|
-
* @param queries An array of subqueries.
|
30
|
-
* @returns A new Query object.
|
31
|
-
*/
|
32
|
-
any(...queries: Query<Record, any>[]): Query<Record, Result>;
|
33
|
-
/**
|
34
|
-
* Builds a new query object representing a logical AND between the given subqueries.
|
35
|
-
* @param queries An array of subqueries.
|
36
|
-
* @returns A new Query object.
|
37
|
-
*/
|
38
|
-
all(...queries: Query<Record, any>[]): Query<Record, Result>;
|
39
|
-
/**
|
40
|
-
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
41
|
-
* @param queries An array of subqueries.
|
42
|
-
* @returns A new Query object.
|
43
|
-
*/
|
44
|
-
not(...queries: Query<Record, any>[]): Query<Record, Result>;
|
45
|
-
/**
|
46
|
-
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
47
|
-
* @param queries An array of subqueries.
|
48
|
-
* @returns A new Query object.
|
49
|
-
*/
|
50
|
-
none(...queries: Query<Record, any>[]): Query<Record, Result>;
|
51
|
-
/**
|
52
|
-
* Builds a new query object adding one or more constraints. Examples:
|
53
|
-
*
|
54
|
-
* ```
|
55
|
-
* query.filter("columnName", columnValue)
|
56
|
-
* query.filter({
|
57
|
-
* "columnName": columnValue
|
58
|
-
* })
|
59
|
-
* query.filter({
|
60
|
-
* "columnName": operator(columnValue) // Use gt, gte, lt, lte, startsWith,...
|
61
|
-
* })
|
62
|
-
* ```
|
63
|
-
*
|
64
|
-
* @returns A new Query object.
|
65
|
-
*/
|
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
|
-
/**
|
69
|
-
* Builds a new query with a new sort option.
|
70
|
-
* @param column The column name.
|
71
|
-
* @param direction The direction. Either ascending or descending.
|
72
|
-
* @returns A new Query object.
|
73
|
-
*/
|
74
|
-
sort<F extends SelectableColumn<Record>>(column: F, direction: SortDirection): Query<Record, Result>;
|
75
|
-
/**
|
76
|
-
* Builds a new query specifying the set of columns to be returned in the query response.
|
77
|
-
* @param columns Array of column names to be returned by the query.
|
78
|
-
* @returns A new Query object.
|
79
|
-
*/
|
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
|
-
/**
|
89
|
-
* Performs the query in the database and returns a set of results.
|
90
|
-
* @param options Additional options to be used when performing the query.
|
91
|
-
* @returns An array of records from the database.
|
92
|
-
*/
|
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']>[]>;
|
96
|
-
/**
|
97
|
-
* Performs the query in the database and returns all the results.
|
98
|
-
* Warning: If there are a large number of results, this method can have performance implications.
|
99
|
-
* @param options Additional options to be used when performing the query.
|
100
|
-
* @returns An array of records from the database.
|
101
|
-
*/
|
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']>[]>;
|
105
|
-
/**
|
106
|
-
* Performs the query in the database and returns the first result.
|
107
|
-
* @param options Additional options to be used when performing the query.
|
108
|
-
* @returns The first record that matches the query, or null if no record matched the query.
|
109
|
-
*/
|
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>>;
|
117
|
-
hasNextPage(): boolean;
|
118
|
-
}
|
package/dist/schema/query.js
DELETED
@@ -1,242 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
12
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
13
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
14
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
16
|
-
};
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
19
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
21
|
-
};
|
22
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
23
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
24
|
-
var m = o[Symbol.asyncIterator], i;
|
25
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
26
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
27
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
28
|
-
};
|
29
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
30
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
31
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
32
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
33
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
34
|
-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
35
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
36
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
37
|
-
function fulfill(value) { resume("next", value); }
|
38
|
-
function reject(value) { resume("throw", value); }
|
39
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
40
|
-
};
|
41
|
-
var _Query_table, _Query_repository, _Query_data;
|
42
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
43
|
-
exports.Query = void 0;
|
44
|
-
const lang_1 = require("../util/lang");
|
45
|
-
const pagination_1 = require("./pagination");
|
46
|
-
/**
|
47
|
-
* Query objects contain the information of all filters, sorting, etc. to be included in the database query.
|
48
|
-
*
|
49
|
-
* Query objects are immutable. Any method that adds more constraints or options to the query will return
|
50
|
-
* a new Query object containing the both the previous and the new constraints and options.
|
51
|
-
*/
|
52
|
-
class Query {
|
53
|
-
constructor(repository, table, data, parent) {
|
54
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
55
|
-
_Query_table.set(this, void 0);
|
56
|
-
_Query_repository.set(this, void 0);
|
57
|
-
_Query_data.set(this, { filter: {} });
|
58
|
-
// Implements pagination
|
59
|
-
this.meta = { page: { cursor: 'start', more: true } };
|
60
|
-
this.records = [];
|
61
|
-
__classPrivateFieldSet(this, _Query_table, table, "f");
|
62
|
-
if (repository) {
|
63
|
-
__classPrivateFieldSet(this, _Query_repository, repository, "f");
|
64
|
-
}
|
65
|
-
else {
|
66
|
-
__classPrivateFieldSet(this, _Query_repository, this, "f");
|
67
|
-
}
|
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
|
-
this.any = this.any.bind(this);
|
77
|
-
this.all = this.all.bind(this);
|
78
|
-
this.not = this.not.bind(this);
|
79
|
-
this.filter = this.filter.bind(this);
|
80
|
-
this.sort = this.sort.bind(this);
|
81
|
-
this.none = this.none.bind(this);
|
82
|
-
Object.defineProperty(this, 'table', { enumerable: false });
|
83
|
-
Object.defineProperty(this, 'repository', { enumerable: false });
|
84
|
-
}
|
85
|
-
getQueryOptions() {
|
86
|
-
return __classPrivateFieldGet(this, _Query_data, "f");
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* Builds a new query object representing a logical OR between the given subqueries.
|
90
|
-
* @param queries An array of subqueries.
|
91
|
-
* @returns A new Query object.
|
92
|
-
*/
|
93
|
-
any(...queries) {
|
94
|
-
const $any = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
|
95
|
-
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $any } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
96
|
-
}
|
97
|
-
/**
|
98
|
-
* Builds a new query object representing a logical AND between the given subqueries.
|
99
|
-
* @param queries An array of subqueries.
|
100
|
-
* @returns A new Query object.
|
101
|
-
*/
|
102
|
-
all(...queries) {
|
103
|
-
const $all = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
|
104
|
-
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
105
|
-
}
|
106
|
-
/**
|
107
|
-
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
108
|
-
* @param queries An array of subqueries.
|
109
|
-
* @returns A new Query object.
|
110
|
-
*/
|
111
|
-
not(...queries) {
|
112
|
-
const $not = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
|
113
|
-
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $not } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
114
|
-
}
|
115
|
-
/**
|
116
|
-
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
117
|
-
* @param queries An array of subqueries.
|
118
|
-
* @returns A new Query object.
|
119
|
-
*/
|
120
|
-
none(...queries) {
|
121
|
-
const $none = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
|
122
|
-
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $none } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
123
|
-
}
|
124
|
-
filter(a, b) {
|
125
|
-
var _a, _b;
|
126
|
-
if (arguments.length === 1) {
|
127
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
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));
|
129
|
-
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
130
|
-
}
|
131
|
-
else {
|
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 }]));
|
133
|
-
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
|
134
|
-
}
|
135
|
-
}
|
136
|
-
/**
|
137
|
-
* Builds a new query with a new sort option.
|
138
|
-
* @param column The column name.
|
139
|
-
* @param direction The direction. Either ascending or descending.
|
140
|
-
* @returns A new Query object.
|
141
|
-
*/
|
142
|
-
sort(column, direction) {
|
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 }];
|
146
|
-
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { sort }, __classPrivateFieldGet(this, _Query_data, "f"));
|
147
|
-
}
|
148
|
-
/**
|
149
|
-
* Builds a new query specifying the set of columns to be returned in the query response.
|
150
|
-
* @param columns Array of column names to be returned by the query.
|
151
|
-
* @returns A new Query object.
|
152
|
-
*/
|
153
|
-
select(columns) {
|
154
|
-
return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { columns }, __classPrivateFieldGet(this, _Query_data, "f"));
|
155
|
-
}
|
156
|
-
getPaginated(options = {}) {
|
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);
|
159
|
-
}
|
160
|
-
[(_Query_table = new WeakMap(), _Query_repository = new WeakMap(), _Query_data = new WeakMap(), Symbol.asyncIterator)]() {
|
161
|
-
return __asyncGenerator(this, arguments, function* _a() {
|
162
|
-
var e_1, _b;
|
163
|
-
try {
|
164
|
-
for (var _c = __asyncValues(this.getIterator(1)), _d; _d = yield __await(_c.next()), !_d.done;) {
|
165
|
-
const [record] = _d.value;
|
166
|
-
yield yield __await(record);
|
167
|
-
}
|
168
|
-
}
|
169
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
170
|
-
finally {
|
171
|
-
try {
|
172
|
-
if (_d && !_d.done && (_b = _c.return)) yield __await(_b.call(_c));
|
173
|
-
}
|
174
|
-
finally { if (e_1) throw e_1.error; }
|
175
|
-
}
|
176
|
-
});
|
177
|
-
}
|
178
|
-
getIterator(chunk, options = {}) {
|
179
|
-
return __asyncGenerator(this, arguments, function* getIterator_1() {
|
180
|
-
let offset = 0;
|
181
|
-
let end = false;
|
182
|
-
while (!end) {
|
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.
|
185
|
-
yield yield __await(records);
|
186
|
-
offset += chunk;
|
187
|
-
end = !meta.page.more;
|
188
|
-
}
|
189
|
-
});
|
190
|
-
}
|
191
|
-
getMany(options = {}) {
|
192
|
-
return __awaiter(this, void 0, void 0, function* () {
|
193
|
-
const { records } = yield this.getPaginated(options);
|
194
|
-
// Method overloading does not provide type inference for the return type.
|
195
|
-
return records;
|
196
|
-
});
|
197
|
-
}
|
198
|
-
getAll(chunk = pagination_1.PAGINATION_MAX_SIZE, options = {}) {
|
199
|
-
var e_2, _a;
|
200
|
-
return __awaiter(this, void 0, void 0, function* () {
|
201
|
-
const results = [];
|
202
|
-
try {
|
203
|
-
for (var _b = __asyncValues(this.getIterator(chunk, options)), _c; _c = yield _b.next(), !_c.done;) {
|
204
|
-
const page = _c.value;
|
205
|
-
results.push(...page);
|
206
|
-
}
|
207
|
-
}
|
208
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
209
|
-
finally {
|
210
|
-
try {
|
211
|
-
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
|
212
|
-
}
|
213
|
-
finally { if (e_2) throw e_2.error; }
|
214
|
-
}
|
215
|
-
// Method overloading does not provide type inference for the return type.
|
216
|
-
return results;
|
217
|
-
});
|
218
|
-
}
|
219
|
-
getOne(options = {}) {
|
220
|
-
return __awaiter(this, void 0, void 0, function* () {
|
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.
|
223
|
-
return records[0] || null;
|
224
|
-
});
|
225
|
-
}
|
226
|
-
nextPage(size, offset) {
|
227
|
-
return this.firstPage(size, offset);
|
228
|
-
}
|
229
|
-
previousPage(size, offset) {
|
230
|
-
return this.firstPage(size, offset);
|
231
|
-
}
|
232
|
-
firstPage(size, offset) {
|
233
|
-
return this.getPaginated({ page: { size, offset } });
|
234
|
-
}
|
235
|
-
lastPage(size, offset) {
|
236
|
-
return this.getPaginated({ page: { size, offset, before: 'end' } });
|
237
|
-
}
|
238
|
-
hasNextPage() {
|
239
|
-
return this.meta.page.more;
|
240
|
-
}
|
241
|
-
}
|
242
|
-
exports.Query = Query;
|