@xata.io/client 0.16.1 → 0.16.2

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/dist/index.mjs CHANGED
@@ -1,3 +1,27 @@
1
+ const defaultTrace = async (_name, fn, _options) => {
2
+ return await fn({
3
+ setAttributes: () => {
4
+ return;
5
+ },
6
+ onError: () => {
7
+ return;
8
+ }
9
+ });
10
+ };
11
+ const TraceAttributes = {
12
+ VERSION: "xata.sdk.version",
13
+ TABLE: "xata.table",
14
+ HTTP_REQUEST_ID: "http.request_id",
15
+ HTTP_STATUS_CODE: "http.status_code",
16
+ HTTP_HOST: "http.host",
17
+ HTTP_SCHEME: "http.scheme",
18
+ HTTP_USER_AGENT: "http.user_agent",
19
+ HTTP_METHOD: "http.method",
20
+ HTTP_URL: "http.url",
21
+ HTTP_ROUTE: "http.route",
22
+ HTTP_TARGET: "http.target"
23
+ };
24
+
1
25
  function notEmpty(value) {
2
26
  return value !== null && value !== void 0;
3
27
  }
@@ -122,13 +146,13 @@ function getFetchImplementation(userFetch) {
122
146
  const fetchImpl = userFetch ?? globalFetch;
123
147
  if (!fetchImpl) {
124
148
  throw new Error(
125
- `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
149
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
126
150
  );
127
151
  }
128
152
  return fetchImpl;
129
153
  }
130
154
 
131
- const VERSION = "0.16.1";
155
+ const VERSION = "0.16.2";
132
156
 
133
157
  class ErrorWithCause extends Error {
134
158
  constructor(message, options) {
@@ -207,34 +231,62 @@ async function fetch$1({
207
231
  fetchImpl,
208
232
  apiKey,
209
233
  apiUrl,
210
- workspacesApiUrl
234
+ workspacesApiUrl,
235
+ trace
211
236
  }) {
212
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
213
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
214
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
215
- const response = await fetchImpl(url, {
216
- method: method.toUpperCase(),
217
- body: body ? JSON.stringify(body) : void 0,
218
- headers: {
219
- "Content-Type": "application/json",
220
- "User-Agent": `Xata client-ts/${VERSION}`,
221
- ...headers,
222
- ...hostHeader(fullUrl),
223
- Authorization: `Bearer ${apiKey}`
224
- }
225
- });
226
- if (response.status === 204) {
227
- return {};
228
- }
229
- const requestId = response.headers?.get("x-request-id") ?? void 0;
237
+ return trace(
238
+ `${method.toUpperCase()} ${path}`,
239
+ async ({ setAttributes, onError }) => {
240
+ const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
241
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
242
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
243
+ setAttributes({
244
+ [TraceAttributes.HTTP_URL]: url,
245
+ [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
246
+ });
247
+ const response = await fetchImpl(url, {
248
+ method: method.toUpperCase(),
249
+ body: body ? JSON.stringify(body) : void 0,
250
+ headers: {
251
+ "Content-Type": "application/json",
252
+ "User-Agent": `Xata client-ts/${VERSION}`,
253
+ ...headers,
254
+ ...hostHeader(fullUrl),
255
+ Authorization: `Bearer ${apiKey}`
256
+ }
257
+ });
258
+ if (response.status === 204) {
259
+ return {};
260
+ }
261
+ const { host, protocol } = parseUrl(response.url);
262
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
263
+ setAttributes({
264
+ [TraceAttributes.HTTP_REQUEST_ID]: requestId,
265
+ [TraceAttributes.HTTP_STATUS_CODE]: response.status,
266
+ [TraceAttributes.HTTP_HOST]: host,
267
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
268
+ });
269
+ try {
270
+ const jsonResponse = await response.json();
271
+ if (response.ok) {
272
+ return jsonResponse;
273
+ }
274
+ throw new FetcherError(response.status, jsonResponse, requestId);
275
+ } catch (error) {
276
+ const fetcherError = new FetcherError(response.status, error, requestId);
277
+ onError(fetcherError.message);
278
+ throw fetcherError;
279
+ }
280
+ },
281
+ { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
282
+ );
283
+ }
284
+ function parseUrl(url) {
230
285
  try {
231
- const jsonResponse = await response.json();
232
- if (response.ok) {
233
- return jsonResponse;
234
- }
235
- throw new FetcherError(response.status, jsonResponse, requestId);
286
+ const { host, protocol } = new URL(url);
287
+ return { host, protocol };
236
288
  } catch (error) {
237
- throw new FetcherError(response.status, error, requestId);
289
+ return {};
238
290
  }
239
291
  }
240
292
 
@@ -565,7 +617,8 @@ class XataApiClient {
565
617
  __privateAdd$7(this, _extraProps, void 0);
566
618
  __privateAdd$7(this, _namespaces, {});
567
619
  const provider = options.host ?? "production";
568
- const apiKey = options?.apiKey ?? getAPIKey();
620
+ const apiKey = options.apiKey ?? getAPIKey();
621
+ const trace = options.trace ?? defaultTrace;
569
622
  if (!apiKey) {
570
623
  throw new Error("Could not resolve a valid apiKey");
571
624
  }
@@ -573,7 +626,8 @@ class XataApiClient {
573
626
  apiUrl: getHostUrl(provider, "main"),
574
627
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
575
628
  fetchImpl: getFetchImplementation(options.fetch),
576
- apiKey
629
+ apiKey,
630
+ trace
577
631
  });
578
632
  }
579
633
  get user() {
@@ -1190,7 +1244,7 @@ const _Query = class {
1190
1244
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1191
1245
  }
1192
1246
  }
1193
- sort(column, direction) {
1247
+ sort(column, direction = "asc") {
1194
1248
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1195
1249
  const sort = [...originalSort, { column, direction }];
1196
1250
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
@@ -1326,7 +1380,7 @@ var __privateMethod$2 = (obj, member, method) => {
1326
1380
  __accessCheck$4(obj, member, "access private method");
1327
1381
  return method;
1328
1382
  };
1329
- var _table, _getFetchProps, _db, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
1383
+ var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
1330
1384
  class Repository extends Query {
1331
1385
  }
1332
1386
  class RestRepository extends Query {
@@ -1346,168 +1400,196 @@ class RestRepository extends Query {
1346
1400
  __privateAdd$4(this, _db, void 0);
1347
1401
  __privateAdd$4(this, _cache, void 0);
1348
1402
  __privateAdd$4(this, _schemaTables$2, void 0);
1403
+ __privateAdd$4(this, _trace, void 0);
1349
1404
  __privateSet$4(this, _table, options.table);
1350
1405
  __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1351
1406
  __privateSet$4(this, _db, options.db);
1352
1407
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1353
1408
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1409
+ const trace = options.pluginOptions.trace ?? defaultTrace;
1410
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1411
+ return trace(name, fn, {
1412
+ ...options2,
1413
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1414
+ [TraceAttributes.VERSION]: VERSION
1415
+ });
1416
+ });
1354
1417
  }
1355
1418
  async create(a, b, c) {
1356
- if (Array.isArray(a)) {
1357
- if (a.length === 0)
1358
- return [];
1359
- const columns = isStringArray(b) ? b : void 0;
1360
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1361
- }
1362
- if (isString(a) && isObject(b)) {
1363
- if (a === "")
1364
- throw new Error("The id can't be empty");
1365
- const columns = isStringArray(c) ? c : void 0;
1366
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1367
- }
1368
- if (isObject(a) && isString(a.id)) {
1369
- if (a.id === "")
1370
- throw new Error("The id can't be empty");
1371
- const columns = isStringArray(b) ? b : void 0;
1372
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1373
- }
1374
- if (isObject(a)) {
1375
- const columns = isStringArray(b) ? b : void 0;
1376
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1377
- }
1378
- throw new Error("Invalid arguments for create method");
1419
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
1420
+ if (Array.isArray(a)) {
1421
+ if (a.length === 0)
1422
+ return [];
1423
+ const columns = isStringArray(b) ? b : void 0;
1424
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1425
+ }
1426
+ if (isString(a) && isObject(b)) {
1427
+ if (a === "")
1428
+ throw new Error("The id can't be empty");
1429
+ const columns = isStringArray(c) ? c : void 0;
1430
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1431
+ }
1432
+ if (isObject(a) && isString(a.id)) {
1433
+ if (a.id === "")
1434
+ throw new Error("The id can't be empty");
1435
+ const columns = isStringArray(b) ? b : void 0;
1436
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1437
+ }
1438
+ if (isObject(a)) {
1439
+ const columns = isStringArray(b) ? b : void 0;
1440
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1441
+ }
1442
+ throw new Error("Invalid arguments for create method");
1443
+ });
1379
1444
  }
1380
1445
  async read(a, b) {
1381
- const columns = isStringArray(b) ? b : ["*"];
1382
- if (Array.isArray(a)) {
1383
- if (a.length === 0)
1384
- return [];
1385
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1386
- const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1387
- const dictionary = finalObjects.reduce((acc, object) => {
1388
- acc[object.id] = object;
1389
- return acc;
1390
- }, {});
1391
- return ids.map((id2) => dictionary[id2] ?? null);
1392
- }
1393
- const id = isString(a) ? a : a.id;
1394
- if (isString(id)) {
1395
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1396
- try {
1397
- const response = await getRecord({
1398
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1399
- queryParams: { columns },
1400
- ...fetchProps
1401
- });
1402
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1403
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1404
- } catch (e) {
1405
- if (isObject(e) && e.status === 404) {
1406
- return null;
1446
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
1447
+ const columns = isStringArray(b) ? b : ["*"];
1448
+ if (Array.isArray(a)) {
1449
+ if (a.length === 0)
1450
+ return [];
1451
+ const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1452
+ const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1453
+ const dictionary = finalObjects.reduce((acc, object) => {
1454
+ acc[object.id] = object;
1455
+ return acc;
1456
+ }, {});
1457
+ return ids.map((id2) => dictionary[id2] ?? null);
1458
+ }
1459
+ const id = isString(a) ? a : a.id;
1460
+ if (isString(id)) {
1461
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1462
+ try {
1463
+ const response = await getRecord({
1464
+ pathParams: {
1465
+ workspace: "{workspaceId}",
1466
+ dbBranchName: "{dbBranch}",
1467
+ tableName: __privateGet$4(this, _table),
1468
+ recordId: id
1469
+ },
1470
+ queryParams: { columns },
1471
+ ...fetchProps
1472
+ });
1473
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1474
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1475
+ } catch (e) {
1476
+ if (isObject(e) && e.status === 404) {
1477
+ return null;
1478
+ }
1479
+ throw e;
1407
1480
  }
1408
- throw e;
1409
1481
  }
1410
- }
1411
- return null;
1482
+ return null;
1483
+ });
1412
1484
  }
1413
1485
  async update(a, b, c) {
1414
- if (Array.isArray(a)) {
1415
- if (a.length === 0)
1416
- return [];
1417
- if (a.length > 100) {
1418
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1486
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
1487
+ if (Array.isArray(a)) {
1488
+ if (a.length === 0)
1489
+ return [];
1490
+ if (a.length > 100) {
1491
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1492
+ }
1493
+ const columns = isStringArray(b) ? b : ["*"];
1494
+ return Promise.all(a.map((object) => this.update(object, columns)));
1419
1495
  }
1420
- const columns = isStringArray(b) ? b : ["*"];
1421
- return Promise.all(a.map((object) => this.update(object, columns)));
1422
- }
1423
- if (isString(a) && isObject(b)) {
1424
- const columns = isStringArray(c) ? c : void 0;
1425
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1426
- }
1427
- if (isObject(a) && isString(a.id)) {
1428
- const columns = isStringArray(b) ? b : void 0;
1429
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1430
- }
1431
- throw new Error("Invalid arguments for update method");
1496
+ if (isString(a) && isObject(b)) {
1497
+ const columns = isStringArray(c) ? c : void 0;
1498
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1499
+ }
1500
+ if (isObject(a) && isString(a.id)) {
1501
+ const columns = isStringArray(b) ? b : void 0;
1502
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1503
+ }
1504
+ throw new Error("Invalid arguments for update method");
1505
+ });
1432
1506
  }
1433
1507
  async createOrUpdate(a, b, c) {
1434
- if (Array.isArray(a)) {
1435
- if (a.length === 0)
1436
- return [];
1437
- if (a.length > 100) {
1438
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1508
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1509
+ if (Array.isArray(a)) {
1510
+ if (a.length === 0)
1511
+ return [];
1512
+ if (a.length > 100) {
1513
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1514
+ }
1515
+ const columns = isStringArray(b) ? b : ["*"];
1516
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1439
1517
  }
1440
- const columns = isStringArray(b) ? b : ["*"];
1441
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1442
- }
1443
- if (isString(a) && isObject(b)) {
1444
- const columns = isStringArray(c) ? c : void 0;
1445
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1446
- }
1447
- if (isObject(a) && isString(a.id)) {
1448
- const columns = isStringArray(c) ? c : void 0;
1449
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1450
- }
1451
- throw new Error("Invalid arguments for createOrUpdate method");
1518
+ if (isString(a) && isObject(b)) {
1519
+ const columns = isStringArray(c) ? c : void 0;
1520
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1521
+ }
1522
+ if (isObject(a) && isString(a.id)) {
1523
+ const columns = isStringArray(c) ? c : void 0;
1524
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1525
+ }
1526
+ throw new Error("Invalid arguments for createOrUpdate method");
1527
+ });
1452
1528
  }
1453
1529
  async delete(a) {
1454
- if (Array.isArray(a)) {
1455
- if (a.length === 0)
1530
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
1531
+ if (Array.isArray(a)) {
1532
+ if (a.length === 0)
1533
+ return;
1534
+ if (a.length > 100) {
1535
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1536
+ }
1537
+ await Promise.all(a.map((id) => this.delete(id)));
1456
1538
  return;
1457
- if (a.length > 100) {
1458
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1459
1539
  }
1460
- await Promise.all(a.map((id) => this.delete(id)));
1461
- return;
1462
- }
1463
- if (isString(a)) {
1464
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1465
- return;
1466
- }
1467
- if (isObject(a) && isString(a.id)) {
1468
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1469
- return;
1470
- }
1471
- throw new Error("Invalid arguments for delete method");
1540
+ if (isString(a)) {
1541
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1542
+ return;
1543
+ }
1544
+ if (isObject(a) && isString(a.id)) {
1545
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1546
+ return;
1547
+ }
1548
+ throw new Error("Invalid arguments for delete method");
1549
+ });
1472
1550
  }
1473
1551
  async search(query, options = {}) {
1474
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1475
- const { records } = await searchTable({
1476
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1477
- body: {
1478
- query,
1479
- fuzziness: options.fuzziness,
1480
- prefix: options.prefix,
1481
- highlight: options.highlight,
1482
- filter: options.filter,
1483
- boosters: options.boosters
1484
- },
1485
- ...fetchProps
1552
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
1553
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1554
+ const { records } = await searchTable({
1555
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1556
+ body: {
1557
+ query,
1558
+ fuzziness: options.fuzziness,
1559
+ prefix: options.prefix,
1560
+ highlight: options.highlight,
1561
+ filter: options.filter,
1562
+ boosters: options.boosters
1563
+ },
1564
+ ...fetchProps
1565
+ });
1566
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1567
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1486
1568
  });
1487
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1488
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1489
1569
  }
1490
1570
  async query(query) {
1491
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1492
- if (cacheQuery)
1493
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1494
- const data = query.getQueryOptions();
1495
- const body = {
1496
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1497
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1498
- page: data.pagination,
1499
- columns: data.columns
1500
- };
1501
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1502
- const { meta, records: objects } = await queryTable({
1503
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1504
- body,
1505
- ...fetchProps
1571
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
1572
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1573
+ if (cacheQuery)
1574
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1575
+ const data = query.getQueryOptions();
1576
+ const body = {
1577
+ filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1578
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1579
+ page: data.pagination,
1580
+ columns: data.columns
1581
+ };
1582
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1583
+ const { meta, records: objects } = await queryTable({
1584
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1585
+ body,
1586
+ ...fetchProps
1587
+ });
1588
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1589
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1590
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1591
+ return new Page(query, meta, records);
1506
1592
  });
1507
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1508
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1509
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1510
- return new Page(query, meta, records);
1511
1593
  }
1512
1594
  }
1513
1595
  _table = new WeakMap();
@@ -1515,6 +1597,7 @@ _getFetchProps = new WeakMap();
1515
1597
  _db = new WeakMap();
1516
1598
  _cache = new WeakMap();
1517
1599
  _schemaTables$2 = new WeakMap();
1600
+ _trace = new WeakMap();
1518
1601
  _insertRecordWithoutId = new WeakSet();
1519
1602
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1520
1603
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1735,18 +1818,25 @@ class SimpleCache {
1735
1818
  }
1736
1819
  _map = new WeakMap();
1737
1820
 
1738
- const gt = (value) => ({ $gt: value });
1739
- const ge = (value) => ({ $ge: value });
1740
- const gte = (value) => ({ $ge: value });
1741
- const lt = (value) => ({ $lt: value });
1742
- const lte = (value) => ({ $le: value });
1743
- const le = (value) => ({ $le: value });
1821
+ const greaterThan = (value) => ({ $gt: value });
1822
+ const gt = greaterThan;
1823
+ const greaterThanEquals = (value) => ({ $ge: value });
1824
+ const greaterEquals = greaterThanEquals;
1825
+ const gte = greaterThanEquals;
1826
+ const ge = greaterThanEquals;
1827
+ const lessThan = (value) => ({ $lt: value });
1828
+ const lt = lessThan;
1829
+ const lessThanEquals = (value) => ({ $le: value });
1830
+ const lessEquals = lessThanEquals;
1831
+ const lte = lessThanEquals;
1832
+ const le = lessThanEquals;
1744
1833
  const exists = (column) => ({ $exists: column });
1745
1834
  const notExists = (column) => ({ $notExists: column });
1746
1835
  const startsWith = (value) => ({ $startsWith: value });
1747
1836
  const endsWith = (value) => ({ $endsWith: value });
1748
1837
  const pattern = (value) => ({ $pattern: value });
1749
1838
  const is = (value) => ({ $is: value });
1839
+ const equals = is;
1750
1840
  const isNot = (value) => ({ $isNot: value });
1751
1841
  const contains = (value) => ({ $contains: value });
1752
1842
  const includes = (value) => ({ $includes: value });
@@ -1923,7 +2013,8 @@ async function resolveXataBranch(gitBranch, options) {
1923
2013
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1924
2014
  workspacesApiUrl: `${protocol}//${host}`,
1925
2015
  pathParams: { dbName, workspace },
1926
- queryParams: { gitBranch, fallbackBranch }
2016
+ queryParams: { gitBranch, fallbackBranch },
2017
+ trace: defaultTrace
1927
2018
  });
1928
2019
  return branch;
1929
2020
  }
