@xata.io/client 0.0.0-beta.bdce130 → 0.0.0-beta.ccaf25d

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/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -9,259 +13,8 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
9
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
22
- if (kind === "m") throw new TypeError("Private method is not writable");
23
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
24
- 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");
25
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
26
- };
27
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
28
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
29
- 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");
30
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
31
- };
32
- var __asyncValues = (this && this.__asyncValues) || function (o) {
33
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
34
- var m = o[Symbol.asyncIterator], i;
35
- 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);
36
- 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); }); }; }
37
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
38
- };
39
- var _RestRepository_client, _RestRepository_fetch, _RestRepository_table;
40
16
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
42
- const filters_1 = require("./schema/filters");
43
- const pagination_1 = require("./schema/pagination");
44
- const query_1 = require("./schema/query");
45
- class Repository extends query_1.Query {
46
- }
47
- exports.Repository = Repository;
48
- class RestRepository extends Repository {
49
- constructor(client, table) {
50
- super(null, table, {});
51
- _RestRepository_client.set(this, void 0);
52
- _RestRepository_fetch.set(this, void 0);
53
- _RestRepository_table.set(this, void 0);
54
- __classPrivateFieldSet(this, _RestRepository_client, client, "f");
55
- __classPrivateFieldSet(this, _RestRepository_table, table, "f");
56
- // TODO: Remove when integrating with API client
57
- const fetchImpl = typeof fetch !== 'undefined' ? fetch : __classPrivateFieldGet(this, _RestRepository_client, "f").options.fetch;
58
- if (!fetchImpl) {
59
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
60
- }
61
- __classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
62
- }
63
- request(method, path, body) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const { databaseURL, apiKey } = __classPrivateFieldGet(this, _RestRepository_client, "f").options;
66
- const branch = yield __classPrivateFieldGet(this, _RestRepository_client, "f").getBranch();
67
- const fetchImpl = __classPrivateFieldGet(this, _RestRepository_fetch, "f");
68
- const resp = yield fetchImpl(`${databaseURL}:${branch}${path}`, {
69
- method,
70
- headers: {
71
- Accept: '*/*',
72
- 'Content-Type': 'application/json',
73
- Authorization: `Bearer ${apiKey}`
74
- },
75
- body: JSON.stringify(body)
76
- });
77
- if (!resp.ok) {
78
- try {
79
- const json = yield resp.json();
80
- const message = json.message;
81
- if (typeof message === 'string') {
82
- throw new XataError(message, resp.status);
83
- }
84
- }
85
- catch (err) {
86
- if (err instanceof XataError)
87
- throw err;
88
- // Ignore errors for other reasons.
89
- // For example if the response's body cannot be parsed as JSON
90
- }
91
- throw new XataError(resp.statusText, resp.status);
92
- }
93
- if (resp.status === 204)
94
- return undefined;
95
- return resp.json();
96
- });
97
- }
98
- create(object) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const record = transformObjectLinks(object);
101
- const response = yield this.request('POST', `/tables/${__classPrivateFieldGet(this, _RestRepository_table, "f")}/data`, record);
102
- if (!response) {
103
- throw new Error("The server didn't return any data for the query");
104
- }
105
- const finalObject = yield this.read(response.id);
106
- if (!finalObject) {
107
- throw new Error('The server failed to save the record');
108
- }
109
- return finalObject;
110
- });
111
- }
112
- createMany(objects) {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const records = objects.map((object) => transformObjectLinks(object));
115
- const response = yield this.request('POST', `/tables/${__classPrivateFieldGet(this, _RestRepository_table, "f")}/bulk`, { records });
116
- if (!response) {
117
- throw new Error("The server didn't return any data for the query");
118
- }
119
- // TODO: Use filer.$any() to get all the records
120
- const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));
121
- if (finalObjects.some((object) => !object)) {
122
- throw new Error('The server failed to save the record');
123
- }
124
- return finalObjects;
125
- });
126
- }
127
- read(id) {
128
- return __awaiter(this, void 0, void 0, function* () {
129
- try {
130
- const response = yield this.request('GET', `/tables/${__classPrivateFieldGet(this, _RestRepository_table, "f")}/data/${id}`);
131
- if (!response)
132
- return null;
133
- return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
134
- }
135
- catch (err) {
136
- if (err.status === 404)
137
- return null;
138
- throw err;
139
- }
140
- });
141
- }
142
- update(id, object) {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- const response = yield this.request('PUT', `/tables/${__classPrivateFieldGet(this, _RestRepository_table, "f")}/data/${id}`, object);
145
- if (!response) {
146
- throw new Error("The server didn't return any data for the query");
147
- }
148
- // TODO: Review this, not sure we are properly initializing the object
149
- return __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), response);
150
- });
151
- }
152
- delete(id) {
153
- return __awaiter(this, void 0, void 0, function* () {
154
- yield this.request('DELETE', `/tables/${__classPrivateFieldGet(this, _RestRepository_table, "f")}/data/${id}`);
155
- });
156
- }
157
- query(query, options) {
158
- var _a, _b, _c;
159
- return __awaiter(this, void 0, void 0, function* () {
160
- const data = query.getQueryOptions();
161
- const body = {
162
- filter: Object.values(data.filter).some(Boolean) ? data.filter : undefined,
163
- sort: (_a = (0, filters_1.buildSortFilter)(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : data.sort,
164
- page: (_b = options === null || options === void 0 ? void 0 : options.page) !== null && _b !== void 0 ? _b : data.page,
165
- columns: (_c = options === null || options === void 0 ? void 0 : options.columns) !== null && _c !== void 0 ? _c : data.columns
166
- };
167
- const response = yield this.request('POST', `/tables/${__classPrivateFieldGet(this, _RestRepository_table, "f")}/query`, body);
168
- if (!response) {
169
- throw new Error("The server didn't return any data for the query");
170
- }
171
- const { meta, records: objects } = response;
172
- const records = objects.map((record) => __classPrivateFieldGet(this, _RestRepository_client, "f").initObject(__classPrivateFieldGet(this, _RestRepository_table, "f"), record));
173
- // TODO: We should properly type this any
174
- return new pagination_1.Page(query, meta, records);
175
- });
176
- }
177
- }
178
- exports.RestRepository = RestRepository;
179
- _RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap();
180
- class RestRespositoryFactory {
181
- createRepository(client, table) {
182
- return new RestRepository(client, table);
183
- }
184
- }
185
- exports.RestRespositoryFactory = RestRespositoryFactory;
186
- class BaseClient {
187
- constructor(options, links) {
188
- if (!options.databaseURL || !options.apiKey || !options.branch) {
189
- throw new Error('Options databaseURL, apiKey and branch are required');
190
- }
191
- this.options = options;
192
- this.links = links;
193
- }
194
- initObject(table, object) {
195
- const o = {};
196
- Object.assign(o, object);
197
- const tableLinks = this.links[table] || [];
198
- for (const link of tableLinks) {
199
- const [field, linkTable] = link;
200
- const value = o[field];
201
- if (value && typeof value === 'object') {
202
- const { id } = value;
203
- if (Object.keys(value).find((col) => col === 'id')) {
204
- o[field] = this.initObject(linkTable, value);
205
- }
206
- else if (id) {
207
- o[field] = {
208
- id,
209
- get: () => {
210
- this.db[linkTable].read(id);
211
- }
212
- };
213
- }
214
- }
215
- }
216
- const db = this.db;
217
- o.read = function () {
218
- return db[table].read(o['id']);
219
- };
220
- o.update = function (data) {
221
- return db[table].update(o['id'], data);
222
- };
223
- o.delete = function () {
224
- return db[table].delete(o['id']);
225
- };
226
- for (const prop of ['read', 'update', 'delete']) {
227
- Object.defineProperty(o, prop, { enumerable: false });
228
- }
229
- // TODO: links and rev links
230
- Object.freeze(o);
231
- return o;
232
- }
233
- getBranch() {
234
- var e_1, _a;
235
- return __awaiter(this, void 0, void 0, function* () {
236
- if (this.branch)
237
- return this.branch;
238
- const { branch: param } = this.options;
239
- const strategies = Array.isArray(param) ? [...param] : [param];
240
- const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
241
- return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
242
- });
243
- try {
244
- for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
245
- const strategy = strategies_1_1.value;
246
- const branch = yield evaluateBranch(strategy);
247
- if (branch) {
248
- this.branch = branch;
249
- return branch;
250
- }
251
- }
252
- }
253
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
254
- finally {
255
- try {
256
- if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
257
- }
258
- finally { if (e_1) throw e_1.error; }
259
- }
260
- throw new Error('Unable to resolve branch value');
261
- });
262
- }
263
- }
264
- exports.BaseClient = BaseClient;
17
+ exports.XataError = void 0;
265
18
  class XataError extends Error {
266
19
  constructor(message, status) {
267
20
  super(message);
@@ -269,17 +22,5 @@ class XataError extends Error {
269
22
  }
270
23
  }
271
24
  exports.XataError = XataError;
272
- const isBranchStrategyBuilder = (strategy) => {
273
- return typeof strategy === 'function';
274
- };
275
- // TODO: We can find a better implementation for links
276
- const transformObjectLinks = (object) => {
277
- return Object.entries(object).reduce((acc, [key, value]) => {
278
- if (value && typeof value === 'object' && typeof value.id === 'string') {
279
- return Object.assign(Object.assign({}, acc), { [key]: value.id });
280
- }
281
- return Object.assign(Object.assign({}, acc), { [key]: value });
282
- }, {});
283
- };
284
25
  __exportStar(require("./api"), exports);
285
26
  __exportStar(require("./schema"), exports);
@@ -1 +1,6 @@
1
1
  export * from './operators';
2
+ export * from './pagination';
3
+ export { Query } from './query';
4
+ export type { Identifiable, XataRecord } from './record';
5
+ export { BaseClient, Repository, RestRepository, RestRespositoryFactory } from './repository';
6
+ export type { XataClientOptions } from './repository';
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,4 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.BaseClient = exports.Query = void 0;
13
18
  __exportStar(require("./operators"), exports);
19
+ __exportStar(require("./pagination"), exports);
20
+ var query_1 = require("./query");
21
+ Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
22
+ var repository_1 = require("./repository");
23
+ Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
24
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
25
+ Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_1.RestRepository; } });
26
+ Object.defineProperty(exports, "RestRespositoryFactory", { enumerable: true, get: function () { return repository_1.RestRespositoryFactory; } });
@@ -1,21 +1,72 @@
1
1
  import { Constraint } from './filters';
