@xata.io/client 0.0.0-alpha.vec0bff6 → 0.0.0-alpha.vec88a57

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
  }
@@ -150,7 +174,7 @@ function getFetchImplementation(userFetch) {
150
174
  return fetchImpl;
151
175
  }
152
176
 
153
- const VERSION = "0.0.0-alpha.vec0bff6";
177
+ const VERSION = "0.0.0-alpha.vec88a57";
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
 
@@ -351,6 +403,11 @@ const deleteDatabase = (variables) => fetch$1({
351
403
  method: "delete",
352
404
  ...variables
353
405
  });
406
+ const getDatabaseMetadata = (variables) => fetch$1({
407
+ url: "/dbs/{dbName}/metadata",
408
+ method: "get",
409
+ ...variables
410
+ });
354
411
  const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
355
412
  const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
356
413
  const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
@@ -489,6 +546,7 @@ const operationsByTag = {
489
546
  getDatabaseList,
490
547
  createDatabase,
491
548
  deleteDatabase,
549
+ getDatabaseMetadata,
492
550
  getGitBranchesMapping,
493
551
  addGitBranchesEntry,
494
552
  removeGitBranchesEntry,
@@ -581,7 +639,8 @@ class XataApiClient {
581
639
  __privateAdd$7(this, _extraProps, void 0);
582
640
  __privateAdd$7(this, _namespaces, {});
583
641
  const provider = options.host ?? "production";
584
- const apiKey = options?.apiKey ?? getAPIKey();
642
+ const apiKey = options.apiKey ?? getAPIKey();
643
+ const trace = options.trace ?? defaultTrace;
585
644
  if (!apiKey) {
586
645
  throw new Error("Could not resolve a valid apiKey");
587
646
  }
@@ -589,7 +648,8 @@ class XataApiClient {
589
648
  apiUrl: getHostUrl(provider, "main"),
590
649
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
591
650
  fetchImpl: getFetchImplementation(options.fetch),
592
- apiKey
651
+ apiKey,
652
+ trace
593
653
  });
594
654
  }
595
655
  get user() {
@@ -761,6 +821,12 @@ class DatabaseApi {
761
821
  ...this.extraProps
762
822
  });
763
823
  }
