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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/CHANGELOG.md +87 -0
  3. package/dist/api/client.d.ts +95 -0
  4. package/dist/api/client.js +251 -0
  5. package/dist/api/components.d.ts +1437 -0
  6. package/dist/api/components.js +998 -0
  7. package/dist/api/fetcher.d.ts +40 -0
  8. package/dist/api/fetcher.js +79 -0
  9. package/dist/api/index.d.ts +7 -0
  10. package/dist/api/index.js +21 -0
  11. package/dist/api/parameters.d.ts +16 -0
  12. package/dist/api/parameters.js +2 -0
  13. package/dist/api/providers.d.ts +8 -0
  14. package/dist/api/providers.js +30 -0
  15. package/dist/api/responses.d.ts +50 -0
  16. package/dist/api/responses.js +2 -0
  17. package/dist/api/schemas.d.ts +311 -0
  18. package/dist/api/schemas.js +2 -0
  19. package/dist/client.d.ts +39 -0
  20. package/dist/client.js +124 -0
  21. package/dist/index.d.ts +5 -182
  22. package/dist/index.js +19 -499
  23. package/dist/namespace.d.ts +7 -0
  24. package/dist/namespace.js +6 -0
  25. package/dist/schema/filters.d.ts +96 -0
  26. package/dist/schema/filters.js +2 -0
  27. package/dist/schema/filters.spec.d.ts +1 -0
  28. package/dist/schema/filters.spec.js +177 -0
  29. package/dist/schema/index.d.ts +21 -0
  30. package/dist/schema/index.js +49 -0
  31. package/dist/schema/operators.d.ts +74 -0
  32. package/dist/schema/operators.js +93 -0
  33. package/dist/schema/pagination.d.ts +83 -0
  34. package/dist/schema/pagination.js +93 -0
  35. package/dist/schema/query.d.ts +118 -0
  36. package/dist/schema/query.js +242 -0
  37. package/dist/schema/record.d.ts +66 -0
  38. package/dist/schema/record.js +13 -0
  39. package/dist/schema/repository.d.ts +134 -0
  40. package/dist/schema/repository.js +284 -0
  41. package/dist/schema/selection.d.ts +25 -0
  42. package/dist/schema/selection.js +2 -0
  43. package/dist/schema/selection.spec.d.ts +1 -0
  44. package/dist/schema/selection.spec.js +204 -0
  45. package/dist/schema/sorting.d.ts +17 -0
  46. package/dist/schema/sorting.js +28 -0
  47. package/dist/schema/sorting.spec.d.ts +1 -0
  48. package/dist/schema/sorting.spec.js +11 -0
  49. package/dist/search/index.d.ts +20 -0
  50. package/dist/search/index.js +30 -0
  51. package/dist/util/branches.d.ts +5 -0
  52. package/dist/util/branches.js +7 -0
  53. package/dist/util/config.d.ts +11 -0
  54. package/dist/util/config.js +121 -0
  55. package/dist/util/environment.d.ts +5 -0
  56. package/dist/util/environment.js +68 -0
  57. package/dist/util/fetch.d.ts +2 -0
  58. package/dist/util/fetch.js +13 -0
  59. package/dist/util/lang.d.ts +5 -0
  60. package/dist/util/lang.js +22 -0
  61. package/dist/util/types.d.ts +25 -0
  62. package/dist/util/types.js +2 -0
  63. package/package.json +5 -2
  64. package/tsconfig.json +21 -0
  65. package/dist/util/errors.d.ts +0 -3
  66. package/dist/util/errors.js +0 -9
package/dist/index.js CHANGED
@@ -1,493 +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
- });
10
- };
11
- var __asyncValues = (this && this.__asyncValues) || function (o) {
12
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
13
- var m = o[Symbol.asyncIterator], i;
14
- 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);
15
- 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
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
- };
18
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
19
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
20
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
21
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
22
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
23
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
24
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
25
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
26
- function fulfill(value) { resume("next", value); }
27
- function reject(value) { resume("throw", value); }
28
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
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);
29
15
  };
30
16
  Object.defineProperty(exports, "__esModule", { value: true });