2
2
  declare type ComparableType = number | Date;
3
+ /**
4
+ * Operator to restrict results to only values that are greater than the given value.
5
+ */
3
6
  export declare const gt: <T extends ComparableType>(value: T) => Constraint<T>;
7
+ /**
8
+ * Operator to restrict results to only values that are greater than or equal to the given value.
9
+ */
4
10
  export declare const ge: <T extends ComparableType>(value: T) => Constraint<T>;
11
+ /**
12
+ * Operator to restrict results to only values that are greater than or equal to the given value.
13
+ */
5
14
  export declare const gte: <T extends ComparableType>(value: T) => Constraint<T>;
15
+ /**
16
+ * Operator to restrict results to only values that are lower than the given value.
17
+ */
6
18
  export declare const lt: <T extends ComparableType>(value: T) => Constraint<T>;
19
+ /**
20
+ * Operator to restrict results to only values that are lower than or equal to the given value.
21
+ */
7
22
  export declare const lte: <T extends ComparableType>(value: T) => Constraint<T>;
23
+ /**
24
+ * Operator to restrict results to only values that are lower than or equal to the given value.
25
+ */
8
26
  export declare const le: <T extends ComparableType>(value: T) => Constraint<T>;
27
+ /**
28
+ * Operator to restrict results to only values that are not null.
29
+ */
9
30
  export declare const exists: (column: string) => Constraint<string>;
