@xata.io/client 0.0.0-alpha.vf73045e → 0.0.0-alpha.vf79e7d8

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.0.0-alpha.vf73045e";
177
+ const VERSION = "0.0.0-alpha.vf79e7d8";
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
 
@@ -539,9 +591,9 @@ const operationsByTag = {
539
591
  };
540
592
 
541
593
  function getHostUrl(provider, type) {
542
- if (isValidAlias(provider)) {
594
+ if (isHostProviderAlias(provider)) {
543
595
  return providers[provider][type];
544
- } else if (isValidBuilder(provider)) {
596
+ } else if (isHostProviderBuilder(provider)) {
545
597
  return provider[type];
546
598
  }
547
599
  throw new Error("Invalid API provider");
@@ -556,10 +608,10 @@ const providers = {
556
608
  workspaces: "https://{workspaceId}.staging.xatabase.co"
557
609
  }
558
610
  };
559
- function isValidAlias(alias) {
611
+ function isHostProviderAlias(alias) {
560
612
  return isString(alias) && Object.keys(providers).includes(alias);
561
613
  }
562
- function isValidBuilder(builder) {
614
+ function isHostProviderBuilder(builder) {
563
615
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
564
616
  }
565
617
 
@@ -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() {
@@ -1204,11 +1258,12 @@ const _Query = class {
1204
1258
  }
1205
1259
  filter(a, b) {
1206
1260
  if (arguments.length === 1) {
1207
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1261
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
1208
1262
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1209
1263
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1210
1264
  } else {
1211
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1265
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: b }] : void 0;
1266
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1212
1267
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1213
1268
  }
1214
1269
  }
@@ -1348,7 +1403,7 @@ var __privateMethod$2 = (obj, member, method) => {
1348
1403
  __accessCheck$4(obj, member, "access private method");
1349
1404
  return method;
1350
1405
  };
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;
1406
+ 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
1407
  class Repository extends Query {
1353
1408
  }
1354
1409
  class RestRepository extends Query {
@@ -1368,168 +1423,193 @@ class RestRepository extends Query {
1368
1423
  __privateAdd$4(this, _db, void 0);
1369
1424
  __privateAdd$4(this, _cache, void 0);
1370
1425
  __privateAdd$4(this, _schemaTables$2, void 0);
1426
+ __privateAdd$4(this, _trace, void 0);
1371
1427
  __privateSet$4(this, _table, options.table);
1372
1428
  __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1373
1429
  __privateSet$4(this, _db, options.db);
1374
1430
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1375
1431
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1432
+ const trace = options.pluginOptions.trace ?? defaultTrace;
1433
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1434
+ return trace(name, fn, {
1435
+ ...options2,
1436
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1437
+ [TraceAttributes.VERSION]: VERSION
1438
+ });
1439
+ });
1376
1440
  }
1377
1441
  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");
1442
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
1443
+ if (Array.isArray(a)) {
1444
+ if (a.length === 0)
1445
+ return [];
1446
+ const columns = isStringArray(b) ? b : void 0;
1447
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1448
+ }
1449
+ if (isString(a) && isObject(b)) {
1450
+ if (a === "")
1451
+ throw new Error("The id can't be empty");
1452
+ const columns = isStringArray(c) ? c : void 0;
1453
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1454
+ }
1455
+ if (isObject(a) && isString(a.id)) {
1456
+ if (a.id === "")
1457
+ throw new Error("The id can't be empty");
1458
+ const columns = isStringArray(b) ? b : void 0;
1459
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1460
+ }
1461
+ if (isObject(a)) {
1462
+ const columns = isStringArray(b) ? b : void 0;
1463
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1464
+ }
1465
+ throw new Error("Invalid arguments for create method");
1466
+ });
1401
1467
  }
1402
1468
  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;
