@xata.io/client 0.0.0-beta.c9e08d0 → 0.0.0-beta.ca9389a

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.
Files changed (66) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/CHANGELOG.md +87 -0
  3. package/dist/api/client.d.ts +95 -0
  4. package/dist/api/client.js +251 -0
  5. package/dist/api/components.d.ts +1437 -0
  6. package/dist/api/components.js +998 -0
  7. package/dist/api/fetcher.d.ts +40 -0
  8. package/dist/api/fetcher.js +79 -0
  9. package/dist/api/index.d.ts +7 -0
  10. package/dist/api/index.js +21 -0
  11. package/dist/api/parameters.d.ts +16 -0
  12. package/dist/api/parameters.js +2 -0
  13. package/dist/api/providers.d.ts +8 -0
  14. package/dist/api/providers.js +30 -0
  15. package/dist/api/responses.d.ts +50 -0
  16. package/dist/api/responses.js +2 -0
  17. package/dist/api/schemas.d.ts +311 -0
  18. package/dist/api/schemas.js +2 -0
  19. package/dist/client.d.ts +39 -0
  20. package/dist/client.js +124 -0
  21. package/dist/index.d.ts +5 -182
  22. package/dist/index.js +19 -499
  23. package/dist/namespace.d.ts +7 -0
  24. package/dist/namespace.js +6 -0
  25. package/dist/schema/filters.d.ts +96 -0
  26. package/dist/schema/filters.js +2 -0
  27. package/dist/schema/filters.spec.d.ts +1 -0
  28. package/dist/schema/filters.spec.js +177 -0
  29. package/dist/schema/index.d.ts +21 -0
  30. package/dist/schema/index.js +49 -0
  31. package/dist/schema/operators.d.ts +74 -0
  32. package/dist/schema/operators.js +93 -0
  33. package/dist/schema/pagination.d.ts +83 -0
  34. package/dist/schema/pagination.js +93 -0
  35. package/dist/schema/query.d.ts +118 -0
  36. package/dist/schema/query.js +242 -0
  37. package/dist/schema/record.d.ts +66 -0
  38. package/dist/schema/record.js +13 -0
  39. package/dist/schema/repository.d.ts +134 -0
  40. package/dist/schema/repository.js +284 -0
  41. package/dist/schema/selection.d.ts +25 -0
  42. package/dist/schema/selection.js +2 -0
  43. package/dist/schema/selection.spec.d.ts +1 -0
  44. package/dist/schema/selection.spec.js +204 -0
  45. package/dist/schema/sorting.d.ts +17 -0
  46. package/dist/schema/sorting.js +28 -0
  47. package/dist/schema/sorting.spec.d.ts +1 -0
  48. package/dist/schema/sorting.spec.js +11 -0
  49. package/dist/search/index.d.ts +20 -0
  50. package/dist/search/index.js +30 -0
  51. package/dist/util/branches.d.ts +5 -0
  52. package/dist/util/branches.js +7 -0
  53. package/dist/util/config.d.ts +11 -0
  54. package/dist/util/config.js +121 -0
  55. package/dist/util/environment.d.ts +5 -0
  56. package/dist/util/environment.js +68 -0
  57. package/dist/util/fetch.d.ts +2 -0
  58. package/dist/util/fetch.js +13 -0
  59. package/dist/util/lang.d.ts +5 -0
  60. package/dist/util/lang.js +22 -0
  61. package/dist/util/types.d.ts +25 -0
  62. package/dist/util/types.js +2 -0
  63. package/package.json +5 -2
  64. package/tsconfig.json +21 -0
  65. package/dist/util/errors.d.ts +0 -3
  66. package/dist/util/errors.js +0 -9
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /* eslint-disable @typescript-eslint/no-unused-vars */
4
+ const vitest_1 = require("vitest");
5
+ // Single column with implicit is
6
+ const singleColumnWithImplicitIs = { name: 'r2' };
7
+ // Single column with explicit is
8
+ const singleColumnWithExplicitIs = { name: { $is: 'r2' } };
9
+ // Is string
10
+ const isString = { string: 'string' };
11
+ // Is true
12
+ const isTrue = { boolean: true };
13
+ // Is false
14
+ const isFalse = { boolean: false };
15
+ // Is pos int
16
+ const isPosInt = { number: 1234567 };
17
+ // Is neg int
18
+ const isNegInt = { number: -42 };
19
+ // Is float
20
+ const isFloat = { number: 3.14 };
21
+ // with dots
22
+ const withDots = { 'settings.plan': 'free' };
23
+ // Nested columns
24
+ const nestedColumns = { settings: { plan: 'free' } };
25
+ // Nested columns array
26
+ const nestedColumnsArray = { settings: [{ dark: false }, { plan: 'free' }] };
27
+ // Nested columns any
28
+ const nestedColumnsAny = { settings: { $any: [{ plan: 'free' }, { plan: 'trial' }] } };
29
+ // Nested columns any value
30
+ const nestedColumnsAnyValue = { settings: { plan: { $any: ['free', 'trial'] } } };
31
+ // Or with $any
32
+ const orWithAny = { 'settings.plan': { $any: ['free', 'paid'] } };
33
+ // Multiple columns implicit and
34
+ const multipleColumnsImplicitAnd = { 'settings.dark': true, 'settings.plan': 'free' };
35
+ // Explicit $all with multi-key filter list
36
+ const explicitAllWithMultiKeyFilterList = {
37
+ $all: { 'settings.dark': true, 'settings.plan': 'free' }
38
+ };
39
+ // Explicit $all with filter list
40
+ const explicitAllWithFilterList = {
41
+ $all: [{ 'settings.dark': true }, { 'settings.plan': 'free' }]
42
+ };
43
+ // Explicit $any with multi-key filter list
44
+ const explicitAnyWithMultiKeyFilterList = {
45
+ $all: { 'settings.dark': true, 'settings.plan': 'free' }
46
+ };
47
+ // Explicit $any with filter list
48
+ const explicitAnyWithFilterList = {
49
+ $any: [{ 'settings.dark': true }, { 'settings.plan': 'free' }]
50
+ };
51
+ // $any with multiple values
52
+ const anyWithMultipleValues = { number: { $any: [1, 2, 3] } };
53
+ // $none with multiple values
54
+ const noneWithMultipleValues = { number: { $none: [1, 2, 3] } };
55
+ // Exists filter
56
+ const existsFilter = { $exists: 'test' };
57
+ // Not exists filter
58
+ const notExistsFilter = { $notExists: 'test' };
59
+ // Exists with all
60
+ const existsWithAll = { $all: [{ $exists: 'settings' }, { $exists: 'name' }] };
61
+ // Nest any with not
62
+ const nestAnyWithNot = { $not: { $any: { 'settings.dark': true, 'settings.plan': 'free' } } };
63
+ // Mix $all and $any with extra keys
64
+ const mixAllAndAnyWithExtraKeys = {
65
+ $all: { $any: { 'settings.dark': false, 'settings.plan': 'free' }, name: 'r1' }
66
+ };
67
+ // Range query with less first
68
+ const rangeQueryWithLessFirst = { age: { $lt: 30, $ge: 20 } };
69
+ // Range query with greater first
70
+ const rangeQueryWithGreaterFirst = { age: { $ge: 20, $lt: 30 } };
71
+ // Ordered op
72
+ const orderedOp = { age: { $lt: 30 } };
73
+ // Simple includes
74
+ const simpleIncludes = { labels: { $includes: 'test' } };
75
+ // Simple includes with op
76
+ const simpleIncludesWithOp = { labels: { $includes: { $contains: 'test' } } };
77
+ // Simple includes multiple
78
+ const simpleIncludesMultiple = { labels: { $includes: ['a', 'b', 'c'] } };
79
+ // Simple includes multiple with op
80
+ const simpleIncludesMultipleWithOp = {
81
+ labels: { $includes: [{ $is: 'a' }, { $is: 'b' }, { $is: 'c' }] }
82
+ };
83
+ // Includes with many comparisons
84
+ const includesWithManyComparisons = {
85
+ labels: { $includes: { $all: [{ $contains: 'a' }, { $contains: 'b' }] } }
86
+ };
87
+ // Simple includes multiple op and value
88
+ const simpleIncludesMultipleOpAndValue = { labels: { $includes: [{ $contains: 'a' }, 'b'] } };
89
+ // Includes with mode and array of filters
90
+ const includesWithModeAndArrayOfFilters = {
91
+ labels: { $includesNone: [{ $contains: 'test' }, 'abc', { $endsWith: 'bad' }] }
92
+ };
93
+ // Includes with mix of any and all in predicate position
94
+ const includesWithMixOfAnyAndAllInPredicatePosition = {
95
+ labels: { $includes: { $any: { $all: [{ $startsWith: 'test' }, { $contains: 'x' }], $any: ['a', 'b'] } } }
96
+ };
97
+ // Simple $includesany
98
+ const simpleIncludesAny = { labels: { $includesAny: 'test' } };
99
+ // Simple $includesall
100
+ const simpleIncludesAll = { labels: { $includesAll: 'test' } };
101
+ // Simple $includesnone
102
+ const simpleIncludesNone = { labels: { $includesNone: 'test' } };
103
+ // Exists value must be string not int
104
+ // @ts-expect-error
105
+ const existsValueMustBeStringNotInt = { $exists: 42 };
106
+ // Exists value must be string not objct
107
+ // @ts-expect-error
108
+ const existsValueMustBeStringNotObject = { $exists: { field: 'settings.unknown' } };
109
+ // Filter by one column
110
+ const filterByOneColumn = { name: 'r1' };
111
+ // Filter with the $is operator
112
+ const filterWithTheIsOperator = { name: { $is: 'r1' } };
113
+ // Filter with dot notation
114
+ const filterWithDotNotation = { 'settings.plan': 'free' };
115
+ // Filter with nested object
116
+ const filterWithNestedObject = { 'settings.plan': { $is: 'free' } };
117
+ // Filter with $any operation
118
+ const filterWithAnyOperation = { 'settings.plan': { $any: ['free', 'paid'] } };
119
+ // Filter with and operations
120
+ const filterWithAndOperations = { 'settings.dark': true, 'settings.plan': 'free' };
121
+ // Filter with both and and any operations
122
+ const filterWithBothAndAndAnyOperations = {
123
+ $any: { 'settings.dark': true, 'settings.plan': 'free' }
124
+ };
125
+ // Filter with both and and any operations in array
126
+ const filterWithBothAndAndAnyOperationsInArray = { $any: [{ name: 'r1' }, { name: 'r2' }] };
127
+ // Filter with exists operation
128
+ const filterWithExistsOperation = { $exists: 'settings' };
129
+ // Filter with exists, and and any operations
130
+ const filterWithExistsAndAndAnyOperations = {
131
+ $all: [{ $exists: 'settings' }, { $exists: 'name' }]
132
+ };
133
+ // Filter with not exists operation
134
+ const filterWithNotExistsOperation = { $notExists: 'settings' };
135
+ // Filter with partial match
136
+ const filterWithPartialMatch = { name: { $contains: 'value' } };
137
+ // Filter with pattern operator
138
+ const filterWithPatternOperator = { name: { $pattern: 'value' } };
139
+ // Filter with $startsWith and $endsWith operators
140
+ const filterWithStartsWithAndEndsWithOperators = {
141
+ name: { $startsWith: 'value', $endsWith: 'value' }
142
+ };
143
+ // Filter with numeric ranges
144
+ const filterWithNumericRanges = { age: { $lt: 30, $ge: 20 } };
145
+ // Filter with negations
146
+ const filterWithNegations = { $not: { name: 'r1' } };
147
+ // Filter with complex negations
148
+ const filterWithComplexNegations = { $not: { $any: [{ name: 'r1' }, { name: 'r2' }] } };
149
+ // Filter with arrays complex negations
150
+ const filterWithArraysComplexNegations = {
151
+ labels: {
152
+ $includes: {
153
+ $all: [{ $contains: 'label' }, { $not: { $endsWith: '-debug' } }]
154
+ }
155
+ }
156
+ };
157
+ // Filters with $includesAll
158
+ const filtersWithIncludesAll = {
159
+ 'settings.labels': {
160
+ $includesAll: [{ $contains: 'label' }]
161
+ }
162
+ };
163
+ // Filter with invalid property type
164
+ // @ts-expect-error
165
+ const filterWithInvalidPropertyType = { name: 42 };
166
+ // Filter with invalid dot notation property type
167
+ // @ts-expect-error
168
+ const filterWithInvalidNestedPropertyType = { 'settings.plan': 42 };
169
+ // Filter with invalid nested object property type
170
+ // @ts-expect-error
171
+ const filterWithInvalidNestedObjectPropertyType = { settings: { plan: 42 } };
172
+ // Filter with invalid property $is type
173
+ // @ts-expect-error
174
+ const filterWithInvalidOperator = { name: { $is: 42 } };
175
+ (0, vitest_1.test)('fake test', () => {
176
+ // This is a fake test to make sure that the type definitions in this file are working
177
+ });
@@ -0,0 +1,21 @@
1
+ import { Namespace, NamespaceBuildOptions } from '../namespace';
2
+ import { BaseData } from './record';
3
+ import { LinkDictionary, Repository } from './repository';
4
+ export * from './operators';
5
+ export * from './pagination';
6
+ export { Query } from './query';
7
+ export { isIdentifiable, isXataRecord } from './record';
8
+ export type { Identifiable, XataRecord } from './record';
9
+ export { Repository, RestRepository } from './repository';
10
+ export declare type SchemaDefinition = {
11
+ table: string;
12
+ links?: LinkDictionary;
13
+ };
14
+ export declare type SchemaNamespaceResult<Schemas extends Record<string, BaseData>> = {
15
+ [Key in keyof Schemas]: Repository<Schemas[Key]>;
16
+ };
17
+ export declare class SchemaNamespace<Schemas extends Record<string, BaseData>> extends Namespace {
18
+ private links?;
19
+ constructor(links?: LinkDictionary | undefined);
20
+ build(options: NamespaceBuildOptions): SchemaNamespaceResult<Schemas>;
21
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SchemaNamespace = exports.RestRepository = exports.Repository = exports.isXataRecord = exports.isIdentifiable = exports.Query = void 0;
18
+ const namespace_1 = require("../namespace");
19
+ const lang_1 = require("../util/lang");
20
+ const repository_1 = require("./repository");
21
+ __exportStar(require("./operators"), exports);
22
+ __exportStar(require("./pagination"), exports);
23
+ var query_1 = require("./query");
24
+ Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
25
+ var record_1 = require("./record");
26
+ Object.defineProperty(exports, "isIdentifiable", { enumerable: true, get: function () { return record_1.isIdentifiable; } });
27
+ Object.defineProperty(exports, "isXataRecord", { enumerable: true, get: function () { return record_1.isXataRecord; } });
28
+ var repository_2 = require("./repository");
29
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_2.Repository; } });
30
+ Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_2.RestRepository; } });
31
+ class SchemaNamespace extends namespace_1.Namespace {
32
+ constructor(links) {
33
+ super();
34
+ this.links = links;
35
+ }
36
+ build(options) {
37
+ const { getFetchProps } = options;
38
+ const links = this.links;
39
+ const schemaNamespace = new Proxy({}, {
40
+ get: (_target, table) => {
41
+ if (!(0, lang_1.isString)(table))
42
+ throw new Error('Invalid table name');
43
+ return new repository_1.RestRepository({ schemaNamespace, getFetchProps, table, links });
44
+ }
45
+ });
46
+ return schemaNamespace;
47
+ }
48
+ }
49
+ exports.SchemaNamespace = SchemaNamespace;
@@ -0,0 +1,74 @@
1
+ import { ArrayFilter, ComparableType, ComparableTypeFilter, ExistanceFilter, PropertyFilter, StringTypeFilter } from './filters';
2
+ import { SelectableColumn } from './selection';
3
+ /**
4
+ * Operator to restrict results to only values that are greater than the given value.
5
+ */
6
+ export declare const gt: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
7
+ /**
8
+ * Operator to restrict results to only values that are greater than or equal to the given value.
9
+ */
10
+ export declare const ge: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
11
+ /**
12
+ * Operator to restrict results to only values that are greater than or equal to the given value.
13
+ */
14
+ export declare const gte: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
15
+ /**
16
+ * Operator to restrict results to only values that are lower than the given value.
17
+ */
18
+ export declare const lt: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
19
+ /**
20
+ * Operator to restrict results to only values that are lower than or equal to the given value.
21
+ */
22
+ export declare const lte: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
23
+ /**
24
+ * Operator to restrict results to only values that are lower than or equal to the given value.
25
+ */
26
+ export declare const le: <T extends ComparableType>(value: T) => ComparableTypeFilter<T>;
27
+ /**
28
+ * Operator to restrict results to only values that are not null.
29
+ */
30
+ export declare const exists: <T>(column: SelectableColumn<T, []>) => ExistanceFilter<T>;
31
+ /**
32
+ * Operator to restrict results to only values that are null.
33
+ */
34
+ export declare const notExists: <T>(column: SelectableColumn<T, []>) => ExistanceFilter<T>;
35
+ /**
36
+ * Operator to restrict results to only values that start with the given prefix.
37
+ */
38
+ export declare const startsWith: (value: string) => StringTypeFilter;
39
+ /**
40
+ * Operator to restrict results to only values that end with the given suffix.
41
+ */
42
+ export declare const endsWith: (value: string) => StringTypeFilter;
43
+ /**
44
+ * Operator to restrict results to only values that match the given pattern.
45
+ */
46
+ export declare const pattern: (value: string) => StringTypeFilter;
47
+ /**
48
+ * Operator to restrict results to only values that are equal to the given value.
49
+ */
50
+ export declare const is: <T>(value: T) => PropertyFilter<T>;
51
+ /**
52
+ * Operator to restrict results to only values that are not equal to the given value.
53
+ */
54
+ export declare const isNot: <T>(value: T) => PropertyFilter<T>;
55
+ /**
56
+ * Operator to restrict results to only values that contain the given value.
57
+ */
58
+ export declare const contains: (value: string) => StringTypeFilter;
59
+ /**
60
+ * Operator to restrict results if some array items match the predicate.
61
+ */
62
+ export declare const includes: <T>(value: T) => ArrayFilter<T>;
63
+ /**
64
+ * Operator to restrict results if all array items match the predicate.
65
+ */
66
+ export declare const includesAll: <T>(value: T) => ArrayFilter<T>;
67
+ /**
68
+ * Operator to restrict results if none array items match the predicate.
69
+ */
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>;
@@ -0,0 +1,93 @@
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;
@@ -0,0 +1,83 @@
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;
@@ -0,0 +1,93 @@
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;