31
+ /**
32
+ * Operator to restrict results to only values that are null.
33
+ */
10
34
  export declare const notExists: (column: string) => Constraint<string>;
35
+ /**
36
+ * Operator to restrict results to only values that start with the given prefix.
37
+ */
11
38
  export declare const startsWith: (value: string) => Constraint<string>;
39
+ /**
40
+ * Operator to restrict results to only values that end with the given suffix.
41
+ */
12
42
  export declare const endsWith: (value: string) => Constraint<string>;
43
+ /**
44
+ * Operator to restrict results to only values that match the given pattern.
45
+ */
13
46
  export declare const pattern: (value: string) => Constraint<string>;
47
+ /**
48
+ * Operator to restrict results to only values that are equal to the given value.
49
+ */
14
50
  export declare const is: <T>(value: T) => Constraint<T>;
51
+ /**
52
+ * Operator to restrict results to only values that are not equal to the given value.
53
+ */
15
54
  export declare const isNot: <T>(value: T) => Constraint<T>;
55
+ /**
56
+ * Operator to restrict results to only values that contain the given value.
57
+ */
16
58
  export declare const contains: <T>(value: T) => Constraint<T>;
59
+ /**
60
+ * Operator to restrict results to only arrays that include the given value.
61
+ */
17
62
  export declare const includes: (value: string) => Constraint<string>;
