@xata.io/client 0.0.0-alpha.vf4789c2 → 0.0.0-alpha.vf5ce72f

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
  }
@@ -35,6 +59,9 @@ function isDefined(value) {
35
59
  function isString(value) {
36
60
  return isDefined(value) && typeof value === "string";
37
61
  }
62
+ function isStringArray(value) {
63
+ return isDefined(value) && Array.isArray(value) && value.every(isString);
64
+ }
38
65
  function toBase64(value) {
39
66
  try {
40
67
  return btoa(value);
@@ -140,12 +167,14 @@ function getFetchImplementation(userFetch) {
140
167
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
141
168
  const fetchImpl = userFetch ?? globalFetch;
142
169
  if (!fetchImpl) {
143
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
170
+ throw new Error(
171
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
172
+ );
144
173
  }
145
174
  return fetchImpl;
146
175
  }
147
176
 
148
- const VERSION = "0.0.0-alpha.vf4789c2";
177
+ const VERSION = "0.0.0-alpha.vf5ce72f";
149
178
 
150
179
  class ErrorWithCause extends Error {
151
180
  constructor(message, options) {
@@ -224,34 +253,62 @@ async function fetch$1({
224
253
  fetchImpl,
225
254
  apiKey,
226
255
  apiUrl,
227
- workspacesApiUrl
256
+ workspacesApiUrl,
257
+ trace
228
258
  }) {
229
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
230
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
231
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
232
- const response = await fetchImpl(url, {
233
- method: method.toUpperCase(),
234
- body: body ? JSON.stringify(body) : void 0,
235
- headers: {
236
- "Content-Type": "application/json",
237
- "User-Agent": `Xata client-ts/${VERSION}`,
238
- ...headers,
239
- ...hostHeader(fullUrl),
240
- Authorization: `Bearer ${apiKey}`
241
- }
242
- });
243
- if (response.status === 204) {
244
- return {};
245
- }
246
- 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) {
247
307
  try {
248
- const jsonResponse = await response.json();
249
- if (response.ok) {
250
- return jsonResponse;
251
- }
252
- throw new FetcherError(response.status, jsonResponse, requestId);
308
+ const { host, protocol } = new URL(url);
309
+ return { host, protocol };
253
310
  } catch (error) {
254
- throw new FetcherError(response.status, error, requestId);
311
+ return {};
255
312
  }
256
313
  }
257
314
 
@@ -346,6 +403,11 @@ const deleteDatabase = (variables) => fetch$1({
346
403
  method: "delete",
347
404
  ...variables
348
405
  });
406
+ const getDatabaseMetadata = (variables) => fetch$1({
407
+ url: "/dbs/{dbName}/metadata",
408
+ method: "get",
409
+ ...variables
410
+ });
349
411
  const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
350
412
  const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
351
413
  const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
@@ -359,11 +421,7 @@ const getBranchDetails = (variables) => fetch$1({
359
421
  method: "get",
360
422
  ...variables
361
423
  });
362
- const createBranch = (variables) => fetch$1({
363
- url: "/db/{dbBranchName}",
364
- method: "put",
365
- ...variables
366
- });
424
+ const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
367
425
  const deleteBranch = (variables) => fetch$1({
368
426
  url: "/db/{dbBranchName}",
369
427
  method: "delete",
@@ -437,11 +495,7 @@ const updateColumn = (variables) => fetch$1({
437
495
  method: "patch",
438
496
  ...variables
439
497
  });
440
- const insertRecord = (variables) => fetch$1({
441
- url: "/db/{dbBranchName}/tables/{tableName}/data",
442
- method: "post",
443
- ...variables
444
- });
498
+ const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
445
499
  const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
446
500
  const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
447
501
  const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
@@ -492,6 +546,7 @@ const operationsByTag = {
492
546
  getDatabaseList,
493
547
  createDatabase,
494
548
  deleteDatabase,
549
+ getDatabaseMetadata,
495
550
  getGitBranchesMapping,
496
551
  addGitBranchesEntry,
497
552
  removeGitBranchesEntry,
@@ -584,7 +639,8 @@ class XataApiClient {
584
639
  __privateAdd$7(this, _extraProps, void 0);
585
640
  __privateAdd$7(this, _namespaces, {});
586
641
  const provider = options.host ?? "production";
587
- const apiKey = options?.apiKey ?? getAPIKey();
642
+ const apiKey = options.apiKey ?? getAPIKey();
643
+ const trace = options.trace ?? defaultTrace;
588
644
  if (!apiKey) {
589
645
  throw new Error("Could not resolve a valid apiKey");
590
646
  }
@@ -592,7 +648,8 @@ class XataApiClient {
592
648
  apiUrl: getHostUrl(provider, "main"),
593
649
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
594
650
  fetchImpl: getFetchImplementation(options.fetch),
595
- apiKey
651
+ apiKey,
652
+ trace
596
653
  });
597
654
  }
598
655
  get user() {
@@ -764,6 +821,12 @@ class DatabaseApi {
764
821
  ...this.extraProps
765
822
  });
766
823
  }
824
+ getDatabaseMetadata(workspace, dbName) {
825
+ return operationsByTag.database.getDatabaseMetadata({
826
+ pathParams: { workspace, dbName },
827
+ ...this.extraProps
828
+ });
829
+ }
767
830
  getGitBranchesMapping(workspace, dbName) {
768
831
  return operationsByTag.database.getGitBranchesMapping({
769
832
  pathParams: { workspace, dbName },
@@ -936,9 +999,10 @@ class RecordsApi {
936
999
  constructor(extraProps) {
937
1000
  this.extraProps = extraProps;
938
1001
  }
939
- insertRecord(workspace, database, branch, tableName, record) {
1002
+ insertRecord(workspace, database, branch, tableName, record, options = {}) {
940
1003
  return operationsByTag.records.insertRecord({
941
1004
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1005
+ queryParams: options,
942
1006
  body: record,
943
1007
  ...this.extraProps
944
1008
  });
@@ -967,21 +1031,24 @@ class RecordsApi {
967
1031
  ...this.extraProps
968
1032
  });
969
1033
  }
970
- deleteRecord(workspace, database, branch, tableName, recordId) {
1034
+ deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
971
1035
  return operationsByTag.records.deleteRecord({
972
1036
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1037
+ queryParams: options,
973
1038
  ...this.extraProps
974
1039
  });
975
1040
  }
976
1041
  getRecord(workspace, database, branch, tableName, recordId, options = {}) {
977
1042
  return operationsByTag.records.getRecord({
978
1043
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1044
+ queryParams: options,
979
1045
  ...this.extraProps
980
1046
  });
981
1047
  }
982
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
1048
+ bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
983
1049
  return operationsByTag.records.bulkInsertTableRecords({
984
1050
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1051
+ queryParams: options,
985
1052
  body: { records },
986
1053
  ...this.extraProps
987
1054
  });
@@ -1199,13 +1266,18 @@ const _Query = class {
1199
1266
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1200
1267
  }
1201
1268
  }
1202
- sort(column, direction) {
1269
+ sort(column, direction = "asc") {
1203
1270
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1204
1271
  const sort = [...originalSort, { column, direction }];
1205
1272
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
1206
1273
  }
1207
1274
  select(columns) {
1208
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { columns }, __privateGet$5(this, _data));
1275
+ return new _Query(
1276
+ __privateGet$5(this, _repository),
1277
+ __privateGet$5(this, _table$1),
1278
+ { columns },
1279
+ __privateGet$5(this, _data)
1280
+ );
1209
1281
  }
1210
1282
  getPaginated(options = {}) {
1211
1283
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
@@ -1330,7 +1402,7 @@ var __privateMethod$2 = (obj, member, method) => {
1330
1402
  __accessCheck$4(obj, member, "access private method");
1331
1403
  return method;
1332
1404
  };
1333
- var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_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;
1334
1406
  class Repository extends Query {
1335
1407
  }
1336
1408
  class RestRepository extends Query {
@@ -1342,191 +1414,211 @@ class RestRepository extends Query {
1342
1414
  __privateAdd$4(this, _updateRecordWithID);
1343
1415
  __privateAdd$4(this, _upsertRecordWithID);
1344
1416
  __privateAdd$4(this, _deleteRecord);
1345
- __privateAdd$4(this, _invalidateCache);
1346
- __privateAdd$4(this, _setCacheRecord);
1347
- __privateAdd$4(this, _getCacheRecord);
1348
1417
  __privateAdd$4(this, _setCacheQuery);
1349
1418
  __privateAdd$4(this, _getCacheQuery);
1350
1419
  __privateAdd$4(this, _getSchemaTables$1);
1351
1420
  __privateAdd$4(this, _table, void 0);
1352
1421
  __privateAdd$4(this, _getFetchProps, void 0);
1422
+ __privateAdd$4(this, _db, void 0);
1353
1423
  __privateAdd$4(this, _cache, void 0);
1354
1424
  __privateAdd$4(this, _schemaTables$2, void 0);
1425
+ __privateAdd$4(this, _trace, void 0);
1355
1426
  __privateSet$4(this, _table, options.table);
1356
1427
  __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1357
- this.db = options.db;
1428
+ __privateSet$4(this, _db, options.db);
1358
1429
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1359
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
+ });
1360
1439
  }
1361
- async create(a, b) {
1362
- if (Array.isArray(a)) {
1363
- if (a.length === 0)
1364
- return [];
1365
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1366
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1367
- return records;
1368
- }
1369
- if (isString(a) && isObject(b)) {
1370
- if (a === "")
1371
- throw new Error("The id can't be empty");
1372
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1373
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1374
- return record;
1375
- }
1376
- if (isObject(a) && isString(a.id)) {
1377
- if (a.id === "")
1378
- throw new Error("The id can't be empty");
1379
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1380
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1381
- return record;
1382
- }
1383
- if (isObject(a)) {
1384
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1385
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1386
- return record;
1387
- }
1388
- throw new Error("Invalid arguments for create method");
1389
- }
1390
- async read(a) {
1391
- if (Array.isArray(a)) {
1392
- if (a.length === 0)
1393
- return [];
1394
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1395
- return this.getAll({ filter: { id: { $any: ids } } });
1396
- }
1397
- const id = isString(a) ? a : a.id;
1398
- if (isString(id)) {
1399
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
1400
- if (cacheRecord)
1401
- return cacheRecord;
1402
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1403
- try {
1404
- const response = await getRecord({
1405
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1406
- ...fetchProps
1407
- });
1408
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1409
- return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1410
- } catch (e) {
1411
- if (isObject(e) && e.status === 404) {
1412
- return null;
1440
+ async create(a, b, c) {
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
+ });
1466
+ }
1467
+ async read(a, b) {
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) => extractId(item));
1474
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(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 = extractId(a);
1482
+ if (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;
1413
1502
  }
1414
- throw e;
1415
1503
  }
1416
- }
1504
+ return null;
1505
+ });
1417
1506
  }
1418
- async update(a, b) {
1419
- if (Array.isArray(a)) {
1420
- if (a.length === 0)
1421
- return [];
1422
- if (a.length > 100) {
1423
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1507
+ async update(a, b, c) {
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)));
1424
1517
  }
1425
- return Promise.all(a.map((object) => this.update(object)));
1426
- }
1427
- if (isString(a) && isObject(b)) {
1428
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1429
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1430
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1431
- return record;
1432
- }
1433
- if (isObject(a) && isString(a.id)) {
1434
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1435
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1436
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1437
- return record;
1438
- }
1439
- throw new Error("Invalid arguments for update method");
1440
- }
1441
- async createOrUpdate(a, b) {
1442
- if (Array.isArray(a)) {
1443
- if (a.length === 0)
1444
- return [];
1445
- if (a.length > 100) {
1446
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
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);
1447
1521
  }
1448
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1449
- }
1450
- if (isString(a) && isObject(b)) {
1451
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1452
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1453
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1454
- return record;
1455
- }
1456
- if (isObject(a) && isString(a.id)) {
1457
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1458
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1459
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1460
- return record;
1461
- }
1462
- throw new Error("Invalid arguments for createOrUpdate method");
1463
- }
1464
- async delete(a) {
1465
- if (Array.isArray(a)) {
1466
- if (a.length === 0)
1467
- return;
1468
- if (a.length > 100) {
1469
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
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);
1470
1525
  }
1471
- await Promise.all(a.map((id) => this.delete(id)));
1472
- return;
1473
- }
1474
- if (isString(a)) {
1475
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1476
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1477
- return;
1478
- }
1479
- if (isObject(a) && isString(a.id)) {
1480
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1481
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1482
- return;
1483
- }
1484
- throw new Error("Invalid arguments for delete method");
1526
+ throw new Error("Invalid arguments for update method");
1527
+ });
1528
+ }
1529
+ async createOrUpdate(a, b, c) {
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)));
1539
+ }
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
+ });
1550
+ }
1551
+ async delete(a, b) {
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
+ return Promise.all(a.map((id) => this.delete(id, b)));
1560
+ }
1561
+ if (isString(a)) {
1562
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1563
+ }
1564
+ if (isObject(a) && isString(a.id)) {
1565
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1566
+ }
1567
+ throw new Error("Invalid arguments for delete method");
1568
+ });
1485
1569
  }
