@xata.io/client 0.24.2 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +9 -4
- package/CHANGELOG.md +24 -0
- package/dist/index.cjs +513 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +581 -100
- package/dist/index.mjs +509 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -27,8 +27,11 @@ function notEmpty(value) {
|
|
27
27
|
function compact(arr) {
|
28
28
|
return arr.filter(notEmpty);
|
29
29
|
}
|
30
|
+
function compactObject(obj) {
|
31
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
32
|
+
}
|
30
33
|
function isObject(value) {
|
31
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
34
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
32
35
|
}
|
33
36
|
function isDefined(value) {
|
34
37
|
return value !== null && value !== void 0;
|
@@ -83,6 +86,15 @@ function chunk(array, chunkSize) {
|
|
83
86
|
async function timeout(ms) {
|
84
87
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
85
88
|
}
|
89
|
+
function promiseMap(inputValues, mapper) {
|
90
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
91
|
+
(acc) => mapper(inputValue).then((result) => {
|
92
|
+
acc.push(result);
|
93
|
+
return acc;
|
94
|
+
})
|
95
|
+
);
|
96
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
97
|
+
}
|
86
98
|
|
87
99
|
function getEnvironment() {
|
88
100
|
try {
|
@@ -210,6 +222,12 @@ function getPreviewBranch() {
|
|
210
222
|
}
|
211
223
|
}
|
212
224
|
|
225
|
+
var __defProp$8 = Object.defineProperty;
|
226
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
227
|
+
var __publicField$8 = (obj, key, value) => {
|
228
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
229
|
+
return value;
|
230
|
+
};
|
213
231
|
var __accessCheck$8 = (obj, member, msg) => {
|
214
232
|
if (!member.has(obj))
|
215
233
|
throw TypeError("Cannot " + msg);
|
@@ -233,6 +251,7 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
233
251
|
return method;
|
234
252
|
};
|
235
253
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
254
|
+
const REQUEST_TIMEOUT = 3e4;
|
236
255
|
function getFetchImplementation(userFetch) {
|
237
256
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
238
257
|
const fetchImpl = userFetch ?? globalFetch;
|
@@ -249,6 +268,8 @@ class ApiRequestPool {
|
|
249
268
|
__privateAdd$8(this, _fetch, void 0);
|
250
269
|
__privateAdd$8(this, _queue, void 0);
|
251
270
|
__privateAdd$8(this, _concurrency, void 0);
|
271
|
+
__publicField$8(this, "running");
|
272
|
+
__publicField$8(this, "started");
|
252
273
|
__privateSet$8(this, _queue, []);
|
253
274
|
__privateSet$8(this, _concurrency, concurrency);
|
254
275
|
this.running = 0;
|
@@ -265,9 +286,12 @@ class ApiRequestPool {
|
|
265
286
|
}
|
266
287
|
request(url, options) {
|
267
288
|
const start = /* @__PURE__ */ new Date();
|
268
|
-
const
|
289
|
+
const fetchImpl = this.getFetch();
|
269
290
|
const runRequest = async (stalled = false) => {
|
270
|
-
const response = await
|
291
|
+
const response = await Promise.race([fetchImpl(url, options), timeout(REQUEST_TIMEOUT).then(() => null)]);
|
292
|
+
if (!response) {
|
293
|
+
throw new Error("Request timed out");
|
294
|
+
}
|
271
295
|
if (response.status === 429) {
|
272
296
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
273
297
|
await timeout(rateLimitReset * 1e3);
|
@@ -490,16 +514,26 @@ function defaultOnOpen(response) {
|
|
490
514
|
}
|
491
515
|
}
|
492
516
|
|
493
|
-
const VERSION = "0.
|
517
|
+
const VERSION = "0.25.0";
|
494
518
|
|
519
|
+
var __defProp$7 = Object.defineProperty;
|
520
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
521
|
+
var __publicField$7 = (obj, key, value) => {
|
522
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
523
|
+
return value;
|
524
|
+
};
|
495
525
|
class ErrorWithCause extends Error {
|
496
526
|
constructor(message, options) {
|
497
527
|
super(message, options);
|
528
|
+
__publicField$7(this, "cause");
|
498
529
|
}
|
499
530
|
}
|
500
531
|
class FetcherError extends ErrorWithCause {
|
501
532
|
constructor(status, data, requestId) {
|
502
533
|
super(getMessage(data));
|
534
|
+
__publicField$7(this, "status");
|
535
|
+
__publicField$7(this, "requestId");
|
536
|
+
__publicField$7(this, "errors");
|
503
537
|
this.status = status;
|
504
538
|
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
505
539
|
this.requestId = requestId;
|
@@ -566,6 +600,15 @@ function hostHeader(url) {
|
|
566
600
|
const { groups } = pattern.exec(url) ?? {};
|
567
601
|
return groups?.host ? { Host: groups.host } : {};
|
568
602
|
}
|
603
|
+
function parseBody(body, headers) {
|
604
|
+
if (!isDefined(body))
|
605
|
+
return void 0;
|
606
|
+
const { "Content-Type": contentType } = headers ?? {};
|
607
|
+
if (String(contentType).toLowerCase() === "application/json") {
|
608
|
+
return JSON.stringify(body);
|
609
|
+
}
|
610
|
+
return body;
|
611
|
+
}
|
569
612
|
const defaultClientID = generateUUID();
|
570
613
|
async function fetch$1({
|
571
614
|
url: path,
|
@@ -585,7 +628,8 @@ async function fetch$1({
|
|
585
628
|
sessionID,
|
586
629
|
clientName,
|
587
630
|
xataAgentExtra,
|
588
|
-
fetchOptions = {}
|
631
|
+
fetchOptions = {},
|
632
|
+
rawResponse = false
|
589
633
|
}) {
|
590
634
|
pool.setFetch(fetch2);
|
591
635
|
return await trace(
|
@@ -604,7 +648,7 @@ async function fetch$1({
|
|
604
648
|
isDefined(clientName) ? ["service", clientName] : void 0,
|
605
649
|
...Object.entries(xataAgentExtra ?? {})
|
606
650
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
607
|
-
const headers = {
|
651
|
+
const headers = compactObject({
|
608
652
|
"Accept-Encoding": "identity",
|
609
653
|
"Content-Type": "application/json",
|
610
654
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
@@ -613,11 +657,11 @@ async function fetch$1({
|
|
613
657
|
...customHeaders,
|
614
658
|
...hostHeader(fullUrl),
|
615
659
|
Authorization: `Bearer ${apiKey}`
|
616
|
-
};
|
660
|
+
});
|
617
661
|
const response = await pool.request(url, {
|
618
662
|
...fetchOptions,
|
619
663
|
method: method.toUpperCase(),
|
620
|
-
body: body
|
664
|
+
body: parseBody(body, headers),
|
621
665
|
headers,
|
622
666
|
signal
|
623
667
|
});
|
@@ -630,6 +674,9 @@ async function fetch$1({
|
|
630
674
|
[TraceAttributes.HTTP_HOST]: host,
|
631
675
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
632
676
|
});
|
677
|
+
const message = response.headers?.get("x-xata-message");
|
678
|
+
if (message)
|
679
|
+
console.warn(message);
|
633
680
|
if (response.status === 204) {
|
634
681
|
return {};
|
635
682
|
}
|
@@ -637,7 +684,7 @@ async function fetch$1({
|
|
637
684
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
638
685
|
}
|
639
686
|
try {
|
640
|
-
const jsonResponse = await response.json();
|
687
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
641
688
|
if (response.ok) {
|
642
689
|
return jsonResponse;
|
643
690
|
}
|
@@ -910,6 +957,7 @@ const askTable = (variables, signal) => dataPlaneFetch({
|
|
910
957
|
...variables,
|
911
958
|
signal
|
912
959
|
});
|
960
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
913
961
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
914
962
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
915
963
|
const fileAccess = (variables, signal) => dataPlaneFetch({
|
@@ -985,6 +1033,7 @@ const operationsByTag$2 = {
|
|
985
1033
|
sqlQuery,
|
986
1034
|
vectorSearchTable,
|
987
1035
|
askTable,
|
1036
|
+
askTableSession,
|
988
1037
|
summarizeTable,
|
989
1038
|
aggregateTable
|
990
1039
|
}
|
@@ -992,6 +1041,13 @@ const operationsByTag$2 = {
|
|
992
1041
|
|
993
1042
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
994
1043
|
|
1044
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
1045
|
+
const generateAccessToken = (variables, signal) => controlPlaneFetch({
|
1046
|
+
url: "/oauth/token",
|
1047
|
+
method: "post",
|
1048
|
+
...variables,
|
1049
|
+
signal
|
1050
|
+
});
|
995
1051
|
const getUser = (variables, signal) => controlPlaneFetch({
|
996
1052
|
url: "/user",
|
997
1053
|
method: "get",
|
@@ -1097,6 +1153,7 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
1097
1153
|
signal
|
1098
1154
|
});
|
1099
1155
|
const operationsByTag$1 = {
|
1156
|
+
authOther: { grantAuthorizationCode, generateAccessToken },
|
1100
1157
|
users: { getUser, updateUser, deleteUser },
|
1101
1158
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1102
1159
|
workspaces: {
|
@@ -2109,6 +2166,21 @@ class SearchAndFilterApi {
|
|
2109
2166
|
...this.extraProps
|
2110
2167
|
});
|
2111
2168
|
}
|
2169
|
+
askTableSession({
|
2170
|
+
workspace,
|
2171
|
+
region,
|
2172
|
+
database,
|
2173
|
+
branch,
|
2174
|
+
table,
|
2175
|
+
sessionId,
|
2176
|
+
message
|
2177
|
+
}) {
|
2178
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2179
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2180
|
+
body: { message },
|
2181
|
+
...this.extraProps
|
2182
|
+
});
|
2183
|
+
}
|
2112
2184
|
summarizeTable({
|
2113
2185
|
workspace,
|
2114
2186
|
region,
|
@@ -2400,11 +2472,13 @@ class DatabaseApi {
|
|
2400
2472
|
createDatabase({
|
2401
2473
|
workspace,
|
2402
2474
|
database,
|
2403
|
-
data
|
2475
|
+
data,
|
2476
|
+
headers
|
2404
2477
|
}) {
|
2405
2478
|
return operationsByTag.databases.createDatabase({
|
2406
2479
|
pathParams: { workspaceId: workspace, dbName: database },
|
2407
2480
|
body: data,
|
2481
|
+
headers,
|
2408
2482
|
...this.extraProps
|
2409
2483
|
});
|
2410
2484
|
}
|
@@ -2494,13 +2568,261 @@ class XataApiPlugin {
|
|
2494
2568
|
class XataPlugin {
|
2495
2569
|
}
|
2496
2570
|
|
2571
|
+
class FilesPlugin extends XataPlugin {
|
2572
|
+
build(pluginOptions) {
|
2573
|
+
return {
|
2574
|
+
download: async (location) => {
|
2575
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2576
|
+
return await getFileItem({
|
2577
|
+
pathParams: {
|
2578
|
+
workspace: "{workspaceId}",
|
2579
|
+
dbBranchName: "{dbBranch}",
|
2580
|
+
region: "{region}",
|
2581
|
+
tableName: table ?? "",
|
2582
|
+
recordId: record ?? "",
|
2583
|
+
columnName: column ?? "",
|
2584
|
+
fileId
|
2585
|
+
},
|
2586
|
+
...pluginOptions,
|
2587
|
+
rawResponse: true
|
2588
|
+
});
|
2589
|
+
},
|
2590
|
+
upload: async (location, file) => {
|
2591
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2592
|
+
return await putFileItem({
|
2593
|
+
pathParams: {
|
2594
|
+
workspace: "{workspaceId}",
|
2595
|
+
dbBranchName: "{dbBranch}",
|
2596
|
+
region: "{region}",
|
2597
|
+
tableName: table ?? "",
|
2598
|
+
recordId: record ?? "",
|
2599
|
+
columnName: column ?? "",
|
2600
|
+
fileId
|
2601
|
+
},
|
2602
|
+
body: file,
|
2603
|
+
...pluginOptions
|
2604
|
+
});
|
2605
|
+
},
|
2606
|
+
delete: async (location) => {
|
2607
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2608
|
+
return await deleteFileItem({
|
2609
|
+
pathParams: {
|
2610
|
+
workspace: "{workspaceId}",
|
2611
|
+
dbBranchName: "{dbBranch}",
|
2612
|
+
region: "{region}",
|
2613
|
+
tableName: table ?? "",
|
2614
|
+
recordId: record ?? "",
|
2615
|
+
columnName: column ?? "",
|
2616
|
+
fileId
|
2617
|
+
},
|
2618
|
+
...pluginOptions
|
2619
|
+
});
|
2620
|
+
}
|
2621
|
+
};
|
2622
|
+
}
|
2623
|
+
}
|
2624
|
+
|
2625
|
+
function buildTransformString(transformations) {
|
2626
|
+
return transformations.flatMap(
|
2627
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2628
|
+
if (key === "trim") {
|
2629
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2630
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2631
|
+
}
|
2632
|
+
if (key === "gravity" && typeof value === "object") {
|
2633
|
+
const { x = 0.5, y = 0.5 } = value;
|
2634
|
+
return `${key}=${[x, y].join("x")}`;
|
2635
|
+
}
|
2636
|
+
return `${key}=${value}`;
|
2637
|
+
})
|
2638
|
+
).join(",");
|
2639
|
+
}
|
2640
|
+
function transformImage(url, transformations) {
|
2641
|
+
if (!isDefined(url))
|
2642
|
+
return void 0;
|
2643
|
+
const transformationsString = buildTransformString(transformations);
|
2644
|
+
const { hostname, pathname, search } = new URL(url);
|
2645
|
+
return `https://${hostname}/transform/${transformationsString}${pathname}${search}`;
|
2646
|
+
}
|
2647
|
+
|
2648
|
+
var __defProp$6 = Object.defineProperty;
|
2649
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2650
|
+
var __publicField$6 = (obj, key, value) => {
|
2651
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2652
|
+
return value;
|
2653
|
+
};
|
2654
|
+
class XataFile {
|
2655
|
+
constructor(file) {
|
2656
|
+
/**
|
2657
|
+
* Name of this file.
|
2658
|
+
*/
|
2659
|
+
__publicField$6(this, "name");
|
2660
|
+
/**
|
2661
|
+
* Media type of this file.
|
2662
|
+
*/
|
2663
|
+
__publicField$6(this, "mediaType");
|
2664
|
+
/**
|
2665
|
+
* Base64 encoded content of this file.
|
2666
|
+
*/
|
2667
|
+
__publicField$6(this, "base64Content");
|
2668
|
+
/**
|
2669
|
+
* Whether to enable public url for this file.
|
2670
|
+
*/
|
2671
|
+
__publicField$6(this, "enablePublicUrl");
|
2672
|
+
/**
|
2673
|
+
* Timeout for the signed url.
|
2674
|
+
*/
|
2675
|
+
__publicField$6(this, "signedUrlTimeout");
|
2676
|
+
/**
|
2677
|
+
* Size of this file.
|
2678
|
+
*/
|
2679
|
+
__publicField$6(this, "size");
|
2680
|
+
/**
|
2681
|
+
* Version of this file.
|
2682
|
+
*/
|
2683
|
+
__publicField$6(this, "version");
|
2684
|
+
/**
|
2685
|
+
* Url of this file.
|
2686
|
+
*/
|
2687
|
+
__publicField$6(this, "url");
|
2688
|
+
/**
|
2689
|
+
* Signed url of this file.
|
2690
|
+
*/
|
2691
|
+
__publicField$6(this, "signedUrl");
|
2692
|
+
/**
|
2693
|
+
* Attributes of this file.
|
2694
|
+
*/
|
2695
|
+
__publicField$6(this, "attributes");
|
2696
|
+
this.name = file.name;
|
2697
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2698
|
+
this.base64Content = file.base64Content;
|
2699
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2700
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2701
|
+
this.size = file.size;
|
2702
|
+
this.version = file.version;
|
2703
|
+
this.url = file.url;
|
2704
|
+
this.signedUrl = file.signedUrl;
|
2705
|
+
this.attributes = file.attributes;
|
2706
|
+
}
|
2707
|
+
static fromBuffer(buffer, options = {}) {
|
2708
|
+
const base64Content = buffer.toString("base64");
|
2709
|
+
return new XataFile({ ...options, base64Content });
|
2710
|
+
}
|
2711
|
+
toBuffer() {
|
2712
|
+
if (!this.base64Content) {
|
2713
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2714
|
+
}
|
2715
|
+
return Buffer.from(this.base64Content, "base64");
|
2716
|
+
}
|
2717
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2718
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2719
|
+
return this.fromUint8Array(uint8Array, options);
|
2720
|
+
}
|
2721
|
+
toArrayBuffer() {
|
2722
|
+
if (!this.base64Content) {
|
2723
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2724
|
+
}
|
2725
|
+
const binary = atob(this.base64Content);
|
2726
|
+
return new ArrayBuffer(binary.length);
|
2727
|
+
}
|
2728
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2729
|
+
let binary = "";
|
2730
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2731
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2732
|
+
}
|
2733
|
+
const base64Content = btoa(binary);
|
2734
|
+
return new XataFile({ ...options, base64Content });
|
2735
|
+
}
|
2736
|
+
toUint8Array() {
|
2737
|
+
if (!this.base64Content) {
|
2738
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2739
|
+
}
|
2740
|
+
const binary = atob(this.base64Content);
|
2741
|
+
const uint8Array = new Uint8Array(binary.length);
|
2742
|
+
for (let i = 0; i < binary.length; i++) {
|
2743
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2744
|
+
}
|
2745
|
+
return uint8Array;
|
2746
|
+
}
|
2747
|
+
static async fromBlob(file, options = {}) {
|
2748
|
+
const name = options.name ?? file.name;
|
2749
|
+
const mediaType = file.type;
|
2750
|
+
const arrayBuffer = await file.arrayBuffer();
|
2751
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2752
|
+
}
|
2753
|
+
toBlob() {
|
2754
|
+
if (!this.base64Content) {
|
2755
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2756
|
+
}
|
2757
|
+
const arrayBuffer = this.toArrayBuffer();
|
2758
|
+
return new Blob([arrayBuffer], { type: this.mediaType });
|
2759
|
+
}
|
2760
|
+
static fromString(string, options = {}) {
|
2761
|
+
const base64Content = btoa(string);
|
2762
|
+
return new XataFile({ ...options, base64Content });
|
2763
|
+
}
|
2764
|
+
toString() {
|
2765
|
+
if (!this.base64Content) {
|
2766
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2767
|
+
}
|
2768
|
+
return atob(this.base64Content);
|
2769
|
+
}
|
2770
|
+
static fromBase64(base64Content, options = {}) {
|
2771
|
+
return new XataFile({ ...options, base64Content });
|
2772
|
+
}
|
2773
|
+
toBase64() {
|
2774
|
+
if (!this.base64Content) {
|
2775
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2776
|
+
}
|
2777
|
+
return this.base64Content;
|
2778
|
+
}
|
2779
|
+
transform(...options) {
|
2780
|
+
return {
|
2781
|
+
url: transformImage(this.url, options),
|
2782
|
+
signedUrl: transformImage(this.signedUrl, options)
|
2783
|
+
};
|
2784
|
+
}
|
2785
|
+
}
|
2786
|
+
const parseInputFileEntry = async (entry) => {
|
2787
|
+
if (!isDefined(entry))
|
2788
|
+
return null;
|
2789
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2790
|
+
return compactObject({ id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout });
|
2791
|
+
};
|
2792
|
+
|
2497
2793
|
function cleanFilter(filter) {
|
2498
|
-
if (!filter)
|
2794
|
+
if (!isDefined(filter))
|
2499
2795
|
return void 0;
|
2500
|
-
|
2501
|
-
|
2796
|
+
if (!isObject(filter))
|
2797
|
+
return filter;
|
2798
|
+
const values = Object.fromEntries(
|
2799
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2800
|
+
if (!isDefined(value))
|
2801
|
+
return acc;
|
2802
|
+
if (Array.isArray(value)) {
|
2803
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2804
|
+
if (clean.length === 0)
|
2805
|
+
return acc;
|
2806
|
+
return [...acc, [key, clean]];
|
2807
|
+
}
|
2808
|
+
if (isObject(value)) {
|
2809
|
+
const clean = cleanFilter(value);
|
2810
|
+
if (!isDefined(clean))
|
2811
|
+
return acc;
|
2812
|
+
return [...acc, [key, clean]];
|
2813
|
+
}
|
2814
|
+
return [...acc, [key, value]];
|
2815
|
+
}, [])
|
2816
|
+
);
|
2817
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
2502
2818
|
}
|
2503
2819
|
|
2820
|
+
var __defProp$5 = Object.defineProperty;
|
2821
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2822
|
+
var __publicField$5 = (obj, key, value) => {
|
2823
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2824
|
+
return value;
|
2825
|
+
};
|
2504
2826
|
var __accessCheck$6 = (obj, member, msg) => {
|
2505
2827
|
if (!member.has(obj))
|
2506
2828
|
throw TypeError("Cannot " + msg);
|
@@ -2523,6 +2845,14 @@ var _query, _page;
|
|
2523
2845
|
class Page {
|
2524
2846
|
constructor(query, meta, records = []) {
|
2525
2847
|
__privateAdd$6(this, _query, void 0);
|
2848
|
+
/**
|
2849
|
+
* Page metadata, required to retrieve additional records.
|
2850
|
+
*/
|
2851
|
+
__publicField$5(this, "meta");
|
2852
|
+
/**
|
2853
|
+
* The set of results for this page.
|
2854
|
+
*/
|
2855
|
+
__publicField$5(this, "records");
|
2526
2856
|
__privateSet$6(this, _query, query);
|
2527
2857
|
this.meta = meta;
|
2528
2858
|
this.records = new RecordArray(this, records);
|
@@ -2579,7 +2909,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
2579
2909
|
function isCursorPaginationOptions(options) {
|
2580
2910
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
2581
2911
|
}
|
2582
|
-
const _RecordArray = class extends Array {
|
2912
|
+
const _RecordArray = class _RecordArray extends Array {
|
2583
2913
|
constructor(...args) {
|
2584
2914
|
super(..._RecordArray.parseConstructorParams(...args));
|
2585
2915
|
__privateAdd$6(this, _page, void 0);
|
@@ -2650,9 +2980,15 @@ const _RecordArray = class extends Array {
|
|
2650
2980
|
return __privateGet$6(this, _page).meta.page.more;
|
2651
2981
|
}
|
2652
2982
|
};
|
2653
|
-
let RecordArray = _RecordArray;
|
2654
2983
|
_page = new WeakMap();
|
2984
|
+
let RecordArray = _RecordArray;
|
2655
2985
|
|
2986
|
+
var __defProp$4 = Object.defineProperty;
|
2987
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2988
|
+
var __publicField$4 = (obj, key, value) => {
|
2989
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2990
|
+
return value;
|
2991
|
+
};
|
2656
2992
|
var __accessCheck$5 = (obj, member, msg) => {
|
2657
2993
|
if (!member.has(obj))
|
2658
2994
|
throw TypeError("Cannot " + msg);
|
@@ -2676,15 +3012,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2676
3012
|
return method;
|
2677
3013
|
};
|
2678
3014
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2679
|
-
const _Query = class {
|
3015
|
+
const _Query = class _Query {
|
2680
3016
|
constructor(repository, table, data, rawParent) {
|
2681
3017
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2682
3018
|
__privateAdd$5(this, _table$1, void 0);
|
2683
3019
|
__privateAdd$5(this, _repository, void 0);
|
2684
3020
|
__privateAdd$5(this, _data, { filter: {} });
|
2685
3021
|
// Implements pagination
|
2686
|
-
this
|
2687
|
-
this
|
3022
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
3023
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
2688
3024
|
__privateSet$5(this, _table$1, table);
|
2689
3025
|
if (repository) {
|
2690
3026
|
__privateSet$5(this, _repository, repository);
|
@@ -2904,7 +3240,6 @@ const _Query = class {
|
|
2904
3240
|
return this.meta.page.more;
|
2905
3241
|
}
|
2906
3242
|
};
|
2907
|
-
let Query = _Query;
|
2908
3243
|
_table$1 = new WeakMap();
|
2909
3244
|
_repository = new WeakMap();
|
2910
3245
|
_data = new WeakMap();
|
@@ -2919,6 +3254,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2919
3254
|
}
|
2920
3255
|
return value;
|
2921
3256
|
};
|
3257
|
+
let Query = _Query;
|
2922
3258
|
function cleanParent(data, parent) {
|
2923
3259
|
if (isCursorPaginationOptions(data.pagination)) {
|
2924
3260
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2926,6 +3262,21 @@ function cleanParent(data, parent) {
|
|
2926
3262
|
return parent;
|
2927
3263
|
}
|
2928
3264
|
|
3265
|
+
const RecordColumnTypes = [
|
3266
|
+
"bool",
|
3267
|
+
"int",
|
3268
|
+
"float",
|
3269
|
+
"string",
|
3270
|
+
"text",
|
3271
|
+
"email",
|
3272
|
+
"multiple",
|
3273
|
+
"link",
|
3274
|
+
"object",
|
3275
|
+
"datetime",
|
3276
|
+
"vector",
|
3277
|
+
"file[]",
|
3278
|
+
"file"
|
3279
|
+
];
|
2929
3280
|
function isIdentifiable(x) {
|
2930
3281
|
return isObject(x) && isString(x?.id);
|
2931
3282
|
}
|
@@ -2984,7 +3335,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2984
3335
|
__accessCheck$4(obj, member, "access private method");
|
2985
3336
|
return method;
|
2986
3337
|
};
|
2987
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _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$1, getSchemaTables_fn$1;
|
3338
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _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$1, getSchemaTables_fn$1, _transformObjectToApi, transformObjectToApi_fn;
|
2988
3339
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2989
3340
|
class Repository extends Query {
|
2990
3341
|
}
|
@@ -3006,6 +3357,7 @@ class RestRepository extends Query {
|
|
3006
3357
|
__privateAdd$4(this, _setCacheQuery);
|
3007
3358
|
__privateAdd$4(this, _getCacheQuery);
|
3008
3359
|
__privateAdd$4(this, _getSchemaTables$1);
|
3360
|
+
__privateAdd$4(this, _transformObjectToApi);
|
3009
3361
|
__privateAdd$4(this, _table, void 0);
|
3010
3362
|
__privateAdd$4(this, _getFetchProps, void 0);
|
3011
3363
|
__privateAdd$4(this, _db, void 0);
|
@@ -3183,12 +3535,22 @@ class RestRepository extends Query {
|
|
3183
3535
|
return result;
|
3184
3536
|
}
|
3185
3537
|
if (isString(a) && isObject(b)) {
|
3538
|
+
if (a === "")
|
3539
|
+
throw new Error("The id can't be empty");
|
3186
3540
|
const columns = isStringArray(c) ? c : void 0;
|
3187
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3541
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3188
3542
|
}
|
3189
3543
|
if (isObject(a) && isString(a.id)) {
|
3544
|
+
if (a.id === "")
|
3545
|
+
throw new Error("The id can't be empty");
|
3190
3546
|
const columns = isStringArray(c) ? c : void 0;
|
3191
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3547
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3548
|
+
}
|
3549
|
+
if (!isDefined(a) && isObject(b)) {
|
3550
|
+
return await this.create(b, c);
|
3551
|
+
}
|
3552
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3553
|
+
return await this.create(a, b);
|
3192
3554
|
}
|
3193
3555
|
throw new Error("Invalid arguments for createOrUpdate method");
|
3194
3556
|
});
|
@@ -3205,12 +3567,22 @@ class RestRepository extends Query {
|
|
3205
3567
|
return result;
|
3206
3568
|
}
|
3207
3569
|
if (isString(a) && isObject(b)) {
|
3570
|
+
if (a === "")
|
3571
|
+
throw new Error("The id can't be empty");
|
3208
3572
|
const columns = isStringArray(c) ? c : void 0;
|
3209
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3573
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3210
3574
|
}
|
3211
3575
|
if (isObject(a) && isString(a.id)) {
|
3576
|
+
if (a.id === "")
|
3577
|
+
throw new Error("The id can't be empty");
|
3212
3578
|
const columns = isStringArray(c) ? c : void 0;
|
3213
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3579
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3580
|
+
}
|
3581
|
+
if (!isDefined(a) && isObject(b)) {
|
3582
|
+
return await this.create(b, c);
|
3583
|
+
}
|
3584
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3585
|
+
return await this.create(a, b);
|
3214
3586
|
}
|
3215
3587
|
throw new Error("Invalid arguments for createOrReplace method");
|
3216
3588
|
});
|
@@ -3377,23 +3749,28 @@ class RestRepository extends Query {
|
|
3377
3749
|
});
|
3378
3750
|
}
|
3379
3751
|
ask(question, options) {
|
3752
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3380
3753
|
const params = {
|
3381
3754
|
pathParams: {
|
3382
3755
|
workspace: "{workspaceId}",
|
3383
3756
|
dbBranchName: "{dbBranch}",
|
3384
3757
|
region: "{region}",
|
3385
|
-
tableName: __privateGet$4(this, _table)
|
3758
|
+
tableName: __privateGet$4(this, _table),
|
3759
|
+
sessionId: options?.sessionId
|
3386
3760
|
},
|
3387
3761
|
body: {
|
3388
|
-
|
3389
|
-
|
3762
|
+
...questionParam,
|
3763
|
+
rules: options?.rules,
|
3764
|
+
searchType: options?.searchType,
|
3765
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3766
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3390
3767
|
},
|
3391
3768
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3392
3769
|
};
|
3393
3770
|
if (options?.onMessage) {
|
3394
3771
|
fetchSSERequest({
|
3395
3772
|
endpoint: "dataPlane",
|
3396
|
-
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3773
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3397
3774
|
method: "POST",
|
3398
3775
|
onMessage: (message) => {
|
3399
3776
|
options.onMessage?.({ answer: message.text, records: message.records });
|
@@ -3401,7 +3778,7 @@ class RestRepository extends Query {
|
|
3401
3778
|
...params
|
3402
3779
|
});
|
3403
3780
|
} else {
|
3404
|
-
return
|
3781
|
+
return askTableSession(params);
|
3405
3782
|
}
|
3406
3783
|
}
|
3407
3784
|
}
|
@@ -3413,7 +3790,7 @@ _schemaTables$2 = new WeakMap();
|
|
3413
3790
|
_trace = new WeakMap();
|
3414
3791
|
_insertRecordWithoutId = new WeakSet();
|
3415
3792
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
3416
|
-
const record =
|
3793
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3417
3794
|
const response = await insertRecord({
|
3418
3795
|
pathParams: {
|
3419
3796
|
workspace: "{workspaceId}",
|
@@ -3430,7 +3807,9 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
3430
3807
|
};
|
3431
3808
|
_insertRecordWithId = new WeakSet();
|
3432
3809
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
3433
|
-
|
3810
|
+
if (!recordId)
|
3811
|
+
return null;
|
3812
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3434
3813
|
const response = await insertRecordWithID({
|
3435
3814
|
pathParams: {
|
3436
3815
|
workspace: "{workspaceId}",
|
@@ -3448,21 +3827,20 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
3448
3827
|
};
|
3449
3828
|
_insertRecords = new WeakSet();
|
3450
3829
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3451
|
-
const
|
3452
|
-
|
3453
|
-
|
3454
|
-
|
3455
|
-
|
3456
|
-
);
|
3830
|
+
const operations = await promiseMap(objects, async (object) => {
|
3831
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3832
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3833
|
+
});
|
3834
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3457
3835
|
const ids = [];
|
3458
|
-
for (const
|
3836
|
+
for (const operations2 of chunkedOperations) {
|
3459
3837
|
const { results } = await branchTransaction({
|
3460
3838
|
pathParams: {
|
3461
3839
|
workspace: "{workspaceId}",
|
3462
3840
|
dbBranchName: "{dbBranch}",
|
3463
3841
|
region: "{region}"
|
3464
3842
|
},
|
3465
|
-
body: { operations },
|
3843
|
+
body: { operations: operations2 },
|
3466
3844
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3467
3845
|
});
|
3468
3846
|
for (const result of results) {
|
@@ -3477,7 +3855,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
3477
3855
|
};
|
3478
3856
|
_updateRecordWithID = new WeakSet();
|
3479
3857
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
3480
|
-
|
3858
|
+
if (!recordId)
|
3859
|
+
return null;
|
3860
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3481
3861
|
try {
|
3482
3862
|
const response = await updateRecordWithID({
|
3483
3863
|
pathParams: {
|
@@ -3502,21 +3882,20 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3502
3882
|
};
|
3503
3883
|
_updateRecords = new WeakSet();
|
3504
3884
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3505
|
-
const
|
3506
|
-
|
3507
|
-
|
3508
|
-
|
3509
|
-
|
3510
|
-
);
|
3885
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3886
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3887
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3888
|
+
});
|
3889
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3511
3890
|
const ids = [];
|
3512
|
-
for (const
|
3891
|
+
for (const operations2 of chunkedOperations) {
|
3513
3892
|
const { results } = await branchTransaction({
|
3514
3893
|
pathParams: {
|
3515
3894
|
workspace: "{workspaceId}",
|
3516
3895
|
dbBranchName: "{dbBranch}",
|
3517
3896
|
region: "{region}"
|
3518
3897
|
},
|
3519
|
-
body: { operations },
|
3898
|
+
body: { operations: operations2 },
|
3520
3899
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3521
3900
|
});
|
3522
3901
|
for (const result of results) {
|
@@ -3531,6 +3910,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
3531
3910
|
};
|
3532
3911
|
_upsertRecordWithID = new WeakSet();
|
3533
3912
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
3913
|
+
if (!recordId)
|
3914
|
+
return null;
|
3534
3915
|
const response = await upsertRecordWithID({
|
3535
3916
|
pathParams: {
|
3536
3917
|
workspace: "{workspaceId}",
|
@@ -3548,6 +3929,8 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
3548
3929
|
};
|
3549
3930
|
_deleteRecord = new WeakSet();
|
3550
3931
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
3932
|
+
if (!recordId)
|
3933
|
+
return null;
|
3551
3934
|
try {
|
3552
3935
|
const response = await deleteRecord({
|
3553
3936
|
pathParams: {
|
@@ -3572,7 +3955,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
3572
3955
|
_deleteRecords = new WeakSet();
|
3573
3956
|
deleteRecords_fn = async function(recordIds) {
|
3574
3957
|
const chunkedOperations = chunk(
|
3575
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3958
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3576
3959
|
BULK_OPERATION_MAX_SIZE
|
3577
3960
|
);
|
3578
3961
|
for (const operations of chunkedOperations) {
|
@@ -3615,7 +3998,39 @@ getSchemaTables_fn$1 = async function() {
|
|
3615
3998
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
3616
3999
|
return schema.tables;
|
3617
4000
|
};
|
3618
|
-
|
4001
|
+
_transformObjectToApi = new WeakSet();
|
4002
|
+
transformObjectToApi_fn = async function(object) {
|
4003
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4004
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4005
|
+
if (!schema)
|
4006
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4007
|
+
const result = {};
|
4008
|
+
for (const [key, value] of Object.entries(object)) {
|
4009
|
+
if (key === "xata")
|
4010
|
+
continue;
|
4011
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4012
|
+
switch (type) {
|
4013
|
+
case "link": {
|
4014
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4015
|
+
break;
|
4016
|
+
}
|
4017
|
+
case "datetime": {
|
4018
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4019
|
+
break;
|
4020
|
+
}
|
4021
|
+
case `file`:
|
4022
|
+
result[key] = await parseInputFileEntry(value);
|
4023
|
+
break;
|
4024
|
+
case "file[]":
|
4025
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4026
|
+
break;
|
4027
|
+
default:
|
4028
|
+
result[key] = value;
|
4029
|
+
}
|
4030
|
+
}
|
4031
|
+
return result;
|
4032
|
+
};
|
4033
|
+
const removeLinksFromObject = (object) => {
|
3619
4034
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
3620
4035
|
if (key === "xata")
|
3621
4036
|
return acc;
|
@@ -3664,6 +4079,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
3664
4079
|
}
|
3665
4080
|
break;
|
3666
4081
|
}
|
4082
|
+
case "file":
|
4083
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4084
|
+
break;
|
4085
|
+
case "file[]":
|
4086
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4087
|
+
break;
|
3667
4088
|
default:
|
3668
4089
|
data[column.name] = value ?? null;
|
3669
4090
|
if (column.notNull === true && value === null) {
|
@@ -3673,7 +4094,7 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
3673
4094
|
}
|
3674
4095
|
}
|
3675
4096
|
const record = { ...data };
|
3676
|
-
const serializable = { xata, ...
|
4097
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
3677
4098
|
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
3678
4099
|
record.read = function(columns2) {
|
3679
4100
|
return db[table].read(record["id"], columns2);
|
@@ -3699,7 +4120,7 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
3699
4120
|
return JSON.parse(JSON.stringify(serializable));
|
3700
4121
|
};
|
3701
4122
|
record.toString = function() {
|
3702
|
-
return JSON.stringify(
|
4123
|
+
return JSON.stringify(serializable);
|
3703
4124
|
};
|
3704
4125
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3705
4126
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -3717,11 +4138,7 @@ function extractId(value) {
|
|
3717
4138
|
function isValidColumn(columns, column) {
|
3718
4139
|
if (columns.includes("*"))
|
3719
4140
|
return true;
|
3720
|
-
|
3721
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
3722
|
-
return linkColumns.length > 0;
|
3723
|
-
}
|
3724
|
-
return columns.includes(column.name);
|
4141
|
+
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
3725
4142
|
}
|
3726
4143
|
function parseIfVersion(...args) {
|
3727
4144
|
for (const arg of args) {
|
@@ -3732,6 +4149,12 @@ function parseIfVersion(...args) {
|
|
3732
4149
|
return void 0;
|
3733
4150
|
}
|
3734
4151
|
|
4152
|
+
var __defProp$3 = Object.defineProperty;
|
4153
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4154
|
+
var __publicField$3 = (obj, key, value) => {
|
4155
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4156
|
+
return value;
|
4157
|
+
};
|
3735
4158
|
var __accessCheck$3 = (obj, member, msg) => {
|
3736
4159
|
if (!member.has(obj))
|
3737
4160
|
throw TypeError("Cannot " + msg);
|
@@ -3754,6 +4177,8 @@ var _map;
|
|
3754
4177
|
class SimpleCache {
|
3755
4178
|
constructor(options = {}) {
|
3756
4179
|
__privateAdd$3(this, _map, void 0);
|
4180
|
+
__publicField$3(this, "capacity");
|
4181
|
+
__publicField$3(this, "defaultQueryTTL");
|
3757
4182
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
3758
4183
|
this.capacity = options.max ?? 500;
|
3759
4184
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3951,6 +4376,12 @@ class TransactionPlugin extends XataPlugin {
|
|
3951
4376
|
}
|
3952
4377
|
}
|
3953
4378
|
|
4379
|
+
var __defProp$2 = Object.defineProperty;
|
4380
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4381
|
+
var __publicField$2 = (obj, key, value) => {
|
4382
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4383
|
+
return value;
|
4384
|
+
};
|
3954
4385
|
var __accessCheck = (obj, member, msg) => {
|
3955
4386
|
if (!member.has(obj))
|
3956
4387
|
throw TypeError("Cannot " + msg);
|
@@ -3980,6 +4411,10 @@ const buildClient = (plugins) => {
|
|
3980
4411
|
__privateAdd(this, _parseOptions);
|
3981
4412
|
__privateAdd(this, _getFetchProps);
|
3982
4413
|
__privateAdd(this, _options, void 0);
|
4414
|
+
__publicField$2(this, "db");
|
4415
|
+
__publicField$2(this, "search");
|
4416
|
+
__publicField$2(this, "transactions");
|
4417
|
+
__publicField$2(this, "files");
|
3983
4418
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3984
4419
|
__privateSet(this, _options, safeOptions);
|
3985
4420
|
const pluginOptions = {
|
@@ -3990,9 +4425,11 @@ const buildClient = (plugins) => {
|
|
3990
4425
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3991
4426
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3992
4427
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4428
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3993
4429
|
this.db = db;
|
3994
4430
|
this.search = search;
|
3995
4431
|
this.transactions = transactions;
|
4432
|
+
this.files = files;
|
3996
4433
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3997
4434
|
if (namespace === void 0)
|
3998
4435
|
continue;
|
@@ -4089,11 +4526,17 @@ const buildClient = (plugins) => {
|
|
4089
4526
|
class BaseClient extends buildClient() {
|
4090
4527
|
}
|
4091
4528
|
|
4529
|
+
var __defProp$1 = Object.defineProperty;
|
4530
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4531
|
+
var __publicField$1 = (obj, key, value) => {
|
4532
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4533
|
+
return value;
|
4534
|
+
};
|
4092
4535
|
const META = "__";
|
4093
4536
|
const VALUE = "___";
|
4094
4537
|
class Serializer {
|
4095
4538
|
constructor() {
|
4096
|
-
this
|
4539
|
+
__publicField$1(this, "classes", {});
|
4097
4540
|
}
|
4098
4541
|
add(clazz) {
|
4099
4542
|
this.classes[clazz.name] = clazz;
|
@@ -4171,12 +4614,19 @@ function buildWorkerRunner(config) {
|
|
4171
4614
|
};
|
4172
4615
|
}
|
4173
4616
|
|
4617
|
+
var __defProp = Object.defineProperty;
|
4618
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4619
|
+
var __publicField = (obj, key, value) => {
|
4620
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4621
|
+
return value;
|
4622
|
+
};
|
4174
4623
|
class XataError extends Error {
|
4175
4624
|
constructor(message, status) {
|
4176
4625
|
super(message);
|
4626
|
+
__publicField(this, "status");
|
4177
4627
|
this.status = status;
|
4178
4628
|
}
|
4179
4629
|
}
|
4180
4630
|
|
4181
|
-
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
4631
|
+
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, generateAccessToken, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
4182
4632
|
//# sourceMappingURL=index.mjs.map
|