@xata.io/client 0.5.1 → 0.7.1

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 (43) hide show
  1. package/.eslintrc.cjs +13 -0
  2. package/CHANGELOG.md +35 -0
  3. package/dist/api/client.d.ts +1 -1
  4. package/dist/api/client.js +11 -9
  5. package/dist/api/components.d.ts +7 -6
  6. package/dist/api/components.js +7 -6
  7. package/dist/api/fetcher.d.ts +15 -0
  8. package/dist/api/fetcher.js +23 -22
  9. package/dist/api/providers.js +3 -2
  10. package/dist/api/responses.d.ts +6 -0
  11. package/dist/schema/config.d.ts +4 -0
  12. package/dist/schema/config.js +83 -0
  13. package/dist/schema/filters.d.ts +93 -17
  14. package/dist/schema/filters.js +0 -22
  15. package/dist/schema/filters.spec.d.ts +1 -0
  16. package/dist/schema/filters.spec.js +175 -0
  17. package/dist/schema/index.d.ts +1 -0
  18. package/dist/schema/index.js +4 -1
  19. package/dist/schema/operators.d.ts +26 -24
  20. package/dist/schema/operators.js +13 -11
  21. package/dist/schema/pagination.d.ts +13 -13
  22. package/dist/schema/pagination.js +0 -1
  23. package/dist/schema/query.d.ts +39 -50
  24. package/dist/schema/query.js +25 -37
  25. package/dist/schema/record.d.ts +25 -3
  26. package/dist/schema/record.js +11 -0
  27. package/dist/schema/repository.d.ts +79 -35
  28. package/dist/schema/repository.js +212 -114
  29. package/dist/schema/selection.d.ts +24 -11
  30. package/dist/schema/selection.spec.d.ts +1 -0
  31. package/dist/schema/selection.spec.js +203 -0
  32. package/dist/schema/sorting.d.ts +17 -0
  33. package/dist/schema/sorting.js +28 -0
  34. package/dist/schema/sorting.spec.d.ts +1 -0
  35. package/dist/schema/sorting.spec.js +9 -0
  36. package/dist/util/environment.d.ts +5 -0
  37. package/dist/util/environment.js +68 -0
  38. package/dist/util/fetch.d.ts +2 -0
  39. package/dist/util/fetch.js +13 -0
  40. package/dist/util/lang.d.ts +3 -0
  41. package/dist/util/lang.js +13 -1
  42. package/dist/util/types.d.ts +22 -1
  43. package/package.json +5 -2
@@ -51,7 +51,7 @@ const pagination_1 = require("./pagination");
51
51
  */