1469
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
1470
+ const columns = isStringArray(b) ? b : ["*"];
1471
+ if (Array.isArray(a)) {
1472
+ if (a.length === 0)
1473
+ return [];
1474
+ const ids = a.map((item) => extractId(item));
1475
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
1476
+ const dictionary = finalObjects.reduce((acc, object) => {
1477
+ acc[object.id] = object;
1478
+ return acc;
1479
+ }, {});
1480
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1481
+ }
1482
+ const id = extractId(a);
1483
+ if (id) {
1484
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1485
+ try {
1486
+ const response = await getRecord({
1487
+ pathParams: {
1488
+ workspace: "{workspaceId}",
1489
+ dbBranchName: "{dbBranch}",
1490
+ tableName: __privateGet$4(this, _table),
1491
+ recordId: id
1492
+ },
1493
+ queryParams: { columns },
1494
+ ...fetchProps
1495
+ });
1496
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1497
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1498
+ } catch (e) {
1499
+ if (isObject(e) && e.status === 404) {
1500
+ return null;
1501
+ }
1502
+ throw e;
1429
1503
  }
1430
- throw e;
1431
1504
  }
1432
- }
1433
- return null;
1505
+ return null;
1506
+ });
1434
1507
  }
1435
1508
  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");
1509
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
1510
+ if (Array.isArray(a)) {
1511
+ if (a.length === 0)
1512
+ return [];
1513
+ if (a.length > 100) {
1514
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1515
+ }
1516
+ const columns = isStringArray(b) ? b : ["*"];
1517
+ return Promise.all(a.map((object) => this.update(object, columns)));
1441
1518
  }
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");
1519
+ if (isString(a) && isObject(b)) {
1520
+ const columns = isStringArray(c) ? c : void 0;
1521
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1522
+ }
1523
+ if (isObject(a) && isString(a.id)) {
1524
+ const columns = isStringArray(b) ? b : void 0;
1525
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1526
+ }
1527
+ throw new Error("Invalid arguments for update method");
1528
+ });
1454
1529
  }
1455
1530
  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");
1531
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1532
+ if (Array.isArray(a)) {
1533
+ if (a.length === 0)
1534
+ return [];
1535
+ if (a.length > 100) {
1536
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1537
+ }
1538
+ const columns = isStringArray(b) ? b : ["*"];
1539
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1461
1540
  }
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");
1474
- }
1475
- async delete(a) {
1476
- if (Array.isArray(a)) {
1477
- if (a.length === 0)
1478
- 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");
1541
+ if (isString(a) && isObject(b)) {
1542
+ const columns = isStringArray(c) ? c : void 0;
1543
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1481
1544
  }
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");
1545
+ if (isObject(a) && isString(a.id)) {
1546
+ const columns = isStringArray(c) ? c : void 0;
1547
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1548
+ }
1549
+ throw new Error("Invalid arguments for createOrUpdate method");
1550
+ });
1551
+ }
1552
+ async delete(a, b) {
1553
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
1554
+ if (Array.isArray(a)) {
1555
+ if (a.length === 0)
1556
+ return [];
1557
+ if (a.length > 100) {
1558
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1559
+ }
1560
+ return Promise.all(a.map((id) => this.delete(id, b)));
1561
+ }
1562
+ if (isString(a)) {
1563
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1564
+ }
1565
+ if (isObject(a) && isString(a.id)) {
1566
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1567
+ }
1568
+ throw new Error("Invalid arguments for delete method");
1569
+ });
1494
1570
  }
1495
1571
  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
1572
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
1573
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1574
+ const { records } = await searchTable({
1575
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1576
+ body: {
1577
+ query,
1578
+ fuzziness: options.fuzziness,
1579
+ prefix: options.prefix,
1580
+ highlight: options.highlight,
1581
+ filter: options.filter,
1582
+ boosters: options.boosters
1583
+ },
1584
+ ...fetchProps
1585
+ });
1586
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1587
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1508
1588
  });
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
1589
  }
1512
1590
  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
1591
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
1592
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1593
+ if (cacheQuery)
1594
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1595
+ const data = query.getQueryOptions();
1596
+ const body = {
1597
+ filter: cleanFilter(data.filter),
1598
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1599
+ page: data.pagination,
1600
+ columns: data.columns
1601
+ };
1602
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1603
+ const { meta, records: objects } = await queryTable({
1604
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1605
+ body,
1606
+ ...fetchProps
1607
+ });
1608
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1609
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1610
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1611
+ return new Page(query, meta, records);
1528
1612
  });
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
1613
  }