1486
1570
  async search(query, options = {}) {
1487
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1488
- const { records } = await searchTable({
1489
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1490
- body: {
1491
- query,
1492
- fuzziness: options.fuzziness,
1493
- highlight: options.highlight,
1494
- filter: options.filter
1495
- },
1496
- ...fetchProps
1571
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
1572
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1573
+ const { records } = await searchTable({
1574
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1575
+ body: {
1576
+ query,
1577
+ fuzziness: options.fuzziness,
1578
+ prefix: options.prefix,
1579
+ highlight: options.highlight,
1580
+ filter: options.filter,
1581
+ boosters: options.boosters
1582
+ },
1583
+ ...fetchProps
1584
+ });
1585
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1586
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1497
1587
  });
1498
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1499
- return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1500
1588
  }
1501
1589
  async query(query) {
1502
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1503
- if (cacheQuery)
1504
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1505
- const data = query.getQueryOptions();
1506
- const body = {
1507
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1508
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1509
- page: data.pagination,
1510
- columns: data.columns
1511
- };
1512
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1513
- const { meta, records: objects } = await queryTable({
1514
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1515
- body,
1516
- ...fetchProps
1590
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
1591
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1592
+ if (cacheQuery)
1593
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1594
+ const data = query.getQueryOptions();
1595
+ const body = {
1596
+ filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1597
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1598
+ page: data.pagination,
1599
+ columns: data.columns
1600
+ };
1601
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1602
+ const { meta, records: objects } = await queryTable({
1603
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1604
+ body,
1605
+ ...fetchProps
1606
+ });
1607
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1608
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1609
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1610
+ return new Page(query, meta, records);
1517
1611
  });
1518
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1519
- const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
1520
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1521
- return new Page(query, meta, records);
1522
1612
  }
