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