1534
1614
  }
1535
1615
  _table = new WeakMap();
@@ -1537,6 +1617,7 @@ _getFetchProps = new WeakMap();
1537
1617
  _db = new WeakMap();
1538
1618
  _cache = new WeakMap();
1539
1619
  _schemaTables$2 = new WeakMap();
1620
+ _trace = new WeakMap();
1540
1621
  _insertRecordWithoutId = new WeakSet();
1541
1622
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1542
1623
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1592,14 +1673,21 @@ _updateRecordWithID = new WeakSet();
1592
1673
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1593
1674
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1594
1675
  const record = transformObjectLinks(object);
1595
- const response = await updateRecordWithID({
1596
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1597
- queryParams: { columns },
1598
- body: record,
1599
- ...fetchProps
1600
- });
1601
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1602
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1676
+ try {
1677
+ const response = await updateRecordWithID({
1678
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1679
+ queryParams: { columns },
1680
+ body: record,
1681
+ ...fetchProps
1682
+ });
1683
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1684
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1685
+ } catch (e) {
1686
+ if (isObject(e) && e.status === 404) {
1687
+ return null;
1688
+ }
1689
+ throw e;
1690
+ }
1603
1691
  };
1604
1692
  _upsertRecordWithID = new WeakSet();
1605
1693
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1614,12 +1702,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1614
1702
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1615
1703
  };
1616
1704
  _deleteRecord = new WeakSet();
1617
- deleteRecord_fn = async function(recordId) {
1705
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1618
1706
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1619
- await deleteRecord({
1620
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1621
- ...fetchProps
1622
- });
1707
+ try {
1708
+ const response = await deleteRecord({
1709
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1710
+ queryParams: { columns },
1711
+ ...fetchProps
1712
+ });
1713
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1714
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1715
+ } catch (e) {
1716
+ if (isObject(e) && e.status === 404) {
1717
+ return null;
1718
+ }
1719
+ throw e;
1720
+ }
1623
1721
  };
1624
1722
  _setCacheQuery = new WeakSet();
1625
1723
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1707,6 +1805,19 @@ const initObject = (db, schemaTables, table, object) => {
1707
1805
  function isResponseWithRecords(value) {
1708
1806
  return isObject(value) && Array.isArray(value.records);
1709
1807
  }
1808
+ function extractId(value) {
1809
+ if (isString(value))
1810
+ return value;
1811
+ if (isObject(value) && isString(value.id))
1812
+ return value.id;
1813
+ return void 0;
1814
+ }
1815
+ function cleanFilter(filter) {
1816
+ if (!filter)
1817
+ return void 0;
1818
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1819
+ return values.length > 0 ? filter : void 0;
1820
+ }
1710
1821
 
1711
1822
  var __accessCheck$3 = (obj, member, msg) => {
1712
1823
  if (!member.has(obj))
@@ -1757,18 +1868,25 @@ class SimpleCache {
1757
1868
  }
1758
1869
  _map = new WeakMap();
1759
1870
 
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 });
1871
+ const greaterThan = (value) => ({ $gt: value });
1872
+ const gt = greaterThan;
1873
+ const greaterThanEquals = (value) => ({ $ge: value });
1874
+ const greaterEquals = greaterThanEquals;
1875
+ const gte = greaterThanEquals;
1876
+ const ge = greaterThanEquals;
1877
+ const lessThan = (value) => ({ $lt: value });
1878
+ const lt = lessThan;
1879
+ const lessThanEquals = (value) => ({ $le: value });
1880
+ const lessEquals = lessThanEquals;
1881
+ const lte = lessThanEquals;
1882
+ const le = lessThanEquals;
1766
1883
  const exists = (column) => ({ $exists: column });
1767
1884
  const notExists = (column) => ({ $notExists: column });
1768
1885
  const startsWith = (value) => ({ $startsWith: value });
1769
1886
  const endsWith = (value) => ({ $endsWith: value });
1770
1887
  const pattern = (value) => ({ $pattern: value });
1771
1888
  const is = (value) => ({ $is: value });
1889
+ const equals = is;
1772
1890
  const isNot = (value) => ({ $isNot: value });
1773
1891
  const contains = (value) => ({ $contains: value });