52
52
  class Query {
53
53
  constructor(repository, table, data, parent) {
54
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
54
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
55
55
  _Query_table.set(this, void 0);
56
56
  _Query_repository.set(this, void 0);
57
57
  _Query_data.set(this, { filter: {} });
@@ -65,12 +65,14 @@ class Query {
65
65
  else {
66
66
  __classPrivateFieldSet(this, _Query_repository, this, "f");
67
67
  }
68
- __classPrivateFieldGet(this, _Query_data, "f").filter.$any = (_b = (_a = data.filter) === null || _a === void 0 ? void 0 : _a.$any) !== null && _b !== void 0 ? _b : (_c = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _c === void 0 ? void 0 : _c.$any;
69
- __classPrivateFieldGet(this, _Query_data, "f").filter.$all = (_e = (_d = data.filter) === null || _d === void 0 ? void 0 : _d.$all) !== null && _e !== void 0 ? _e : (_f = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _f === void 0 ? void 0 : _f.$all;
70
- __classPrivateFieldGet(this, _Query_data, "f").filter.$not = (_h = (_g = data.filter) === null || _g === void 0 ? void 0 : _g.$not) !== null && _h !== void 0 ? _h : (_j = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _j === void 0 ? void 0 : _j.$not;
71
- __classPrivateFieldGet(this, _Query_data, "f").filter.$none = (_l = (_k = data.filter) === null || _k === void 0 ? void 0 : _k.$none) !== null && _l !== void 0 ? _l : (_m = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _m === void 0 ? void 0 : _m.$none;
72
- __classPrivateFieldGet(this, _Query_data, "f").sort = (_o = data.sort) !== null && _o !== void 0 ? _o : parent === null || parent === void 0 ? void 0 : parent.sort;
73
- __classPrivateFieldGet(this, _Query_data, "f").columns = (_q = (_p = data.columns) !== null && _p !== void 0 ? _p : parent === null || parent === void 0 ? void 0 : parent.columns) !== null && _q !== void 0 ? _q : ['*'];
68
+ __classPrivateFieldGet(this, _Query_data, "f").filter = (_b = (_a = data.filter) !== null && _a !== void 0 ? _a : parent === null || parent === void 0 ? void 0 : parent.filter) !== null && _b !== void 0 ? _b : {};
69
+ __classPrivateFieldGet(this, _Query_data, "f").filter.$any = (_d = (_c = data.filter) === null || _c === void 0 ? void 0 : _c.$any) !== null && _d !== void 0 ? _d : (_e = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _e === void 0 ? void 0 : _e.$any;
70
+ __classPrivateFieldGet(this, _Query_data, "f").filter.$all = (_g = (_f = data.filter) === null || _f === void 0 ? void 0 : _f.$all) !== null && _g !== void 0 ? _g : (_h = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _h === void 0 ? void 0 : _h.$all;
71
+ __classPrivateFieldGet(this, _Query_data, "f").filter.$not = (_k = (_j = data.filter) === null || _j === void 0 ? void 0 : _j.$not) !== null && _k !== void 0 ? _k : (_l = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _l === void 0 ? void 0 : _l.$not;
72
+ __classPrivateFieldGet(this, _Query_data, "f").filter.$none = (_o = (_m = data.filter) === null || _m === void 0 ? void 0 : _m.$none) !== null && _o !== void 0 ? _o : (_p = parent === null || parent === void 0 ? void 0 : parent.filter) === null || _p === void 0 ? void 0 : _p.$none;
73
+ __classPrivateFieldGet(this, _Query_data, "f").sort = (_q = data.sort) !== null && _q !== void 0 ? _q : parent === null || parent === void 0 ? void 0 : parent.sort;
74
+ __classPrivateFieldGet(this, _Query_data, "f").columns = (_s = (_r = data.columns) !== null && _r !== void 0 ? _r : parent === null || parent === void 0 ? void 0 : parent.columns) !== null && _s !== void 0 ? _s : ['*'];
75
+ __classPrivateFieldGet(this, _Query_data, "f").page = (_t = data.page) !== null && _t !== void 0 ? _t : parent === null || parent === void 0 ? void 0 : parent.page;
74
76
  this.any = this.any.bind(this);
75
77
  this.all = this.all.bind(this);
76
78
  this.not = this.not.bind(this);
@@ -89,7 +91,7 @@ class Query {
89
91
  * @returns A new Query object.
90
92
  */
91
93
  any(...queries) {
92
- const $any = queries.map((query) => query.getQueryOptions().filter);
94
+ const $any = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
93
95
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $any } }, __classPrivateFieldGet(this, _Query_data, "f"));
94
96
  }
95
97
  /**
@@ -98,7 +100,7 @@ class Query {
98
100
  * @returns A new Query object.
99
101
  */
100
102
  all(...queries) {
101
- const $all = queries.map((query) => query.getQueryOptions().filter);
103
+ const $all = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
102
104
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
103
105
  }
104
106
  /**
@@ -107,7 +109,7 @@ class Query {
107
109
  * @returns A new Query object.
108
110
  */
109
111
  not(...queries) {
110
- const $not = queries.map((query) => query.getQueryOptions().filter);
112
+ const $not = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
111
113
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $not } }, __classPrivateFieldGet(this, _Query_data, "f"));
112
114
  }
113
115
  /**
@@ -116,19 +118,18 @@ class Query {
116
118
  * @returns A new Query object.
117
119
  */
118
120
  none(...queries) {
119
- const $none = queries.map((query) => query.getQueryOptions().filter);
121
+ const $none = queries.map((query) => { var _a; return (_a = query.getQueryOptions().filter) !== null && _a !== void 0 ? _a : {}; });
120
122
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $none } }, __classPrivateFieldGet(this, _Query_data, "f"));
121
123
  }
122
124
  filter(a, b) {
125
+ var _a, _b;
123
126
  if (arguments.length === 1) {
124
127
  const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
125
- const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat(constraints));
128
+ const $all = (0, lang_1.compact)([(_a = __classPrivateFieldGet(this, _Query_data, "f").filter) === null || _a === void 0 ? void 0 : _a.$all].flat().concat(constraints));
126
129
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
127
130
  }
128
131
  else {
129
- const column = a;
130
- const value = b;
131
- const $all = (0, lang_1.compact)([__classPrivateFieldGet(this, _Query_data, "f").filter.$all].flat().concat({ [column]: value }));
132
+ const $all = (0, lang_1.compact)([(_b = __classPrivateFieldGet(this, _Query_data, "f").filter) === null || _b === void 0 ? void 0 : _b.$all].flat().concat([{ [a]: b }]));
132
133
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { filter: { $all } }, __classPrivateFieldGet(this, _Query_data, "f"));
133
134
  }
134
135
  }
