@xata.io/client 0.0.0-beta.bbcb88d → 0.0.0-beta.bdce130
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/api/client.d.ts +90 -0
- package/dist/api/client.js +206 -0
- package/dist/api/components.d.ts +1430 -0
- package/dist/api/components.js +1001 -0
- package/dist/api/fetcher.d.ts +24 -0
- package/dist/api/fetcher.js +75 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.js +17 -0
- package/dist/api/parameters.d.ts +16 -0
- package/dist/api/parameters.js +2 -0
- package/dist/api/providers.d.ts +8 -0
- package/dist/api/providers.js +29 -0
- package/dist/api/responses.d.ts +38 -0
- package/dist/api/responses.js +2 -0
- package/dist/api/schemas.d.ts +311 -0
- package/dist/api/schemas.js +2 -0
- package/dist/index.d.ts +16 -89
- package/dist/index.js +104 -189
- package/dist/schema/filters.d.ts +20 -0
- package/dist/schema/filters.js +24 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +13 -0
- package/dist/schema/operators.d.ts +21 -0
- package/dist/schema/operators.js +40 -0
- package/dist/schema/pagination.d.ts +41 -0
- package/dist/schema/pagination.js +58 -0
- package/dist/schema/query.d.ts +110 -0
- package/dist/schema/query.js +190 -0
- package/dist/schema/selection.d.ts +18 -0
- package/dist/schema/selection.js +2 -0
- package/dist/util/lang.d.ts +1 -0
- package/dist/util/lang.js +10 -0
- package/dist/util/types.d.ts +3 -0
- package/dist/util/types.js +2 -0
- package/package.json +3 -3
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -304
- package/dist/util/errors.d.ts +0 -3
- package/dist/util/errors.js +0 -9
- package/src/index.test.ts +0 -392
- package/src/index.ts +0 -501
- package/src/util/errors.ts +0 -6
- package/tsconfig.json +0 -21
package/dist/index.js
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
|
+
};
|
2
12
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
13
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
14
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -8,6 +18,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
8
18
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
19
|
});
|
10
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
|
+
};
|
11
32
|
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
12
33
|
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
13
34
|
var m = o[Symbol.asyncIterator], i;
|
@@ -15,177 +36,36 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
15
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); }); }; }
|
16
37
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
17
38
|
};
|
39
|
+
var _RestRepository_client, _RestRepository_fetch, _RestRepository_table;
|
18
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
-
exports.XataError = exports.BaseClient = exports.RestRespositoryFactory = exports.RestRepository = exports.Repository =
|
20
|
-
const
|
21
|
-
const
|
22
|
-
|
23
|
-
|
24
|
-
exports.ge = ge;
|
25
|
-
const gte = (value) => ({ $ge: value });
|
26
|
-
exports.gte = gte;
|
27
|
-
const lt = (value) => ({ $lt: value });
|
28
|
-
exports.lt = lt;
|
29
|
-
const lte = (value) => ({ $le: value });
|
30
|
-
exports.lte = lte;
|
31
|
-
const le = (value) => ({ $le: value });
|
32
|
-
exports.le = le;
|
33
|
-
const exists = (column) => ({ $exists: column });
|
34
|
-
exports.exists = exists;
|
35
|
-
const notExists = (column) => ({ $notExists: column });
|
36
|
-
exports.notExists = notExists;
|
37
|
-
const startsWith = (value) => ({ $startsWith: value });
|
38
|
-
exports.startsWith = startsWith;
|
39
|
-
const endsWith = (value) => ({ $endsWith: value });
|
40
|
-
exports.endsWith = endsWith;
|
41
|
-
const pattern = (value) => ({ $pattern: value });
|
42
|
-
exports.pattern = pattern;
|
43
|
-
const is = (value) => ({ $is: value });
|
44
|
-
exports.is = is;
|
45
|
-
const isNot = (value) => ({ $isNot: value });
|
46
|
-
exports.isNot = isNot;
|
47
|
-
const contains = (value) => ({ $contains: value });
|
48
|
-
exports.contains = contains;
|
49
|
-
// TODO: these can only be applied to columns of type "multiple"
|
50
|
-
const includes = (value) => ({ $includes: value });
|
51
|
-
exports.includes = includes;
|
52
|
-
const includesSubstring = (value) => ({ $includesSubstring: value });
|
53
|
-
exports.includesSubstring = includesSubstring;
|
54
|
-
const includesPattern = (value) => ({ $includesPattern: value });
|
55
|
-
exports.includesPattern = includesPattern;
|
56
|
-
const includesAll = (value) => ({ $includesAll: value });
|
57
|
-
exports.includesAll = includesAll;
|
58
|
-
class Query {
|
59
|
-
constructor(repository, table, data, parent) {
|
60
|
-
if (repository) {
|
61
|
-
this.repository = repository;
|
62
|
-
}
|
63
|
-
else {
|
64
|
-
this.repository = this;
|
65
|
-
}
|
66
|
-
this.table = table;
|
67
|
-
// For some reason Object.assign(this, parent) didn't work in this case
|
68
|
-
// so doing all this manually:
|
69
|
-
this.$any = parent === null || parent === void 0 ? void 0 : parent.$any;
|
70
|
-
this.$all = parent === null || parent === void 0 ? void 0 : parent.$all;
|
71
|
-
this.$not = parent === null || parent === void 0 ? void 0 : parent.$not;
|
72
|
-
this.$none = parent === null || parent === void 0 ? void 0 : parent.$none;
|
73
|
-
this.$sort = parent === null || parent === void 0 ? void 0 : parent.$sort;
|
74
|
-
Object.assign(this, data);
|
75
|
-
// These bindings are used to support deconstructing
|
76
|
-
// const { any, not, filter, sort } = xata.users.query()
|
77
|
-
this.any = this.any.bind(this);
|
78
|
-
this.all = this.all.bind(this);
|
79
|
-
this.not = this.not.bind(this);
|
80
|
-
this.filter = this.filter.bind(this);
|
81
|
-
this.sort = this.sort.bind(this);
|
82
|
-
this.none = this.none.bind(this);
|
83
|
-
Object.defineProperty(this, 'table', { enumerable: false });
|
84
|
-
Object.defineProperty(this, 'repository', { enumerable: false });
|
85
|
-
}
|
86
|
-
any(...queries) {
|
87
|
-
return new Query(this.repository, this.table, {
|
88
|
-
$any: (this.$any || []).concat(queries)
|
89
|
-
}, this);
|
90
|
-
}
|
91
|
-
all(...queries) {
|
92
|
-
return new Query(this.repository, this.table, {
|
93
|
-
$all: (this.$all || []).concat(queries)
|
94
|
-
}, this);
|
95
|
-
}
|
96
|
-
not(...queries) {
|
97
|
-
return new Query(this.repository, this.table, {
|
98
|
-
$not: (this.$not || []).concat(queries)
|
99
|
-
}, this);
|
100
|
-
}
|
101
|
-
none(...queries) {
|
102
|
-
return new Query(this.repository, this.table, {
|
103
|
-
$none: (this.$none || []).concat(queries)
|
104
|
-
}, this);
|
105
|
-
}
|
106
|
-
filter(a, b) {
|
107
|
-
if (arguments.length === 1) {
|
108
|
-
const constraints = a;
|
109
|
-
const queries = [];
|
110
|
-
for (const [column, constraint] of Object.entries(constraints)) {
|
111
|
-
queries.push({ [column]: constraint });
|
112
|
-
}
|
113
|
-
return new Query(this.repository, this.table, {
|
114
|
-
$all: (this.$all || []).concat(queries)
|
115
|
-
}, this);
|
116
|
-
}
|
117
|
-
else {
|
118
|
-
const column = a;
|
119
|
-
const value = b;
|
120
|
-
return new Query(this.repository, this.table, {
|
121
|
-
$all: (this.$all || []).concat({ [column]: value })
|
122
|
-
}, this);
|
123
|
-
}
|
124
|
-
}
|
125
|
-
sort(column, direction) {
|
126
|
-
const sort = Object.assign(Object.assign({}, this.$sort), { [column]: direction });
|
127
|
-
const q = new Query(this.repository, this.table, {
|
128
|
-
$sort: sort
|
129
|
-
}, this);
|
130
|
-
return q;
|
131
|
-
}
|
132
|
-
// TODO: pagination. Maybe implement different methods for different type of paginations
|
133
|
-
// and one to simply get the first records returned by the query with no pagination.
|
134
|
-
getMany(options) {
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
136
|
-
// TODO: use options
|
137
|
-
return this.repository.query(this);
|
138
|
-
});
|
139
|
-
}
|
140
|
-
getOne(options) {
|
141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
142
|
-
// TODO: use options
|
143
|
-
const arr = yield this.getMany(); // TODO, limit to 1
|
144
|
-
return arr[0] || null;
|
145
|
-
});
|
146
|
-
}
|
147
|
-
deleteAll() {
|
148
|
-
return __awaiter(this, void 0, void 0, function* () {
|
149
|
-
// Return number of affected rows
|
150
|
-
return 0;
|
151
|
-
});
|
152
|
-
}
|
153
|
-
include(columns) {
|
154
|
-
// TODO
|
155
|
-
return this;
|
156
|
-
}
|
157
|
-
}
|
158
|
-
exports.Query = Query;
|
159
|
-
class Repository extends Query {
|
160
|
-
select(...columns) {
|
161
|
-
return new Query(this.repository, this.table, {});
|
162
|
-
}
|
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 {
|
163
46
|
}
|
164
47
|
exports.Repository = Repository;
|
165
48
|
class RestRepository extends Repository {
|
166
49
|
constructor(client, table) {
|
167
50
|
super(null, table, {});
|
168
|
-
this
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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.`);
|
176
60
|
}
|
177
|
-
|
178
|
-
this.fetch = this.client.options.fetch;
|
179
|
-
}
|
180
|
-
Object.defineProperty(this, 'client', { enumerable: false });
|
181
|
-
Object.defineProperty(this, 'fetch', { enumerable: false });
|
182
|
-
Object.defineProperty(this, 'hostname', { enumerable: false });
|
61
|
+
__classPrivateFieldSet(this, _RestRepository_fetch, fetchImpl, "f");
|
183
62
|
}
|
184
63
|
request(method, path, body) {
|
185
64
|
return __awaiter(this, void 0, void 0, function* () {
|
186
|
-
const { databaseURL, apiKey } = this.
|
187
|
-
const branch = yield this.
|
188
|
-
const
|
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}`, {
|
189
69
|
method,
|
190
70
|
headers: {
|
191
71
|
Accept: '*/*',
|
@@ -211,31 +91,46 @@ class RestRepository extends Repository {
|
|
211
91
|
throw new XataError(resp.statusText, resp.status);
|
212
92
|
}
|
213
93
|
if (resp.status === 204)
|
214
|
-
return;
|
94
|
+
return undefined;
|
215
95
|
return resp.json();
|
216
96
|
});
|
217
97
|
}
|
218
|
-
select(...columns) {
|
219
|
-
return new Query(this.repository, this.table, {});
|
220
|
-
}
|
221
98
|
create(object) {
|
222
99
|
return __awaiter(this, void 0, void 0, function* () {
|
223
|
-
const
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
body[key] = value.id;
|
228
|
-
}
|
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");
|
229
104
|
}
|
230
|
-
const
|
231
|
-
|
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;
|
232
125
|
});
|
233
126
|
}
|
234
127
|
read(id) {
|
235
128
|
return __awaiter(this, void 0, void 0, function* () {
|
236
129
|
try {
|
237
|
-
const
|
238
|
-
|
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);
|
239
134
|
}
|
240
135
|
catch (err) {
|
241
136
|
if (err.status === 404)
|
@@ -246,33 +141,42 @@ class RestRepository extends Repository {
|
|
246
141
|
}
|
247
142
|
update(id, object) {
|
248
143
|
return __awaiter(this, void 0, void 0, function* () {
|
249
|
-
const
|
250
|
-
|
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);
|
251
150
|
});
|
252
151
|
}
|
253
152
|
delete(id) {
|
254
153
|
return __awaiter(this, void 0, void 0, function* () {
|
255
|
-
yield this.request('DELETE', `/tables/${this
|
154
|
+
yield this.request('DELETE', `/tables/${__classPrivateFieldGet(this, _RestRepository_table, "f")}/data/${id}`);
|
256
155
|
});
|
257
156
|
}
|
258
|
-
query(query) {
|
157
|
+
query(query, options) {
|
158
|
+
var _a, _b, _c;
|
259
159
|
return __awaiter(this, void 0, void 0, function* () {
|
260
|
-
const
|
261
|
-
$any: query.$any,
|
262
|
-
$all: query.$all,
|
263
|
-
$not: query.$not,
|
264
|
-
$none: query.$none
|
265
|
-
};
|
160
|
+
const data = query.getQueryOptions();
|
266
161
|
const body = {
|
267
|
-
filter: Object.values(filter).some(Boolean) ? filter : undefined,
|
268
|
-
sort:
|
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
|
269
166
|
};
|
270
|
-
const
|
271
|
-
|
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);
|
272
175
|
});
|
273
176
|
}
|
274
177
|
}
|
275
178
|
exports.RestRepository = RestRepository;
|
179
|
+
_RestRepository_client = new WeakMap(), _RestRepository_fetch = new WeakMap(), _RestRepository_table = new WeakMap();
|
276
180
|
class RestRespositoryFactory {
|
277
181
|
createRepository(client, table) {
|
278
182
|
return new RestRepository(client, table);
|
@@ -368,3 +272,14 @@ exports.XataError = XataError;
|
|
368
272
|
const isBranchStrategyBuilder = (strategy) => {
|
369
273
|
return typeof strategy === 'function';
|
370
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
|
+
__exportStar(require("./api"), exports);
|
285
|
+
__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 @@
|
|
1
|
+
export * from './operators';
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11
|
+
};
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
+
__exportStar(require("./operators"), exports);
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Constraint } from './filters';
|
2
|
+
declare type ComparableType = number | Date;
|
3
|
+
export declare const gt: <T extends ComparableType>(value: T) => Constraint<T>;
|
4
|
+
export declare const ge: <T extends ComparableType>(value: T) => Constraint<T>;
|
5
|
+
export declare const gte: <T extends ComparableType>(value: T) => Constraint<T>;
|
6
|
+
export declare const lt: <T extends ComparableType>(value: T) => Constraint<T>;
|
7
|
+
export declare const lte: <T extends ComparableType>(value: T) => Constraint<T>;
|
8
|
+
export declare const le: <T extends ComparableType>(value: T) => Constraint<T>;
|
9
|
+
export declare const exists: (column: string) => Constraint<string>;
|
10
|
+
export declare const notExists: (column: string) => Constraint<string>;
|
11
|
+
export declare const startsWith: (value: string) => Constraint<string>;
|
12
|
+
export declare const endsWith: (value: string) => Constraint<string>;
|
13
|
+
export declare const pattern: (value: string) => Constraint<string>;
|
14
|
+
export declare const is: <T>(value: T) => Constraint<T>;
|
15
|
+
export declare const isNot: <T>(value: T) => Constraint<T>;
|
16
|
+
export declare const contains: <T>(value: T) => Constraint<T>;
|
17
|
+
export declare const includes: (value: string) => Constraint<string>;
|
18
|
+
export declare const includesSubstring: (value: string) => Constraint<string>;
|
19
|
+
export declare const includesPattern: (value: string) => Constraint<string>;
|
20
|
+
export declare const includesAll: (value: string) => Constraint<string>;
|
21
|
+
export {};
|
@@ -0,0 +1,40 @@
|
|
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
|
+
const gt = (value) => ({ $gt: value });
|
5
|
+
exports.gt = gt;
|
6
|
+
const ge = (value) => ({ $ge: value });
|
7
|
+
exports.ge = ge;
|
8
|
+
const gte = (value) => ({ $ge: value });
|
9
|
+
exports.gte = gte;
|
10
|
+
const lt = (value) => ({ $lt: value });
|
11
|
+
exports.lt = lt;
|
12
|
+
const lte = (value) => ({ $le: value });
|
13
|
+
exports.lte = lte;
|
14
|
+
const le = (value) => ({ $le: value });
|
15
|
+
exports.le = le;
|
16
|
+
const exists = (column) => ({ $exists: column });
|
17
|
+
exports.exists = exists;
|
18
|
+
const notExists = (column) => ({ $notExists: column });
|
19
|
+
exports.notExists = notExists;
|
20
|
+
const startsWith = (value) => ({ $startsWith: value });
|
21
|
+
exports.startsWith = startsWith;
|
22
|
+
const endsWith = (value) => ({ $endsWith: value });
|
23
|
+
exports.endsWith = endsWith;
|
24
|
+
const pattern = (value) => ({ $pattern: value });
|
25
|
+
exports.pattern = pattern;
|
26
|
+
const is = (value) => ({ $is: value });
|
27
|
+
exports.is = is;
|
28
|
+
const isNot = (value) => ({ $isNot: value });
|
29
|
+
exports.isNot = isNot;
|
30
|
+
const contains = (value) => ({ $contains: value });
|
31
|
+
exports.contains = contains;
|
32
|
+
// TODO: these can only be applied to columns of type "multiple"
|
33
|
+
const includes = (value) => ({ $includes: value });
|
34
|
+
exports.includes = includes;
|
35
|
+
const includesSubstring = (value) => ({ $includesSubstring: value });
|
36
|
+
exports.includesSubstring = includesSubstring;
|
37
|
+
const includesPattern = (value) => ({ $includesPattern: value });
|
38
|
+
exports.includesPattern = includesPattern;
|
39
|
+
const includesAll = (value) => ({ $includesAll: value });
|
40
|
+
exports.includesAll = includesAll;
|
@@ -0,0 +1,41 @@
|
|
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
|
+
export declare class Page<T extends XataRecord, R extends XataRecord> implements Paginable<T, R> {
|
19
|
+
#private;
|
20
|
+
readonly meta: PaginationQueryMeta;
|
21
|
+
readonly records: R[];
|
22
|
+
constructor(query: Query<T, R>, meta: PaginationQueryMeta, records?: R[]);
|
23
|
+
nextPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
24
|
+
previousPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
25
|
+
firstPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
26
|
+
lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
|
27
|
+
hasNextPage(): boolean;
|
28
|
+
}
|
29
|
+
export declare type CursorNavigationOptions = {
|
30
|
+
first?: string;
|
31
|
+
} | {
|
32
|
+
last?: string;
|
33
|
+
} | {
|
34
|
+
after?: string;
|
35
|
+
before?: string;
|
36
|
+
};
|
37
|
+
export declare type OffsetNavigationOptions = {
|
38
|
+
size?: number;
|
39
|
+
offset?: number;
|
40
|
+
};
|
41
|
+
export declare type PaginationOptions = CursorNavigationOptions & OffsetNavigationOptions;
|
@@ -0,0 +1,58 @@
|
|
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.Page = void 0;
|
25
|
+
class Page {
|
26
|
+
constructor(query, meta, records = []) {
|
27
|
+
_Page_query.set(this, void 0);
|
28
|
+
__classPrivateFieldSet(this, _Page_query, query, "f");
|
29
|
+
this.meta = meta;
|
30
|
+
this.records = records;
|
31
|
+
}
|
32
|
+
nextPage(size, offset) {
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
34
|
+
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
|
35
|
+
});
|
36
|
+
}
|
37
|
+
previousPage(size, offset) {
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
39
|
+
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
|
40
|
+
});
|
41
|
+
}
|
42
|
+
firstPage(size, offset) {
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
|
45
|
+
});
|
46
|
+
}
|
47
|
+
lastPage(size, offset) {
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
49
|
+
return __classPrivateFieldGet(this, _Page_query, "f").getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
|
50
|
+
});
|
51
|
+
}
|
52
|
+
// TODO: We need to add something on the backend if we want a hasPreviousPage
|
53
|
+
hasNextPage() {
|
54
|
+
return this.meta.page.more;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
exports.Page = Page;
|
58
|
+
_Page_query = new WeakMap();
|