1774
1892
  const includes = (value) => ({ $includes: value });
@@ -1945,7 +2063,8 @@ async function resolveXataBranch(gitBranch, options) {
1945
2063
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1946
2064
  workspacesApiUrl: `${protocol}//${host}`,
1947
2065
  pathParams: { dbName, workspace },
1948
- queryParams: { gitBranch, fallbackBranch }
2066
+ queryParams: { gitBranch, fallbackBranch },
2067
+ trace: defaultTrace
1949
2068
  });
1950
2069
  return branch;
1951
2070
  }
@@ -1969,7 +2088,8 @@ async function getDatabaseBranch(branch, options) {
1969
2088
  apiUrl: databaseURL,
1970
2089
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1971
2090
  workspacesApiUrl: `${protocol}//${host}`,
1972
- pathParams: { dbBranchName, workspace }
2091
+ pathParams: { dbBranchName, workspace },
2092
+ trace: defaultTrace
1973
2093
  });
1974
2094
  } catch (err) {
1975
2095
  if (isObject(err) && err.status === 404)
@@ -2021,7 +2141,8 @@ const buildClient = (plugins) => {
2021
2141
  __privateSet(this, _options, safeOptions);
2022
2142
  const pluginOptions = {
2023
2143
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2024
- cache: safeOptions.cache
2144
+ cache: safeOptions.cache,
2145
+ trace: safeOptions.trace
2025
2146
  };
2026
2147
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2027
2148
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2050,12 +2171,16 @@ const buildClient = (plugins) => {
2050
2171
  const databaseURL = options?.databaseURL || getDatabaseURL();
2051
2172
  const apiKey = options?.apiKey || getAPIKey();
2052
2173
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2174
+ const trace = options?.trace ?? defaultTrace;
2053
2175
  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");
2176
+ if (!apiKey) {
2177
+ throw new Error("Option apiKey is required");
2056
2178
  }
2057
- return { fetch, databaseURL, apiKey, branch, cache };
2058
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
2179
+ if (!databaseURL) {
2180
+ throw new Error("Option databaseURL is required");
2181
+ }
2182
+ return { fetch, databaseURL, apiKey, branch, cache, trace };
2183
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2059
2184
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2060
2185
  if (!branchValue)
2061
2186
  throw new Error("Unable to resolve branch value");
@@ -2067,7 +2192,8 @@ const buildClient = (plugins) => {
2067
2192
  const hasBranch = params.dbBranchName ?? params.branch;
2068
2193
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2069
2194
  return databaseURL + newPath;
2070
- }
2195
+ },
2196
+ trace
2071
2197
  };
2072
2198
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2073
2199
  if (__privateGet(this, _branch))
@@ -2221,6 +2347,7 @@ exports.deleteUserAPIKey = deleteUserAPIKey;
2221
2347
  exports.deleteWorkspace = deleteWorkspace;
2222
2348
  exports.deserialize = deserialize;
2223
2349
  exports.endsWith = endsWith;
2350
+ exports.equals = equals;
2224
2351
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2225
2352
  exports.exists = exists;
2226
2353
  exports.ge = ge;
@@ -2246,6 +2373,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2246
2373
  exports.getWorkspace = getWorkspace;
2247
2374
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2248
2375
  exports.getWorkspacesList = getWorkspacesList;
2376
+ exports.greaterEquals = greaterEquals;
2377
+ exports.greaterThan = greaterThan;
2378
+ exports.greaterThanEquals = greaterThanEquals;
2249
2379
  exports.gt = gt;
2250
2380
  exports.gte = gte;
2251
2381
  exports.includes = includes;
@@ -2261,6 +2391,9 @@ exports.isIdentifiable = isIdentifiable;
2261
2391
  exports.isNot = isNot;
2262
2392
  exports.isXataRecord = isXataRecord;
2263
2393
  exports.le = le;
2394
+ exports.lessEquals = lessEquals;
2395
+ exports.lessThan = lessThan;
2396
+ exports.lessThanEquals = lessThanEquals;
2264
2397
  exports.lt = lt;
2265
2398
  exports.lte = lte;
2266
2399
  exports.notExists = notExists;