@xata.io/client 0.0.0-beta.f46cf74 → 0.0.0-beta.fef71a6

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.
@@ -81,27 +81,28 @@ export declare class Query<T extends XataRecord, R extends XataRecord = T> imple
81
81
  * @returns A new Query object.
82
82
  */
83
83
  select<K extends SelectableColumn<T>>(columns: K[]): Query<T, Select<T, K>>;
84
- getPaginated<Options extends QueryOptions<T>>(options?: Options): Promise<Page<T, typeof options extends {
85
- columns: SelectableColumn<T>[];
86
- } ? Select<T, typeof options['columns'][number]> : R>>;
84
+ getPaginated<Options extends QueryOptions<T>>(options?: Options): Promise<Page<T, GetWithColumnOptions<T, R, typeof options>>>;
87
85
  [Symbol.asyncIterator](): AsyncIterableIterator<R>;
88
- getIterator(chunk: number, options?: Omit<QueryOptions<T>, 'page'>): AsyncGenerator<R[]>;
86
+ getIterator<Options extends QueryOptions<T>>(chunk: number, options?: Omit<Options, 'page'>): AsyncGenerator<GetWithColumnOptions<T, R, typeof options>[]>;
89
87
  /**
90
88
  * Performs the query in the database and returns a set of results.
91
89
  * @param options Additional options to be used when performing the query.
92
90
  * @returns An array of records from the database.
93
91
  */
94
- getMany<Options extends QueryOptions<T>>(options?: Options): Promise<(typeof options extends {
95
- columns: SelectableColumn<T>[];
96
- } ? Select<T, typeof options['columns'][number]> : R)[]>;
92
+ getMany<Options extends QueryOptions<T>>(options?: Options): Promise<GetWithColumnOptions<T, R, typeof options>[]>;
93
+ /**
94
+ * Performs the query in the database and returns all the results.
95
+ * Warning: If there are a large number of results, this method can have performance implications.
96
+ * @param options Additional options to be used when performing the query.
97
+ * @returns An array of records from the database.
98
+ */
99
+ getAll<Options extends QueryOptions<T>>(options?: Omit<Options, 'page'>): Promise<GetWithColumnOptions<T, R, typeof options>[]>;
97
100
  /**
98
101
  * Performs the query in the database and returns the first result.
99
102
  * @param options Additional options to be used when performing the query.
100
103
  * @returns The first record that matches the query, or null if no record matched the query.
101
104
  */
102
- getOne<Options extends Omit<QueryOptions<T>, 'page'>>(options?: Options): Promise<(typeof options extends {
103
- columns: SelectableColumn<T>[];
104
- } ? Select<T, typeof options['columns'][number]> : R) | null>;
105
+ getOne<Options extends Omit<QueryOptions<T>, 'page'>>(options?: Options): Promise<GetWithColumnOptions<T, R, typeof options> | null>;
105
106
  /**async deleteAll(): Promise<number> {
106
107
  // TODO: Return number of affected rows
107
108
  return 0;
@@ -112,3 +113,16 @@ export declare class Query<T extends XataRecord, R extends XataRecord = T> imple
112
113
  lastPage(size?: number, offset?: number): Promise<Page<T, R>>;
113
114
  hasNextPage(): boolean;
114
115
  }
116
+ /**
117
+ * Helper type to read options and compute the correct type for the result values
118
+ * T: Original type
119
+ * R: Default destination type
120
+ * Options: QueryOptions
121
+ *
122
+ * If the columns are overriden in the options, the result type is the pick of the original type and the columns
123
+ * If the columns are not overriden, the result type is the default destination type
124
+ */
125
+ declare type GetWithColumnOptions<T, R, Options> = Options extends {
126
+ columns: SelectableColumn<T>[];
127
+ } ? Select<T, Options['columns'][number]> : R;
128
+ export {};
@@ -193,6 +193,32 @@ class Query {
193
193
  return records;
194
194
  });
195
195
  }
196
+ /**
197
+ * Performs the query in the database and returns all the results.
198
+ * Warning: If there are a large number of results, this method can have performance implications.
199
+ * @param options Additional options to be used when performing the query.
200
+ * @returns An array of records from the database.
201
+ */
202
+ getAll(options = {}) {
203
+ var e_2, _a;
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ const results = [];
206
+ try {
207
+ for (var _b = __asyncValues(this.getIterator(100, options)), _c; _c = yield _b.next(), !_c.done;) {
208
+ const page = _c.value;
209
+ results.push(...page);
210
+ }
211
+ }
212
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
213
+ finally {
214
+ try {
215
+ if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
216
+ }
217
+ finally { if (e_2) throw e_2.error; }
218
+ }
219
+ return results;
220
+ });
221
+ }
196
222
  /**
197
223
  * Performs the query in the database and returns the first result.
198
224
  * @param options Additional options to be used when performing the query.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xata.io/client",
3
- "version": "0.0.0-beta.f46cf74",
3
+ "version": "0.0.0-beta.fef71a6",
4
4
  "description": "Xata.io SDK for TypeScript and JavaScript",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,5 +20,5 @@
20
20
  "url": "https://github.com/xataio/client-ts/issues"
21
21
  },
22
22
  "homepage": "https://github.com/xataio/client-ts/blob/main/client/README.md",
23
- "gitHead": "f46cf74dea31a3823e8d48ded90a6f0c7d42d894"
23
+ "gitHead": "fef71a6d4020e404d82c373e466e9fd4c23d4d90"
24
24
  }