@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.cjs CHANGED
@@ -20,6 +20,30 @@ function _interopNamespace(e) {
20
20
  return Object.freeze(n);
21
21
  }
22
22
 
23
+ const defaultTrace = async (_name, fn, _options) => {
24
+ return await fn({
25
+ setAttributes: () => {
26
+ return;
27
+ },
28
+ onError: () => {
29
+ return;
30
+ }
31
+ });
32
+ };
33
+ const TraceAttributes = {
34
+ VERSION: "xata.sdk.version",
35
+ TABLE: "xata.table",
36
+ HTTP_REQUEST_ID: "http.request_id",
37
+ HTTP_STATUS_CODE: "http.status_code",
38
+ HTTP_HOST: "http.host",
39
+ HTTP_SCHEME: "http.scheme",
40
+ HTTP_USER_AGENT: "http.user_agent",
41
+ HTTP_METHOD: "http.method",
42
+ HTTP_URL: "http.url",
43
+ HTTP_ROUTE: "http.route",
44
+ HTTP_TARGET: "http.target"
45
+ };
46
+
23
47
  function notEmpty(value) {
24
48
  return value !== null && value !== void 0;
25
49
  }
@@ -144,13 +168,13 @@ function getFetchImplementation(userFetch) {
144
168
  const fetchImpl = userFetch ?? globalFetch;
145
169
  if (!fetchImpl) {
146
170
  throw new Error(
147
- `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
171
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
148
172
  );
149
173
  }
150
174
  return fetchImpl;
151
175
  }
152
176
 
153
- const VERSION = "0.16.1";
177
+ const VERSION = "0.16.2";
154
178
 
155
179
  class ErrorWithCause extends Error {
156
180
  constructor(message, options) {
@@ -229,34 +253,62 @@ async function fetch$1({
229
253
  fetchImpl,
230
254
  apiKey,
231
255
  apiUrl,
232
- workspacesApiUrl
256
+ workspacesApiUrl,
257
+ trace
233
258
  }) {
234
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
235
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
236
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
237
- const response = await fetchImpl(url, {
238
- method: method.toUpperCase(),
239
- body: body ? JSON.stringify(body) : void 0,
240
- headers: {
241
- "Content-Type": "application/json",
242
- "User-Agent": `Xata client-ts/${VERSION}`,
243
- ...headers,
244
- ...hostHeader(fullUrl),
245
- Authorization: `Bearer ${apiKey}`
246
- }
247
- });
248
- if (response.status === 204) {
249
- return {};
250
- }
251
- const requestId = response.headers?.get("x-request-id") ?? void 0;
259
+ return trace(
260
+ `${method.toUpperCase()} ${path}`,
261
+ async ({ setAttributes, onError }) => {
262
+ const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
263
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
264
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
265
+ setAttributes({
266
+ [TraceAttributes.HTTP_URL]: url,
267
+ [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
268
+ });
269
+ const response = await fetchImpl(url, {
270
+ method: method.toUpperCase(),
271
+ body: body ? JSON.stringify(body) : void 0,
272
+ headers: {
273
+ "Content-Type": "application/json",
274
+ "User-Agent": `Xata client-ts/${VERSION}`,
275
+ ...headers,
276
+ ...hostHeader(fullUrl),
277
+ Authorization: `Bearer ${apiKey}`
278
+ }
279
+ });
280
+ if (response.status === 204) {
281
+ return {};
282
+ }
283
+ const { host, protocol } = parseUrl(response.url);
284
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
285
+ setAttributes({
286
+ [TraceAttributes.HTTP_REQUEST_ID]: requestId,
287
+ [TraceAttributes.HTTP_STATUS_CODE]: response.status,
288
+ [TraceAttributes.HTTP_HOST]: host,
289
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
290
+ });
291
+ try {
292
+ const jsonResponse = await response.json();
293
+ if (response.ok) {
294
+ return jsonResponse;
295
+ }
296
+ throw new FetcherError(response.status, jsonResponse, requestId);
297
+ } catch (error) {
298
+ const fetcherError = new FetcherError(response.status, error, requestId);
299
+ onError(fetcherError.message);
300
+ throw fetcherError;
301
+ }
302
+ },
303
+ { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
304
+ );
305
+ }
306
+ function parseUrl(url) {
252
307
  try {
253
- const jsonResponse = await response.json();
254
- if (response.ok) {
255
- return jsonResponse;
256
- }
257
- throw new FetcherError(response.status, jsonResponse, requestId);
308
+ const { host, protocol } = new URL(url);
309
+ return { host, protocol };
258
310
  } catch (error) {
259
- throw new FetcherError(response.status, error, requestId);
311
+ return {};
260
312
  }
261
313
  }
262
314
 
@@ -587,7 +639,8 @@ class XataApiClient {
587
639
  __privateAdd$7(this, _extraProps, void 0);
588
640
  __privateAdd$7(this, _namespaces, {});
589
641
  const provider = options.host ?? "production";
590
- const apiKey = options?.apiKey ?? getAPIKey();
642
+ const apiKey = options.apiKey ?? getAPIKey();
643
+ const trace = options.trace ?? defaultTrace;
591
644
  if (!apiKey) {
592
645
  throw new Error("Could not resolve a valid apiKey");
593
646
  }
@@ -595,7 +648,8 @@ class XataApiClient {
595
648
  apiUrl: getHostUrl(provider, "main"),
596
649
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
597
650
  fetchImpl: getFetchImplementation(options.fetch),
598
- apiKey
651
+ apiKey,
652
+ trace
599
653
  });
600
654
  }
601
655
  get user() {
@@ -1212,7 +1266,7 @@ const _Query = class {
1212
1266
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1213
1267
  }
1214
1268
  }
1215
- sort(column, direction) {
1269
+ sort(column, direction = "asc") {
1216
1270
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1217
1271
  const sort = [...originalSort, { column, direction }];
1218
1272
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
@@ -1348,7 +1402,7 @@ var __privateMethod$2 = (obj, member, method) => {
1348
1402
  __accessCheck$4(obj, member, "access private method");
1349
1403
  return method;
1350
1404
  };
1351
- 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;
1405
+ 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;
1352
1406
  class Repository extends Query {
1353
1407
  }
1354
1408
  class RestRepository extends Query {
@@ -1368,168 +1422,196 @@ class RestRepository extends Query {
1368
1422
  __privateAdd$4(this, _db, void 0);
1369
1423
  __privateAdd$4(this, _cache, void 0);
1370
1424
  __privateAdd$4(this, _schemaTables$2, void 0);
1425
+ __privateAdd$4(this, _trace, void 0);
1371
1426
  __privateSet$4(this, _table, options.table);
1372
1427
  __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1373
1428
  __privateSet$4(this, _db, options.db);
1374
1429
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1375
1430
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1431
+ const trace = options.pluginOptions.trace ?? defaultTrace;
1432
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1433
+ return trace(name, fn, {
1434
+ ...options2,
1435
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1436
+ [TraceAttributes.VERSION]: VERSION
1437
+ });
1438
+ });
1376
1439
  }
1377
1440
  async create(a, b, c) {
1378
- if (Array.isArray(a)) {
1379
- if (a.length === 0)
1380
- return [];
1381
- const columns = isStringArray(b) ? b : void 0;
1382
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1383
- }
1384
- if (isString(a) && isObject(b)) {
1385
- if (a === "")
1386
- throw new Error("The id can't be empty");
1387
- const columns = isStringArray(c) ? c : void 0;
1388
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1389
- }
1390
- if (isObject(a) && isString(a.id)) {
1391
- if (a.id === "")
1392
- throw new Error("The id can't be empty");
1393
- const columns = isStringArray(b) ? b : void 0;
1394
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1395
- }
1396
- if (isObject(a)) {
1397
- const columns = isStringArray(b) ? b : void 0;
1398
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1399
- }
1400
- throw new Error("Invalid arguments for create method");
1441
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
1442
+ if (Array.isArray(a)) {
1443
+ if (a.length === 0)
1444
+ return [];
1445
+ const columns = isStringArray(b) ? b : void 0;
1446
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1447
+ }
1448
+ if (isString(a) && isObject(b)) {
1449
+ if (a === "")
1450
+ throw new Error("The id can't be empty");
1451
+ const columns = isStringArray(c) ? c : void 0;
1452
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1453
+ }
1454
+ if (isObject(a) && isString(a.id)) {
1455
+ if (a.id === "")
1456
+ throw new Error("The id can't be empty");
1457
+ const columns = isStringArray(b) ? b : void 0;
1458
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1459
+ }
1460
+ if (isObject(a)) {
1461
+ const columns = isStringArray(b) ? b : void 0;
1462
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1463
+ }
1464
+ throw new Error("Invalid arguments for create method");
1465
+ });
1401
1466
  }
1402
1467
  async read(a, b) {
1403
- const columns = isStringArray(b) ? b : ["*"];
1404
- if (Array.isArray(a)) {
1405
- if (a.length === 0)
1406
- return [];
1407
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1408
- const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1409
- const dictionary = finalObjects.reduce((acc, object) => {
1410
- acc[object.id] = object;
1411
- return acc;
1412
- }, {});
1413
- return ids.map((id2) => dictionary[id2] ?? null);
1414
- }
1415
- const id = isString(a) ? a : a.id;
1416
- if (isString(id)) {
1417
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1418
- try {
1419
- const response = await getRecord({
1420
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1421
- queryParams: { columns },
1422
- ...fetchProps
1423
- });
1424
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1425
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1426
- } catch (e) {
1427
- if (isObject(e) && e.status === 404) {
1428
- return null;
1468
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
1469
+ const columns = isStringArray(b) ? b : ["*"];
1470
+ if (Array.isArray(a)) {
1471
+ if (a.length === 0)
1472
+ return [];
1473
+ const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1474
+ const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1475
+ const dictionary = finalObjects.reduce((acc, object) => {
1476
+ acc[object.id] = object;
1477
+ return acc;
1478
+ }, {});
1479
+ return ids.map((id2) => dictionary[id2] ?? null);
1480
+ }
1481
+ const id = isString(a) ? a : a.id;
1482
+ if (isString(id)) {
1483
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1484
+ try {
1485
+ const response = await getRecord({
1486
+ pathParams: {
1487
+ workspace: "{workspaceId}",
1488
+ dbBranchName: "{dbBranch}",
1489
+ tableName: __privateGet$4(this, _table),
1490
+ recordId: id
1491
+ },
1492
+ queryParams: { columns },
1493
+ ...fetchProps
1494
+ });
1495
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1496
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1497
+ } catch (e) {
1498
+ if (isObject(e) && e.status === 404) {
1499
+ return null;
1500
+ }
1501
+ throw e;
1429
1502
  }
1430
- throw e;
1431
1503
  }
1432
- }
1433
- return null;
1504
+ return null;
1505
+ });
1434
1506
  }
1435
1507
  async update(a, b, c) {
1436
- if (Array.isArray(a)) {
1437
- if (a.length === 0)
1438
- return [];
1439
- if (a.length > 100) {
1440
- 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, "update", 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.update(object, columns)));
1441
1517
  }
1442
- const columns = isStringArray(b) ? b : ["*"];
1443
- return Promise.all(a.map((object) => this.update(object, columns)));
1444
- }
1445
- if (isString(a) && isObject(b)) {
1446
- const columns = isStringArray(c) ? c : void 0;
1447
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1448
- }
1449
- if (isObject(a) && isString(a.id)) {
1450
- const columns = isStringArray(b) ? b : void 0;
1451
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1452
- }
1453
- throw new Error("Invalid arguments for update method");
1518
+ if (isString(a) && isObject(b)) {
1519
+ const columns = isStringArray(c) ? c : void 0;
1520
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1521
+ }
1522
+ if (isObject(a) && isString(a.id)) {
1523
+ const columns = isStringArray(b) ? b : void 0;
1524
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1525
+ }
1526
+ throw new Error("Invalid arguments for update method");
1527
+ });
1454
1528
  }
1455
1529
  async createOrUpdate(a, b, c) {
1456
- if (Array.isArray(a)) {
1457
- if (a.length === 0)
1458
- return [];
1459
- if (a.length > 100) {
1460
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1530
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1531
+ if (Array.isArray(a)) {
1532
+ if (a.length === 0)
1533
+ return [];
1534
+ if (a.length > 100) {
1535
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1536
+ }
1537
+ const columns = isStringArray(b) ? b : ["*"];
1538
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1461
1539
  }
1462
- const columns = isStringArray(b) ? b : ["*"];
1463
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1464
- }
1465
- if (isString(a) && isObject(b)) {
1466
- const columns = isStringArray(c) ? c : void 0;
1467
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1468
- }
1469
- if (isObject(a) && isString(a.id)) {
1470
- const columns = isStringArray(c) ? c : void 0;
1471
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1472
- }
1473
- throw new Error("Invalid arguments for createOrUpdate method");
1540
+ if (isString(a) && isObject(b)) {
1541
+ const columns = isStringArray(c) ? c : void 0;
1542
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1543
+ }
1544
+ if (isObject(a) && isString(a.id)) {
1545
+ const columns = isStringArray(c) ? c : void 0;
1546
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1547
+ }
1548
+ throw new Error("Invalid arguments for createOrUpdate method");
1549
+ });
1474
1550
  }
1475
1551
  async delete(a) {
1476
- if (Array.isArray(a)) {
1477
- if (a.length === 0)
1552
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
1553
+ if (Array.isArray(a)) {
1554
+ if (a.length === 0)
1555
+ return;
1556
+ if (a.length > 100) {
1557
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1558
+ }
1559
+ await Promise.all(a.map((id) => this.delete(id)));
1478
1560
  return;
1479
- if (a.length > 100) {
1480
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1481
1561
  }
1482
- await Promise.all(a.map((id) => this.delete(id)));
1483
- return;
1484
- }
1485
- if (isString(a)) {
1486
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1487
- return;
1488
- }
1489
- if (isObject(a) && isString(a.id)) {
1490
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1491
- return;
1492
- }
1493
- throw new Error("Invalid arguments for delete method");
1562
+ if (isString(a)) {
1563
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1564
+ return;
1565
+ }
1566
+ if (isObject(a) && isString(a.id)) {
1567
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1568
+ return;
1569
+ }
1570
+ throw new Error("Invalid arguments for delete method");
1571
+ });
1494
1572
  }
1495
1573
  async search(query, options = {}) {
1496
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1497
- const { records } = await searchTable({
1498
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1499
- body: {
1500
- query,
1501
- fuzziness: options.fuzziness,
1502
- prefix: options.prefix,
1503
- highlight: options.highlight,
1504
- filter: options.filter,
1505
- boosters: options.boosters
1506
- },
1507
- ...fetchProps
1574
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
1575
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1576
+ const { records } = await searchTable({
1577
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1578
+ body: {
1579
+ query,
1580
+ fuzziness: options.fuzziness,
1581
+ prefix: options.prefix,
1582
+ highlight: options.highlight,
1583
+ filter: options.filter,
1584
+ boosters: options.boosters
1585
+ },
1586
+ ...fetchProps
1587
+ });
1588
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1589
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1508
1590
  });
1509
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1510
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1511
1591
  }
1512
1592
  async query(query) {
1513
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1514
- if (cacheQuery)
1515
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1516
- const data = query.getQueryOptions();
1517
- const body = {
1518
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1519
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1520
- page: data.pagination,
1521
- columns: data.columns
1522
- };
1523
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1524
- const { meta, records: objects } = await queryTable({
1525
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1526
- body,
1527
- ...fetchProps
1593
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
1594
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1595
+ if (cacheQuery)
1596
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1597
+ const data = query.getQueryOptions();
1598
+ const body = {
1599
+ filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1600
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1601
+ page: data.pagination,
1602
+ columns: data.columns
1603
+ };
1604
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1605
+ const { meta, records: objects } = await queryTable({
1606
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1607
+ body,
1608
+ ...fetchProps
1609
+ });
1610
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1611
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1612
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1613
+ return new Page(query, meta, records);
1528
1614
  });
1529
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1530
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1531
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1532
- return new Page(query, meta, records);
1533
1615
  }
1534
1616
  }
1535
1617
  _table = new WeakMap();
@@ -1537,6 +1619,7 @@ _getFetchProps = new WeakMap();
1537
1619
  _db = new WeakMap();
1538
1620
  _cache = new WeakMap();
1539
1621
  _schemaTables$2 = new WeakMap();
1622
+ _trace = new WeakMap();
1540
1623
  _insertRecordWithoutId = new WeakSet();
1541
1624
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1542
1625
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1757,18 +1840,25 @@ class SimpleCache {
1757
1840
  }
1758
1841
  _map = new WeakMap();
1759
1842
 
1760
- const gt = (value) => ({ $gt: value });
1761
- const ge = (value) => ({ $ge: value });
1762
- const gte = (value) => ({ $ge: value });
1763
- const lt = (value) => ({ $lt: value });
1764
- const lte = (value) => ({ $le: value });
1765
- const le = (value) => ({ $le: value });
1843
+ const greaterThan = (value) => ({ $gt: value });
1844
+ const gt = greaterThan;
1845
+ const greaterThanEquals = (value) => ({ $ge: value });
1846
+ const greaterEquals = greaterThanEquals;
1847
+ const gte = greaterThanEquals;
1848
+ const ge = greaterThanEquals;
1849
+ const lessThan = (value) => ({ $lt: value });
1850
+ const lt = lessThan;
1851
+ const lessThanEquals = (value) => ({ $le: value });
1852
+ const lessEquals = lessThanEquals;
1853
+ const lte = lessThanEquals;
1854
+ const le = lessThanEquals;
1766
1855
  const exists = (column) => ({ $exists: column });
1767
1856
  const notExists = (column) => ({ $notExists: column });
1768
1857
  const startsWith = (value) => ({ $startsWith: value });
1769
1858
  const endsWith = (value) => ({ $endsWith: value });
1770
1859
  const pattern = (value) => ({ $pattern: value });
1771
1860
  const is = (value) => ({ $is: value });
1861
+ const equals = is;
1772
1862
  const isNot = (value) => ({ $isNot: value });
1773
1863
  const contains = (value) => ({ $contains: value });
1774
1864
  const includes = (value) => ({ $includes: value });
@@ -1945,7 +2035,8 @@ async function resolveXataBranch(gitBranch, options) {
1945
2035
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1946
2036
  workspacesApiUrl: `${protocol}//${host}`,
1947
2037
  pathParams: { dbName, workspace },
1948
- queryParams: { gitBranch, fallbackBranch }
2038
+ queryParams: { gitBranch, fallbackBranch },
2039
+ trace: defaultTrace
1949
2040
  });
1950
2041
  return branch;
1951
2042
  }
