@xata.io/client 0.0.0-alpha.vf28813b → 0.0.0-alpha.vf2ed8b7
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 +18 -16
- package/Usage.md +27 -6
- package/dist/index.cjs +458 -217
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +274 -100
- package/dist/index.mjs +448 -218
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
@@ -20,6 +20,28 @@ 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
|
+
});
|
29
|
+
};
|
30
|
+
const TraceAttributes = {
|
31
|
+
KIND: "xata.trace.kind",
|
32
|
+
VERSION: "xata.sdk.version",
|
33
|
+
TABLE: "xata.table",
|
34
|
+
HTTP_REQUEST_ID: "http.request_id",
|
35
|
+
HTTP_STATUS_CODE: "http.status_code",
|
36
|
+
HTTP_HOST: "http.host",
|
37
|
+
HTTP_SCHEME: "http.scheme",
|
38
|
+
HTTP_USER_AGENT: "http.user_agent",
|
39
|
+
HTTP_METHOD: "http.method",
|
40
|
+
HTTP_URL: "http.url",
|
41
|
+
HTTP_ROUTE: "http.route",
|
42
|
+
HTTP_TARGET: "http.target"
|
43
|
+
};
|
44
|
+
|
23
45
|
function notEmpty(value) {
|
24
46
|
return value !== null && value !== void 0;
|
25
47
|
}
|
@@ -144,13 +166,13 @@ function getFetchImplementation(userFetch) {
|
|
144
166
|
const fetchImpl = userFetch ?? globalFetch;
|
145
167
|
if (!fetchImpl) {
|
146
168
|
throw new Error(
|
147
|
-
`
|
169
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
148
170
|
);
|
149
171
|
}
|
150
172
|
return fetchImpl;
|
151
173
|
}
|
152
174
|
|
153
|
-
const VERSION = "0.0.0-alpha.
|
175
|
+
const VERSION = "0.0.0-alpha.vf2ed8b7";
|
154
176
|
|
155
177
|
class ErrorWithCause extends Error {
|
156
178
|
constructor(message, options) {
|
@@ -201,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
201
223
|
}, {});
|
202
224
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
203
225
|
const queryString = query.length > 0 ? `?${query}` : "";
|
204
|
-
|
226
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
227
|
+
return { ...acc, [key]: encodeURIComponent(value).replace("%3A", ":") };
|
228
|
+
}, {});
|
229
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
205
230
|
};
|
206
231
|
function buildBaseUrl({
|
207
232
|
path,
|
@@ -229,34 +254,61 @@ async function fetch$1({
|
|
229
254
|
fetchImpl,
|
230
255
|
apiKey,
|
231
256
|
apiUrl,
|
232
|
-
workspacesApiUrl
|
257
|
+
workspacesApiUrl,
|
258
|
+
trace
|
233
259
|
}) {
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
260
|
+
return trace(
|
261
|
+
`${method.toUpperCase()} ${path}`,
|
262
|
+
async ({ setAttributes }) => {
|
263
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
264
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
265
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
266
|
+
setAttributes({
|
267
|
+
[TraceAttributes.HTTP_URL]: url,
|
268
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
269
|
+
});
|
270
|
+
const response = await fetchImpl(url, {
|
271
|
+
method: method.toUpperCase(),
|
272
|
+
body: body ? JSON.stringify(body) : void 0,
|
273
|
+
headers: {
|
274
|
+
"Content-Type": "application/json",
|
275
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
276
|
+
...headers,
|
277
|
+
...hostHeader(fullUrl),
|
278
|
+
Authorization: `Bearer ${apiKey}`
|
279
|
+
}
|
280
|
+
});
|
281
|
+
if (response.status === 204) {
|
282
|
+
return {};
|
283
|
+
}
|
284
|
+
const { host, protocol } = parseUrl(response.url);
|
285
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
286
|
+
setAttributes({
|
287
|
+
[TraceAttributes.KIND]: "http",
|
288
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
289
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
290
|
+
[TraceAttributes.HTTP_HOST]: host,
|
291
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
292
|
+
});
|
293
|
+
try {
|
294
|
+
const jsonResponse = await response.json();
|
295
|
+
if (response.ok) {
|
296
|
+
return jsonResponse;
|
297
|
+
}
|
298
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
299
|
+
} catch (error) {
|
300
|
+
throw new FetcherError(response.status, error, requestId);
|
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
|
|
@@ -494,6 +546,7 @@ const operationsByTag = {
|
|
494
546
|
getDatabaseList,
|
495
547
|
createDatabase,
|
496
548
|
deleteDatabase,
|
549
|
+
getDatabaseMetadata,
|
497
550
|
getGitBranchesMapping,
|
498
551
|
addGitBranchesEntry,
|
499
552
|
removeGitBranchesEntry,
|
@@ -501,7 +554,6 @@ const operationsByTag = {
|
|
501
554
|
},
|
502
555
|
branch: {
|
503
556
|
getBranchList,
|
504
|
-
getDatabaseMetadata,
|
505
557
|
getBranchDetails,
|
506
558
|
createBranch,
|
507
559
|
deleteBranch,
|
@@ -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() {
|
@@ -767,6 +821,12 @@ class DatabaseApi {
|
|
767
821
|
...this.extraProps
|
768
822
|
});
|
769
823
|
}
|
824
|
+
getDatabaseMetadata(workspace, dbName) {
|
825
|
+
return operationsByTag.database.getDatabaseMetadata({
|
826
|
+
pathParams: { workspace, dbName },
|
827
|
+
...this.extraProps
|
828
|
+
});
|
829
|
+
}
|
770
830
|
getGitBranchesMapping(workspace, dbName) {
|
771
831
|
return operationsByTag.database.getGitBranchesMapping({
|
772
832
|
pathParams: { workspace, dbName },
|
@@ -1198,15 +1258,23 @@ const _Query = class {
|
|
1198
1258
|
}
|
1199
1259
|
filter(a, b) {
|
1200
1260
|
if (arguments.length === 1) {
|
1201
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1261
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1202
1262
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1203
1263
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1204
1264
|
} else {
|
1205
|
-
const
|
1265
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1266
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1206
1267
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1207
1268
|
}
|
1208
1269
|
}
|
1209
|
-
|
1270
|
+
defaultFilter(column, value) {
|
1271
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1272
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1273
|
+
return { $includes: value };
|
1274
|
+
}
|
1275
|
+
return value;
|
1276
|
+
}
|
1277
|
+
sort(column, direction = "asc") {
|
1210
1278
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1211
1279
|
const sort = [...originalSort, { column, direction }];
|
1212
1280
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
@@ -1342,12 +1410,16 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1342
1410
|
__accessCheck$4(obj, member, "access private method");
|
1343
1411
|
return method;
|
1344
1412
|
};
|
1345
|
-
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;
|
1413
|
+
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;
|
1346
1414
|
class Repository extends Query {
|
1347
1415
|
}
|
1348
1416
|
class RestRepository extends Query {
|
1349
1417
|
constructor(options) {
|
1350
|
-
super(
|
1418
|
+
super(
|
1419
|
+
null,
|
1420
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1421
|
+
{}
|
1422
|
+
);
|
1351
1423
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1352
1424
|
__privateAdd$4(this, _insertRecordWithId);
|
1353
1425
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
@@ -1359,176 +1431,205 @@ class RestRepository extends Query {
|
|
1359
1431
|
__privateAdd$4(this, _getSchemaTables$1);
|
1360
1432
|
__privateAdd$4(this, _table, void 0);
|
1361
1433
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1434
|
+
__privateAdd$4(this, _db, void 0);
|
1362
1435
|
__privateAdd$4(this, _cache, void 0);
|
1363
1436
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1437
|
+
__privateAdd$4(this, _trace, void 0);
|
1364
1438
|
__privateSet$4(this, _table, options.table);
|
1365
1439
|
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1366
|
-
this
|
1440
|
+
__privateSet$4(this, _db, options.db);
|
1367
1441
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1368
1442
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1443
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1444
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1445
|
+
return trace(name, fn, {
|
1446
|
+
...options2,
|
1447
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1448
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1449
|
+
[TraceAttributes.VERSION]: VERSION
|
1450
|
+
});
|
1451
|
+
});
|
1369
1452
|
}
|
1370
1453
|
async create(a, b, c) {
|
1371
|
-
|
1372
|
-
if (a
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
if (a
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
if (a.id
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1454
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
1455
|
+
if (Array.isArray(a)) {
|
1456
|
+
if (a.length === 0)
|
1457
|
+
return [];
|
1458
|
+
const columns = isStringArray(b) ? b : void 0;
|
1459
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1460
|
+
}
|
1461
|
+
if (isString(a) && isObject(b)) {
|
1462
|
+
if (a === "")
|
1463
|
+
throw new Error("The id can't be empty");
|
1464
|
+
const columns = isStringArray(c) ? c : void 0;
|
1465
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1466
|
+
}
|
1467
|
+
if (isObject(a) && isString(a.id)) {
|
1468
|
+
if (a.id === "")
|
1469
|
+
throw new Error("The id can't be empty");
|
1470
|
+
const columns = isStringArray(b) ? b : void 0;
|
1471
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1472
|
+
}
|
1473
|
+
if (isObject(a)) {
|
1474
|
+
const columns = isStringArray(b) ? b : void 0;
|
1475
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1476
|
+
}
|
1477
|
+
throw new Error("Invalid arguments for create method");
|
1478
|
+
});
|
1394
1479
|
}
|
1395
1480
|
async read(a, b) {
|
1396
|
-
|
1397
|
-
|
1398
|
-
if (a
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
acc
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1481
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1482
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1483
|
+
if (Array.isArray(a)) {
|
1484
|
+
if (a.length === 0)
|
1485
|
+
return [];
|
1486
|
+
const ids = a.map((item) => extractId(item));
|
1487
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1488
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1489
|
+
acc[object.id] = object;
|
1490
|
+
return acc;
|
1491
|
+
}, {});
|
1492
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1493
|
+
}
|
1494
|
+
const id = extractId(a);
|
1495
|
+
if (id) {
|
1496
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1497
|
+
try {
|
1498
|
+
const response = await getRecord({
|
1499
|
+
pathParams: {
|
1500
|
+
workspace: "{workspaceId}",
|
1501
|
+
dbBranchName: "{dbBranch}",
|
1502
|
+
tableName: __privateGet$4(this, _table),
|
1503
|
+
recordId: id
|
1504
|
+
},
|
1505
|
+
queryParams: { columns },
|
1506
|
+
...fetchProps
|
1507
|
+
});
|
1508
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1509
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1510
|
+
} catch (e) {
|
1511
|
+
if (isObject(e) && e.status === 404) {
|
1512
|
+
return null;
|
1513
|
+
}
|
1514
|
+
throw e;
|
1422
1515
|
}
|
1423
|
-
throw e;
|
1424
1516
|
}
|
1425
|
-
|
1426
|
-
|
1517
|
+
return null;
|
1518
|
+
});
|
1427
1519
|
}
|
1428
1520
|
async update(a, b, c) {
|
1429
|
-
|
1430
|
-
if (a
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1521
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1522
|
+
if (Array.isArray(a)) {
|
1523
|
+
if (a.length === 0)
|
1524
|
+
return [];
|
1525
|
+
if (a.length > 100) {
|
1526
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1527
|
+
}
|
1528
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1529
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1434
1530
|
}
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
}
|
1446
|
-
throw new Error("Invalid arguments for update method");
|
1531
|
+
if (isString(a) && isObject(b)) {
|
1532
|
+
const columns = isStringArray(c) ? c : void 0;
|
1533
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1534
|
+
}
|
1535
|
+
if (isObject(a) && isString(a.id)) {
|
1536
|
+
const columns = isStringArray(b) ? b : void 0;
|
1537
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1538
|
+
}
|
1539
|
+
throw new Error("Invalid arguments for update method");
|
1540
|
+
});
|
1447
1541
|
}
|
1448
1542
|
async createOrUpdate(a, b, c) {
|
1449
|
-
|
1450
|
-
if (a
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1543
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1544
|
+
if (Array.isArray(a)) {
|
1545
|
+
if (a.length === 0)
|
1546
|
+
return [];
|
1547
|
+
if (a.length > 100) {
|
1548
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1549
|
+
}
|
1550
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1551
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1454
1552
|
}
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
if (isString(a) && isObject(b)) {
|
1459
|
-
const columns = isStringArray(c) ? c : void 0;
|
1460
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1461
|
-
}
|
1462
|
-
if (isObject(a) && isString(a.id)) {
|
1463
|
-
const columns = isStringArray(c) ? c : void 0;
|
1464
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1465
|
-
}
|
1466
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1467
|
-
}
|
1468
|
-
async delete(a) {
|
1469
|
-
if (Array.isArray(a)) {
|
1470
|
-
if (a.length === 0)
|
1471
|
-
return;
|
1472
|
-
if (a.length > 100) {
|
1473
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1553
|
+
if (isString(a) && isObject(b)) {
|
1554
|
+
const columns = isStringArray(c) ? c : void 0;
|
1555
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1474
1556
|
}
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1557
|
+
if (isObject(a) && isString(a.id)) {
|
1558
|
+
const columns = isStringArray(c) ? c : void 0;
|
1559
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1560
|
+
}
|
1561
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1562
|
+
});
|
1563
|
+
}
|
1564
|
+
async delete(a, b) {
|
1565
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1566
|
+
if (Array.isArray(a)) {
|
1567
|
+
if (a.length === 0)
|
1568
|
+
return [];
|
1569
|
+
if (a.length > 100) {
|
1570
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1571
|
+
}
|
1572
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1573
|
+
}
|
1574
|
+
if (isString(a)) {
|
1575
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1576
|
+
}
|
1577
|
+
if (isObject(a) && isString(a.id)) {
|
1578
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1579
|
+
}
|
1580
|
+
throw new Error("Invalid arguments for delete method");
|
1581
|
+
});
|
1487
1582
|
}
|
1488
1583
|
async search(query, options = {}) {
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1584
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1585
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1586
|
+
const { records } = await searchTable({
|
1587
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1588
|
+
body: {
|
1589
|
+
query,
|
1590
|
+
fuzziness: options.fuzziness,
|
1591
|
+
prefix: options.prefix,
|
1592
|
+
highlight: options.highlight,
|
1593
|
+
filter: options.filter,
|
1594
|
+
boosters: options.boosters
|
1595
|
+
},
|
1596
|
+
...fetchProps
|
1597
|
+
});
|
1598
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1599
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1501
1600
|
});
|
1502
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1503
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1504
1601
|
}
|
1505
1602
|
async query(query) {
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1603
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
1604
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1605
|
+
if (cacheQuery)
|
1606
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1607
|
+
const data = query.getQueryOptions();
|
1608
|
+
const body = {
|
1609
|
+
filter: cleanFilter(data.filter),
|
1610
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1611
|
+
page: data.pagination,
|
1612
|
+
columns: data.columns
|
1613
|
+
};
|
1614
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1615
|
+
const { meta, records: objects } = await queryTable({
|
1616
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1617
|
+
body,
|
1618
|
+
...fetchProps
|
1619
|
+
});
|
1620
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1621
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1622
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1623
|
+
return new Page(query, meta, records);
|
1521
1624
|
});
|
1522
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1523
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1524
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1525
|
-
return new Page(query, meta, records);
|
1526
1625
|
}
|
1527
1626
|
}
|
1528
1627
|
_table = new WeakMap();
|
1529
1628
|
_getFetchProps = new WeakMap();
|
1629
|
+
_db = new WeakMap();
|
1530
1630
|
_cache = new WeakMap();
|
1531
1631
|
_schemaTables$2 = new WeakMap();
|
1632
|
+
_trace = new WeakMap();
|
1532
1633
|
_insertRecordWithoutId = new WeakSet();
|
1533
1634
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1534
1635
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1544,7 +1645,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1544
1645
|
...fetchProps
|
1545
1646
|
});
|
1546
1647
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1547
|
-
return initObject(this
|
1648
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1548
1649
|
};
|
1549
1650
|
_insertRecordWithId = new WeakSet();
|
1550
1651
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1562,7 +1663,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
1562
1663
|
...fetchProps
|
1563
1664
|
});
|
1564
1665
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1565
|
-
return initObject(this
|
1666
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1566
1667
|
};
|
1567
1668
|
_bulkInsertTableRecords = new WeakSet();
|
1568
1669
|
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
@@ -1578,20 +1679,27 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1578
1679
|
throw new Error("Request included columns but server didn't include them");
|
1579
1680
|
}
|
1580
1681
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1581
|
-
return response.records?.map((item) => initObject(this
|
1682
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1582
1683
|
};
|
1583
1684
|
_updateRecordWithID = new WeakSet();
|
1584
1685
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1585
1686
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1586
1687
|
const record = transformObjectLinks(object);
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1688
|
+
try {
|
1689
|
+
const response = await updateRecordWithID({
|
1690
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1691
|
+
queryParams: { columns },
|
1692
|
+
body: record,
|
1693
|
+
...fetchProps
|
1694
|
+
});
|
1695
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1696
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1697
|
+
} catch (e) {
|
1698
|
+
if (isObject(e) && e.status === 404) {
|
1699
|
+
return null;
|
1700
|
+
}
|
1701
|
+
throw e;
|
1702
|
+
}
|
1595
1703
|
};
|
1596
1704
|
_upsertRecordWithID = new WeakSet();
|
1597
1705
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1603,15 +1711,25 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1603
1711
|
...fetchProps
|
1604
1712
|
});
|
1605
1713
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1606
|
-
return initObject(this
|
1714
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1607
1715
|
};
|
1608
1716
|
_deleteRecord = new WeakSet();
|
1609
|
-
deleteRecord_fn = async function(recordId) {
|
1717
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1610
1718
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1719
|
+
try {
|
1720
|
+
const response = await deleteRecord({
|
1721
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1722
|
+
queryParams: { columns },
|
1723
|
+
...fetchProps
|
1724
|
+
});
|
1725
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1726
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1727
|
+
} catch (e) {
|
1728
|
+
if (isObject(e) && e.status === 404) {
|
1729
|
+
return null;
|
1730
|
+
}
|
1731
|
+
throw e;
|
1732
|
+
}
|
1615
1733
|
};
|
1616
1734
|
_setCacheQuery = new WeakSet();
|
1617
1735
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1699,6 +1817,19 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1699
1817
|
function isResponseWithRecords(value) {
|
1700
1818
|
return isObject(value) && Array.isArray(value.records);
|
1701
1819
|
}
|
1820
|
+
function extractId(value) {
|
1821
|
+
if (isString(value))
|
1822
|
+
return value;
|
1823
|
+
if (isObject(value) && isString(value.id))
|
1824
|
+
return value.id;
|
1825
|
+
return void 0;
|
1826
|
+
}
|
1827
|
+
function cleanFilter(filter) {
|
1828
|
+
if (!filter)
|
1829
|
+
return void 0;
|
1830
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
1831
|
+
return values.length > 0 ? filter : void 0;
|
1832
|
+
}
|
1702
1833
|
|
1703
1834
|
var __accessCheck$3 = (obj, member, msg) => {
|
1704
1835
|
if (!member.has(obj))
|
@@ -1749,18 +1880,25 @@ class SimpleCache {
|
|
1749
1880
|
}
|
1750
1881
|
_map = new WeakMap();
|
1751
1882
|
|
1752
|
-
const
|
1753
|
-
const
|
1754
|
-
const
|
1755
|
-
const
|
1756
|
-
const
|
1757
|
-
const
|
1883
|
+
const greaterThan = (value) => ({ $gt: value });
|
1884
|
+
const gt = greaterThan;
|
1885
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
1886
|
+
const greaterEquals = greaterThanEquals;
|
1887
|
+
const gte = greaterThanEquals;
|
1888
|
+
const ge = greaterThanEquals;
|
1889
|
+
const lessThan = (value) => ({ $lt: value });
|
1890
|
+
const lt = lessThan;
|
1891
|
+
const lessThanEquals = (value) => ({ $le: value });
|
1892
|
+
const lessEquals = lessThanEquals;
|
1893
|
+
const lte = lessThanEquals;
|
1894
|
+
const le = lessThanEquals;
|
1758
1895
|
const exists = (column) => ({ $exists: column });
|
1759
1896
|
const notExists = (column) => ({ $notExists: column });
|
1760
1897
|
const startsWith = (value) => ({ $startsWith: value });
|
1761
1898
|
const endsWith = (value) => ({ $endsWith: value });
|
1762
1899
|
const pattern = (value) => ({ $pattern: value });
|
1763
1900
|
const is = (value) => ({ $is: value });
|
1901
|
+
const equals = is;
|
1764
1902
|
const isNot = (value) => ({ $isNot: value });
|
1765
1903
|
const contains = (value) => ({ $contains: value });
|
1766
1904
|
const includes = (value) => ({ $includes: value });
|
@@ -1937,7 +2075,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1937
2075
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1938
2076
|
workspacesApiUrl: `${protocol}//${host}`,
|
1939
2077
|
pathParams: { dbName, workspace },
|
1940
|
-
queryParams: { gitBranch, fallbackBranch }
|
2078
|
+
queryParams: { gitBranch, fallbackBranch },
|
2079
|
+
trace: defaultTrace
|
1941
2080
|
});
|
1942
2081
|
return branch;
|
1943
2082
|
}
|
@@ -1961,7 +2100,8 @@ async function getDatabaseBranch(branch, options) {
|
|
1961
2100
|
apiUrl: databaseURL,
|
1962
2101
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1963
2102
|
workspacesApiUrl: `${protocol}//${host}`,
|
1964
|
-
pathParams: { dbBranchName, workspace }
|
2103
|
+
pathParams: { dbBranchName, workspace },
|
2104
|
+
trace: defaultTrace
|
1965
2105
|
});
|
1966
2106
|
} catch (err) {
|
1967
2107
|
if (isObject(err) && err.status === 404)
|
@@ -2001,17 +2141,20 @@ var __privateMethod = (obj, member, method) => {
|
|
2001
2141
|
return method;
|
2002
2142
|
};
|
2003
2143
|
const buildClient = (plugins) => {
|
2004
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2144
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2005
2145
|
return _a = class {
|
2006
2146
|
constructor(options = {}, schemaTables) {
|
2007
2147
|
__privateAdd(this, _parseOptions);
|
2008
2148
|
__privateAdd(this, _getFetchProps);
|
2009
2149
|
__privateAdd(this, _evaluateBranch);
|
2010
2150
|
__privateAdd(this, _branch, void 0);
|
2151
|
+
__privateAdd(this, _options, void 0);
|
2011
2152
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2153
|
+
__privateSet(this, _options, safeOptions);
|
2012
2154
|
const pluginOptions = {
|
2013
2155
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2014
|
-
cache: safeOptions.cache
|
2156
|
+
cache: safeOptions.cache,
|
2157
|
+
trace: safeOptions.trace
|
2015
2158
|
};
|
2016
2159
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2017
2160
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2030,22 +2173,26 @@ const buildClient = (plugins) => {
|
|
2030
2173
|
}
|
2031
2174
|
}
|
2032
2175
|
}
|
2033
|
-
|
2176
|
+
async getConfig() {
|
2177
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2178
|
+
const branch = await __privateGet(this, _options).branch();
|
2179
|
+
return { databaseURL, branch };
|
2180
|
+
}
|
2181
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
2034
2182
|
const fetch = getFetchImplementation(options?.fetch);
|
2035
2183
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2036
2184
|
const apiKey = options?.apiKey || getAPIKey();
|
2037
2185
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2186
|
+
const trace = options?.trace ?? defaultTrace;
|
2038
2187
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2039
|
-
if (!
|
2040
|
-
throw new Error("
|
2188
|
+
if (!apiKey) {
|
2189
|
+
throw new Error("Option apiKey is required");
|
2041
2190
|
}
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
apiKey,
|
2046
|
-
|
2047
|
-
branch
|
2048
|
-
}) {
|
2191
|
+
if (!databaseURL) {
|
2192
|
+
throw new Error("Option databaseURL is required");
|
2193
|
+
}
|
2194
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace };
|
2195
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
|
2049
2196
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2050
2197
|
if (!branchValue)
|
2051
2198
|
throw new Error("Unable to resolve branch value");
|
@@ -2057,7 +2204,8 @@ const buildClient = (plugins) => {
|
|
2057
2204
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2058
2205
|
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2059
2206
|
return databaseURL + newPath;
|
2060
|
-
}
|
2207
|
+
},
|
2208
|
+
trace
|
2061
2209
|
};
|
2062
2210
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2063
2211
|
if (__privateGet(this, _branch))
|
@@ -2080,6 +2228,88 @@ const buildClient = (plugins) => {
|
|
2080
2228
|
class BaseClient extends buildClient() {
|
2081
2229
|
}
|
2082
2230
|
|
2231
|
+
const META = "__";
|
2232
|
+
const VALUE = "___";
|
2233
|
+
class Serializer {
|
2234
|
+
constructor() {
|
2235
|
+
this.classes = {};
|
2236
|
+
}
|
2237
|
+
add(clazz) {
|
2238
|
+
this.classes[clazz.name] = clazz;
|
2239
|
+
}
|
2240
|
+
toJSON(data) {
|
2241
|
+
function visit(obj) {
|
2242
|
+
if (Array.isArray(obj))
|
2243
|
+
return obj.map(visit);
|
2244
|
+
const type = typeof obj;
|
2245
|
+
if (type === "undefined")
|
2246
|
+
return { [META]: "undefined" };
|
2247
|
+
if (type === "bigint")
|
2248
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2249
|
+
if (obj === null || type !== "object")
|
2250
|
+
return obj;
|
2251
|
+
const constructor = obj.constructor;
|
2252
|
+
const o = { [META]: constructor.name };
|
2253
|
+
for (const [key, value] of Object.entries(obj)) {
|
2254
|
+
o[key] = visit(value);
|
2255
|
+
}
|
2256
|
+
if (constructor === Date)
|
2257
|
+
o[VALUE] = obj.toISOString();
|
2258
|
+
if (constructor === Map)
|
2259
|
+
o[VALUE] = Object.fromEntries(obj);
|
2260
|
+
if (constructor === Set)
|
2261
|
+
o[VALUE] = [...obj];
|
2262
|
+
return o;
|
2263
|
+
}
|
2264
|
+
return JSON.stringify(visit(data));
|
2265
|
+
}
|
2266
|
+
fromJSON(json) {
|
2267
|
+
return JSON.parse(json, (key, value) => {
|
2268
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2269
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2270
|
+
const constructor = this.classes[clazz];
|
2271
|
+
if (constructor) {
|
2272
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2273
|
+
}
|
2274
|
+
if (clazz === "Date")
|
2275
|
+
return new Date(val);
|
2276
|
+
if (clazz === "Set")
|
2277
|
+
return new Set(val);
|
2278
|
+
if (clazz === "Map")
|
2279
|
+
return new Map(Object.entries(val));
|
2280
|
+
if (clazz === "bigint")
|
2281
|
+
return BigInt(val);
|
2282
|
+
if (clazz === "undefined")
|
2283
|
+
return void 0;
|
2284
|
+
return rest;
|
2285
|
+
}
|
2286
|
+
return value;
|
2287
|
+
});
|
2288
|
+
}
|
2289
|
+
}
|
2290
|
+
const defaultSerializer = new Serializer();
|
2291
|
+
const serialize = (data) => {
|
2292
|
+
return defaultSerializer.toJSON(data);
|
2293
|
+
};
|
2294
|
+
const deserialize = (json) => {
|
2295
|
+
return defaultSerializer.fromJSON(json);
|
2296
|
+
};
|
2297
|
+
|
2298
|
+
function buildWorkerRunner(config) {
|
2299
|
+
return function xataWorker(name, _worker) {
|
2300
|
+
return async (...args) => {
|
2301
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2302
|
+
const result = await fetch(url, {
|
2303
|
+
method: "POST",
|
2304
|
+
headers: { "Content-Type": "application/json" },
|
2305
|
+
body: serialize({ args })
|
2306
|
+
});
|
2307
|
+
const text = await result.text();
|
2308
|
+
return deserialize(text);
|
2309
|
+
};
|
2310
|
+
};
|
2311
|
+
}
|
2312
|
+
|
2083
2313
|
class XataError extends Error {
|
2084
2314
|
constructor(message, status) {
|
2085
2315
|
super(message);
|
@@ -2100,6 +2330,7 @@ exports.Repository = Repository;
|
|
2100
2330
|
exports.RestRepository = RestRepository;
|
2101
2331
|
exports.SchemaPlugin = SchemaPlugin;
|
2102
2332
|
exports.SearchPlugin = SearchPlugin;
|
2333
|
+
exports.Serializer = Serializer;
|
2103
2334
|
exports.SimpleCache = SimpleCache;
|
2104
2335
|
exports.XataApiClient = XataApiClient;
|
2105
2336
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2109,6 +2340,7 @@ exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
|
2109
2340
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2110
2341
|
exports.addTableColumn = addTableColumn;
|
2111
2342
|
exports.buildClient = buildClient;
|
2343
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2112
2344
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2113
2345
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2114
2346
|
exports.contains = contains;
|
@@ -2125,7 +2357,9 @@ exports.deleteTable = deleteTable;
|
|
2125
2357
|
exports.deleteUser = deleteUser;
|
2126
2358
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2127
2359
|
exports.deleteWorkspace = deleteWorkspace;
|
2360
|
+
exports.deserialize = deserialize;
|
2128
2361
|
exports.endsWith = endsWith;
|
2362
|
+
exports.equals = equals;
|
2129
2363
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2130
2364
|
exports.exists = exists;
|
2131
2365
|
exports.ge = ge;
|
@@ -2151,6 +2385,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2151
2385
|
exports.getWorkspace = getWorkspace;
|
2152
2386
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2153
2387
|
exports.getWorkspacesList = getWorkspacesList;
|
2388
|
+
exports.greaterEquals = greaterEquals;
|
2389
|
+
exports.greaterThan = greaterThan;
|
2390
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2154
2391
|
exports.gt = gt;
|
2155
2392
|
exports.gte = gte;
|
2156
2393
|
exports.includes = includes;
|
@@ -2166,6 +2403,9 @@ exports.isIdentifiable = isIdentifiable;
|
|
2166
2403
|
exports.isNot = isNot;
|
2167
2404
|
exports.isXataRecord = isXataRecord;
|
2168
2405
|
exports.le = le;
|
2406
|
+
exports.lessEquals = lessEquals;
|
2407
|
+
exports.lessThan = lessThan;
|
2408
|
+
exports.lessThanEquals = lessThanEquals;
|
2169
2409
|
exports.lt = lt;
|
2170
2410
|
exports.lte = lte;
|
2171
2411
|
exports.notExists = notExists;
|
@@ -2178,6 +2418,7 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
2178
2418
|
exports.resolveBranch = resolveBranch;
|
2179
2419
|
exports.searchBranch = searchBranch;
|
2180
2420
|
exports.searchTable = searchTable;
|
2421
|
+
exports.serialize = serialize;
|
2181
2422
|
exports.setTableSchema = setTableSchema;
|
2182
2423
|
exports.startsWith = startsWith;
|
2183
2424
|
exports.updateBranchMetadata = updateBranchMetadata;
|