@@ -139,7 +140,9 @@ class Query {
139
140
  * @returns A new Query object.
140
141
  */
141
142
  sort(column, direction) {
142
- const sort = Object.assign(Object.assign({}, __classPrivateFieldGet(this, _Query_data, "f").sort), { [column]: direction });
143
+ var _a;
144
+ const originalSort = [(_a = __classPrivateFieldGet(this, _Query_data, "f").sort) !== null && _a !== void 0 ? _a : []].flat();
145
+ const sort = [...originalSort, { column, direction }];
143
146
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { sort }, __classPrivateFieldGet(this, _Query_data, "f"));
144
147
  }
145
148
  /**
@@ -151,7 +154,8 @@ class Query {
151
154
  return new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), { columns }, __classPrivateFieldGet(this, _Query_data, "f"));
152
155
  }
153
156
  getPaginated(options = {}) {
154
- return __classPrivateFieldGet(this, _Query_repository, "f").query(this, options);
157
+ const query = new Query(__classPrivateFieldGet(this, _Query_repository, "f"), __classPrivateFieldGet(this, _Query_table, "f"), options, __classPrivateFieldGet(this, _Query_data, "f"));
158
+ return __classPrivateFieldGet(this, _Query_repository, "f").query(query);
155
159
  }
156
160
  [(_Query_table = new WeakMap(), _Query_repository = new WeakMap(), _Query_data = new WeakMap(), Symbol.asyncIterator)]() {
157
161
  return __asyncGenerator(this, arguments, function* _a() {
@@ -177,29 +181,20 @@ class Query {
177
181
  let end = false;
178
182
  while (!end) {
179
183
  const { records, meta } = yield __await(this.getPaginated(Object.assign(Object.assign({}, options), { page: { size: chunk, offset } })));
184
+ // Method overloading does not provide type inference for the return type.
180
185
  yield yield __await(records);
181
186
  offset += chunk;
182
187
  end = !meta.page.more;
183
188
  }
184
189
  });
185
190
  }
186
- /**
187
- * Performs the query in the database and returns a set of results.
188
- * @param options Additional options to be used when performing the query.
189
- * @returns An array of records from the database.
190
- */
191
191
  getMany(options = {}) {
192
192
  return __awaiter(this, void 0, void 0, function* () {
193
193
  const { records } = yield this.getPaginated(options);
194
+ // Method overloading does not provide type inference for the return type.
194
195
  return records;
195
196
  });
196
197
  }
197
- /**
198
- * Performs the query in the database and returns all the results.
199
- * Warning: If there are a large number of results, this method can have performance implications.
200
- * @param options Additional options to be used when performing the query.
201
- * @returns An array of records from the database.
202
- */
203
198
  getAll(chunk = pagination_1.PAGINATION_MAX_SIZE, options = {}) {
204
199
  var e_2, _a;
205
200
  return __awaiter(this, void 0, void 0, function* () {
@@ -217,24 +212,17 @@ class Query {
217
212
  }
218
213
  finally { if (e_2) throw e_2.error; }
219
214
  }
215
+ // Method overloading does not provide type inference for the return type.
220
216
  return results;
221
217
  });
222
218
  }
223
- /**
224
- * Performs the query in the database and returns the first result.
225
- * @param options Additional options to be used when performing the query.
226
- * @returns The first record that matches the query, or null if no record matched the query.
227
- */
228
219
  getOne(options = {}) {
229
220
  return __awaiter(this, void 0, void 0, function* () {
230
221
  const records = yield this.getMany(Object.assign(Object.assign({}, options), { page: { size: 1 } }));
222
+ // Method overloading does not provide type inference for the return type.
231
223
  return records[0] || null;
232
224
  });
233
225
  }
