@xata.io/client 0.0.0-alpha.vf27674a → 0.0.0-alpha.vf28813b
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/.eslintrc.cjs +1 -2
- package/CHANGELOG.md +134 -0
- package/README.md +271 -1
- package/Usage.md +428 -0
- package/dist/index.cjs +476 -296
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +779 -164
- package/dist/index.mjs +454 -296
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -4
- package/tsconfig.json +1 -0
package/dist/index.mjs
CHANGED
@@ -7,46 +7,101 @@ function compact(arr) {
|
|
7
7
|
function isObject(value) {
|
8
8
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
9
9
|
}
|
10
|
+
function isDefined(value) {
|
11
|
+
return value !== null && value !== void 0;
|
12
|
+
}
|
10
13
|
function isString(value) {
|
11
|
-
return value
|
14
|
+
return isDefined(value) && typeof value === "string";
|
15
|
+
}
|
16
|
+
function isStringArray(value) {
|
17
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
12
18
|
}
|
13
19
|
function toBase64(value) {
|
14
20
|
try {
|
15
21
|
return btoa(value);
|
16
22
|
} catch (err) {
|
17
|
-
|
23
|
+
const buf = Buffer;
|
24
|
+
return buf.from(value).toString("base64");
|
18
25
|
}
|
19
26
|
}
|
20
27
|
|
21
|
-
function
|
28
|
+
function getEnvironment() {
|
22
29
|
try {
|
23
|
-
if (isObject(process) &&
|
24
|
-
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
|
+
};
|
25
38
|
}
|
26
39
|
} catch (err) {
|
27
40
|
}
|
28
41
|
try {
|
29
|
-
if (isObject(Deno) &&
|
30
|
-
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
|
+
};
|
31
50
|
}
|
32
51
|
} catch (err) {
|
33
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
|
+
}
|
34
88
|
}
|
35
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"] };
|
36
94
|
try {
|
37
95
|
if (typeof require === "function") {
|
38
|
-
|
39
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
96
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
40
97
|
}
|
98
|
+
const { execSync } = await import(nodeModule);
|
99
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
41
100
|
} catch (err) {
|
42
101
|
}
|
43
102
|
try {
|
44
103
|
if (isObject(Deno)) {
|
45
|
-
const process2 = Deno.run({
|
46
|
-
cmd: ["git", "branch", "--show-current"],
|
47
|
-
stdout: "piped",
|
48
|
-
stderr: "piped"
|
49
|
-
});
|
104
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
50
105
|
return new TextDecoder().decode(await process2.output()).trim();
|
51
106
|
}
|
52
107
|
} catch (err) {
|
@@ -55,7 +110,8 @@ async function getGitBranch() {
|
|
55
110
|
|
56
111
|
function getAPIKey() {
|
57
112
|
try {
|
58
|
-
|
113
|
+
const { apiKey } = getEnvironment();
|
114
|
+
return apiKey;
|
59
115
|
} catch (err) {
|
60
116
|
return void 0;
|
61
117
|
}
|
@@ -65,21 +121,35 @@ function getFetchImplementation(userFetch) {
|
|
65
121
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
66
122
|
const fetchImpl = userFetch ?? globalFetch;
|
67
123
|
if (!fetchImpl) {
|
68
|
-
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
|
+
);
|
69
127
|
}
|
70
128
|
return fetchImpl;
|
71
129
|
}
|
72
130
|
|
73
|
-
|
74
|
-
|
131
|
+
const VERSION = "0.0.0-alpha.vf28813b";
|
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) {
|
75
140
|
super(getMessage(data));
|
76
141
|
this.status = status;
|
77
142
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
143
|
+
this.requestId = requestId;
|
78
144
|
if (data instanceof Error) {
|
79
145
|
this.stack = data.stack;
|
80
146
|
this.cause = data.cause;
|
81
147
|
}
|
82
148
|
}
|
149
|
+
toString() {
|
150
|
+
const error = super.toString();
|
151
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
152
|
+
}
|
83
153
|
}
|
84
154
|
function isBulkError(error) {
|
85
155
|
return isObject(error) && Array.isArray(error.errors);
|
@@ -102,7 +172,12 @@ function getMessage(data) {
|
|
102
172
|
}
|
103
173
|
|
104
174
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
105
|
-
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();
|
106
181
|
const queryString = query.length > 0 ? `?${query}` : "";
|
107
182
|
return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
|
108
183
|
};
|
@@ -142,6 +217,7 @@ async function fetch$1({
|
|
142
217
|
body: body ? JSON.stringify(body) : void 0,
|
143
218
|
headers: {
|
144
219
|
"Content-Type": "application/json",
|
220
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
145
221
|
...headers,
|
146
222
|
...hostHeader(fullUrl),
|
147
223
|
Authorization: `Bearer ${apiKey}`
|
@@ -150,14 +226,15 @@ async function fetch$1({
|
|
150
226
|
if (response.status === 204) {
|
151
227
|
return {};
|
152
228
|
}
|
229
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
153
230
|
try {
|
154
231
|
const jsonResponse = await response.json();
|
155
232
|
if (response.ok) {
|
156
233
|
return jsonResponse;
|
157
234
|
}
|
158
|
-
throw new FetcherError(response.status, jsonResponse);
|
235
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
159
236
|
} catch (error) {
|
160
|
-
throw new FetcherError(response.status, error);
|
237
|
+
throw new FetcherError(response.status, error, requestId);
|
161
238
|
}
|
162
239
|
}
|
163
240
|
|
@@ -216,6 +293,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
216
293
|
...variables
|
217
294
|
});
|
218
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 });
|
219
297
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
220
298
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
221
299
|
method: "delete",
|
@@ -251,6 +329,11 @@ const deleteDatabase = (variables) => fetch$1({
|
|
251
329
|
method: "delete",
|
252
330
|
...variables
|
253
331
|
});
|
332
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
333
|
+
url: "/dbs/{dbName}/metadata",
|
334
|
+
method: "get",
|
335
|
+
...variables
|
336
|
+
});
|
254
337
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
255
338
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
256
339
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -264,11 +347,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
264
347
|
method: "get",
|
265
348
|
...variables
|
266
349
|
});
|
267
|
-
const createBranch = (variables) => fetch$1({
|
268
|
-
url: "/db/{dbBranchName}",
|
269
|
-
method: "put",
|
270
|
-
...variables
|
271
|
-
});
|
350
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
272
351
|
const deleteBranch = (variables) => fetch$1({
|
273
352
|
url: "/db/{dbBranchName}",
|
274
353
|
method: "delete",
|
@@ -342,11 +421,7 @@ const updateColumn = (variables) => fetch$1({
|
|
342
421
|
method: "patch",
|
343
422
|
...variables
|
344
423
|
});
|
345
|
-
const insertRecord = (variables) => fetch$1({
|
346
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
347
|
-
method: "post",
|
348
|
-
...variables
|
349
|
-
});
|
424
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
350
425
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
351
426
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
352
427
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -366,6 +441,11 @@ const queryTable = (variables) => fetch$1({
|
|
366
441
|
method: "post",
|
367
442
|
...variables
|
368
443
|
});
|
444
|
+
const searchTable = (variables) => fetch$1({
|
445
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
446
|
+
method: "post",
|
447
|
+
...variables
|
448
|
+
});
|
369
449
|
const searchBranch = (variables) => fetch$1({
|
370
450
|
url: "/db/{dbBranchName}/search",
|
371
451
|
method: "post",
|
@@ -383,6 +463,7 @@ const operationsByTag = {
|
|
383
463
|
updateWorkspaceMemberRole,
|
384
464
|
removeWorkspaceMember,
|
385
465
|
inviteWorkspaceMember,
|
466
|
+
updateWorkspaceMemberInvite,
|
386
467
|
cancelWorkspaceMemberInvite,
|
387
468
|
resendWorkspaceMemberInvite,
|
388
469
|
acceptWorkspaceMemberInvite
|
@@ -398,6 +479,7 @@ const operationsByTag = {
|
|
398
479
|
},
|
399
480
|
branch: {
|
400
481
|
getBranchList,
|
482
|
+
getDatabaseMetadata,
|
401
483
|
getBranchDetails,
|
402
484
|
createBranch,
|
403
485
|
deleteBranch,
|
@@ -429,6 +511,7 @@ const operationsByTag = {
|
|
429
511
|
getRecord,
|
430
512
|
bulkInsertTableRecords,
|
431
513
|
queryTable,
|
514
|
+
searchTable,
|
432
515
|
searchBranch
|
433
516
|
}
|
434
517
|
};
|
@@ -471,7 +554,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
471
554
|
throw TypeError("Cannot add the same private member more than once");
|
472
555
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
473
556
|
};
|
474
|
-
var __privateSet$
|
557
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
475
558
|
__accessCheck$7(obj, member, "write to private field");
|
476
559
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
477
560
|
return value;
|
@@ -486,7 +569,7 @@ class XataApiClient {
|
|
486
569
|
if (!apiKey) {
|
487
570
|
throw new Error("Could not resolve a valid apiKey");
|
488
571
|
}
|
489
|
-
__privateSet$
|
572
|
+
__privateSet$7(this, _extraProps, {
|
490
573
|
apiUrl: getHostUrl(provider, "main"),
|
491
574
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
492
575
|
fetchImpl: getFetchImplementation(options.fetch),
|
@@ -613,6 +696,13 @@ class WorkspaceApi {
|
|
613
696
|
...this.extraProps
|
614
697
|
});
|
615
698
|
}
|
699
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
700
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
701
|
+
pathParams: { workspaceId, inviteId },
|
702
|
+
body: { role },
|
703
|
+
...this.extraProps
|
704
|
+
});
|
705
|
+
}
|
616
706
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
617
707
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
618
708
|
pathParams: { workspaceId, inviteId },
|
@@ -675,10 +765,10 @@ class DatabaseApi {
|
|
675
765
|
...this.extraProps
|
676
766
|
});
|
677
767
|
}
|
678
|
-
resolveBranch(workspace, dbName, gitBranch) {
|
768
|
+
resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
|
679
769
|
return operationsByTag.database.resolveBranch({
|
680
770
|
pathParams: { workspace, dbName },
|
681
|
-
queryParams: { gitBranch },
|
771
|
+
queryParams: { gitBranch, fallbackBranch },
|
682
772
|
...this.extraProps
|
683
773
|
});
|
684
774
|
}
|
@@ -827,9 +917,10 @@ class RecordsApi {
|
|
827
917
|
constructor(extraProps) {
|
828
918
|
this.extraProps = extraProps;
|
829
919
|
}
|
830
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
920
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
831
921
|
return operationsByTag.records.insertRecord({
|
832
922
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
923
|
+
queryParams: options,
|
833
924
|
body: record,
|
834
925
|
...this.extraProps
|
835
926
|
});
|
@@ -858,21 +949,24 @@ class RecordsApi {
|
|
858
949
|
...this.extraProps
|
859
950
|
});
|
860
951
|
}
|
861
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
952
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
862
953
|
return operationsByTag.records.deleteRecord({
|
863
954
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
955
|
+
queryParams: options,
|
864
956
|
...this.extraProps
|
865
957
|
});
|
866
958
|
}
|
867
959
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
868
960
|
return operationsByTag.records.getRecord({
|
869
961
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
962
|
+
queryParams: options,
|
870
963
|
...this.extraProps
|
871
964
|
});
|
872
965
|
}
|
873
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
966
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
874
967
|
return operationsByTag.records.bulkInsertTableRecords({
|
875
968
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
969
|
+
queryParams: options,
|
876
970
|
body: { records },
|
877
971
|
...this.extraProps
|
878
972
|
});
|
@@ -884,6 +978,13 @@ class RecordsApi {
|
|
884
978
|
...this.extraProps
|
885
979
|
});
|
886
980
|
}
|
981
|
+
searchTable(workspace, database, branch, tableName, query) {
|
982
|
+
return operationsByTag.records.searchTable({
|
983
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
984
|
+
body: query,
|
985
|
+
...this.extraProps
|
986
|
+
});
|
987
|
+
}
|
887
988
|
searchBranch(workspace, database, branch, query) {
|
888
989
|
return operationsByTag.records.searchBranch({
|
889
990
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -916,18 +1017,18 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
916
1017
|
throw TypeError("Cannot add the same private member more than once");
|
917
1018
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
918
1019
|
};
|
919
|
-
var __privateSet$
|
1020
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
920
1021
|
__accessCheck$6(obj, member, "write to private field");
|
921
1022
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
922
1023
|
return value;
|
923
1024
|
};
|
924
|
-
var _query;
|
1025
|
+
var _query, _page;
|
925
1026
|
class Page {
|
926
1027
|
constructor(query, meta, records = []) {
|
927
1028
|
__privateAdd$6(this, _query, void 0);
|
928
|
-
__privateSet$
|
1029
|
+
__privateSet$6(this, _query, query);
|
929
1030
|
this.meta = meta;
|
930
|
-
this.records = records;
|
1031
|
+
this.records = new RecordArray(this, records);
|
931
1032
|
}
|
932
1033
|
async nextPage(size, offset) {
|
933
1034
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
@@ -947,9 +1048,56 @@ class Page {
|
|
947
1048
|
}
|
948
1049
|
_query = new WeakMap();
|
949
1050
|
const PAGINATION_MAX_SIZE = 200;
|
950
|
-
const PAGINATION_DEFAULT_SIZE =
|
1051
|
+
const PAGINATION_DEFAULT_SIZE = 20;
|
951
1052
|
const PAGINATION_MAX_OFFSET = 800;
|
952
1053
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1054
|
+
function isCursorPaginationOptions(options) {
|
1055
|
+
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
1056
|
+
}
|
1057
|
+
const _RecordArray = class extends Array {
|
1058
|
+
constructor(...args) {
|
1059
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
1060
|
+
__privateAdd$6(this, _page, void 0);
|
1061
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1062
|
+
}
|
1063
|
+
static parseConstructorParams(...args) {
|
1064
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1065
|
+
return new Array(args[0]);
|
1066
|
+
}
|
1067
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
1068
|
+
const result = args[1] ?? args[0].records ?? [];
|
1069
|
+
return new Array(...result);
|
1070
|
+
}
|
1071
|
+
return new Array(...args);
|
1072
|
+
}
|
1073
|
+
toArray() {
|
1074
|
+
return new Array(...this);
|
1075
|
+
}
|
1076
|
+
map(callbackfn, thisArg) {
|
1077
|
+
return this.toArray().map(callbackfn, thisArg);
|
1078
|
+
}
|
1079
|
+
async nextPage(size, offset) {
|
1080
|
+
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1081
|
+
return new _RecordArray(newPage);
|
1082
|
+
}
|
1083
|
+
async previousPage(size, offset) {
|
1084
|
+
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1085
|
+
return new _RecordArray(newPage);
|
1086
|
+
}
|
1087
|
+
async firstPage(size, offset) {
|
1088
|
+
const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
|
1089
|
+
return new _RecordArray(newPage);
|
1090
|
+
}
|
1091
|
+
async lastPage(size, offset) {
|
1092
|
+
const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
|
1093
|
+
return new _RecordArray(newPage);
|
1094
|
+
}
|
1095
|
+
hasNextPage() {
|
1096
|
+
return __privateGet$6(this, _page).meta.page.more;
|
1097
|
+
}
|
1098
|
+
};
|
1099
|
+
let RecordArray = _RecordArray;
|
1100
|
+
_page = new WeakMap();
|
953
1101
|
|
954
1102
|
var __accessCheck$5 = (obj, member, msg) => {
|
955
1103
|
if (!member.has(obj))
|
@@ -964,25 +1112,26 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
964
1112
|
throw TypeError("Cannot add the same private member more than once");
|
965
1113
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
966
1114
|
};
|
967
|
-
var __privateSet$
|
1115
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
968
1116
|
__accessCheck$5(obj, member, "write to private field");
|
969
1117
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
970
1118
|
return value;
|
971
1119
|
};
|
972
1120
|
var _table$1, _repository, _data;
|
973
1121
|
const _Query = class {
|
974
|
-
constructor(repository, table, data,
|
1122
|
+
constructor(repository, table, data, rawParent) {
|
975
1123
|
__privateAdd$5(this, _table$1, void 0);
|
976
1124
|
__privateAdd$5(this, _repository, void 0);
|
977
1125
|
__privateAdd$5(this, _data, { filter: {} });
|
978
1126
|
this.meta = { page: { cursor: "start", more: true } };
|
979
|
-
this.records = [];
|
980
|
-
__privateSet$
|
1127
|
+
this.records = new RecordArray(this, []);
|
1128
|
+
__privateSet$5(this, _table$1, table);
|
981
1129
|
if (repository) {
|
982
|
-
__privateSet$
|
1130
|
+
__privateSet$5(this, _repository, repository);
|
983
1131
|
} else {
|
984
|
-
__privateSet$
|
1132
|
+
__privateSet$5(this, _repository, this);
|
985
1133
|
}
|
1134
|
+
const parent = cleanParent(data, rawParent);
|
986
1135
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
987
1136
|
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
988
1137
|
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
@@ -1041,7 +1190,12 @@ const _Query = class {
|
|
1041
1190
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1042
1191
|
}
|
1043
1192
|
select(columns) {
|
1044
|
-
return new _Query(
|
1193
|
+
return new _Query(
|
1194
|
+
__privateGet$5(this, _repository),
|
1195
|
+
__privateGet$5(this, _table$1),
|
1196
|
+
{ columns },
|
1197
|
+
__privateGet$5(this, _data)
|
1198
|
+
);
|
1045
1199
|
}
|
1046
1200
|
getPaginated(options = {}) {
|
1047
1201
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1054,18 +1208,21 @@ const _Query = class {
|
|
1054
1208
|
}
|
1055
1209
|
async *getIterator(options = {}) {
|
1056
1210
|
const { batchSize = 1 } = options;
|
1057
|
-
let
|
1058
|
-
let
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1211
|
+
let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
|
1212
|
+
let more = page.hasNextPage();
|
1213
|
+
yield page.records;
|
1214
|
+
while (more) {
|
1215
|
+
page = await page.nextPage();
|
1216
|
+
more = page.hasNextPage();
|
1217
|
+
yield page.records;
|
1064
1218
|
}
|
1065
1219
|
}
|
1066
1220
|
async getMany(options = {}) {
|
1067
|
-
const
|
1068
|
-
|
1221
|
+
const page = await this.getPaginated(options);
|
1222
|
+
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1223
|
+
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1224
|
+
}
|
1225
|
+
return page.records;
|
1069
1226
|
}
|
1070
1227
|
async getAll(options = {}) {
|
1071
1228
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1077,7 +1234,7 @@ const _Query = class {
|
|
1077
1234
|
}
|
1078
1235
|
async getFirst(options = {}) {
|
1079
1236
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1080
|
-
return records[0]
|
1237
|
+
return records[0] ?? null;
|
1081
1238
|
}
|
1082
1239
|
cache(ttl) {
|
1083
1240
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
@@ -1102,12 +1259,20 @@ let Query = _Query;
|
|
1102
1259
|
_table$1 = new WeakMap();
|
1103
1260
|
_repository = new WeakMap();
|
1104
1261
|
_data = new WeakMap();
|
1262
|
+
function cleanParent(data, parent) {
|
1263
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
1264
|
+
return { ...parent, sorting: void 0, filter: void 0 };
|
1265
|
+
}
|
1266
|
+
return parent;
|
1267
|
+
}
|
1105
1268
|
|
1106
1269
|
function isIdentifiable(x) {
|
1107
1270
|
return isObject(x) && isString(x?.id);
|
1108
1271
|
}
|
1109
1272
|
function isXataRecord(x) {
|
1110
|
-
|
1273
|
+
const record = x;
|
1274
|
+
const metadata = record?.getMetadata();
|
1275
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
1111
1276
|
}
|
1112
1277
|
|
1113
1278
|
function isSortFilterString(value) {
|
@@ -1146,7 +1311,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1146
1311
|
throw TypeError("Cannot add the same private member more than once");
|
1147
1312
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1148
1313
|
};
|
1149
|
-
var __privateSet$
|
1314
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
1150
1315
|
__accessCheck$4(obj, member, "write to private field");
|
1151
1316
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1152
1317
|
return value;
|
@@ -1155,7 +1320,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1155
1320
|
__accessCheck$4(obj, member, "access private method");
|
1156
1321
|
return method;
|
1157
1322
|
};
|
1158
|
-
var _table, _getFetchProps, _cache,
|
1323
|
+
var _table, _getFetchProps, _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;
|
1159
1324
|
class Repository extends Query {
|
1160
1325
|
}
|
1161
1326
|
class RestRepository extends Query {
|
@@ -1167,111 +1332,121 @@ class RestRepository extends Query {
|
|
1167
1332
|
__privateAdd$4(this, _updateRecordWithID);
|
1168
1333
|
__privateAdd$4(this, _upsertRecordWithID);
|
1169
1334
|
__privateAdd$4(this, _deleteRecord);
|
1170
|
-
__privateAdd$4(this, _invalidateCache);
|
1171
|
-
__privateAdd$4(this, _setCacheRecord);
|
1172
|
-
__privateAdd$4(this, _getCacheRecord);
|
1173
1335
|
__privateAdd$4(this, _setCacheQuery);
|
1174
1336
|
__privateAdd$4(this, _getCacheQuery);
|
1175
|
-
__privateAdd$4(this,
|
1337
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
1176
1338
|
__privateAdd$4(this, _table, void 0);
|
1177
1339
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1178
1340
|
__privateAdd$4(this, _cache, void 0);
|
1179
|
-
__privateAdd$4(this,
|
1180
|
-
__privateSet$
|
1181
|
-
__privateSet$
|
1341
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
1342
|
+
__privateSet$4(this, _table, options.table);
|
1343
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1182
1344
|
this.db = options.db;
|
1183
|
-
__privateSet$
|
1345
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1346
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1184
1347
|
}
|
1185
|
-
async create(a, b) {
|
1348
|
+
async create(a, b, c) {
|
1186
1349
|
if (Array.isArray(a)) {
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1350
|
+
if (a.length === 0)
|
1351
|
+
return [];
|
1352
|
+
const columns = isStringArray(b) ? b : void 0;
|
1353
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1190
1354
|
}
|
1191
1355
|
if (isString(a) && isObject(b)) {
|
1192
1356
|
if (a === "")
|
1193
1357
|
throw new Error("The id can't be empty");
|
1194
|
-
const
|
1195
|
-
|
1196
|
-
return record;
|
1358
|
+
const columns = isStringArray(c) ? c : void 0;
|
1359
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1197
1360
|
}
|
1198
1361
|
if (isObject(a) && isString(a.id)) {
|
1199
1362
|
if (a.id === "")
|
1200
1363
|
throw new Error("The id can't be empty");
|
1201
|
-
const
|
1202
|
-
|
1203
|
-
return record;
|
1364
|
+
const columns = isStringArray(b) ? b : void 0;
|
1365
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1204
1366
|
}
|
1205
1367
|
if (isObject(a)) {
|
1206
|
-
const
|
1207
|
-
|
1208
|
-
return record;
|
1368
|
+
const columns = isStringArray(b) ? b : void 0;
|
1369
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1209
1370
|
}
|
1210
1371
|
throw new Error("Invalid arguments for create method");
|
1211
1372
|
}
|
1212
|
-
async read(
|
1213
|
-
const
|
1214
|
-
if (
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
const
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
return
|
1224
|
-
}
|
1225
|
-
|
1226
|
-
|
1373
|
+
async read(a, b) {
|
1374
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1375
|
+
if (Array.isArray(a)) {
|
1376
|
+
if (a.length === 0)
|
1377
|
+
return [];
|
1378
|
+
const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
|
1379
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
1380
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1381
|
+
acc[object.id] = object;
|
1382
|
+
return acc;
|
1383
|
+
}, {});
|
1384
|
+
return ids.map((id2) => dictionary[id2] ?? null);
|
1385
|
+
}
|
1386
|
+
const id = isString(a) ? a : a.id;
|
1387
|
+
if (isString(id)) {
|
1388
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1389
|
+
try {
|
1390
|
+
const response = await getRecord({
|
1391
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
|
1392
|
+
queryParams: { columns },
|
1393
|
+
...fetchProps
|
1394
|
+
});
|
1395
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1396
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1397
|
+
} catch (e) {
|
1398
|
+
if (isObject(e) && e.status === 404) {
|
1399
|
+
return null;
|
1400
|
+
}
|
1401
|
+
throw e;
|
1227
1402
|
}
|
1228
|
-
throw e;
|
1229
1403
|
}
|
1404
|
+
return null;
|
1230
1405
|
}
|
1231
|
-
async update(a, b) {
|
1406
|
+
async update(a, b, c) {
|
1232
1407
|
if (Array.isArray(a)) {
|
1408
|
+
if (a.length === 0)
|
1409
|
+
return [];
|
1233
1410
|
if (a.length > 100) {
|
1234
1411
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1235
1412
|
}
|
1236
|
-
|
1413
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1414
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1237
1415
|
}
|
1238
1416
|
if (isString(a) && isObject(b)) {
|
1239
|
-
|
1240
|
-
|
1241
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1242
|
-
return record;
|
1417
|
+
const columns = isStringArray(c) ? c : void 0;
|
1418
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1243
1419
|
}
|
1244
1420
|
if (isObject(a) && isString(a.id)) {
|
1245
|
-
|
1246
|
-
|
1247
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1248
|
-
return record;
|
1421
|
+
const columns = isStringArray(b) ? b : void 0;
|
1422
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1249
1423
|
}
|
1250
1424
|
throw new Error("Invalid arguments for update method");
|
1251
1425
|
}
|
1252
|
-
async createOrUpdate(a, b) {
|
1426
|
+
async createOrUpdate(a, b, c) {
|
1253
1427
|
if (Array.isArray(a)) {
|
1428
|
+
if (a.length === 0)
|
1429
|
+
return [];
|
1254
1430
|
if (a.length > 100) {
|
1255
1431
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1256
1432
|
}
|
1257
|
-
|
1433
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1434
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1258
1435
|
}
|
1259
1436
|
if (isString(a) && isObject(b)) {
|
1260
|
-
|
1261
|
-
|
1262
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1263
|
-
return record;
|
1437
|
+
const columns = isStringArray(c) ? c : void 0;
|
1438
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1264
1439
|
}
|
1265
1440
|
if (isObject(a) && isString(a.id)) {
|
1266
|
-
|
1267
|
-
|
1268
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1269
|
-
return record;
|
1441
|
+
const columns = isStringArray(c) ? c : void 0;
|
1442
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1270
1443
|
}
|
1271
1444
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1272
1445
|
}
|
1273
1446
|
async delete(a) {
|
1274
1447
|
if (Array.isArray(a)) {
|
1448
|
+
if (a.length === 0)
|
1449
|
+
return;
|
1275
1450
|
if (a.length > 100) {
|
1276
1451
|
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1277
1452
|
}
|
@@ -1280,25 +1455,30 @@ class RestRepository extends Query {
|
|
1280
1455
|
}
|
1281
1456
|
if (isString(a)) {
|
1282
1457
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
1283
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1284
1458
|
return;
|
1285
1459
|
}
|
1286
1460
|
if (isObject(a) && isString(a.id)) {
|
1287
1461
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
1288
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1289
1462
|
return;
|
1290
1463
|
}
|
1291
1464
|
throw new Error("Invalid arguments for delete method");
|
1292
1465
|
}
|
1293
1466
|
async search(query, options = {}) {
|
1294
1467
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1295
|
-
const { records } = await
|
1296
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1297
|
-
body: {
|
1468
|
+
const { records } = await searchTable({
|
1469
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1470
|
+
body: {
|
1471
|
+
query,
|
1472
|
+
fuzziness: options.fuzziness,
|
1473
|
+
prefix: options.prefix,
|
1474
|
+
highlight: options.highlight,
|
1475
|
+
filter: options.filter,
|
1476
|
+
boosters: options.boosters
|
1477
|
+
},
|
1298
1478
|
...fetchProps
|
1299
1479
|
});
|
1300
|
-
const
|
1301
|
-
return records.map((item) => initObject(this.db,
|
1480
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1481
|
+
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1302
1482
|
}
|
1303
1483
|
async query(query) {
|
1304
1484
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
@@ -1307,7 +1487,7 @@ class RestRepository extends Query {
|
|
1307
1487
|
const data = query.getQueryOptions();
|
1308
1488
|
const body = {
|
1309
1489
|
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1310
|
-
sort: data.sort ? buildSortFilter(data.sort) : void 0,
|
1490
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1311
1491
|
page: data.pagination,
|
1312
1492
|
columns: data.columns
|
1313
1493
|
};
|
@@ -1317,8 +1497,8 @@ class RestRepository extends Query {
|
|
1317
1497
|
body,
|
1318
1498
|
...fetchProps
|
1319
1499
|
});
|
1320
|
-
const
|
1321
|
-
const records = objects.map((record) => initObject(this.db,
|
1500
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1501
|
+
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1322
1502
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1323
1503
|
return new Page(query, meta, records);
|
1324
1504
|
}
|
@@ -1326,9 +1506,9 @@ class RestRepository extends Query {
|
|
1326
1506
|
_table = new WeakMap();
|
1327
1507
|
_getFetchProps = new WeakMap();
|
1328
1508
|
_cache = new WeakMap();
|
1329
|
-
|
1509
|
+
_schemaTables$2 = new WeakMap();
|
1330
1510
|
_insertRecordWithoutId = new WeakSet();
|
1331
|
-
insertRecordWithoutId_fn = async function(object) {
|
1511
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1332
1512
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1333
1513
|
const record = transformObjectLinks(object);
|
1334
1514
|
const response = await insertRecord({
|
@@ -1337,17 +1517,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1337
1517
|
dbBranchName: "{dbBranch}",
|
1338
1518
|
tableName: __privateGet$4(this, _table)
|
1339
1519
|
},
|
1520
|
+
queryParams: { columns },
|
1340
1521
|
body: record,
|
1341
1522
|
...fetchProps
|
1342
1523
|
});
|
1343
|
-
const
|
1344
|
-
|
1345
|
-
throw new Error("The server failed to save the record");
|
1346
|
-
}
|
1347
|
-
return finalObject;
|
1524
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1525
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1348
1526
|
};
|
1349
1527
|
_insertRecordWithId = new WeakSet();
|
1350
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1528
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1351
1529
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1352
1530
|
const record = transformObjectLinks(object);
|
1353
1531
|
const response = await insertRecordWithID({
|
@@ -1358,56 +1536,52 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1358
1536
|
recordId
|
1359
1537
|
},
|
1360
1538
|
body: record,
|
1361
|
-
queryParams: { createOnly: true },
|
1539
|
+
queryParams: { createOnly: true, columns },
|
1362
1540
|
...fetchProps
|
1363
1541
|
});
|
1364
|
-
const
|
1365
|
-
|
1366
|
-
throw new Error("The server failed to save the record");
|
1367
|
-
}
|
1368
|
-
return finalObject;
|
1542
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1543
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1369
1544
|
};
|
1370
1545
|
_bulkInsertTableRecords = new WeakSet();
|
1371
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1546
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1372
1547
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1373
1548
|
const records = objects.map((object) => transformObjectLinks(object));
|
1374
1549
|
const response = await bulkInsertTableRecords({
|
1375
1550
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1551
|
+
queryParams: { columns },
|
1376
1552
|
body: { records },
|
1377
1553
|
...fetchProps
|
1378
1554
|
});
|
1379
|
-
|
1380
|
-
|
1381
|
-
throw new Error("The server failed to save some records");
|
1555
|
+
if (!isResponseWithRecords(response)) {
|
1556
|
+
throw new Error("Request included columns but server didn't include them");
|
1382
1557
|
}
|
1383
|
-
|
1558
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1559
|
+
return response.records?.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1384
1560
|
};
|
1385
1561
|
_updateRecordWithID = new WeakSet();
|
1386
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1562
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1387
1563
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1388
1564
|
const record = transformObjectLinks(object);
|
1389
1565
|
const response = await updateRecordWithID({
|
1390
1566
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1567
|
+
queryParams: { columns },
|
1391
1568
|
body: record,
|
1392
1569
|
...fetchProps
|
1393
1570
|
});
|
1394
|
-
const
|
1395
|
-
|
1396
|
-
throw new Error("The server failed to save the record");
|
1397
|
-
return item;
|
1571
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1572
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1398
1573
|
};
|
1399
1574
|
_upsertRecordWithID = new WeakSet();
|
1400
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1575
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1401
1576
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1402
1577
|
const response = await upsertRecordWithID({
|
1403
1578
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1579
|
+
queryParams: { columns },
|
1404
1580
|
body: object,
|
1405
1581
|
...fetchProps
|
1406
1582
|
});
|
1407
|
-
const
|
1408
|
-
|
1409
|
-
throw new Error("The server failed to save the record");
|
1410
|
-
return item;
|
1583
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1584
|
+
return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
|
1411
1585
|
};
|
1412
1586
|
_deleteRecord = new WeakSet();
|
1413
1587
|
deleteRecord_fn = async function(recordId) {
|
@@ -1417,29 +1591,6 @@ deleteRecord_fn = async function(recordId) {
|
|
1417
1591
|
...fetchProps
|
1418
1592
|
});
|
1419
1593
|
};
|
1420
|
-
_invalidateCache = new WeakSet();
|
1421
|
-
invalidateCache_fn = async function(recordId) {
|
1422
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1423
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1424
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1425
|
-
for (const [key, value] of queries) {
|
1426
|
-
const ids = getIds(value);
|
1427
|
-
if (ids.includes(recordId))
|
1428
|
-
await __privateGet$4(this, _cache).delete(key);
|
1429
|
-
}
|
1430
|
-
};
|
1431
|
-
_setCacheRecord = new WeakSet();
|
1432
|
-
setCacheRecord_fn = async function(record) {
|
1433
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1434
|
-
return;
|
1435
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1436
|
-
};
|
1437
|
-
_getCacheRecord = new WeakSet();
|
1438
|
-
getCacheRecord_fn = async function(recordId) {
|
1439
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1440
|
-
return null;
|
1441
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1442
|
-
};
|
1443
1594
|
_setCacheQuery = new WeakSet();
|
1444
1595
|
setCacheQuery_fn = async function(query, meta, records) {
|
1445
1596
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1456,17 +1607,17 @@ getCacheQuery_fn = async function(query) {
|
|
1456
1607
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1457
1608
|
return hasExpired ? null : result;
|
1458
1609
|
};
|
1459
|
-
|
1460
|
-
|
1461
|
-
if (__privateGet$4(this,
|
1462
|
-
return __privateGet$4(this,
|
1610
|
+
_getSchemaTables$1 = new WeakSet();
|
1611
|
+
getSchemaTables_fn$1 = async function() {
|
1612
|
+
if (__privateGet$4(this, _schemaTables$2))
|
1613
|
+
return __privateGet$4(this, _schemaTables$2);
|
1463
1614
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1464
1615
|
const { schema } = await getBranchDetails({
|
1465
1616
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1466
1617
|
...fetchProps
|
1467
1618
|
});
|
1468
|
-
__privateSet$
|
1469
|
-
return schema;
|
1619
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1620
|
+
return schema.tables;
|
1470
1621
|
};
|
1471
1622
|
const transformObjectLinks = (object) => {
|
1472
1623
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
@@ -1475,20 +1626,21 @@ const transformObjectLinks = (object) => {
|
|
1475
1626
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1476
1627
|
}, {});
|
1477
1628
|
};
|
1478
|
-
const initObject = (db,
|
1629
|
+
const initObject = (db, schemaTables, table, object) => {
|
1479
1630
|
const result = {};
|
1480
|
-
|
1481
|
-
|
1631
|
+
const { xata, ...rest } = object ?? {};
|
1632
|
+
Object.assign(result, rest);
|
1633
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1482
1634
|
if (!columns)
|
1483
1635
|
console.error(`Table ${table} not found in schema`);
|
1484
1636
|
for (const column of columns ?? []) {
|
1485
1637
|
const value = result[column.name];
|
1486
1638
|
switch (column.type) {
|
1487
1639
|
case "datetime": {
|
1488
|
-
const date = new Date(value);
|
1489
|
-
if (isNaN(date.getTime())) {
|
1640
|
+
const date = value !== void 0 ? new Date(value) : void 0;
|
1641
|
+
if (date && isNaN(date.getTime())) {
|
1490
1642
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1491
|
-
} else {
|
1643
|
+
} else if (date) {
|
1492
1644
|
result[column.name] = date;
|
1493
1645
|
}
|
1494
1646
|
break;
|
@@ -1497,36 +1649,33 @@ const initObject = (db, schema, table, object) => {
|
|
1497
1649
|
const linkTable = column.link?.table;
|
1498
1650
|
if (!linkTable) {
|
1499
1651
|
console.error(`Failed to parse link for field ${column.name}`);
|
1500
|
-
} else if (
|
1501
|
-
result[column.name] = initObject(db,
|
1652
|
+
} else if (isObject(value)) {
|
1653
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
1502
1654
|
}
|
1503
1655
|
break;
|
1504
1656
|
}
|
1505
1657
|
}
|
1506
1658
|
}
|
1507
|
-
result.read = function() {
|
1508
|
-
return db[table].read(result["id"]);
|
1659
|
+
result.read = function(columns2) {
|
1660
|
+
return db[table].read(result["id"], columns2);
|
1509
1661
|
};
|
1510
|
-
result.update = function(data) {
|
1511
|
-
return db[table].update(result["id"], data);
|
1662
|
+
result.update = function(data, columns2) {
|
1663
|
+
return db[table].update(result["id"], data, columns2);
|
1512
1664
|
};
|
1513
1665
|
result.delete = function() {
|
1514
1666
|
return db[table].delete(result["id"]);
|
1515
1667
|
};
|
1516
|
-
|
1668
|
+
result.getMetadata = function() {
|
1669
|
+
return xata;
|
1670
|
+
};
|
1671
|
+
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
1517
1672
|
Object.defineProperty(result, prop, { enumerable: false });
|
1518
1673
|
}
|
1519
1674
|
Object.freeze(result);
|
1520
1675
|
return result;
|
1521
1676
|
};
|
1522
|
-
function
|
1523
|
-
|
1524
|
-
return value.map((item) => getIds(item)).flat();
|
1525
|
-
}
|
1526
|
-
if (!isObject(value))
|
1527
|
-
return [];
|
1528
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1529
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1677
|
+
function isResponseWithRecords(value) {
|
1678
|
+
return isObject(value) && Array.isArray(value.records);
|
1530
1679
|
}
|
1531
1680
|
|
1532
1681
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1542,7 +1691,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1542
1691
|
throw TypeError("Cannot add the same private member more than once");
|
1543
1692
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1544
1693
|
};
|
1545
|
-
var __privateSet$
|
1694
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1546
1695
|
__accessCheck$3(obj, member, "write to private field");
|
1547
1696
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1548
1697
|
return value;
|
@@ -1551,9 +1700,8 @@ var _map;
|
|
1551
1700
|
class SimpleCache {
|
1552
1701
|
constructor(options = {}) {
|
1553
1702
|
__privateAdd$3(this, _map, void 0);
|
1554
|
-
__privateSet$
|
1703
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1555
1704
|
this.capacity = options.max ?? 500;
|
1556
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1557
1705
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1558
1706
|
}
|
1559
1707
|
async getAll() {
|
@@ -1611,31 +1759,42 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1611
1759
|
throw TypeError("Cannot add the same private member more than once");
|
1612
1760
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1613
1761
|
};
|
1614
|
-
var
|
1762
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1763
|
+
__accessCheck$2(obj, member, "write to private field");
|
1764
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1765
|
+
return value;
|
1766
|
+
};
|
1767
|
+
var _tables, _schemaTables$1;
|
1615
1768
|
class SchemaPlugin extends XataPlugin {
|
1616
|
-
constructor(
|
1769
|
+
constructor(schemaTables) {
|
1617
1770
|
super();
|
1618
|
-
this.tableNames = tableNames;
|
1619
1771
|
__privateAdd$2(this, _tables, {});
|
1772
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
1773
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1620
1774
|
}
|
1621
1775
|
build(pluginOptions) {
|
1622
|
-
const db = new Proxy(
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1776
|
+
const db = new Proxy(
|
1777
|
+
{},
|
1778
|
+
{
|
1779
|
+
get: (_target, table) => {
|
1780
|
+
if (!isString(table))
|
1781
|
+
throw new Error("Invalid table name");
|
1782
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1783
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1784
|
+
}
|
1785
|
+
return __privateGet$2(this, _tables)[table];
|
1628
1786
|
}
|
1629
|
-
return __privateGet$2(this, _tables)[table];
|
1630
1787
|
}
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1788
|
+
);
|
1789
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1790
|
+
for (const table of tableNames) {
|
1791
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1634
1792
|
}
|
1635
1793
|
return db;
|
1636
1794
|
}
|
1637
1795
|
}
|
1638
1796
|
_tables = new WeakMap();
|
1797
|
+
_schemaTables$1 = new WeakMap();
|
1639
1798
|
|
1640
1799
|
var __accessCheck$1 = (obj, member, msg) => {
|
1641
1800
|
if (!member.has(obj))
|
@@ -1659,105 +1818,118 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
1659
1818
|
__accessCheck$1(obj, member, "access private method");
|
1660
1819
|
return method;
|
1661
1820
|
};
|
1662
|
-
var
|
1821
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
1663
1822
|
class SearchPlugin extends XataPlugin {
|
1664
|
-
constructor(db) {
|
1823
|
+
constructor(db, schemaTables) {
|
1665
1824
|
super();
|
1666
1825
|
this.db = db;
|
1667
1826
|
__privateAdd$1(this, _search);
|
1668
|
-
__privateAdd$1(this,
|
1669
|
-
__privateAdd$1(this,
|
1827
|
+
__privateAdd$1(this, _getSchemaTables);
|
1828
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
1829
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
1670
1830
|
}
|
1671
1831
|
build({ getFetchProps }) {
|
1672
1832
|
return {
|
1673
1833
|
all: async (query, options = {}) => {
|
1674
1834
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1675
|
-
const
|
1835
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1676
1836
|
return records.map((record) => {
|
1677
1837
|
const { table = "orphan" } = record.xata;
|
1678
|
-
return { table, record: initObject(this.db,
|
1838
|
+
return { table, record: initObject(this.db, schemaTables, table, record) };
|
1679
1839
|
});
|
1680
1840
|
},
|
1681
1841
|
byTable: async (query, options = {}) => {
|
1682
1842
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1683
|
-
const
|
1843
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1684
1844
|
return records.reduce((acc, record) => {
|
1685
1845
|
const { table = "orphan" } = record.xata;
|
1686
1846
|
const items = acc[table] ?? [];
|
1687
|
-
const item = initObject(this.db,
|
1847
|
+
const item = initObject(this.db, schemaTables, table, record);
|
1688
1848
|
return { ...acc, [table]: [...items, item] };
|
1689
1849
|
}, {});
|
1690
1850
|
}
|
1691
1851
|
};
|
1692
1852
|
}
|
1693
1853
|
}
|
1694
|
-
|
1854
|
+
_schemaTables = new WeakMap();
|
1695
1855
|
_search = new WeakSet();
|
1696
1856
|
search_fn = async function(query, options, getFetchProps) {
|
1697
1857
|
const fetchProps = await getFetchProps();
|
1698
|
-
const { tables, fuzziness } = options ?? {};
|
1858
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1699
1859
|
const { records } = await searchBranch({
|
1700
1860
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1701
|
-
body: { tables, query, fuzziness },
|
1861
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1702
1862
|
...fetchProps
|
1703
1863
|
});
|
1704
1864
|
return records;
|
1705
1865
|
};
|
1706
|
-
|
1707
|
-
|
1708
|
-
if (__privateGet$1(this,
|
1709
|
-
return __privateGet$1(this,
|
1866
|
+
_getSchemaTables = new WeakSet();
|
1867
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
1868
|
+
if (__privateGet$1(this, _schemaTables))
|
1869
|
+
return __privateGet$1(this, _schemaTables);
|
1710
1870
|
const fetchProps = await getFetchProps();
|
1711
1871
|
const { schema } = await getBranchDetails({
|
1712
1872
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1713
1873
|
...fetchProps
|
1714
1874
|
});
|
1715
|
-
__privateSet$1(this,
|
1716
|
-
return schema;
|
1875
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
1876
|
+
return schema.tables;
|
1717
1877
|
};
|
1718
1878
|
|
1719
1879
|
const isBranchStrategyBuilder = (strategy) => {
|
1720
1880
|
return typeof strategy === "function";
|
1721
1881
|
};
|
1722
1882
|
|
1723
|
-
const envBranchNames = [
|
1724
|
-
"XATA_BRANCH",
|
1725
|
-
"VERCEL_GIT_COMMIT_REF",
|
1726
|
-
"CF_PAGES_BRANCH",
|
1727
|
-
"BRANCH"
|
1728
|
-
];
|
1729
|
-
const defaultBranch = "main";
|
1730
1883
|
async function getCurrentBranchName(options) {
|
1731
|
-
const
|
1732
|
-
if (
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
return void 0;
|
1884
|
+
const { branch, envBranch } = getEnvironment();
|
1885
|
+
if (branch) {
|
1886
|
+
const details = await getDatabaseBranch(branch, options);
|
1887
|
+
if (details)
|
1888
|
+
return branch;
|
1889
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1890
|
+
}
|
1891
|
+
const gitBranch = envBranch || await getGitBranch();
|
1892
|
+
return resolveXataBranch(gitBranch, options);
|
1741
1893
|
}
|
1742
1894
|
async function getCurrentBranchDetails(options) {
|
1743
|
-
const
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1895
|
+
const branch = await getCurrentBranchName(options);
|
1896
|
+
return getDatabaseBranch(branch, options);
|
1897
|
+
}
|
1898
|
+
async function resolveXataBranch(gitBranch, options) {
|
1899
|
+
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1900
|
+
const apiKey = options?.apiKey || getAPIKey();
|
1901
|
+
if (!databaseURL)
|
1902
|
+
throw new Error(
|
1903
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1904
|
+
);
|
1905
|
+
if (!apiKey)
|
1906
|
+
throw new Error(
|
1907
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1908
|
+
);
|
1909
|
+
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1910
|
+
const [workspace] = host.split(".");
|
1911
|
+
const { fallbackBranch } = getEnvironment();
|
1912
|
+
const { branch } = await resolveBranch({
|
1913
|
+
apiKey,
|
1914
|
+
apiUrl: databaseURL,
|
1915
|
+
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1916
|
+
workspacesApiUrl: `${protocol}//${host}`,
|
1917
|
+
pathParams: { dbName, workspace },
|
1918
|
+
queryParams: { gitBranch, fallbackBranch }
|
1919
|
+
});
|
1920
|
+
return branch;
|
1753
1921
|
}
|
1754
1922
|
async function getDatabaseBranch(branch, options) {
|
1755
1923
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1756
1924
|
const apiKey = options?.apiKey || getAPIKey();
|
1757
1925
|
if (!databaseURL)
|
1758
|
-
throw new Error(
|
1926
|
+
throw new Error(
|
1927
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1928
|
+
);
|
1759
1929
|
if (!apiKey)
|
1760
|
-
throw new Error(
|
1930
|
+
throw new Error(
|
1931
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1932
|
+
);
|
1761
1933
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1762
1934
|
const [workspace] = host.split(".");
|
1763
1935
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1767,10 +1939,7 @@ async function getDatabaseBranch(branch, options) {
|
|
1767
1939
|
apiUrl: databaseURL,
|
1768
1940
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1769
1941
|
workspacesApiUrl: `${protocol}//${host}`,
|
1770
|
-
pathParams: {
|
1771
|
-
dbBranchName,
|
1772
|
-
workspace
|
1773
|
-
}
|
1942
|
+
pathParams: { dbBranchName, workspace }
|
1774
1943
|
});
|
1775
1944
|
} catch (err) {
|
1776
1945
|
if (isObject(err) && err.status === 404)
|
@@ -1778,21 +1947,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1778
1947
|
throw err;
|
1779
1948
|
}
|
1780
1949
|
}
|
1781
|
-
function getBranchByEnvVariable() {
|
1782
|
-
for (const name of envBranchNames) {
|
1783
|
-
const value = getEnvVariable(name);
|
1784
|
-
if (value) {
|
1785
|
-
return value;
|
1786
|
-
}
|
1787
|
-
}
|
1788
|
-
try {
|
1789
|
-
return XATA_BRANCH;
|
1790
|
-
} catch (err) {
|
1791
|
-
}
|
1792
|
-
}
|
1793
1950
|
function getDatabaseURL() {
|
1794
1951
|
try {
|
1795
|
-
|
1952
|
+
const { databaseURL } = getEnvironment();
|
1953
|
+
return databaseURL;
|
1796
1954
|
} catch (err) {
|
1797
1955
|
return void 0;
|
1798
1956
|
}
|
@@ -1823,7 +1981,7 @@ var __privateMethod = (obj, member, method) => {
|
|
1823
1981
|
const buildClient = (plugins) => {
|
1824
1982
|
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1825
1983
|
return _a = class {
|
1826
|
-
constructor(options = {},
|
1984
|
+
constructor(options = {}, schemaTables) {
|
1827
1985
|
__privateAdd(this, _parseOptions);
|
1828
1986
|
__privateAdd(this, _getFetchProps);
|
1829
1987
|
__privateAdd(this, _evaluateBranch);
|
@@ -1833,12 +1991,12 @@ const buildClient = (plugins) => {
|
|
1833
1991
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1834
1992
|
cache: safeOptions.cache
|
1835
1993
|
};
|
1836
|
-
const db = new SchemaPlugin(
|
1837
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
1994
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
1995
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
1838
1996
|
this.db = db;
|
1839
1997
|
this.search = search;
|
1840
1998
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
1841
|
-
if (
|
1999
|
+
if (namespace === void 0)
|
1842
2000
|
continue;
|
1843
2001
|
const result = namespace.build(pluginOptions);
|
1844
2002
|
if (result instanceof Promise) {
|
@@ -1854,8 +2012,8 @@ const buildClient = (plugins) => {
|
|
1854
2012
|
const fetch = getFetchImplementation(options?.fetch);
|
1855
2013
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1856
2014
|
const apiKey = options?.apiKey || getAPIKey();
|
1857
|
-
const cache = options?.cache ?? new SimpleCache({
|
1858
|
-
const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch })
|
2015
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2016
|
+
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1859
2017
|
if (!databaseURL || !apiKey) {
|
1860
2018
|
throw new Error("Options databaseURL and apiKey are required");
|
1861
2019
|
}
|
@@ -1882,7 +2040,7 @@ const buildClient = (plugins) => {
|
|
1882
2040
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
1883
2041
|
if (__privateGet(this, _branch))
|
1884
2042
|
return __privateGet(this, _branch);
|
1885
|
-
if (
|
2043
|
+
if (param === void 0)
|
1886
2044
|
return void 0;
|
1887
2045
|
const strategies = Array.isArray(param) ? [...param] : [param];
|
1888
2046
|
const evaluateBranch = async (strategy) => {
|
@@ -1907,5 +2065,5 @@ class XataError extends Error {
|
|
1907
2065
|
}
|
1908
2066
|
}
|
1909
2067
|
|
1910
|
-
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,
|
2068
|
+
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, getDatabaseMetadata, 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 };
|
1911
2069
|
//# sourceMappingURL=index.mjs.map
|