824
+ getDatabaseMetadata(workspace, dbName) {
825
+ return operationsByTag.database.getDatabaseMetadata({
826
+ pathParams: { workspace, dbName },
827
+ ...this.extraProps
828
+ });
829
+ }
764
830
  getGitBranchesMapping(workspace, dbName) {
765
831
  return operationsByTag.database.getGitBranchesMapping({
766
832
  pathParams: { workspace, dbName },
@@ -1200,7 +1266,7 @@ const _Query = class {
1200
1266
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1201
1267
  }
1202
1268
  }
1203
- sort(column, direction) {
1269
+ sort(column, direction = "asc") {
1204
1270
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1205
1271
  const sort = [...originalSort, { column, direction }];
1206
1272
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
@@ -1336,7 +1402,7 @@ var __privateMethod$2 = (obj, member, method) => {
1336
1402
  __accessCheck$4(obj, member, "access private method");
1337
1403
  return method;
1338
1404
  };
1339
- 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;
1340
1406
  class Repository extends Query {
1341
1407
  }
1342
1408
  class RestRepository extends Query {
@@ -1356,168 +1422,196 @@ class RestRepository extends Query {
1356
1422
  __privateAdd$4(this, _db, void 0);
1357
1423
  __privateAdd$4(this, _cache, void 0);
1358
1424
  __privateAdd$4(this, _schemaTables$2, void 0);
1425
+ __privateAdd$4(this, _trace, void 0);
1359
1426
  __privateSet$4(this, _table, options.table);
1360
1427
  __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1361
1428
  __privateSet$4(this, _db, options.db);
1362
1429
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1363
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
+ });
1364
1439
  }
1365
1440
  async create(a, b, c) {
1366
- if (Array.isArray(a)) {
1367
- if (a.length === 0)
1368
- return [];
1369
- const columns = isStringArray(b) ? b : void 0;
1370
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1371
- }
1372
- if (isString(a) && isObject(b)) {
1373
- if (a === "")
1374
- throw new Error("The id can't be empty");
1375
- const columns = isStringArray(c) ? c : void 0;
1376
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1377
- }
1378
- if (isObject(a) && isString(a.id)) {
1379
- if (a.id === "")
1380
- throw new Error("The id can't be empty");
1381
- const columns = isStringArray(b) ? b : void 0;
1382
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1383
- }
1384
- if (isObject(a)) {
1385
- const columns = isStringArray(b) ? b : void 0;
1386
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1387
- }
1388
- 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
+ });
1389
1466
  }
1390
1467
  async read(a, b) {
1391
- const columns = isStringArray(b) ? b : ["*"];
1392
- if (Array.isArray(a)) {
1393
- if (a.length === 0)
1394
- return [];
1395
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1396
- const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1397
- const dictionary = finalObjects.reduce((acc, object) => {
1398
- acc[object.id] = object;
1399
- return acc;
1400
- }, {});
1401
- return ids.map((id2) => dictionary[id2] ?? null);
1402
- }
1403
- const id = isString(a) ? a : a.id;
1404
- if (isString(id)) {
1405
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1406
- try {
1407
- const response = await getRecord({
1408
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1409
- queryParams: { columns },
1410
- ...fetchProps
1411
- });
1412
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1413
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1414
- } catch (e) {
1415
- if (isObject(e) && e.status === 404) {
1416
- 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;
1417
1502
  }
1418
- throw e;
1419
1503
  }
1420
- }
1421
- return null;
1504
+ return null;
1505
+ });
1422
1506
  }
1423
1507
  async update(a, b, c) {
1424
- if (Array.isArray(a)) {
1425
- if (a.length === 0)
1426
- return [];
1427
- if (a.length > 100) {
1428
- 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)));
1429
1517
  }
1430
- const columns = isStringArray(b) ? b : ["*"];
1431
- return Promise.all(a.map((object) => this.update(object, columns)));
1432
- }
1433
- if (isString(a) && isObject(b)) {
1434
- const columns = isStringArray(c) ? c : void 0;
1435
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1436
- }
1437
- if (isObject(a) && isString(a.id)) {
1438
- const columns = isStringArray(b) ? b : void 0;
1439
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1440
- }
1441
- 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
+ });
1442
1528
  }
1443
1529
  async createOrUpdate(a, b, c) {
1444
- if (Array.isArray(a)) {
1445
- if (a.length === 0)
1446
- return [];
1447
- if (a.length > 100) {
1448
- 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)));
1449
1539
  }
1450
- const columns = isStringArray(b) ? b : ["*"];
1451
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1452
- }
1453
- if (isString(a) && isObject(b)) {
1454
- const columns = isStringArray(c) ? c : void 0;
1455
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1456
- }
1457
- if (isObject(a) && isString(a.id)) {
1458
- const columns = isStringArray(c) ? c : void 0;
1459
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1460
- }
1461
- 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
+ });
1462
1550
  }
1463
1551
  async delete(a) {
1464
- if (Array.isArray(a)) {
1465
- 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)));
1466
1560
  return;
1467
- if (a.length > 100) {
1468
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1469
1561
  }
1470
- await Promise.all(a.map((id) => this.delete(id)));
1471
- return;
1472
- }
1473
- if (isString(a)) {
1474
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1475
- return;
1476
- }
1477
- if (isObject(a) && isString(a.id)) {
1478
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1479
- return;
1480
- }
1481
- 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
+ });
1482
1572
  }
