@xata.io/client 0.0.0-alpha.vfc99020 → 0.0.0-alpha.vfc9ddd5
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 +4 -9
- package/CHANGELOG.md +57 -1
- package/dist/index.cjs +292 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +276 -246
- package/dist/index.mjs +286 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -20,7 +20,8 @@ const TraceAttributes = {
|
|
20
20
|
HTTP_METHOD: "http.method",
|
21
21
|
HTTP_URL: "http.url",
|
22
22
|
HTTP_ROUTE: "http.route",
|
23
|
-
HTTP_TARGET: "http.target"
|
23
|
+
HTTP_TARGET: "http.target",
|
24
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
24
25
|
};
|
25
26
|
|
26
27
|
function notEmpty(value) {
|
@@ -32,8 +33,15 @@ function compact(arr) {
|
|
32
33
|
function compactObject(obj) {
|
33
34
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
34
35
|
}
|
36
|
+
function isBlob(value) {
|
37
|
+
try {
|
38
|
+
return value instanceof Blob;
|
39
|
+
} catch (error) {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
}
|
35
43
|
function isObject(value) {
|
36
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
44
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
37
45
|
}
|
38
46
|
function isDefined(value) {
|
39
47
|
return value !== null && value !== void 0;
|
@@ -265,14 +273,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
265
273
|
return method;
|
266
274
|
};
|
267
275
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
-
const REQUEST_TIMEOUT =
|
276
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
269
277
|
function getFetchImplementation(userFetch) {
|
270
278
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
271
|
-
const
|
279
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
280
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
272
281
|
if (!fetchImpl) {
|
273
|
-
throw new Error(
|
274
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
275
|
-
);
|
282
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
276
283
|
}
|
277
284
|
return fetchImpl;
|
278
285
|
}
|
@@ -314,7 +321,7 @@ class ApiRequestPool {
|
|
314
321
|
}
|
315
322
|
if (stalled) {
|
316
323
|
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
317
|
-
console.warn(`A request to Xata hit
|
324
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
318
325
|
}
|
319
326
|
return response;
|
320
327
|
};
|
@@ -529,7 +536,7 @@ function defaultOnOpen(response) {
|
|
529
536
|
}
|
530
537
|
}
|
531
538
|
|
532
|
-
const VERSION = "0.
|
539
|
+
const VERSION = "0.26.5";
|
533
540
|
|
534
541
|
var __defProp$7 = Object.defineProperty;
|
535
542
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
@@ -615,11 +622,14 @@ function hostHeader(url) {
|
|
615
622
|
const { groups } = pattern.exec(url) ?? {};
|
616
623
|
return groups?.host ? { Host: groups.host } : {};
|
617
624
|
}
|
618
|
-
function parseBody(body, headers) {
|
625
|
+
async function parseBody(body, headers) {
|
619
626
|
if (!isDefined(body))
|
620
627
|
return void 0;
|
628
|
+
if (isBlob(body) || typeof body.text === "function") {
|
629
|
+
return body;
|
630
|
+
}
|
621
631
|
const { "Content-Type": contentType } = headers ?? {};
|
622
|
-
if (String(contentType).toLowerCase() === "application/json") {
|
632
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
623
633
|
return JSON.stringify(body);
|
624
634
|
}
|
625
635
|
return body;
|
@@ -676,7 +686,7 @@ async function fetch$1({
|
|
676
686
|
const response = await pool.request(url, {
|
677
687
|
...fetchOptions,
|
678
688
|
method: method.toUpperCase(),
|
679
|
-
body: parseBody(body, headers),
|
689
|
+
body: await parseBody(body, headers),
|
680
690
|
headers,
|
681
691
|
signal
|
682
692
|
});
|
@@ -687,7 +697,8 @@ async function fetch$1({
|
|
687
697
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
688
698
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
689
699
|
[TraceAttributes.HTTP_HOST]: host,
|
690
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
700
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
701
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
691
702
|
});
|
692
703
|
const message = response.headers?.get("x-xata-message");
|
693
704
|
if (message)
|
@@ -959,12 +970,6 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
959
970
|
...variables,
|
960
971
|
signal
|
961
972
|
});
|
962
|
-
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
963
|
-
url: "/db/{dbBranchName}/sql",
|
964
|
-
method: "post",
|
965
|
-
...variables,
|
966
|
-
signal
|
967
|
-
});
|
968
973
|
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
969
974
|
const askTable = (variables, signal) => dataPlaneFetch({
|
970
975
|
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
@@ -981,6 +986,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
981
986
|
...variables,
|
982
987
|
signal
|
983
988
|
});
|
989
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
990
|
+
url: "/db/{dbBranchName}/sql",
|
991
|
+
method: "post",
|
992
|
+
...variables,
|
993
|
+
signal
|
994
|
+
});
|
984
995
|
const operationsByTag$2 = {
|
985
996
|
branch: {
|
986
997
|
getBranchList,
|
@@ -1045,13 +1056,13 @@ const operationsByTag$2 = {
|
|
1045
1056
|
queryTable,
|
1046
1057
|
searchBranch,
|
1047
1058
|
searchTable,
|
1048
|
-
sqlQuery,
|
1049
1059
|
vectorSearchTable,
|
1050
1060
|
askTable,
|
1051
1061
|
askTableSession,
|
1052
1062
|
summarizeTable,
|
1053
1063
|
aggregateTable
|
1054
|
-
}
|
1064
|
+
},
|
1065
|
+
sql: { sqlQuery }
|
1055
1066
|
};
|
1056
1067
|
|
1057
1068
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -1100,6 +1111,25 @@ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
|
1100
1111
|
...variables,
|
1101
1112
|
signal
|
1102
1113
|
});
|
1114
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1115
|
+
url: "/user/oauth/clients/{clientId}",
|
1116
|
+
method: "delete",
|
1117
|
+
...variables,
|
1118
|
+
signal
|
1119
|
+
});
|
1120
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1121
|
+
url: "/user/oauth/tokens",
|
1122
|
+
method: "get",
|
1123
|
+
...variables,
|
1124
|
+
signal
|
1125
|
+
});
|
1126
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1127
|
+
url: "/user/oauth/tokens/{token}",
|
1128
|
+
method: "delete",
|
1129
|
+
...variables,
|
1130
|
+
signal
|
1131
|
+
});
|
1132
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
1103
1133
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
1104
1134
|
url: "/workspaces",
|
1105
1135
|
method: "get",
|
@@ -1169,9 +1199,17 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
1169
1199
|
signal
|
1170
1200
|
});
|
1171
1201
|
const operationsByTag$1 = {
|
1172
|
-
|
1202
|
+
oAuth: {
|
1203
|
+
getAuthorizationCode,
|
1204
|
+
grantAuthorizationCode,
|
1205
|
+
getUserOAuthClients,
|
1206
|
+
deleteUserOAuthClient,
|
1207
|
+
getUserOAuthAccessTokens,
|
1208
|
+
deleteOAuthAccessToken,
|
1209
|
+
updateOAuthAccessToken
|
1210
|
+
},
|
1173
1211
|
users: { getUser, updateUser, deleteUser },
|
1174
|
-
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey
|
1212
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1175
1213
|
workspaces: {
|
1176
1214
|
getWorkspacesList,
|
1177
1215
|
createWorkspace,
|
@@ -2605,7 +2643,9 @@ class FilesPlugin extends XataPlugin {
|
|
2605
2643
|
},
|
2606
2644
|
upload: async (location, file) => {
|
2607
2645
|
const { table, record, column, fileId = "" } = location ?? {};
|
2646
|
+
const contentType = getContentType(file);
|
2608
2647
|
return await putFileItem({
|
2648
|
+
...pluginOptions,
|
2609
2649
|
pathParams: {
|
2610
2650
|
workspace: "{workspaceId}",
|
2611
2651
|
dbBranchName: "{dbBranch}",
|
@@ -2616,7 +2656,7 @@ class FilesPlugin extends XataPlugin {
|
|
2616
2656
|
fileId
|
2617
2657
|
},
|
2618
2658
|
body: file,
|
2619
|
-
|
2659
|
+
headers: { "Content-Type": contentType }
|
2620
2660
|
});
|
2621
2661
|
},
|
2622
2662
|
delete: async (location) => {
|
@@ -2637,6 +2677,19 @@ class FilesPlugin extends XataPlugin {
|
|
2637
2677
|
};
|
2638
2678
|
}
|
2639
2679
|
}
|
2680
|
+
function getContentType(file) {
|
2681
|
+
if (typeof file === "string") {
|
2682
|
+
return "text/plain";
|
2683
|
+
}
|
2684
|
+
if (isBlob(file)) {
|
2685
|
+
return file.type;
|
2686
|
+
}
|
2687
|
+
try {
|
2688
|
+
return file.type;
|
2689
|
+
} catch (e) {
|
2690
|
+
}
|
2691
|
+
return "application/octet-stream";
|
2692
|
+
}
|
2640
2693
|
|
2641
2694
|
function buildTransformString(transformations) {
|
2642
2695
|
return transformations.flatMap(
|
@@ -2653,12 +2706,17 @@ function buildTransformString(transformations) {
|
|
2653
2706
|
})
|
2654
2707
|
).join(",");
|
2655
2708
|
}
|
2656
|
-
function transformImage(url, transformations) {
|
2709
|
+
function transformImage(url, ...transformations) {
|
2657
2710
|
if (!isDefined(url))
|
2658
2711
|
return void 0;
|
2659
|
-
const
|
2712
|
+
const newTransformations = buildTransformString(transformations);
|
2660
2713
|
const { hostname, pathname, search } = new URL(url);
|
2661
|
-
|
2714
|
+
const pathParts = pathname.split("/");
|
2715
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2716
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2717
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2718
|
+
const path = pathParts.join("/");
|
2719
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2662
2720
|
}
|
2663
2721
|
|
2664
2722
|
var __defProp$6 = Object.defineProperty;
|
@@ -2670,19 +2728,23 @@ var __publicField$6 = (obj, key, value) => {
|
|
2670
2728
|
class XataFile {
|
2671
2729
|
constructor(file) {
|
2672
2730
|
/**
|
2673
|
-
*
|
2731
|
+
* Identifier of the file.
|
2732
|
+
*/
|
2733
|
+
__publicField$6(this, "id");
|
2734
|
+
/**
|
2735
|
+
* Name of the file.
|
2674
2736
|
*/
|
2675
2737
|
__publicField$6(this, "name");
|
2676
2738
|
/**
|
2677
|
-
* Media type of
|
2739
|
+
* Media type of the file.
|
2678
2740
|
*/
|
2679
2741
|
__publicField$6(this, "mediaType");
|
2680
2742
|
/**
|
2681
|
-
* Base64 encoded content of
|
2743
|
+
* Base64 encoded content of the file.
|
2682
2744
|
*/
|
2683
2745
|
__publicField$6(this, "base64Content");
|
2684
2746
|
/**
|
2685
|
-
* Whether to enable public url for
|
2747
|
+
* Whether to enable public url for the file.
|
2686
2748
|
*/
|
2687
2749
|
__publicField$6(this, "enablePublicUrl");
|
2688
2750
|
/**
|
@@ -2690,35 +2752,36 @@ class XataFile {
|
|
2690
2752
|
*/
|
2691
2753
|
__publicField$6(this, "signedUrlTimeout");
|
2692
2754
|
/**
|
2693
|
-
* Size of
|
2755
|
+
* Size of the file.
|
2694
2756
|
*/
|
2695
2757
|
__publicField$6(this, "size");
|
2696
2758
|
/**
|
2697
|
-
* Version of
|
2759
|
+
* Version of the file.
|
2698
2760
|
*/
|
2699
2761
|
__publicField$6(this, "version");
|
2700
2762
|
/**
|
2701
|
-
* Url of
|
2763
|
+
* Url of the file.
|
2702
2764
|
*/
|
2703
2765
|
__publicField$6(this, "url");
|
2704
2766
|
/**
|
2705
|
-
* Signed url of
|
2767
|
+
* Signed url of the file.
|
2706
2768
|
*/
|
2707
2769
|
__publicField$6(this, "signedUrl");
|
2708
2770
|
/**
|
2709
|
-
* Attributes of
|
2771
|
+
* Attributes of the file.
|
2710
2772
|
*/
|
2711
2773
|
__publicField$6(this, "attributes");
|
2712
|
-
this.
|
2774
|
+
this.id = file.id;
|
2775
|
+
this.name = file.name || "";
|
2713
2776
|
this.mediaType = file.mediaType || "application/octet-stream";
|
2714
2777
|
this.base64Content = file.base64Content;
|
2715
|
-
this.enablePublicUrl = file.enablePublicUrl;
|
2716
|
-
this.signedUrlTimeout = file.signedUrlTimeout;
|
2717
|
-
this.size = file.size;
|
2718
|
-
this.version = file.version;
|
2719
|
-
this.url = file.url;
|
2778
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2779
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2780
|
+
this.size = file.size ?? 0;
|
2781
|
+
this.version = file.version ?? 1;
|
2782
|
+
this.url = file.url || "";
|
2720
2783
|
this.signedUrl = file.signedUrl;
|
2721
|
-
this.attributes = file.attributes;
|
2784
|
+
this.attributes = file.attributes || {};
|
2722
2785
|
}
|
2723
2786
|
static fromBuffer(buffer, options = {}) {
|
2724
2787
|
const base64Content = buffer.toString("base64");
|
@@ -2770,8 +2833,12 @@ class XataFile {
|
|
2770
2833
|
if (!this.base64Content) {
|
2771
2834
|
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2772
2835
|
}
|
2773
|
-
const
|
2774
|
-
|
2836
|
+
const binary = atob(this.base64Content);
|
2837
|
+
const uint8Array = new Uint8Array(binary.length);
|
2838
|
+
for (let i = 0; i < binary.length; i++) {
|
2839
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2840
|
+
}
|
2841
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2775
2842
|
}
|
2776
2843
|
static fromString(string, options = {}) {
|
2777
2844
|
const base64Content = btoa(string);
|
@@ -2794,8 +2861,10 @@ class XataFile {
|
|
2794
2861
|
}
|
2795
2862
|
transform(...options) {
|
2796
2863
|
return {
|
2797
|
-
url: transformImage(this.url, options),
|
2798
|
-
signedUrl: transformImage(this.signedUrl, options)
|
2864
|
+
url: transformImage(this.url, ...options),
|
2865
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2866
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2867
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2799
2868
|
};
|
2800
2869
|
}
|
2801
2870
|
}
|
@@ -2803,7 +2872,15 @@ const parseInputFileEntry = async (entry) => {
|
|
2803
2872
|
if (!isDefined(entry))
|
2804
2873
|
return null;
|
2805
2874
|
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2806
|
-
return compactObject({
|
2875
|
+
return compactObject({
|
2876
|
+
id,
|
2877
|
+
// Name cannot be an empty string in our API
|
2878
|
+
name: name ? name : void 0,
|
2879
|
+
mediaType,
|
2880
|
+
base64Content,
|
2881
|
+
enablePublicUrl,
|
2882
|
+
signedUrlTimeout
|
2883
|
+
});
|
2807
2884
|
};
|
2808
2885
|
|
2809
2886
|
function cleanFilter(filter) {
|
@@ -2833,6 +2910,25 @@ function cleanFilter(filter) {
|
|
2833
2910
|
return Object.keys(values).length > 0 ? values : void 0;
|
2834
2911
|
}
|
2835
2912
|
|
2913
|
+
function stringifyJson(value) {
|
2914
|
+
if (!isDefined(value))
|
2915
|
+
return value;
|
2916
|
+
if (isString(value))
|
2917
|
+
return value;
|
2918
|
+
try {
|
2919
|
+
return JSON.stringify(value);
|
2920
|
+
} catch (e) {
|
2921
|
+
return value;
|
2922
|
+
}
|
2923
|
+
}
|
2924
|
+
function parseJson(value) {
|
2925
|
+
try {
|
2926
|
+
return JSON.parse(value);
|
2927
|
+
} catch (e) {
|
2928
|
+
return value;
|
2929
|
+
}
|
2930
|
+
}
|
2931
|
+
|
2836
2932
|
var __defProp$5 = Object.defineProperty;
|
2837
2933
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2838
2934
|
var __publicField$5 = (obj, key, value) => {
|
@@ -3291,7 +3387,8 @@ const RecordColumnTypes = [
|
|
3291
3387
|
"datetime",
|
3292
3388
|
"vector",
|
3293
3389
|
"file[]",
|
3294
|
-
"file"
|
3390
|
+
"file",
|
3391
|
+
"json"
|
3295
3392
|
];
|
3296
3393
|
function isIdentifiable(x) {
|
3297
3394
|
return isObject(x) && isString(x?.id);
|
@@ -3302,6 +3399,24 @@ function isXataRecord(x) {
|
|
3302
3399
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
3303
3400
|
}
|
3304
3401
|
|
3402
|
+
function isValidExpandedColumn(column) {
|
3403
|
+
return isObject(column) && isString(column.name);
|
3404
|
+
}
|
3405
|
+
function isValidSelectableColumns(columns) {
|
3406
|
+
if (!Array.isArray(columns)) {
|
3407
|
+
return false;
|
3408
|
+
}
|
3409
|
+
return columns.every((column) => {
|
3410
|
+
if (typeof column === "string") {
|
3411
|
+
return true;
|
3412
|
+
}
|
3413
|
+
if (typeof column === "object") {
|
3414
|
+
return isValidExpandedColumn(column);
|
3415
|
+
}
|
3416
|
+
return false;
|
3417
|
+
});
|
3418
|
+
}
|
3419
|
+
|
3305
3420
|
function isSortFilterString(value) {
|
3306
3421
|
return isString(value);
|
3307
3422
|
}
|
@@ -3402,24 +3517,24 @@ class RestRepository extends Query {
|
|
3402
3517
|
if (a.length === 0)
|
3403
3518
|
return [];
|
3404
3519
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3405
|
-
const columns =
|
3520
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3406
3521
|
const result = await this.read(ids, columns);
|
3407
3522
|
return result;
|
3408
3523
|
}
|
3409
3524
|
if (isString(a) && isObject(b)) {
|
3410
3525
|
if (a === "")
|
3411
3526
|
throw new Error("The id can't be empty");
|
3412
|
-
const columns =
|
3527
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3413
3528
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3414
3529
|
}
|
3415
3530
|
if (isObject(a) && isString(a.id)) {
|
3416
3531
|
if (a.id === "")
|
3417
3532
|
throw new Error("The id can't be empty");
|
3418
|
-
const columns =
|
3533
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3419
3534
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3420
3535
|
}
|
3421
3536
|
if (isObject(a)) {
|
3422
|
-
const columns =
|
3537
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3423
3538
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
3424
3539
|
}
|
3425
3540
|
throw new Error("Invalid arguments for create method");
|
@@ -3427,7 +3542,7 @@ class RestRepository extends Query {
|
|
3427
3542
|
}
|
3428
3543
|
async read(a, b) {
|
3429
3544
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
3430
|
-
const columns =
|
3545
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3431
3546
|
if (Array.isArray(a)) {
|
3432
3547
|
if (a.length === 0)
|
3433
3548
|
return [];
|
@@ -3454,7 +3569,13 @@ class RestRepository extends Query {
|
|
3454
3569
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3455
3570
|
});
|
3456
3571
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3457
|
-
return initObject(
|
3572
|
+
return initObject(
|
3573
|
+
__privateGet$4(this, _db),
|
3574
|
+
schemaTables,
|
3575
|
+
__privateGet$4(this, _table),
|
3576
|
+
response,
|
3577
|
+
columns
|
3578
|
+
);
|
3458
3579
|
} catch (e) {
|
3459
3580
|
if (isObject(e) && e.status === 404) {
|
3460
3581
|
return null;
|
@@ -3496,17 +3617,17 @@ class RestRepository extends Query {
|
|
3496
3617
|
ifVersion,
|
3497
3618
|
upsert: false
|
3498
3619
|
});
|
3499
|
-
const columns =
|
3620
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3500
3621
|
const result = await this.read(a, columns);
|
3501
3622
|
return result;
|
3502
3623
|
}
|
3503
3624
|
try {
|
3504
3625
|
if (isString(a) && isObject(b)) {
|
3505
|
-
const columns =
|
3626
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3506
3627
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3507
3628
|
}
|
3508
3629
|
if (isObject(a) && isString(a.id)) {
|
3509
|
-
const columns =
|
3630
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3510
3631
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3511
3632
|
}
|
3512
3633
|
} catch (error) {
|
@@ -3546,20 +3667,20 @@ class RestRepository extends Query {
|
|
3546
3667
|
ifVersion,
|
3547
3668
|
upsert: true
|
3548
3669
|
});
|
3549
|
-
const columns =
|
3670
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3550
3671
|
const result = await this.read(a, columns);
|
3551
3672
|
return result;
|
3552
3673
|
}
|
3553
3674
|
if (isString(a) && isObject(b)) {
|
3554
3675
|
if (a === "")
|
3555
3676
|
throw new Error("The id can't be empty");
|
3556
|
-
const columns =
|
3677
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3557
3678
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3558
3679
|
}
|
3559
3680
|
if (isObject(a) && isString(a.id)) {
|
3560
3681
|
if (a.id === "")
|
3561
3682
|
throw new Error("The id can't be empty");
|
3562
|
-
const columns =
|
3683
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3563
3684
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3564
3685
|
}
|
3565
3686
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3578,20 +3699,20 @@ class RestRepository extends Query {
|
|
3578
3699
|
if (a.length === 0)
|
3579
3700
|
return [];
|
3580
3701
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
3581
|
-
const columns =
|
3702
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3582
3703
|
const result = await this.read(ids, columns);
|
3583
3704
|
return result;
|
3584
3705
|
}
|
3585
3706
|
if (isString(a) && isObject(b)) {
|
3586
3707
|
if (a === "")
|
3587
3708
|
throw new Error("The id can't be empty");
|
3588
|
-
const columns =
|
3709
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3589
3710
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3590
3711
|
}
|
3591
3712
|
if (isObject(a) && isString(a.id)) {
|
3592
3713
|
if (a.id === "")
|
3593
3714
|
throw new Error("The id can't be empty");
|
3594
|
-
const columns =
|
3715
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3595
3716
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3596
3717
|
}
|
3597
3718
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3615,7 +3736,7 @@ class RestRepository extends Query {
|
|
3615
3736
|
return o.id;
|
3616
3737
|
throw new Error("Invalid arguments for delete method");
|
3617
3738
|
});
|
3618
|
-
const columns =
|
3739
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3619
3740
|
const result = await this.read(a, columns);
|
3620
3741
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3621
3742
|
return result;
|
@@ -3734,7 +3855,13 @@ class RestRepository extends Query {
|
|
3734
3855
|
});
|
3735
3856
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3736
3857
|
const records = objects.map(
|
3737
|
-
(record) => initObject(
|
3858
|
+
(record) => initObject(
|
3859
|
+
__privateGet$4(this, _db),
|
3860
|
+
schemaTables,
|
3861
|
+
__privateGet$4(this, _table),
|
3862
|
+
record,
|
3863
|
+
data.columns ?? ["*"]
|
3864
|
+
)
|
3738
3865
|
);
|
3739
3866
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
3740
3867
|
return new Page(query, meta, records);
|
@@ -4040,6 +4167,9 @@ transformObjectToApi_fn = async function(object) {
|
|
4040
4167
|
case "file[]":
|
4041
4168
|
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4042
4169
|
break;
|
4170
|
+
case "json":
|
4171
|
+
result[key] = stringifyJson(value);
|
4172
|
+
break;
|
4043
4173
|
default:
|
4044
4174
|
result[key] = value;
|
4045
4175
|
}
|
@@ -4083,13 +4213,19 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4083
4213
|
if (item === column.name) {
|
4084
4214
|
return [...acc, "*"];
|
4085
4215
|
}
|
4086
|
-
if (item.startsWith(`${column.name}.`)) {
|
4216
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
4087
4217
|
const [, ...path] = item.split(".");
|
4088
4218
|
return [...acc, path.join(".")];
|
4089
4219
|
}
|
4090
4220
|
return acc;
|
4091
4221
|
}, []);
|
4092
|
-
data[column.name] = initObject(
|
4222
|
+
data[column.name] = initObject(
|
4223
|
+
db,
|
4224
|
+
schemaTables,
|
4225
|
+
linkTable,
|
4226
|
+
value,
|
4227
|
+
selectedLinkColumns
|
4228
|
+
);
|
4093
4229
|
} else {
|
4094
4230
|
data[column.name] = null;
|
4095
4231
|
}
|
@@ -4101,6 +4237,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4101
4237
|
case "file[]":
|
4102
4238
|
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4103
4239
|
break;
|
4240
|
+
case "json":
|
4241
|
+
data[column.name] = parseJson(value);
|
4242
|
+
break;
|
4104
4243
|
default:
|
4105
4244
|
data[column.name] = value ?? null;
|
4106
4245
|
if (column.notNull === true && value === null) {
|
@@ -4116,12 +4255,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4116
4255
|
return db[table].read(record["id"], columns2);
|
4117
4256
|
};
|
4118
4257
|
record.update = function(data2, b, c) {
|
4119
|
-
const columns2 =
|
4258
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4120
4259
|
const ifVersion = parseIfVersion(b, c);
|
4121
4260
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
4122
4261
|
};
|
4123
4262
|
record.replace = function(data2, b, c) {
|
4124
|
-
const columns2 =
|
4263
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4125
4264
|
const ifVersion = parseIfVersion(b, c);
|
4126
4265
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4127
4266
|
};
|
@@ -4154,7 +4293,7 @@ function extractId(value) {
|
|
4154
4293
|
function isValidColumn(columns, column) {
|
4155
4294
|
if (columns.includes("*"))
|
4156
4295
|
return true;
|
4157
|
-
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
4296
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
4158
4297
|
}
|
4159
4298
|
function parseIfVersion(...args) {
|
4160
4299
|
for (const arg of args) {
|
@@ -4377,6 +4516,78 @@ getSchemaTables_fn = async function(pluginOptions) {
|
|
4377
4516
|
return schema.tables;
|
4378
4517
|
};
|
4379
4518
|
|
4519
|
+
function escapeElement(elementRepresentation) {
|
4520
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4521
|
+
return '"' + escaped + '"';
|
4522
|
+
}
|
4523
|
+
function arrayString(val) {
|
4524
|
+
let result = "{";
|
4525
|
+
for (let i = 0; i < val.length; i++) {
|
4526
|
+
if (i > 0) {
|
4527
|
+
result = result + ",";
|
4528
|
+
}
|
4529
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4530
|
+
result = result + "NULL";
|
4531
|
+
} else if (Array.isArray(val[i])) {
|
4532
|
+
result = result + arrayString(val[i]);
|
4533
|
+
} else if (val[i] instanceof Buffer) {
|
4534
|
+
result += "\\\\x" + val[i].toString("hex");
|
4535
|
+
} else {
|
4536
|
+
result += escapeElement(prepareValue(val[i]));
|
4537
|
+
}
|
4538
|
+
}
|
4539
|
+
result = result + "}";
|
4540
|
+
return result;
|
4541
|
+
}
|
4542
|
+
function prepareValue(value) {
|
4543
|
+
if (!isDefined(value))
|
4544
|
+
return null;
|
4545
|
+
if (value instanceof Date) {
|
4546
|
+
return value.toISOString();
|
4547
|
+
}
|
4548
|
+
if (Array.isArray(value)) {
|
4549
|
+
return arrayString(value);
|
4550
|
+
}
|
4551
|
+
if (isObject(value)) {
|
4552
|
+
return JSON.stringify(value);
|
4553
|
+
}
|
4554
|
+
try {
|
4555
|
+
return value.toString();
|
4556
|
+
} catch (e) {
|
4557
|
+
return value;
|
4558
|
+
}
|
4559
|
+
}
|
4560
|
+
function prepareParams(param1, param2) {
|
4561
|
+
if (isString(param1)) {
|
4562
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4563
|
+
}
|
4564
|
+
if (isStringArray(param1)) {
|
4565
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4566
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4567
|
+
}, "");
|
4568
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4569
|
+
}
|
4570
|
+
if (isObject(param1)) {
|
4571
|
+
const { statement, params, consistency } = param1;
|
4572
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4573
|
+
}
|
4574
|
+
throw new Error("Invalid query");
|
4575
|
+
}
|
4576
|
+
|
4577
|
+
class SQLPlugin extends XataPlugin {
|
4578
|
+
build(pluginOptions) {
|
4579
|
+
return async (param1, ...param2) => {
|
4580
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4581
|
+
const { records, warning } = await sqlQuery({
|
4582
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4583
|
+
body: { statement, params, consistency },
|
4584
|
+
...pluginOptions
|
4585
|
+
});
|
4586
|
+
return { records, warning };
|
4587
|
+
};
|
4588
|
+
}
|
4589
|
+
}
|
4590
|
+
|
4380
4591
|
class TransactionPlugin extends XataPlugin {
|
4381
4592
|
build(pluginOptions) {
|
4382
4593
|
return {
|
@@ -4430,6 +4641,7 @@ const buildClient = (plugins) => {
|
|
4430
4641
|
__publicField$2(this, "db");
|
4431
4642
|
__publicField$2(this, "search");
|
4432
4643
|
__publicField$2(this, "transactions");
|
4644
|
+
__publicField$2(this, "sql");
|
4433
4645
|
__publicField$2(this, "files");
|
4434
4646
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
4435
4647
|
__privateSet(this, _options, safeOptions);
|
@@ -4441,10 +4653,12 @@ const buildClient = (plugins) => {
|
|
4441
4653
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
4442
4654
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4443
4655
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4656
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4444
4657
|
const files = new FilesPlugin().build(pluginOptions);
|
4445
4658
|
this.db = db;
|
4446
4659
|
this.search = search;
|
4447
4660
|
this.transactions = transactions;
|
4661
|
+
this.sql = sql;
|
4448
4662
|
this.files = files;
|
4449
4663
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
4450
4664
|
if (namespace === void 0)
|
@@ -4658,6 +4872,7 @@ exports.RecordArray = RecordArray;
|
|
4658
4872
|
exports.RecordColumnTypes = RecordColumnTypes;
|
4659
4873
|
exports.Repository = Repository;
|
4660
4874
|
exports.RestRepository = RestRepository;
|
4875
|
+
exports.SQLPlugin = SQLPlugin;
|
4661
4876
|
exports.SchemaPlugin = SchemaPlugin;
|
4662
4877
|
exports.SearchPlugin = SearchPlugin;
|
4663
4878
|
exports.Serializer = Serializer;
|
@@ -4698,10 +4913,12 @@ exports.deleteDatabase = deleteDatabase;
|
|
4698
4913
|
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
4699
4914
|
exports.deleteFile = deleteFile;
|
4700
4915
|
exports.deleteFileItem = deleteFileItem;
|
4916
|
+
exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
|
4701
4917
|
exports.deleteRecord = deleteRecord;
|
4702
4918
|
exports.deleteTable = deleteTable;
|
4703
4919
|
exports.deleteUser = deleteUser;
|
4704
4920
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
4921
|
+
exports.deleteUserOAuthClient = deleteUserOAuthClient;
|
4705
4922
|
exports.deleteWorkspace = deleteWorkspace;
|
4706
4923
|
exports.deserialize = deserialize;
|
4707
4924
|
exports.endsWith = endsWith;
|
@@ -4737,6 +4954,7 @@ exports.getTableColumns = getTableColumns;
|
|
4737
4954
|
exports.getTableSchema = getTableSchema;
|
4738
4955
|
exports.getUser = getUser;
|
4739
4956
|
exports.getUserAPIKeys = getUserAPIKeys;
|
4957
|
+
exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
|
4740
4958
|
exports.getUserOAuthClients = getUserOAuthClients;
|
4741
4959
|
exports.getWorkspace = getWorkspace;
|
4742
4960
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
@@ -4760,6 +4978,8 @@ exports.isHostProviderAlias = isHostProviderAlias;
|
|
4760
4978
|
exports.isHostProviderBuilder = isHostProviderBuilder;
|
4761
4979
|
exports.isIdentifiable = isIdentifiable;
|
4762
4980
|
exports.isNot = isNot;
|
4981
|
+
exports.isValidExpandedColumn = isValidExpandedColumn;
|
4982
|
+
exports.isValidSelectableColumns = isValidSelectableColumns;
|
4763
4983
|
exports.isXataRecord = isXataRecord;
|
4764
4984
|
exports.le = le;
|
4765
4985
|
exports.lessEquals = lessEquals;
|
@@ -4800,6 +5020,7 @@ exports.updateColumn = updateColumn;
|
|
4800
5020
|
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
4801
5021
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
4802
5022
|
exports.updateMigrationRequest = updateMigrationRequest;
|
5023
|
+
exports.updateOAuthAccessToken = updateOAuthAccessToken;
|
4803
5024
|
exports.updateRecordWithID = updateRecordWithID;
|
4804
5025
|
exports.updateTable = updateTable;
|
4805
5026
|
exports.updateUser = updateUser;
|