63
+ /**
64
+ * Operator to restrict results to only arrays that include a value matching the given substring.
65
+ */
18
66
  export declare const includesSubstring: (value: string) => Constraint<string>;
67
+ /**
68
+ * Operator to restrict results to only arrays that include a value matching the given pattern.
69
+ */
19
70
  export declare const includesPattern: (value: string) => Constraint<string>;
20
71
  export declare const includesAll: (value: string) => Constraint<string>;
21
72
  export {};
@@ -1,39 +1,90 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.includesAll = exports.includesPattern = exports.includesSubstring = 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
+ */
4
7
  const gt = (value) => ({ $gt: value });
5
8
  exports.gt = gt;
9
+ /**
10
+ * Operator to restrict results to only values that are greater than or equal to the given value.
11
+ */
6
12
  const ge = (value) => ({ $ge: value });
7
13
  exports.ge = ge;
14
+ /**
15
+ * Operator to restrict results to only values that are greater than or equal to the given value.
16
+ */
8
17
  const gte = (value) => ({ $ge: value });
9
18
  exports.gte = gte;
19
+ /**
20
+ * Operator to restrict results to only values that are lower than the given value.
21
+ */
10
22
  const lt = (value) => ({ $lt: value });
11
23
  exports.lt = lt;
24
+ /**
25
+ * Operator to restrict results to only values that are lower than or equal to the given value.
26
+ */
12
27
  const lte = (value) => ({ $le: value });
13
28
  exports.lte = lte;
29
+ /**
30
+ * Operator to restrict results to only values that are lower than or equal to the given value.
31
+ */
14
32
  const le = (value) => ({ $le: value });
15
33
  exports.le = le;
34
+ /**
35
+ * Operator to restrict results to only values that are not null.
36
+ */
16
37
  const exists = (column) => ({ $exists: column });
17
38
  exports.exists = exists;
39
+ /**
40
+ * Operator to restrict results to only values that are null.
41
+ */
18
42
  const notExists = (column) => ({ $notExists: column });
19
43
  exports.notExists = notExists;
44
+ /**
45
+ * Operator to restrict results to only values that start with the given prefix.
46
+ */
20
47
  const startsWith = (value) => ({ $startsWith: value });
21
48
  exports.startsWith = startsWith;
49
+ /**
50
+ * Operator to restrict results to only values that end with the given suffix.
51
+ */
22
52
  const endsWith = (value) => ({ $endsWith: value });
23
53
  exports.endsWith = endsWith;
54
+ /**
55
+ * Operator to restrict results to only values that match the given pattern.
56
+ */
24
57
  const pattern = (value) => ({ $pattern: value });
25
58
  exports.pattern = pattern;
59
+ /**
60
+ * Operator to restrict results to only values that are equal to the given value.
61
+ */
26
62
  const is = (value) => ({ $is: value });
27
63
  exports.is = is;
64
+ /**
65
+ * Operator to restrict results to only values that are not equal to the given value.
66
+ */
28
67
  const isNot = (value) => ({ $isNot: value });
