@xata.io/client 0.0.0-beta.f12621e → 0.0.0-beta.f46df88

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 (44) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/CHANGELOG.md +49 -0
  3. package/dist/api/client.d.ts +95 -0
  4. package/dist/api/client.js +236 -0
  5. package/dist/api/components.d.ts +1436 -0
  6. package/dist/api/components.js +997 -0
  7. package/dist/api/fetcher.d.ts +25 -0
  8. package/dist/api/fetcher.js +73 -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/index.d.ts +1 -61
  20. package/dist/index.js +7 -268
  21. package/dist/schema/filters.d.ts +7 -5
  22. package/dist/schema/filters.js +2 -1
  23. package/dist/schema/index.d.ts +6 -0
  24. package/dist/schema/index.js +17 -1
  25. package/dist/schema/operators.d.ts +51 -0
  26. package/dist/schema/operators.js +51 -0
  27. package/dist/schema/pagination.d.ts +57 -16
  28. package/dist/schema/pagination.js +56 -7
  29. package/dist/schema/query.d.ts +112 -37
  30. package/dist/schema/query.js +125 -71
  31. package/dist/schema/record.d.ts +66 -0
  32. package/dist/schema/record.js +13 -0
  33. package/dist/schema/repository.d.ts +100 -0
  34. package/dist/schema/repository.js +288 -0
  35. package/dist/schema/selection.d.ts +23 -17
  36. package/dist/schema/selection.spec.d.ts +1 -0
  37. package/dist/schema/selection.spec.js +109 -0
  38. package/dist/util/lang.d.ts +5 -0
  39. package/dist/util/lang.js +22 -0
  40. package/dist/util/types.d.ts +11 -1
  41. package/package.json +2 -2
  42. package/tsconfig.json +21 -0
  43. package/dist/util/errors.d.ts +0 -3
  44. package/dist/util/errors.js +0 -9
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,262 +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 __asyncValues = (this && this.__asyncValues) || function (o) {
22
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
23
- var m = o[Symbol.asyncIterator], i;
24
- 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);
25
- 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); }); }; }
26
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
27
- };
28
16
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
30
- const filters_1 = require("./schema/filters");
31
- const pagination_1 = require("./schema/pagination");
32
- const query_1 = require("./schema/query");
33
- const errors_1 = require("./util/errors");
34
- class Repository extends query_1.Query {
35
- select(columns) {
36
- return new query_1.Query(this.repository, this.table, { columns });
37
- }
38
- }
39
- exports.Repository = Repository;
40
- class RestRepository extends Repository {
41
- constructor(client, table) {
42
- super(null, table, {});
43
- this.client = client;
44
- const doWeHaveFetch = typeof fetch !== 'undefined';
45
- const isInjectedFetchProblematic = !this.client.options.fetch;
46
- if (doWeHaveFetch) {
47
- this.fetch = fetch;
48
- }
49
- else if (isInjectedFetchProblematic) {
50
- throw new Error(errors_1.errors.falsyFetchImplementation);
51
- }
52
- else {
53
- this.fetch = this.client.options.fetch;
54
- }
55
- Object.defineProperty(this, 'client', { enumerable: false });
56
- Object.defineProperty(this, 'fetch', { enumerable: false });
57
- Object.defineProperty(this, 'hostname', { enumerable: false });
58
- }
59
- request(method, path, body) {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- const { databaseURL, apiKey } = this.client.options;
62
- const branch = yield this.client.getBranch();
63
- const fetchImpl = this.fetch;
64
- const resp = yield fetchImpl(`${databaseURL}:${branch}${path}`, {
65
- method,
66
- headers: {
67
- Accept: '*/*',
68
- 'Content-Type': 'application/json',
69
- Authorization: `Bearer ${apiKey}`
70
- },
71
- body: JSON.stringify(body)
72
- });
73
- if (!resp.ok) {
74
- try {
75
- const json = yield resp.json();
76
- const message = json.message;
77
- if (typeof message === 'string') {
78
- throw new XataError(message, resp.status);
79
- }
80
- }
81
- catch (err) {
82
- if (err instanceof XataError)
83
- throw err;
84
- // Ignore errors for other reasons.
85
- // For example if the response's body cannot be parsed as JSON
86
- }
87
- throw new XataError(resp.statusText, resp.status);
88
- }
89
- if (resp.status === 204)
90
- return undefined;
91
- return resp.json();
92
- });
93
- }
94
- select(columns) {
95
- return new query_1.Query(this.repository, this.table, { columns });
96
- }
97
- create(object) {
98
- return __awaiter(this, void 0, void 0, function* () {
99
- const record = transformObjectLinks(object);
100
- const response = yield this.request('POST', `/tables/${this.table}/data`, record);
101
- if (!response) {
102
- throw new Error("The server didn't return any data for the query");
103
- }
104
- const finalObject = yield this.read(response.id);
105
- if (!finalObject) {
106
- throw new Error('The server failed to save the record');
107
- }
108
- return finalObject;
109
- });
110
- }
111
- createMany(objects) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- const records = objects.map((object) => transformObjectLinks(object));
114
- const response = yield this.request('POST', `/tables/${this.table}/bulk`, { records });
115
- if (!response) {
116
- throw new Error("The server didn't return any data for the query");
117
- }
118
- // TODO: Use filer.$any() to get all the records
119
- const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));
120
- if (finalObjects.some((object) => !object)) {
121
- throw new Error('The server failed to save the record');
122
- }
123
- return finalObjects;
124
- });
125
- }
126
- read(id) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- try {
129
- const response = yield this.request('GET', `/tables/${this.table}/data/${id}`);
130
- if (!response)
131
- return null;
132
- return this.client.initObject(this.table, response);
133
- }
134
- catch (err) {
135
- if (err.status === 404)
136
- return null;
137
- throw err;
138
- }
139
- });
140
- }
141
- update(id, object) {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- const response = yield this.request('PUT', `/tables/${this.table}/data/${id}`, object);
144
- if (!response) {
145
- throw new Error("The server didn't return any data for the query");
146
- }
147
- // TODO: Review this, not sure we are properly initializing the object
148
- return this.client.initObject(this.table, response);
149
- });
150
- }
151
- delete(id) {
152
- return __awaiter(this, void 0, void 0, function* () {
153
- yield this.request('DELETE', `/tables/${this.table}/data/${id}`);
154
- });
155
- }
156
- _runQuery(query, options) {
157
- var _a, _b;
158
- return __awaiter(this, void 0, void 0, function* () {
159
- const filter = {
160
- $any: query.$any,
161
- $all: query.$all,
162
- $not: query.$not,
163
- $none: query.$none
164
- };
165
- const body = {
166
- filter: Object.values(filter).some(Boolean) ? filter : undefined,
167
- sort: (_a = (0, filters_1.buildSortFilter)(options === null || options === void 0 ? void 0 : options.sort)) !== null && _a !== void 0 ? _a : query.$sort,
168
- page: options === null || options === void 0 ? void 0 : options.page,
169
- columns: (_b = options === null || options === void 0 ? void 0 : options.columns) !== null && _b !== void 0 ? _b : query.columns
170
- };
171
- const response = yield this.request('POST', `/tables/${this.table}/query`, body);
172
- if (!response) {
173
- throw new Error("The server didn't return any data for the query");
174
- }
175
- const { meta, records: objects } = response;
176
- const records = objects.map((record) => this.client.initObject(this.table, record));
177
- // TODO: We should properly type this any
178
- return new pagination_1.Page(query, meta, records);
179
- });
180
- }
181
- }
182
- exports.RestRepository = RestRepository;
183
- class RestRespositoryFactory {
184
- createRepository(client, table) {
185
- return new RestRepository(client, table);
186
- }
187
- }
188
- exports.RestRespositoryFactory = RestRespositoryFactory;
189
- class BaseClient {
190
- constructor(options, links) {
191
- if (!options.databaseURL || !options.apiKey || !options.branch) {
192
- throw new Error('Options databaseURL, apiKey and branch are required');
193
- }
194
- this.options = options;
195
- this.links = links;
196
- }
197
- initObject(table, object) {
198
- const o = {};
199
- Object.assign(o, object);
200
- const tableLinks = this.links[table] || [];
201
- for (const link of tableLinks) {
202
- const [field, linkTable] = link;
203
- const value = o[field];
204
- if (value && typeof value === 'object') {
205
- const { id } = value;
206
- if (Object.keys(value).find((col) => col === 'id')) {
207
- o[field] = this.initObject(linkTable, value);
208
- }
209
- else if (id) {
210
- o[field] = {
211
- id,
212
- get: () => {
213
- this.db[linkTable].read(id);
214
- }
215
- };
216
- }
217
- }
218
- }
219
- const db = this.db;
220
- o.read = function () {
221
- return db[table].read(o['id']);
222
- };
223
- o.update = function (data) {
224
- return db[table].update(o['id'], data);
225
- };
226
- o.delete = function () {
227
- return db[table].delete(o['id']);
228
- };
229
- for (const prop of ['read', 'update', 'delete']) {
230
- Object.defineProperty(o, prop, { enumerable: false });
231
- }
232
- // TODO: links and rev links
233
- Object.freeze(o);
234
- return o;
235
- }
236
- getBranch() {
237
- var e_1, _a;
238
- return __awaiter(this, void 0, void 0, function* () {
239
- if (this.branch)
240
- return this.branch;
241
- const { branch: param } = this.options;
242
- const strategies = Array.isArray(param) ? [...param] : [param];
243
- const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
244
- return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
245
- });
246
- try {
247
- for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
248
- const strategy = strategies_1_1.value;
249
- const branch = yield evaluateBranch(strategy);
250
- if (branch) {
251
- this.branch = branch;
252
- return branch;
253
- }
254
- }
255
- }
256
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
257
- finally {
258
- try {
259
- if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
260
- }
261
- finally { if (e_1) throw e_1.error; }
262
- }
263
- throw new Error('Unable to resolve branch value');
264
- });
265
- }
266
- }
267
- exports.BaseClient = BaseClient;
17
+ exports.XataError = void 0;
268
18
  class XataError extends Error {
269
19
  constructor(message, status) {
270
20
  super(message);
@@ -272,16 +22,5 @@ class XataError extends Error {
272
22
  }
273
23
  }
274
24
  exports.XataError = XataError;
275
- const isBranchStrategyBuilder = (strategy) => {
276
- return typeof strategy === 'function';
277
- };
278
- // TODO: We can find a better implementation for links
279
- const transformObjectLinks = (object) => {
280
- return Object.entries(object).reduce((acc, [key, value]) => {
281
- if (value && typeof value === 'object' && typeof value.id === 'string') {
282
- return Object.assign(Object.assign({}, acc), { [key]: value.id });
283
- }
284
- return Object.assign(Object.assign({}, acc), { [key]: value });
285
- }, {});
286
- };
25
+ __exportStar(require("./api"), exports);
287
26
  __exportStar(require("./schema"), exports);
@@ -1,12 +1,14 @@
1
+ import { XataRecord } from './record';
2
+ import { SelectableColumn } from './selection';
1
3
  export declare type SortDirection = 'asc' | 'desc';
2
- export declare type SortFilterExtended<T> = {
3
- column: keyof T;
4
+ export declare type SortFilterExtended<T extends XataRecord> = {
5
+ column: SelectableColumn<T>;
4
6
  direction?: SortDirection;
5
7
  };
6
- export declare type SortFilter<T> = SortFilterExtended<T> | keyof T;
7
- export declare function isSortFilterObject<T>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
8
+ export declare type SortFilter<T extends XataRecord> = SelectableColumn<T> | SortFilterExtended<T>;
9
+ export declare function isSortFilterObject<T extends XataRecord>(filter: SortFilter<T>): filter is SortFilterExtended<T>;
8
10
  export declare type FilterOperator = '$gt' | '$lt' | '$ge' | '$le' | '$exists' | '$notExists' | '$endsWith' | '$startsWith' | '$pattern' | '$is' | '$isNot' | '$contains' | '$includes' | '$includesSubstring' | '$includesPattern' | '$includesAll';
9
- export declare function buildSortFilter<T>(filter?: SortFilter<T> | SortFilter<T>[]): {
11
+ export declare function buildSortFilter<T extends XataRecord>(filter?: SortFilter<T> | SortFilter<T>[]): {
10
12
  [key: string]: SortDirection;
11
13
  } | undefined;
12
14
  export declare type Constraint<T> = {
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildSortFilter = exports.isSortFilterObject = void 0;
4
+ const lang_1 = require("../util/lang");
4
5
  function isSortFilterObject(filter) {
5
- return typeof filter === 'object' && filter.column !== undefined;
6
+ return (0, lang_1.isObject)(filter) && filter.column !== undefined;
6
7
  }
7
8
  exports.isSortFilterObject = isSortFilterObject;
8
9
  function buildSortFilter(filter) {
@@ -1 +1,7 @@
1
1
  export * from './operators';
2
+ export * from './pagination';
3
+ export { Query } from './query';
4
+ export { isIdentifiable, isXataRecord } from './record';
5
+ export type { Identifiable, XataRecord } from './record';
6
+ export { BaseClient, Repository, RestRepository, RestRespositoryFactory } from './repository';
7
+ 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,16 @@ 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.isXataRecord = exports.isIdentifiable = 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 record_1 = require("./record");
23
+ Object.defineProperty(exports, "isIdentifiable", { enumerable: true, get: function () { return record_1.isIdentifiable; } });
24
+ Object.defineProperty(exports, "isXataRecord", { enumerable: true, get: function () { return record_1.isXataRecord; } });
25
+ var repository_1 = require("./repository");
26
+ Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
27
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
28
+ Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_1.RestRepository; } });
29
+ 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,30 +1,67 @@
1
- import { XataRecord } from '..';
2
1
  import { Query } from './query';
2
+ import { XataRecord } from './record';
3
3
  export declare type PaginationQueryMeta = {
4
4
  page: {
5
5
  cursor: string;
6
6
  more: boolean;
7
7
  };
8
8
  };
9
- export interface BasePage<T extends XataRecord, R extends XataRecord> {
10
- query: Query<T, R>;
9
+ export interface Paginable<Record extends XataRecord, Result extends XataRecord = Record> {
11
10
  meta: PaginationQueryMeta;
12
- records: R[];
13
- nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
14
- previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
15
- firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
16
- lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
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>>;
17
16
  hasNextPage(): boolean;
18
17
  }
19
- export declare class Page<T extends XataRecord, R extends XataRecord> implements BasePage<T, R> {
20
- readonly query: Query<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<Record extends XataRecord, Result extends XataRecord = Record> implements Paginable<Record, Result> {
23
+ #private;
24
+ /**
25
+ * Page metadata, required to retrieve additional records.
26
+ */
21
27
  readonly meta: PaginationQueryMeta;
22
- readonly records: R[];
23
- constructor(query: Query<T, R>, meta: PaginationQueryMeta, records?: R[]);
24
- nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
25
- previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
26
- firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
27
- lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
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
+ */
28
65
  hasNextPage(): boolean;
29
66
  }
30
67
  export declare type CursorNavigationOptions = {
@@ -40,3 +77,7 @@ export declare type OffsetNavigationOptions = {
40
77
  offset?: number;
41
78
  };
42
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;