234
- /**async deleteAll(): Promise<number> {
235
- // TODO: Return number of affected rows
236
- return 0;
237
- }**/
238
226
  nextPage(size, offset) {
239
227
  return this.firstPage(size, offset);
240
228
  }
@@ -1,4 +1,4 @@
1
- import { Selectable } from './selection';
1
+ import { SelectedPick } from './selection';
2
2
  /**
3
3
  * Represents an identifiable record from the database.
4
4
  */
@@ -27,14 +27,14 @@ export interface XataRecord extends Identifiable {
27
27
  /**
28
28
  * Retrieves a refreshed copy of the current record from the database.
29
29
  */
30
- read(): Promise<this>;
30
+ read(): Promise<SelectedPick<this, ['*']> | null>;
31
31
  /**
32
32
  * Performs a partial update of the current record. On success a new object is
33
33
  * returned and the current object is not mutated.
34
34
  * @param data The columns and their values that have to be updated.
35
35
  * @returns A new record containing the latest values for all the columns of the current record.
36
36
  */
37
- update(data: Partial<Selectable<this>>): Promise<this>;
37
+ update(data: Partial<EditableData<Omit<this, keyof XataRecord>>>): Promise<SelectedPick<this, ['*']>>;
38
38
  /**
39
39
  * Performs a deletion of the current record in the database.
40
40
  *
@@ -42,3 +42,25 @@ export interface XataRecord extends Identifiable {
42
42
  */
43
43
  delete(): Promise<void>;
44
44
  }
45
+ export declare type Link<Record extends XataRecord> = Omit<XataRecord, 'read' | 'update'> & {
46
+ /**
47
+ * Retrieves a refreshed copy of the current record from the database.
48
+ */
49
+ read(): Promise<SelectedPick<Record, ['*']> | null>;
50
+ /**
51
+ * Performs a partial update of the current record. On success a new object is
52
+ * returned and the current object is not mutated.
53
+ * @param data The columns and their values that have to be updated.
54
+ * @returns A new record containing the latest values for all the columns of the current record.
55
+ */
56
+ update(data: Partial<EditableData<Omit<Record, keyof XataRecord>>>): Promise<SelectedPick<Record, ['*']>>;
57
+ };
58
+ export declare function isIdentifiable(x: any): x is Identifiable & Record<string, unknown>;
59
+ export declare function isXataRecord(x: any): x is XataRecord & Record<string, unknown>;
60
+ export declare type EditableData<O extends BaseData> = {
61
+ [K in keyof O]: O[K] extends XataRecord ? {
62
+ id: string;
63
+ } : NonNullable<O[K]> extends XataRecord ? {
64
+ id: string;
65
+ } | null | undefined : O[K];
66
+ };
@@ -1,2 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isXataRecord = exports.isIdentifiable = void 0;
4
+ const lang_1 = require("../util/lang");
5
+ function isIdentifiable(x) {
6
+ return (0, lang_1.isObject)(x) && (0, lang_1.isString)(x === null || x === void 0 ? void 0 : x.id);
7
+ }
8
+ exports.isIdentifiable = isIdentifiable;
9
+ function isXataRecord(x) {
10
+ var _a;
11
+ return (isIdentifiable(x) && typeof (x === null || x === void 0 ? void 0 : x.xata) === 'object' && typeof ((_a = x === null || x === void 0 ? void 0 : x.xata) === null || _a === void 0 ? void 0 : _a.version) === 'number');
12
+ }
13
+ exports.isXataRecord = isXataRecord;
@@ -1,77 +1,121 @@
1
1
  import { FetchImpl } from '../api/fetcher';
2
2
  import { Page } from './pagination';
3
- import { Query, QueryOptions } from './query';
4
- import { BaseData, XataRecord } from './record';
5
- import { Select, SelectableColumn } from './selection';
3
+ import { Query } from './query';
4
+ import { BaseData, EditableData, Identifiable, XataRecord } from './record';
5
+ import { SelectedPick } from './selection';
6
6
  export declare type Links = Record<string, Array<string[]>>;
7
7
  /**
8
8
  * Common interface for performing operations on a table.
9
9
  */
