@xata.io/client 0.28.4 → 0.29.1
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/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +24 -0
- package/dist/index.cjs +311 -272
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +178 -54
- package/dist/index.mjs +311 -273
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -246,7 +246,7 @@ var __accessCheck$8 = (obj, member, msg) => {
|
|
246
246
|
if (!member.has(obj))
|
247
247
|
throw TypeError("Cannot " + msg);
|
248
248
|
};
|
249
|
-
var __privateGet$
|
249
|
+
var __privateGet$7 = (obj, member, getter) => {
|
250
250
|
__accessCheck$8(obj, member, "read from private field");
|
251
251
|
return getter ? getter.call(obj) : member.get(obj);
|
252
252
|
};
|
@@ -255,7 +255,7 @@ var __privateAdd$8 = (obj, member, value) => {
|
|
255
255
|
throw TypeError("Cannot add the same private member more than once");
|
256
256
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
257
257
|
};
|
258
|
-
var __privateSet$
|
258
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
259
259
|
__accessCheck$8(obj, member, "write to private field");
|
260
260
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
261
261
|
return value;
|
@@ -281,19 +281,19 @@ class ApiRequestPool {
|
|
281
281
|
__privateAdd$8(this, _fetch, void 0);
|
282
282
|
__privateAdd$8(this, _queue, void 0);
|
283
283
|
__privateAdd$8(this, _concurrency, void 0);
|
284
|
-
__privateSet$
|
285
|
-
__privateSet$
|
284
|
+
__privateSet$6(this, _queue, []);
|
285
|
+
__privateSet$6(this, _concurrency, concurrency);
|
286
286
|
this.running = 0;
|
287
287
|
this.started = 0;
|
288
288
|
}
|
289
289
|
setFetch(fetch2) {
|
290
|
-
__privateSet$
|
290
|
+
__privateSet$6(this, _fetch, fetch2);
|
291
291
|
}
|
292
292
|
getFetch() {
|
293
|
-
if (!__privateGet$
|
293
|
+
if (!__privateGet$7(this, _fetch)) {
|
294
294
|
throw new Error("Fetch not set");
|
295
295
|
}
|
296
|
-
return __privateGet$
|
296
|
+
return __privateGet$7(this, _fetch);
|
297
297
|
}
|
298
298
|
request(url, options) {
|
299
299
|
const start = /* @__PURE__ */ new Date();
|
@@ -325,19 +325,19 @@ _queue = new WeakMap();
|
|
325
325
|
_concurrency = new WeakMap();
|
326
326
|
_enqueue = new WeakSet();
|
327
327
|
enqueue_fn = function(task) {
|
328
|
-
const promise = new Promise((resolve) => __privateGet$
|
328
|
+
const promise = new Promise((resolve) => __privateGet$7(this, _queue).push(resolve)).finally(() => {
|
329
329
|
this.started--;
|
330
330
|
this.running++;
|
331
331
|
}).then(() => task()).finally(() => {
|
332
332
|
this.running--;
|
333
|
-
const next = __privateGet$
|
333
|
+
const next = __privateGet$7(this, _queue).shift();
|
334
334
|
if (next !== void 0) {
|
335
335
|
this.started++;
|
336
336
|
next();
|
337
337
|
}
|
338
338
|
});
|
339
|
-
if (this.running + this.started < __privateGet$
|
340
|
-
const next = __privateGet$
|
339
|
+
if (this.running + this.started < __privateGet$7(this, _concurrency)) {
|
340
|
+
const next = __privateGet$7(this, _queue).shift();
|
341
341
|
if (next !== void 0) {
|
342
342
|
this.started++;
|
343
343
|
next();
|
@@ -526,7 +526,7 @@ function defaultOnOpen(response) {
|
|
526
526
|
}
|
527
527
|
}
|
528
528
|
|
529
|
-
const VERSION = "0.
|
529
|
+
const VERSION = "0.29.1";
|
530
530
|
|
531
531
|
class ErrorWithCause extends Error {
|
532
532
|
constructor(message, options) {
|
@@ -1347,7 +1347,7 @@ var __accessCheck$7 = (obj, member, msg) => {
|
|
1347
1347
|
if (!member.has(obj))
|
1348
1348
|
throw TypeError("Cannot " + msg);
|
1349
1349
|
};
|
1350
|
-
var __privateGet$
|
1350
|
+
var __privateGet$6 = (obj, member, getter) => {
|
1351
1351
|
__accessCheck$7(obj, member, "read from private field");
|
1352
1352
|
return getter ? getter.call(obj) : member.get(obj);
|
1353
1353
|
};
|
@@ -1356,7 +1356,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
1356
1356
|
throw TypeError("Cannot add the same private member more than once");
|
1357
1357
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1358
1358
|
};
|
1359
|
-
var __privateSet$
|
1359
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
1360
1360
|
__accessCheck$7(obj, member, "write to private field");
|
1361
1361
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1362
1362
|
return value;
|
@@ -1373,7 +1373,7 @@ class XataApiClient {
|
|
1373
1373
|
if (!apiKey) {
|
1374
1374
|
throw new Error("Could not resolve a valid apiKey");
|
1375
1375
|
}
|
1376
|
-
__privateSet$
|
1376
|
+
__privateSet$5(this, _extraProps, {
|
1377
1377
|
apiUrl: getHostUrl(provider, "main"),
|
1378
1378
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
1379
1379
|
fetch: getFetchImplementation(options.fetch),
|
@@ -1385,64 +1385,64 @@ class XataApiClient {
|
|
1385
1385
|
});
|
1386
1386
|
}
|
1387
1387
|
get user() {
|
1388
|
-
if (!__privateGet$
|
1389
|
-
__privateGet$
|
1390
|
-
return __privateGet$
|
1388
|
+
if (!__privateGet$6(this, _namespaces).user)
|
1389
|
+
__privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
|
1390
|
+
return __privateGet$6(this, _namespaces).user;
|
1391
1391
|
}
|
1392
1392
|
get authentication() {
|
1393
|
-
if (!__privateGet$
|
1394
|
-
__privateGet$
|
1395
|
-
return __privateGet$
|
1393
|
+
if (!__privateGet$6(this, _namespaces).authentication)
|
1394
|
+
__privateGet$6(this, _namespaces).authentication = new AuthenticationApi(__privateGet$6(this, _extraProps));
|
1395
|
+
return __privateGet$6(this, _namespaces).authentication;
|
1396
1396
|
}
|
1397
1397
|
get workspaces() {
|
1398
|
-
if (!__privateGet$
|
1399
|
-
__privateGet$
|
1400
|
-
return __privateGet$
|
1398
|
+
if (!__privateGet$6(this, _namespaces).workspaces)
|
1399
|
+
__privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
|
1400
|
+
return __privateGet$6(this, _namespaces).workspaces;
|
1401
1401
|
}
|
1402
1402
|
get invites() {
|
1403
|
-
if (!__privateGet$
|
1404
|
-
__privateGet$
|
1405
|
-
return __privateGet$
|
1403
|
+
if (!__privateGet$6(this, _namespaces).invites)
|
1404
|
+
__privateGet$6(this, _namespaces).invites = new InvitesApi(__privateGet$6(this, _extraProps));
|
1405
|
+
return __privateGet$6(this, _namespaces).invites;
|
1406
1406
|
}
|
1407
1407
|
get database() {
|
1408
|
-
if (!__privateGet$
|
1409
|
-
__privateGet$
|
1410
|
-
return __privateGet$
|
1408
|
+
if (!__privateGet$6(this, _namespaces).database)
|
1409
|
+
__privateGet$6(this, _namespaces).database = new DatabaseApi(__privateGet$6(this, _extraProps));
|
1410
|
+
return __privateGet$6(this, _namespaces).database;
|
1411
1411
|
}
|
1412
1412
|
get branches() {
|
1413
|
-
if (!__privateGet$
|
1414
|
-
__privateGet$
|
1415
|
-
return __privateGet$
|
1413
|
+
if (!__privateGet$6(this, _namespaces).branches)
|
1414
|
+
__privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
|
1415
|
+
return __privateGet$6(this, _namespaces).branches;
|
1416
1416
|
}
|
1417
1417
|
get migrations() {
|
1418
|
-
if (!__privateGet$
|
1419
|
-
__privateGet$
|
1420
|
-
return __privateGet$
|
1418
|
+
if (!__privateGet$6(this, _namespaces).migrations)
|
1419
|
+
__privateGet$6(this, _namespaces).migrations = new MigrationsApi(__privateGet$6(this, _extraProps));
|
1420
|
+
return __privateGet$6(this, _namespaces).migrations;
|
1421
1421
|
}
|
1422
1422
|
get migrationRequests() {
|
1423
|
-
if (!__privateGet$
|
1424
|
-
__privateGet$
|
1425
|
-
return __privateGet$
|
1423
|
+
if (!__privateGet$6(this, _namespaces).migrationRequests)
|
1424
|
+
__privateGet$6(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$6(this, _extraProps));
|
1425
|
+
return __privateGet$6(this, _namespaces).migrationRequests;
|
1426
1426
|
}
|
1427
1427
|
get tables() {
|
1428
|
-
if (!__privateGet$
|
1429
|
-
__privateGet$
|
1430
|
-
return __privateGet$
|
1428
|
+
if (!__privateGet$6(this, _namespaces).tables)
|
1429
|
+
__privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
|
1430
|
+
return __privateGet$6(this, _namespaces).tables;
|
1431
1431
|
}
|
1432
1432
|
get records() {
|
1433
|
-
if (!__privateGet$
|
1434
|
-
__privateGet$
|
1435
|
-
return __privateGet$
|
1433
|
+
if (!__privateGet$6(this, _namespaces).records)
|
1434
|
+
__privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
|
1435
|
+
return __privateGet$6(this, _namespaces).records;
|
1436
1436
|
}
|
1437
1437
|
get files() {
|
1438
|
-
if (!__privateGet$
|
1439
|
-
__privateGet$
|
1440
|
-
return __privateGet$
|
1438
|
+
if (!__privateGet$6(this, _namespaces).files)
|
1439
|
+
__privateGet$6(this, _namespaces).files = new FilesApi(__privateGet$6(this, _extraProps));
|
1440
|
+
return __privateGet$6(this, _namespaces).files;
|
1441
1441
|
}
|
1442
1442
|
get searchAndFilter() {
|
1443
|
-
if (!__privateGet$
|
1444
|
-
__privateGet$
|
1445
|
-
return __privateGet$
|
1443
|
+
if (!__privateGet$6(this, _namespaces).searchAndFilter)
|
1444
|
+
__privateGet$6(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$6(this, _extraProps));
|
1445
|
+
return __privateGet$6(this, _namespaces).searchAndFilter;
|
1446
1446
|
}
|
1447
1447
|
}
|
1448
1448
|
_extraProps = new WeakMap();
|
@@ -1744,6 +1744,30 @@ class BranchApi {
|
|
1744
1744
|
...this.extraProps
|
1745
1745
|
});
|
1746
1746
|
}
|
1747
|
+
pgRollMigrationHistory({
|
1748
|
+
workspace,
|
1749
|
+
region,
|
1750
|
+
database,
|
1751
|
+
branch
|
1752
|
+
}) {
|
1753
|
+
return operationsByTag.branch.pgRollMigrationHistory({
|
1754
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1755
|
+
...this.extraProps
|
1756
|
+
});
|
1757
|
+
}
|
1758
|
+
applyMigration({
|
1759
|
+
workspace,
|
1760
|
+
region,
|
1761
|
+
database,
|
1762
|
+
branch,
|
1763
|
+
migration
|
1764
|
+
}) {
|
1765
|
+
return operationsByTag.branch.applyMigration({
|
1766
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1767
|
+
body: migration,
|
1768
|
+
...this.extraProps
|
1769
|
+
});
|
1770
|
+
}
|
1747
1771
|
}
|
1748
1772
|
class TableApi {
|
1749
1773
|
constructor(extraProps) {
|
@@ -2557,6 +2581,17 @@ class MigrationsApi {
|
|
2557
2581
|
...this.extraProps
|
2558
2582
|
});
|
2559
2583
|
}
|
2584
|
+
getSchema({
|
2585
|
+
workspace,
|
2586
|
+
region,
|
2587
|
+
database,
|
2588
|
+
branch
|
2589
|
+
}) {
|
2590
|
+
return operationsByTag.migrations.getSchema({
|
2591
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2592
|
+
...this.extraProps
|
2593
|
+
});
|
2594
|
+
}
|
2560
2595
|
}
|
2561
2596
|
class DatabaseApi {
|
2562
2597
|
constructor(extraProps) {
|
@@ -2862,7 +2897,7 @@ var __accessCheck$6 = (obj, member, msg) => {
|
|
2862
2897
|
if (!member.has(obj))
|
2863
2898
|
throw TypeError("Cannot " + msg);
|
2864
2899
|
};
|
2865
|
-
var __privateGet$
|
2900
|
+
var __privateGet$5 = (obj, member, getter) => {
|
2866
2901
|
__accessCheck$6(obj, member, "read from private field");
|
2867
2902
|
return getter ? getter.call(obj) : member.get(obj);
|
2868
2903
|
};
|
@@ -2871,7 +2906,7 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
2871
2906
|
throw TypeError("Cannot add the same private member more than once");
|
2872
2907
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
2873
2908
|
};
|
2874
|
-
var __privateSet$
|
2909
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
2875
2910
|
__accessCheck$6(obj, member, "write to private field");
|
2876
2911
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
2877
2912
|
return value;
|
@@ -2880,9 +2915,9 @@ var _query, _page;
|
|
2880
2915
|
class Page {
|
2881
2916
|
constructor(query, meta, records = []) {
|
2882
2917
|
__privateAdd$6(this, _query, void 0);
|
2883
|
-
__privateSet$
|
2918
|
+
__privateSet$4(this, _query, query);
|
2884
2919
|
this.meta = meta;
|
2885
|
-
this.records = new
|
2920
|
+
this.records = new PageRecordArray(this, records);
|
2886
2921
|
}
|
2887
2922
|
/**
|
2888
2923
|
* Retrieves the next page of results.
|
@@ -2891,7 +2926,7 @@ class Page {
|
|
2891
2926
|
* @returns The next page or results.
|
2892
2927
|
*/
|
2893
2928
|
async nextPage(size, offset) {
|
2894
|
-
return __privateGet$
|
2929
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
2895
2930
|
}
|
2896
2931
|
/**
|
2897
2932
|
* Retrieves the previous page of results.
|
@@ -2900,7 +2935,7 @@ class Page {
|
|
2900
2935
|
* @returns The previous page or results.
|
2901
2936
|
*/
|
2902
2937
|
async previousPage(size, offset) {
|
2903
|
-
return __privateGet$
|
2938
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
2904
2939
|
}
|
2905
2940
|
/**
|
2906
2941
|
* Retrieves the start page of results.
|
@@ -2909,7 +2944,7 @@ class Page {
|
|
2909
2944
|
* @returns The start page or results.
|
2910
2945
|
*/
|
2911
2946
|
async startPage(size, offset) {
|
2912
|
-
return __privateGet$
|
2947
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
2913
2948
|
}
|
2914
2949
|
/**
|
2915
2950
|
* Retrieves the end page of results.
|
@@ -2918,7 +2953,7 @@ class Page {
|
|
2918
2953
|
* @returns The end page or results.
|
2919
2954
|
*/
|
2920
2955
|
async endPage(size, offset) {
|
2921
|
-
return __privateGet$
|
2956
|
+
return __privateGet$5(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
2922
2957
|
}
|
2923
2958
|
/**
|
2924
2959
|
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
@@ -2936,11 +2971,38 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
2936
2971
|
function isCursorPaginationOptions(options) {
|
2937
2972
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
2938
2973
|
}
|
2939
|
-
|
2974
|
+
class RecordArray extends Array {
|
2975
|
+
constructor(...args) {
|
2976
|
+
super(...RecordArray.parseConstructorParams(...args));
|
2977
|
+
}
|
2978
|
+
static parseConstructorParams(...args) {
|
2979
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
2980
|
+
return new Array(args[0]);
|
2981
|
+
}
|
2982
|
+
if (args.length <= 1 && Array.isArray(args[0] ?? [])) {
|
2983
|
+
const result = args[0] ?? [];
|
2984
|
+
return new Array(...result);
|
2985
|
+
}
|
2986
|
+
return new Array(...args);
|
2987
|
+
}
|
2988
|
+
toArray() {
|
2989
|
+
return new Array(...this);
|
2990
|
+
}
|
2991
|
+
toSerializable() {
|
2992
|
+
return JSON.parse(this.toString());
|
2993
|
+
}
|
2994
|
+
toString() {
|
2995
|
+
return JSON.stringify(this.toArray());
|
2996
|
+
}
|
2997
|
+
map(callbackfn, thisArg) {
|
2998
|
+
return this.toArray().map(callbackfn, thisArg);
|
2999
|
+
}
|
3000
|
+
}
|
3001
|
+
const _PageRecordArray = class _PageRecordArray extends Array {
|
2940
3002
|
constructor(...args) {
|
2941
|
-
super(...
|
3003
|
+
super(..._PageRecordArray.parseConstructorParams(...args));
|
2942
3004
|
__privateAdd$6(this, _page, void 0);
|
2943
|
-
__privateSet$
|
3005
|
+
__privateSet$4(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
2944
3006
|
}
|
2945
3007
|
static parseConstructorParams(...args) {
|
2946
3008
|
if (args.length === 1 && typeof args[0] === "number") {
|
@@ -2970,8 +3032,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2970
3032
|
* @returns A new array of objects
|
2971
3033
|
*/
|
2972
3034
|
async nextPage(size, offset) {
|
2973
|
-
const newPage = await __privateGet$
|
2974
|
-
return new
|
3035
|
+
const newPage = await __privateGet$5(this, _page).nextPage(size, offset);
|
3036
|
+
return new _PageRecordArray(newPage);
|
2975
3037
|
}
|
2976
3038
|
/**
|
2977
3039
|
* Retrieve previous page of records
|
@@ -2979,8 +3041,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2979
3041
|
* @returns A new array of objects
|
2980
3042
|
*/
|
2981
3043
|
async previousPage(size, offset) {
|
2982
|
-
const newPage = await __privateGet$
|
2983
|
-
return new
|
3044
|
+
const newPage = await __privateGet$5(this, _page).previousPage(size, offset);
|
3045
|
+
return new _PageRecordArray(newPage);
|
2984
3046
|
}
|
2985
3047
|
/**
|
2986
3048
|
* Retrieve start page of records
|
@@ -2988,8 +3050,8 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2988
3050
|
* @returns A new array of objects
|
2989
3051
|
*/
|
2990
3052
|
async startPage(size, offset) {
|
2991
|
-
const newPage = await __privateGet$
|
2992
|
-
return new
|
3053
|
+
const newPage = await __privateGet$5(this, _page).startPage(size, offset);
|
3054
|
+
return new _PageRecordArray(newPage);
|
2993
3055
|
}
|
2994
3056
|
/**
|
2995
3057
|
* Retrieve end page of records
|
@@ -2997,24 +3059,24 @@ const _RecordArray = class _RecordArray extends Array {
|
|
2997
3059
|
* @returns A new array of objects
|
2998
3060
|
*/
|
2999
3061
|
async endPage(size, offset) {
|
3000
|
-
const newPage = await __privateGet$
|
3001
|
-
return new
|
3062
|
+
const newPage = await __privateGet$5(this, _page).endPage(size, offset);
|
3063
|
+
return new _PageRecordArray(newPage);
|
3002
3064
|
}
|
3003
3065
|
/**
|
3004
3066
|
* @returns Boolean indicating if there is a next page
|
3005
3067
|
*/
|
3006
3068
|
hasNextPage() {
|
3007
|
-
return __privateGet$
|
3069
|
+
return __privateGet$5(this, _page).meta.page.more;
|
3008
3070
|
}
|
3009
3071
|
};
|
3010
3072
|
_page = new WeakMap();
|
3011
|
-
let
|
3073
|
+
let PageRecordArray = _PageRecordArray;
|
3012
3074
|
|
3013
3075
|
var __accessCheck$5 = (obj, member, msg) => {
|
3014
3076
|
if (!member.has(obj))
|
3015
3077
|
throw TypeError("Cannot " + msg);
|
3016
3078
|
};
|
3017
|
-
var __privateGet$
|
3079
|
+
var __privateGet$4 = (obj, member, getter) => {
|
3018
3080
|
__accessCheck$5(obj, member, "read from private field");
|
3019
3081
|
return getter ? getter.call(obj) : member.get(obj);
|
3020
3082
|
};
|
@@ -3023,7 +3085,7 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
3023
3085
|
throw TypeError("Cannot add the same private member more than once");
|
3024
3086
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3025
3087
|
};
|
3026
|
-
var __privateSet$
|
3088
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
3027
3089
|
__accessCheck$5(obj, member, "write to private field");
|
3028
3090
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
3029
3091
|
return value;
|
@@ -3041,25 +3103,25 @@ const _Query = class _Query {
|
|
3041
3103
|
__privateAdd$5(this, _data, { filter: {} });
|
3042
3104
|
// Implements pagination
|
3043
3105
|
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
3044
|
-
this.records = new
|
3045
|
-
__privateSet$
|
3106
|
+
this.records = new PageRecordArray(this, []);
|
3107
|
+
__privateSet$3(this, _table$1, table);
|
3046
3108
|
if (repository) {
|
3047
|
-
__privateSet$
|
3109
|
+
__privateSet$3(this, _repository, repository);
|
3048
3110
|
} else {
|
3049
|
-
__privateSet$
|
3111
|
+
__privateSet$3(this, _repository, this);
|
3050
3112
|
}
|
3051
3113
|
const parent = cleanParent(data, rawParent);
|
3052
|
-
__privateGet$
|
3053
|
-
__privateGet$
|
3054
|
-
__privateGet$
|
3055
|
-
__privateGet$
|
3056
|
-
__privateGet$
|
3057
|
-
__privateGet$
|
3058
|
-
__privateGet$
|
3059
|
-
__privateGet$
|
3060
|
-
__privateGet$
|
3061
|
-
__privateGet$
|
3062
|
-
__privateGet$
|
3114
|
+
__privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
3115
|
+
__privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
3116
|
+
__privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
3117
|
+
__privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
3118
|
+
__privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
3119
|
+
__privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
|
3120
|
+
__privateGet$4(this, _data).columns = data.columns ?? parent?.columns;
|
3121
|
+
__privateGet$4(this, _data).consistency = data.consistency ?? parent?.consistency;
|
3122
|
+
__privateGet$4(this, _data).pagination = data.pagination ?? parent?.pagination;
|
3123
|
+
__privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
|
3124
|
+
__privateGet$4(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
3063
3125
|
this.any = this.any.bind(this);
|
3064
3126
|
this.all = this.all.bind(this);
|
3065
3127
|
this.not = this.not.bind(this);
|
@@ -3070,10 +3132,10 @@ const _Query = class _Query {
|
|
3070
3132
|
Object.defineProperty(this, "repository", { enumerable: false });
|
3071
3133
|
}
|
3072
3134
|
getQueryOptions() {
|
3073
|
-
return __privateGet$
|
3135
|
+
return __privateGet$4(this, _data);
|
3074
3136
|
}
|
3075
3137
|
key() {
|
3076
|
-
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$
|
3138
|
+
const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$4(this, _data);
|
3077
3139
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
3078
3140
|
return toBase64(key);
|
3079
3141
|
}
|
@@ -3084,7 +3146,7 @@ const _Query = class _Query {
|
|
3084
3146
|
*/
|
3085
3147
|
any(...queries) {
|
3086
3148
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3087
|
-
return new _Query(__privateGet$
|
3149
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
|
3088
3150
|
}
|
3089
3151
|
/**
|
3090
3152
|
* Builds a new query object representing a logical AND between the given subqueries.
|
@@ -3093,7 +3155,7 @@ const _Query = class _Query {
|
|
3093
3155
|
*/
|
3094
3156
|
all(...queries) {
|
3095
3157
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3096
|
-
return new _Query(__privateGet$
|
3158
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3097
3159
|
}
|
3098
3160
|
/**
|
3099
3161
|
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
@@ -3102,7 +3164,7 @@ const _Query = class _Query {
|
|
3102
3164
|
*/
|
3103
3165
|
not(...queries) {
|
3104
3166
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3105
|
-
return new _Query(__privateGet$
|
3167
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
|
3106
3168
|
}
|
3107
3169
|
/**
|
3108
3170
|
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
@@ -3111,25 +3173,25 @@ const _Query = class _Query {
|
|
3111
3173
|
*/
|
3112
3174
|
none(...queries) {
|
3113
3175
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
3114
|
-
return new _Query(__privateGet$
|
3176
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
|
3115
3177
|
}
|
3116
3178
|
filter(a, b) {
|
3117
3179
|
if (arguments.length === 1) {
|
3118
3180
|
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
3119
3181
|
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
3120
3182
|
}));
|
3121
|
-
const $all = compact([__privateGet$
|
3122
|
-
return new _Query(__privateGet$
|
3183
|
+
const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
|
3184
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3123
3185
|
} else {
|
3124
3186
|
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
3125
|
-
const $all = compact([__privateGet$
|
3126
|
-
return new _Query(__privateGet$
|
3187
|
+
const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
|
3188
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
|
3127
3189
|
}
|
3128
3190
|
}
|
3129
3191
|
sort(column, direction = "asc") {
|
3130
|
-
const originalSort = [__privateGet$
|
3192
|
+
const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
|
3131
3193
|
const sort = [...originalSort, { column, direction }];
|
3132
|
-
return new _Query(__privateGet$
|
3194
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
|
3133
3195
|
}
|
3134
3196
|
/**
|
3135
3197
|
* Builds a new query specifying the set of columns to be returned in the query response.
|
@@ -3138,15 +3200,15 @@ const _Query = class _Query {
|
|
3138
3200
|
*/
|
3139
3201
|
select(columns) {
|
3140
3202
|
return new _Query(
|
3141
|
-
__privateGet$
|
3142
|
-
__privateGet$
|
3203
|
+
__privateGet$4(this, _repository),
|
3204
|
+
__privateGet$4(this, _table$1),
|
3143
3205
|
{ columns },
|
3144
|
-
__privateGet$
|
3206
|
+
__privateGet$4(this, _data)
|
3145
3207
|
);
|
3146
3208
|
}
|
3147
3209
|
getPaginated(options = {}) {
|
3148
|
-
const query = new _Query(__privateGet$
|
3149
|
-
return __privateGet$
|
3210
|
+
const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
|
3211
|
+
return __privateGet$4(this, _repository).query(query);
|
3150
3212
|
}
|
3151
3213
|
/**
|
3152
3214
|
* Get results in an iterator
|
@@ -3183,7 +3245,7 @@ const _Query = class _Query {
|
|
3183
3245
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
3184
3246
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
3185
3247
|
}
|
3186
|
-
const array = new
|
3248
|
+
const array = new PageRecordArray(page, results.slice(0, size));
|
3187
3249
|
return array;
|
3188
3250
|
}
|
3189
3251
|
async getAll(options = {}) {
|
@@ -3192,7 +3254,7 @@ const _Query = class _Query {
|
|
3192
3254
|
for await (const page of this.getIterator({ ...rest, batchSize })) {
|
3193
3255
|
results.push(...page);
|
3194
3256
|
}
|
3195
|
-
return results;
|
3257
|
+
return new RecordArray(results);
|
3196
3258
|
}
|
3197
3259
|
async getFirst(options = {}) {
|
3198
3260
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
@@ -3207,12 +3269,12 @@ const _Query = class _Query {
|
|
3207
3269
|
async summarize(params = {}) {
|
3208
3270
|
const { summaries, summariesFilter, ...options } = params;
|
3209
3271
|
const query = new _Query(
|
3210
|
-
__privateGet$
|
3211
|
-
__privateGet$
|
3272
|
+
__privateGet$4(this, _repository),
|
3273
|
+
__privateGet$4(this, _table$1),
|
3212
3274
|
options,
|
3213
|
-
__privateGet$
|
3275
|
+
__privateGet$4(this, _data)
|
3214
3276
|
);
|
3215
|
-
return __privateGet$
|
3277
|
+
return __privateGet$4(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
3216
3278
|
}
|
3217
3279
|
/**
|
3218
3280
|
* Builds a new query object adding a cache TTL in milliseconds.
|
@@ -3220,7 +3282,7 @@ const _Query = class _Query {
|
|
3220
3282
|
* @returns A new Query object.
|
3221
3283
|
*/
|
3222
3284
|
cache(ttl) {
|
3223
|
-
return new _Query(__privateGet$
|
3285
|
+
return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
|
3224
3286
|
}
|
3225
3287
|
/**
|
3226
3288
|
* Retrieve next page of records
|
@@ -3266,7 +3328,7 @@ _repository = new WeakMap();
|
|
3266
3328
|
_data = new WeakMap();
|
3267
3329
|
_cleanFilterConstraint = new WeakSet();
|
3268
3330
|
cleanFilterConstraint_fn = function(column, value) {
|
3269
|
-
const columnType = __privateGet$
|
3331
|
+
const columnType = __privateGet$4(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
3270
3332
|
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
3271
3333
|
return { $includes: value };
|
3272
3334
|
}
|
@@ -3292,7 +3354,6 @@ const RecordColumnTypes = [
|
|
3292
3354
|
"email",
|
3293
3355
|
"multiple",
|
3294
3356
|
"link",
|
3295
|
-
"object",
|
3296
3357
|
"datetime",
|
3297
3358
|
"vector",
|
3298
3359
|
"file[]",
|
@@ -3357,7 +3418,7 @@ var __accessCheck$4 = (obj, member, msg) => {
|
|
3357
3418
|
if (!member.has(obj))
|
3358
3419
|
throw TypeError("Cannot " + msg);
|
3359
3420
|
};
|
3360
|
-
var __privateGet$
|
3421
|
+
var __privateGet$3 = (obj, member, getter) => {
|
3361
3422
|
__accessCheck$4(obj, member, "read from private field");
|
3362
3423
|
return getter ? getter.call(obj) : member.get(obj);
|
3363
3424
|
};
|
@@ -3366,7 +3427,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
3366
3427
|
throw TypeError("Cannot add the same private member more than once");
|
3367
3428
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
3368
3429
|
};
|
3369
|
-
var __privateSet$
|
3430
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
3370
3431
|
__accessCheck$4(obj, member, "write to private field");
|
3371
3432
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
3372
3433
|
return value;
|
@@ -3375,7 +3436,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
3375
3436
|
__accessCheck$4(obj, member, "access private method");
|
3376
3437
|
return method;
|
3377
3438
|
};
|
3378
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables
|
3439
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables, getSchemaTables_fn, _transformObjectToApi, transformObjectToApi_fn;
|
3379
3440
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
3380
3441
|
class Repository extends Query {
|
3381
3442
|
}
|
@@ -3396,31 +3457,31 @@ class RestRepository extends Query {
|
|
3396
3457
|
__privateAdd$4(this, _deleteRecords);
|
3397
3458
|
__privateAdd$4(this, _setCacheQuery);
|
3398
3459
|
__privateAdd$4(this, _getCacheQuery);
|
3399
|
-
__privateAdd$4(this, _getSchemaTables
|
3460
|
+
__privateAdd$4(this, _getSchemaTables);
|
3400
3461
|
__privateAdd$4(this, _transformObjectToApi);
|
3401
3462
|
__privateAdd$4(this, _table, void 0);
|
3402
3463
|
__privateAdd$4(this, _getFetchProps, void 0);
|
3403
3464
|
__privateAdd$4(this, _db, void 0);
|
3404
3465
|
__privateAdd$4(this, _cache, void 0);
|
3405
|
-
__privateAdd$4(this, _schemaTables
|
3466
|
+
__privateAdd$4(this, _schemaTables, void 0);
|
3406
3467
|
__privateAdd$4(this, _trace, void 0);
|
3407
|
-
__privateSet$
|
3408
|
-
__privateSet$
|
3409
|
-
__privateSet$
|
3410
|
-
__privateSet$
|
3411
|
-
__privateSet$
|
3468
|
+
__privateSet$2(this, _table, options.table);
|
3469
|
+
__privateSet$2(this, _db, options.db);
|
3470
|
+
__privateSet$2(this, _cache, options.pluginOptions.cache);
|
3471
|
+
__privateSet$2(this, _schemaTables, options.schemaTables);
|
3472
|
+
__privateSet$2(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
3412
3473
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
3413
|
-
__privateSet$
|
3474
|
+
__privateSet$2(this, _trace, async (name, fn, options2 = {}) => {
|
3414
3475
|
return trace(name, fn, {
|
3415
3476
|
...options2,
|
3416
|
-
[TraceAttributes.TABLE]: __privateGet$
|
3477
|
+
[TraceAttributes.TABLE]: __privateGet$3(this, _table),
|
3417
3478
|
[TraceAttributes.KIND]: "sdk-operation",
|
3418
3479
|
[TraceAttributes.VERSION]: VERSION
|
3419
3480
|
});
|
3420
3481
|
});
|
3421
3482
|
}
|
3422
3483
|
async create(a, b, c, d) {
|
3423
|
-
return __privateGet$
|
3484
|
+
return __privateGet$3(this, _trace).call(this, "create", async () => {
|
3424
3485
|
const ifVersion = parseIfVersion(b, c, d);
|
3425
3486
|
if (Array.isArray(a)) {
|
3426
3487
|
if (a.length === 0)
|
@@ -3450,7 +3511,7 @@ class RestRepository extends Query {
|
|
3450
3511
|
});
|
3451
3512
|
}
|
3452
3513
|
async read(a, b) {
|
3453
|
-
return __privateGet$
|
3514
|
+
return __privateGet$3(this, _trace).call(this, "read", async () => {
|
3454
3515
|
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3455
3516
|
if (Array.isArray(a)) {
|
3456
3517
|
if (a.length === 0)
|
@@ -3471,17 +3532,17 @@ class RestRepository extends Query {
|
|
3471
3532
|
workspace: "{workspaceId}",
|
3472
3533
|
dbBranchName: "{dbBranch}",
|
3473
3534
|
region: "{region}",
|
3474
|
-
tableName: __privateGet$
|
3535
|
+
tableName: __privateGet$3(this, _table),
|
3475
3536
|
recordId: id
|
3476
3537
|
},
|
3477
3538
|
queryParams: { columns },
|
3478
|
-
...__privateGet$
|
3539
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3479
3540
|
});
|
3480
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3541
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3481
3542
|
return initObject(
|
3482
|
-
__privateGet$
|
3543
|
+
__privateGet$3(this, _db),
|
3483
3544
|
schemaTables,
|
3484
|
-
__privateGet$
|
3545
|
+
__privateGet$3(this, _table),
|
3485
3546
|
response,
|
3486
3547
|
columns
|
3487
3548
|
);
|
@@ -3496,7 +3557,7 @@ class RestRepository extends Query {
|
|
3496
3557
|
});
|
3497
3558
|
}
|
3498
3559
|
async readOrThrow(a, b) {
|
3499
|
-
return __privateGet$
|
3560
|
+
return __privateGet$3(this, _trace).call(this, "readOrThrow", async () => {
|
3500
3561
|
const result = await this.read(a, b);
|
3501
3562
|
if (Array.isArray(result)) {
|
3502
3563
|
const missingIds = compact(
|
@@ -3515,7 +3576,7 @@ class RestRepository extends Query {
|
|
3515
3576
|
});
|
3516
3577
|
}
|
3517
3578
|
async update(a, b, c, d) {
|
3518
|
-
return __privateGet$
|
3579
|
+
return __privateGet$3(this, _trace).call(this, "update", async () => {
|
3519
3580
|
const ifVersion = parseIfVersion(b, c, d);
|
3520
3581
|
if (Array.isArray(a)) {
|
3521
3582
|
if (a.length === 0)
|
@@ -3548,7 +3609,7 @@ class RestRepository extends Query {
|
|
3548
3609
|
});
|
3549
3610
|
}
|
3550
3611
|
async updateOrThrow(a, b, c, d) {
|
3551
|
-
return __privateGet$
|
3612
|
+
return __privateGet$3(this, _trace).call(this, "updateOrThrow", async () => {
|
3552
3613
|
const result = await this.update(a, b, c, d);
|
3553
3614
|
if (Array.isArray(result)) {
|
3554
3615
|
const missingIds = compact(
|
@@ -3567,7 +3628,7 @@ class RestRepository extends Query {
|
|
3567
3628
|
});
|
3568
3629
|
}
|
3569
3630
|
async createOrUpdate(a, b, c, d) {
|
3570
|
-
return __privateGet$
|
3631
|
+
return __privateGet$3(this, _trace).call(this, "createOrUpdate", async () => {
|
3571
3632
|
const ifVersion = parseIfVersion(b, c, d);
|
3572
3633
|
if (Array.isArray(a)) {
|
3573
3634
|
if (a.length === 0)
|
@@ -3602,7 +3663,7 @@ class RestRepository extends Query {
|
|
3602
3663
|
});
|
3603
3664
|
}
|
3604
3665
|
async createOrReplace(a, b, c, d) {
|
3605
|
-
return __privateGet$
|
3666
|
+
return __privateGet$3(this, _trace).call(this, "createOrReplace", async () => {
|
3606
3667
|
const ifVersion = parseIfVersion(b, c, d);
|
3607
3668
|
if (Array.isArray(a)) {
|
3608
3669
|
if (a.length === 0)
|
@@ -3634,7 +3695,7 @@ class RestRepository extends Query {
|
|
3634
3695
|
});
|
3635
3696
|
}
|
3636
3697
|
async delete(a, b) {
|
3637
|
-
return __privateGet$
|
3698
|
+
return __privateGet$3(this, _trace).call(this, "delete", async () => {
|
3638
3699
|
if (Array.isArray(a)) {
|
3639
3700
|
if (a.length === 0)
|
3640
3701
|
return [];
|
@@ -3660,7 +3721,7 @@ class RestRepository extends Query {
|
|
3660
3721
|
});
|
3661
3722
|
}
|
3662
3723
|
async deleteOrThrow(a, b) {
|
3663
|
-
return __privateGet$
|
3724
|
+
return __privateGet$3(this, _trace).call(this, "deleteOrThrow", async () => {
|
3664
3725
|
const result = await this.delete(a, b);
|
3665
3726
|
if (Array.isArray(result)) {
|
3666
3727
|
const missingIds = compact(
|
@@ -3678,13 +3739,13 @@ class RestRepository extends Query {
|
|
3678
3739
|
});
|
3679
3740
|
}
|
3680
3741
|
async search(query, options = {}) {
|
3681
|
-
return __privateGet$
|
3742
|
+
return __privateGet$3(this, _trace).call(this, "search", async () => {
|
3682
3743
|
const { records, totalCount } = await searchTable({
|
3683
3744
|
pathParams: {
|
3684
3745
|
workspace: "{workspaceId}",
|
3685
3746
|
dbBranchName: "{dbBranch}",
|
3686
3747
|
region: "{region}",
|
3687
|
-
tableName: __privateGet$
|
3748
|
+
tableName: __privateGet$3(this, _table)
|
3688
3749
|
},
|
3689
3750
|
body: {
|
3690
3751
|
query,
|
@@ -3696,23 +3757,23 @@ class RestRepository extends Query {
|
|
3696
3757
|
page: options.page,
|
3697
3758
|
target: options.target
|
3698
3759
|
},
|
3699
|
-
...__privateGet$
|
3760
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3700
3761
|
});
|
3701
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3762
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3702
3763
|
return {
|
3703
|
-
records: records.map((item) => initObject(__privateGet$
|
3764
|
+
records: records.map((item) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), item, ["*"])),
|
3704
3765
|
totalCount
|
3705
3766
|
};
|
3706
3767
|
});
|
3707
3768
|
}
|
3708
3769
|
async vectorSearch(column, query, options) {
|
3709
|
-
return __privateGet$
|
3770
|
+
return __privateGet$3(this, _trace).call(this, "vectorSearch", async () => {
|
3710
3771
|
const { records, totalCount } = await vectorSearchTable({
|
3711
3772
|
pathParams: {
|
3712
3773
|
workspace: "{workspaceId}",
|
3713
3774
|
dbBranchName: "{dbBranch}",
|
3714
3775
|
region: "{region}",
|
3715
|
-
tableName: __privateGet$
|
3776
|
+
tableName: __privateGet$3(this, _table)
|
3716
3777
|
},
|
3717
3778
|
body: {
|
3718
3779
|
column,
|
@@ -3721,32 +3782,32 @@ class RestRepository extends Query {
|
|
3721
3782
|
size: options?.size,
|
3722
3783
|
filter: options?.filter
|
3723
3784
|
},
|
3724
|
-
...__privateGet$
|
3785
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3725
3786
|
});
|
3726
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3787
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3727
3788
|
return {
|
3728
|
-
records: records.map((item) => initObject(__privateGet$
|
3789
|
+
records: records.map((item) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), item, ["*"])),
|
3729
3790
|
totalCount
|
3730
3791
|
};
|
3731
3792
|
});
|
3732
3793
|
}
|
3733
3794
|
async aggregate(aggs, filter) {
|
3734
|
-
return __privateGet$
|
3795
|
+
return __privateGet$3(this, _trace).call(this, "aggregate", async () => {
|
3735
3796
|
const result = await aggregateTable({
|
3736
3797
|
pathParams: {
|
3737
3798
|
workspace: "{workspaceId}",
|
3738
3799
|
dbBranchName: "{dbBranch}",
|
3739
3800
|
region: "{region}",
|
3740
|
-
tableName: __privateGet$
|
3801
|
+
tableName: __privateGet$3(this, _table)
|
3741
3802
|
},
|
3742
3803
|
body: { aggs, filter },
|
3743
|
-
...__privateGet$
|
3804
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3744
3805
|
});
|
3745
3806
|
return result;
|
3746
3807
|
});
|
3747
3808
|
}
|
3748
3809
|
async query(query) {
|
3749
|
-
return __privateGet$
|
3810
|
+
return __privateGet$3(this, _trace).call(this, "query", async () => {
|
3750
3811
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
3751
3812
|
if (cacheQuery)
|
3752
3813
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
@@ -3756,7 +3817,7 @@ class RestRepository extends Query {
|
|
3756
3817
|
workspace: "{workspaceId}",
|
3757
3818
|
dbBranchName: "{dbBranch}",
|
3758
3819
|
region: "{region}",
|
3759
|
-
tableName: __privateGet$
|
3820
|
+
tableName: __privateGet$3(this, _table)
|
3760
3821
|
},
|
3761
3822
|
body: {
|
3762
3823
|
filter: cleanFilter(data.filter),
|
@@ -3766,14 +3827,14 @@ class RestRepository extends Query {
|
|
3766
3827
|
consistency: data.consistency
|
3767
3828
|
},
|
3768
3829
|
fetchOptions: data.fetchOptions,
|
3769
|
-
...__privateGet$
|
3830
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3770
3831
|
});
|
3771
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3832
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3772
3833
|
const records = objects.map(
|
3773
3834
|
(record) => initObject(
|
3774
|
-
__privateGet$
|
3835
|
+
__privateGet$3(this, _db),
|
3775
3836
|
schemaTables,
|
3776
|
-
__privateGet$
|
3837
|
+
__privateGet$3(this, _table),
|
3777
3838
|
record,
|
3778
3839
|
data.columns ?? ["*"]
|
3779
3840
|
)
|
@@ -3783,14 +3844,14 @@ class RestRepository extends Query {
|
|
3783
3844
|
});
|
3784
3845
|
}
|
3785
3846
|
async summarizeTable(query, summaries, summariesFilter) {
|
3786
|
-
return __privateGet$
|
3847
|
+
return __privateGet$3(this, _trace).call(this, "summarize", async () => {
|
3787
3848
|
const data = query.getQueryOptions();
|
3788
3849
|
const result = await summarizeTable({
|
3789
3850
|
pathParams: {
|
3790
3851
|
workspace: "{workspaceId}",
|
3791
3852
|
dbBranchName: "{dbBranch}",
|
3792
3853
|
region: "{region}",
|
3793
|
-
tableName: __privateGet$
|
3854
|
+
tableName: __privateGet$3(this, _table)
|
3794
3855
|
},
|
3795
3856
|
body: {
|
3796
3857
|
filter: cleanFilter(data.filter),
|
@@ -3801,13 +3862,13 @@ class RestRepository extends Query {
|
|
3801
3862
|
summaries,
|
3802
3863
|
summariesFilter
|
3803
3864
|
},
|
3804
|
-
...__privateGet$
|
3865
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3805
3866
|
});
|
3806
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3867
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3807
3868
|
return {
|
3808
3869
|
...result,
|
3809
3870
|
summaries: result.summaries.map(
|
3810
|
-
(summary) => initObject(__privateGet$
|
3871
|
+
(summary) => initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), summary, data.columns ?? [])
|
3811
3872
|
)
|
3812
3873
|
};
|
3813
3874
|
});
|
@@ -3819,7 +3880,7 @@ class RestRepository extends Query {
|
|
3819
3880
|
workspace: "{workspaceId}",
|
3820
3881
|
dbBranchName: "{dbBranch}",
|
3821
3882
|
region: "{region}",
|
3822
|
-
tableName: __privateGet$
|
3883
|
+
tableName: __privateGet$3(this, _table),
|
3823
3884
|
sessionId: options?.sessionId
|
3824
3885
|
},
|
3825
3886
|
body: {
|
@@ -3829,7 +3890,7 @@ class RestRepository extends Query {
|
|
3829
3890
|
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3830
3891
|
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3831
3892
|
},
|
3832
|
-
...__privateGet$
|
3893
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3833
3894
|
};
|
3834
3895
|
if (options?.onMessage) {
|
3835
3896
|
fetchSSERequest({
|
@@ -3850,7 +3911,7 @@ _table = new WeakMap();
|
|
3850
3911
|
_getFetchProps = new WeakMap();
|
3851
3912
|
_db = new WeakMap();
|
3852
3913
|
_cache = new WeakMap();
|
3853
|
-
_schemaTables
|
3914
|
+
_schemaTables = new WeakMap();
|
3854
3915
|
_trace = new WeakMap();
|
3855
3916
|
_insertRecordWithoutId = new WeakSet();
|
3856
3917
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
@@ -3860,14 +3921,14 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
3860
3921
|
workspace: "{workspaceId}",
|
3861
3922
|
dbBranchName: "{dbBranch}",
|
3862
3923
|
region: "{region}",
|
3863
|
-
tableName: __privateGet$
|
3924
|
+
tableName: __privateGet$3(this, _table)
|
3864
3925
|
},
|
3865
3926
|
queryParams: { columns },
|
3866
3927
|
body: record,
|
3867
|
-
...__privateGet$
|
3928
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3868
3929
|
});
|
3869
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3870
|
-
return initObject(__privateGet$
|
3930
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3931
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3871
3932
|
};
|
3872
3933
|
_insertRecordWithId = new WeakSet();
|
3873
3934
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
@@ -3879,21 +3940,21 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
3879
3940
|
workspace: "{workspaceId}",
|
3880
3941
|
dbBranchName: "{dbBranch}",
|
3881
3942
|
region: "{region}",
|
3882
|
-
tableName: __privateGet$
|
3943
|
+
tableName: __privateGet$3(this, _table),
|
3883
3944
|
recordId
|
3884
3945
|
},
|
3885
3946
|
body: record,
|
3886
3947
|
queryParams: { createOnly, columns, ifVersion },
|
3887
|
-
...__privateGet$
|
3948
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3888
3949
|
});
|
3889
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3890
|
-
return initObject(__privateGet$
|
3950
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
3951
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3891
3952
|
};
|
3892
3953
|
_insertRecords = new WeakSet();
|
3893
3954
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3894
3955
|
const operations = await promiseMap(objects, async (object) => {
|
3895
3956
|
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3896
|
-
return { insert: { table: __privateGet$
|
3957
|
+
return { insert: { table: __privateGet$3(this, _table), record, createOnly, ifVersion } };
|
3897
3958
|
});
|
3898
3959
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3899
3960
|
const ids = [];
|
@@ -3905,7 +3966,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
3905
3966
|
region: "{region}"
|
3906
3967
|
},
|
3907
3968
|
body: { operations: operations2 },
|
3908
|
-
...__privateGet$
|
3969
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3909
3970
|
});
|
3910
3971
|
for (const result of results) {
|
3911
3972
|
if (result.operation === "insert") {
|
@@ -3928,15 +3989,15 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3928
3989
|
workspace: "{workspaceId}",
|
3929
3990
|
dbBranchName: "{dbBranch}",
|
3930
3991
|
region: "{region}",
|
3931
|
-
tableName: __privateGet$
|
3992
|
+
tableName: __privateGet$3(this, _table),
|
3932
3993
|
recordId
|
3933
3994
|
},
|
3934
3995
|
queryParams: { columns, ifVersion },
|
3935
3996
|
body: record,
|
3936
|
-
...__privateGet$
|
3997
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3937
3998
|
});
|
3938
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3939
|
-
return initObject(__privateGet$
|
3999
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4000
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3940
4001
|
} catch (e) {
|
3941
4002
|
if (isObject(e) && e.status === 404) {
|
3942
4003
|
return null;
|
@@ -3948,7 +4009,7 @@ _updateRecords = new WeakSet();
|
|
3948
4009
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3949
4010
|
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3950
4011
|
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3951
|
-
return { update: { table: __privateGet$
|
4012
|
+
return { update: { table: __privateGet$3(this, _table), id, ifVersion, upsert, fields } };
|
3952
4013
|
});
|
3953
4014
|
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3954
4015
|
const ids = [];
|
@@ -3960,7 +4021,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
3960
4021
|
region: "{region}"
|
3961
4022
|
},
|
3962
4023
|
body: { operations: operations2 },
|
3963
|
-
...__privateGet$
|
4024
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3964
4025
|
});
|
3965
4026
|
for (const result of results) {
|
3966
4027
|
if (result.operation === "update") {
|
@@ -3981,15 +4042,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3981
4042
|
workspace: "{workspaceId}",
|
3982
4043
|
dbBranchName: "{dbBranch}",
|
3983
4044
|
region: "{region}",
|
3984
|
-
tableName: __privateGet$
|
4045
|
+
tableName: __privateGet$3(this, _table),
|
3985
4046
|
recordId
|
3986
4047
|
},
|
3987
4048
|
queryParams: { columns, ifVersion },
|
3988
4049
|
body: object,
|
3989
|
-
...__privateGet$
|
4050
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
3990
4051
|
});
|
3991
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
3992
|
-
return initObject(__privateGet$
|
4052
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4053
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
3993
4054
|
};
|
3994
4055
|
_deleteRecord = new WeakSet();
|
3995
4056
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
@@ -4001,14 +4062,14 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
4001
4062
|
workspace: "{workspaceId}",
|
4002
4063
|
dbBranchName: "{dbBranch}",
|
4003
4064
|
region: "{region}",
|
4004
|
-
tableName: __privateGet$
|
4065
|
+
tableName: __privateGet$3(this, _table),
|
4005
4066
|
recordId
|
4006
4067
|
},
|
4007
4068
|
queryParams: { columns },
|
4008
|
-
...__privateGet$
|
4069
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
4009
4070
|
});
|
4010
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
4011
|
-
return initObject(__privateGet$
|
4071
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4072
|
+
return initObject(__privateGet$3(this, _db), schemaTables, __privateGet$3(this, _table), response, columns);
|
4012
4073
|
} catch (e) {
|
4013
4074
|
if (isObject(e) && e.status === 404) {
|
4014
4075
|
return null;
|
@@ -4019,7 +4080,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
4019
4080
|
_deleteRecords = new WeakSet();
|
4020
4081
|
deleteRecords_fn = async function(recordIds) {
|
4021
4082
|
const chunkedOperations = chunk(
|
4022
|
-
compact(recordIds).map((id) => ({ delete: { table: __privateGet$
|
4083
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$3(this, _table), id } })),
|
4023
4084
|
BULK_OPERATION_MAX_SIZE
|
4024
4085
|
);
|
4025
4086
|
for (const operations of chunkedOperations) {
|
@@ -4030,44 +4091,44 @@ deleteRecords_fn = async function(recordIds) {
|
|
4030
4091
|
region: "{region}"
|
4031
4092
|
},
|
4032
4093
|
body: { operations },
|
4033
|
-
...__privateGet$
|
4094
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
4034
4095
|
});
|
4035
4096
|
}
|
4036
4097
|
};
|
4037
4098
|
_setCacheQuery = new WeakSet();
|
4038
4099
|
setCacheQuery_fn = async function(query, meta, records) {
|
4039
|
-
await __privateGet$
|
4100
|
+
await __privateGet$3(this, _cache)?.set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
4040
4101
|
};
|
4041
4102
|
_getCacheQuery = new WeakSet();
|
4042
4103
|
getCacheQuery_fn = async function(query) {
|
4043
|
-
const key = `query_${__privateGet$
|
4044
|
-
const result = await __privateGet$
|
4104
|
+
const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
|
4105
|
+
const result = await __privateGet$3(this, _cache)?.get(key);
|
4045
4106
|
if (!result)
|
4046
4107
|
return null;
|
4047
|
-
const defaultTTL = __privateGet$
|
4108
|
+
const defaultTTL = __privateGet$3(this, _cache)?.defaultQueryTTL ?? -1;
|
4048
4109
|
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
4049
4110
|
if (ttl < 0)
|
4050
4111
|
return null;
|
4051
4112
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
4052
4113
|
return hasExpired ? null : result;
|
4053
4114
|
};
|
4054
|
-
_getSchemaTables
|
4055
|
-
getSchemaTables_fn
|
4056
|
-
if (__privateGet$
|
4057
|
-
return __privateGet$
|
4115
|
+
_getSchemaTables = new WeakSet();
|
4116
|
+
getSchemaTables_fn = async function() {
|
4117
|
+
if (__privateGet$3(this, _schemaTables))
|
4118
|
+
return __privateGet$3(this, _schemaTables);
|
4058
4119
|
const { schema } = await getBranchDetails({
|
4059
4120
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4060
|
-
...__privateGet$
|
4121
|
+
...__privateGet$3(this, _getFetchProps).call(this)
|
4061
4122
|
});
|
4062
|
-
__privateSet$
|
4123
|
+
__privateSet$2(this, _schemaTables, schema.tables);
|
4063
4124
|
return schema.tables;
|
4064
4125
|
};
|
4065
4126
|
_transformObjectToApi = new WeakSet();
|
4066
4127
|
transformObjectToApi_fn = async function(object) {
|
4067
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables
|
4068
|
-
const schema = schemaTables.find((table) => table.name === __privateGet$
|
4128
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables, getSchemaTables_fn).call(this);
|
4129
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$3(this, _table));
|
4069
4130
|
if (!schema)
|
4070
|
-
throw new Error(`Table ${__privateGet$
|
4131
|
+
throw new Error(`Table ${__privateGet$3(this, _table)} not found in schema`);
|
4071
4132
|
const result = {};
|
4072
4133
|
for (const [key, value] of Object.entries(object)) {
|
4073
4134
|
if (key === "xata")
|
@@ -4223,7 +4284,7 @@ var __accessCheck$3 = (obj, member, msg) => {
|
|
4223
4284
|
if (!member.has(obj))
|
4224
4285
|
throw TypeError("Cannot " + msg);
|
4225
4286
|
};
|
4226
|
-
var __privateGet$
|
4287
|
+
var __privateGet$2 = (obj, member, getter) => {
|
4227
4288
|
__accessCheck$3(obj, member, "read from private field");
|
4228
4289
|
return getter ? getter.call(obj) : member.get(obj);
|
4229
4290
|
};
|
@@ -4232,7 +4293,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
4232
4293
|
throw TypeError("Cannot add the same private member more than once");
|
4233
4294
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4234
4295
|
};
|
4235
|
-
var __privateSet$
|
4296
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
4236
4297
|
__accessCheck$3(obj, member, "write to private field");
|
4237
4298
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
4238
4299
|
return value;
|
@@ -4241,29 +4302,29 @@ var _map;
|
|
4241
4302
|
class SimpleCache {
|
4242
4303
|
constructor(options = {}) {
|
4243
4304
|
__privateAdd$3(this, _map, void 0);
|
4244
|
-
__privateSet$
|
4305
|
+
__privateSet$1(this, _map, /* @__PURE__ */ new Map());
|
4245
4306
|
this.capacity = options.max ?? 500;
|
4246
4307
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
4247
4308
|
}
|
4248
4309
|
async getAll() {
|
4249
|
-
return Object.fromEntries(__privateGet$
|
4310
|
+
return Object.fromEntries(__privateGet$2(this, _map));
|
4250
4311
|
}
|
4251
4312
|
async get(key) {
|
4252
|
-
return __privateGet$
|
4313
|
+
return __privateGet$2(this, _map).get(key) ?? null;
|
4253
4314
|
}
|
4254
4315
|
async set(key, value) {
|
4255
4316
|
await this.delete(key);
|
4256
|
-
__privateGet$
|
4257
|
-
if (__privateGet$
|
4258
|
-
const leastRecentlyUsed = __privateGet$
|
4317
|
+
__privateGet$2(this, _map).set(key, value);
|
4318
|
+
if (__privateGet$2(this, _map).size > this.capacity) {
|
4319
|
+
const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
|
4259
4320
|
await this.delete(leastRecentlyUsed);
|
4260
4321
|
}
|
4261
4322
|
}
|
4262
4323
|
async delete(key) {
|
4263
|
-
__privateGet$
|
4324
|
+
__privateGet$2(this, _map).delete(key);
|
4264
4325
|
}
|
4265
4326
|
async clear() {
|
4266
|
-
return __privateGet$
|
4327
|
+
return __privateGet$2(this, _map).clear();
|
4267
4328
|
}
|
4268
4329
|
}
|
4269
4330
|
_map = new WeakMap();
|
@@ -4300,7 +4361,7 @@ var __accessCheck$2 = (obj, member, msg) => {
|
|
4300
4361
|
if (!member.has(obj))
|
4301
4362
|
throw TypeError("Cannot " + msg);
|
4302
4363
|
};
|
4303
|
-
var __privateGet$
|
4364
|
+
var __privateGet$1 = (obj, member, getter) => {
|
4304
4365
|
__accessCheck$2(obj, member, "read from private field");
|
4305
4366
|
return getter ? getter.call(obj) : member.get(obj);
|
4306
4367
|
};
|
@@ -4309,18 +4370,11 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
4309
4370
|
throw TypeError("Cannot add the same private member more than once");
|
4310
4371
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4311
4372
|
};
|
4312
|
-
var
|
4313
|
-
__accessCheck$2(obj, member, "write to private field");
|
4314
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
4315
|
-
return value;
|
4316
|
-
};
|
4317
|
-
var _tables, _schemaTables$1;
|
4373
|
+
var _tables;
|
4318
4374
|
class SchemaPlugin extends XataPlugin {
|
4319
|
-
constructor(
|
4375
|
+
constructor() {
|
4320
4376
|
super();
|
4321
4377
|
__privateAdd$2(this, _tables, {});
|
4322
|
-
__privateAdd$2(this, _schemaTables$1, void 0);
|
4323
|
-
__privateSet$2(this, _schemaTables$1, schemaTables);
|
4324
4378
|
}
|
4325
4379
|
build(pluginOptions) {
|
4326
4380
|
const db = new Proxy(
|
@@ -4329,22 +4383,21 @@ class SchemaPlugin extends XataPlugin {
|
|
4329
4383
|
get: (_target, table) => {
|
4330
4384
|
if (!isString(table))
|
4331
4385
|
throw new Error("Invalid table name");
|
4332
|
-
if (__privateGet$
|
4333
|
-
__privateGet$
|
4386
|
+
if (__privateGet$1(this, _tables)[table] === void 0) {
|
4387
|
+
__privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
4334
4388
|
}
|
4335
|
-
return __privateGet$
|
4389
|
+
return __privateGet$1(this, _tables)[table];
|
4336
4390
|
}
|
4337
4391
|
}
|
4338
4392
|
);
|
4339
|
-
const tableNames =
|
4393
|
+
const tableNames = pluginOptions.tables?.map(({ name }) => name) ?? [];
|
4340
4394
|
for (const table of tableNames) {
|
4341
|
-
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables:
|
4395
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: pluginOptions.tables });
|
4342
4396
|
}
|
4343
4397
|
return db;
|
4344
4398
|
}
|
4345
4399
|
}
|
4346
4400
|
_tables = new WeakMap();
|
4347
|
-
_schemaTables$1 = new WeakMap();
|
4348
4401
|
|
4349
4402
|
class FilesPlugin extends XataPlugin {
|
4350
4403
|
build(pluginOptions) {
|
@@ -4424,54 +4477,40 @@ var __accessCheck$1 = (obj, member, msg) => {
|
|
4424
4477
|
if (!member.has(obj))
|
4425
4478
|
throw TypeError("Cannot " + msg);
|
4426
4479
|
};
|
4427
|
-
var __privateGet$1 = (obj, member, getter) => {
|
4428
|
-
__accessCheck$1(obj, member, "read from private field");
|
4429
|
-
return getter ? getter.call(obj) : member.get(obj);
|
4430
|
-
};
|
4431
4480
|
var __privateAdd$1 = (obj, member, value) => {
|
4432
4481
|
if (member.has(obj))
|
4433
4482
|
throw TypeError("Cannot add the same private member more than once");
|
4434
4483
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
4435
4484
|
};
|
4436
|
-
var __privateSet$1 = (obj, member, value, setter) => {
|
4437
|
-
__accessCheck$1(obj, member, "write to private field");
|
4438
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
4439
|
-
return value;
|
4440
|
-
};
|
4441
4485
|
var __privateMethod$1 = (obj, member, method) => {
|
4442
4486
|
__accessCheck$1(obj, member, "access private method");
|
4443
4487
|
return method;
|
4444
4488
|
};
|
4445
|
-
var
|
4489
|
+
var _search, search_fn;
|
4446
4490
|
class SearchPlugin extends XataPlugin {
|
4447
|
-
constructor(db
|
4491
|
+
constructor(db) {
|
4448
4492
|
super();
|
4449
4493
|
this.db = db;
|
4450
4494
|
__privateAdd$1(this, _search);
|
4451
|
-
__privateAdd$1(this, _getSchemaTables);
|
4452
|
-
__privateAdd$1(this, _schemaTables, void 0);
|
4453
|
-
__privateSet$1(this, _schemaTables, schemaTables);
|
4454
4495
|
}
|
4455
4496
|
build(pluginOptions) {
|
4456
4497
|
return {
|
4457
4498
|
all: async (query, options = {}) => {
|
4458
4499
|
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4459
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4460
4500
|
return {
|
4461
4501
|
totalCount,
|
4462
4502
|
records: records.map((record) => {
|
4463
4503
|
const { table = "orphan" } = record.xata;
|
4464
|
-
return { table, record: initObject(this.db,
|
4504
|
+
return { table, record: initObject(this.db, pluginOptions.tables, table, record, ["*"]) };
|
4465
4505
|
})
|
4466
4506
|
};
|
4467
4507
|
},
|
4468
4508
|
byTable: async (query, options = {}) => {
|
4469
4509
|
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4470
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4471
4510
|
const records = rawRecords.reduce((acc, record) => {
|
4472
4511
|
const { table = "orphan" } = record.xata;
|
4473
4512
|
const items = acc[table] ?? [];
|
4474
|
-
const item = initObject(this.db,
|
4513
|
+
const item = initObject(this.db, pluginOptions.tables, table, record, ["*"]);
|
4475
4514
|
return { ...acc, [table]: [...items, item] };
|
4476
4515
|
}, {});
|
4477
4516
|
return { totalCount, records };
|
@@ -4479,29 +4518,17 @@ class SearchPlugin extends XataPlugin {
|
|
4479
4518
|
};
|
4480
4519
|
}
|
4481
4520
|
}
|
4482
|
-
_schemaTables = new WeakMap();
|
4483
4521
|
_search = new WeakSet();
|
4484
4522
|
search_fn = async function(query, options, pluginOptions) {
|
4485
4523
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4486
4524
|
const { records, totalCount } = await searchBranch({
|
4487
4525
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4488
|
-
// @ts-
|
4526
|
+
// @ts-expect-error Filter properties do not match inferred type
|
4489
4527
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
4490
4528
|
...pluginOptions
|
4491
4529
|
});
|
4492
4530
|
return { records, totalCount };
|
4493
4531
|
};
|
4494
|
-
_getSchemaTables = new WeakSet();
|
4495
|
-
getSchemaTables_fn = async function(pluginOptions) {
|
4496
|
-
if (__privateGet$1(this, _schemaTables))
|
4497
|
-
return __privateGet$1(this, _schemaTables);
|
4498
|
-
const { schema } = await getBranchDetails({
|
4499
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4500
|
-
...pluginOptions
|
4501
|
-
});
|
4502
|
-
__privateSet$1(this, _schemaTables, schema.tables);
|
4503
|
-
return schema.tables;
|
4504
|
-
};
|
4505
4532
|
|
4506
4533
|
function escapeElement(elementRepresentation) {
|
4507
4534
|
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
@@ -4563,17 +4590,26 @@ function prepareParams(param1, param2) {
|
|
4563
4590
|
|
4564
4591
|
class SQLPlugin extends XataPlugin {
|
4565
4592
|
build(pluginOptions) {
|
4566
|
-
return async (
|
4567
|
-
|
4568
|
-
|
4593
|
+
return async (query, ...parameters) => {
|
4594
|
+
if (!isParamsObject(query) && (!isTemplateStringsArray(query) || !Array.isArray(parameters))) {
|
4595
|
+
throw new Error("Invalid usage of `xata.sql`. Please use it as a tagged template or with an object.");
|
4596
|
+
}
|
4597
|
+
const { statement, params, consistency } = prepareParams(query, parameters);
|
4598
|
+
const { records, warning, columns } = await sqlQuery({
|
4569
4599
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4570
4600
|
body: { statement, params, consistency },
|
4571
4601
|
...pluginOptions
|
4572
4602
|
});
|
4573
|
-
return { records, warning };
|
4603
|
+
return { records, warning, columns };
|
4574
4604
|
};
|
4575
4605
|
}
|
4576
4606
|
}
|
4607
|
+
function isTemplateStringsArray(strings) {
|
4608
|
+
return Array.isArray(strings) && "raw" in strings && Array.isArray(strings.raw);
|
4609
|
+
}
|
4610
|
+
function isParamsObject(params) {
|
4611
|
+
return isObject(params) && "statement" in params;
|
4612
|
+
}
|
4577
4613
|
|
4578
4614
|
class TransactionPlugin extends XataPlugin {
|
4579
4615
|
build(pluginOptions) {
|
@@ -4615,7 +4651,7 @@ var __privateMethod = (obj, member, method) => {
|
|
4615
4651
|
const buildClient = (plugins) => {
|
4616
4652
|
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
4617
4653
|
return _a = class {
|
4618
|
-
constructor(options = {},
|
4654
|
+
constructor(options = {}, tables) {
|
4619
4655
|
__privateAdd(this, _parseOptions);
|
4620
4656
|
__privateAdd(this, _getFetchProps);
|
4621
4657
|
__privateAdd(this, _options, void 0);
|
@@ -4624,13 +4660,15 @@ const buildClient = (plugins) => {
|
|
4624
4660
|
const pluginOptions = {
|
4625
4661
|
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
4626
4662
|
cache: safeOptions.cache,
|
4627
|
-
host: safeOptions.host
|
4663
|
+
host: safeOptions.host,
|
4664
|
+
tables
|
4628
4665
|
};
|
4629
|
-
const db = new SchemaPlugin(
|
4630
|
-
const search = new SearchPlugin(db
|
4666
|
+
const db = new SchemaPlugin().build(pluginOptions);
|
4667
|
+
const search = new SearchPlugin(db).build(pluginOptions);
|
4631
4668
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4632
4669
|
const sql = new SQLPlugin().build(pluginOptions);
|
4633
4670
|
const files = new FilesPlugin().build(pluginOptions);
|
4671
|
+
this.schema = { tables };
|
4634
4672
|
this.db = db;
|
4635
4673
|
this.search = search;
|
4636
4674
|
this.transactions = transactions;
|
@@ -4806,5 +4844,5 @@ class XataError extends Error {
|
|
4806
4844
|
}
|
4807
4845
|
}
|
4808
4846
|
|
4809
|
-
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, pgRollMigrationHistory, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
4847
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, PageRecordArray, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, pgRollMigrationHistory, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
4810
4848
|
//# sourceMappingURL=index.mjs.map
|