1483
1573
  async search(query, options = {}) {
1484
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1485
- const { records } = await searchTable({
1486
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1487
- body: {
1488
- query,
1489
- fuzziness: options.fuzziness,
1490
- prefix: options.prefix,
1491
- highlight: options.highlight,
1492
- filter: options.filter,
1493
- boosters: options.boosters
1494
- },
1495
- ...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));
1496
1590
  });
1497
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1498
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1499
1591
  }
1500
1592
  async query(query) {
1501
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1502
- if (cacheQuery)
1503
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1504
- const data = query.getQueryOptions();
1505
- const body = {
1506
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1507
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1508
- page: data.pagination,
1509
- columns: data.columns
1510
- };
1511
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1512
- const { meta, records: objects } = await queryTable({
1513
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1514
- body,
1515
- ...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);
1516
1614
  });
1517
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1518
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1519
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1520
- return new Page(query, meta, records);
1521
1615
  }
1522
1616
  }
1523
1617
  _table = new WeakMap();
@@ -1525,6 +1619,7 @@ _getFetchProps = new WeakMap();
1525
1619
  _db = new WeakMap();
1526
1620
  _cache = new WeakMap();
1527
1621
  _schemaTables$2 = new WeakMap();
1622
+ _trace = new WeakMap();
1528
1623
  _insertRecordWithoutId = new WeakSet();
1529
1624
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1530
1625
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1745,18 +1840,25 @@ class SimpleCache {
1745
1840
  }
1746
1841
  _map = new WeakMap();
1747
1842
 
1748
- const gt = (value) => ({ $gt: value });
1749
- const ge = (value) => ({ $ge: value });
1750
- const gte = (value) => ({ $ge: value });
1751
- const lt = (value) => ({ $lt: value });
1752
- const lte = (value) => ({ $le: value });
1753
- 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;
1754
1855
  const exists = (column) => ({ $exists: column });
1755
1856
  const notExists = (column) => ({ $notExists: column });
1756
1857
  const startsWith = (value) => ({ $startsWith: value });
1757
1858
  const endsWith = (value) => ({ $endsWith: value });
1758
1859
  const pattern = (value) => ({ $pattern: value });
1759
1860
  const is = (value) => ({ $is: value });
1861
+ const equals = is;
1760
1862
  const isNot = (value) => ({ $isNot: value });
1761
1863
  const contains = (value) => ({ $contains: value });
1762
1864
  const includes = (value) => ({ $includes: value });
@@ -1933,7 +2035,8 @@ async function resolveXataBranch(gitBranch, options) {
1933
2035
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1934
2036
  workspacesApiUrl: `${protocol}//${host}`,
1935
2037
  pathParams: { dbName, workspace },
1936
- queryParams: { gitBranch, fallbackBranch }
2038
+ queryParams: { gitBranch, fallbackBranch },
2039
+ trace: defaultTrace
1937
2040
  });
1938
2041
  return branch;
1939
2042
  }
@@ -1957,7 +2060,8 @@ async function getDatabaseBranch(branch, options) {
1957
2060
  apiUrl: databaseURL,
1958
2061
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1959
2062
  workspacesApiUrl: `${protocol}//${host}`,
1960
- pathParams: { dbBranchName, workspace }
2063
+ pathParams: { dbBranchName, workspace },
2064
+ trace: defaultTrace
1961
2065
  });