@@ -1947,7 +2038,8 @@ async function getDatabaseBranch(branch, options) {
1947
2038
  apiUrl: databaseURL,
1948
2039
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1949
2040
  workspacesApiUrl: `${protocol}//${host}`,
1950
- pathParams: { dbBranchName, workspace }
2041
+ pathParams: { dbBranchName, workspace },
2042
+ trace: defaultTrace
1951
2043
  });
1952
2044
  } catch (err) {
1953
2045
  if (isObject(err) && err.status === 404)
@@ -1999,7 +2091,8 @@ const buildClient = (plugins) => {
1999
2091
  __privateSet(this, _options, safeOptions);
2000
2092
  const pluginOptions = {
2001
2093
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2002
- cache: safeOptions.cache
2094
+ cache: safeOptions.cache,
2095
+ trace: safeOptions.trace
2003
2096
  };
2004
2097
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2005
2098
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2028,12 +2121,16 @@ const buildClient = (plugins) => {
2028
2121
  const databaseURL = options?.databaseURL || getDatabaseURL();
2029
2122
  const apiKey = options?.apiKey || getAPIKey();
2030
2123
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2124
+ const trace = options?.trace ?? defaultTrace;
2031
2125
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2032
- if (!databaseURL || !apiKey) {
2033
- throw new Error("Options databaseURL and apiKey are required");
2126
+ if (!apiKey) {
2127
+ throw new Error("Option apiKey is required");
2128
+ }
2129
+ if (!databaseURL) {
2130
+ throw new Error("Option databaseURL is required");
2034
2131
  }
2035
- return { fetch, databaseURL, apiKey, branch, cache };
2036
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
2132
+ return { fetch, databaseURL, apiKey, branch, cache, trace };
2133
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2037
2134
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2038
2135
  if (!branchValue)
2039
2136
  throw new Error("Unable to resolve branch value");
@@ -2045,7 +2142,8 @@ const buildClient = (plugins) => {
2045
2142
  const hasBranch = params.dbBranchName ?? params.branch;
2046
2143
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2047
2144
  return databaseURL + newPath;
2048
- }
2145
+ },
2146
+ trace
2049
2147
  };
2050
2148
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2051
2149
  if (__privateGet(this, _branch))
@@ -2157,5 +2255,5 @@ class XataError extends Error {
2157
2255
  }
2158
2256
  }
2159
2257
 
2160
- export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2258
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2161
2259
  //# sourceMappingURL=index.mjs.map