10
- export declare abstract class Repository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record> {
11
- abstract create(object: Data): Promise<Record>;
10
+ export declare abstract class Repository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
11
+ abstract create(object: EditableData<Data> & Partial<Identifiable>): Promise<SelectedPick<Record, ['*']>>;
12
+ /**
13
+ * Creates a single record in the table with a unique id.
14
+ * @param id The unique id.
15
+ * @param object Object containing the column names with their values to be stored in the table.
16
+ * @returns The full persisted record.
17
+ */
18
+ abstract create(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
12
19
  /**
13
20
  * Creates multiple records in the table.
14
21
  * @param objects Array of objects with the column names and the values to be stored in the table.
15
22
  * @returns Array of the persisted records.
16
23
  */
17
- abstract createMany(objects: Data[]): Promise<Record[]>;
24
+ abstract create(objects: Array<EditableData<Data> & Partial<Identifiable>>): Promise<SelectedPick<Record, ['*']>[]>;
18
25
  /**
19
26
  * Queries a single record from the table given its unique id.
20
27
  * @param id The unique id.
21
28
  * @returns The persisted record for the given id or null if the record could not be found.
22
29
  */
23
- abstract read(id: string): Promise<Record | null>;
30
+ abstract read(id: string): Promise<SelectedPick<Record, ['*']> | null>;
24
31
  /**
25
- * Insert a single record with a unique id.
26
- * @param id The unique id.
27
- * @param object Object containing the column names with their values to be stored in the table.
32
+ * Partially update a single record.
33
+ * @param object An object with its id and the columns to be updated.
28
34
  * @returns The full persisted record.
29
35
  */
30
- abstract insert(id: string, object: Data): Promise<Record>;
36
+ abstract update(object: Partial<EditableData<Data>> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
31
37
  /**
32
38
  * Partially update a single record given its unique id.
33
39
  * @param id The unique id.
34
- * @param object The column names and their values that have to be updatd.
40
+ * @param object The column names and their values that have to be updated.
35
41
  * @returns The full persisted record.
36
42
  */
37
- abstract update(id: string, object: Partial<Data>): Promise<Record>;
43
+ abstract update(id: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
38
44
  /**
39
- * Updates or inserts a single record. If a record exists with the given id,
45
+ * Partially updates multiple records.
46
+ * @param objects An array of objects with their ids and columns to be updated.
47
+ * @returns Array of the persisted records.
48
+ */
49
+ abstract update(objects: Array<Partial<EditableData<Data>> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
50
+ /**
51
+ * Creates or updates a single record. If a record exists with the given id,
52
+ * it will be update, otherwise a new record will be created.
53
+ * @param object Object containing the column names with their values to be persisted in the table.
54
+ * @returns The full persisted record.
55
+ */
56
+ abstract createOrUpdate(object: EditableData<Data> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
57
+ /**
58
+ * Creates or updates a single record. If a record exists with the given id,
40
59
  * it will be update, otherwise a new record will be created.
41
60
  * @param id A unique id.
42
61
  * @param object The column names and the values to be persisted.
43
62
  * @returns The full persisted record.
44
63
  */
45
- abstract updateOrInsert(id: string, object: Data): Promise<Record>;
64
+ abstract createOrUpdate(id: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
65
+ /**
66
+ * Creates or updates a single record. If a record exists with the given id,
67
+ * it will be update, otherwise a new record will be created.
68
+ * @param objects Array of objects with the column names and the values to be stored in the table.
69
+ * @returns Array of the persisted records.
70
+ */
71
+ abstract createOrUpdate(objects: Array<EditableData<Data> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
46
72
  /**
47
73
  * Deletes a record given its unique id.
48
74
  * @param id The unique id.
49
75
  * @throws If the record could not be found or there was an error while performing the deletion.
50
76
  */
51
- abstract delete(id: string): void;
52
- abstract query<Result extends XataRecord, Options extends QueryOptions<Record>>(query: Query<Record, Result>, options: Options): Promise<Page<Record, typeof options extends {
53
- columns: SelectableColumn<Data>[];
54
- } ? Select<Data, typeof options['columns'][number]> : Result>>;
77
+ abstract delete(id: string): Promise<void>;
78
+ /**
79
+ * Deletes a record given its unique id.
80
+ * @param id An object with a unique id.
81
+ * @throws If the record could not be found or there was an error while performing the deletion.
82
+ */
83
+ abstract delete(id: Identifiable): Promise<void>;
84
+ /**
85
+ * Deletes a record given a list of unique ids.
86
+ * @param ids The array of unique ids.
87
+ * @throws If the record could not be found or there was an error while performing the deletion.
88
+ */
89
+ abstract delete(ids: string[]): Promise<void>;
90
+ /**
91
+ * Deletes a record given a list of unique ids.
92
+ * @param ids An array of objects with unique ids.
93
+ * @throws If the record could not be found or there was an error while performing the deletion.
94
+ */
95
+ abstract delete(ids: Identifiable[]): Promise<void>;
96
+ abstract query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
55
97
  }
56
- export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Repository<Data, Record> {
98
+ export declare class RestRepository<Data extends BaseData, Record extends XataRecord = Data & XataRecord> extends Query<Record, SelectedPick<Record, ['*']>> {
57
99
  #private;
58
100
  constructor(client: BaseClient<any>, table: string);
59
- create(object: Data): Promise<Record>;
60
- createMany(objects: Data[]): Promise<Record[]>;
61
- read(recordId: string): Promise<Record | null>;
62
- update(recordId: string, object: Partial<Data>): Promise<Record>;
63
- insert(recordId: string, object: Data): Promise<Record>;
64
- updateOrInsert(recordId: string, object: Data): Promise<Record>;
65
- delete(recordId: string): Promise<void>;
66
- query<Result extends XataRecord, Options extends QueryOptions<Record>>(query: Query<Record, Result>, options?: Options): Promise<Page<Record, typeof options extends {
67
- columns: SelectableColumn<Data>[];
68
- } ? Select<Data, typeof options['columns'][number]> : Result>>;
101
+ create(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
102
+ create(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
103
+ create(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
104
+ read(recordId: string): Promise<SelectedPick<Record, ['*']> | null>;
105
+ update(object: Partial<EditableData<Data>> & Identifiable): Promise<SelectedPick<Record, ['*']>>;
106
+ update(recordId: string, object: Partial<EditableData<Data>>): Promise<SelectedPick<Record, ['*']>>;
107
+ update(objects: Array<Partial<EditableData<Data>> & Identifiable>): Promise<SelectedPick<Record, ['*']>[]>;
108
+ createOrUpdate(object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
109
+ createOrUpdate(recordId: string, object: EditableData<Data>): Promise<SelectedPick<Record, ['*']>>;
110
+ createOrUpdate(objects: EditableData<Data>[]): Promise<SelectedPick<Record, ['*']>[]>;
111
+ delete(recordId: string | Identifiable | Array<string | Identifiable>): Promise<void>;
112
+ query<Result extends XataRecord>(query: Query<Record, Result>): Promise<Page<Record, Result>>;
69
113
  }
70
114
  interface RepositoryFactory {
71
- createRepository<Data extends BaseData>(client: BaseClient<any>, table: string): Repository<Data>;
115
+ createRepository<Data extends BaseData>(client: BaseClient<any>, table: string): Repository<Data & XataRecord>;
72
116
  }
73
117
  export declare class RestRespositoryFactory implements RepositoryFactory {
74
- createRepository<Data extends BaseData>(client: BaseClient<any>, table: string): Repository<Data>;
118
+ createRepository<Data extends BaseData>(client: BaseClient<any>, table: string): Repository<Data & XataRecord>;
75
119
  }
76
120
  declare type BranchStrategyValue = string | undefined | null;
77
121
  declare type BranchStrategyBuilder = () => BranchStrategyValue | Promise<BranchStrategyValue>;
@@ -86,18 +130,18 @@ export declare type XataClientOptions = {
86
130
  */
87
131
  fetch?: FetchImpl;
88
132
  databaseURL?: string;
89
- branch: BranchStrategyOption;
133
+ branch?: BranchStrategyOption;
90
134
  /**
91
135
  * API key to be used. You can create one in your account settings at https://app.xata.io/settings.
92
136
  */
93
- apiKey: string;
137
+ apiKey?: string;
94
138
  repositoryFactory?: RepositoryFactory;
95
139
  };
96
140
  export declare class BaseClient<D extends Record<string, Repository<any>> = Record<string, Repository<any>>> {
97
141
  #private;
98
142
  options: XataClientOptions;
99
143
  db: D;
100
- constructor(options: XataClientOptions, links?: Links);
144
+ constructor(options?: XataClientOptions, links?: Links);
101
145
  initObject<T>(table: string, object: object): T;
102
146
  getBranch(): Promise<string>;
103
147
  }