@xata.io/client 0.1.4 → 0.3.0

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 (45) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +201 -0
  3. package/dist/api/client.d.ts +95 -0
  4. package/dist/api/client.js +235 -0
  5. package/dist/api/components.d.ts +1440 -0
  6. package/dist/api/components.js +1001 -0
  7. package/dist/api/fetcher.d.ts +25 -0
  8. package/dist/api/fetcher.js +78 -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 +29 -0
  15. package/dist/api/responses.d.ts +44 -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 +2 -122
  20. package/dist/index.js +16 -324
  21. package/dist/schema/filters.d.ts +20 -0
  22. package/dist/schema/filters.js +24 -0
  23. package/dist/schema/index.d.ts +5 -0
  24. package/dist/schema/index.js +25 -0
  25. package/dist/schema/operators.d.ts +72 -0
  26. package/dist/schema/operators.js +91 -0
  27. package/dist/schema/pagination.d.ts +79 -0
  28. package/dist/schema/pagination.js +90 -0
  29. package/dist/schema/query.d.ts +114 -0
  30. package/dist/schema/query.js +227 -0
  31. package/dist/schema/record.d.ts +36 -0
  32. package/dist/schema/record.js +2 -0
  33. package/dist/schema/repository.d.ts +109 -0
  34. package/dist/schema/repository.js +273 -0
  35. package/dist/schema/selection.d.ts +13 -0
  36. package/dist/schema/selection.js +2 -0
  37. package/dist/util/lang.d.ts +2 -0
  38. package/dist/util/lang.js +10 -0
  39. package/dist/util/types.d.ts +3 -0
  40. package/dist/util/types.js +2 -0
  41. package/package.json +4 -3
  42. package/dist/index.test.d.ts +0 -1
  43. package/dist/index.test.js +0 -182
  44. package/src/index.test.ts +0 -222
  45. package/src/index.ts +0 -466
package/dist/index.js CHANGED
@@ -1,330 +1,20 @@
1
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
- });
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);
10
15
  };
