@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.mjs
CHANGED
@@ -18,7 +18,8 @@ const TraceAttributes = {
|
|
18
18
|
HTTP_METHOD: "http.method",
|
19
19
|
HTTP_URL: "http.url",
|
20
20
|
HTTP_ROUTE: "http.route",
|
21
|
-
HTTP_TARGET: "http.target"
|
21
|
+
HTTP_TARGET: "http.target",
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
22
23
|
};
|
23
24
|
|
24
25
|
function notEmpty(value) {
|
@@ -30,8 +31,15 @@ function compact(arr) {
|
|
30
31
|
function compactObject(obj) {
|
31
32
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
32
33
|
}
|
34
|
+
function isBlob(value) {
|
35
|
+
try {
|
36
|
+
return value instanceof Blob;
|
37
|
+
} catch (error) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
}
|
33
41
|
function isObject(value) {
|
34
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
35
43
|
}
|
36
44
|
function isDefined(value) {
|
37
45
|
return value !== null && value !== void 0;
|
@@ -263,14 +271,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
263
271
|
return method;
|
264
272
|
};
|
265
273
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
266
|
-
const REQUEST_TIMEOUT =
|
274
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
267
275
|
function getFetchImplementation(userFetch) {
|
268
276
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
269
|
-
const
|
277
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
278
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
270
279
|
if (!fetchImpl) {
|
271
|
-
throw new Error(
|
272
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
273
|
-
);
|
280
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
274
281
|
}
|
275
282
|
return fetchImpl;
|
276
283
|
}
|
@@ -312,7 +319,7 @@ class ApiRequestPool {
|
|
312
319
|
}
|
313
320
|
if (stalled) {
|
314
321
|
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
315
|
-
console.warn(`A request to Xata hit
|
322
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
316
323
|
}
|
317
324
|
return response;
|
318
325
|
};
|
@@ -527,7 +534,7 @@ function defaultOnOpen(response) {
|
|
527
534
|
}
|
528
535
|
}
|
529
536
|
|
530
|
-
const VERSION = "0.
|
537
|
+
const VERSION = "0.26.5";
|
531
538
|
|
532
539
|
var __defProp$7 = Object.defineProperty;
|
533
540
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
@@ -613,11 +620,14 @@ function hostHeader(url) {
|
|
613
620
|
const { groups } = pattern.exec(url) ?? {};
|
614
621
|
return groups?.host ? { Host: groups.host } : {};
|
615
622
|
}
|
616
|
-
function parseBody(body, headers) {
|
623
|
+
async function parseBody(body, headers) {
|
617
624
|
if (!isDefined(body))
|
618
625
|
return void 0;
|
626
|
+
if (isBlob(body) || typeof body.text === "function") {
|
627
|
+
return body;
|
628
|
+
}
|
619
629
|
const { "Content-Type": contentType } = headers ?? {};
|
620
|
-
if (String(contentType).toLowerCase() === "application/json") {
|
630
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
621
631
|
return JSON.stringify(body);
|
622
632
|
}
|
623
633
|
return body;
|
@@ -674,7 +684,7 @@ async function fetch$1({
|
|
674
684
|
const response = await pool.request(url, {
|
675
685
|
...fetchOptions,
|
676
686
|
method: method.toUpperCase(),
|
677
|
-
body: parseBody(body, headers),
|
687
|
+
body: await parseBody(body, headers),
|
678
688
|
headers,
|
679
689
|
signal
|
680
690
|
});
|
@@ -685,7 +695,8 @@ async function fetch$1({
|
|
685
695
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
686
696
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
687
697
|
[TraceAttributes.HTTP_HOST]: host,
|
688
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
698
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
699
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
689
700
|
});
|
690
701
|
const message = response.headers?.get("x-xata-message");
|
691
702
|
if (message)
|
@@ -957,12 +968,6 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
957
968
|
...variables,
|
958
969
|
signal
|
959
970
|
});
|
960
|
-
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
961
|
-
url: "/db/{dbBranchName}/sql",
|
962
|
-
method: "post",
|
963
|
-
...variables,
|
964
|
-
signal
|
965
|
-
});
|
966
971
|
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
967
972
|
const askTable = (variables, signal) => dataPlaneFetch({
|
968
973
|
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
@@ -979,6 +984,12 @@ const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
979
984
|
...variables,
|
980
985
|
signal
|
981
986
|
});
|
987
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
988
|
+
url: "/db/{dbBranchName}/sql",
|
989
|
+
method: "post",
|
990
|
+
...variables,
|
991
|
+
signal
|
992
|
+
});
|
982
993
|
const operationsByTag$2 = {
|
983
994
|
branch: {
|
984
995
|
getBranchList,
|
@@ -1043,13 +1054,13 @@ const operationsByTag$2 = {
|
|
1043
1054
|
queryTable,
|
1044
1055
|
searchBranch,
|
1045
1056
|
searchTable,
|
1046
|
-
sqlQuery,
|
1047
1057
|
vectorSearchTable,
|
1048
1058
|
askTable,
|
1049
1059
|
askTableSession,
|
1050
1060
|
summarizeTable,
|
1051
1061
|
aggregateTable
|
1052
|
-
}
|
1062
|
+
},
|
1063
|
+
sql: { sqlQuery }
|
1053
1064
|
};
|
1054
1065
|
|
1055
1066
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -1098,6 +1109,25 @@ const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
|
1098
1109
|
...variables,
|
1099
1110
|
signal
|
1100
1111
|
});
|
1112
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1113
|
+
url: "/user/oauth/clients/{clientId}",
|
1114
|
+
method: "delete",
|
1115
|
+
...variables,
|
1116
|
+
signal
|
1117
|
+
});
|
1118
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1119
|
+
url: "/user/oauth/tokens",
|
1120
|
+
method: "get",
|
1121
|
+
...variables,
|
1122
|
+
signal
|
1123
|
+
});
|
1124
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1125
|
+
url: "/user/oauth/tokens/{token}",
|
1126
|
+
method: "delete",
|
1127
|
+
...variables,
|
1128
|
+
signal
|
1129
|
+
});
|
1130
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
1101
1131
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
1102
1132
|
url: "/workspaces",
|
1103
1133
|
method: "get",
|
@@ -1167,9 +1197,17 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
1167
1197
|
signal
|
1168
1198
|
});
|
1169
1199
|
const operationsByTag$1 = {
|
1170
|
-
|
1200
|
+
oAuth: {
|
1201
|
+
getAuthorizationCode,
|
1202
|
+
grantAuthorizationCode,
|
1203
|
+
getUserOAuthClients,
|
1204
|
+
deleteUserOAuthClient,
|
1205
|
+
getUserOAuthAccessTokens,
|
1206
|
+
deleteOAuthAccessToken,
|
1207
|
+
updateOAuthAccessToken
|
1208
|
+
},
|
1171
1209
|
users: { getUser, updateUser, deleteUser },
|
1172
|
-
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey
|
1210
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1173
1211
|
workspaces: {
|
1174
1212
|
getWorkspacesList,
|
1175
1213
|
createWorkspace,
|
@@ -2603,7 +2641,9 @@ class FilesPlugin extends XataPlugin {
|
|
2603
2641
|
},
|
2604
2642
|
upload: async (location, file) => {
|
2605
2643
|
const { table, record, column, fileId = "" } = location ?? {};
|
2644
|
+
const contentType = getContentType(file);
|
2606
2645
|
return await putFileItem({
|
2646
|
+
...pluginOptions,
|
2607
2647
|
pathParams: {
|
2608
2648
|
workspace: "{workspaceId}",
|
2609
2649
|
dbBranchName: "{dbBranch}",
|
@@ -2614,7 +2654,7 @@ class FilesPlugin extends XataPlugin {
|
|
2614
2654
|
fileId
|
2615
2655
|
},
|
2616
2656
|
body: file,
|
2617
|
-
|
2657
|
+
headers: { "Content-Type": contentType }
|
2618
2658
|
});
|
2619
2659
|
},
|
2620
2660
|
delete: async (location) => {
|
@@ -2635,6 +2675,19 @@ class FilesPlugin extends XataPlugin {
|
|
2635
2675
|
};
|
2636
2676
|
}
|
2637
2677
|
}
|
2678
|
+
function getContentType(file) {
|
2679
|
+
if (typeof file === "string") {
|
2680
|
+
return "text/plain";
|
2681
|
+
}
|
2682
|
+
if (isBlob(file)) {
|
2683
|
+
return file.type;
|
2684
|
+
}
|
2685
|
+
try {
|
2686
|
+
return file.type;
|
2687
|
+
} catch (e) {
|
2688
|
+
}
|
2689
|
+
return "application/octet-stream";
|
2690
|
+
}
|
2638
2691
|
|
2639
2692
|
function buildTransformString(transformations) {
|
2640
2693
|
return transformations.flatMap(
|
@@ -2651,12 +2704,17 @@ function buildTransformString(transformations) {
|
|
2651
2704
|
})
|
2652
2705
|
).join(",");
|
2653
2706
|
}
|
2654
|
-
function transformImage(url, transformations) {
|
2707
|
+
function transformImage(url, ...transformations) {
|
2655
2708
|
if (!isDefined(url))
|
2656
2709
|
return void 0;
|
2657
|
-
const
|
2710
|
+
const newTransformations = buildTransformString(transformations);
|
2658
2711
|
const { hostname, pathname, search } = new URL(url);
|
2659
|
-
|
2712
|
+
const pathParts = pathname.split("/");
|
2713
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2714
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2715
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2716
|
+
const path = pathParts.join("/");
|
2717
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2660
2718
|
}
|
2661
2719
|
|
2662
2720
|
var __defProp$6 = Object.defineProperty;
|
@@ -2668,19 +2726,23 @@ var __publicField$6 = (obj, key, value) => {
|
|
2668
2726
|
class XataFile {
|
2669
2727
|
constructor(file) {
|
2670
2728
|
/**
|
2671
|
-
*
|
2729
|
+
* Identifier of the file.
|
2730
|
+
*/
|
2731
|
+
__publicField$6(this, "id");
|
2732
|
+
/**
|
2733
|
+
* Name of the file.
|
2672
2734
|
*/
|
2673
2735
|
__publicField$6(this, "name");
|
2674
2736
|
/**
|
2675
|
-
* Media type of
|
2737
|
+
* Media type of the file.
|
2676
2738
|
*/
|
2677
2739
|
__publicField$6(this, "mediaType");
|
2678
2740
|
/**
|
2679
|
-
* Base64 encoded content of
|
2741
|
+
* Base64 encoded content of the file.
|
2680
2742
|
*/
|
2681
2743
|
__publicField$6(this, "base64Content");
|
2682
2744
|
/**
|
2683
|
-
* Whether to enable public url for
|
2745
|
+
* Whether to enable public url for the file.
|
2684
2746
|
*/
|
2685
2747
|
__publicField$6(this, "enablePublicUrl");
|
2686
2748
|
/**
|
@@ -2688,35 +2750,36 @@ class XataFile {
|
|
2688
2750
|
*/
|
2689
2751
|
__publicField$6(this, "signedUrlTimeout");
|
2690
2752
|
/**
|
2691
|
-
* Size of
|
2753
|
+
* Size of the file.
|
2692
2754
|
*/
|
2693
2755
|
__publicField$6(this, "size");
|
2694
2756
|
/**
|
2695
|
-
* Version of
|
2757
|
+
* Version of the file.
|
2696
2758
|
*/
|
2697
2759
|
__publicField$6(this, "version");
|
2698
2760
|
/**
|
2699
|
-
* Url of
|
2761
|
+
* Url of the file.
|
2700
2762
|
*/
|
2701
2763
|
__publicField$6(this, "url");
|
2702
2764
|
/**
|
2703
|
-
* Signed url of
|
2765
|
+
* Signed url of the file.
|
2704
2766
|
*/
|
2705
2767
|
__publicField$6(this, "signedUrl");
|
2706
2768
|
/**
|
2707
|
-
* Attributes of
|
2769
|
+
* Attributes of the file.
|
2708
2770
|
*/
|
2709
2771
|
__publicField$6(this, "attributes");
|
2710
|
-
this.
|
2772
|
+
this.id = file.id;
|
2773
|
+
this.name = file.name || "";
|
2711
2774
|
this.mediaType = file.mediaType || "application/octet-stream";
|
2712
2775
|
this.base64Content = file.base64Content;
|
2713
|
-
this.enablePublicUrl = file.enablePublicUrl;
|
2714
|
-
this.signedUrlTimeout = file.signedUrlTimeout;
|
2715
|
-
this.size = file.size;
|
2716
|
-
this.version = file.version;
|
2717
|
-
this.url = file.url;
|
2776
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2777
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2778
|
+
this.size = file.size ?? 0;
|
2779
|
+
this.version = file.version ?? 1;
|
2780
|
+
this.url = file.url || "";
|
2718
2781
|
this.signedUrl = file.signedUrl;
|
2719
|
-
this.attributes = file.attributes;
|
2782
|
+
this.attributes = file.attributes || {};
|
2720
2783
|
}
|
2721
2784
|
static fromBuffer(buffer, options = {}) {
|
2722
2785
|
const base64Content = buffer.toString("base64");
|
@@ -2768,8 +2831,12 @@ class XataFile {
|
|
2768
2831
|
if (!this.base64Content) {
|
2769
2832
|
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2770
2833
|
}
|
2771
|
-
const
|
2772
|
-
|
2834
|
+
const binary = atob(this.base64Content);
|
2835
|
+
const uint8Array = new Uint8Array(binary.length);
|
2836
|
+
for (let i = 0; i < binary.length; i++) {
|
2837
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2838
|
+
}
|
2839
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2773
2840
|
}
|
2774
2841
|
static fromString(string, options = {}) {
|
2775
2842
|
const base64Content = btoa(string);
|
@@ -2792,8 +2859,10 @@ class XataFile {
|
|
2792
2859
|
}
|
2793
2860
|
transform(...options) {
|
2794
2861
|
return {
|
2795
|
-
url: transformImage(this.url, options),
|
2796
|
-
signedUrl: transformImage(this.signedUrl, options)
|
2862
|
+
url: transformImage(this.url, ...options),
|
2863
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2864
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2865
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2797
2866
|
};
|
2798
2867
|
}
|
2799
2868
|
}
|
@@ -2801,7 +2870,15 @@ const parseInputFileEntry = async (entry) => {
|
|
2801
2870
|
if (!isDefined(entry))
|
2802
2871
|
return null;
|
2803
2872
|
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2804
|
-
return compactObject({
|
2873
|
+
return compactObject({
|
2874
|
+
id,
|
2875
|
+
// Name cannot be an empty string in our API
|
2876
|
+
name: name ? name : void 0,
|
2877
|
+
mediaType,
|
2878
|
+
base64Content,
|
2879
|
+
enablePublicUrl,
|
2880
|
+
signedUrlTimeout
|
2881
|
+
});
|
2805
2882
|
};
|
2806
2883
|
|
2807
2884
|
function cleanFilter(filter) {
|
@@ -2831,6 +2908,25 @@ function cleanFilter(filter) {
|
|
2831
2908
|
return Object.keys(values).length > 0 ? values : void 0;
|
2832
2909
|
}
|
2833
2910
|
|
2911
|
+
function stringifyJson(value) {
|
2912
|
+
if (!isDefined(value))
|
2913
|
+
return value;
|
2914
|
+
if (isString(value))
|
2915
|
+
return value;
|
2916
|
+
try {
|
2917
|
+
return JSON.stringify(value);
|
2918
|
+
} catch (e) {
|
2919
|
+
return value;
|
2920
|
+
}
|
2921
|
+
}
|
2922
|
+
function parseJson(value) {
|
2923
|
+
try {
|
2924
|
+
return JSON.parse(value);
|
2925
|
+
} catch (e) {
|
2926
|
+
return value;
|
2927
|
+
}
|
2928
|
+
}
|
2929
|
+
|
2834
2930
|
var __defProp$5 = Object.defineProperty;
|
2835
2931
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2836
2932
|
var __publicField$5 = (obj, key, value) => {
|
@@ -3289,7 +3385,8 @@ const RecordColumnTypes = [
|
|
3289
3385
|
"datetime",
|
3290
3386
|
"vector",
|
3291
3387
|
"file[]",
|
3292
|
-
"file"
|
3388
|
+
"file",
|
3389
|
+
"json"
|
3293
3390
|
];
|
3294
3391
|
function isIdentifiable(x) {
|
3295
3392
|
return isObject(x) && isString(x?.id);
|
@@ -3300,6 +3397,24 @@ function isXataRecord(x) {
|
|
3300
3397
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
3301
3398
|
}
|
3302
3399
|
|
3400
|
+
function isValidExpandedColumn(column) {
|
3401
|
+
return isObject(column) && isString(column.name);
|
3402
|
+
}
|
3403
|
+
function isValidSelectableColumns(columns) {
|
3404
|
+
if (!Array.isArray(columns)) {
|
3405
|
+
return false;
|
3406
|
+
}
|
3407
|
+
return columns.every((column) => {
|
3408
|
+
if (typeof column === "string") {
|
3409
|
+
return true;
|
3410
|
+
}
|
3411
|
+
if (typeof column === "object") {
|
3412
|
+
return isValidExpandedColumn(column);
|
3413
|
+
}
|
3414
|
+
return false;
|
3415
|
+
});
|
3416
|
+
}
|
3417
|
+
|
3303
3418
|
function isSortFilterString(value) {
|
3304
3419
|
return isString(value);
|
3305
3420
|
}
|
@@ -3400,24 +3515,24 @@ class RestRepository extends Query {
|
|
3400
3515
|
if (a.length === 0)
|
3401
3516
|
return [];
|
3402
3517
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3403
|
-
const columns =
|
3518
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3404
3519
|
const result = await this.read(ids, columns);
|
3405
3520
|
return result;
|
3406
3521
|
}
|
3407
3522
|
if (isString(a) && isObject(b)) {
|
3408
3523
|
if (a === "")
|
3409
3524
|
throw new Error("The id can't be empty");
|
3410
|
-
const columns =
|
3525
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3411
3526
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3412
3527
|
}
|
3413
3528
|
if (isObject(a) && isString(a.id)) {
|
3414
3529
|
if (a.id === "")
|
3415
3530
|
throw new Error("The id can't be empty");
|
3416
|
-
const columns =
|
3531
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3417
3532
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3418
3533
|
}
|
3419
3534
|
if (isObject(a)) {
|
3420
|
-
const columns =
|
3535
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3421
3536
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
3422
3537
|
}
|
3423
3538
|
throw new Error("Invalid arguments for create method");
|
@@ -3425,7 +3540,7 @@ class RestRepository extends Query {
|
|
3425
3540
|
}
|
3426
3541
|
async read(a, b) {
|
3427
3542
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
3428
|
-
const columns =
|
3543
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3429
3544
|
if (Array.isArray(a)) {
|
3430
3545
|
if (a.length === 0)
|
3431
3546
|
return [];
|
@@ -3452,7 +3567,13 @@ class RestRepository extends Query {
|
|
3452
3567
|
...__privateGet$4(this, _getFetchProps).call(this)
|
3453
3568
|
});
|
3454
3569
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3455
|
-
return initObject(
|
3570
|
+
return initObject(
|
3571
|
+
__privateGet$4(this, _db),
|
3572
|
+
schemaTables,
|
3573
|
+
__privateGet$4(this, _table),
|
3574
|
+
response,
|
3575
|
+
columns
|
3576
|
+
);
|
3456
3577
|
} catch (e) {
|
3457
3578
|
if (isObject(e) && e.status === 404) {
|
3458
3579
|
return null;
|
@@ -3494,17 +3615,17 @@ class RestRepository extends Query {
|
|
3494
3615
|
ifVersion,
|
3495
3616
|
upsert: false
|
3496
3617
|
});
|
3497
|
-
const columns =
|
3618
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3498
3619
|
const result = await this.read(a, columns);
|
3499
3620
|
return result;
|
3500
3621
|
}
|
3501
3622
|
try {
|
3502
3623
|
if (isString(a) && isObject(b)) {
|
3503
|
-
const columns =
|
3624
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3504
3625
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3505
3626
|
}
|
3506
3627
|
if (isObject(a) && isString(a.id)) {
|
3507
|
-
const columns =
|
3628
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3508
3629
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3509
3630
|
}
|
3510
3631
|
} catch (error) {
|
@@ -3544,20 +3665,20 @@ class RestRepository extends Query {
|
|
3544
3665
|
ifVersion,
|
3545
3666
|
upsert: true
|
3546
3667
|
});
|
3547
|
-
const columns =
|
3668
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3548
3669
|
const result = await this.read(a, columns);
|
3549
3670
|
return result;
|
3550
3671
|
}
|
3551
3672
|
if (isString(a) && isObject(b)) {
|
3552
3673
|
if (a === "")
|
3553
3674
|
throw new Error("The id can't be empty");
|
3554
|
-
const columns =
|
3675
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3555
3676
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3556
3677
|
}
|
3557
3678
|
if (isObject(a) && isString(a.id)) {
|
3558
3679
|
if (a.id === "")
|
3559
3680
|
throw new Error("The id can't be empty");
|
3560
|
-
const columns =
|
3681
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3561
3682
|
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3562
3683
|
}
|
3563
3684
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3576,20 +3697,20 @@ class RestRepository extends Query {
|
|
3576
3697
|
if (a.length === 0)
|
3577
3698
|
return [];
|
3578
3699
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
3579
|
-
const columns =
|
3700
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3580
3701
|
const result = await this.read(ids, columns);
|
3581
3702
|
return result;
|
3582
3703
|
}
|
3583
3704
|
if (isString(a) && isObject(b)) {
|
3584
3705
|
if (a === "")
|
3585
3706
|
throw new Error("The id can't be empty");
|
3586
|
-
const columns =
|
3707
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3587
3708
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3588
3709
|
}
|
3589
3710
|
if (isObject(a) && isString(a.id)) {
|
3590
3711
|
if (a.id === "")
|
3591
3712
|
throw new Error("The id can't be empty");
|
3592
|
-
const columns =
|
3713
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3593
3714
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3594
3715
|
}
|
3595
3716
|
if (!isDefined(a) && isObject(b)) {
|
@@ -3613,7 +3734,7 @@ class RestRepository extends Query {
|
|
3613
3734
|
return o.id;
|
3614
3735
|
throw new Error("Invalid arguments for delete method");
|
3615
3736
|
});
|
3616
|
-
const columns =
|
3737
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3617
3738
|
const result = await this.read(a, columns);
|
3618
3739
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3619
3740
|
return result;
|
@@ -3732,7 +3853,13 @@ class RestRepository extends Query {
|
|
3732
3853
|
});
|
3733
3854
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3734
3855
|
const records = objects.map(
|
3735
|
-
(record) => initObject(
|
3856
|
+
(record) => initObject(
|
3857
|
+
__privateGet$4(this, _db),
|
3858
|
+
schemaTables,
|
3859
|
+
__privateGet$4(this, _table),
|
3860
|
+
record,
|
3861
|
+
data.columns ?? ["*"]
|
3862
|
+
)
|
3736
3863
|
);
|
3737
3864
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
3738
3865
|
return new Page(query, meta, records);
|
@@ -4038,6 +4165,9 @@ transformObjectToApi_fn = async function(object) {
|
|
4038
4165
|
case "file[]":
|
4039
4166
|
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4040
4167
|
break;
|
4168
|
+
case "json":
|
4169
|
+
result[key] = stringifyJson(value);
|
4170
|
+
break;
|
4041
4171
|
default:
|
4042
4172
|
result[key] = value;
|
4043
4173
|
}
|
@@ -4081,13 +4211,19 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4081
4211
|
if (item === column.name) {
|
4082
4212
|
return [...acc, "*"];
|
4083
4213
|
}
|
4084
|
-
if (item.startsWith(`${column.name}.`)) {
|
4214
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
4085
4215
|
const [, ...path] = item.split(".");
|
4086
4216
|
return [...acc, path.join(".")];
|
4087
4217
|
}
|
4088
4218
|
return acc;
|
4089
4219
|
}, []);
|
4090
|
-
data[column.name] = initObject(
|
4220
|
+
data[column.name] = initObject(
|
4221
|
+
db,
|
4222
|
+
schemaTables,
|
4223
|
+
linkTable,
|
4224
|
+
value,
|
4225
|
+
selectedLinkColumns
|
4226
|
+
);
|
4091
4227
|
} else {
|
4092
4228
|
data[column.name] = null;
|
4093
4229
|
}
|
@@ -4099,6 +4235,9 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4099
4235
|
case "file[]":
|
4100
4236
|
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4101
4237
|
break;
|
4238
|
+
case "json":
|
4239
|
+
data[column.name] = parseJson(value);
|
4240
|
+
break;
|
4102
4241
|
default:
|
4103
4242
|
data[column.name] = value ?? null;
|
4104
4243
|
if (column.notNull === true && value === null) {
|
@@ -4114,12 +4253,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
4114
4253
|
return db[table].read(record["id"], columns2);
|
4115
4254
|
};
|
4116
4255
|
record.update = function(data2, b, c) {
|
4117
|
-
const columns2 =
|
4256
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4118
4257
|
const ifVersion = parseIfVersion(b, c);
|
4119
4258
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
4120
4259
|
};
|
4121
4260
|
record.replace = function(data2, b, c) {
|
4122
|
-
const columns2 =
|
4261
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
4123
4262
|
const ifVersion = parseIfVersion(b, c);
|
4124
4263
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4125
4264
|
};
|
@@ -4152,7 +4291,7 @@ function extractId(value) {
|
|
4152
4291
|
function isValidColumn(columns, column) {
|
4153
4292
|
if (columns.includes("*"))
|
4154
4293
|
return true;
|
4155
|
-
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
4294
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
4156
4295
|
}
|
4157
4296
|
function parseIfVersion(...args) {
|
4158
4297
|
for (const arg of args) {
|
@@ -4375,6 +4514,78 @@ getSchemaTables_fn = async function(pluginOptions) {
|
|
4375
4514
|
return schema.tables;
|
4376
4515
|
};
|
4377
4516
|
|
4517
|
+
function escapeElement(elementRepresentation) {
|
4518
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4519
|
+
return '"' + escaped + '"';
|
4520
|
+
}
|
4521
|
+
function arrayString(val) {
|
4522
|
+
let result = "{";
|
4523
|
+
for (let i = 0; i < val.length; i++) {
|
4524
|
+
if (i > 0) {
|
4525
|
+
result = result + ",";
|
4526
|
+
}
|
4527
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4528
|
+
result = result + "NULL";
|
4529
|
+
} else if (Array.isArray(val[i])) {
|
4530
|
+
result = result + arrayString(val[i]);
|
4531
|
+
} else if (val[i] instanceof Buffer) {
|
4532
|
+
result += "\\\\x" + val[i].toString("hex");
|
4533
|
+
} else {
|
4534
|
+
result += escapeElement(prepareValue(val[i]));
|
4535
|
+
}
|
4536
|
+
}
|
4537
|
+
result = result + "}";
|
4538
|
+
return result;
|
4539
|
+
}
|
4540
|
+
function prepareValue(value) {
|
4541
|
+
if (!isDefined(value))
|
4542
|
+
return null;
|
4543
|
+
if (value instanceof Date) {
|
4544
|
+
return value.toISOString();
|
4545
|
+
}
|
4546
|
+
if (Array.isArray(value)) {
|
4547
|
+
return arrayString(value);
|
4548
|
+
}
|
4549
|
+
if (isObject(value)) {
|
4550
|
+
return JSON.stringify(value);
|
4551
|
+
}
|
4552
|
+
try {
|
4553
|
+
return value.toString();
|
4554
|
+
} catch (e) {
|
4555
|
+
return value;
|
4556
|
+
}
|
4557
|
+
}
|
4558
|
+
function prepareParams(param1, param2) {
|
4559
|
+
if (isString(param1)) {
|
4560
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4561
|
+
}
|
4562
|
+
if (isStringArray(param1)) {
|
4563
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4564
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4565
|
+
}, "");
|
4566
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4567
|
+
}
|
4568
|
+
if (isObject(param1)) {
|
4569
|
+
const { statement, params, consistency } = param1;
|
4570
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4571
|
+
}
|
4572
|
+
throw new Error("Invalid query");
|
4573
|
+
}
|
4574
|
+
|
4575
|
+
class SQLPlugin extends XataPlugin {
|
4576
|
+
build(pluginOptions) {
|
4577
|
+
return async (param1, ...param2) => {
|
4578
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4579
|
+
const { records, warning } = await sqlQuery({
|
4580
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4581
|
+
body: { statement, params, consistency },
|
4582
|
+
...pluginOptions
|
4583
|
+
});
|
4584
|
+
return { records, warning };
|
4585
|
+
};
|
4586
|
+
}
|
4587
|
+
}
|
4588
|
+
|
4378
4589
|
class TransactionPlugin extends XataPlugin {
|
4379
4590
|
build(pluginOptions) {
|
4380
4591
|
return {
|
@@ -4428,6 +4639,7 @@ const buildClient = (plugins) => {
|
|
4428
4639
|
__publicField$2(this, "db");
|
4429
4640
|
__publicField$2(this, "search");
|
4430
4641
|
__publicField$2(this, "transactions");
|
4642
|
+
__publicField$2(this, "sql");
|
4431
4643
|
__publicField$2(this, "files");
|
4432
4644
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
4433
4645
|
__privateSet(this, _options, safeOptions);
|
@@ -4439,10 +4651,12 @@ const buildClient = (plugins) => {
|
|
4439
4651
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
4440
4652
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4441
4653
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4654
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4442
4655
|
const files = new FilesPlugin().build(pluginOptions);
|
4443
4656
|
this.db = db;
|
4444
4657
|
this.search = search;
|
4445
4658
|
this.transactions = transactions;
|
4659
|
+
this.sql = sql;
|
4446
4660
|
this.files = files;
|
4447
4661
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
4448
4662
|
if (namespace === void 0)
|
@@ -4642,5 +4856,5 @@ class XataError extends Error {
|
|
4642
4856
|
}
|
4643
4857
|
}
|
4644
4858
|
|
4645
|
-
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, 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, getAPIKey, getAuthorizationCode, 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, getUserOAuthClients, 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, transformImage, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
4859
|
+
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, 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, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getAuthorizationCode, 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, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, 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, transformImage, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
4646
4860
|
//# sourceMappingURL=index.mjs.map
|