@@ -1969,7 +2060,8 @@ async function getDatabaseBranch(branch, options) {
1969
2060
  apiUrl: databaseURL,
1970
2061
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1971
2062
  workspacesApiUrl: `${protocol}//${host}`,
1972
- pathParams: { dbBranchName, workspace }
2063
+ pathParams: { dbBranchName, workspace },
2064
+ trace: defaultTrace
1973
2065
  });
1974
2066
  } catch (err) {
1975
2067
  if (isObject(err) && err.status === 404)
@@ -2021,7 +2113,8 @@ const buildClient = (plugins) => {
2021
2113
  __privateSet(this, _options, safeOptions);
2022
2114
  const pluginOptions = {
2023
2115
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2024
- cache: safeOptions.cache
2116
+ cache: safeOptions.cache,
2117
+ trace: safeOptions.trace
2025
2118
  };
2026
2119
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2027
2120
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2050,12 +2143,16 @@ const buildClient = (plugins) => {
2050
2143
  const databaseURL = options?.databaseURL || getDatabaseURL();
2051
2144
  const apiKey = options?.apiKey || getAPIKey();
2052
2145
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2146
+ const trace = options?.trace ?? defaultTrace;
2053
2147
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2054
- if (!databaseURL || !apiKey) {
2055
- throw new Error("Options databaseURL and apiKey are required");
2148
+ if (!apiKey) {
2149
+ throw new Error("Option apiKey is required");
2150
+ }
2151
+ if (!databaseURL) {
2152
+ throw new Error("Option databaseURL is required");
2056
2153
  }
2057
- return { fetch, databaseURL, apiKey, branch, cache };
2058
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
2154
+ return { fetch, databaseURL, apiKey, branch, cache, trace };
2155
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2059
2156
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2060
2157
  if (!branchValue)
2061
2158
  throw new Error("Unable to resolve branch value");
@@ -2067,7 +2164,8 @@ const buildClient = (plugins) => {
2067
2164
  const hasBranch = params.dbBranchName ?? params.branch;
2068
2165
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2069
2166
  return databaseURL + newPath;
2070
- }
2167
+ },
2168
+ trace
2071
2169
  };
2072
2170
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2073
2171
  if (__privateGet(this, _branch))
@@ -2221,6 +2319,7 @@ exports.deleteUserAPIKey = deleteUserAPIKey;
2221
2319
  exports.deleteWorkspace = deleteWorkspace;
2222
2320
  exports.deserialize = deserialize;
2223
2321
  exports.endsWith = endsWith;
2322
+ exports.equals = equals;
2224
2323
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2225
2324
  exports.exists = exists;
2226
2325
  exports.ge = ge;
@@ -2246,6 +2345,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2246
2345
  exports.getWorkspace = getWorkspace;
2247
2346
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2248
2347
  exports.getWorkspacesList = getWorkspacesList;
2348
+ exports.greaterEquals = greaterEquals;
2349
+ exports.greaterThan = greaterThan;
2350
+ exports.greaterThanEquals = greaterThanEquals;
2249
2351
  exports.gt = gt;
2250
2352
  exports.gte = gte;
2251
2353
  exports.includes = includes;
@@ -2261,6 +2363,9 @@ exports.isIdentifiable = isIdentifiable;
2261
2363
  exports.isNot = isNot;
2262
2364
  exports.isXataRecord = isXataRecord;
2263
2365
  exports.le = le;
2366
+ exports.lessEquals = lessEquals;
2367
+ exports.lessThan = lessThan;
2368
+ exports.lessThanEquals = lessThanEquals;
2264
2369
  exports.lt = lt;
2265
2370
  exports.lte = lte;
2266
2371
  exports.notExists = notExists;