@xata.io/client 0.22.0 → 0.22.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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @xata.io/client@0.22.0 add-version /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.22.1 add-version /home/runner/work/client-ts/client-ts/packages/client
3
3
  > node ../../scripts/add-version-file.mjs
4
4
 
@@ -1,5 +1,5 @@
1
1
 
2
- > @xata.io/client@0.22.0 build /home/runner/work/client-ts/client-ts/packages/client
2
+ > @xata.io/client@0.22.1 build /home/runner/work/client-ts/client-ts/packages/client
3
3
  > rimraf dist && rollup -c
4
4
 
5
5
  
@@ -7,7 +7,7 @@
7
7
  created dist/index.cjs in 1s
8
8
  
9
9
  src/index.ts → dist/index.mjs...
10
- created dist/index.mjs in 814ms
10
+ created dist/index.mjs in 947ms
11
11
  
12
12
  src/index.ts → dist/index.d.ts...
13
- created dist/index.d.ts in 6.5s
13
+ created dist/index.d.ts in 6.6s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.22.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#885](https://github.com/xataio/client-ts/pull/885) [`4cafde72`](https://github.com/xataio/client-ts/commit/4cafde728e4e9e5e83812d475d9980397ae78362) Thanks [@SferaDev](https://github.com/SferaDev)! - Update body of compareBranchSchemas
8
+
9
+ - [#890](https://github.com/xataio/client-ts/pull/890) [`639710a5`](https://github.com/xataio/client-ts/commit/639710a52132f260bf3a26560a21ae2193abb71d) Thanks [@SferaDev](https://github.com/SferaDev)! - Expose consistency settings in summarize
10
+
3
11
  ## 0.22.0
4
12
 
5
13
  ### Minor Changes
package/README.md CHANGED
@@ -4,277 +4,4 @@ The Xata SDK supports typescript definitions for your Xata database schema. It a
4
4
 
5
5
  It has zero dependencies and runs in Node.js, V8, Deno and Bun.
6
6
 
7
- ## Installation
8
-
9
- See our [docs](https://xata.io/docs/sdk/typescript#installation) to get started using the Xata SDK.
10
-
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
- - [Installation](#installation)
18
- - [Usage](#usage)
19
- - [Schema-generated Client](#schema-generated-client)
20
- - [Schema-less Client](#schema-less-client)
21
- - [API Design](#api-design)
22
- - [Creating Records](#creating-records)
23
- - [Query a Single Record by its ID](#query-a-single-record-by-its-id)
24
- - [Querying Multiple Records](#querying-multiple-records)
25
- - [Updating Records](#updating-records)
26
- - [Deleting Records](#deleting-records)
27
- - [API Client](#api-client)
28
- - [Deno support](#deno-support)
29
-
30
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
31
-
32
- ## Manual Installation
33
-
34
- ```bash
35
- npm install @xata.io/client
36
- ```
37
-
38
- ## Usage
39
-
40
- There are three ways to use the SDK:
41
-
42
- - **Schema-generated Client**: SDK to create/read/update/delete records in a given database following a schema file (with type-safety).
43
- - **Schema-less Client**: SDK to create/read/update/delete records in any database without schema validation (with partial type-safety).
44
- - **API Client**: SDK to interact with the whole Xata API and all its endpoints.
45
-
46
- ### Schema-generated Client
47
-
48
- 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).
49
-
50
- To run it (and assuming you have configured the project with `xata init`):
51
-
52
- ```bash
53
- xata codegen
54
- ```
55
-
56
- In a TypeScript file, start using the generated code like this:
57
-
58
- ```ts
59
- import { XataClient } from './xata'; // or wherever you chose to generate the client
60
-
61
- const xata = new XataClient();
62
- ```
63
-
64
- The import above will differ if you chose to generate the code in a different location.
65
-
66
- 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.
67
-
68
- 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).
69
-
70
- ```ts
71
- interface User extends Identifiable {
72
- email?: string | null;
73
- }
74
-
75
- type UserRecord = User & XataRecord;
76
-
77
- async function initializeDatabase(admin: User): Promise<UserRecord> {
78
- return xata.db.users.create(admin);
79
- }
80
-
81
- const admin = await initializeDatabase({ email: 'admin@example.com' });
82
- await admin.update({ email: 'admin@foo.bar' });
83
- await admin.delete();
84
- ```
85
-
86
- You will learn more about the available operations below, under the [`API Design`](#api-design) section.
87
-
88
- ### Schema-less Client
89
-
90
- If you don't have a schema file, or you are building a generic way to interact with Xata, you can use the `BaseClient` class without schema validation.
91
-
92
- ```ts
93
- import { BaseClient } from '@xata.io/client';
94
-
95
- const xata = new BaseClient({
96
- branch: 'branchname',
97
- apiKey: 'xau_1234abcdef',
98
- fetch: fetchImplementation // Required if your runtime doesn't provide a global `fetch` function.
99
- });
100
- ```
101
-
102
- It works the same way as the code-generated `XataClient` but doesn't provide type-safety for your model.
103
-
104
- You can read more on the methods available below, in the next section.
105
-
106
- ### API Design
107
-
108
- 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]`.
109
-
110
- 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.
111
-
112
- #### Creating Records
113
-
114
- Invoke the `create()` method in the repository. Example:
115
-
116
- ```ts
117
- const user = await xata.db.users.create({
118
- fullName: 'John Smith'
119
- });
120
- ```
121
-
122
- If you want to create a record with a specific ID, you can provide the id as parameter to the `create()` method.
123
-
124
- ```ts
125
- const user = await xata.db.users.create('user_admin', {
126
- fullName: 'John Smith'
127
- });
128
- ```
129
-
130
- And if you want to create or update a record with a specific ID, you can invoke `createOrUpdate()` with an id parameter.
131
-
132
- ```ts
133
- const user = await xata.db.users.createOrUpdate('user_admin', {
134
- fullName: 'John Smith'
135
- });
136
- ```
137
-
138
- #### Query a Single Record by its ID
139
-
140
- ```ts
141
- // `user` will be null if the record cannot be found
142
- const user = await xata.db.users.read('rec_1234abcdef');
143
- ```
144
-
145
- #### Querying Multiple Records
146
-
147
- ```ts
148
- // Query records selecting all fields.
149
- const page = await xata.db.users.select().getPaginated();
150
- const user = await xata.db.users.select().getFirst();
151
-
152
- // You can also use `xata.db.users` directly, since it's an immutable Query too!
153
- const page = await xata.db.users.getPaginated();
154
- const user = await xata.db.users.getFirst();
155
-
156
- // Query records selecting just one or more fields
157
- const page = await xata.db.users.select('email', 'profile').getPaginated();
158
-
159
- // Apply constraints
160
- const page = await xata.db.users.filter('email', 'foo@example.com').getPaginated();
161
-
162
- // Sorting
163
- const page = await xata.db.users.sort('full_name', 'asc').getPaginated();
164
- ```
165
-
166
- 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()`.
167
-
168
- To learn the differences between these methods, see the [reference](https://docs.xata.io/sdk/reference#query).
169
-
170
- ```ts
171
- // Operators that combine multiple conditions can be deconstructed
172
- const { filter, any, all, not, sort } = xata.db.users;
173
- const query = filter('email', 'foo@example.com');
174
-
175
- // Single-column operators are imported directly from the package
176
- import { gt, includes, startsWith } from '@xata.io/client';
177
- filter('email', startsWith('username')).not(filter('created_at', gt(somePastDate)));
178
-
179
- // Queries are immutable objects. This is useful to derive queries from other queries
180
- const admins = filter('admin', true);
181
- const spaniardsAdmins = admins.filter('country', 'Spain');
182
- await admins.getAll(); // still returns all admins
183
-
184
- // Finally fetch the results of the query
185
- const users = await query.getAll();
186
- const firstUser = await query.getFirst();
187
- ```
188
-
189
- The `getPaginated()` method will return a `Page` object. It's a wrapper that internally uses cursor based pagination.
190
-
191
- ```ts
192
- page.records; // Array of records
193
- page.hasNextPage(); // Boolean
194
-
195
- const nextPage = await page.nextPage(); // Page object
196
- const previousPage = await page.previousPage(); // Page object
197
- const startPage = await page.startPage(); // Page object
198
- const endPage = await page.endPage(); // Page object
199
- ```
200
-
201
- 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:
202
-
203
- ```ts
204
- for await (const record of xata.db.users) {
205
- console.log(record);
206
- }
207
-
208
- for await (const record of xata.db.users.filter('team.id', teamId)) {
209
- console.log(record);
210
- }
211
-
212
- for await (const records of xata.db.users.getIterator({ batchSize: 100 })) {
213
- console.log(records);
214
- }
215
- ```
216
-
217
- #### Updating Records
218
-
219
- Updating a record leaves the existing object unchanged, but returns a new object with the updated values.
220
-
221
- ```ts
222
- // Using an existing object
223
- const updatedUser = await user.update({
224
- fullName: 'John Smith Jr.'
225
- });
226
-
227
- // Using a record id
228
- const updatedUser = await xata.db.users.update('rec_1234abcdef', {
229
- fullName: 'John Smith Jr.'
230
- });
231
- ```
232
-
233
- #### Deleting Records
234
-
235
- ```ts
236
- // Using an existing object
237
- await user.delete();
238
-
239
- // Using a record id
240
- await xata.db.users.delete('rec_1234abcdef');
241
- ```
242
-
243
- ### API Client
244
-
245
- 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...
246
-
247
- To communicate with the SDK we provide a constructor called `XataApiClient` that accepts an API token and an optional fetch implementation method.
248
-
249
- ```ts
250
- const api = new XataApiClient({ apiKey: process.env.XATA_API_KEY });
251
- ```
252
-
253
- Once you have initialized the API client, the operations are organized following the same hiearchy as in the [official documentation](https://docs.xata.io). You have different namespaces for each entity (ie. `workspaces`, `databases`, `tables`, `branches`, `users`, `records`...).
254
-
255
- ```ts
256
- const { id: workspace } = await api.workspaces.createWorkspace({ name: 'example' });
257
- const { databaseName } = await api.database.createDatabase(workspace, 'database', { region: 'eu-west-1' });
258
-
259
- await api.branches.createBranch(workspace, databaseName, 'branch');
260
- await api.tables.createTable(workspace, databaseName, 'branch', 'table');
261
- await api.tables.setTableSchema(workspace, databaseName, 'branch', 'table', {
262
- columns: [{ name: 'email', type: 'string' }]
263
- });
264
-
265
- const { id: recordId } = await api.records.insertRecord(workspace, databaseName, 'branch', 'table', {
266
- email: 'example@foo.bar'
267
- });
268
-
269
- const record = await api.records.getRecord(workspace, databaseName, 'branch', 'table', recordId);
270
-
271
- await api.workspaces.deleteWorkspace(workspace);
272
- ```
273
-
274
- ## Deno support
275
-
276
- 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:
277
-
278
- ```ts
279
- import { buildClient, BaseClientOptions, XataRecord } from 'https://deno.land/x/xata/mod.ts';
280
- ```
7
+ You can find the SDK documentation [here](https://xata.io/docs/typescript-client/overview).
package/dist/index.cjs CHANGED
@@ -302,7 +302,7 @@ function generateUUID() {
302
302
  });
303
303
  }
304
304
 
305
- const VERSION = "0.22.0";
305
+ const VERSION = "0.22.1";
306
306
 
307
307
  class ErrorWithCause extends Error {
308
308
  constructor(message, options) {
@@ -396,6 +396,7 @@ async function fetch$1({
396
396
  clientID,
397
397
  sessionID,
398
398
  clientName,
399
+ xataAgentExtra,
399
400
  fetchOptions = {}
400
401
  }) {
401
402
  pool.setFetch(fetchImpl);
@@ -412,7 +413,8 @@ async function fetch$1({
412
413
  const xataAgent = compact([
413
414
  ["client", "TS_SDK"],
414
415
  ["version", VERSION],
415
- isDefined(clientName) ? ["service", clientName] : void 0
416
+ isDefined(clientName) ? ["service", clientName] : void 0,
417
+ ...Object.entries(xataAgentExtra ?? {})
416
418
  ]).map(([key, value]) => `${key}=${value}`).join("; ");
417
419
  const headers = {
418
420
  "Accept-Encoding": "identity",
@@ -769,6 +771,9 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
769
771
  });
770
772
  const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
771
773
  const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
774
+ const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
775
+ const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
776
+ const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
772
777
  const listRegions = (variables, signal) => controlPlaneFetch({
773
778
  url: "/workspaces/{workspaceId}/regions",
774
779
  method: "get",
@@ -801,6 +806,9 @@ const operationsByTag$1 = {
801
806
  deleteDatabase,
802
807
  getDatabaseMetadata,
803
808
  updateDatabaseMetadata,
809
+ getDatabaseGithubSettings,
810
+ updateDatabaseGithubSettings,
811
+ deleteDatabaseGithubSettings,
804
812
  listRegions
805
813
  }
806
814
  };
@@ -845,7 +853,8 @@ function parseWorkspacesUrlParts(url) {
845
853
  return null;
846
854
  const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
847
855
  const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
848
- const match = url.match(regex) || url.match(regexStaging);
856
+ const regexDev = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xata\.tech.*/;
857
+ const match = url.match(regex) || url.match(regexStaging) || url.match(regexDev);
849
858
  if (!match)
850
859
  return null;
851
860
  return { workspace: match[1], region: match[2] };
@@ -888,6 +897,7 @@ class XataApiClient {
888
897
  apiKey,
889
898
  trace,
890
899
  clientName: options.clientName,
900
+ xataAgentExtra: options.xataAgentExtra,
891
901
  clientID
892
902
  });
893
903
  }
@@ -1763,11 +1773,13 @@ class MigrationsApi {
1763
1773
  region,
1764
1774
  database,
1765
1775
  branch,
1766
- schema
1776
+ schema,
1777
+ schemaOperations,
1778
+ branchOperations
1767
1779
  }) {
1768
1780
  return operationsByTag.migrations.compareBranchWithUserSchema({
1769
1781
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1770
- body: { schema },
1782
+ body: { schema, schemaOperations, branchOperations },
1771
1783
  ...this.extraProps
1772
1784
  });
1773
1785
  }
@@ -1777,11 +1789,12 @@ class MigrationsApi {
1777
1789
  database,
1778
1790
  branch,
1779
1791
  compare,
1780
- schema
1792
+ sourceBranchOperations,
1793
+ targetBranchOperations
1781
1794
  }) {
1782
1795
  return operationsByTag.migrations.compareBranchSchemas({
1783
1796
  pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1784
- body: { schema },
1797
+ body: { sourceBranchOperations, targetBranchOperations },
1785
1798
  ...this.extraProps
1786
1799
  });
1787
1800
  }
@@ -1875,6 +1888,35 @@ class DatabaseApi {
1875
1888
  ...this.extraProps
1876
1889
  });
1877
1890
  }
1891
+ getDatabaseGithubSettings({
1892
+ workspace,
1893
+ database
1894
+ }) {
1895
+ return operationsByTag.databases.getDatabaseGithubSettings({
1896
+ pathParams: { workspaceId: workspace, dbName: database },
1897
+ ...this.extraProps
1898
+ });
1899
+ }
1900
+ updateDatabaseGithubSettings({
1901
+ workspace,
1902
+ database,
1903
+ settings
1904
+ }) {
1905
+ return operationsByTag.databases.updateDatabaseGithubSettings({
1906
+ pathParams: { workspaceId: workspace, dbName: database },
1907
+ body: settings,
1908
+ ...this.extraProps
1909
+ });
1910
+ }
1911
+ deleteDatabaseGithubSettings({
1912
+ workspace,
1913
+ database
1914
+ }) {
1915
+ return operationsByTag.databases.deleteDatabaseGithubSettings({
1916
+ pathParams: { workspaceId: workspace, dbName: database },
1917
+ ...this.extraProps
1918
+ });
1919
+ }
1878
1920
  listRegions({ workspace }) {
1879
1921
  return operationsByTag.databases.listRegions({
1880
1922
  pathParams: { workspaceId: workspace },
@@ -3240,7 +3282,8 @@ async function resolveXataBranch(gitBranch, options) {
3240
3282
  pathParams: { dbName, workspace, region },
3241
3283
  queryParams: { gitBranch, fallbackBranch },
3242
3284
  trace: defaultTrace,
3243
- clientName: options?.clientName
3285
+ clientName: options?.clientName,
3286
+ xataAgentExtra: options?.xataAgentExtra
3244
3287
  });
3245
3288
  return branch;
3246
3289
  }
@@ -3360,11 +3403,13 @@ const buildClient = (plugins) => {
3360
3403
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3361
3404
  const trace = options?.trace ?? defaultTrace;
3362
3405
  const clientName = options?.clientName;
3406
+ const xataAgentExtra = options?.xataAgentExtra;
3363
3407
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
3364
3408
  apiKey,
3365
3409
  databaseURL,
3366
3410
  fetchImpl: options?.fetch,
3367
- clientName: options?.clientName
3411
+ clientName,
3412
+ xataAgentExtra
3368
3413
  });
3369
3414
  if (!apiKey) {
3370
3415
  throw new Error("Option apiKey is required");
@@ -3372,7 +3417,18 @@ const buildClient = (plugins) => {
3372
3417
  if (!databaseURL) {
3373
3418
  throw new Error("Option databaseURL is required");
3374
3419
  }
3375
- return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser, clientName };
3420
+ return {
3421
+ fetch,
3422
+ databaseURL,
3423
+ apiKey,
3424
+ branch,
3425
+ cache,
3426
+ trace,
3427
+ clientID: generateUUID(),
3428
+ enableBrowser,
3429
+ clientName,
3430
+ xataAgentExtra
3431
+ };
3376
3432
  }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
3377
3433
  fetch,
3378
3434
  apiKey,
@@ -3380,7 +3436,8 @@ const buildClient = (plugins) => {
3380
3436
  branch,
3381
3437
  trace,
3382
3438
  clientID,
3383
- clientName
3439
+ clientName,
3440
+ xataAgentExtra
3384
3441
  }) {
3385
3442
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
3386
3443
  if (!branchValue)
@@ -3396,7 +3453,8 @@ const buildClient = (plugins) => {
3396
3453
  },
3397
3454
  trace,
3398
3455
  clientID,
3399
- clientName
3456
+ clientName,
3457
+ xataAgentExtra
3400
3458
  };
3401
3459
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
3402
3460
  if (__privateGet(this, _branch))
@@ -3551,6 +3609,7 @@ exports.createWorkspace = createWorkspace;
3551
3609
  exports.deleteBranch = deleteBranch;
3552
3610
  exports.deleteColumn = deleteColumn;
3553
3611
  exports.deleteDatabase = deleteDatabase;
3612
+ exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
3554
3613
  exports.deleteRecord = deleteRecord;
3555
3614
  exports.deleteTable = deleteTable;
3556
3615
  exports.deleteUser = deleteUser;
@@ -3573,6 +3632,7 @@ exports.getBranchStats = getBranchStats;
3573
3632
  exports.getColumn = getColumn;
3574
3633
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
3575
3634
  exports.getCurrentBranchName = getCurrentBranchName;
3635
+ exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
3576
3636
  exports.getDatabaseList = getDatabaseList;
3577
3637
  exports.getDatabaseMetadata = getDatabaseMetadata;
3578
3638
  exports.getDatabaseURL = getDatabaseURL;
@@ -3637,6 +3697,7 @@ exports.summarizeTable = summarizeTable;
3637
3697
  exports.updateBranchMetadata = updateBranchMetadata;
3638
3698
  exports.updateBranchSchema = updateBranchSchema;
3639
3699
  exports.updateColumn = updateColumn;
3700
+ exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
3640
3701
  exports.updateDatabaseMetadata = updateDatabaseMetadata;
3641
3702
  exports.updateMigrationRequest = updateMigrationRequest;
3642
3703
  exports.updateRecordWithID = updateRecordWithID;