1962
2066
  } catch (err) {
1963
2067
  if (isObject(err) && err.status === 404)
@@ -2009,7 +2113,8 @@ const buildClient = (plugins) => {
2009
2113
  __privateSet(this, _options, safeOptions);
2010
2114
  const pluginOptions = {
2011
2115
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2012
- cache: safeOptions.cache
2116
+ cache: safeOptions.cache,
2117
+ trace: safeOptions.trace
2013
2118
  };
2014
2119
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2015
2120
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2038,12 +2143,16 @@ const buildClient = (plugins) => {
2038
2143
  const databaseURL = options?.databaseURL || getDatabaseURL();
2039
2144
  const apiKey = options?.apiKey || getAPIKey();
2040
2145
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2146
+ const trace = options?.trace ?? defaultTrace;
2041
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 });
2042
- if (!databaseURL || !apiKey) {
2043
- 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");
2044
2153
  }
2045
- return { fetch, databaseURL, apiKey, branch, cache };
2046
- }, _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 }) {
2047
2156
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2048
2157
  if (!branchValue)
2049
2158
  throw new Error("Unable to resolve branch value");
@@ -2055,7 +2164,8 @@ const buildClient = (plugins) => {
2055
2164
  const hasBranch = params.dbBranchName ?? params.branch;
2056
2165
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2057
2166
  return databaseURL + newPath;
2058
- }
2167
+ },
2168
+ trace
2059
2169
  };
2060
2170
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2061
2171
  if (__privateGet(this, _branch))
