@xata.io/client 0.0.0-alpha.vfde9dcf → 0.0.0-alpha.vfef462e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +120 -0
- package/README.md +271 -1
- package/Usage.md +428 -0
- package/dist/index.cjs +423 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +685 -150
- package/dist/index.mjs +404 -283
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -4
package/dist/index.mjs
CHANGED
@@ -13,43 +13,95 @@ function isDefined(value) {
|
|
13
13
|
function isString(value) {
|
14
14
|
return isDefined(value) && typeof value === "string";
|
15
15
|
}
|
16
|
+
function isStringArray(value) {
|
17
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
18
|
+
}
|
16
19
|
function toBase64(value) {
|
17
20
|
try {
|
18
21
|
return btoa(value);
|
19
22
|
} catch (err) {
|
20
|
-
|
23
|
+
const buf = Buffer;
|
24
|
+
return buf.from(value).toString("base64");
|
21
25
|
}
|
22
26
|
}
|
23
27
|
|
24
|
-
function
|
28
|
+
function getEnvironment() {
|
25
29
|
try {
|
26
|
-
if (isObject(process) &&
|
27
|
-
return
|
30
|
+
if (isObject(process) && isObject(process.env)) {
|
31
|
+
return {
|
32
|
+
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
33
|
+
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
34
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
35
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
|
36
|
+
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
37
|
+
};
|
28
38
|
}
|
29
39
|
} catch (err) {
|
30
40
|
}
|
31
41
|
try {
|
32
|
-
if (isObject(Deno) &&
|
33
|
-
return
|
42
|
+
if (isObject(Deno) && isObject(Deno.env)) {
|
43
|
+
return {
|
44
|
+
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
45
|
+
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
46
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
47
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
|
48
|
+
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
49
|
+
};
|
34
50
|
}
|
35
51
|
} catch (err) {
|
36
52
|
}
|
53
|
+
return {
|
54
|
+
apiKey: getGlobalApiKey(),
|
55
|
+
databaseURL: getGlobalDatabaseURL(),
|
56
|
+
branch: getGlobalBranch(),
|
57
|
+
envBranch: void 0,
|
58
|
+
fallbackBranch: getGlobalFallbackBranch()
|
59
|
+
};
|
60
|
+
}
|
61
|
+
function getGlobalApiKey() {
|
62
|
+
try {
|
63
|
+
return XATA_API_KEY;
|
64
|
+
} catch (err) {
|
65
|
+
return void 0;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
function getGlobalDatabaseURL() {
|
69
|
+
try {
|
70
|
+
return XATA_DATABASE_URL;
|
71
|
+
} catch (err) {
|
72
|
+
return void 0;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
function getGlobalBranch() {
|
76
|
+
try {
|
77
|
+
return XATA_BRANCH;
|
78
|
+
} catch (err) {
|
79
|
+
return void 0;
|
80
|
+
}
|
81
|
+
}
|
82
|
+
function getGlobalFallbackBranch() {
|
83
|
+
try {
|
84
|
+
return XATA_FALLBACK_BRANCH;
|
85
|
+
} catch (err) {
|
86
|
+
return void 0;
|
87
|
+
}
|
37
88
|
}
|
38
89
|
async function getGitBranch() {
|
90
|
+
const cmd = ["git", "branch", "--show-current"];
|
91
|
+
const fullCmd = cmd.join(" ");
|
92
|
+
const nodeModule = ["child", "process"].join("_");
|
93
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
39
94
|
try {
|
40
95
|
if (typeof require === "function") {
|
41
|
-
|
42
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
96
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
43
97
|
}
|
98
|
+
const { execSync } = await import(nodeModule);
|
99
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
44
100
|
} catch (err) {
|
45
101
|
}
|
46
102
|
try {
|
47
103
|
if (isObject(Deno)) {
|
48
|
-
const process2 = Deno.run({
|
49
|
-
cmd: ["git", "branch", "--show-current"],
|
50
|
-
stdout: "piped",
|
51
|
-
stderr: "piped"
|
52
|
-
});
|
104
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
53
105
|
return new TextDecoder().decode(await process2.output()).trim();
|
54
106
|
}
|
55
107
|
} catch (err) {
|
@@ -58,7 +110,8 @@ async function getGitBranch() {
|
|
58
110
|
|
59
111
|
function getAPIKey() {
|
60
112
|
try {
|
61
|
-
|
113
|
+
const { apiKey } = getEnvironment();
|
114
|
+
return apiKey;
|
62
115
|
} catch (err) {
|
63
116
|
return void 0;
|
64
117
|
}
|
@@ -68,21 +121,35 @@ function getFetchImplementation(userFetch) {
|
|
68
121
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
69
122
|
const fetchImpl = userFetch ?? globalFetch;
|
70
123
|
if (!fetchImpl) {
|
71
|
-
throw new Error(
|
124
|
+
throw new Error(
|
125
|
+
`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
|
126
|
+
);
|
72
127
|
}
|
73
128
|
return fetchImpl;
|
74
129
|
}
|
75
130
|
|
76
|
-
|
77
|
-
|
131
|
+
const VERSION = "0.0.0-alpha.vfef462e";
|
132
|
+
|
133
|
+
class ErrorWithCause extends Error {
|
134
|
+
constructor(message, options) {
|
135
|
+
super(message, options);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
class FetcherError extends ErrorWithCause {
|
139
|
+
constructor(status, data, requestId) {
|
78
140
|
super(getMessage(data));
|
79
141
|
this.status = status;
|
80
142
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
143
|
+
this.requestId = requestId;
|
81
144
|
if (data instanceof Error) {
|
82
145
|
this.stack = data.stack;
|
83
146
|
this.cause = data.cause;
|
84
147
|
}
|
85
148
|
}
|
149
|
+
toString() {
|
150
|
+
const error = super.toString();
|
151
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
152
|
+
}
|
86
153
|
}
|
87
154
|
function isBulkError(error) {
|
88
155
|
return isObject(error) && Array.isArray(error.errors);
|
@@ -105,7 +172,12 @@ function getMessage(data) {
|
|
105
172
|
}
|
106
173
|
|
107
174
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
108
|
-
const
|
175
|
+
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
176
|
+
if (value === void 0 || value === null)
|
177
|
+
return acc;
|
178
|
+
return { ...acc, [key]: value };
|
179
|
+
}, {});
|
180
|
+
const query = new URLSearchParams(cleanQueryParams).toString();
|
109
181
|
const queryString = query.length > 0 ? `?${query}` : "";
|
110
182
|
return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
|
111
183
|
};
|
@@ -145,6 +217,7 @@ async function fetch$1({
|
|
145
217
|
body: body ? JSON.stringify(body) : void 0,
|
146
218
|
headers: {
|
147
219
|
"Content-Type": "application/json",
|
220
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
148
221
|
...headers,
|
149
222
|
...hostHeader(fullUrl),
|
150
223
|
Authorization: `Bearer ${apiKey}`
|
@@ -153,14 +226,15 @@ async function fetch$1({
|
|
153
226
|
if (response.status === 204) {
|
154
227
|
return {};
|
155
228
|
}
|
229
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
156
230
|
try {
|
157
231
|
const jsonResponse = await response.json();
|
158
232
|
if (response.ok) {
|
159
233
|
return jsonResponse;
|
160
234
|
}
|
161
|
-
throw new FetcherError(response.status, jsonResponse);
|
235
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
162
236
|
} catch (error) {
|
163
|
-
throw new FetcherError(response.status, error);
|
237
|
+
throw new FetcherError(response.status, error, requestId);
|
164
238
|
}
|
165
239
|
}
|
166
240
|
|
@@ -219,6 +293,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
219
293
|
...variables
|
220
294
|
});
|
221
295
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
296
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
222
297
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
223
298
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
224
299
|
method: "delete",
|
@@ -267,11 +342,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
267
342
|
method: "get",
|
268
343
|
...variables
|
269
344
|
});
|
270
|
-
const createBranch = (variables) => fetch$1({
|
271
|
-
url: "/db/{dbBranchName}",
|
272
|
-
method: "put",
|
273
|
-
...variables
|
274
|
-
});
|
345
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
275
346
|
const deleteBranch = (variables) => fetch$1({
|
276
347
|
url: "/db/{dbBranchName}",
|
277
348
|
method: "delete",
|
@@ -345,11 +416,7 @@ const updateColumn = (variables) => fetch$1({
|
|
345
416
|
method: "patch",
|
346
417
|
...variables
|
347
418
|
});
|
348
|
-
const insertRecord = (variables) => fetch$1({
|
349
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
350
|
-
method: "post",
|
351
|
-
...variables
|
352
|
-
});
|
419
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
353
420
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
354
421
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
355
422
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -391,6 +458,7 @@ const operationsByTag = {
|
|
391
458
|
updateWorkspaceMemberRole,
|
392
459
|
removeWorkspaceMember,
|
393
460
|
inviteWorkspaceMember,
|
461
|
+
updateWorkspaceMemberInvite,
|
394
462
|
cancelWorkspaceMemberInvite,
|
395
463
|
resendWorkspaceMemberInvite,
|
396
464
|
acceptWorkspaceMemberInvite
|
@@ -480,7 +548,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
480
548
|
throw TypeError("Cannot add the same private member more than once");
|
481
549
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
482
550
|
};
|
483
|
-
var __privateSet$
|
551
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
484
552
|
__accessCheck$7(obj, member, "write to private field");
|
485
553
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
486
554
|
return value;
|
@@ -495,7 +563,7 @@ class XataApiClient {
|
|
495
563
|
if (!apiKey) {
|
496
564
|
throw new Error("Could not resolve a valid apiKey");
|
497
565
|
}
|
498
|
-
__privateSet$
|
566
|
+
__privateSet$7(this, _extraProps, {
|
499
567
|
apiUrl: getHostUrl(provider, "main"),
|
500
568
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
501
569
|
fetchImpl: getFetchImplementation(options.fetch),
|
@@ -622,6 +690,13 @@ class WorkspaceApi {
|
|
622
690
|
...this.extraProps
|
623
691
|
});
|
624
692
|
}
|
693
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
694
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
695
|
+
pathParams: { workspaceId, inviteId },
|
696
|
+
body: { role },
|
697
|
+
...this.extraProps
|
698
|
+
});
|
699
|
+
}
|
625
700
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
626
701
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
627
702
|
pathParams: { workspaceId, inviteId },
|
@@ -684,10 +759,10 @@ class DatabaseApi {
|
|
684
759
|
...this.extraProps
|
685
760
|
});
|
686
761
|
}
|
687
|
-
resolveBranch(workspace, dbName, gitBranch) {
|
762
|
+
resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
|
688
763
|
return operationsByTag.database.resolveBranch({
|
689
764
|
pathParams: { workspace, dbName },
|
690
|
-
queryParams: { gitBranch },
|
765
|
+
queryParams: { gitBranch, fallbackBranch },
|
691
766
|
...this.extraProps
|
692
767
|
});
|
693
768
|
}
|
@@ -836,9 +911,10 @@ class RecordsApi {
|
|
836
911
|
constructor(extraProps) {
|
837
912
|
this.extraProps = extraProps;
|
838
913
|
}
|
839
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
914
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
840
915
|
return operationsByTag.records.insertRecord({
|
841
916
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
917
|
+
queryParams: options,
|
842
918
|
body: record,
|
843
919
|
...this.extraProps
|
844
920
|
});
|
@@ -867,21 +943,24 @@ class RecordsApi {
|
|
867
943
|
...this.extraProps
|
868
944
|
});
|
869
945
|
}
|
870
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
946
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
871
947
|
return operationsByTag.records.deleteRecord({
|
872
948
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
949
|
+
queryParams: options,
|
873
950
|
...this.extraProps
|
874
951
|
});
|
875
952
|
}
|
876
953
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
877
954
|
return operationsByTag.records.getRecord({
|
878
955
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
956
|
+
queryParams: options,
|
879
957
|
...this.extraProps
|
880
958
|
});
|
881
959
|
}
|
882
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
960
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
883
961
|
return operationsByTag.records.bulkInsertTableRecords({
|
884
962
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
963
|
+
queryParams: options,
|
885
964
|
body: { records },
|
886
965
|
...this.extraProps
|
887
966
|
});
|
@@ -932,18 +1011,18 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
932
1011
|
throw TypeError("Cannot add the same private member more than once");
|
933
1012
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
934
1013
|
};
|
935
|
-
var __privateSet$
|
1014
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
936
1015
|
__accessCheck$6(obj, member, "write to private field");
|
937
1016
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
938
1017
|
return value;
|
939
1018
|
};
|
940
|
-
var _query;
|
1019
|
+
var _query, _page;
|
941
1020
|
class Page {
|
942
1021
|
constructor(query, meta, records = []) {
|
943
1022
|
__privateAdd$6(this, _query, void 0);
|
944
|
-
__privateSet$
|
1023
|
+
__privateSet$6(this, _query, query);
|
945
1024
|
this.meta = meta;
|
946
|
-
this.records = records;
|
1025
|
+
this.records = new RecordArray(this, records);
|
947
1026
|
}
|
948
1027
|
async nextPage(size, offset) {
|
949
1028
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
@@ -963,12 +1042,56 @@ class Page {
|
|
963
1042
|
}
|
964
1043
|
_query = new WeakMap();
|
965
1044
|
const PAGINATION_MAX_SIZE = 200;
|
966
|
-
const PAGINATION_DEFAULT_SIZE =
|
1045
|
+
const PAGINATION_DEFAULT_SIZE = 20;
|
967
1046
|
const PAGINATION_MAX_OFFSET = 800;
|
968
1047
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
969
1048
|
function isCursorPaginationOptions(options) {
|
970
1049
|
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
971
1050
|
}
|
1051
|
+
const _RecordArray = class extends Array {
|
1052
|
+
constructor(...args) {
|
1053
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
1054
|
+
__privateAdd$6(this, _page, void 0);
|
1055
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1056
|
+
}
|
1057
|
+
static parseConstructorParams(...args) {
|
1058
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1059
|
+
return new Array(args[0]);
|
1060
|
+
}
|
1061
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
1062
|
+
const result = args[1] ?? args[0].records ?? [];
|
1063
|
+
return new Array(...result);
|
1064
|
+
}
|
1065
|
+
return new Array(...args);
|
1066
|
+
}
|
1067
|
+
toArray() {
|
1068
|
+
return new Array(...this);
|
1069
|
+
}
|
1070
|
+
map(callbackfn, thisArg) {
|
1071
|
+
return this.toArray().map(callbackfn, thisArg);
|
1072
|
+
}
|
1073
|
+
async nextPage(size, offset) {
|
1074
|
+
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1075
|
+
return new _RecordArray(newPage);
|
1076
|
+
}
|
1077
|
+
async previousPage(size, offset) {
|
1078
|
+
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1079
|
+
return new _RecordArray(newPage);
|
1080
|
+
}
|
1081
|
+
async firstPage(size, offset) {
|
1082
|
+
const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
|
1083
|
+
return new _RecordArray(newPage);
|
1084
|
+
}
|
1085
|
+
async lastPage(size, offset) {
|
1086
|
+
const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
|
1087
|
+
return new _RecordArray(newPage);
|
1088
|
+
}
|
1089
|
+
hasNextPage() {
|
1090
|
+
return __privateGet$6(this, _page).meta.page.more;
|
1091
|
+
}
|
1092
|
+
};
|
1093
|
+
let RecordArray = _RecordArray;
|
1094
|
+
_page = new WeakMap();
|
972
1095
|
|
973
1096
|
var __accessCheck$5 = (obj, member, msg) => {
|
974
1097
|
if (!member.has(obj))
|
@@ -983,25 +1106,26 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
983
1106
|
throw TypeError("Cannot add the same private member more than once");
|
984
1107
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
985
1108
|
};
|
986
|
-
var __privateSet$
|
1109
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
987
1110
|
__accessCheck$5(obj, member, "write to private field");
|
988
1111
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
989
1112
|
return value;
|
990
1113
|
};
|
991
1114
|
var _table$1, _repository, _data;
|
992
1115
|
const _Query = class {
|
993
|
-
constructor(repository, table, data,
|
1116
|
+
constructor(repository, table, data, rawParent) {
|
994
1117
|
__privateAdd$5(this, _table$1, void 0);
|
995
1118
|
__privateAdd$5(this, _repository, void 0);
|
996
1119
|
__privateAdd$5(this, _data, { filter: {} });
|
997
1120
|
this.meta = { page: { cursor: "start", more: true } };
|
998
|
-
this.records = [];
|
999
|
-
__privateSet$
|
1121
|
+
this.records = new RecordArray(this, []);
|
1122
|
+
__privateSet$5(this, _table$1, table);
|
1000
1123
|
if (repository) {
|
1001
|
-
__privateSet$
|
1124
|
+
__privateSet$5(this, _repository, repository);
|
1002
1125
|
} else {
|
1003
|
-
__privateSet$
|
1126
|
+
__privateSet$5(this, _repository, this);
|
1004
1127
|
}
|
1128
|
+
const parent = cleanParent(data, rawParent);
|
1005
1129
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
1006
1130
|
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
1007
1131
|
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
@@ -1060,7 +1184,12 @@ const _Query = class {
|
|
1060
1184
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1061
1185
|
}
|
1062
1186
|
select(columns) {
|
1063
|
-
return new _Query(
|
1187
|
+
return new _Query(
|
1188
|
+
__privateGet$5(this, _repository),
|
1189
|
+
__privateGet$5(this, _table$1),
|
1190
|
+
{ columns },
|
1191
|
+
__privateGet$5(this, _data)
|
1192
|
+
);
|
1064
1193
|
}
|
1065
1194
|
getPaginated(options = {}) {
|
1066
1195
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1083,8 +1212,11 @@ const _Query = class {
|
|
1083
1212
|
}
|
1084
1213
|
}
|
1085
1214
|
async getMany(options = {}) {
|
1086
|
-
const
|
1087
|
-
|
1215
|
+
const page = await this.getPaginated(options);
|
1216
|
+
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1217
|
+
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1218
|
+
}
|
1219
|
+
return page.records;
|
1088
1220
|
}
|
1089
1221
|
async getAll(options = {}) {
|
1090
1222
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1121,12 +1253,20 @@ let Query = _Query;
|
|
1121
1253
|
_table$1 = new WeakMap();
|
1122
1254
|
_repository = new WeakMap();
|
1123
1255
|
_data = new WeakMap();
|
1256
|
+
function cleanParent(data, parent) {
|
1257
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
1258
|
+
return { ...parent, sorting: void 0, filter: void 0 };
|
1259
|
+
}
|
1260
|
+
return parent;
|
1261
|
+
}
|
1124
1262
|
|
1125
1263
|
function isIdentifiable(x) {
|
1126
1264
|
return isObject(x) && isString(x?.id);
|
1127
1265
|
}
|
1128
1266
|
function isXataRecord(x) {
|
1129
|
-
|
1267
|
+
const record = x;
|
1268
|
+
const metadata = record?.getMetadata();
|
1269
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
1130
1270
|
}
|
1131
1271
|
|
1132
1272
|
function isSortFilterString(value) {
|
@@ -1165,7 +1305,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1165
1305
|
throw TypeError("Cannot add the same private member more than once");
|
1166
1306
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1167
1307
|
};
|
1168
|
-
var __privateSet$
|
1308
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
1169
1309
|
__accessCheck$4(obj, member, "write to private field");
|
1170
1310
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1171
1311
|
return value;
|
@@ -1174,7 +1314,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1174
1314
|
__accessCheck$4(obj, member, "access private method");
|
1175
1315
|
return method;
|
1176
1316
|
};
|
1177
|
-
var _table, _getFetchProps, _cache,
|
1317
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
1178
1318
|
class Repository extends Query {
|
1179
1319
|
}
|
1180
1320
|
class RestRepository extends Query {
|
@@ -1186,111 +1326,122 @@ class RestRepository extends Query {
|
|
1186
1326
|
__privateAdd$4(this, _updateRecordWithID);
|
1187
1327
|
__privateAdd$4(this, _upsertRecordWithID);
|
1188
1328
|
__privateAdd$4(this, _deleteRecord);
|
1189
|
-
__privateAdd$4(this, _invalidateCache);
|
1190
|
-
__privateAdd$4(this, _setCacheRecord);
|
1191
|
-
__privateAdd$4(this, _getCacheRecord);
|
1192
1329
|
__privateAdd$4(this, _setCacheQuery);
|
1193
1330
|
__privateAdd$4(this, _getCacheQuery);
|
1194
|
-
__privateAdd$4(this,
|
1331
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
1195
1332
|
__privateAdd$4(this, _table, void 0);
|
1196
1333
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1334
|
+
__privateAdd$4(this, _db, void 0);
|
1197
1335
|
__privateAdd$4(this, _cache, void 0);
|
1198
|
-
__privateAdd$4(this,
|
1199
|
-
__privateSet$
|
1200
|
-
__privateSet$
|
1201
|
-
this
|
1202
|
-
__privateSet$
|
1203
|
-
|
1204
|
-
|
1336
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
1337
|
+
__privateSet$4(this, _table, options.table);
|
1338
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1339
|
+
__privateSet$4(this, _db, options.db);
|
1340
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1341
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1342
|
+
}
|
1343
|
+
async create(a, b, c) {
|
1205
1344
|
if (Array.isArray(a)) {
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1345
|
+
if (a.length === 0)
|
1346
|
+
return [];
|
1347
|
+
const columns = isStringArray(b) ? b : void 0;
|
1348
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1209
1349
|
}
|
1210
1350
|
if (isString(a) && isObject(b)) {
|
1211
1351
|
if (a === "")
|
1212
1352
|
throw new Error("The id can't be empty");
|
1213
|
-
const
|
1214
|
-
|
1215
|
-
return record;
|
1353
|
+
const columns = isStringArray(c) ? c : void 0;
|
1354
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1216
1355
|
}
|
1217
1356
|
if (isObject(a) && isString(a.id)) {
|
1218
1357
|
if (a.id === "")
|
1219
1358
|
throw new Error("The id can't be empty");
|
1220
|
-
const
|
1221
|
-
|
1222
|
-
return record;
|
1359
|
+
const columns = isStringArray(b) ? b : void 0;
|
1360
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1223
1361
|
}
|
1224
1362
|
if (isObject(a)) {
|
1225
|
-
const
|
1226
|
-
|
1227
|
-
return record;
|
1363
|
+
const columns = isStringArray(b) ? b : void 0;
|
1364
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1228
1365
|
}
|
1229
1366
|
throw new Error("Invalid arguments for create method");
|
1230
1367
|
}
|
1231
|
-
async read(
|
1232
|
-
const
|
1233
|
-
if (
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
const
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
return
|
1243
|
-
}
|
1244
|
-
|
1245
|
-
|
1368
|
+
async read(a, b) {
|
1369
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1370
|
+
if (Array.isArray(a)) {
|
1371
|
+
if (a.length === 0)
|
1372
|
+
return [];
|
1373
|
+
const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
|
1374
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
1375
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1376
|
+
acc[object.id] = object;
|
1377
|
+
return acc;
|
1378
|
+
}, {});
|
1379
|
+
return ids.map((id2) => dictionary[id2] ?? null);
|
1380
|
+
}
|
1381
|
+
const id = isString(a) ? a : a.id;
|
1382
|
+
if (isString(id)) {
|
1383
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1384
|
+
try {
|
1385
|
+
const response = await getRecord({
|
1386
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
|
1387
|
+
queryParams: { columns },
|
1388
|
+
...fetchProps
|
1389
|
+
});
|
1390
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1391
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1392
|
+
} catch (e) {
|
1393
|
+
if (isObject(e) && e.status === 404) {
|
1394
|
+
return null;
|
1395
|
+
}
|
1396
|
+
throw e;
|
1246
1397
|
}
|
1247
|
-
throw e;
|
1248
1398
|
}
|
1399
|
+
return null;
|
1249
1400
|
}
|
1250
|
-
async update(a, b) {
|
1401
|
+
async update(a, b, c) {
|
1251
1402
|
if (Array.isArray(a)) {
|
1403
|
+
if (a.length === 0)
|
1404
|
+
return [];
|
1252
1405
|
if (a.length > 100) {
|
1253
1406
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1254
1407
|
}
|
1255
|
-
|
1408
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1409
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1256
1410
|
}
|
1257
1411
|
if (isString(a) && isObject(b)) {
|
1258
|
-
|
1259
|
-
|
1260
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1261
|
-
return record;
|
1412
|
+
const columns = isStringArray(c) ? c : void 0;
|
1413
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1262
1414
|
}
|
1263
1415
|
if (isObject(a) && isString(a.id)) {
|
1264
|
-
|
1265
|
-
|
1266
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1267
|
-
return record;
|
1416
|
+
const columns = isStringArray(b) ? b : void 0;
|
1417
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1268
1418
|
}
|
1269
1419
|
throw new Error("Invalid arguments for update method");
|
1270
1420
|
}
|
1271
|
-
async createOrUpdate(a, b) {
|
1421
|
+
async createOrUpdate(a, b, c) {
|
1272
1422
|
if (Array.isArray(a)) {
|
1423
|
+
if (a.length === 0)
|
1424
|
+
return [];
|
1273
1425
|
if (a.length > 100) {
|
1274
1426
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1275
1427
|
}
|
1276
|
-
|
1428
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1429
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1277
1430
|
}
|
1278
1431
|
if (isString(a) && isObject(b)) {
|
1279
|
-
|
1280
|
-
|
1281
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1282
|
-
return record;
|
1432
|
+
const columns = isStringArray(c) ? c : void 0;
|
1433
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1283
1434
|
}
|
1284
1435
|
if (isObject(a) && isString(a.id)) {
|
1285
|
-
|
1286
|
-
|
1287
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1288
|
-
return record;
|
1436
|
+
const columns = isStringArray(c) ? c : void 0;
|
1437
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1289
1438
|
}
|
1290
1439
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1291
1440
|
}
|
1292
1441
|
async delete(a) {
|
1293
1442
|
if (Array.isArray(a)) {
|
1443
|
+
if (a.length === 0)
|
1444
|
+
return;
|
1294
1445
|
if (a.length > 100) {
|
1295
1446
|
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1296
1447
|
}
|
@@ -1299,12 +1450,10 @@ class RestRepository extends Query {
|
|
1299
1450
|
}
|
1300
1451
|
if (isString(a)) {
|
1301
1452
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
1302
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1303
1453
|
return;
|
1304
1454
|
}
|
1305
1455
|
if (isObject(a) && isString(a.id)) {
|
1306
1456
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
1307
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1308
1457
|
return;
|
1309
1458
|
}
|
1310
1459
|
throw new Error("Invalid arguments for delete method");
|
@@ -1316,24 +1465,24 @@ class RestRepository extends Query {
|
|
1316
1465
|
body: {
|
1317
1466
|
query,
|
1318
1467
|
fuzziness: options.fuzziness,
|
1319
|
-
|
1468
|
+
prefix: options.prefix,
|
1469
|
+
highlight: options.highlight,
|
1470
|
+
filter: options.filter,
|
1471
|
+
boosters: options.boosters
|
1320
1472
|
},
|
1321
1473
|
...fetchProps
|
1322
1474
|
});
|
1323
|
-
const
|
1324
|
-
return records.map((item) => initObject(this
|
1475
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1476
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1325
1477
|
}
|
1326
1478
|
async query(query) {
|
1327
1479
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1328
1480
|
if (cacheQuery)
|
1329
1481
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1330
1482
|
const data = query.getQueryOptions();
|
1331
|
-
const filter = Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0;
|
1332
|
-
const sort = data.sort !== void 0 ? buildSortFilter(data.sort) : void 0;
|
1333
|
-
const isCursorPagination = isCursorPaginationOptions(data.pagination);
|
1334
1483
|
const body = {
|
1335
|
-
filter:
|
1336
|
-
sort:
|
1484
|
+
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1485
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1337
1486
|
page: data.pagination,
|
1338
1487
|
columns: data.columns
|
1339
1488
|
};
|
@@ -1343,18 +1492,19 @@ class RestRepository extends Query {
|
|
1343
1492
|
body,
|
1344
1493
|
...fetchProps
|
1345
1494
|
});
|
1346
|
-
const
|
1347
|
-
const records = objects.map((record) => initObject(this
|
1495
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1496
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1348
1497
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1349
1498
|
return new Page(query, meta, records);
|
1350
1499
|
}
|
1351
1500
|
}
|
1352
1501
|
_table = new WeakMap();
|
1353
1502
|
_getFetchProps = new WeakMap();
|
1503
|
+
_db = new WeakMap();
|
1354
1504
|
_cache = new WeakMap();
|
1355
|
-
|
1505
|
+
_schemaTables$2 = new WeakMap();
|
1356
1506
|
_insertRecordWithoutId = new WeakSet();
|
1357
|
-
insertRecordWithoutId_fn = async function(object) {
|
1507
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1358
1508
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1359
1509
|
const record = transformObjectLinks(object);
|
1360
1510
|
const response = await insertRecord({
|
@@ -1363,17 +1513,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1363
1513
|
dbBranchName: "{dbBranch}",
|
1364
1514
|
tableName: __privateGet$4(this, _table)
|
1365
1515
|
},
|
1516
|
+
queryParams: { columns },
|
1366
1517
|
body: record,
|
1367
1518
|
...fetchProps
|
1368
1519
|
});
|
1369
|
-
const
|
1370
|
-
|
1371
|
-
throw new Error("The server failed to save the record");
|
1372
|
-
}
|
1373
|
-
return finalObject;
|
1520
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1521
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1374
1522
|
};
|
1375
1523
|
_insertRecordWithId = new WeakSet();
|
1376
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1524
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1377
1525
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1378
1526
|
const record = transformObjectLinks(object);
|
1379
1527
|
const response = await insertRecordWithID({
|
@@ -1384,56 +1532,52 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1384
1532
|
recordId
|
1385
1533
|
},
|
1386
1534
|
body: record,
|
1387
|
-
queryParams: { createOnly: true },
|
1535
|
+
queryParams: { createOnly: true, columns },
|
1388
1536
|
...fetchProps
|
1389
1537
|
});
|
1390
|
-
const
|
1391
|
-
|
1392
|
-
throw new Error("The server failed to save the record");
|
1393
|
-
}
|
1394
|
-
return finalObject;
|
1538
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1539
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1395
1540
|
};
|
1396
1541
|
_bulkInsertTableRecords = new WeakSet();
|
1397
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1542
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1398
1543
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1399
1544
|
const records = objects.map((object) => transformObjectLinks(object));
|
1400
1545
|
const response = await bulkInsertTableRecords({
|
1401
1546
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1547
|
+
queryParams: { columns },
|
1402
1548
|
body: { records },
|
1403
1549
|
...fetchProps
|
1404
1550
|
});
|
1405
|
-
|
1406
|
-
|
1407
|
-
throw new Error("The server failed to save some records");
|
1551
|
+
if (!isResponseWithRecords(response)) {
|
1552
|
+
throw new Error("Request included columns but server didn't include them");
|
1408
1553
|
}
|
1409
|
-
|
1554
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1555
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1410
1556
|
};
|
1411
1557
|
_updateRecordWithID = new WeakSet();
|
1412
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1558
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1413
1559
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1414
1560
|
const record = transformObjectLinks(object);
|
1415
1561
|
const response = await updateRecordWithID({
|
1416
1562
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1563
|
+
queryParams: { columns },
|
1417
1564
|
body: record,
|
1418
1565
|
...fetchProps
|
1419
1566
|
});
|
1420
|
-
const
|
1421
|
-
|
1422
|
-
throw new Error("The server failed to save the record");
|
1423
|
-
return item;
|
1567
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1568
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1424
1569
|
};
|
1425
1570
|
_upsertRecordWithID = new WeakSet();
|
1426
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1571
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1427
1572
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1428
1573
|
const response = await upsertRecordWithID({
|
1429
1574
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1575
|
+
queryParams: { columns },
|
1430
1576
|
body: object,
|
1431
1577
|
...fetchProps
|
1432
1578
|
});
|
1433
|
-
const
|
1434
|
-
|
1435
|
-
throw new Error("The server failed to save the record");
|
1436
|
-
return item;
|
1579
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1580
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1437
1581
|
};
|
1438
1582
|
_deleteRecord = new WeakSet();
|
1439
1583
|
deleteRecord_fn = async function(recordId) {
|
@@ -1443,29 +1587,6 @@ deleteRecord_fn = async function(recordId) {
|
|
1443
1587
|
...fetchProps
|
1444
1588
|
});
|
1445
1589
|
};
|
1446
|
-
_invalidateCache = new WeakSet();
|
1447
|
-
invalidateCache_fn = async function(recordId) {
|
1448
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1449
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1450
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1451
|
-
for (const [key, value] of queries) {
|
1452
|
-
const ids = getIds(value);
|
1453
|
-
if (ids.includes(recordId))
|
1454
|
-
await __privateGet$4(this, _cache).delete(key);
|
1455
|
-
}
|
1456
|
-
};
|
1457
|
-
_setCacheRecord = new WeakSet();
|
1458
|
-
setCacheRecord_fn = async function(record) {
|
1459
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1460
|
-
return;
|
1461
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1462
|
-
};
|
1463
|
-
_getCacheRecord = new WeakSet();
|
1464
|
-
getCacheRecord_fn = async function(recordId) {
|
1465
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1466
|
-
return null;
|
1467
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1468
|
-
};
|
1469
1590
|
_setCacheQuery = new WeakSet();
|
1470
1591
|
setCacheQuery_fn = async function(query, meta, records) {
|
1471
1592
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1482,17 +1603,17 @@ getCacheQuery_fn = async function(query) {
|
|
1482
1603
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1483
1604
|
return hasExpired ? null : result;
|
1484
1605
|
};
|
1485
|
-
|
1486
|
-
|
1487
|
-
if (__privateGet$4(this,
|
1488
|
-
return __privateGet$4(this,
|
1606
|
+
_getSchemaTables$1 = new WeakSet();
|
1607
|
+
getSchemaTables_fn$1 = async function() {
|
1608
|
+
if (__privateGet$4(this, _schemaTables$2))
|
1609
|
+
return __privateGet$4(this, _schemaTables$2);
|
1489
1610
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1490
1611
|
const { schema } = await getBranchDetails({
|
1491
1612
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1492
1613
|
...fetchProps
|
1493
1614
|
});
|
1494
|
-
__privateSet$
|
1495
|
-
return schema;
|
1615
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1616
|
+
return schema.tables;
|
1496
1617
|
};
|
1497
1618
|
const transformObjectLinks = (object) => {
|
1498
1619
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
@@ -1501,20 +1622,21 @@ const transformObjectLinks = (object) => {
|
|
1501
1622
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1502
1623
|
}, {});
|
1503
1624
|
};
|
1504
|
-
const initObject = (db,
|
1625
|
+
const initObject = (db, schemaTables, table, object) => {
|
1505
1626
|
const result = {};
|
1506
|
-
|
1507
|
-
|
1627
|
+
const { xata, ...rest } = object ?? {};
|
1628
|
+
Object.assign(result, rest);
|
1629
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1508
1630
|
if (!columns)
|
1509
1631
|
console.error(`Table ${table} not found in schema`);
|
1510
1632
|
for (const column of columns ?? []) {
|
1511
1633
|
const value = result[column.name];
|
1512
1634
|
switch (column.type) {
|
1513
1635
|
case "datetime": {
|
1514
|
-
const date = new Date(value);
|
1515
|
-
if (isNaN(date.getTime())) {
|
1636
|
+
const date = value !== void 0 ? new Date(value) : void 0;
|
1637
|
+
if (date && isNaN(date.getTime())) {
|
1516
1638
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1517
|
-
} else {
|
1639
|
+
} else if (date) {
|
1518
1640
|
result[column.name] = date;
|
1519
1641
|
}
|
1520
1642
|
break;
|
@@ -1524,35 +1646,32 @@ const initObject = (db, schema, table, object) => {
|
|
1524
1646
|
if (!linkTable) {
|
1525
1647
|
console.error(`Failed to parse link for field ${column.name}`);
|
1526
1648
|
} else if (isObject(value)) {
|
1527
|
-
result[column.name] = initObject(db,
|
1649
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
1528
1650
|
}
|
1529
1651
|
break;
|
1530
1652
|
}
|
1531
1653
|
}
|
1532
1654
|
}
|
1533
|
-
result.read = function() {
|
1534
|
-
return db[table].read(result["id"]);
|
1655
|
+
result.read = function(columns2) {
|
1656
|
+
return db[table].read(result["id"], columns2);
|
1535
1657
|
};
|
1536
|
-
result.update = function(data) {
|
1537
|
-
return db[table].update(result["id"], data);
|
1658
|
+
result.update = function(data, columns2) {
|
1659
|
+
return db[table].update(result["id"], data, columns2);
|
1538
1660
|
};
|
1539
1661
|
result.delete = function() {
|
1540
1662
|
return db[table].delete(result["id"]);
|
1541
1663
|
};
|
1542
|
-
|
1664
|
+
result.getMetadata = function() {
|
1665
|
+
return xata;
|
1666
|
+
};
|
1667
|
+
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
1543
1668
|
Object.defineProperty(result, prop, { enumerable: false });
|
1544
1669
|
}
|
1545
1670
|
Object.freeze(result);
|
1546
1671
|
return result;
|
1547
1672
|
};
|
1548
|
-
function
|
1549
|
-
|
1550
|
-
return value.map((item) => getIds(item)).flat();
|
1551
|
-
}
|
1552
|
-
if (!isObject(value))
|
1553
|
-
return [];
|
1554
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1555
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1673
|
+
function isResponseWithRecords(value) {
|
1674
|
+
return isObject(value) && Array.isArray(value.records);
|
1556
1675
|
}
|
1557
1676
|
|
1558
1677
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1568,7 +1687,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1568
1687
|
throw TypeError("Cannot add the same private member more than once");
|
1569
1688
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1570
1689
|
};
|
1571
|
-
var __privateSet$
|
1690
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1572
1691
|
__accessCheck$3(obj, member, "write to private field");
|
1573
1692
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1574
1693
|
return value;
|
@@ -1577,9 +1696,8 @@ var _map;
|
|
1577
1696
|
class SimpleCache {
|
1578
1697
|
constructor(options = {}) {
|
1579
1698
|
__privateAdd$3(this, _map, void 0);
|
1580
|
-
__privateSet$
|
1699
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1581
1700
|
this.capacity = options.max ?? 500;
|
1582
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1583
1701
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1584
1702
|
}
|
1585
1703
|
async getAll() {
|
@@ -1637,31 +1755,42 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1637
1755
|
throw TypeError("Cannot add the same private member more than once");
|
1638
1756
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1639
1757
|
};
|
1640
|
-
var
|
1758
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1759
|
+
__accessCheck$2(obj, member, "write to private field");
|
1760
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1761
|
+
return value;
|
1762
|
+
};
|
1763
|
+
var _tables, _schemaTables$1;
|
1641
1764
|
class SchemaPlugin extends XataPlugin {
|
1642
|
-
constructor(
|
1765
|
+
constructor(schemaTables) {
|
1643
1766
|
super();
|
1644
|
-
this.tableNames = tableNames;
|
1645
1767
|
__privateAdd$2(this, _tables, {});
|
1768
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
1769
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1646
1770
|
}
|
1647
1771
|
build(pluginOptions) {
|
1648
|
-
const db = new Proxy(
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1772
|
+
const db = new Proxy(
|
1773
|
+
{},
|
1774
|
+
{
|
1775
|
+
get: (_target, table) => {
|
1776
|
+
if (!isString(table))
|
1777
|
+
throw new Error("Invalid table name");
|
1778
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1779
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1780
|
+
}
|
1781
|
+
return __privateGet$2(this, _tables)[table];
|
1654
1782
|
}
|
1655
|
-
return __privateGet$2(this, _tables)[table];
|
1656
1783
|
}
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1784
|
+
);
|
1785
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1786
|
+
for (const table of tableNames) {
|
1787
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1660
1788
|
}
|
1661
1789
|
return db;
|
1662
1790
|
}
|
1663
1791
|
}
|
1664
1792
|
_tables = new WeakMap();
|
1793
|
+
_schemaTables$1 = new WeakMap();
|
1665
1794
|
|
1666
1795
|
var __accessCheck$1 = (obj, member, msg) => {
|
1667
1796
|
if (!member.has(obj))
|
@@ -1685,82 +1814,77 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
1685
1814
|
__accessCheck$1(obj, member, "access private method");
|
1686
1815
|
return method;
|
1687
1816
|
};
|
1688
|
-
var
|
1817
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
1689
1818
|
class SearchPlugin extends XataPlugin {
|
1690
|
-
constructor(db) {
|
1819
|
+
constructor(db, schemaTables) {
|
1691
1820
|
super();
|
1692
1821
|
this.db = db;
|
1693
1822
|
__privateAdd$1(this, _search);
|
1694
|
-
__privateAdd$1(this,
|
1695
|
-
__privateAdd$1(this,
|
1823
|
+
__privateAdd$1(this, _getSchemaTables);
|
1824
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
1825
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
1696
1826
|
}
|
1697
1827
|
build({ getFetchProps }) {
|
1698
1828
|
return {
|
1699
1829
|
all: async (query, options = {}) => {
|
1700
1830
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1701
|
-
const
|
1831
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1702
1832
|
return records.map((record) => {
|
1703
1833
|
const { table = "orphan" } = record.xata;
|
1704
|
-
return { table, record: initObject(this.db,
|
1834
|
+
return { table, record: initObject(this.db, schemaTables, table, record) };
|
1705
1835
|
});
|
1706
1836
|
},
|
1707
1837
|
byTable: async (query, options = {}) => {
|
1708
1838
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1709
|
-
const
|
1839
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1710
1840
|
return records.reduce((acc, record) => {
|
1711
1841
|
const { table = "orphan" } = record.xata;
|
1712
1842
|
const items = acc[table] ?? [];
|
1713
|
-
const item = initObject(this.db,
|
1843
|
+
const item = initObject(this.db, schemaTables, table, record);
|
1714
1844
|
return { ...acc, [table]: [...items, item] };
|
1715
1845
|
}, {});
|
1716
1846
|
}
|
1717
1847
|
};
|
1718
1848
|
}
|
1719
1849
|
}
|
1720
|
-
|
1850
|
+
_schemaTables = new WeakMap();
|
1721
1851
|
_search = new WeakSet();
|
1722
1852
|
search_fn = async function(query, options, getFetchProps) {
|
1723
1853
|
const fetchProps = await getFetchProps();
|
1724
|
-
const { tables, fuzziness } = options ?? {};
|
1854
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1725
1855
|
const { records } = await searchBranch({
|
1726
1856
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1727
|
-
body: { tables, query, fuzziness },
|
1857
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1728
1858
|
...fetchProps
|
1729
1859
|
});
|
1730
1860
|
return records;
|
1731
1861
|
};
|
1732
|
-
|
1733
|
-
|
1734
|
-
if (__privateGet$1(this,
|
1735
|
-
return __privateGet$1(this,
|
1862
|
+
_getSchemaTables = new WeakSet();
|
1863
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
1864
|
+
if (__privateGet$1(this, _schemaTables))
|
1865
|
+
return __privateGet$1(this, _schemaTables);
|
1736
1866
|
const fetchProps = await getFetchProps();
|
1737
1867
|
const { schema } = await getBranchDetails({
|
1738
1868
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1739
1869
|
...fetchProps
|
1740
1870
|
});
|
1741
|
-
__privateSet$1(this,
|
1742
|
-
return schema;
|
1871
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
1872
|
+
return schema.tables;
|
1743
1873
|
};
|
1744
1874
|
|
1745
1875
|
const isBranchStrategyBuilder = (strategy) => {
|
1746
1876
|
return typeof strategy === "function";
|
1747
1877
|
};
|
1748
1878
|
|
1749
|
-
const envBranchNames = [
|
1750
|
-
"XATA_BRANCH",
|
1751
|
-
"VERCEL_GIT_COMMIT_REF",
|
1752
|
-
"CF_PAGES_BRANCH",
|
1753
|
-
"BRANCH"
|
1754
|
-
];
|
1755
1879
|
async function getCurrentBranchName(options) {
|
1756
|
-
const
|
1757
|
-
if (
|
1758
|
-
const details = await getDatabaseBranch(
|
1880
|
+
const { branch, envBranch } = getEnvironment();
|
1881
|
+
if (branch) {
|
1882
|
+
const details = await getDatabaseBranch(branch, options);
|
1759
1883
|
if (details)
|
1760
|
-
return
|
1761
|
-
console.warn(`Branch ${
|
1884
|
+
return branch;
|
1885
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1762
1886
|
}
|
1763
|
-
const gitBranch = await getGitBranch();
|
1887
|
+
const gitBranch = envBranch || await getGitBranch();
|
1764
1888
|
return resolveXataBranch(gitBranch, options);
|
1765
1889
|
}
|
1766
1890
|
async function getCurrentBranchDetails(options) {
|
@@ -1771,18 +1895,23 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1771
1895
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1772
1896
|
const apiKey = options?.apiKey || getAPIKey();
|
1773
1897
|
if (!databaseURL)
|
1774
|
-
throw new Error(
|
1898
|
+
throw new Error(
|
1899
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1900
|
+
);
|
1775
1901
|
if (!apiKey)
|
1776
|
-
throw new Error(
|
1902
|
+
throw new Error(
|
1903
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1904
|
+
);
|
1777
1905
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1778
1906
|
const [workspace] = host.split(".");
|
1907
|
+
const { fallbackBranch } = getEnvironment();
|
1779
1908
|
const { branch } = await resolveBranch({
|
1780
1909
|
apiKey,
|
1781
1910
|
apiUrl: databaseURL,
|
1782
1911
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1783
1912
|
workspacesApiUrl: `${protocol}//${host}`,
|
1784
1913
|
pathParams: { dbName, workspace },
|
1785
|
-
queryParams: { gitBranch, fallbackBranch
|
1914
|
+
queryParams: { gitBranch, fallbackBranch }
|
1786
1915
|
});
|
1787
1916
|
return branch;
|
1788
1917
|
}
|
@@ -1790,9 +1919,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1790
1919
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1791
1920
|
const apiKey = options?.apiKey || getAPIKey();
|
1792
1921
|
if (!databaseURL)
|
1793
|
-
throw new Error(
|
1922
|
+
throw new Error(
|
1923
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1924
|
+
);
|
1794
1925
|
if (!apiKey)
|
1795
|
-
throw new Error(
|
1926
|
+
throw new Error(
|
1927
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1928
|
+
);
|
1796
1929
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1797
1930
|
const [workspace] = host.split(".");
|
1798
1931
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1802,10 +1935,7 @@ async function getDatabaseBranch(branch, options) {
|
|
1802
1935
|
apiUrl: databaseURL,
|
1803
1936
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1804
1937
|
workspacesApiUrl: `${protocol}//${host}`,
|
1805
|
-
pathParams: {
|
1806
|
-
dbBranchName,
|
1807
|
-
workspace
|
1808
|
-
}
|
1938
|
+
pathParams: { dbBranchName, workspace }
|
1809
1939
|
});
|
1810
1940
|
} catch (err) {
|
1811
1941
|
if (isObject(err) && err.status === 404)
|
@@ -1813,21 +1943,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1813
1943
|
throw err;
|
1814
1944
|
}
|
1815
1945
|
}
|
1816
|
-
function getBranchByEnvVariable() {
|
1817
|
-
for (const name of envBranchNames) {
|
1818
|
-
const value = getEnvVariable(name);
|
1819
|
-
if (value) {
|
1820
|
-
return value;
|
1821
|
-
}
|
1822
|
-
}
|
1823
|
-
try {
|
1824
|
-
return XATA_BRANCH;
|
1825
|
-
} catch (err) {
|
1826
|
-
}
|
1827
|
-
}
|
1828
1946
|
function getDatabaseURL() {
|
1829
1947
|
try {
|
1830
|
-
|
1948
|
+
const { databaseURL } = getEnvironment();
|
1949
|
+
return databaseURL;
|
1831
1950
|
} catch (err) {
|
1832
1951
|
return void 0;
|
1833
1952
|
}
|
@@ -1856,20 +1975,22 @@ var __privateMethod = (obj, member, method) => {
|
|
1856
1975
|
return method;
|
1857
1976
|
};
|
1858
1977
|
const buildClient = (plugins) => {
|
1859
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1978
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1860
1979
|
return _a = class {
|
1861
|
-
constructor(options = {},
|
1980
|
+
constructor(options = {}, schemaTables) {
|
1862
1981
|
__privateAdd(this, _parseOptions);
|
1863
1982
|
__privateAdd(this, _getFetchProps);
|
1864
1983
|
__privateAdd(this, _evaluateBranch);
|
1865
1984
|
__privateAdd(this, _branch, void 0);
|
1985
|
+
__privateAdd(this, _options, void 0);
|
1866
1986
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
1987
|
+
__privateSet(this, _options, safeOptions);
|
1867
1988
|
const pluginOptions = {
|
1868
1989
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1869
1990
|
cache: safeOptions.cache
|
1870
1991
|
};
|
1871
|
-
const db = new SchemaPlugin(
|
1872
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
1992
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
1993
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
1873
1994
|
this.db = db;
|
1874
1995
|
this.search = search;
|
1875
1996
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
@@ -1885,22 +2006,22 @@ const buildClient = (plugins) => {
|
|
1885
2006
|
}
|
1886
2007
|
}
|
1887
2008
|
}
|
1888
|
-
|
2009
|
+
async getConfig() {
|
2010
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2011
|
+
const branch = await __privateGet(this, _options).branch();
|
2012
|
+
return { databaseURL, branch };
|
2013
|
+
}
|
2014
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1889
2015
|
const fetch = getFetchImplementation(options?.fetch);
|
1890
2016
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1891
2017
|
const apiKey = options?.apiKey || getAPIKey();
|
1892
|
-
const cache = options?.cache ?? new SimpleCache({
|
2018
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
1893
2019
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1894
2020
|
if (!databaseURL || !apiKey) {
|
1895
2021
|
throw new Error("Options databaseURL and apiKey are required");
|
1896
2022
|
}
|
1897
2023
|
return { fetch, databaseURL, apiKey, branch, cache };
|
1898
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
1899
|
-
fetch,
|
1900
|
-
apiKey,
|
1901
|
-
databaseURL,
|
1902
|
-
branch
|
1903
|
-
}) {
|
2024
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
|
1904
2025
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
1905
2026
|
if (!branchValue)
|
1906
2027
|
throw new Error("Unable to resolve branch value");
|
@@ -1942,5 +2063,5 @@ class XataError extends Error {
|
|
1942
2063
|
}
|
1943
2064
|
}
|
1944
2065
|
|
1945
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
|
2066
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
1946
2067
|
//# sourceMappingURL=index.mjs.map
|