11
16
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = exports.Query = 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;
13
- const gt = (value) => ({ $gt: value });
14
- exports.gt = gt;
15
- const ge = (value) => ({ $ge: value });
16
- exports.ge = ge;
17
- const gte = (value) => ({ $ge: value });
18
- exports.gte = gte;
19
- const lt = (value) => ({ $lt: value });
20
- exports.lt = lt;
21
- const lte = (value) => ({ $le: value });
22
- exports.lte = lte;
23
- const le = (value) => ({ $le: value });
24
- exports.le = le;
25
- const exists = (column) => ({ $exists: column });
26
- exports.exists = exists;
27
- const notExists = (column) => ({ $notExists: column });
28
- exports.notExists = notExists;
29
- const startsWith = (value) => ({ $startsWith: value });
30
- exports.startsWith = startsWith;
31
- const endsWith = (value) => ({ $endsWith: value });
32
- exports.endsWith = endsWith;
33
- const pattern = (value) => ({ $pattern: value });
34
- exports.pattern = pattern;
35
- const is = (value) => ({ $is: value });
36
- exports.is = is;
37
- const isNot = (value) => ({ $isNot: value });
38
- exports.isNot = isNot;
39
- const contains = (value) => ({ $contains: value });
40
- exports.contains = contains;
41
- // TODO: these can only be applied to columns of type "multiple"
42
- const includes = (value) => ({ $includes: value });
43
- exports.includes = includes;
44
- const includesSubstring = (value) => ({ $includesSubstring: value });
45
- exports.includesSubstring = includesSubstring;
46
- const includesPattern = (value) => ({ $includesPattern: value });
47
- exports.includesPattern = includesPattern;
48
- const includesAll = (value) => ({ $includesAll: value });
49
- exports.includesAll = includesAll;
50
- class Query {
51
- constructor(repository, table, data, parent) {
52
- if (repository) {
53
- this.repository = repository;
54
- }
55
- else {
56
- this.repository = this;
57
- }
58
- this.table = table;
59
- // For some reason Object.assign(this, parent) didn't work in this case
60
- // so doing all this manually:
61
- this.$any = parent === null || parent === void 0 ? void 0 : parent.$any;
62
- this.$all = parent === null || parent === void 0 ? void 0 : parent.$all;
63
- this.$not = parent === null || parent === void 0 ? void 0 : parent.$not;
64
- this.$none = parent === null || parent === void 0 ? void 0 : parent.$none;
65
- this.$sort = parent === null || parent === void 0 ? void 0 : parent.$sort;
66
- Object.assign(this, data);
67
- // These bindings are used to support deconstructing
68
- // const { any, not, filter, sort } = xata.users.query()
69
- this.any = this.any.bind(this);
70
- this.all = this.all.bind(this);
71
- this.not = this.not.bind(this);
72
- this.filter = this.filter.bind(this);
73
- this.sort = this.sort.bind(this);
74
- this.none = this.none.bind(this);
75
- Object.defineProperty(this, 'table', { enumerable: false });
76
- Object.defineProperty(this, 'repository', { enumerable: false });
77
- }
78
- any(...queries) {
79
- return new Query(this.repository, this.table, {
80
- $any: (this.$any || []).concat(queries)
81
- }, this);
82
- }
83
- all(...queries) {
84
- return new Query(this.repository, this.table, {
85
- $all: (this.$all || []).concat(queries)
86
- }, this);
87
- }
88
- not(...queries) {
89
- return new Query(this.repository, this.table, {
90
- $not: (this.$not || []).concat(queries)
91
- }, this);
92
- }
93
- none(...queries) {
94
- return new Query(this.repository, this.table, {
95
- $none: (this.$none || []).concat(queries)
96
- }, this);
97
- }
98
- filter(a, b) {
99
- if (arguments.length === 1) {
100
- const constraints = a;
101
- const queries = [];
102
- for (const [column, constraint] of Object.entries(constraints)) {
103
- queries.push({ [column]: constraint });
104
- }
105
- return new Query(this.repository, this.table, {
106
- $all: (this.$all || []).concat(queries)
107
- }, this);
108
- }
109
- else {
110
- const column = a;
111
- const value = b;
112
- return new Query(this.repository, this.table, {
113
- $all: (this.$all || []).concat({ [column]: value })
114
- }, this);
115
- }
116
- }
117
- sort(column, direction) {
118
- const sort = Object.assign(Object.assign({}, this.$sort), { [column]: direction });
119
- const q = new Query(this.repository, this.table, {
120
- $sort: sort
121
- }, this);
122
- return q;
123
- }
124
- // TODO: pagination. Maybe implement different methods for different type of paginations
125
- // and one to simply get the first records returned by the query with no pagination.
126
- getMany(options) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- // TODO: use options
129
- return this.repository.query(this);
130
- });
131
- }
132
- getOne(options) {
133
- return __awaiter(this, void 0, void 0, function* () {
134
- // TODO: use options
135
- const arr = yield this.getMany(); // TODO, limit to 1
136
- return arr[0] || null;
137
- });
138
- }
139
- deleteAll() {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- // Return number of affected rows
142
- return 0;
143
- });
144
- }
145
- include(columns) {
146
- // TODO
147
- return this;
148
- }
149
- }
150
- exports.Query = Query;
151
- class Repository extends Query {
152
- select(...columns) {
153
- return new Query(this.repository, this.table, {});
154
- }
155
- }
156
- exports.Repository = Repository;
157
- class RestRepository extends Repository {
158
- constructor(client, table) {
159
- super(null, table, {});
160
- this.client = client;
161
- const { fetch } = client.options;
162
- if (fetch) {
163
- this.fetch = fetch;
164
- }
165
- else if (typeof window === 'object') {
166
- this.fetch = window.fetch;
167
- }
168
- else if (typeof require === 'function') {
169
- try {
170
- this.fetch = require('node-fetch');
171
- }
172
- catch (err) {
173
- try {
174
- this.fetch = require('cross-fetch');
175
- }
176
- catch (err) {
177
- throw new Error('No fetch implementation found. Please provide one in the constructor');
178
- }
179
- }
180
- }
181
- Object.defineProperty(this, 'client', { enumerable: false });
182
- Object.defineProperty(this, 'fetch', { enumerable: false });
183
- Object.defineProperty(this, 'hostname', { enumerable: false });
184
- }
185
- request(method, path, body) {
186
- return __awaiter(this, void 0, void 0, function* () {
187
- const { databaseURL } = this.client.options;
188
- const resp = yield this.fetch(`${databaseURL}${path}`, {
189
- method,
190
- headers: {
191
- Accept: '*/*',
192
- 'Content-Type': 'application/json',
193
- Authorization: `Bearer ${this.client.options.apiKey}`
194
- },
195
- body: JSON.stringify(body)
196
- });
197
- if (!resp.ok) {
198
- try {
199
- const json = yield resp.json();
200
- const message = json.message;
201
- if (typeof message === 'string') {
202
- throw new XataError(message, resp.status);
203
- }
204
- }
205
- catch (err) {
206
- if (err instanceof XataError)
207
- throw err;
208
- // Ignore errors for other reasons.
209
- // For example if the response's body cannot be parsed as JSON
210
- }
211
- throw new XataError(resp.statusText, resp.status);
212
- }
213
- if (resp.status === 204)
214
- return;
215
- return resp.json();
216
- });
217
- }
218
- select(...columns) {
219
- return new Query(this.repository, this.table, {});
220
- }
221
- create(object) {
222
- return __awaiter(this, void 0, void 0, function* () {
223
- const body = Object.assign({}, object);
224
- for (const key of Object.keys(body)) {
225
- const value = body[key];
226
- if (value && typeof value === 'object' && typeof value._id === 'string') {
227
- body[key] = value._id;
228
- }
229
- }
230
- const obj = yield this.request('POST', `/tables/${this.table}/data`, body);
231
- return this.client.initObject(this.table, obj);
232
- });
233
- }
234
- read(id) {
235
- return __awaiter(this, void 0, void 0, function* () {
236
- try {
237
- const obj = yield this.request('GET', `/tables/${this.table}/data/${id}`);
238
- return this.client.initObject(this.table, obj);
239
- }
240
- catch (err) {
241
- if (err.status === 404)
242
- return null;
243
- throw err;
244
- }
245
- });
246
- }
247
- update(id, object) {
248
- return __awaiter(this, void 0, void 0, function* () {
249
- const obj = yield this.request('PUT', `/tables/${this.table}/data/${id}`, object);
250
- return this.client.initObject(this.table, obj);
251
- });
252
- }
253
- delete(id) {
254
- return __awaiter(this, void 0, void 0, function* () {
255
- yield this.request('DELETE', `/tables/${this.table}/data/${id}`);
256
- });
257
- }
258
- query(query) {
259
- return __awaiter(this, void 0, void 0, function* () {
260
- const filter = {
261
- $any: query.$any,
262
- $all: query.$all,
263
- $not: query.$not,
264
- $none: query.$none
265
- };
266
- const body = {
267
- filter: Object.values(filter).some(Boolean) ? filter : undefined,
268
- sort: query.$sort
269
- };
270
- const result = yield this.request('POST', `/tables/${this.table}/query`, body);
271
- return result.records.map((record) => this.client.initObject(this.table, record));
272
- });
273
- }
274
- }
275
- exports.RestRepository = RestRepository;
276
- class RestRespositoryFactory {
277
- createRepository(client, table) {
278
- return new RestRepository(client, table);
279
- }
280
- }
281
- exports.RestRespositoryFactory = RestRespositoryFactory;
282
- class BaseClient {
283
- constructor(options, links) {
284
- this.options = options;
285
- this.links = links;
286
- }
287
- initObject(table, object) {
288
- const o = {};
289
- Object.assign(o, object);
290
- const tableLinks = this.links[table] || [];
291
- for (const link of tableLinks) {
292
- const [field, linkTable] = link;
293
- const value = o[field];
294
- if (value && typeof value === 'object') {
295
- const { _id } = value;
296
- if (Object.keys(value).find((col) => !col.startsWith('_'))) {
297
- o[field] = this.initObject(linkTable, value);
298
- }
299
- else if (_id) {
300
- o[field] = {
301
- _id,
302
- get: () => {
303
- this.db[linkTable].read(_id);
304
- }
305
- };
306
- }
307
- }
308
- }
309
- const db = this.db;
310
- o.read = function () {
311
- return db[table].read(o['_id']);
312
- };
313
- o.update = function (data) {
314
- return db[table].update(o['_id'], data);
315
- };
316
- o.delete = function () {
317
- return db[table].delete(o['_id']);
318
- };
319
- for (const prop of ['read', 'update', 'delete']) {
320
- Object.defineProperty(o, prop, { enumerable: false });
321
- }
322
- // TODO: links and rev links
323
- Object.freeze(o);
324
- return o;
325
- }
326
- }
327
- exports.BaseClient = BaseClient;
17
+ exports.XataError = void 0;
328
18
  class XataError extends Error {
329
19
  constructor(message, status) {
330
20
  super(message);
@@ -332,3 +22,5 @@ class XataError extends Error {
332
22
  }
333
23
  }
334
24
  exports.XataError = XataError;
25
+ __exportStar(require("./api"), exports);
26
+ __exportStar(require("./schema"), exports);
@@ -0,0 +1,20 @@
1
+ export declare type SortDirection = 'asc' | 'desc';
2
+ export declare type SortFilterExtended<T> = {
3
+ column: keyof T;
4
+ direction?: SortDirection;
5
+ };
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 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>[]): {
10
+ [key: string]: SortDirection;
11
+ } | undefined;
12
+ export declare type Constraint<T> = {
13
+ [key in FilterOperator]?: T;
14
+ };
15
+ export declare type DeepConstraint<T> = T extends Record<string, any> ? {
16
+ [key in keyof T]?: T[key] | DeepConstraint<T[key]>;
17
+ } : Constraint<T>;
18
+ export declare type FilterConstraints<T> = {
19
+ [key in keyof T]?: T[key] extends Record<string, any> ? FilterConstraints<T[key]> : T[key] | DeepConstraint<T[key]>;
20
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildSortFilter = exports.isSortFilterObject = void 0;
4
+ function isSortFilterObject(filter) {
5
+ return typeof filter === 'object' && filter.column !== undefined;
6
+ }
7
+ exports.isSortFilterObject = isSortFilterObject;
8
+ function buildSortFilter(filter) {
9
+ if (!filter)
10
+ return undefined;
11
+ const filters = Array.isArray(filter) ? filter : [filter];
12
+ return filters.reduce((acc, item) => {
13
+ if (typeof item === 'string') {
14
+ return Object.assign(Object.assign({}, acc), { [item]: 'asc' });
15
+ }
16
+ else if (isSortFilterObject(item)) {
17
+ return Object.assign(Object.assign({}, acc), { [item.column]: item.direction });
18
+ }
19
+ else {
20
+ return acc;
21
+ }
22
+ }, {});
23
+ }
24
+ exports.buildSortFilter = buildSortFilter;
@@ -0,0 +1,5 @@
1
+ export * from './operators';
2
+ export type { XataRecord } from './record';
3
+ export { Repository, RestRepository, RestRespositoryFactory, BaseClient } from './repository';
4
+ export type { XataClientOptions } from './repository';
5
+ export { Query } from './query';
@@ -0,0 +1,25 @@
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.Query = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository = void 0;
18
+ __exportStar(require("./operators"), exports);
19
+ var repository_1 = require("./repository");
20
+ Object.defineProperty(exports, "Repository", { enumerable: true, get: function () { return repository_1.Repository; } });
21
+ Object.defineProperty(exports, "RestRepository", { enumerable: true, get: function () { return repository_1.RestRepository; } });
22
+ Object.defineProperty(exports, "RestRespositoryFactory", { enumerable: true, get: function () { return repository_1.RestRespositoryFactory; } });
23
+ Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return repository_1.BaseClient; } });
24
+ var query_1 = require("./query");
25
+ Object.defineProperty(exports, "Query", { enumerable: true, get: function () { return query_1.Query; } });
@@ -0,0 +1,72 @@
1
+ import { Constraint } from './filters';
2
+ declare type ComparableType = number | Date;
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) => Constraint<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) => Constraint<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) => Constraint<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) => Constraint<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) => Constraint<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) => Constraint<T>;
27
+ /**
28
+ * Operator to restrict results to only values that are not null.
29
+ */
30
+ export declare const exists: (column: string) => Constraint<string>;
31
+ /**
32
+ * Operator to restrict results to only values that are null.
33
+ */
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
+ */
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
+ */
42
+ export declare const endsWith: (value: string) => Constraint<string>;
43
+ /**
44
+ * Operator to restrict results to only values that match the given pattern.
45
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
70
+ export declare const includesPattern: (value: string) => Constraint<string>;
71
+ export declare const includesAll: (value: string) => Constraint<string>;
72
+ export {};
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
+ */
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
+ // 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
+ */
78
+ const includes = (value) => ({ $includes: value });
79
+ exports.includes = includes;
80
+ /**
81
+ * Operator to restrict results to only arrays that include a value matching the given substring.
82
+ */
83
+ const includesSubstring = (value) => ({ $includesSubstring: value });
84
+ exports.includesSubstring = includesSubstring;
85
+ /**
86
+ * Operator to restrict results to only arrays that include a value matching the given pattern.
87
+ */
88
+ const includesPattern = (value) => ({ $includesPattern: value });
89
+ exports.includesPattern = includesPattern;
90
+ const includesAll = (value) => ({ $includesAll: value });
91
+ exports.includesAll = includesAll;
@@ -0,0 +1,79 @@
1
+ import { XataRecord } from '..';
2
+ import { Query } from './query';
3
+ export declare type PaginationQueryMeta = {
4
+ page: {
5
+ cursor: string;
6
+ more: boolean;
7
+ };
8
+ };
9
+ export interface Paginable<T extends XataRecord, R extends XataRecord = T> {
10
+ meta: PaginationQueryMeta;
11
+ records: R[];
12
+ nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
13
+ previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
14
+ firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
15
+ lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
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<T extends XataRecord, R extends XataRecord> implements Paginable<T, R> {
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: R[];
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
+ */
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
+ */
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
+ */
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
+ */
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
+ */
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;