@xata.io/client 0.10.1 → 0.12.0

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,45 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#376](https://github.com/xataio/client-ts/pull/376) [`db3c88e`](https://github.com/xataio/client-ts/commit/db3c88e1f2bee6d308afb8d6e95b7c090a87e7a7) Thanks [@SferaDev](https://github.com/SferaDev)! - Hide xata object and expose getMetadata method
8
+
9
+ ### Patch Changes
10
+
11
+ - [#364](https://github.com/xataio/client-ts/pull/364) [`1cde95f`](https://github.com/xataio/client-ts/commit/1cde95f05a6b9fbf0564ea05400140f0cef41a3a) Thanks [@SferaDev](https://github.com/SferaDev)! - Add peer dep of TS 4.5+
12
+
13
+ * [#362](https://github.com/xataio/client-ts/pull/362) [`57bf0e2`](https://github.com/xataio/client-ts/commit/57bf0e2e049ed0498683ff42d287983f295342b7) Thanks [@SferaDev](https://github.com/SferaDev)! - Do not show error if date is not defined
14
+
15
+ ## 0.11.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#322](https://github.com/xataio/client-ts/pull/322) [`bc64c28`](https://github.com/xataio/client-ts/commit/bc64c28fbfbb000c7190ac8092e2ef6a261df86f) Thanks [@SferaDev](https://github.com/SferaDev)! - Add filter support for cross-table search operations
20
+
21
+ ### Patch Changes
22
+
23
+ - [#327](https://github.com/xataio/client-ts/pull/327) [`505257c`](https://github.com/xataio/client-ts/commit/505257c0c42ca0c8beaf5c0f638037c576dcc43c) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow reading multiple uids at the same time
24
+
25
+ * [#346](https://github.com/xataio/client-ts/pull/346) [`ff7e5c6`](https://github.com/xataio/client-ts/commit/ff7e5c6f211913196d8c28600d7a7675ed261688) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix compat with TS 4.8
26
+
27
+ - [#345](https://github.com/xataio/client-ts/pull/345) [`bf64cb8`](https://github.com/xataio/client-ts/commit/bf64cb885d55a0271e966314384324f02ded084e) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix bug with nullable record filters inferred as never
28
+
29
+ * [#334](https://github.com/xataio/client-ts/pull/334) [`ce07601`](https://github.com/xataio/client-ts/commit/ce07601e4ddf9f75e20249d479dc04a63795ca96) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for TS 4.5
30
+
31
+ - [#325](https://github.com/xataio/client-ts/pull/325) [`12f1ce3`](https://github.com/xataio/client-ts/commit/12f1ce362f6cda27dfdb3afab0800282bddc8b5e) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix offset errors with operations that affect many rows
32
+
33
+ * [#345](https://github.com/xataio/client-ts/pull/345) [`a73a2a2`](https://github.com/xataio/client-ts/commit/a73a2a2014c44cf88eaef42196ba1dba9d516b4a) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix issue with Filter<T> not narrowing down type on object properties
34
+
35
+ ## 0.10.2
36
+
37
+ ### Patch Changes
38
+
39
+ - [#312](https://github.com/xataio/client-ts/pull/312) [`0edf1af`](https://github.com/xataio/client-ts/commit/0edf1af2205c4761d53a02c74ddaab3168d69775) Thanks [@SferaDev](https://github.com/SferaDev)! - Add filtering to search by table
40
+
41
+ * [#312](https://github.com/xataio/client-ts/pull/312) [`66ad7cc`](https://github.com/xataio/client-ts/commit/66ad7cc0365046c5d039c37117feac04428d8373) Thanks [@SferaDev](https://github.com/SferaDev)! - Add new API method for searching in a given table
42
+
3
43
  ## 0.10.1
4
44
 
5
45
  ### Patch Changes
package/README.md CHANGED
@@ -1 +1,258 @@
1
- Visit https://github.com/xataio/client-ts for more information.
1
+ # Xata SDK for TypeScript and JavaScript
2
+
3
+ This SDK has zero dependencies, so it can be used in many JavaScript runtimes including Node.js, Cloudflare workers, Deno, Electron, etc.
4
+
5
+ It also works in browsers for the same reason. But this is strongly discouraged because the API token would be leaked.
6
+
7
+ ## Installing
8
+
9
+ ```bash
10
+ npm install @xata.io/client
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ There are three ways to use the SDK:
16
+
17
+ - **Schema-generated Client**: SDK to create/read/update/delete records in a given database following a schema file (with type-safety).
18
+ - **Schema-less Client**: SDK to create/read/update/delete records in any database without schema validation (with partial type-safety).
19
+ - **API Client**: SDK to interact with the whole Xata API and all its endpoints.
20
+
21
+ ### Schema-generated Client
22
+
23
+ To use the schema-generated client, you need to run the code generator utility that comes with [our CLI](../../cli/README.md).
24
+
25
+ To run it (and assuming you have configured the project with `xata init`):
26
+
27
+ ```bash
28
+ xata codegen
29
+ ```
30
+
31
+ In a TypeScript file start using the generated code:
32
+
33
+ ```ts
34
+ import { XataClient } from './xata';
35
+
36
+ const xata = new XataClient({
37
+ fetch: fetchImplementation // Required if your runtime doesn't provide a global `fetch` function.
38
+ });
39
+ ```
40
+
41
+ The import above will differ if you chose to genreate the code in a different location.
42
+
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.
44
+
45
+ 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
+
47
+ ```ts
48
+ interface User extends Identifiable {
49
+ email?: string | null;
50
+ }
51
+
52
+ type UserRecord = User & XataRecord;
53
+
54
+ async function initializeDatabase(admin: User): Promise<UserRecord> {
55
+ return xata.db.users.create(admin);
56
+ }
57
+
58
+ const admin = await initializeDatabase({ email: 'admin@example.com' });
59
+ await admin.update({ email: 'admin@foo.bar' });
60
+ await admin.delete();
61
+ ```
62
+
63
+ You will learn more about the available operations below, under the `API Design` section.
64
+
65
+ ### Schema-less Client
66
+
67
+ 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.
68
+
69
+ ```ts
70
+ import { BaseClient } from '@xata.io/client';
71
+
72
+ const xata = new BaseClient({
73
+ branch: 'branchname',
74
+ apiKey: 'xau_1234abcdef',
75
+ fetch: fetchImplementation // Required if your runtime doesn't provide a global `fetch` function.
76
+ });
77
+ ```
78
+
79
+ It works the same way as the code-generated `XataClient` but doesn't provide type-safety for your model.
80
+
81
+ You can read more on the methods available below, under the `API Design` section.
82
+
83
+ ### API Design
84
+
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]`.
86
+
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.
88
+
89
+ **Creating objects**
90
+
91
+ Invoke the `create()` method in the repository. Example:
92
+
93
+ ```ts
94
+ const user = await xata.db.users.create({
95
+ fullName: 'John Smith'
96
+ });
97
+ ```
98
+
99
+ If you want to create a record with a specific ID, you can invoke `insert()`.
100
+
101
+ ```ts
102
+ const user = await xata.db.users.insert('user_admin', {
103
+ fullName: 'John Smith'
104
+ });
105
+ ```
106
+
107
+ And if you want to create or insert a record with a specific ID, you can invoke `updateOrInsert()`.
108
+
109
+ ```ts
110
+ const user = await client.db.users.updateOrInsert('user_admin', {
111
+ fullName: 'John Smith'
112
+ });
113
+ ```
114
+
115
+ **Query a single object by its id**
116
+
117
+ ```ts
118
+ // `user` will be null if the object cannot be found
119
+ const user = await xata.db.users.read('rec_1234abcdef');
120
+ ```
121
+
122
+ **Querying multiple objects**
123
+
124
+ ```ts
125
+ // Query objects selecting all fields.
126
+ const users = await xata.db.users.select().getMany();
127
+ const user = await xata.db.users.select().getFirst();
128
+
129
+ // You can also use `xata.db.users` directly, since it's an immutable Query too!
130
+ const users = await xata.db.users.getMany();
131
+ const user = await xata.db.users.getFirst();
132
+
133
+ // Query objects selecting just one or more fields
134
+ const users = await xata.db.users.select('email', 'profile').getMany();
135
+
136
+ // Apply constraints
137
+ const users = await xata.db.users.filter('email', 'foo@example.com').getMany();
138
+
139
+ // Sorting
140
+ const users = await xata.db.users.sort('fullName', 'asc').getMany();
141
+ ```
142
+
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 `getAll()`, `getFirst()`, `getMany()` or `getPaginated()`.
144
+
145
+ ```ts
146
+ // Operators that combine multiple conditions can be deconstructed
147
+ const { filter, any, all, not, sort } = xata.db.users;
148
+ const query = filter('email', 'foo@example.com');
149
+
150
+ // Single-column operators are imported directly from the package
151
+ import { gt, includes, startsWith } from '@xata.io/client';
152
+ filter('email', startsWith('username')).not(filter('created_at', gt(somePastDate)));
153
+
154
+ // Queries are immutable objects. This is useful to derive queries from other queries
155
+ const admins = filter('admin', true);
156
+ const spaniardsAdmins = admins.filter('country', 'Spain');
157
+ await admins.getMany(); // still returns all admins
158
+
159
+ // Finally fetch the results of the query
160
+ const users = await query.getMany();
161
+ const firstUser = await query.getFirst();
162
+
163
+ // Also you can paginate the results
164
+ const page = await query.getPaginated();
165
+ const hasPage2 = page.hasNextPage();
166
+ const page2 = await page.nextPage();
167
+ ```
168
+
169
+ 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:
170
+
171
+ ```ts
172
+ for await (const record of xata.db.users) {
173
+ console.log(record);
174
+ }
175
+
176
+ for await (const record of xata.db.users.filter('team.id', teamId)) {
177
+ console.log(record);
178
+ }
179
+
180
+ for await (const records of xata.db.users.getIterator({ batchSize: 100 })) {
181
+ console.log(records);
182
+ }
183
+ ```
184
+
185
+ **Updating objects**
186
+
187
+ Updating an object leaves the existing instance unchanged, but returns a new object with the updated values.
188
+
189
+ ```ts
190
+ // Using an existing object
191
+ const updatedUser = await user.update({
192
+ fullName: 'John Smith Jr.'
193
+ });
194
+
195
+ // Using an object's id
196
+ const updatedUser = await xata.db.users.update('rec_1234abcdef', {
197
+ fullName: 'John Smith Jr.'
198
+ });
199
+ ```
200
+
201
+ **Deleting objects**
202
+
203
+ ```ts
204
+ // Using an existing object
205
+ await user.delete();
206
+
207
+ // Using an object's id
208
+ await xata.db.users.delete('rec_1234abcdef');
209
+ ```
210
+
211
+ #### Deno support
212
+
213
+ Right now we are still not publishing the client on deno.land or have support for deno in the codegen.
214
+
215
+ However you can already use it with your preferred node CDN with the following import in the auto-generated `xata.ts` file:
216
+
217
+ ```ts
218
+ import {
219
+ BaseClient,
220
+ Query,
221
+ Repository,
222
+ RestRespositoryFactory,
223
+ XataClientOptions,
224
+ XataRecord
225
+ } from 'https://esm.sh/@xata.io/client@<version>/dist/schema?target=deno';
226
+ ```
227
+
228
+ ### API Client
229
+
230
+ 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...
231
+
232
+ To communicate with the SDK we provide a constructor called `XataApiClient` that accepts an API token and an optional fetch implementation method.
233
+
234
+ ```ts
235
+ const api = new XataApiClient({ apiKey: process.env.XATA_API_KEY });
236
+ ```
237
+
238
+ 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`...).
239
+
240
+ ```ts
241
+ const { id: workspace } = await client.workspaces.createWorkspace({ name: 'example', slug: 'example' });
242
+
243
+ const { databaseName } = await client.databases.createDatabase(workspace, 'database');
244
+
245
+ await client.branches.createBranch(workspace, databaseName, 'branch');
246
+ await client.tables.createTable(workspace, databaseName, 'branch', 'table');
247
+ await client.tables.setTableSchema(workspace, databaseName, 'branch', 'table', {
248
+ columns: [{ name: 'email', type: 'string' }]
249
+ });
250
+
251
+ const { id: recordId } = await client.records.insertRecord(workspace, databaseName, 'branch', 'table', {
252
+ email: 'example@foo.bar'
253
+ });
254
+
255
+ const record = await client.records.getRecord(workspace, databaseName, 'branch', 'table', recordId);
256
+
257
+ await client.workspaces.deleteWorkspace(workspace);
258
+ ```
package/dist/index.cjs CHANGED
@@ -11,8 +11,11 @@ function compact(arr) {
11
11
  function isObject(value) {
12
12
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
13
13
  }
14
+ function isDefined(value) {
15
+ return value !== null && value !== void 0;
16
+ }
14
17
  function isString(value) {
15
- return value !== void 0 && value !== null && typeof value === "string";
18
+ return isDefined(value) && typeof value === "string";
16
19
  }
17
20
  function toBase64(value) {
18
21
  try {
@@ -74,7 +77,12 @@ function getFetchImplementation(userFetch) {
74
77
  return fetchImpl;
75
78
  }
76
79
 
77
- class FetcherError extends Error {
80
+ class ErrorWithCause extends Error {
81
+ constructor(message, options) {
82
+ super(message, options);
83
+ }
84
+ }
85
+ class FetcherError extends ErrorWithCause {
78
86
  constructor(status, data) {
79
87
  super(getMessage(data));
80
88
  this.status = status;
@@ -370,6 +378,11 @@ const queryTable = (variables) => fetch$1({
370
378
  method: "post",
371
379
  ...variables
372
380
  });
381
+ const searchTable = (variables) => fetch$1({
382
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
383
+ method: "post",
384
+ ...variables
385
+ });
373
386
  const searchBranch = (variables) => fetch$1({
374
387
  url: "/db/{dbBranchName}/search",
375
388
  method: "post",
@@ -433,6 +446,7 @@ const operationsByTag = {
433
446
  getRecord,
434
447
  bulkInsertTableRecords,
435
448
  queryTable,
449
+ searchTable,
436
450
  searchBranch
437
451
  }
438
452
  };
@@ -888,6 +902,13 @@ class RecordsApi {
888
902
  ...this.extraProps
889
903
  });
890
904
  }
905
+ searchTable(workspace, database, branch, tableName, query) {
906
+ return operationsByTag.records.searchTable({
907
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
908
+ body: query,
909
+ ...this.extraProps
910
+ });
911
+ }
891
912
  searchBranch(workspace, database, branch, query) {
892
913
  return operationsByTag.records.searchBranch({
893
914
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -954,6 +975,9 @@ const PAGINATION_MAX_SIZE = 200;
954
975
  const PAGINATION_DEFAULT_SIZE = 200;
955
976
  const PAGINATION_MAX_OFFSET = 800;
956
977
  const PAGINATION_DEFAULT_OFFSET = 0;
978
+ function isCursorPaginationOptions(options) {
979
+ return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
980
+ }
957
981
 
958
982
  var __accessCheck$5 = (obj, member, msg) => {
959
983
  if (!member.has(obj))
@@ -975,7 +999,7 @@ var __privateSet$4 = (obj, member, value, setter) => {
975
999
  };
976
1000
  var _table$1, _repository, _data;
977
1001
  const _Query = class {
978
- constructor(repository, table, data, parent) {
1002
+ constructor(repository, table, data, rawParent) {
979
1003
  __privateAdd$5(this, _table$1, void 0);
980
1004
  __privateAdd$5(this, _repository, void 0);
981
1005
  __privateAdd$5(this, _data, { filter: {} });
@@ -987,6 +1011,7 @@ const _Query = class {
987
1011
  } else {
988
1012
  __privateSet$4(this, _repository, this);
989
1013
  }
1014
+ const parent = cleanParent(data, rawParent);
990
1015
  __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
991
1016
  __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
992
1017
  __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
@@ -1058,13 +1083,13 @@ const _Query = class {
1058
1083
  }
1059
1084
  async *getIterator(options = {}) {
1060
1085
  const { batchSize = 1 } = options;
1061
- let offset = 0;
1062
- let end = false;
1063
- while (!end) {
1064
- const { records, meta } = await this.getPaginated({ ...options, pagination: { size: batchSize, offset } });
1065
- yield records;
1066
- offset += batchSize;
1067
- end = !meta.page.more;
1086
+ let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
1087
+ let more = page.hasNextPage();
1088
+ yield page.records;
1089
+ while (more) {
1090
+ page = await page.nextPage();
1091
+ more = page.hasNextPage();
1092
+ yield page.records;
1068
1093
  }
1069
1094
  }
1070
1095
  async getMany(options = {}) {
@@ -1106,12 +1131,20 @@ let Query = _Query;
1106
1131
  _table$1 = new WeakMap();
1107
1132
  _repository = new WeakMap();
1108
1133
  _data = new WeakMap();
1134
+ function cleanParent(data, parent) {
1135
+ if (isCursorPaginationOptions(data.pagination)) {
1136
+ return { ...parent, sorting: void 0, filter: void 0 };
1137
+ }
1138
+ return parent;
1139
+ }
1109
1140
 
1110
1141
  function isIdentifiable(x) {
1111
1142
  return isObject(x) && isString(x?.id);
1112
1143
  }
1113
1144
  function isXataRecord(x) {
1114
- return isIdentifiable(x) && typeof x?.xata === "object" && typeof x?.xata?.version === "number";
1145
+ const record = x;
1146
+ const metadata = record?.getMetadata();
1147
+ return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
1115
1148
  }
1116
1149
 
1117
1150
  function isSortFilterString(value) {
@@ -1188,6 +1221,8 @@ class RestRepository extends Query {
1188
1221
  }
1189
1222
  async create(a, b) {
1190
1223
  if (Array.isArray(a)) {
1224
+ if (a.length === 0)
1225
+ return [];
1191
1226
  const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1192
1227
  await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1193
1228
  return records;
@@ -1213,27 +1248,36 @@ class RestRepository extends Query {
1213
1248
  }
1214
1249
  throw new Error("Invalid arguments for create method");
1215
1250
  }
1216
- async read(recordId) {
1217
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1218
- if (cacheRecord)
1219
- return cacheRecord;
1220
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1221
- try {
1222
- const response = await getRecord({
1223
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1224
- ...fetchProps
1225
- });
1226
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1227
- return initObject(this.db, schema, __privateGet$4(this, _table), response);
1228
- } catch (e) {
1229
- if (isObject(e) && e.status === 404) {
1230
- return null;
1251
+ async read(a) {
1252
+ if (Array.isArray(a)) {
1253
+ if (a.length === 0)
1254
+ return [];
1255
+ return this.getAll({ filter: { id: { $any: a } } });
1256
+ }
1257
+ if (isString(a)) {
1258
+ const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, a);
1259
+ if (cacheRecord)
1260
+ return cacheRecord;
1261
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1262
+ try {
1263
+ const response = await getRecord({
1264
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: a },
1265
+ ...fetchProps
1266
+ });
1267
+ const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1268
+ return initObject(this.db, schema, __privateGet$4(this, _table), response);
1269
+ } catch (e) {
1270
+ if (isObject(e) && e.status === 404) {
1271
+ return null;
1272
+ }
1273
+ throw e;
1231
1274
  }
1232
- throw e;
1233
1275
  }
1234
1276
  }
1235
1277
  async update(a, b) {
1236
1278
  if (Array.isArray(a)) {
1279
+ if (a.length === 0)
1280
+ return [];
1237
1281
  if (a.length > 100) {
1238
1282
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1239
1283
  }
@@ -1255,6 +1299,8 @@ class RestRepository extends Query {
1255
1299
  }
1256
1300
  async createOrUpdate(a, b) {
1257
1301
  if (Array.isArray(a)) {
1302
+ if (a.length === 0)
1303
+ return [];
1258
1304
  if (a.length > 100) {
1259
1305
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1260
1306
  }
@@ -1276,6 +1322,8 @@ class RestRepository extends Query {
1276
1322
  }
1277
1323
  async delete(a) {
1278
1324
  if (Array.isArray(a)) {
1325
+ if (a.length === 0)
1326
+ return;
1279
1327
  if (a.length > 100) {
1280
1328
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1281
1329
  }
@@ -1296,9 +1344,14 @@ class RestRepository extends Query {
1296
1344
  }
1297
1345
  async search(query, options = {}) {
1298
1346
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1299
- const { records } = await searchBranch({
1300
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1301
- body: { tables: [__privateGet$4(this, _table)], query, fuzziness: options.fuzziness },
1347
+ const { records } = await searchTable({
1348
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1349
+ body: {
1350
+ query,
1351
+ fuzziness: options.fuzziness,
1352
+ highlight: options.highlight,
1353
+ filter: options.filter
1354
+ },
1302
1355
  ...fetchProps
1303
1356
  });
1304
1357
  const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
@@ -1481,7 +1534,8 @@ const transformObjectLinks = (object) => {
1481
1534
  };
1482
1535
  const initObject = (db, schema, table, object) => {
1483
1536
  const result = {};
1484
- Object.assign(result, object);
1537
+ const { xata, ...rest } = object ?? {};
1538
+ Object.assign(result, rest);
1485
1539
  const { columns } = schema.tables.find(({ name }) => name === table) ?? {};
1486
1540
  if (!columns)
1487
1541
  console.error(`Table ${table} not found in schema`);
@@ -1489,10 +1543,10 @@ const initObject = (db, schema, table, object) => {
1489
1543
  const value = result[column.name];
1490
1544
  switch (column.type) {
1491
1545
  case "datetime": {
1492
- const date = new Date(value);
1493
- if (isNaN(date.getTime())) {
1546
+ const date = value !== void 0 ? new Date(value) : void 0;
1547
+ if (date && isNaN(date.getTime())) {
1494
1548
  console.error(`Failed to parse date ${value} for field ${column.name}`);
1495
- } else {
1549
+ } else if (date) {
1496
1550
  result[column.name] = date;
1497
1551
  }
1498
1552
  break;
@@ -1517,7 +1571,10 @@ const initObject = (db, schema, table, object) => {
1517
1571
  result.delete = function() {
1518
1572
  return db[table].delete(result["id"]);
1519
1573
  };
1520
- for (const prop of ["read", "update", "delete"]) {
1574
+ result.getMetadata = function() {
1575
+ return xata;
1576
+ };
1577
+ for (const prop of ["read", "update", "delete", "getMetadata"]) {
1521
1578
  Object.defineProperty(result, prop, { enumerable: false });
1522
1579
  }
1523
1580
  Object.freeze(result);
@@ -1699,10 +1756,10 @@ _schema = new WeakMap();
1699
1756
  _search = new WeakSet();
1700
1757
  search_fn = async function(query, options, getFetchProps) {
1701
1758
  const fetchProps = await getFetchProps();
1702
- const { tables, fuzziness } = options ?? {};
1759
+ const { tables, fuzziness, highlight } = options ?? {};
1703
1760
  const { records } = await searchBranch({
1704
1761
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1705
- body: { tables, query, fuzziness },
1762
+ body: { tables, query, fuzziness, highlight },
1706
1763
  ...fetchProps
1707
1764
  });
1708
1765
  return records;
@@ -1992,6 +2049,7 @@ exports.insertRecord = insertRecord;
1992
2049
  exports.insertRecordWithID = insertRecordWithID;
1993
2050
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
1994
2051
  exports.is = is;
2052
+ exports.isCursorPaginationOptions = isCursorPaginationOptions;
1995
2053
  exports.isIdentifiable = isIdentifiable;
1996
2054
  exports.isNot = isNot;
1997
2055
  exports.isXataRecord = isXataRecord;
@@ -2007,6 +2065,7 @@ exports.removeWorkspaceMember = removeWorkspaceMember;
2007
2065
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
2008
2066
  exports.resolveBranch = resolveBranch;
2009
2067
  exports.searchBranch = searchBranch;
2068
+ exports.searchTable = searchTable;
2010
2069
  exports.setTableSchema = setTableSchema;
2011
2070
  exports.startsWith = startsWith;
2012
2071
  exports.updateBranchMetadata = updateBranchMetadata;