29
68
  exports.isNot = isNot;
69
+ /**
70
+ * Operator to restrict results to only values that contain the given value.
71
+ */
30
72
  const contains = (value) => ({ $contains: value });
31
73
  exports.contains = contains;
32
74
  // TODO: these can only be applied to columns of type "multiple"
75
+ /**
76
+ * Operator to restrict results to only arrays that include the given value.
77
+ */
33
78
  const includes = (value) => ({ $includes: value });
34
79
  exports.includes = includes;
80
+ /**
81
+ * Operator to restrict results to only arrays that include a value matching the given substring.
82
+ */
35
83
  const includesSubstring = (value) => ({ $includesSubstring: value });
36
84
  exports.includesSubstring = includesSubstring;
85
+ /**
86
+ * Operator to restrict results to only arrays that include a value matching the given pattern.
87
+ */
37
88
  const includesPattern = (value) => ({ $includesPattern: value });
38
89
  exports.includesPattern = includesPattern;
39
90
  const includesAll = (value) => ({ $includesAll: value });
@@ -1,5 +1,5 @@
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;
@@ -15,15 +15,53 @@ export interface Paginable<T extends XataRecord, R extends XataRecord = T> {
15
15
  lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
16
16
  hasNextPage(): boolean;
17
17
  }
18
- export declare class Page<T extends XataRecord, R extends XataRecord> implements Paginable<T, R> {
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<T extends XataRecord, R extends XataRecord = T> implements Paginable<T, R> {
19
23
  #private;
24
+ /**
25
+ * Page metadata, required to retrieve additional records.
26
+ */
20
27
  readonly meta: PaginationQueryMeta;
28
+ /**
29
+ * The set of results for this page.
30
+ */
21
31
  readonly records: R[];
22
32
  constructor(query: Query<T, R>, meta: PaginationQueryMeta, records?: R[]);
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
+ */
23
39
  nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
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
+ */
24
46
  previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
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
+ */
25
53
  firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
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
+ */
26
60
  lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
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
+ */
27
65
  hasNextPage(): boolean;
28
66
  }
29
67
  export declare type CursorNavigationOptions = {
@@ -39,3 +77,7 @@ export declare type OffsetNavigationOptions = {
39
77
  offset?: number;
40
78
  };
41
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;
@@ -21,7 +21,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
21
21
  };
22
22
  var _Page_query;
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.Page = void 0;
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
+ */
25
29
  class Page {
26
30
  constructor(query, meta, records = []) {
27
31
  _Page_query.set(this, void 0);
@@ -29,30 +33,62 @@ class Page {
29
33
  this.meta = meta;
30
34
  this.records = records;
31
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
+ */
32
42
  nextPage(size, offset) {
33
43
  return __awaiter(this, void 0, void 0, function* () {
34
44
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
35
45
  });
36
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
+ */
37
53
  previousPage(size, offset) {
38
54
  return __awaiter(this, void 0, void 0, function* () {
39
55
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
40
56
  });
41
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
+ */
42
64
  firstPage(size, offset) {
43
65
  return __awaiter(this, void 0, void 0, function* () {
44
66
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
45
67
  });
46
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
+ */
47
75
  lastPage(size, offset) {
48
76
  return __awaiter(this, void 0, void 0, function* () {
49
77
  return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
50
78
  });
51
79
  }
52
80
  // TODO: We need to add something on the backend if we want a hasPreviousPage
81
+ /**
82
+ * Shortcut method to check if there will be additional results if the next page of results is retrieved.
83
+ * @returns Whether or not there will be additional results in the next page of results.
84
+ */
53
85
  hasNextPage() {
54
86
  return this.meta.page.more;
55
87
  }
56
88
  }
57
89
  exports.Page = Page;
58
90
  _Page_query = new WeakMap();
91
+ exports.PAGINATION_MAX_SIZE = 200;
92
+ exports.PAGINATION_DEFAULT_SIZE = 200;
93
+ exports.PAGINATION_MAX_OFFSET = 800;
94
+ exports.PAGINATION_DEFAULT_OFFSET = 0;