1523
1613
  }
1524
1614
  _table = new WeakMap();
1525
1615
  _getFetchProps = new WeakMap();
1616
+ _db = new WeakMap();
1526
1617
  _cache = new WeakMap();
1527
1618
  _schemaTables$2 = new WeakMap();
1619
+ _trace = new WeakMap();
1528
1620
  _insertRecordWithoutId = new WeakSet();
1529
- insertRecordWithoutId_fn = async function(object) {
1621
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1530
1622
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1531
1623
  const record = transformObjectLinks(object);
1532
1624
  const response = await insertRecord({
@@ -1535,17 +1627,15 @@ insertRecordWithoutId_fn = async function(object) {
1535
1627
  dbBranchName: "{dbBranch}",
1536
1628
  tableName: __privateGet$4(this, _table)
1537
1629
  },
1630
+ queryParams: { columns },
1538
1631
  body: record,
1539
1632
  ...fetchProps
1540
1633
  });
1541
- const finalObject = await this.read(response.id);
1542
- if (!finalObject) {
1543
- throw new Error("The server failed to save the record");
1544
- }
1545
- return finalObject;
1634
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1635
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1546
1636
  };
1547
1637
  _insertRecordWithId = new WeakSet();
1548
- insertRecordWithId_fn = async function(recordId, object) {
1638
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1549
1639
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1550
1640
  const record = transformObjectLinks(object);
1551
1641
  const response = await insertRecordWithID({
@@ -1556,92 +1646,78 @@ insertRecordWithId_fn = async function(recordId, object) {
1556
1646
  recordId
1557
1647
  },
1558
1648
  body: record,
1559
- queryParams: { createOnly: true },
1649
+ queryParams: { createOnly: true, columns },
1560
1650
  ...fetchProps
1561
1651
  });
1562
- const finalObject = await this.read(response.id);
1563
- if (!finalObject) {
1564
- throw new Error("The server failed to save the record");
1565
- }
1566
- return finalObject;
1652
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1653
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1567
1654
  };