@@ -2078,6 +2188,88 @@ const buildClient = (plugins) => {
2078
2188
  class BaseClient extends buildClient() {
2079
2189
  }
2080
2190
 
2191
+ const META = "__";
2192
+ const VALUE = "___";
2193
+ class Serializer {
2194
+ constructor() {
2195
+ this.classes = {};
2196
+ }
2197
+ add(clazz) {
2198
+ this.classes[clazz.name] = clazz;
2199
+ }
2200
+ toJSON(data) {
2201
+ function visit(obj) {
2202
+ if (Array.isArray(obj))
2203
+ return obj.map(visit);
2204
+ const type = typeof obj;
2205
+ if (type === "undefined")
2206
+ return { [META]: "undefined" };
2207
+ if (type === "bigint")
2208
+ return { [META]: "bigint", [VALUE]: obj.toString() };
2209
+ if (obj === null || type !== "object")
2210
+ return obj;
2211
+ const constructor = obj.constructor;
2212
+ const o = { [META]: constructor.name };
2213
+ for (const [key, value] of Object.entries(obj)) {
2214
+ o[key] = visit(value);
2215
+ }
2216
+ if (constructor === Date)
2217
+ o[VALUE] = obj.toISOString();
2218
+ if (constructor === Map)
2219
+ o[VALUE] = Object.fromEntries(obj);
2220
+ if (constructor === Set)
2221
+ o[VALUE] = [...obj];
2222
+ return o;
2223
+ }
2224
+ return JSON.stringify(visit(data));
2225
+ }
2226
+ fromJSON(json) {
2227
+ return JSON.parse(json, (key, value) => {
2228
+ if (value && typeof value === "object" && !Array.isArray(value)) {
2229
+ const { [META]: clazz, [VALUE]: val, ...rest } = value;
2230
+ const constructor = this.classes[clazz];
2231
+ if (constructor) {
2232
+ return Object.assign(Object.create(constructor.prototype), rest);
2233
+ }
2234
+ if (clazz === "Date")
2235
+ return new Date(val);
2236
+ if (clazz === "Set")
2237
+ return new Set(val);
2238
+ if (clazz === "Map")
2239
+ return new Map(Object.entries(val));
2240
+ if (clazz === "bigint")
2241
+ return BigInt(val);
2242
+ if (clazz === "undefined")
2243
+ return void 0;
2244
+ return rest;
2245
+ }
2246
+ return value;
2247
+ });
2248
+ }
2249
+ }
2250
+ const defaultSerializer = new Serializer();
2251
+ const serialize = (data) => {
2252
+ return defaultSerializer.toJSON(data);
2253
+ };
2254
+ const deserialize = (json) => {
2255
+ return defaultSerializer.fromJSON(json);
2256
+ };
2257
+
2258
+ function buildWorkerRunner(config) {
2259
+ return function xataWorker(name, _worker) {
2260
+ return async (...args) => {
2261
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2262
+ const result = await fetch(url, {
2263
+ method: "POST",
2264
+ headers: { "Content-Type": "application/json" },
2265
+ body: serialize({ args })
2266
+ });
2267
+ const text = await result.text();
2268
+ return deserialize(text);
2269
+ };
2270
+ };
2271
+ }
2272
+
2081
2273
  class XataError extends Error {
2082
2274
  constructor(message, status) {
2083
2275
  super(message);
@@ -2098,6 +2290,7 @@ exports.Repository = Repository;
2098
2290
  exports.RestRepository = RestRepository;
2099
2291
  exports.SchemaPlugin = SchemaPlugin;
2100
2292
  exports.SearchPlugin = SearchPlugin;
2293
+ exports.Serializer = Serializer;
2101
2294
  exports.SimpleCache = SimpleCache;
2102
2295
  exports.XataApiClient = XataApiClient;
2103
2296
  exports.XataApiPlugin = XataApiPlugin;
@@ -2107,6 +2300,7 @@ exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2107
2300
  exports.addGitBranchesEntry = addGitBranchesEntry;
2108
2301
  exports.addTableColumn = addTableColumn;
2109
2302
  exports.buildClient = buildClient;
2303
+ exports.buildWorkerRunner = buildWorkerRunner;
2110
2304
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2111
2305
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2112
2306
  exports.contains = contains;
@@ -2123,7 +2317,9 @@ exports.deleteTable = deleteTable;
2123
2317
  exports.deleteUser = deleteUser;
2124
2318
  exports.deleteUserAPIKey = deleteUserAPIKey;
2125
2319
  exports.deleteWorkspace = deleteWorkspace;
2320
+ exports.deserialize = deserialize;
2126
2321
  exports.endsWith = endsWith;
2322
+ exports.equals = equals;
2127
2323
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2128
2324
  exports.exists = exists;
2129
2325
  exports.ge = ge;
@@ -2138,6 +2334,7 @@ exports.getColumn = getColumn;
2138
2334
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
2139
2335
  exports.getCurrentBranchName = getCurrentBranchName;
2140
2336
  exports.getDatabaseList = getDatabaseList;
2337
+ exports.getDatabaseMetadata = getDatabaseMetadata;
2141
2338
  exports.getDatabaseURL = getDatabaseURL;
2142
2339
  exports.getGitBranchesMapping = getGitBranchesMapping;
2143
2340
  exports.getRecord = getRecord;
@@ -2148,6 +2345,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2148
2345
  exports.getWorkspace = getWorkspace;
2149
2346
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2150
2347
  exports.getWorkspacesList = getWorkspacesList;
2348
+ exports.greaterEquals = greaterEquals;
2349
+ exports.greaterThan = greaterThan;
2350
+ exports.greaterThanEquals = greaterThanEquals;
2151
2351
  exports.gt = gt;
2152
2352
  exports.gte = gte;
2153
2353
  exports.includes = includes;
@@ -2163,6 +2363,9 @@ exports.isIdentifiable = isIdentifiable;
2163
2363
  exports.isNot = isNot;
2164
2364
  exports.isXataRecord = isXataRecord;
2165
2365
  exports.le = le;
2366
+ exports.lessEquals = lessEquals;
2367
+ exports.lessThan = lessThan;
2368
+ exports.lessThanEquals = lessThanEquals;
2166
2369
  exports.lt = lt;
2167
2370
  exports.lte = lte;
2168
2371
  exports.notExists = notExists;
@@ -2175,6 +2378,7 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
2175
2378
  exports.resolveBranch = resolveBranch;
2176
2379
  exports.searchBranch = searchBranch;
2177
2380
  exports.searchTable = searchTable;
2381
+ exports.serialize = serialize;
2178
2382
  exports.setTableSchema = setTableSchema;
2179
2383
  exports.startsWith = startsWith;
2180
2384
  exports.updateBranchMetadata = updateBranchMetadata;