@xata.io/client 0.0.0-alpha.vf3081bb → 0.0.0-alpha.vf3111df
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 +98 -0
- package/README.md +43 -35
- package/Usage.md +449 -0
- package/dist/index.cjs +645 -380
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +648 -160
- package/dist/index.mjs +622 -381
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,103 @@
|
|
1
1
|
# @xata.io/client
|
2
2
|
|
3
|
+
## 0.16.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#541](https://github.com/xataio/client-ts/pull/541) [`c74467c`](https://github.com/xataio/client-ts/commit/c74467caeff4e3d60d0981a173b462e970c6c1fc) Thanks [@SferaDev](https://github.com/SferaDev)! - Add tracing with open telemetry
|
8
|
+
|
9
|
+
* [#534](https://github.com/xataio/client-ts/pull/534) [`efc09b4`](https://github.com/xataio/client-ts/commit/efc09b420a25253b428662c2eec40ff3bc36ce79) Thanks [@SferaDev](https://github.com/SferaDev)! - Make sort direction optional
|
10
|
+
|
11
|
+
## 0.16.1
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- [#531](https://github.com/xataio/client-ts/pull/531) [`e33d8fb`](https://github.com/xataio/client-ts/commit/e33d8fbca264d3ab1597ed698d5e79484dcba8a3) Thanks [@xata-bot](https://github.com/xata-bot)! - Add new method to list database metadata in the API client
|
16
|
+
|
17
|
+
* [#524](https://github.com/xataio/client-ts/pull/524) [`a3b1044`](https://github.com/xataio/client-ts/commit/a3b1044038c4ae73b4aacaa112818e69b7d380e1) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose internal config information
|
18
|
+
|
19
|
+
- [#525](https://github.com/xataio/client-ts/pull/525) [`5f0f2c2`](https://github.com/xataio/client-ts/commit/5f0f2c2bb42da360e810f0a61ce360f8f8b07a04) Thanks [@xata-bot](https://github.com/xata-bot)! - Update dependencies
|
20
|
+
|
21
|
+
## 0.16.0
|
22
|
+
|
23
|
+
### Minor Changes
|
24
|
+
|
25
|
+
- [#485](https://github.com/xataio/client-ts/pull/485) [`a9cbb26`](https://github.com/xataio/client-ts/commit/a9cbb263fbca47cb91a827db252d95a5bb4079a6) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow selecting columns with record operations
|
26
|
+
|
27
|
+
* [#485](https://github.com/xataio/client-ts/pull/485) [`7e04a3d`](https://github.com/xataio/client-ts/commit/7e04a3d1c51958a44f687a0036ead8bb3f5a2dfb) Thanks [@SferaDev](https://github.com/SferaDev)! - Remove record cache
|
28
|
+
|
29
|
+
### Patch Changes
|
30
|
+
|
31
|
+
- [#503](https://github.com/xataio/client-ts/pull/503) [`6a96ea5`](https://github.com/xataio/client-ts/commit/6a96ea5da4c5b7ca9a99b57ebbce8d6766b5d4d8) Thanks [@xata-bot](https://github.com/xata-bot)! - Update API response types for create of tables and branches
|
32
|
+
|
33
|
+
* [#421](https://github.com/xataio/client-ts/pull/421) [`43f2560`](https://github.com/xataio/client-ts/commit/43f25605ddd0d2fd514a1542a14389d28955c500) Thanks [@SferaDev](https://github.com/SferaDev)! - Add search boosters and allow prefix search
|
34
|
+
|
35
|
+
## 0.15.0
|
36
|
+
|
37
|
+
### Patch Changes
|
38
|
+
|
39
|
+
- [#496](https://github.com/xataio/client-ts/pull/496) [`e923d11`](https://github.com/xataio/client-ts/commit/e923d11fe357519dc4ca3ae722670e6e70ccd1c6) Thanks [@gimenete](https://github.com/gimenete)! - Ignore git output in Xata client
|
40
|
+
|
41
|
+
* [#481](https://github.com/xataio/client-ts/pull/481) [`599b52c`](https://github.com/xataio/client-ts/commit/599b52c3090222eedef85d1ad1e907874cd3e801) Thanks [@xata-bot](https://github.com/xata-bot)! - Add updateWorkspaceMemberInvite API method
|
42
|
+
|
43
|
+
## 0.14.0
|
44
|
+
|
45
|
+
### Minor Changes
|
46
|
+
|
47
|
+
- [#409](https://github.com/xataio/client-ts/pull/409) [`8812380`](https://github.com/xataio/client-ts/commit/881238062b5eeac2dc8b9ba156720e0acc22c5c5) Thanks [@SferaDev](https://github.com/SferaDev)! - Infer types from schema in codegen
|
48
|
+
|
49
|
+
* [#457](https://github.com/xataio/client-ts/pull/457) [`0584a5b`](https://github.com/xataio/client-ts/commit/0584a5b207a21dbc36ddc1d44b276f1d5bb60dc5) Thanks [@SferaDev](https://github.com/SferaDev)! - Load env variables so that code analysis detects them
|
50
|
+
|
51
|
+
- [#469](https://github.com/xataio/client-ts/pull/469) [`8d8a912`](https://github.com/xataio/client-ts/commit/8d8a9129e36452266c4c12fe35b421f66e572498) Thanks [@gimenete](https://github.com/gimenete)! - Treat branch name specified with third party env variables as git branches in the resolution algorithm
|
52
|
+
|
53
|
+
### Patch Changes
|
54
|
+
|
55
|
+
- [#462](https://github.com/xataio/client-ts/pull/462) [`7547b7e`](https://github.com/xataio/client-ts/commit/7547b7edbc9a95c6620784cc5348316f27502c73) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix bug with RecordArray.map
|
56
|
+
|
57
|
+
* [#472](https://github.com/xataio/client-ts/pull/472) [`e99010c`](https://github.com/xataio/client-ts/commit/e99010c9ab9d355abadcfbcf98b5a3fcc80c307a) Thanks [@SferaDev](https://github.com/SferaDev)! - Add id as entity property
|
58
|
+
|
59
|
+
- [#443](https://github.com/xataio/client-ts/pull/443) [`c4be404`](https://github.com/xataio/client-ts/commit/c4be404a3ecb34df9b1ef4501c92f5bdc221f19c) Thanks [@SferaDev](https://github.com/SferaDev)! - Improve performance with `create([])` operation
|
60
|
+
|
61
|
+
## 0.13.4
|
62
|
+
|
63
|
+
### Patch Changes
|
64
|
+
|
65
|
+
- [#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
|
66
|
+
|
67
|
+
## 0.13.3
|
68
|
+
|
69
|
+
### Patch Changes
|
70
|
+
|
71
|
+
- [#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
|
72
|
+
|
73
|
+
## 0.13.2
|
74
|
+
|
75
|
+
### Patch Changes
|
76
|
+
|
77
|
+
- [#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
|
78
|
+
|
79
|
+
* [#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
|
80
|
+
|
81
|
+
- [#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
|
82
|
+
|
83
|
+
## 0.13.1
|
84
|
+
|
85
|
+
### Patch Changes
|
86
|
+
|
87
|
+
- [#417](https://github.com/xataio/client-ts/pull/417) [`86a14ec`](https://github.com/xataio/client-ts/commit/86a14eccbca94f572252327c9c0306577a1c3ebd) Thanks [@SferaDev](https://github.com/SferaDev)! - Update User-Agent
|
88
|
+
|
89
|
+
* [#422](https://github.com/xataio/client-ts/pull/422) [`2896418`](https://github.com/xataio/client-ts/commit/289641844e5b2752197dbbbf3a93ef6068b684e4) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow sending link as string id
|
90
|
+
|
91
|
+
- [#420](https://github.com/xataio/client-ts/pull/420) [`301b21f`](https://github.com/xataio/client-ts/commit/301b21f4784f755a8694ca21a0f2fd48e1b16df4) Thanks [@SferaDev](https://github.com/SferaDev)! - Exclude date internal columns in selection
|
92
|
+
|
93
|
+
* [#399](https://github.com/xataio/client-ts/pull/399) [`dd4b2ef`](https://github.com/xataio/client-ts/commit/dd4b2effed2251ac8afbfb2909c21a9deb35bef1) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow create many objects mixed some with ids others without
|
94
|
+
|
95
|
+
- [#425](https://github.com/xataio/client-ts/pull/425) [`00279ff`](https://github.com/xataio/client-ts/commit/00279ff985793020237f8098cba97dfec7738f82) Thanks [@SferaDev](https://github.com/SferaDev)! - Do not send falsy values to query string
|
96
|
+
|
97
|
+
* [#399](https://github.com/xataio/client-ts/pull/399) [`8e66998`](https://github.com/xataio/client-ts/commit/8e6699867a1aa1968d12db4ced80c13d4b951f88) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow passing identifiable objects to `read()` operations
|
98
|
+
|
99
|
+
- [#425](https://github.com/xataio/client-ts/pull/425) [`8a4e019`](https://github.com/xataio/client-ts/commit/8a4e019031e678d946cf9dfb0e4803906fad9b5f) Thanks [@SferaDev](https://github.com/SferaDev)! - Add fallback branch to `api.databases.resolveBranch`
|
100
|
+
|
3
101
|
## 0.13.0
|
4
102
|
|
5
103
|
### Minor 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
|
-
|
5
|
+
## Table of Contents
|
6
6
|
|
7
|
-
|
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](
|
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
|
57
|
+
The import above will differ if you chose to generate the code in a different location.
|
42
58
|
|
43
|
-
The `fetch`
|
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,
|
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
|
-
|
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
|
-
|
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
|
-
|
138
|
+
#### Querying Multiple Objects
|
123
139
|
|
124
140
|
```ts
|
125
141
|
// Query objects selecting all fields.
|
@@ -140,7 +156,9 @@ 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
|
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()`.
|
160
|
+
|
161
|
+
To learn the differences between these methods, see the [reference](https://docs.xata.io/sdk/reference#query).
|
144
162
|
|
145
163
|
```ts
|
146
164
|
// Operators that combine multiple conditions can be deconstructed
|
@@ -173,7 +191,7 @@ const firstPage = await page.firstPage(); // Page object
|
|
173
191
|
const lastPage = await page.lastPage(); // Page object
|
174
192
|
```
|
175
193
|
|
176
|
-
If you want to use an iterator, both the Repository and the Query classes implement an AsyncIterable
|
194
|
+
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
195
|
|
178
196
|
```ts
|
179
197
|
for await (const record of xata.db.users) {
|
@@ -189,7 +207,7 @@ for await (const records of xata.db.users.getIterator({ batchSize: 100 })) {
|
|
189
207
|
}
|
190
208
|
```
|
191
209
|
|
192
|
-
|
210
|
+
#### Updating Objects
|
193
211
|
|
194
212
|
Updating an object leaves the existing instance unchanged, but returns a new object with the updated values.
|
195
213
|
|
@@ -205,7 +223,7 @@ const updatedUser = await xata.db.users.update('rec_1234abcdef', {
|
|
205
223
|
});
|
206
224
|
```
|
207
225
|
|
208
|
-
|
226
|
+
#### Deleting Objects
|
209
227
|
|
210
228
|
```ts
|
211
229
|
// Using an existing object
|
@@ -217,7 +235,7 @@ await xata.db.users.delete('rec_1234abcdef');
|
|
217
235
|
|
218
236
|
### API Client
|
219
237
|
|
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...
|
238
|
+
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
239
|
|
222
240
|
To communicate with the SDK we provide a constructor called `XataApiClient` that accepts an API token and an optional fetch implementation method.
|
223
241
|
|
@@ -229,7 +247,6 @@ Once you have initialized the API client, the operations are organized following
|
|
229
247
|
|
230
248
|
```ts
|
231
249
|
const { id: workspace } = await client.workspaces.createWorkspace({ name: 'example', slug: 'example' });
|
232
|
-
|
233
250
|
const { databaseName } = await client.databases.createDatabase(workspace, 'database');
|
234
251
|
|
235
252
|
await client.branches.createBranch(workspace, databaseName, 'branch');
|
@@ -249,17 +266,8 @@ await client.workspaces.deleteWorkspace(workspace);
|
|
249
266
|
|
250
267
|
## Deno support
|
251
268
|
|
252
|
-
|
253
|
-
|
254
|
-
However you can already use it with your preferred node CDN with the following import in the auto-generated `xata.ts` file:
|
269
|
+
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
270
|
|
256
271
|
```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';
|
272
|
+
import { buildClient, BaseClientOptions, XataRecord } from 'https://deno.land/x/xata/mod.ts';
|
265
273
|
```
|