31
- 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;
32
- const errors_1 = require("./util/errors");
33
- const gt = (value) => ({ $gt: value });
34
- exports.gt = gt;
35
- const ge = (value) => ({ $ge: value });
36
- exports.ge = ge;
37
- const gte = (value) => ({ $ge: value });
38
- exports.gte = gte;
39
- const lt = (value) => ({ $lt: value });
40
- exports.lt = lt;
41
- const lte = (value) => ({ $le: value });
42
- exports.lte = lte;
43
- const le = (value) => ({ $le: value });
44
- exports.le = le;
45
- const exists = (column) => ({ $exists: column });
46
- exports.exists = exists;
47
- const notExists = (column) => ({ $notExists: column });
48
- exports.notExists = notExists;
49
- const startsWith = (value) => ({ $startsWith: value });
50
- exports.startsWith = startsWith;
51
- const endsWith = (value) => ({ $endsWith: value });
52
- exports.endsWith = endsWith;
53
- const pattern = (value) => ({ $pattern: value });
54
- exports.pattern = pattern;
55
- const is = (value) => ({ $is: value });
56
- exports.is = is;
57
- const isNot = (value) => ({ $isNot: value });
58
- exports.isNot = isNot;
59
- const contains = (value) => ({ $contains: value });
60
- exports.contains = contains;
61
- // TODO: these can only be applied to columns of type "multiple"
62
- const includes = (value) => ({ $includes: value });
63
- exports.includes = includes;
64
- const includesSubstring = (value) => ({ $includesSubstring: value });
65
- exports.includesSubstring = includesSubstring;
66
- const includesPattern = (value) => ({ $includesPattern: value });
67
- exports.includesPattern = includesPattern;
68
- const includesAll = (value) => ({ $includesAll: value });
69
- exports.includesAll = includesAll;
70
- class Page {
71
- constructor(query, meta, records = []) {
72
- this.query = query;
73
- this.meta = meta;
74
- this.records = records;
75
- }
76
- nextPage(size, offset) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- return this.query.getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
79
- });
80
- }
81
- previousPage(size, offset) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- return this.query.getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
84
- });
85
- }
86
- firstPage(size, offset) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- return this.query.getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
89
- });
90
- }
91
- lastPage(size, offset) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- return this.query.getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
94
- });
95
- }
96
- // TODO: We need to add something on the backend if we want a hasPreviousPage
97
- hasNextPage() {
98
- return this.meta.page.more;
99
- }
100
- }
101
- class Query {
102
- constructor(repository, table, data, parent) {
103
- // Cursor pagination
104
- this.query = this;
105
- this.meta = { page: { cursor: 'start', more: true } };
106
- this.records = [];
107
- if (repository) {
108
- this.repository = repository;
109
- }
110
- else {
111
- this.repository = this;
112
- }
113
- this.table = table;
114
- // For some reason Object.assign(this, parent) didn't work in this case
115
- // so doing all this manually:
116
- this.$any = parent === null || parent === void 0 ? void 0 : parent.$any;
117
- this.$all = parent === null || parent === void 0 ? void 0 : parent.$all;
118
- this.$not = parent === null || parent === void 0 ? void 0 : parent.$not;
119
- this.$none = parent === null || parent === void 0 ? void 0 : parent.$none;
120
- this.$sort = parent === null || parent === void 0 ? void 0 : parent.$sort;
121
- Object.assign(this, data);
122
- // These bindings are used to support deconstructing
123
- // const { any, not, filter, sort } = xata.users.query()
124
- this.any = this.any.bind(this);
125
- this.all = this.all.bind(this);
126
- this.not = this.not.bind(this);
127
- this.filter = this.filter.bind(this);
128
- this.sort = this.sort.bind(this);
129
- this.none = this.none.bind(this);
130
- Object.defineProperty(this, 'table', { enumerable: false });
131
- Object.defineProperty(this, 'repository', { enumerable: false });
132
- }
133
- any(...queries) {
134
- return new Query(this.repository, this.table, {
135
- $any: (this.$any || []).concat(queries)
136
- }, this);
137
- }
138
- all(...queries) {
139
- return new Query(this.repository, this.table, {
140
- $all: (this.$all || []).concat(queries)
141
- }, this);
142
- }
143
- not(...queries) {
144
- return new Query(this.repository, this.table, {
145
- $not: (this.$not || []).concat(queries)
146
- }, this);
147
- }
148
- none(...queries) {
149
- return new Query(this.repository, this.table, {
150
- $none: (this.$none || []).concat(queries)
151
- }, this);
152
- }
153
- filter(a, b) {
154
- if (arguments.length === 1) {
155
- const constraints = a;
156
- const queries = [];
157
- for (const [column, constraint] of Object.entries(constraints)) {
158
- queries.push({ [column]: constraint });
159
- }
160
- return new Query(this.repository, this.table, {
161
- $all: (this.$all || []).concat(queries)
162
- }, this);
163
- }
164
- else {
165
- const column = a;
166
- const value = b;
167
- return new Query(this.repository, this.table, {
168
- $all: (this.$all || []).concat({ [column]: value })
169
- }, this);
170
- }
171
- }
172
- sort(column, direction) {
173
- const sort = Object.assign(Object.assign({}, this.$sort), { [column]: direction });
174
- const q = new Query(this.repository, this.table, {
175
- $sort: sort
176
- }, this);
177
- return q;
178
- }
179
- getPaginated(options) {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- return this.repository._runQuery(this, options);
182
- });
183
- }
184
- [Symbol.asyncIterator]() {
185
- return __asyncGenerator(this, arguments, function* _a() {
186
- var e_1, _b;
187
- try {
188
- for (var _c = __asyncValues(this.getIterator(1)), _d; _d = yield __await(_c.next()), !_d.done;) {
189
- const [record] = _d.value;
190
- yield yield __await(record);
191
- }
192
- }
193
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
194
- finally {
195
- try {
196
- if (_d && !_d.done && (_b = _c.return)) yield __await(_b.call(_c));
197
- }
198
- finally { if (e_1) throw e_1.error; }
199
- }
200
- });
201
- }
202
- getIterator(chunk, options = {}) {
203
- return __asyncGenerator(this, arguments, function* getIterator_1() {
204
- let offset = 0;
205
- let end = false;
206
- while (!end) {
207
- const { records, meta } = yield __await(this.getPaginated(Object.assign(Object.assign({}, options), { page: { size: chunk, offset } })));
208
- yield yield __await(records);
209
- offset += chunk;
210
- end = !meta.page.more;
211
- }
212
- });
213
- }
214
- getMany(options) {
215
- return __awaiter(this, void 0, void 0, function* () {
216
- const { records } = yield this.getPaginated(options);
217
- return records;
218
- });
219
- }
220
- getOne(options = {}) {
221
- return __awaiter(this, void 0, void 0, function* () {
222
- const records = yield this.getMany(Object.assign(Object.assign({}, options), { page: { size: 1 } }));
223
- return records[0] || null;
224
- });
225
- }
226
- deleteAll() {
227
- return __awaiter(this, void 0, void 0, function* () {
228
- // TODO: Return number of affected rows
229
- return 0;
230
- });
231
- }
232
- include(columns) {
233
- // TODO
234
- return this;
235
- }
236
- nextPage(size, offset) {
237
- return __awaiter(this, void 0, void 0, function* () {
238
- return this.firstPage(size, offset);
239
- });
240
- }
241
- previousPage(size, offset) {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- return this.firstPage(size, offset);
244
- });
245
- }
246
- firstPage(size, offset) {
247
- return __awaiter(this, void 0, void 0, function* () {
248
- return this.getPaginated({ page: { size, offset } });
249
- });
250
- }
251
- lastPage(size, offset) {
252
- return __awaiter(this, void 0, void 0, function* () {
253
- return this.getPaginated({ page: { size, offset, before: 'end' } });
254
- });
255
- }
256
- hasNextPage() {
257
- return this.meta.page.more;
258
- }
259
- }
260
- exports.Query = Query;
261
- class Repository extends Query {
262
- select(...columns) {
263
- return new Query(this.repository, this.table, {});
264
- }
265
- }
266
- exports.Repository = Repository;
267
- class RestRepository extends Repository {
268
- constructor(client, table) {
269
- super(null, table, {});
270
- this.client = client;
271
- const doWeHaveFetch = typeof fetch !== 'undefined';
272
- const isInjectedFetchProblematic = !this.client.options.fetch;
273
- if (doWeHaveFetch) {
274
- this.fetch = fetch;
275
- }
276
- else if (isInjectedFetchProblematic) {
277
- throw new Error(errors_1.errors.falsyFetchImplementation);
278
- }
279
- else {
280
- this.fetch = this.client.options.fetch;
281
- }
282
- Object.defineProperty(this, 'client', { enumerable: false });
283
- Object.defineProperty(this, 'fetch', { enumerable: false });
284
- Object.defineProperty(this, 'hostname', { enumerable: false });
285
- }
286
- request(method, path, body) {
287
- return __awaiter(this, void 0, void 0, function* () {
288
- const { databaseURL, apiKey } = this.client.options;
289
- const branch = yield this.client.getBranch();
290
- const resp = yield this.fetch(`${databaseURL}:${branch}${path}`, {
291
- method,
292
- headers: {
293
- Accept: '*/*',
294
- 'Content-Type': 'application/json',
295
- Authorization: `Bearer ${apiKey}`
296
- },
297
- body: JSON.stringify(body)
298
- });
299
- if (!resp.ok) {
300
- try {
301
- const json = yield resp.json();
302
- const message = json.message;
303
- if (typeof message === 'string') {
304
- throw new XataError(message, resp.status);
305
- }
306
- }
307
- catch (err) {
308
- if (err instanceof XataError)
309
- throw err;
310
- // Ignore errors for other reasons.
311
- // For example if the response's body cannot be parsed as JSON
312
- }
313
- throw new XataError(resp.statusText, resp.status);
314
- }
315
- if (resp.status === 204)
316
- return undefined;
317
- return resp.json();
318
- });
319
- }
320
- select(...columns) {
321
- return new Query(this.repository, this.table, {});
322
- }
323
- create(object) {
324
- return __awaiter(this, void 0, void 0, function* () {
325
- const record = transformObjectLinks(object);
326
- const response = yield this.request('POST', `/tables/${this.table}/data`, record);
327
- if (!response) {
328
- throw new Error("The server didn't return any data for the query");
329
- }
330
- const finalObject = yield this.read(response.id);
331
- if (!finalObject) {
332
- throw new Error('The server failed to save the record');
333
- }
334
- return finalObject;
335
- });
336
- }
337
- createMany(objects) {
338
- return __awaiter(this, void 0, void 0, function* () {
339
- const records = objects.map((object) => transformObjectLinks(object));
340
- const response = yield this.request('POST', `/tables/${this.table}/bulk`, { records });
341
- if (!response) {
342
- throw new Error("The server didn't return any data for the query");
343
- }
344
- // TODO: Use filer.$any() to get all the records
345
- const finalObjects = yield Promise.all(response.recordIDs.map((id) => this.read(id)));
346
- if (finalObjects.some((object) => !object)) {
347
- throw new Error('The server failed to save the record');
348
- }
349
- return finalObjects;
350
- });
351
- }
352
- read(id) {
353
- return __awaiter(this, void 0, void 0, function* () {
354
- try {
355
- const response = yield this.request('GET', `/tables/${this.table}/data/${id}`);
356
- if (!response)
357
- return null;
358
- return this.client.initObject(this.table, response);
359
- }
360
- catch (err) {
361
- if (err.status === 404)
362
- return null;
363
- throw err;
364
- }
365
- });
366
- }
367
- update(id, object) {
368
- return __awaiter(this, void 0, void 0, function* () {
369
- const response = yield this.request('PUT', `/tables/${this.table}/data/${id}`, object);
370
- if (!response) {
371
- throw new Error("The server didn't return any data for the query");
372
- }
373
- // TODO: Review this, not sure we are properly initializing the object
374
- return this.client.initObject(this.table, response);
375
- });
376
- }
377
- delete(id) {
378
- return __awaiter(this, void 0, void 0, function* () {
379
- yield this.request('DELETE', `/tables/${this.table}/data/${id}`);
380
- });
381
- }
382
- _runQuery(query, options) {
383
- return __awaiter(this, void 0, void 0, function* () {
384
- const filter = {
385
- $any: query.$any,
386
- $all: query.$all,
387
- $not: query.$not,
388
- $none: query.$none
389
- };
390
- const body = {
391
- filter: Object.values(filter).some(Boolean) ? filter : undefined,
392
- sort: query.$sort,
393
- page: options === null || options === void 0 ? void 0 : options.page
394
- };
395
- const response = yield this.request('POST', `/tables/${this.table}/query`, body);
396
- if (!response) {
397
- throw new Error("The server didn't return any data for the query");
398
- }
399
- const { meta, records: objects } = response;
400
- const records = objects.map((record) => this.client.initObject(this.table, record));
401
- return new Page(query, meta, records);
402
- });
403
- }
404
- }
405
- exports.RestRepository = RestRepository;
406
- class RestRespositoryFactory {
407
- createRepository(client, table) {
408
- return new RestRepository(client, table);
409
- }
410
- }
411
- exports.RestRespositoryFactory = RestRespositoryFactory;
412
- class BaseClient {
413
- constructor(options, links) {
414
- if (!options.databaseURL || !options.apiKey || !options.branch) {
415
- throw new Error('Options databaseURL, apiKey and branch are required');
416
- }
417
- this.options = options;
418
- this.links = links;
419
- }
420
- initObject(table, object) {
421
- const o = {};
422
- Object.assign(o, object);
423
- const tableLinks = this.links[table] || [];
424
- for (const link of tableLinks) {
425
- const [field, linkTable] = link;
426
- const value = o[field];
427
- if (value && typeof value === 'object') {
428
- const { id } = value;
429
- if (Object.keys(value).find((col) => col === 'id')) {
430
- o[field] = this.initObject(linkTable, value);
431
- }
432
- else if (id) {
433
- o[field] = {
434
- id,
435
- get: () => {
436
- this.db[linkTable].read(id);
437
- }
438
- };
439
- }
440
- }
441
- }
442
- const db = this.db;
443
- o.read = function () {
444
- return db[table].read(o['id']);
445
- };
446
- o.update = function (data) {
447
- return db[table].update(o['id'], data);
448
- };
449
- o.delete = function () {
450
- return db[table].delete(o['id']);
451
- };
452
- for (const prop of ['read', 'update', 'delete']) {
453
- Object.defineProperty(o, prop, { enumerable: false });
454
- }
455
- // TODO: links and rev links
456
- Object.freeze(o);
457
- return o;
458
- }
459
- getBranch() {
460
- var e_2, _a;
461
- return __awaiter(this, void 0, void 0, function* () {
462
- if (this.branch)
463
- return this.branch;
464
- const { branch: param } = this.options;
465
- const strategies = Array.isArray(param) ? [...param] : [param];
466
- const evaluateBranch = (strategy) => __awaiter(this, void 0, void 0, function* () {
467
- return isBranchStrategyBuilder(strategy) ? yield strategy() : strategy;
468
- });
469
- try {
470
- for (var strategies_1 = __asyncValues(strategies), strategies_1_1; strategies_1_1 = yield strategies_1.next(), !strategies_1_1.done;) {
471
- const strategy = strategies_1_1.value;
472
- const branch = yield evaluateBranch(strategy);
473
- if (branch) {
474
- this.branch = branch;
475
- return branch;
476
- }
477
- }
478
- }
479
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
480
- finally {
481
- try {
482
- if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) yield _a.call(strategies_1);
483
- }
484
- finally { if (e_2) throw e_2.error; }
485
- }
486
- throw new Error('Unable to resolve branch value');
487
- });
488
- }
489
- }
490
- exports.BaseClient = BaseClient;
17
+ exports.XataError = void 0;
491
18
  class XataError extends Error {
492
19
  constructor(message, status) {
493
20
  super(message);
@@ -495,15 +22,8 @@ class XataError extends Error {
495
22
  }
496
23
  }
497
24
  exports.XataError = XataError;
498
- const isBranchStrategyBuilder = (strategy) => {
499
- return typeof strategy === 'function';
500
- };
501
- // TODO: We can find a better implementation for links
502
- const transformObjectLinks = (object) => {
503
- return Object.entries(object).reduce((acc, [key, value]) => {
504
- if (value && typeof value === 'object' && typeof value.id === 'string') {
505
- return Object.assign(Object.assign({}, acc), { [key]: value.id });
506
- }
507
- return Object.assign(Object.assign({}, acc), { [key]: value });
508
- }, {});
509
- };
25
+ __exportStar(require("./api"), exports);
26
+ __exportStar(require("./client"), exports);
27
+ __exportStar(require("./schema"), exports);
28
+ __exportStar(require("./search"), exports);
29
+ __exportStar(require("./util/config"), exports);
@@ -0,0 +1,7 @@
1
+ import { FetcherExtraProps } from './api/fetcher';
2
+ export declare abstract class Namespace {
3
+ abstract build(options: NamespaceBuildOptions): unknown;
4
+ }
5
+ export declare type NamespaceBuildOptions = {
6
+ getFetchProps: () => Promise<FetcherExtraProps>;
7
+ };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Namespace = void 0;
4
+ class Namespace {
5
+ }
6
+ exports.Namespace = Namespace;
@@ -0,0 +1,96 @@
1
+ import { SingleOrArray } from '../util/types';
2
+ import { SelectableColumn, ValueAtColumn } from './selection';
3
+ /**
4
+ * PropertyMatchFilter
5
+ * Example:
6
+ {
7
+ "filter": {
8
+ "name": "value",
9
+ "name": {
10
+ "$is": "value",
11
+ "$any": [ "value1", "value2" ],
12
+ },
13
+ "settings.plan": {"$any": ["free", "paid"]},
14
+ "settings.plan": "free",
15
+ "settings": {
16
+ "plan": "free"
17
+ },
18
+ }
19
+ }
20
+ */
21
+ declare type PropertyAccessFilter<Record> = {
22
+ [key in SelectableColumn<Record>]?: NestedApiFilter<ValueAtColumn<Record, key>> | PropertyFilter<ValueAtColumn<Record, key>>;
23
+ };
24
+ export declare type PropertyFilter<T> = T | {
25
+ $is: T;
26
+ } | {
27
+ $isNot: T;
28
+ } | {
29
+ $any: T[];
30
+ } | {
31
+ $none: T[];
32
+ } | ValueTypeFilters<T>;
33
+ declare type IncludesFilter<T> = PropertyFilter<T> | {
34
+ [key in '$all' | '$none' | '$any']?: IncludesFilter<T> | Array<IncludesFilter<T> | {
35
+ $not: IncludesFilter<T>;
36
+ }>;
37
+ };
38
+ export declare type StringTypeFilter = {
39
+ [key in '$contains' | '$pattern' | '$startsWith' | '$endsWith']?: string;
40
+ };
41
+ export declare type ComparableType = number | Date;
42
+ export declare type ComparableTypeFilter<T extends ComparableType> = {
43
+ [key in '$gt' | '$lt' | '$ge' | '$le']?: T;
44
+ };
45
+ export declare type ArrayFilter<T> = {
46
+ [key in '$includes']?: SingleOrArray<PropertyFilter<T> | ValueTypeFilters<T>> | IncludesFilter<T>;
47
+ } | {
48
+ [key in '$includesAll' | '$includesNone' | '$includesAny']?: T | Array<PropertyFilter<T> | {
49
+ $not: PropertyFilter<T>;
50
+ }>;
51
+ };
52
+ declare type ValueTypeFilters<T> = T | T extends string ? StringTypeFilter : T extends number ? ComparableTypeFilter<number> : T extends Date ? ComparableTypeFilter<Date> : T extends Array<infer T> ? ArrayFilter<T> : never;
53
+ /**
54
+ * AggregatorFilter
55
+ * Example:
56
+ {
57
+ "filter": {
58
+ "$any": {
59
+ "settings.dark": true,
60
+ "settings.plan": "free"
61
+ }
62
+ },
63
+ }
64
+ {
65
+ "filter": {
66
+ "$any": [
67
+ {
68
+ "name": "r1",
69
+ },
70
+ {
71
+ "name": "r2",
72
+ },
73
+ ],
74
+ }
75
+ */
76
+ declare type AggregatorFilter<Record> = {
77
+ [key in '$all' | '$any' | '$not' | '$none']?: SingleOrArray<Filter<Record>>;
78
+ };
79
+ /**
80
+ * Existance filter
81
+ * Example: { filter: { $exists: "settings" } }
82
+ */
83
+ export declare type ExistanceFilter<Record> = {
84
+ [key in '$exists' | '$notExists']?: SelectableColumn<Record>;
85
+ };
86
+ declare type BaseApiFilter<Record> = PropertyAccessFilter<Record> | AggregatorFilter<Record> | ExistanceFilter<Record>;
87
+ /**
88
+ * Nested filter
89
+ * Injects the Api filters on nested properties
90
+ * Example: { filter: { settings: { plan: { $any: ['free', 'trial'] } } } }
91
+ */
92
+ declare type NestedApiFilter<T> = T extends Record<string, any> ? {
93
+ [key in keyof T]?: T[key] extends Record<string, any> ? SingleOrArray<Filter<T[key]>> : PropertyFilter<T[key]>;
94
+ } : PropertyFilter<T>;
95
+ export declare type Filter<Record> = BaseApiFilter<Record> | NestedApiFilter<Record>;
96
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};