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