1568
1655
  _bulkInsertTableRecords = new WeakSet();
1569
- bulkInsertTableRecords_fn = async function(objects) {
1656
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1570
1657
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1571
1658
  const records = objects.map((object) => transformObjectLinks(object));
1572
- const { recordIDs } = await bulkInsertTableRecords({
1659
+ const response = await bulkInsertTableRecords({
1573
1660
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1661
+ queryParams: { columns },
1574
1662
  body: { records },
1575
1663
  ...fetchProps
1576
1664
  });
1577
- const finalObjects = await this.read(recordIDs);
1578
- if (finalObjects.length !== objects.length) {
1579
- throw new Error("The server failed to save some records");
1665
+ if (!isResponseWithRecords(response)) {
1666
+ throw new Error("Request included columns but server didn't include them");
1580
1667
  }
1581
- const dictionary = finalObjects.reduce((acc, object) => {
1582
- acc[object.id] = object;
1583
- return acc;
1584
- }, {});
1585
- return recordIDs.map((id) => dictionary[id]);
1668
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1669
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1586
1670
  };
1587
1671
  _updateRecordWithID = new WeakSet();
1588
- updateRecordWithID_fn = async function(recordId, object) {
1672
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1589
1673
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1590
1674
  const record = transformObjectLinks(object);
1591
- const response = await updateRecordWithID({
1592
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1593
- body: record,
1594
- ...fetchProps
1595
- });
1596
- const item = await this.read(response.id);
1597
- if (!item)
1598
- throw new Error("The server failed to save the record");
1599
- return item;
1675
+ try {
1676
+ const response = await updateRecordWithID({
1677
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1678
+ queryParams: { columns },
1679
+ body: record,
1680
+ ...fetchProps
1681
+ });
1682
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1683
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1684
+ } catch (e) {
1685
+ if (isObject(e) && e.status === 404) {
1686
+ return null;
1687
+ }
1688
+ throw e;
1689
+ }
1600
1690
  };
1601
1691
  _upsertRecordWithID = new WeakSet();
1602
- upsertRecordWithID_fn = async function(recordId, object) {
1692
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1603
1693
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1604
1694
  const response = await upsertRecordWithID({
1605
1695
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1696
+ queryParams: { columns },
1606
1697
  body: object,
1607
1698
  ...fetchProps
1608
1699
  });
1609
- const item = await this.read(response.id);
1610
- if (!item)
1611
- throw new Error("The server failed to save the record");
1612
- return item;
1700
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1701
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1613
1702
  };
1614
1703
  _deleteRecord = new WeakSet();
1615
- deleteRecord_fn = async function(recordId) {
1704
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1616
1705
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1617
- await deleteRecord({
1618
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1619
- ...fetchProps
1620
- });
1621
- };
1622
- _invalidateCache = new WeakSet();
1623
- invalidateCache_fn = async function(recordId) {
1624
- await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1625
- const cacheItems = await __privateGet$4(this, _cache).getAll();
1626
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1627
- for (const [key, value] of queries) {
1628
- const ids = getIds(value);
1629
- if (ids.includes(recordId))
1630
- await __privateGet$4(this, _cache).delete(key);
1706
+ try {
1707
+ const response = await deleteRecord({
1708
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1709
+ queryParams: { columns },
1710
+ ...fetchProps
1711
+ });
1712
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1713
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1714
+ } catch (e) {
1715
+ if (isObject(e) && e.status === 404) {
1716
+ return null;
1717
+ }
1718
+ throw e;
1631
1719
  }
1632
1720
  };
1633
- _setCacheRecord = new WeakSet();
1634
- setCacheRecord_fn = async function(record) {
1635
- if (!__privateGet$4(this, _cache).cacheRecords)
1636
- return;
1637
- await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1638
- };
1639
- _getCacheRecord = new WeakSet();
1640
- getCacheRecord_fn = async function(recordId) {
1641
- if (!__privateGet$4(this, _cache).cacheRecords)
1642
- return null;
1643
- return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1644
- };
1645
1721
  _setCacheQuery = new WeakSet();
1646
1722
  setCacheQuery_fn = async function(query, meta, records) {
1647
1723
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -1707,11 +1783,11 @@ const initObject = (db, schemaTables, table, object) => {
1707
1783
  }
1708
1784
  }
1709
1785
  }
1710
- result.read = function() {
1711
- return db[table].read(result["id"]);
1786
+ result.read = function(columns2) {
1787
+ return db[table].read(result["id"], columns2);
1712
1788
  };
1713
- result.update = function(data) {
1714
- return db[table].update(result["id"], data);
1789
+ result.update = function(data, columns2) {
1790
+ return db[table].update(result["id"], data, columns2);
1715
1791
  };
1716
1792
  result.delete = function() {
1717
1793
  return db[table].delete(result["id"]);
@@ -1725,14 +1801,15 @@ const initObject = (db, schemaTables, table, object) => {
1725
1801
  Object.freeze(result);
1726
1802
  return result;
1727
1803
  };
1728
- function getIds(value) {
1729
- if (Array.isArray(value)) {
1730
- return value.map((item) => getIds(item)).flat();
1731
- }
1732
- if (!isObject(value))
1733
- return [];
1734
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1735
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1804
+ function isResponseWithRecords(value) {
1805
+ return isObject(value) && Array.isArray(value.records);
1806
+ }
1807
+ function extractId(value) {
1808
+ if (isString(value))
1809
+ return value;
1810
+ if (isObject(value) && isString(value.id))
1811
+ return value.id;
1812
+ return void 0;
1736
1813
  }
1737
1814
 
1738
1815
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1759,7 +1836,6 @@ class SimpleCache {
1759
1836
  __privateAdd$3(this, _map, void 0);
1760
1837
  __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1761
1838
  this.capacity = options.max ?? 500;
1762
- this.cacheRecords = options.cacheRecords ?? true;
1763
1839
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1764
1840
  }
1765
1841
  async getAll() {
@@ -1785,18 +1861,25 @@ class SimpleCache {
1785
1861
  }
1786
1862
  _map = new WeakMap();
1787
1863
 
1788
- const gt = (value) => ({ $gt: value });
1789
- const ge = (value) => ({ $ge: value });
1790
- const gte = (value) => ({ $ge: value });
1791
- const lt = (value) => ({ $lt: value });
1792
- const lte = (value) => ({ $le: value });
1793
- const le = (value) => ({ $le: value });
1864
+ const greaterThan = (value) => ({ $gt: value });
1865
+ const gt = greaterThan;
1866
+ const greaterThanEquals = (value) => ({ $ge: value });
1867
+ const greaterEquals = greaterThanEquals;
1868
+ const gte = greaterThanEquals;
1869
+ const ge = greaterThanEquals;
1870
+ const lessThan = (value) => ({ $lt: value });
1871
+ const lt = lessThan;
1872
+ const lessThanEquals = (value) => ({ $le: value });
1873
+ const lessEquals = lessThanEquals;
1874
+ const lte = lessThanEquals;
1875
+ const le = lessThanEquals;
1794
1876
  const exists = (column) => ({ $exists: column });
1795
1877
  const notExists = (column) => ({ $notExists: column });
1796
1878
  const startsWith = (value) => ({ $startsWith: value });
1797
1879
  const endsWith = (value) => ({ $endsWith: value });
1798
1880
  const pattern = (value) => ({ $pattern: value });
1799
1881
  const is = (value) => ({ $is: value });
1882
+ const equals = is;
1800
1883
  const isNot = (value) => ({ $isNot: value });
1801
1884
  const contains = (value) => ({ $contains: value });
1802
1885
  const includes = (value) => ({ $includes: value });
@@ -1831,16 +1914,19 @@ class SchemaPlugin extends XataPlugin {
1831
1914
  __privateSet$2(this, _schemaTables$1, schemaTables);
1832
1915
  }
1833
1916
  build(pluginOptions) {
1834
- const db = new Proxy({}, {
1835
- get: (_target, table) => {
1836
- if (!isString(table))
1837
- throw new Error("Invalid table name");
1838
- if (__privateGet$2(this, _tables)[table] === void 0) {
1839
- __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1917
+ const db = new Proxy(
1918
+ {},
1919
+ {
1920
+ get: (_target, table) => {
1921
+ if (!isString(table))
1922
+ throw new Error("Invalid table name");
1923
+ if (__privateGet$2(this, _tables)[table] === void 0) {
1924
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1925
+ }
1926
+ return __privateGet$2(this, _tables)[table];
1840
1927
  }
1841
- return __privateGet$2(this, _tables)[table];
1842
1928
  }
1843
- });
1929
+ );
1844
1930
  const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
1845
1931
  for (const table of tableNames) {
1846
1932
  db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
@@ -1910,10 +1996,10 @@ _schemaTables = new WeakMap();
1910
1996
  _search = new WeakSet();
1911
1997
  search_fn = async function(query, options, getFetchProps) {
1912
1998
  const fetchProps = await getFetchProps();
1913
- const { tables, fuzziness, highlight } = options ?? {};
1999
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1914
2000
  const { records } = await searchBranch({
1915
2001
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1916
- body: { tables, query, fuzziness, highlight },
2002
+ body: { tables, query, fuzziness, prefix, highlight },
1917
2003
  ...fetchProps
1918
2004
  });
1919
2005
  return records;
@@ -1954,9 +2040,13 @@ async function resolveXataBranch(gitBranch, options) {
1954
2040
  const databaseURL = options?.databaseURL || getDatabaseURL();
1955
2041
  const apiKey = options?.apiKey || getAPIKey();
1956
2042
  if (!databaseURL)
1957
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
2043
+ throw new Error(
2044
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2045
+ );
1958
2046
  if (!apiKey)
1959
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
2047
+ throw new Error(
2048
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2049
+ );
1960
2050
  const [protocol, , host, , dbName] = databaseURL.split("/");
1961
2051
  const [workspace] = host.split(".");
1962
2052
  const { fallbackBranch } = getEnvironment();
@@ -1966,7 +2056,8 @@ async function resolveXataBranch(gitBranch, options) {
1966
2056
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1967
2057
  workspacesApiUrl: `${protocol}//${host}`,
1968
2058
  pathParams: { dbName, workspace },
1969
- queryParams: { gitBranch, fallbackBranch }
2059
+ queryParams: { gitBranch, fallbackBranch },
2060
+ trace: defaultTrace
1970
2061
  });
1971
2062
  return branch;
1972
2063
  }
@@ -1974,9 +2065,13 @@ async function getDatabaseBranch(branch, options) {
1974
2065
  const databaseURL = options?.databaseURL || getDatabaseURL();
1975
2066
  const apiKey = options?.apiKey || getAPIKey();
1976
2067
  if (!databaseURL)
1977
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
2068
+ throw new Error(
2069
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2070
+ );
1978
2071
  if (!apiKey)
1979
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
2072
+ throw new Error(
2073
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2074
+ );
1980
2075
  const [protocol, , host, , database] = databaseURL.split("/");
1981
2076
  const [workspace] = host.split(".");
1982
2077
  const dbBranchName = `${database}:${branch}`;
@@ -1986,7 +2081,8 @@ async function getDatabaseBranch(branch, options) {
1986
2081
  apiUrl: databaseURL,
1987
2082
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1988
2083
  workspacesApiUrl: `${protocol}//${host}`,
1989
- pathParams: { dbBranchName, workspace }
2084
+ pathParams: { dbBranchName, workspace },
2085
+ trace: defaultTrace
1990
2086
  });
1991
2087
  } catch (err) {
1992
2088
  if (isObject(err) && err.status === 404)
@@ -2026,17 +2122,20 @@ var __privateMethod = (obj, member, method) => {
2026
2122
  return method;
2027
2123
  };
2028
2124
  const buildClient = (plugins) => {
2029
- var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
2125
+ var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
2030
2126
  return _a = class {
2031
2127
  constructor(options = {}, schemaTables) {
2032
2128
  __privateAdd(this, _parseOptions);
2033
2129
  __privateAdd(this, _getFetchProps);
2034
2130
  __privateAdd(this, _evaluateBranch);
2035
2131
  __privateAdd(this, _branch, void 0);
2132
+ __privateAdd(this, _options, void 0);
2036
2133
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
2134
+ __privateSet(this, _options, safeOptions);
2037
2135
  const pluginOptions = {
2038
2136
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2039
- cache: safeOptions.cache
2137
+ cache: safeOptions.cache,
2138
+ trace: safeOptions.trace
2040
2139
  };
2041
2140
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2042
2141
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2055,22 +2154,26 @@ const buildClient = (plugins) => {
2055
2154
  }
2056
2155
  }
2057
2156
  }
2058
- }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2157
+ async getConfig() {
2158
+ const databaseURL = __privateGet(this, _options).databaseURL;
2159
+ const branch = await __privateGet(this, _options).branch();
2160
+ return { databaseURL, branch };
2161
+ }
2162
+ }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2059
2163
  const fetch = getFetchImplementation(options?.fetch);
2060
2164
  const databaseURL = options?.databaseURL || getDatabaseURL();
2061
2165
  const apiKey = options?.apiKey || getAPIKey();
2062
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
2166
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2167
+ const trace = options?.trace ?? defaultTrace;
2063
2168
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2064
- if (!databaseURL || !apiKey) {
2065
- throw new Error("Options databaseURL and apiKey are required");
2169
+ if (!apiKey) {
2170
+ throw new Error("Option apiKey is required");
2066
2171
  }
2067
- return { fetch, databaseURL, apiKey, branch, cache };
2068
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
2069
- fetch,
2070
- apiKey,
2071
- databaseURL,
2072
- branch
2073
- }) {
2172
+ if (!databaseURL) {
2173
+ throw new Error("Option databaseURL is required");
2174
+ }
2175
+ return { fetch, databaseURL, apiKey, branch, cache, trace };
2176
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2074
2177
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2075
2178
  if (!branchValue)
2076
2179
  throw new Error("Unable to resolve branch value");
@@ -2082,7 +2185,8 @@ const buildClient = (plugins) => {
2082
2185
  const hasBranch = params.dbBranchName ?? params.branch;
2083
2186
  const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2084
2187
  return databaseURL + newPath;
2085
- }
2188
+ },
2189
+ trace
2086
2190
  };
2087
2191
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2088
2192
  if (__privateGet(this, _branch))
@@ -2105,6 +2209,88 @@ const buildClient = (plugins) => {
2105
2209
  class BaseClient extends buildClient() {
2106
2210
  }
2107
2211
 
2212
+ const META = "__";
2213
+ const VALUE = "___";
2214
+ class Serializer {
2215
+ constructor() {
2216
+ this.classes = {};
2217
+ }
2218
+ add(clazz) {
2219
+ this.classes[clazz.name] = clazz;
2220
+ }
2221
+ toJSON(data) {
2222
+ function visit(obj) {
2223
+ if (Array.isArray(obj))
2224
+ return obj.map(visit);
2225
+ const type = typeof obj;
2226
+ if (type === "undefined")
2227
+ return { [META]: "undefined" };
2228
+ if (type === "bigint")
2229
+ return { [META]: "bigint", [VALUE]: obj.toString() };
2230
+ if (obj === null || type !== "object")
2231
+ return obj;
2232
+ const constructor = obj.constructor;
2233
+ const o = { [META]: constructor.name };
2234
+ for (const [key, value] of Object.entries(obj)) {
2235
+ o[key] = visit(value);
2236
+ }
2237
+ if (constructor === Date)
2238
+ o[VALUE] = obj.toISOString();
2239
+ if (constructor === Map)
2240
+ o[VALUE] = Object.fromEntries(obj);
2241
+ if (constructor === Set)
2242
+ o[VALUE] = [...obj];
2243
+ return o;
2244
+ }
2245
+ return JSON.stringify(visit(data));
2246
+ }
2247
+ fromJSON(json) {
2248
+ return JSON.parse(json, (key, value) => {
2249
+ if (value && typeof value === "object" && !Array.isArray(value)) {
2250
+ const { [META]: clazz, [VALUE]: val, ...rest } = value;
2251
+ const constructor = this.classes[clazz];
2252
+ if (constructor) {
2253
+ return Object.assign(Object.create(constructor.prototype), rest);
2254
+ }
2255
+ if (clazz === "Date")
2256
+ return new Date(val);
2257
+ if (clazz === "Set")
2258
+ return new Set(val);
2259
+ if (clazz === "Map")
2260
+ return new Map(Object.entries(val));
2261
+ if (clazz === "bigint")
2262
+ return BigInt(val);
2263
+ if (clazz === "undefined")
2264
+ return void 0;
2265
+ return rest;
2266
+ }
2267
+ return value;
2268
+ });
2269
+ }
2270
+ }
2271
+ const defaultSerializer = new Serializer();
2272
+ const serialize = (data) => {
2273
+ return defaultSerializer.toJSON(data);
2274
+ };
2275
+ const deserialize = (json) => {
2276
+ return defaultSerializer.fromJSON(json);
2277
+ };
2278
+
2279
+ function buildWorkerRunner(config) {
2280
+ return function xataWorker(name, _worker) {
2281
+ return async (...args) => {
2282
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2283
+ const result = await fetch(url, {
2284
+ method: "POST",
2285
+ headers: { "Content-Type": "application/json" },
2286
+ body: serialize({ args })
2287
+ });
2288
+ const text = await result.text();
2289
+ return deserialize(text);
2290
+ };
2291
+ };
2292
+ }
2293
+
2108
2294
  class XataError extends Error {
2109
2295
  constructor(message, status) {
2110
2296
  super(message);
@@ -2125,6 +2311,7 @@ exports.Repository = Repository;
2125
2311
  exports.RestRepository = RestRepository;
2126
2312
  exports.SchemaPlugin = SchemaPlugin;
2127
2313
  exports.SearchPlugin = SearchPlugin;
2314
+ exports.Serializer = Serializer;
2128
2315
  exports.SimpleCache = SimpleCache;
2129
2316
  exports.XataApiClient = XataApiClient;
2130
2317
  exports.XataApiPlugin = XataApiPlugin;
@@ -2134,6 +2321,7 @@ exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2134
2321
  exports.addGitBranchesEntry = addGitBranchesEntry;
2135
2322
  exports.addTableColumn = addTableColumn;
2136
2323
  exports.buildClient = buildClient;
2324
+ exports.buildWorkerRunner = buildWorkerRunner;
2137
2325
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2138
2326
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2139
2327
  exports.contains = contains;
@@ -2150,7 +2338,9 @@ exports.deleteTable = deleteTable;
2150
2338
  exports.deleteUser = deleteUser;
2151
2339
  exports.deleteUserAPIKey = deleteUserAPIKey;
2152
2340
  exports.deleteWorkspace = deleteWorkspace;
2341
+ exports.deserialize = deserialize;
2153
2342
  exports.endsWith = endsWith;
2343
+ exports.equals = equals;
2154
2344
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2155
2345
  exports.exists = exists;
2156
2346
  exports.ge = ge;
@@ -2165,6 +2355,7 @@ exports.getColumn = getColumn;
2165
2355
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
2166
2356
  exports.getCurrentBranchName = getCurrentBranchName;
2167
2357
  exports.getDatabaseList = getDatabaseList;
2358
+ exports.getDatabaseMetadata = getDatabaseMetadata;
2168
2359
  exports.getDatabaseURL = getDatabaseURL;
2169
2360
  exports.getGitBranchesMapping = getGitBranchesMapping;
2170
2361
  exports.getRecord = getRecord;
@@ -2175,6 +2366,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2175
2366
  exports.getWorkspace = getWorkspace;
2176
2367
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2177
2368
  exports.getWorkspacesList = getWorkspacesList;
2369
+ exports.greaterEquals = greaterEquals;
2370
+ exports.greaterThan = greaterThan;
2371
+ exports.greaterThanEquals = greaterThanEquals;
2178
2372
  exports.gt = gt;
2179
2373
  exports.gte = gte;
2180
2374
  exports.includes = includes;
@@ -2190,6 +2384,9 @@ exports.isIdentifiable = isIdentifiable;
2190
2384
  exports.isNot = isNot;
2191
2385
  exports.isXataRecord = isXataRecord;
2192
2386
  exports.le = le;
2387
+ exports.lessEquals = lessEquals;
2388
+ exports.lessThan = lessThan;
2389
+ exports.lessThanEquals = lessThanEquals;
2193
2390
  exports.lt = lt;
2194
2391
  exports.lte = lte;
2195
2392
  exports.notExists = notExists;
@@ -2202,6 +2399,7 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
2202
2399
  exports.resolveBranch = resolveBranch;
2203
2400
  exports.searchBranch = searchBranch;
2204
2401
  exports.searchTable = searchTable;
2402
+ exports.serialize = serialize;
2205
2403
  exports.setTableSchema = setTableSchema;
2206
2404
  exports.startsWith = startsWith;
2207
2405
  exports.updateBranchMetadata = updateBranchMetadata;