@xata.io/client 0.16.0 → 0.17.0
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 +32 -0
- package/README.md +2 -0
- package/Usage.md +27 -6
- package/dist/index.cjs +468 -221
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +304 -105
- package/dist/index.mjs +457 -222
- 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
|
}
|
@@ -143,12 +167,14 @@ function getFetchImplementation(userFetch) {
|
|
143
167
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
144
168
|
const fetchImpl = userFetch ?? globalFetch;
|
145
169
|
if (!fetchImpl) {
|
146
|
-
throw new Error(
|
170
|
+
throw new Error(
|
171
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
172
|
+
);
|
147
173
|
}
|
148
174
|
return fetchImpl;
|
149
175
|
}
|
150
176
|
|
151
|
-
const VERSION = "0.
|
177
|
+
const VERSION = "0.17.0";
|
152
178
|
|
153
179
|
class ErrorWithCause extends Error {
|
154
180
|
constructor(message, options) {
|
@@ -227,34 +253,62 @@ async function fetch$1({
|
|
227
253
|
fetchImpl,
|
228
254
|
apiKey,
|
229
255
|
apiUrl,
|
230
|
-
workspacesApiUrl
|
256
|
+
workspacesApiUrl,
|
257
|
+
trace
|
231
258
|
}) {
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
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) {
|
250
307
|
try {
|
251
|
-
const
|
252
|
-
|
253
|
-
return jsonResponse;
|
254
|
-
}
|
255
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
308
|
+
const { host, protocol } = new URL(url);
|
309
|
+
return { host, protocol };
|
256
310
|
} catch (error) {
|
257
|
-
|
311
|
+
return {};
|
258
312
|
}
|
259
313
|
}
|
260
314
|
|
@@ -349,6 +403,11 @@ const deleteDatabase = (variables) => fetch$1({
|
|
349
403
|
method: "delete",
|
350
404
|
...variables
|
351
405
|
});
|
406
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
407
|
+
url: "/dbs/{dbName}/metadata",
|
408
|
+
method: "get",
|
409
|
+
...variables
|
410
|
+
});
|
352
411
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
353
412
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
354
413
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -487,6 +546,7 @@ const operationsByTag = {
|
|
487
546
|
getDatabaseList,
|
488
547
|
createDatabase,
|
489
548
|
deleteDatabase,
|
549
|
+
getDatabaseMetadata,
|
490
550
|
getGitBranchesMapping,
|
491
551
|
addGitBranchesEntry,
|
492
552
|
removeGitBranchesEntry,
|
@@ -579,7 +639,8 @@ class XataApiClient {
|
|
579
639
|
__privateAdd$7(this, _extraProps, void 0);
|
580
640
|
__privateAdd$7(this, _namespaces, {});
|
581
641
|
const provider = options.host ?? "production";
|
582
|
-
const apiKey = options
|
642
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
643
|
+
const trace = options.trace ?? defaultTrace;
|
583
644
|
if (!apiKey) {
|
584
645
|
throw new Error("Could not resolve a valid apiKey");
|
585
646
|
}
|
@@ -587,7 +648,8 @@ class XataApiClient {
|
|
587
648
|
apiUrl: getHostUrl(provider, "main"),
|
588
649
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
589
650
|
fetchImpl: getFetchImplementation(options.fetch),
|
590
|
-
apiKey
|
651
|
+
apiKey,
|
652
|
+
trace
|
591
653
|
});
|
592
654
|
}
|
593
655
|
get user() {
|
@@ -759,6 +821,12 @@ class DatabaseApi {
|
|
759
821
|
...this.extraProps
|
760
822
|
});
|
761
823
|
}
|
824
|
+
getDatabaseMetadata(workspace, dbName) {
|
825
|
+
return operationsByTag.database.getDatabaseMetadata({
|
826
|
+
pathParams: { workspace, dbName },
|
827
|
+
...this.extraProps
|
828
|
+
});
|
829
|
+
}
|
762
830
|
getGitBranchesMapping(workspace, dbName) {
|
763
831
|
return operationsByTag.database.getGitBranchesMapping({
|
764
832
|
pathParams: { workspace, dbName },
|
@@ -1198,13 +1266,18 @@ const _Query = class {
|
|
1198
1266
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1199
1267
|
}
|
1200
1268
|
}
|
1201
|
-
sort(column, direction) {
|
1269
|
+
sort(column, direction = "asc") {
|
1202
1270
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1203
1271
|
const sort = [...originalSort, { column, direction }];
|
1204
1272
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1205
1273
|
}
|
1206
1274
|
select(columns) {
|
1207
|
-
return new _Query(
|
1275
|
+
return new _Query(
|
1276
|
+
__privateGet$5(this, _repository),
|
1277
|
+
__privateGet$5(this, _table$1),
|
1278
|
+
{ columns },
|
1279
|
+
__privateGet$5(this, _data)
|
1280
|
+
);
|
1208
1281
|
}
|
1209
1282
|
getPaginated(options = {}) {
|
1210
1283
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1329,7 +1402,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1329
1402
|
__accessCheck$4(obj, member, "access private method");
|
1330
1403
|
return method;
|
1331
1404
|
};
|
1332
|
-
var _table, _getFetchProps, _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;
|
1333
1406
|
class Repository extends Query {
|
1334
1407
|
}
|
1335
1408
|
class RestRepository extends Query {
|
@@ -1346,176 +1419,204 @@ class RestRepository extends Query {
|
|
1346
1419
|
__privateAdd$4(this, _getSchemaTables$1);
|
1347
1420
|
__privateAdd$4(this, _table, void 0);
|
1348
1421
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1422
|
+
__privateAdd$4(this, _db, void 0);
|
1349
1423
|
__privateAdd$4(this, _cache, void 0);
|
1350
1424
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1425
|
+
__privateAdd$4(this, _trace, void 0);
|
1351
1426
|
__privateSet$4(this, _table, options.table);
|
1352
1427
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1353
|
-
this
|
1428
|
+
__privateSet$4(this, _db, options.db);
|
1354
1429
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1355
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
|
+
});
|
1356
1439
|
}
|
1357
1440
|
async create(a, b, c) {
|
1358
|
-
|
1359
|
-
if (a
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
if (a
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
if (a.id
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
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
|
+
});
|
1381
1466
|
}
|
1382
1467
|
async read(a, b) {
|
1383
|
-
|
1384
|
-
|
1385
|
-
if (a
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
acc
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
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;
|
1409
1502
|
}
|
1410
|
-
throw e;
|
1411
1503
|
}
|
1412
|
-
|
1413
|
-
|
1504
|
+
return null;
|
1505
|
+
});
|
1414
1506
|
}
|
1415
1507
|
async update(a, b, c) {
|
1416
|
-
|
1417
|
-
if (a
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
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)));
|
1421
1517
|
}
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
}
|
1433
|
-
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
|
+
});
|
1434
1528
|
}
|
1435
1529
|
async createOrUpdate(a, b, c) {
|
1436
|
-
|
1437
|
-
if (a
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
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)));
|
1441
1539
|
}
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
if (isString(a) && isObject(b)) {
|
1446
|
-
const columns = isStringArray(c) ? c : void 0;
|
1447
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1448
|
-
}
|
1449
|
-
if (isObject(a) && isString(a.id)) {
|
1450
|
-
const columns = isStringArray(c) ? c : void 0;
|
1451
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1452
|
-
}
|
1453
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1454
|
-
}
|
1455
|
-
async delete(a) {
|
1456
|
-
if (Array.isArray(a)) {
|
1457
|
-
if (a.length === 0)
|
1458
|
-
return;
|
1459
|
-
if (a.length > 100) {
|
1460
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
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);
|
1461
1543
|
}
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
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
|
+
});
|
1474
1569
|
}
|
1475
1570
|
async search(query, options = {}) {
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
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));
|
1488
1587
|
});
|
1489
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1490
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1491
1588
|
}
|
1492
1589
|
async query(query) {
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
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);
|
1508
1611
|
});
|
1509
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1510
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1511
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1512
|
-
return new Page(query, meta, records);
|
1513
1612
|
}
|
1514
1613
|
}
|
1515
1614
|
_table = new WeakMap();
|
1516
1615
|
_getFetchProps = new WeakMap();
|
1616
|
+
_db = new WeakMap();
|
1517
1617
|
_cache = new WeakMap();
|
1518
1618
|
_schemaTables$2 = new WeakMap();
|
1619
|
+
_trace = new WeakMap();
|
1519
1620
|
_insertRecordWithoutId = new WeakSet();
|
1520
1621
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1521
1622
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1531,7 +1632,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1531
1632
|
...fetchProps
|
1532
1633
|
});
|
1533
1634
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1534
|
-
return initObject(this
|
1635
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1535
1636
|
};
|
1536
1637
|
_insertRecordWithId = new WeakSet();
|
1537
1638
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1549,7 +1650,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
1549
1650
|
...fetchProps
|
1550
1651
|
});
|
1551
1652
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1552
|
-
return initObject(this
|
1653
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1553
1654
|
};
|
1554
1655
|
_bulkInsertTableRecords = new WeakSet();
|
1555
1656
|
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
@@ -1565,20 +1666,27 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1565
1666
|
throw new Error("Request included columns but server didn't include them");
|
1566
1667
|
}
|
1567
1668
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1568
|
-
return response.records?.map((item) => initObject(this
|
1669
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1569
1670
|
};
|
1570
1671
|
_updateRecordWithID = new WeakSet();
|
1571
1672
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1572
1673
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1573
1674
|
const record = transformObjectLinks(object);
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
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
|
+
}
|
1582
1690
|
};
|
1583
1691
|
_upsertRecordWithID = new WeakSet();
|
1584
1692
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1590,15 +1698,25 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1590
1698
|
...fetchProps
|
1591
1699
|
});
|
1592
1700
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1593
|
-
return initObject(this
|
1701
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1594
1702
|
};
|
1595
1703
|
_deleteRecord = new WeakSet();
|
1596
|
-
deleteRecord_fn = async function(recordId) {
|
1704
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1597
1705
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
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;
|
1719
|
+
}
|
1602
1720
|
};
|
1603
1721
|
_setCacheQuery = new WeakSet();
|
1604
1722
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1686,6 +1804,13 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1686
1804
|
function isResponseWithRecords(value) {
|
1687
1805
|
return isObject(value) && Array.isArray(value.records);
|
1688
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;
|
1813
|
+
}
|
1689
1814
|
|
1690
1815
|
var __accessCheck$3 = (obj, member, msg) => {
|
1691
1816
|
if (!member.has(obj))
|
@@ -1736,18 +1861,25 @@ class SimpleCache {
|
|
1736
1861
|
}
|
1737
1862
|
_map = new WeakMap();
|
1738
1863
|
|
1739
|
-
const
|
1740
|
-
const
|
1741
|
-
const
|
1742
|
-
const
|
1743
|
-
const
|
1744
|
-
const
|
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;
|
1745
1876
|
const exists = (column) => ({ $exists: column });
|
1746
1877
|
const notExists = (column) => ({ $notExists: column });
|
1747
1878
|
const startsWith = (value) => ({ $startsWith: value });
|
1748
1879
|
const endsWith = (value) => ({ $endsWith: value });
|
1749
1880
|
const pattern = (value) => ({ $pattern: value });
|
1750
1881
|
const is = (value) => ({ $is: value });
|
1882
|
+
const equals = is;
|
1751
1883
|
const isNot = (value) => ({ $isNot: value });
|
1752
1884
|
const contains = (value) => ({ $contains: value });
|
1753
1885
|
const includes = (value) => ({ $includes: value });
|
@@ -1782,16 +1914,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1782
1914
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1783
1915
|
}
|
1784
1916
|
build(pluginOptions) {
|
1785
|
-
const db = new Proxy(
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
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];
|
1791
1927
|
}
|
1792
|
-
return __privateGet$2(this, _tables)[table];
|
1793
1928
|
}
|
1794
|
-
|
1929
|
+
);
|
1795
1930
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1796
1931
|
for (const table of tableNames) {
|
1797
1932
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1905,9 +2040,13 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1905
2040
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1906
2041
|
const apiKey = options?.apiKey || getAPIKey();
|
1907
2042
|
if (!databaseURL)
|
1908
|
-
throw new Error(
|
2043
|
+
throw new Error(
|
2044
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2045
|
+
);
|
1909
2046
|
if (!apiKey)
|
1910
|
-
throw new Error(
|
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
|
+
);
|
1911
2050
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1912
2051
|
const [workspace] = host.split(".");
|
1913
2052
|
const { fallbackBranch } = getEnvironment();
|
@@ -1917,7 +2056,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1917
2056
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1918
2057
|
workspacesApiUrl: `${protocol}//${host}`,
|
1919
2058
|
pathParams: { dbName, workspace },
|
1920
|
-
queryParams: { gitBranch, fallbackBranch }
|
2059
|
+
queryParams: { gitBranch, fallbackBranch },
|
2060
|
+
trace: defaultTrace
|
1921
2061
|
});
|
1922
2062
|
return branch;
|
1923
2063
|
}
|
@@ -1925,9 +2065,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1925
2065
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1926
2066
|
const apiKey = options?.apiKey || getAPIKey();
|
1927
2067
|
if (!databaseURL)
|
1928
|
-
throw new Error(
|
2068
|
+
throw new Error(
|
2069
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2070
|
+
);
|
1929
2071
|
if (!apiKey)
|
1930
|
-
throw new Error(
|
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
|
+
);
|
1931
2075
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1932
2076
|
const [workspace] = host.split(".");
|
1933
2077
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1937,7 +2081,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1937
2081
|
apiUrl: databaseURL,
|
1938
2082
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1939
2083
|
workspacesApiUrl: `${protocol}//${host}`,
|
1940
|
-
pathParams: { dbBranchName, workspace }
|
2084
|
+
pathParams: { dbBranchName, workspace },
|
2085
|
+
trace: defaultTrace
|
1941
2086
|
});
|
1942
2087
|
} catch (err) {
|
1943
2088
|
if (isObject(err) && err.status === 404)
|
@@ -1977,17 +2122,20 @@ var __privateMethod = (obj, member, method) => {
|
|
1977
2122
|
return method;
|
1978
2123
|
};
|
1979
2124
|
const buildClient = (plugins) => {
|
1980
|
-
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;
|
1981
2126
|
return _a = class {
|
1982
2127
|
constructor(options = {}, schemaTables) {
|
1983
2128
|
__privateAdd(this, _parseOptions);
|
1984
2129
|
__privateAdd(this, _getFetchProps);
|
1985
2130
|
__privateAdd(this, _evaluateBranch);
|
1986
2131
|
__privateAdd(this, _branch, void 0);
|
2132
|
+
__privateAdd(this, _options, void 0);
|
1987
2133
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2134
|
+
__privateSet(this, _options, safeOptions);
|
1988
2135
|
const pluginOptions = {
|
1989
2136
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1990
|
-
cache: safeOptions.cache
|
2137
|
+
cache: safeOptions.cache,
|
2138
|
+
trace: safeOptions.trace
|
1991
2139
|
};
|
1992
2140
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
1993
2141
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2006,22 +2154,26 @@ const buildClient = (plugins) => {
|
|
2006
2154
|
}
|
2007
2155
|
}
|
2008
2156
|
}
|
2009
|
-
|
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) {
|
2010
2163
|
const fetch = getFetchImplementation(options?.fetch);
|
2011
2164
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2012
2165
|
const apiKey = options?.apiKey || getAPIKey();
|
2013
2166
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2167
|
+
const trace = options?.trace ?? defaultTrace;
|
2014
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 });
|
2015
|
-
if (!
|
2016
|
-
throw new Error("
|
2169
|
+
if (!apiKey) {
|
2170
|
+
throw new Error("Option apiKey is required");
|
2017
2171
|
}
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
apiKey,
|
2022
|
-
|
2023
|
-
branch
|
2024
|
-
}) {
|
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 }) {
|
2025
2177
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2026
2178
|
if (!branchValue)
|
2027
2179
|
throw new Error("Unable to resolve branch value");
|
@@ -2033,7 +2185,8 @@ const buildClient = (plugins) => {
|
|
2033
2185
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2034
2186
|
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2035
2187
|
return databaseURL + newPath;
|
2036
|
-
}
|
2188
|
+
},
|
2189
|
+
trace
|
2037
2190
|
};
|
2038
2191
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2039
2192
|
if (__privateGet(this, _branch))
|
@@ -2056,6 +2209,88 @@ const buildClient = (plugins) => {
|
|
2056
2209
|
class BaseClient extends buildClient() {
|
2057
2210
|
}
|
2058
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
|
+
|
2059
2294
|
class XataError extends Error {
|
2060
2295
|
constructor(message, status) {
|
2061
2296
|
super(message);
|
@@ -2076,6 +2311,7 @@ exports.Repository = Repository;
|
|
2076
2311
|
exports.RestRepository = RestRepository;
|
2077
2312
|
exports.SchemaPlugin = SchemaPlugin;
|
2078
2313
|
exports.SearchPlugin = SearchPlugin;
|
2314
|
+
exports.Serializer = Serializer;
|
2079
2315
|
exports.SimpleCache = SimpleCache;
|
2080
2316
|
exports.XataApiClient = XataApiClient;
|
2081
2317
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2085,6 +2321,7 @@ exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
|
2085
2321
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2086
2322
|
exports.addTableColumn = addTableColumn;
|
2087
2323
|
exports.buildClient = buildClient;
|
2324
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2088
2325
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2089
2326
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2090
2327
|
exports.contains = contains;
|
@@ -2101,7 +2338,9 @@ exports.deleteTable = deleteTable;
|
|
2101
2338
|
exports.deleteUser = deleteUser;
|
2102
2339
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2103
2340
|
exports.deleteWorkspace = deleteWorkspace;
|
2341
|
+
exports.deserialize = deserialize;
|
2104
2342
|
exports.endsWith = endsWith;
|
2343
|
+
exports.equals = equals;
|
2105
2344
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2106
2345
|
exports.exists = exists;
|
2107
2346
|
exports.ge = ge;
|
@@ -2116,6 +2355,7 @@ exports.getColumn = getColumn;
|
|
2116
2355
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
2117
2356
|
exports.getCurrentBranchName = getCurrentBranchName;
|
2118
2357
|
exports.getDatabaseList = getDatabaseList;
|
2358
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2119
2359
|
exports.getDatabaseURL = getDatabaseURL;
|
2120
2360
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
2121
2361
|
exports.getRecord = getRecord;
|
@@ -2126,6 +2366,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2126
2366
|
exports.getWorkspace = getWorkspace;
|
2127
2367
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2128
2368
|
exports.getWorkspacesList = getWorkspacesList;
|
2369
|
+
exports.greaterEquals = greaterEquals;
|
2370
|
+
exports.greaterThan = greaterThan;
|
2371
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2129
2372
|
exports.gt = gt;
|
2130
2373
|
exports.gte = gte;
|
2131
2374
|
exports.includes = includes;
|
@@ -2141,6 +2384,9 @@ exports.isIdentifiable = isIdentifiable;
|
|
2141
2384
|
exports.isNot = isNot;
|
2142
2385
|
exports.isXataRecord = isXataRecord;
|
2143
2386
|
exports.le = le;
|
2387
|
+
exports.lessEquals = lessEquals;
|
2388
|
+
exports.lessThan = lessThan;
|
2389
|
+
exports.lessThanEquals = lessThanEquals;
|
2144
2390
|
exports.lt = lt;
|
2145
2391
|
exports.lte = lte;
|
2146
2392
|
exports.notExists = notExists;
|
@@ -2153,6 +2399,7 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
2153
2399
|
exports.resolveBranch = resolveBranch;
|
2154
2400
|
exports.searchBranch = searchBranch;
|
2155
2401
|
exports.searchTable = searchTable;
|
2402
|
+
exports.serialize = serialize;
|
2156
2403
|
exports.setTableSchema = setTableSchema;
|
2157
2404
|
exports.startsWith = startsWith;
|
2158
2405
|
exports.updateBranchMetadata = updateBranchMetadata;
|