@xata.io/client 0.13.1 → 0.13.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.13.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#444](https://github.com/xataio/client-ts/pull/444) [`3c3a5af`](https://github.com/xataio/client-ts/commit/3c3a5afb1d5fb3295fd8cf6c2b66709a5c047507) Thanks [@SferaDev](https://github.com/SferaDev)! - Publish xata client on deno.land
8
+
9
+ ## 0.13.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [#434](https://github.com/xataio/client-ts/pull/434) [`b82383d`](https://github.com/xataio/client-ts/commit/b82383d7541d19ae71ad7e047fd100901981f28b) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix problem with SSR `RecordArray` in Next.js
14
+
15
+ ## 0.13.2
16
+
17
+ ### Patch Changes
18
+
19
+ - [#431](https://github.com/xataio/client-ts/pull/431) [`8f62024`](https://github.com/xataio/client-ts/commit/8f62024101028b981dc31a68fb258e89110d45dc) Thanks [@SferaDev](https://github.com/SferaDev)! - Include request ids in the error response
20
+
21
+ * [#429](https://github.com/xataio/client-ts/pull/429) [`bb102b4`](https://github.com/xataio/client-ts/commit/bb102b46b722d0a61996c42cda991c9f0080e464) Thanks [@SferaDev](https://github.com/SferaDev)! - Avoid detection of `Buffer` in edge runtime middleware
22
+
23
+ - [#428](https://github.com/xataio/client-ts/pull/428) [`06740ca`](https://github.com/xataio/client-ts/commit/06740cad216831216f0be8cf9de7e354c0ef9191) Thanks [@SferaDev](https://github.com/SferaDev)! - Improve selection types to make them more readable
24
+
3
25
  ## 0.13.1
4
26
 
5
27
  ### Patch Changes
package/README.md CHANGED
@@ -1,10 +1,28 @@
1
1
  # Xata SDK for TypeScript and JavaScript
2
2
 
3
- This SDK has zero dependencies, so it can be used in many JavaScript runtimes including Node.js, Cloudflare workers, Deno, Electron, etc.
3
+ This SDK has zero dependencies, so it can be used in many JavaScript runtimes including Node.js, Cloudflare workers, Deno, Electron, etc. It also works in browsers for the same reason. But this is strongly discouraged because you can easily leak your API keys from browsers.
4
4
 
5
- It also works in browsers for the same reason. But this is strongly discouraged because the API token would be leaked.
5
+ ## Table of Contents
6
6
 
7
- ## Installing
7
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
8
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9
+
10
+ - [Installation](#installation)
11
+ - [Usage](#usage)
12
+ - [Schema-generated Client](#schema-generated-client)
13
+ - [Schema-less Client](#schema-less-client)
14
+ - [API Design](#api-design)
15
+ - [Creating Objects](#creating-objects)
16
+ - [Query a Single Object by its ID](#query-a-single-object-by-its-id)
17
+ - [Querying Multiple Objects](#querying-multiple-objects)
18
+ - [Updating Objects](#updating-objects)
19
+ - [Deleting Objects](#deleting-objects)
20
+ - [API Client](#api-client)
21
+ - [Deno support](#deno-support)
22
+
23
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
24
+
25
+ ## Installation
8
26
 
9
27
  ```bash
10
28
  npm install @xata.io/client
@@ -20,7 +38,7 @@ There are three ways to use the SDK:
20
38
 
21
39
  ### Schema-generated Client
22
40
 
23
- To use the schema-generated client, you need to run the code generator utility that comes with [our CLI](../../cli/README.md).
41
+ To use the schema-generated client, you need to run the code generator utility that comes with [our CLI](https://docs.xata.io/cli/getting-started).
24
42
 
25
43
  To run it (and assuming you have configured the project with `xata init`):
26
44
 
@@ -28,19 +46,17 @@ To run it (and assuming you have configured the project with `xata init`):
28
46
  xata codegen
29
47
  ```
30
48
 
31
- In a TypeScript file start using the generated code:
49
+ In a TypeScript file, start using the generated code like this:
32
50
 
33
51
  ```ts
34
- import { XataClient } from './xata';
52
+ import { XataClient } from './xata'; // or wherever you chose to generate the client
35
53
 
36
- const xata = new XataClient({
37
- fetch: fetchImplementation // Required if your runtime doesn't provide a global `fetch` function.
38
- });
54
+ const xata = new XataClient();
39
55
  ```
40
56
 
41
- The import above will differ if you chose to genreate the code in a different location.
57
+ The import above will differ if you chose to generate the code in a different location.
42
58
 
43
- The `fetch` paramter is required only if your runtime doesn't provide a global `fetch` function. There's also a `databaseURL` argument that by default will contain a URL pointing to your database (e.g. `https://myworkspace-123abc.xata.sh/db/databasename`), it can be specified in the constructor to overwrite that value if for whatever reason you need to connect to a different workspace or database.
59
+ The `XataClient` constructor accepts an object with configuration options, like the `fetch` parameter, which is required only if your runtime doesn't provide a global `fetch` function. There's also a `databaseURL` argument that by default will contain a URL pointing to your database (e.g. `https://myworkspace-123abc.xata.sh/db/databasename`). It can be specified in the constructor to overwrite that value if for whatever reason you need to connect to a different workspace or database.
44
60
 
45
61
  The code generator will create two TypeScript types for each schema entity. The base one will be an `Identifiable` entity with the internal properties your entity has and the `Record` one will extend it with a set of operations (update, delete, etc...) and some schema metadata (xata version).
46
62
 
@@ -60,7 +76,7 @@ await admin.update({ email: 'admin@foo.bar' });
60
76
  await admin.delete();
61
77
  ```
62
78
 
63
- You will learn more about the available operations below, under the `API Design` section.
79
+ You will learn more about the available operations below, under the [`API Design`](#api-design) section.
64
80
 
65
81
  ### Schema-less Client
66
82
 
@@ -78,15 +94,15 @@ const xata = new BaseClient({
78
94
 
79
95
  It works the same way as the code-generated `XataClient` but doesn't provide type-safety for your model.
80
96
 
81
- You can read more on the methods available below, under the `API Design` section.
97
+ You can read more on the methods available below, in the next section.
82
98
 
83
99
  ### API Design
84
100
 
85
- The Xata SDK to create/read/update/delete records follows the repository pattern. Each table will have a repository object available at `xata.db.[table-name]`.
101
+ The Xata SDK to create/read/update/delete records follows the [repository pattern](https://lyz-code.github.io/blue-book/architecture/repository_pattern/). Each table will have a repository object available at `xata.db.[table-name]`.
86
102
 
87
- For example if you have a `users` table there'll be a repository at `xata.db.users`. If you're using the schema-less client, you can also use the `xata.db.[table-name]` syntax to access the repository but without TypeScript auto-completion.
103
+ For example if you have a `users` table, there'll be a repository at `xata.db.users`. If you're using the schema-less client, you can also use the `xata.db.[table-name]` syntax to access the repository but without TypeScript auto-completion.
88
104
 
89
- **Creating objects**
105
+ #### Creating Objects
90
106
 
91
107
  Invoke the `create()` method in the repository. Example:
92
108
 
@@ -112,14 +128,14 @@ const user = await client.db.users.updateOrInsert('user_admin', {
112
128
  });
113
129
  ```
114
130
 
115
- **Query a single object by its id**
131
+ #### Query a Single Object by its ID
116
132
 
117
133
  ```ts
118
134
  // `user` will be null if the object cannot be found
119
135
  const user = await xata.db.users.read('rec_1234abcdef');
120
136
  ```
121
137
 
122
- **Querying multiple objects**
138
+ #### Querying Multiple Objects
123
139
 
124
140
  ```ts
125
141
  // Query objects selecting all fields.
@@ -140,7 +156,7 @@ const page = await xata.db.users.filter('email', 'foo@example.com').getPaginated
140
156
  const page = await xata.db.users.sort('full_name', 'asc').getPaginated();
141
157
  ```
142
158
 
143
- Query operations (`select()`, `filter()`, `sort()`) return a `Query` object. These objects are immutable. You can add additional constraints, sort, etc. by calling their methods, and a new query will be returned. In order to finally make a query to the database you'll invoke `getPaginated()`, `getMany()`, `getAll()`, or `getFirst()`.
159
+ Query operations (`select()`, `filter()`, `sort()`) return a `Query` object. These objects are immutable. You can add additional constraints, `sort`, etc. by calling their methods, and a new query will be returned. In order to finally make a query to the database you'll invoke `getPaginated()`, `getMany()`, `getAll()`, or `getFirst()`.
144
160
 
145
161
  ```ts
146
162
  // Operators that combine multiple conditions can be deconstructed
@@ -173,7 +189,7 @@ const firstPage = await page.firstPage(); // Page object
173
189
  const lastPage = await page.lastPage(); // Page object
174
190
  ```
175
191
 
176
- If you want to use an iterator, both the Repository and the Query classes implement an AsyncIterable. Alternatively you can use `getIterator()` and customize the batch size of the iterator:
192
+ If you want to use an iterator, both the Repository and the Query classes implement an `AsyncIterable`. Alternatively you can use `getIterator()` and customize the batch size of the iterator:
177
193
 
178
194
  ```ts
179
195
  for await (const record of xata.db.users) {
@@ -189,7 +205,7 @@ for await (const records of xata.db.users.getIterator({ batchSize: 100 })) {
189
205
  }
190
206
  ```
191
207
 
192
- **Updating objects**
208
+ #### Updating Objects
193
209
 
194
210
  Updating an object leaves the existing instance unchanged, but returns a new object with the updated values.
195
211
 
@@ -205,7 +221,7 @@ const updatedUser = await xata.db.users.update('rec_1234abcdef', {
205
221
  });
206
222
  ```
207
223
 
208
- **Deleting objects**
224
+ #### Deleting Objects
209
225
 
210
226
  ```ts
211
227
  // Using an existing object
@@ -217,7 +233,7 @@ await xata.db.users.delete('rec_1234abcdef');
217
233
 
218
234
  ### API Client
219
235
 
220
- One of the main features of the SDK is the ability to interact with the whole Xata API and perform administrative operations such as creating/reading/updating/deleting workspaces, databases, tables, branches...
236
+ One of the main features of the SDK is the ability to interact with the whole Xata API and perform administrative operations such as creating/reading/updating/deleting [workspaces](https://docs.xata.io/concepts/workspaces), databases, tables, branches...
221
237
 
222
238
  To communicate with the SDK we provide a constructor called `XataApiClient` that accepts an API token and an optional fetch implementation method.
223
239
 
@@ -229,7 +245,6 @@ Once you have initialized the API client, the operations are organized following
229
245
 
230
246
  ```ts
231
247
  const { id: workspace } = await client.workspaces.createWorkspace({ name: 'example', slug: 'example' });
232
-
233
248
  const { databaseName } = await client.databases.createDatabase(workspace, 'database');
234
249
 
235
250
  await client.branches.createBranch(workspace, databaseName, 'branch');
@@ -249,17 +264,8 @@ await client.workspaces.deleteWorkspace(workspace);
249
264
 
250
265
  ## Deno support
251
266
 
252
- Right now we are still not publishing the client on deno.land or have support for deno in the codegen.
253
-
254
- However you can already use it with your preferred node CDN with the following import in the auto-generated `xata.ts` file:
267
+ We publish the client on [deno.land](https://deno.land/x/xata). You can use it by changing the import in the auto-generated `xata.ts` file:
255
268
 
256
269
  ```ts
257
- import {
258
- BaseClient,
259
- Query,
260
- Repository,
261
- RestRespositoryFactory,
262
- XataClientOptions,
263
- XataRecord
264
- } from 'https://esm.sh/@xata.io/client@<version>/dist/schema?target=deno';
270
+ import { buildClient, BaseClientOptions, XataRecord } from 'https://deno.land/x/xata/mod.ts';
265
271
  ```
package/Usage.md CHANGED
@@ -1,23 +1,134 @@
1
- # TypeScript SDK
1
+ # Xata SDK Reference
2
2
 
3
- There're four types of objects in the Xata TypeScript SDK:
3
+ There are four types of objects in the Xata TypeScript SDK. In this document, we will understand them deeper to better work with the Xata SDK.
4
4
 
5
- - `Repository`: a table representation that can be used to create, read, update, and delete records.
6
5
  - `Query`: a combination of filters and other parameters to retrieve a collection of records.
6
+ - `Repository`: a table representation that can be used to create, read, update, and delete records.
7
7
  - `XataRecord`: a row in a table.
8
8
  - `Page`: a collection of records that can be paginated.
9
9
 
10
- ## Repository
10
+ Let's explore them below.
11
+
12
+ ## Table of Contents
13
+
14
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
15
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
16
+
17
+ - [Query](#query)
18
+ - [Column selection](#column-selection)
19
+ - [Sorting](#sorting)
20
+ - [Filtering](#filtering)
21
+ - [Combining queries](#combining-queries)
22
+ - [Repository](#repository)
23
+ - [Reading records](#reading-records)
24
+ - [Creating records](#creating-records)
25
+ - [Updating records](#updating-records)
26
+ - [Deleting records](#deleting-records)
27
+ - [Searching records](#searching-records)
28
+ - [Page](#page)
29
+ - [Iterators and generators](#iterators-and-generators)
30
+ - [Helper variables](#helper-variables)
31
+ - [XataRecord](#xatarecord)
32
+
33
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
34
+
35
+ ## Query
36
+
37
+ To get a collection of records, you can use the `Query` object. It provides the following methods:
38
+
39
+ - `getFirst()`: returns the first record in the query results.
40
+ - `getPaginated()`: returns a page of records in the query results.
41
+ - `getAll()`: returns all the records in the query results.
42
+ - `getMany()`: returns an array of some records in the query results.
43
+
44
+ Since the [`Repository`](#repository) class implements the `Query` interface, you can use it to query and paginate the records in the table too.
45
+
46
+ ```ts
47
+ const user = xata.db.users.getFirst();
48
+ ```
49
+
50
+ ### Column selection
51
+
52
+ The `Query` object can be used to select the columns that will be returned in the results. You can pick multiple columns by providing an array of column names, or you can pick all the columns by providing `*`.
53
+
54
+ The dot notation is supported to select columns from nested objects.
55
+
56
+ ```ts
57
+ const user = xata.db.users.select(['*', 'team.*']).getFirst();
58
+ ```
59
+
60
+ ### Sorting
61
+
62
+ The `Query` object can be used to sort the order of the results. You can sort the results by providing a column name and an `asc` or `desc` string.
63
+
64
+ ```ts
65
+ const user = xata.db.users.orderBy('fullName', 'asc').getFirst();
66
+ ```
67
+
68
+ ### Filtering
69
+
70
+ You can filter the results by providing the column and the value to filter.
71
+
72
+ ```ts
73
+ const user = xata.db.users.filter('fullName', 'John').getFirst();
74
+ ```
75
+
76
+ To combine multiple filters in an 'AND' clause, you can pipe the filters together.
77
+
78
+ ```ts
79
+ const user = xata.db.users.filter('fullName', 'John').filter('team.name', 'Marketing').getFirst();
80
+ ```
81
+
82
+ Also you can filter the results by providing a `filter` object.
83
+
84
+ ```ts
85
+ const user = xata.db.users.filter({ fullName: 'John', 'team.name': 'Marketing' }).getFirst();
86
+ ```
87
+
88
+ We offer some helper functions to build the filter values, like: `gt`, `ge`, `gte`, `lt`, `le`, `lte`, `exists`, `notExists`, `startsWith`, `endsWith`, `pattern`, `is`, `isNot`, `contains`, `includes`, and others specific to the type of the column.
89
+
90
+ ```ts
91
+ const user = xata.db.users.filter('name', startsWith('Bar')).getFirst();
92
+ ```
93
+
94
+ If you prefer to directly use the filter operators as in the API, you can add them in the `filter` object.
95
+
96
+ ```ts
97
+ xata.db.users.filter({ full_name: { $startsWith: 'foo' } }).getFirst();
98
+ ```
99
+
100
+ ### Combining Queries
101
+
102
+ Queries can be stored in variables and can be combined with other queries.
103
+
104
+ ```ts
105
+ const johnQuery = xata.db.users.filter('fullName', 'John');
106
+ const janeQuery = xata.db.users.filter('fullName', 'Jane');
107
+
108
+ const johns = await johnQuery.getAll();
109
+ const janes = await janeQuery.getAll();
110
+
111
+ const users = await xata.db.users.any(johnQuery, janeQuery).getAll();
112
+ ```
113
+
114
+ We offer the following helper methods to combine queries:
115
+
116
+ - `any()`: returns the records that match any of the queries.
117
+ - `all()`: returns the records that match all of the queries.
118
+ - `none()`: returns the records that match none of the queries.
119
+ - `not()`: returns the records that don't match the given query.
120
+
121
+ You can read more about the query operators in the API section for the query table endpoint.
11
122
 
12
- Any table in the database can be represented by a `Repository` object.
123
+ ## Repository
13
124
 
14
- A repository is an object that can be used to create, read, update, and delete records in the table it represents.
125
+ Any table in the database can be represented by a `Repository` object. A repository is an object that can be used to create, read, update, and delete records in the table it represents. It also implements the `Query` and `Page` interfaces, so you can use it to query and paginate the records in the table too.
15
126
 
16
- It also implements the `Query` and `Page` interfaces, so you can use it to query and paginate the records in the table too. We'll see how to use these objects in the next section.
127
+ We'll see how to use these objects in the next section.
17
128
 
18
129
  ### Reading records
19
130
 
20
- The `read()` method can be used to read a records by their ids:
131
+ The `read()` method can be used to read records by their ids:
21
132
 
22
133
  - If the object cannot be found, the method will return `null`.
23
134
  - If the object can be found, the method will return a `XataRecord` object.
@@ -44,7 +155,7 @@ const user = await xata.db.users.read(object1);
44
155
  const users = await xata.db.users.read([object1, object2]);
45
156
  ```
46
157
 
47
- ### Creating records
158
+ ### Creating Records
48
159
 
49
160
  Both the `create()` and `createOrUpdate()` methods can be used to create a new record.
50
161
 
@@ -93,7 +204,7 @@ const users = await xata.db.users.createOrUpdate([
93
204
 
94
205
  ### Updating records
95
206
 
96
- The `update()` method can be used to update an existing record. It will throw an Error if the record cannot be found.
207
+ The `update()` method can be used to update an existing record. It will throw an `Error` if the record cannot be found.
97
208
 
98
209
  ```ts
99
210
  const user = await xata.db.users.update('rec_1234abcdef', { fullName: 'John Smith' });
@@ -114,9 +225,9 @@ const users = await xata.db.users.update([
114
225
  ]);
115
226
  ```
116
227
 
117
- ### Deleting records
228
+ ### Deleting Records
118
229
 
119
- The `delete()` method can be used to delete an existing record. It will throw an Error if the record cannot be found.
230
+ The `delete()` method can be used to delete an existing record. It will throw an `Error` if the record cannot be found.
120
231
 
121
232
  ```ts
122
233
  const user = await xata.db.users.delete('rec_1234abcdef');
@@ -145,7 +256,7 @@ const object2 = { id: 'user_admin' };
145
256
  const users = await xata.db.users.delete([object1, object2]);
146
257
  ```
147
258
 
148
- ### Searching records
259
+ ### Searching Records
149
260
 
150
261
  The `search()` method can be used to search records. It returns an array of records.
151
262
 
@@ -159,105 +270,9 @@ Also you can customize the results with an `options` object that includes `fuzzi
159
270
  const results = await xata.db.users.search('John', { fuzziness: 1, filter: { 'team.name': 'Marketing' } });
160
271
  ```
161
272
 
162
- ## Query
163
-
164
- To get a collection of records, you can use the `Query` object.
165
-
166
- It provides the following methods:
167
-
168
- - `getFirst()`: returns the first record in the query results.
169
- - `getPaginated()`: returns a page of records in the query results.
170
- - `getAll()`: returns all the records in the query results.
171
- - `getMany()`: returns an array of some records in the query results.
172
-
173
- Since the `Repository` class implements the `Query` interface, you can use it to query and paginate the records in the table too.
174
-
175
- ```ts
176
- const user = xata.db.users.getFirst();
177
- ```
178
-
179
- ### Column selection
180
-
181
- The `Query` object can be used to select the columns that will be returned in the results.
182
-
183
- You can pick multiple columns by providing an array of column names, or you can pick all the columns by providing `*`.
184
-
185
- The dot notation is supported to select columns from nested objects.
186
-
187
- ```ts
188
- const user = xata.db.users.select(['*', 'team.*']).getFirst();
189
- ```
190
-
191
- ### Sorting
192
-
193
- The `Query` object can be used to sort the order of the results.
194
-
195
- You can sort the results by providing a column name and an `asc` or `desc` string.
196
-
197
- ```ts
198
- const user = xata.db.users.orderBy('fullName', 'asc').getFirst();
199
- ```
200
-
201
- ### Filtering
202
-
203
- You can filter the results by providing the column and the value to filter.
204
-
205
- ```ts
206
- const user = xata.db.users.filter('fullName', 'John').getFirst();
207
- ```
208
-
209
- To combine multiple filters in an 'AND' clause, you can pipe the filters together.
210
-
211
- ```ts
212
- const user = xata.db.users.filter('fullName', 'John').filter('team.name', 'Marketing').getFirst();
213
- ```
214
-
215
- Also you can filter the results by providing a `filter` object.
216
-
217
- ```ts
218
- const user = xata.db.users.filter({ fullName: 'John', 'team.name': 'Marketing' }).getFirst();
219
- ```
220
-
221
- We offer some helper functions to build the filter values, like: `gt`, `ge`, `gte`, `lt`, `le`, `lte`, `exists`, `notExists`, `startsWith`, `endsWith`, `pattern`, `is`, `isNot`, `contains`, `includes`, and others specific to the type of the column.
222
-
223
- ```ts
224
- const user = xata.db.users.filter('name', startsWith('Bar')).getFirst();
225
- ```
226
-
227
- If you prefer to directly use the filter operators as in the API, you can add them in the `filter` object.
228
-
229
- ```ts
230
- xata.db.users.filter({ full_name: { $startsWith: 'foo' } }).getFirst();
231
- ```
232
-
233
- ### Combining queries
234
-
235
- Queries can be stored in variables and can be combined with other queries.
236
-
237
- ```ts
238
- const johnQuery = xata.db.users.filter('fullName', 'John');
239
- const janeQuery = xata.db.users.filter('fullName', 'Jane');
240
-
241
- const johns = await johnQuery.getAll();
242
- const janes = await janeQuery.getAll();
243
-
244
- const users = await xata.db.users.any(johnQuery, janeQuery).getAll();
245
- ```
246
-
247
- We offer the following helper methods to combine queries:
248
-
249
- - `any()`: returns the records that match any of the queries.
250
- - `all()`: returns the records that match all of the queries.
251
- - `none()`: returns the records that match none of the queries.
252
- - `not()`: returns the records that don't match the given query.
253
-
254
- You can read more about the query operators in the API section for the query table endpoint.
255
-
256
273
  ## Page
257
274
 
258
- Some methods of the `Query` interface provide a `Page` object as a return value that can be used to paginate the results.
259
-
260
- The `Page` object can be used to get the queried records of a table in pages. It is an abstraction of cursor-based pagination.
275
+ Some methods of the `Query` interface provide a `Page` object as a return value that can be used to paginate the results. The `Page` object can be used to get the queried records of a table in pages. It is an abstraction of cursor-based pagination.
261
276
 
262
277
  It contains:
263
278
 
@@ -299,7 +314,7 @@ records.hasNextPage();
299
314
  const { records: page2Records } = await records.nextPage();
300
315
  ```
301
316
 
302
- Optionally you can provide `offset` and `size` parameters to the pagination and override the default values.
317
+ Optionally, you can provide `offset` and `size` parameters to the pagination and override the default values.
303
318
 
304
319
  ```ts
305
320
  const page = await xata.db.users.getPaginated();
@@ -312,7 +327,7 @@ const page2 = await page.nextPage(50);
312
327
  const page3 = await page2.nextPage(10, 60);
313
328
  ```
314
329
 
315
- ### Iterators and generators
330
+ ### Iterators and Generators
316
331
 
317
332
  The `Query` object can be used to iterate over the results as a way to paginate the results.
318
333
 
@@ -330,7 +345,7 @@ for await (const users of xata.db.users.getIterator({ batchSize: 50 })) {
330
345
  }
331
346
  ```
332
347
 
333
- ### Helper variables
348
+ ### Helper Variables
334
349
 
335
350
  We expose some helper variables of the API limits when paginating:
336
351
 
@@ -339,7 +354,7 @@ We expose some helper variables of the API limits when paginating:
339
354
  - `PAGINATION_MAX_OFFSET`: Maximum offset.
340
355
  - `PAGINATION_DEFAULT_OFFSET`: Default offset.
341
356
 
342
- You can use these variables if you implement your own pagination mechanism, as they will be updated when the API limits are updated.
357
+ You can use these variables if you implement your own pagination mechanism, as they will be updated when our API limits are updated.
343
358
 
344
359
  ## XataRecord
345
360
 
package/dist/index.cjs CHANGED
@@ -21,7 +21,8 @@ function toBase64(value) {
21
21
  try {
22
22
  return btoa(value);
23
23
  } catch (err) {
24
- return Buffer.from(value).toString("base64");
24
+ const buf = Buffer;
25
+ return buf.from(value).toString("base64");
25
26
  }
26
27
  }
27
28
 
@@ -77,7 +78,7 @@ function getFetchImplementation(userFetch) {
77
78
  return fetchImpl;
78
79
  }
79
80
 
80
- const VERSION = "0.13.1";
81
+ const VERSION = "0.13.4";
81
82
 
82
83
  class ErrorWithCause extends Error {
83
84
  constructor(message, options) {
@@ -85,15 +86,20 @@ class ErrorWithCause extends Error {
85
86
  }
86
87
  }
87
88
  class FetcherError extends ErrorWithCause {
88
- constructor(status, data) {
89
+ constructor(status, data, requestId) {
89
90
  super(getMessage(data));
90
91
  this.status = status;
91
92
  this.errors = isBulkError(data) ? data.errors : void 0;
93
+ this.requestId = requestId;
92
94
  if (data instanceof Error) {
93
95
  this.stack = data.stack;
94
96
  this.cause = data.cause;
95
97
  }
96
98
  }
99
+ toString() {
100
+ const error = super.toString();
101
+ return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
102
+ }
97
103
  }
98
104
  function isBulkError(error) {
99
105
  return isObject(error) && Array.isArray(error.errors);
@@ -170,14 +176,15 @@ async function fetch$1({
170
176
  if (response.status === 204) {
171
177
  return {};
172
178
  }
179
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
173
180
  try {
174
181
  const jsonResponse = await response.json();
175
182
  if (response.ok) {
176
183
  return jsonResponse;
177
184
  }
178
- throw new FetcherError(response.status, jsonResponse);
185
+ throw new FetcherError(response.status, jsonResponse, requestId);
179
186
  } catch (error) {
180
- throw new FetcherError(response.status, error);
187
+ throw new FetcherError(response.status, error, requestId);
181
188
  }
182
189
  }
183
190
 
@@ -988,10 +995,20 @@ function isCursorPaginationOptions(options) {
988
995
  }
989
996
  const _RecordArray = class extends Array {
990
997
  constructor(page, overrideRecords) {
991
- super(...overrideRecords ?? page.records);
998
+ super(..._RecordArray.parseConstructorParams(page, overrideRecords));
992
999
  __privateAdd$6(this, _page, void 0);
993
1000
  __privateSet$5(this, _page, page);
994
1001
  }
1002
+ static parseConstructorParams(...args) {
1003
+ if (args.length === 1 && typeof args[0] === "number") {
1004
+ return new Array(args[0]);
1005
+ }
1006
+ if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
1007
+ const result = args[1] ?? args[0].records ?? [];
1008
+ return new Array(...result);
1009
+ }
1010
+ return new Array(...args);
1011
+ }
995
1012
  async nextPage(size, offset) {
996
1013
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
997
1014
  return new _RecordArray(newPage);