@xata.io/client 0.0.0-alpha.vf3081bb → 0.0.0-alpha.vf38b6da
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 +90 -0
- package/README.md +43 -35
- package/Usage.md +442 -0
- package/dist/index.cjs +437 -260
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +637 -160
- package/dist/index.mjs +414 -261
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -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,26 +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
|
|
131
|
+
const VERSION = "0.0.0-alpha.vf38b6da";
|
132
|
+
|
76
133
|
class ErrorWithCause extends Error {
|
77
134
|
constructor(message, options) {
|
78
135
|
super(message, options);
|
79
136
|
}
|
80
137
|
}
|
81
138
|
class FetcherError extends ErrorWithCause {
|
82
|
-
constructor(status, data) {
|
139
|
+
constructor(status, data, requestId) {
|
83
140
|
super(getMessage(data));
|
84
141
|
this.status = status;
|
85
142
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
143
|
+
this.requestId = requestId;
|
86
144
|
if (data instanceof Error) {
|
87
145
|
this.stack = data.stack;
|
88
146
|
this.cause = data.cause;
|
89
147
|
}
|
90
148
|
}
|
149
|
+
toString() {
|
150
|
+
const error = super.toString();
|
151
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
152
|
+
}
|
91
153
|
}
|
92
154
|
function isBulkError(error) {
|
93
155
|
return isObject(error) && Array.isArray(error.errors);
|
@@ -110,7 +172,12 @@ function getMessage(data) {
|
|
110
172
|
}
|
111
173
|
|
112
174
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
113
|
-
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();
|
114
181
|
const queryString = query.length > 0 ? `?${query}` : "";
|
115
182
|
return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
|
116
183
|
};
|
@@ -150,6 +217,7 @@ async function fetch$1({
|
|
150
217
|
body: body ? JSON.stringify(body) : void 0,
|
151
218
|
headers: {
|
152
219
|
"Content-Type": "application/json",
|
220
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
153
221
|
...headers,
|
154
222
|
...hostHeader(fullUrl),
|
155
223
|
Authorization: `Bearer ${apiKey}`
|
@@ -158,14 +226,15 @@ async function fetch$1({
|
|
158
226
|
if (response.status === 204) {
|
159
227
|
return {};
|
160
228
|
}
|
229
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
161
230
|
try {
|
162
231
|
const jsonResponse = await response.json();
|
163
232
|
if (response.ok) {
|
164
233
|
return jsonResponse;
|
165
234
|
}
|
166
|
-
throw new FetcherError(response.status, jsonResponse);
|
235
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
167
236
|
} catch (error) {
|
168
|
-
throw new FetcherError(response.status, error);
|
237
|
+
throw new FetcherError(response.status, error, requestId);
|
169
238
|
}
|
170
239
|
}
|
171
240
|
|
@@ -224,6 +293,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
224
293
|
...variables
|
225
294
|
});
|
226
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 });
|
227
297
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
228
298
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
229
299
|
method: "delete",
|
@@ -259,6 +329,11 @@ const deleteDatabase = (variables) => fetch$1({
|
|
259
329
|
method: "delete",
|
260
330
|
...variables
|
261
331
|
});
|
332
|
+
const getDatabaseMetadata = (variables) => fetch$1({
|
333
|
+
url: "/dbs/{dbName}/metadata",
|
334
|
+
method: "get",
|
335
|
+
...variables
|
336
|
+
});
|
262
337
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
263
338
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
264
339
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -272,11 +347,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
272
347
|
method: "get",
|
273
348
|
...variables
|
274
349
|
});
|
275
|
-
const createBranch = (variables) => fetch$1({
|
276
|
-
url: "/db/{dbBranchName}",
|
277
|
-
method: "put",
|
278
|
-
...variables
|
279
|
-
});
|
350
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
280
351
|
const deleteBranch = (variables) => fetch$1({
|
281
352
|
url: "/db/{dbBranchName}",
|
282
353
|
method: "delete",
|
@@ -350,11 +421,7 @@ const updateColumn = (variables) => fetch$1({
|
|
350
421
|
method: "patch",
|
351
422
|
...variables
|
352
423
|
});
|
353
|
-
const insertRecord = (variables) => fetch$1({
|
354
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
355
|
-
method: "post",
|
356
|
-
...variables
|
357
|
-
});
|
424
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
358
425
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
359
426
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
360
427
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -396,6 +463,7 @@ const operationsByTag = {
|
|
396
463
|
updateWorkspaceMemberRole,
|
397
464
|
removeWorkspaceMember,
|
398
465
|
inviteWorkspaceMember,
|
466
|
+
updateWorkspaceMemberInvite,
|
399
467
|
cancelWorkspaceMemberInvite,
|
400
468
|
resendWorkspaceMemberInvite,
|
401
469
|
acceptWorkspaceMemberInvite
|
@@ -404,6 +472,7 @@ const operationsByTag = {
|
|
404
472
|
getDatabaseList,
|
405
473
|
createDatabase,
|
406
474
|
deleteDatabase,
|
475
|
+
getDatabaseMetadata,
|
407
476
|
getGitBranchesMapping,
|
408
477
|
addGitBranchesEntry,
|
409
478
|
removeGitBranchesEntry,
|
@@ -485,7 +554,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
485
554
|
throw TypeError("Cannot add the same private member more than once");
|
486
555
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
487
556
|
};
|
488
|
-
var __privateSet$
|
557
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
489
558
|
__accessCheck$7(obj, member, "write to private field");
|
490
559
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
491
560
|
return value;
|
@@ -500,7 +569,7 @@ class XataApiClient {
|
|
500
569
|
if (!apiKey) {
|
501
570
|
throw new Error("Could not resolve a valid apiKey");
|
502
571
|
}
|
503
|
-
__privateSet$
|
572
|
+
__privateSet$7(this, _extraProps, {
|
504
573
|
apiUrl: getHostUrl(provider, "main"),
|
505
574
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
506
575
|
fetchImpl: getFetchImplementation(options.fetch),
|
@@ -627,6 +696,13 @@ class WorkspaceApi {
|
|
627
696
|
...this.extraProps
|
628
697
|
});
|
629
698
|
}
|
699
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
700
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
701
|
+
pathParams: { workspaceId, inviteId },
|
702
|
+
body: { role },
|
703
|
+
...this.extraProps
|
704
|
+
});
|
705
|
+
}
|
630
706
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
631
707
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
632
708
|
pathParams: { workspaceId, inviteId },
|
@@ -669,6 +745,12 @@ class DatabaseApi {
|
|
669
745
|
...this.extraProps
|
670
746
|
});
|
671
747
|
}
|
748
|
+
getDatabaseMetadata(workspace, dbName) {
|
749
|
+
return operationsByTag.database.getDatabaseMetadata({
|
750
|
+
pathParams: { workspace, dbName },
|
751
|
+
...this.extraProps
|
752
|
+
});
|
753
|
+
}
|
672
754
|
getGitBranchesMapping(workspace, dbName) {
|
673
755
|
return operationsByTag.database.getGitBranchesMapping({
|
674
756
|
pathParams: { workspace, dbName },
|
@@ -689,10 +771,10 @@ class DatabaseApi {
|
|
689
771
|
...this.extraProps
|
690
772
|
});
|
691
773
|
}
|
692
|
-
resolveBranch(workspace, dbName, gitBranch) {
|
774
|
+
resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
|
693
775
|
return operationsByTag.database.resolveBranch({
|
694
776
|
pathParams: { workspace, dbName },
|
695
|
-
queryParams: { gitBranch },
|
777
|
+
queryParams: { gitBranch, fallbackBranch },
|
696
778
|
...this.extraProps
|
697
779
|
});
|
698
780
|
}
|
@@ -841,9 +923,10 @@ class RecordsApi {
|
|
841
923
|
constructor(extraProps) {
|
842
924
|
this.extraProps = extraProps;
|
843
925
|
}
|
844
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
926
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
845
927
|
return operationsByTag.records.insertRecord({
|
846
928
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
929
|
+
queryParams: options,
|
847
930
|
body: record,
|
848
931
|
...this.extraProps
|
849
932
|
});
|
@@ -872,21 +955,24 @@ class RecordsApi {
|
|
872
955
|
...this.extraProps
|
873
956
|
});
|
874
957
|
}
|
875
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
958
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
876
959
|
return operationsByTag.records.deleteRecord({
|
877
960
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
961
|
+
queryParams: options,
|
878
962
|
...this.extraProps
|
879
963
|
});
|
880
964
|
}
|
881
965
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
882
966
|
return operationsByTag.records.getRecord({
|
883
967
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
968
|
+
queryParams: options,
|
884
969
|
...this.extraProps
|
885
970
|
});
|
886
971
|
}
|
887
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
972
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
888
973
|
return operationsByTag.records.bulkInsertTableRecords({
|
889
974
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
975
|
+
queryParams: options,
|
890
976
|
body: { records },
|
891
977
|
...this.extraProps
|
892
978
|
});
|
@@ -937,7 +1023,7 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
937
1023
|
throw TypeError("Cannot add the same private member more than once");
|
938
1024
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
939
1025
|
};
|
940
|
-
var __privateSet$
|
1026
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
941
1027
|
__accessCheck$6(obj, member, "write to private field");
|
942
1028
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
943
1029
|
return value;
|
@@ -946,7 +1032,7 @@ var _query, _page;
|
|
946
1032
|
class Page {
|
947
1033
|
constructor(query, meta, records = []) {
|
948
1034
|
__privateAdd$6(this, _query, void 0);
|
949
|
-
__privateSet$
|
1035
|
+
__privateSet$6(this, _query, query);
|
950
1036
|
this.meta = meta;
|
951
1037
|
this.records = new RecordArray(this, records);
|
952
1038
|
}
|
@@ -975,10 +1061,26 @@ function isCursorPaginationOptions(options) {
|
|
975
1061
|
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
976
1062
|
}
|
977
1063
|
const _RecordArray = class extends Array {
|
978
|
-
constructor(
|
979
|
-
super(...
|
1064
|
+
constructor(...args) {
|
1065
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
980
1066
|
__privateAdd$6(this, _page, void 0);
|
981
|
-
__privateSet$
|
1067
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1068
|
+
}
|
1069
|
+
static parseConstructorParams(...args) {
|
1070
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1071
|
+
return new Array(args[0]);
|
1072
|
+
}
|
1073
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
1074
|
+
const result = args[1] ?? args[0].records ?? [];
|
1075
|
+
return new Array(...result);
|
1076
|
+
}
|
1077
|
+
return new Array(...args);
|
1078
|
+
}
|
1079
|
+
toArray() {
|
1080
|
+
return new Array(...this);
|
1081
|
+
}
|
1082
|
+
map(callbackfn, thisArg) {
|
1083
|
+
return this.toArray().map(callbackfn, thisArg);
|
982
1084
|
}
|
983
1085
|
async nextPage(size, offset) {
|
984
1086
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
@@ -1016,7 +1118,7 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
1016
1118
|
throw TypeError("Cannot add the same private member more than once");
|
1017
1119
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1018
1120
|
};
|
1019
|
-
var __privateSet$
|
1121
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
1020
1122
|
__accessCheck$5(obj, member, "write to private field");
|
1021
1123
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1022
1124
|
return value;
|
@@ -1029,11 +1131,11 @@ const _Query = class {
|
|
1029
1131
|
__privateAdd$5(this, _data, { filter: {} });
|
1030
1132
|
this.meta = { page: { cursor: "start", more: true } };
|
1031
1133
|
this.records = new RecordArray(this, []);
|
1032
|
-
__privateSet$
|
1134
|
+
__privateSet$5(this, _table$1, table);
|
1033
1135
|
if (repository) {
|
1034
|
-
__privateSet$
|
1136
|
+
__privateSet$5(this, _repository, repository);
|
1035
1137
|
} else {
|
1036
|
-
__privateSet$
|
1138
|
+
__privateSet$5(this, _repository, this);
|
1037
1139
|
}
|
1038
1140
|
const parent = cleanParent(data, rawParent);
|
1039
1141
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
@@ -1088,13 +1190,18 @@ const _Query = class {
|
|
1088
1190
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1089
1191
|
}
|
1090
1192
|
}
|
1091
|
-
sort(column, direction) {
|
1193
|
+
sort(column, direction = "asc") {
|
1092
1194
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1093
1195
|
const sort = [...originalSort, { column, direction }];
|
1094
1196
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1095
1197
|
}
|
1096
1198
|
select(columns) {
|
1097
|
-
return new _Query(
|
1199
|
+
return new _Query(
|
1200
|
+
__privateGet$5(this, _repository),
|
1201
|
+
__privateGet$5(this, _table$1),
|
1202
|
+
{ columns },
|
1203
|
+
__privateGet$5(this, _data)
|
1204
|
+
);
|
1098
1205
|
}
|
1099
1206
|
getPaginated(options = {}) {
|
1100
1207
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1210,7 +1317,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1210
1317
|
throw TypeError("Cannot add the same private member more than once");
|
1211
1318
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1212
1319
|
};
|
1213
|
-
var __privateSet$
|
1320
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
1214
1321
|
__accessCheck$4(obj, member, "write to private field");
|
1215
1322
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1216
1323
|
return value;
|
@@ -1219,7 +1326,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1219
1326
|
__accessCheck$4(obj, member, "access private method");
|
1220
1327
|
return method;
|
1221
1328
|
};
|
1222
|
-
var _table, _getFetchProps, _cache,
|
1329
|
+
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;
|
1223
1330
|
class Repository extends Query {
|
1224
1331
|
}
|
1225
1332
|
class RestRepository extends Query {
|
@@ -1231,68 +1338,69 @@ class RestRepository extends Query {
|
|
1231
1338
|
__privateAdd$4(this, _updateRecordWithID);
|
1232
1339
|
__privateAdd$4(this, _upsertRecordWithID);
|
1233
1340
|
__privateAdd$4(this, _deleteRecord);
|
1234
|
-
__privateAdd$4(this, _invalidateCache);
|
1235
|
-
__privateAdd$4(this, _setCacheRecord);
|
1236
|
-
__privateAdd$4(this, _getCacheRecord);
|
1237
1341
|
__privateAdd$4(this, _setCacheQuery);
|
1238
1342
|
__privateAdd$4(this, _getCacheQuery);
|
1239
|
-
__privateAdd$4(this,
|
1343
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
1240
1344
|
__privateAdd$4(this, _table, void 0);
|
1241
1345
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1346
|
+
__privateAdd$4(this, _db, void 0);
|
1242
1347
|
__privateAdd$4(this, _cache, void 0);
|
1243
|
-
__privateAdd$4(this,
|
1244
|
-
__privateSet$
|
1245
|
-
__privateSet$
|
1246
|
-
this
|
1247
|
-
__privateSet$
|
1248
|
-
|
1249
|
-
|
1348
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
1349
|
+
__privateSet$4(this, _table, options.table);
|
1350
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1351
|
+
__privateSet$4(this, _db, options.db);
|
1352
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1353
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1354
|
+
}
|
1355
|
+
async create(a, b, c) {
|
1250
1356
|
if (Array.isArray(a)) {
|
1251
1357
|
if (a.length === 0)
|
1252
1358
|
return [];
|
1253
|
-
const
|
1254
|
-
|
1255
|
-
return records;
|
1359
|
+
const columns = isStringArray(b) ? b : void 0;
|
1360
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1256
1361
|
}
|
1257
1362
|
if (isString(a) && isObject(b)) {
|
1258
1363
|
if (a === "")
|
1259
1364
|
throw new Error("The id can't be empty");
|
1260
|
-
const
|
1261
|
-
|
1262
|
-
return record;
|
1365
|
+
const columns = isStringArray(c) ? c : void 0;
|
1366
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1263
1367
|
}
|
1264
1368
|
if (isObject(a) && isString(a.id)) {
|
1265
1369
|
if (a.id === "")
|
1266
1370
|
throw new Error("The id can't be empty");
|
1267
|
-
const
|
1268
|
-
|
1269
|
-
return record;
|
1371
|
+
const columns = isStringArray(b) ? b : void 0;
|
1372
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1270
1373
|
}
|
1271
1374
|
if (isObject(a)) {
|
1272
|
-
const
|
1273
|
-
|
1274
|
-
return record;
|
1375
|
+
const columns = isStringArray(b) ? b : void 0;
|
1376
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1275
1377
|
}
|
1276
1378
|
throw new Error("Invalid arguments for create method");
|
1277
1379
|
}
|
1278
|
-
async read(a) {
|
1380
|
+
async read(a, b) {
|
1381
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1279
1382
|
if (Array.isArray(a)) {
|
1280
1383
|
if (a.length === 0)
|
1281
1384
|
return [];
|
1282
|
-
|
1385
|
+
const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
|
1386
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
1387
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1388
|
+
acc[object.id] = object;
|
1389
|
+
return acc;
|
1390
|
+
}, {});
|
1391
|
+
return ids.map((id2) => dictionary[id2] ?? null);
|
1283
1392
|
}
|
1284
|
-
|
1285
|
-
|
1286
|
-
if (cacheRecord)
|
1287
|
-
return cacheRecord;
|
1393
|
+
const id = isString(a) ? a : a.id;
|
1394
|
+
if (isString(id)) {
|
1288
1395
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1289
1396
|
try {
|
1290
1397
|
const response = await getRecord({
|
1291
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId:
|
1398
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
|
1399
|
+
queryParams: { columns },
|
1292
1400
|
...fetchProps
|
1293
1401
|
});
|
1294
|
-
const
|
1295
|
-
return initObject(this
|
1402
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1403
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1296
1404
|
} catch (e) {
|
1297
1405
|
if (isObject(e) && e.status === 404) {
|
1298
1406
|
return null;
|
@@ -1300,50 +1408,45 @@ class RestRepository extends Query {
|
|
1300
1408
|
throw e;
|
1301
1409
|
}
|
1302
1410
|
}
|
1411
|
+
return null;
|
1303
1412
|
}
|
1304
|
-
async update(a, b) {
|
1413
|
+
async update(a, b, c) {
|
1305
1414
|
if (Array.isArray(a)) {
|
1306
1415
|
if (a.length === 0)
|
1307
1416
|
return [];
|
1308
1417
|
if (a.length > 100) {
|
1309
1418
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1310
1419
|
}
|
1311
|
-
|
1420
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1421
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1312
1422
|
}
|
1313
1423
|
if (isString(a) && isObject(b)) {
|
1314
|
-
|
1315
|
-
|
1316
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1317
|
-
return record;
|
1424
|
+
const columns = isStringArray(c) ? c : void 0;
|
1425
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1318
1426
|
}
|
1319
1427
|
if (isObject(a) && isString(a.id)) {
|
1320
|
-
|
1321
|
-
|
1322
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1323
|
-
return record;
|
1428
|
+
const columns = isStringArray(b) ? b : void 0;
|
1429
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1324
1430
|
}
|
1325
1431
|
throw new Error("Invalid arguments for update method");
|
1326
1432
|
}
|
1327
|
-
async createOrUpdate(a, b) {
|
1433
|
+
async createOrUpdate(a, b, c) {
|
1328
1434
|
if (Array.isArray(a)) {
|
1329
1435
|
if (a.length === 0)
|
1330
1436
|
return [];
|
1331
1437
|
if (a.length > 100) {
|
1332
1438
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1333
1439
|
}
|
1334
|
-
|
1440
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1441
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1335
1442
|
}
|
1336
1443
|
if (isString(a) && isObject(b)) {
|
1337
|
-
|
1338
|
-
|
1339
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1340
|
-
return record;
|
1444
|
+
const columns = isStringArray(c) ? c : void 0;
|
1445
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1341
1446
|
}
|
1342
1447
|
if (isObject(a) && isString(a.id)) {
|
1343
|
-
|
1344
|
-
|
1345
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1346
|
-
return record;
|
1448
|
+
const columns = isStringArray(c) ? c : void 0;
|
1449
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1347
1450
|
}
|
1348
1451
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1349
1452
|
}
|
@@ -1359,12 +1462,10 @@ class RestRepository extends Query {
|
|
1359
1462
|
}
|
1360
1463
|
if (isString(a)) {
|
1361
1464
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
1362
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1363
1465
|
return;
|
1364
1466
|
}
|
1365
1467
|
if (isObject(a) && isString(a.id)) {
|
1366
1468
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
1367
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1368
1469
|
return;
|
1369
1470
|
}
|
1370
1471
|
throw new Error("Invalid arguments for delete method");
|
@@ -1376,13 +1477,15 @@ class RestRepository extends Query {
|
|
1376
1477
|
body: {
|
1377
1478
|
query,
|
1378
1479
|
fuzziness: options.fuzziness,
|
1480
|
+
prefix: options.prefix,
|
1379
1481
|
highlight: options.highlight,
|
1380
|
-
filter: options.filter
|
1482
|
+
filter: options.filter,
|
1483
|
+
boosters: options.boosters
|
1381
1484
|
},
|
1382
1485
|
...fetchProps
|
1383
1486
|
});
|
1384
|
-
const
|
1385
|
-
return records.map((item) => initObject(this
|
1487
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1488
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1386
1489
|
}
|
1387
1490
|
async query(query) {
|
1388
1491
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
@@ -1401,18 +1504,19 @@ class RestRepository extends Query {
|
|
1401
1504
|
body,
|
1402
1505
|
...fetchProps
|
1403
1506
|
});
|
1404
|
-
const
|
1405
|
-
const records = objects.map((record) => initObject(this
|
1507
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1508
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1406
1509
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1407
1510
|
return new Page(query, meta, records);
|
1408
1511
|
}
|
1409
1512
|
}
|
1410
1513
|
_table = new WeakMap();
|
1411
1514
|
_getFetchProps = new WeakMap();
|
1515
|
+
_db = new WeakMap();
|
1412
1516
|
_cache = new WeakMap();
|
1413
|
-
|
1517
|
+
_schemaTables$2 = new WeakMap();
|
1414
1518
|
_insertRecordWithoutId = new WeakSet();
|
1415
|
-
insertRecordWithoutId_fn = async function(object) {
|
1519
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1416
1520
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1417
1521
|
const record = transformObjectLinks(object);
|
1418
1522
|
const response = await insertRecord({
|
@@ -1421,17 +1525,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1421
1525
|
dbBranchName: "{dbBranch}",
|
1422
1526
|
tableName: __privateGet$4(this, _table)
|
1423
1527
|
},
|
1528
|
+
queryParams: { columns },
|
1424
1529
|
body: record,
|
1425
1530
|
...fetchProps
|
1426
1531
|
});
|
1427
|
-
const
|
1428
|
-
|
1429
|
-
throw new Error("The server failed to save the record");
|
1430
|
-
}
|
1431
|
-
return finalObject;
|
1532
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1533
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1432
1534
|
};
|
1433
1535
|
_insertRecordWithId = new WeakSet();
|
1434
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1536
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1435
1537
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1436
1538
|
const record = transformObjectLinks(object);
|
1437
1539
|
const response = await insertRecordWithID({
|
@@ -1442,56 +1544,52 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1442
1544
|
recordId
|
1443
1545
|
},
|
1444
1546
|
body: record,
|
1445
|
-
queryParams: { createOnly: true },
|
1547
|
+
queryParams: { createOnly: true, columns },
|
1446
1548
|
...fetchProps
|
1447
1549
|
});
|
1448
|
-
const
|
1449
|
-
|
1450
|
-
throw new Error("The server failed to save the record");
|
1451
|
-
}
|
1452
|
-
return finalObject;
|
1550
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1551
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1453
1552
|
};
|
1454
1553
|
_bulkInsertTableRecords = new WeakSet();
|
1455
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1554
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1456
1555
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1457
1556
|
const records = objects.map((object) => transformObjectLinks(object));
|
1458
1557
|
const response = await bulkInsertTableRecords({
|
1459
1558
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1559
|
+
queryParams: { columns },
|
1460
1560
|
body: { records },
|
1461
1561
|
...fetchProps
|
1462
1562
|
});
|
1463
|
-
|
1464
|
-
|
1465
|
-
throw new Error("The server failed to save some records");
|
1563
|
+
if (!isResponseWithRecords(response)) {
|
1564
|
+
throw new Error("Request included columns but server didn't include them");
|
1466
1565
|
}
|
1467
|
-
|
1566
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1567
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1468
1568
|
};
|
1469
1569
|
_updateRecordWithID = new WeakSet();
|
1470
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1570
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1471
1571
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1472
1572
|
const record = transformObjectLinks(object);
|
1473
1573
|
const response = await updateRecordWithID({
|
1474
1574
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1575
|
+
queryParams: { columns },
|
1475
1576
|
body: record,
|
1476
1577
|
...fetchProps
|
1477
1578
|
});
|
1478
|
-
const
|
1479
|
-
|
1480
|
-
throw new Error("The server failed to save the record");
|
1481
|
-
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);
|
1482
1581
|
};
|
1483
1582
|
_upsertRecordWithID = new WeakSet();
|
1484
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1583
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1485
1584
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1486
1585
|
const response = await upsertRecordWithID({
|
1487
1586
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1587
|
+
queryParams: { columns },
|
1488
1588
|
body: object,
|
1489
1589
|
...fetchProps
|
1490
1590
|
});
|
1491
|
-
const
|
1492
|
-
|
1493
|
-
throw new Error("The server failed to save the record");
|
1494
|
-
return item;
|
1591
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1592
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1495
1593
|
};
|
1496
1594
|
_deleteRecord = new WeakSet();
|
1497
1595
|
deleteRecord_fn = async function(recordId) {
|
@@ -1501,29 +1599,6 @@ deleteRecord_fn = async function(recordId) {
|
|
1501
1599
|
...fetchProps
|
1502
1600
|
});
|
1503
1601
|
};
|
1504
|
-
_invalidateCache = new WeakSet();
|
1505
|
-
invalidateCache_fn = async function(recordId) {
|
1506
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1507
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1508
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1509
|
-
for (const [key, value] of queries) {
|
1510
|
-
const ids = getIds(value);
|
1511
|
-
if (ids.includes(recordId))
|
1512
|
-
await __privateGet$4(this, _cache).delete(key);
|
1513
|
-
}
|
1514
|
-
};
|
1515
|
-
_setCacheRecord = new WeakSet();
|
1516
|
-
setCacheRecord_fn = async function(record) {
|
1517
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1518
|
-
return;
|
1519
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1520
|
-
};
|
1521
|
-
_getCacheRecord = new WeakSet();
|
1522
|
-
getCacheRecord_fn = async function(recordId) {
|
1523
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1524
|
-
return null;
|
1525
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1526
|
-
};
|
1527
1602
|
_setCacheQuery = new WeakSet();
|
1528
1603
|
setCacheQuery_fn = async function(query, meta, records) {
|
1529
1604
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1540,17 +1615,17 @@ getCacheQuery_fn = async function(query) {
|
|
1540
1615
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1541
1616
|
return hasExpired ? null : result;
|
1542
1617
|
};
|
1543
|
-
|
1544
|
-
|
1545
|
-
if (__privateGet$4(this,
|
1546
|
-
return __privateGet$4(this,
|
1618
|
+
_getSchemaTables$1 = new WeakSet();
|
1619
|
+
getSchemaTables_fn$1 = async function() {
|
1620
|
+
if (__privateGet$4(this, _schemaTables$2))
|
1621
|
+
return __privateGet$4(this, _schemaTables$2);
|
1547
1622
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1548
1623
|
const { schema } = await getBranchDetails({
|
1549
1624
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1550
1625
|
...fetchProps
|
1551
1626
|
});
|
1552
|
-
__privateSet$
|
1553
|
-
return schema;
|
1627
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1628
|
+
return schema.tables;
|
1554
1629
|
};
|
1555
1630
|
const transformObjectLinks = (object) => {
|
1556
1631
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
@@ -1559,11 +1634,11 @@ const transformObjectLinks = (object) => {
|
|
1559
1634
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1560
1635
|
}, {});
|
1561
1636
|
};
|
1562
|
-
const initObject = (db,
|
1637
|
+
const initObject = (db, schemaTables, table, object) => {
|
1563
1638
|
const result = {};
|
1564
1639
|
const { xata, ...rest } = object ?? {};
|
1565
1640
|
Object.assign(result, rest);
|
1566
|
-
const { columns } =
|
1641
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1567
1642
|
if (!columns)
|
1568
1643
|
console.error(`Table ${table} not found in schema`);
|
1569
1644
|
for (const column of columns ?? []) {
|
@@ -1583,17 +1658,17 @@ const initObject = (db, schema, table, object) => {
|
|
1583
1658
|
if (!linkTable) {
|
1584
1659
|
console.error(`Failed to parse link for field ${column.name}`);
|
1585
1660
|
} else if (isObject(value)) {
|
1586
|
-
result[column.name] = initObject(db,
|
1661
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
1587
1662
|
}
|
1588
1663
|
break;
|
1589
1664
|
}
|
1590
1665
|
}
|
1591
1666
|
}
|
1592
|
-
result.read = function() {
|
1593
|
-
return db[table].read(result["id"]);
|
1667
|
+
result.read = function(columns2) {
|
1668
|
+
return db[table].read(result["id"], columns2);
|
1594
1669
|
};
|
1595
|
-
result.update = function(data) {
|
1596
|
-
return db[table].update(result["id"], data);
|
1670
|
+
result.update = function(data, columns2) {
|
1671
|
+
return db[table].update(result["id"], data, columns2);
|
1597
1672
|
};
|
1598
1673
|
result.delete = function() {
|
1599
1674
|
return db[table].delete(result["id"]);
|
@@ -1607,14 +1682,8 @@ const initObject = (db, schema, table, object) => {
|
|
1607
1682
|
Object.freeze(result);
|
1608
1683
|
return result;
|
1609
1684
|
};
|
1610
|
-
function
|
1611
|
-
|
1612
|
-
return value.map((item) => getIds(item)).flat();
|
1613
|
-
}
|
1614
|
-
if (!isObject(value))
|
1615
|
-
return [];
|
1616
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1617
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1685
|
+
function isResponseWithRecords(value) {
|
1686
|
+
return isObject(value) && Array.isArray(value.records);
|
1618
1687
|
}
|
1619
1688
|
|
1620
1689
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1630,7 +1699,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1630
1699
|
throw TypeError("Cannot add the same private member more than once");
|
1631
1700
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1632
1701
|
};
|
1633
|
-
var __privateSet$
|
1702
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1634
1703
|
__accessCheck$3(obj, member, "write to private field");
|
1635
1704
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1636
1705
|
return value;
|
@@ -1639,9 +1708,8 @@ var _map;
|
|
1639
1708
|
class SimpleCache {
|
1640
1709
|
constructor(options = {}) {
|
1641
1710
|
__privateAdd$3(this, _map, void 0);
|
1642
|
-
__privateSet$
|
1711
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1643
1712
|
this.capacity = options.max ?? 500;
|
1644
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1645
1713
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1646
1714
|
}
|
1647
1715
|
async getAll() {
|
@@ -1699,31 +1767,42 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1699
1767
|
throw TypeError("Cannot add the same private member more than once");
|
1700
1768
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1701
1769
|
};
|
1702
|
-
var
|
1770
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1771
|
+
__accessCheck$2(obj, member, "write to private field");
|
1772
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1773
|
+
return value;
|
1774
|
+
};
|
1775
|
+
var _tables, _schemaTables$1;
|
1703
1776
|
class SchemaPlugin extends XataPlugin {
|
1704
|
-
constructor(
|
1777
|
+
constructor(schemaTables) {
|
1705
1778
|
super();
|
1706
|
-
this.tableNames = tableNames;
|
1707
1779
|
__privateAdd$2(this, _tables, {});
|
1780
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
1781
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1708
1782
|
}
|
1709
1783
|
build(pluginOptions) {
|
1710
|
-
const db = new Proxy(
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1784
|
+
const db = new Proxy(
|
1785
|
+
{},
|
1786
|
+
{
|
1787
|
+
get: (_target, table) => {
|
1788
|
+
if (!isString(table))
|
1789
|
+
throw new Error("Invalid table name");
|
1790
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1791
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1792
|
+
}
|
1793
|
+
return __privateGet$2(this, _tables)[table];
|
1716
1794
|
}
|
1717
|
-
return __privateGet$2(this, _tables)[table];
|
1718
1795
|
}
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1796
|
+
);
|
1797
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1798
|
+
for (const table of tableNames) {
|
1799
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1722
1800
|
}
|
1723
1801
|
return db;
|
1724
1802
|
}
|
1725
1803
|
}
|
1726
1804
|
_tables = new WeakMap();
|
1805
|
+
_schemaTables$1 = new WeakMap();
|
1727
1806
|
|
1728
1807
|
var __accessCheck$1 = (obj, member, msg) => {
|
1729
1808
|
if (!member.has(obj))
|
@@ -1747,82 +1826,77 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
1747
1826
|
__accessCheck$1(obj, member, "access private method");
|
1748
1827
|
return method;
|
1749
1828
|
};
|
1750
|
-
var
|
1829
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
1751
1830
|
class SearchPlugin extends XataPlugin {
|
1752
|
-
constructor(db) {
|
1831
|
+
constructor(db, schemaTables) {
|
1753
1832
|
super();
|
1754
1833
|
this.db = db;
|
1755
1834
|
__privateAdd$1(this, _search);
|
1756
|
-
__privateAdd$1(this,
|
1757
|
-
__privateAdd$1(this,
|
1835
|
+
__privateAdd$1(this, _getSchemaTables);
|
1836
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
1837
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
1758
1838
|
}
|
1759
1839
|
build({ getFetchProps }) {
|
1760
1840
|
return {
|
1761
1841
|
all: async (query, options = {}) => {
|
1762
1842
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1763
|
-
const
|
1843
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1764
1844
|
return records.map((record) => {
|
1765
1845
|
const { table = "orphan" } = record.xata;
|
1766
|
-
return { table, record: initObject(this.db,
|
1846
|
+
return { table, record: initObject(this.db, schemaTables, table, record) };
|
1767
1847
|
});
|
1768
1848
|
},
|
1769
1849
|
byTable: async (query, options = {}) => {
|
1770
1850
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1771
|
-
const
|
1851
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1772
1852
|
return records.reduce((acc, record) => {
|
1773
1853
|
const { table = "orphan" } = record.xata;
|
1774
1854
|
const items = acc[table] ?? [];
|
1775
|
-
const item = initObject(this.db,
|
1855
|
+
const item = initObject(this.db, schemaTables, table, record);
|
1776
1856
|
return { ...acc, [table]: [...items, item] };
|
1777
1857
|
}, {});
|
1778
1858
|
}
|
1779
1859
|
};
|
1780
1860
|
}
|
1781
1861
|
}
|
1782
|
-
|
1862
|
+
_schemaTables = new WeakMap();
|
1783
1863
|
_search = new WeakSet();
|
1784
1864
|
search_fn = async function(query, options, getFetchProps) {
|
1785
1865
|
const fetchProps = await getFetchProps();
|
1786
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
1866
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1787
1867
|
const { records } = await searchBranch({
|
1788
1868
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1789
|
-
body: { tables, query, fuzziness, highlight },
|
1869
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1790
1870
|
...fetchProps
|
1791
1871
|
});
|
1792
1872
|
return records;
|
1793
1873
|
};
|
1794
|
-
|
1795
|
-
|
1796
|
-
if (__privateGet$1(this,
|
1797
|
-
return __privateGet$1(this,
|
1874
|
+
_getSchemaTables = new WeakSet();
|
1875
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
1876
|
+
if (__privateGet$1(this, _schemaTables))
|
1877
|
+
return __privateGet$1(this, _schemaTables);
|
1798
1878
|
const fetchProps = await getFetchProps();
|
1799
1879
|
const { schema } = await getBranchDetails({
|
1800
1880
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1801
1881
|
...fetchProps
|
1802
1882
|
});
|
1803
|
-
__privateSet$1(this,
|
1804
|
-
return schema;
|
1883
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
1884
|
+
return schema.tables;
|
1805
1885
|
};
|
1806
1886
|
|
1807
1887
|
const isBranchStrategyBuilder = (strategy) => {
|
1808
1888
|
return typeof strategy === "function";
|
1809
1889
|
};
|
1810
1890
|
|
1811
|
-
const envBranchNames = [
|
1812
|
-
"XATA_BRANCH",
|
1813
|
-
"VERCEL_GIT_COMMIT_REF",
|
1814
|
-
"CF_PAGES_BRANCH",
|
1815
|
-
"BRANCH"
|
1816
|
-
];
|
1817
1891
|
async function getCurrentBranchName(options) {
|
1818
|
-
const
|
1819
|
-
if (
|
1820
|
-
const details = await getDatabaseBranch(
|
1892
|
+
const { branch, envBranch } = getEnvironment();
|
1893
|
+
if (branch) {
|
1894
|
+
const details = await getDatabaseBranch(branch, options);
|
1821
1895
|
if (details)
|
1822
|
-
return
|
1823
|
-
console.warn(`Branch ${
|
1896
|
+
return branch;
|
1897
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1824
1898
|
}
|
1825
|
-
const gitBranch = await getGitBranch();
|
1899
|
+
const gitBranch = envBranch || await getGitBranch();
|
1826
1900
|
return resolveXataBranch(gitBranch, options);
|
1827
1901
|
}
|
1828
1902
|
async function getCurrentBranchDetails(options) {
|
@@ -1833,18 +1907,23 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1833
1907
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1834
1908
|
const apiKey = options?.apiKey || getAPIKey();
|
1835
1909
|
if (!databaseURL)
|
1836
|
-
throw new Error(
|
1910
|
+
throw new Error(
|
1911
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1912
|
+
);
|
1837
1913
|
if (!apiKey)
|
1838
|
-
throw new Error(
|
1914
|
+
throw new Error(
|
1915
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1916
|
+
);
|
1839
1917
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1840
1918
|
const [workspace] = host.split(".");
|
1919
|
+
const { fallbackBranch } = getEnvironment();
|
1841
1920
|
const { branch } = await resolveBranch({
|
1842
1921
|
apiKey,
|
1843
1922
|
apiUrl: databaseURL,
|
1844
1923
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1845
1924
|
workspacesApiUrl: `${protocol}//${host}`,
|
1846
1925
|
pathParams: { dbName, workspace },
|
1847
|
-
queryParams: { gitBranch, fallbackBranch
|
1926
|
+
queryParams: { gitBranch, fallbackBranch }
|
1848
1927
|
});
|
1849
1928
|
return branch;
|
1850
1929
|
}
|
@@ -1852,9 +1931,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1852
1931
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1853
1932
|
const apiKey = options?.apiKey || getAPIKey();
|
1854
1933
|
if (!databaseURL)
|
1855
|
-
throw new Error(
|
1934
|
+
throw new Error(
|
1935
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1936
|
+
);
|
1856
1937
|
if (!apiKey)
|
1857
|
-
throw new Error(
|
1938
|
+
throw new Error(
|
1939
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1940
|
+
);
|
1858
1941
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1859
1942
|
const [workspace] = host.split(".");
|
1860
1943
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1864,10 +1947,7 @@ async function getDatabaseBranch(branch, options) {
|
|
1864
1947
|
apiUrl: databaseURL,
|
1865
1948
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1866
1949
|
workspacesApiUrl: `${protocol}//${host}`,
|
1867
|
-
pathParams: {
|
1868
|
-
dbBranchName,
|
1869
|
-
workspace
|
1870
|
-
}
|
1950
|
+
pathParams: { dbBranchName, workspace }
|
1871
1951
|
});
|
1872
1952
|
} catch (err) {
|
1873
1953
|
if (isObject(err) && err.status === 404)
|
@@ -1875,21 +1955,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1875
1955
|
throw err;
|
1876
1956
|
}
|
1877
1957
|
}
|
1878
|
-
function getBranchByEnvVariable() {
|
1879
|
-
for (const name of envBranchNames) {
|
1880
|
-
const value = getEnvVariable(name);
|
1881
|
-
if (value) {
|
1882
|
-
return value;
|
1883
|
-
}
|
1884
|
-
}
|
1885
|
-
try {
|
1886
|
-
return XATA_BRANCH;
|
1887
|
-
} catch (err) {
|
1888
|
-
}
|
1889
|
-
}
|
1890
1958
|
function getDatabaseURL() {
|
1891
1959
|
try {
|
1892
|
-
|
1960
|
+
const { databaseURL } = getEnvironment();
|
1961
|
+
return databaseURL;
|
1893
1962
|
} catch (err) {
|
1894
1963
|
return void 0;
|
1895
1964
|
}
|
@@ -1918,20 +1987,22 @@ var __privateMethod = (obj, member, method) => {
|
|
1918
1987
|
return method;
|
1919
1988
|
};
|
1920
1989
|
const buildClient = (plugins) => {
|
1921
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1990
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1922
1991
|
return _a = class {
|
1923
|
-
constructor(options = {},
|
1992
|
+
constructor(options = {}, schemaTables) {
|
1924
1993
|
__privateAdd(this, _parseOptions);
|
1925
1994
|
__privateAdd(this, _getFetchProps);
|
1926
1995
|
__privateAdd(this, _evaluateBranch);
|
1927
1996
|
__privateAdd(this, _branch, void 0);
|
1997
|
+
__privateAdd(this, _options, void 0);
|
1928
1998
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
1999
|
+
__privateSet(this, _options, safeOptions);
|
1929
2000
|
const pluginOptions = {
|
1930
2001
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1931
2002
|
cache: safeOptions.cache
|
1932
2003
|
};
|
1933
|
-
const db = new SchemaPlugin(
|
1934
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
2004
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2005
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
1935
2006
|
this.db = db;
|
1936
2007
|
this.search = search;
|
1937
2008
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
@@ -1947,22 +2018,22 @@ const buildClient = (plugins) => {
|
|
1947
2018
|
}
|
1948
2019
|
}
|
1949
2020
|
}
|
1950
|
-
|
2021
|
+
async getConfig() {
|
2022
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2023
|
+
const branch = await __privateGet(this, _options).branch();
|
2024
|
+
return { databaseURL, branch };
|
2025
|
+
}
|
2026
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1951
2027
|
const fetch = getFetchImplementation(options?.fetch);
|
1952
2028
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1953
2029
|
const apiKey = options?.apiKey || getAPIKey();
|
1954
|
-
const cache = options?.cache ?? new SimpleCache({
|
2030
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
1955
2031
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1956
2032
|
if (!databaseURL || !apiKey) {
|
1957
2033
|
throw new Error("Options databaseURL and apiKey are required");
|
1958
2034
|
}
|
1959
2035
|
return { fetch, databaseURL, apiKey, branch, cache };
|
1960
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
1961
|
-
fetch,
|
1962
|
-
apiKey,
|
1963
|
-
databaseURL,
|
1964
|
-
branch
|
1965
|
-
}) {
|
2036
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
|
1966
2037
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
1967
2038
|
if (!branchValue)
|
1968
2039
|
throw new Error("Unable to resolve branch value");
|
@@ -1997,6 +2068,88 @@ const buildClient = (plugins) => {
|
|
1997
2068
|
class BaseClient extends buildClient() {
|
1998
2069
|
}
|
1999
2070
|
|
2071
|
+
const META = "__";
|
2072
|
+
const VALUE = "___";
|
2073
|
+
class Serializer {
|
2074
|
+
constructor() {
|
2075
|
+
this.classes = {};
|
2076
|
+
}
|
2077
|
+
add(clazz) {
|
2078
|
+
this.classes[clazz.name] = clazz;
|
2079
|
+
}
|
2080
|
+
toJSON(data) {
|
2081
|
+
function visit(obj) {
|
2082
|
+
if (Array.isArray(obj))
|
2083
|
+
return obj.map(visit);
|
2084
|
+
const type = typeof obj;
|
2085
|
+
if (type === "undefined")
|
2086
|
+
return { [META]: "undefined" };
|
2087
|
+
if (type === "bigint")
|
2088
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
2089
|
+
if (obj === null || type !== "object")
|
2090
|
+
return obj;
|
2091
|
+
const constructor = obj.constructor;
|
2092
|
+
const o = { [META]: constructor.name };
|
2093
|
+
for (const [key, value] of Object.entries(obj)) {
|
2094
|
+
o[key] = visit(value);
|
2095
|
+
}
|
2096
|
+
if (constructor === Date)
|
2097
|
+
o[VALUE] = obj.toISOString();
|
2098
|
+
if (constructor === Map)
|
2099
|
+
o[VALUE] = Object.fromEntries(obj);
|
2100
|
+
if (constructor === Set)
|
2101
|
+
o[VALUE] = [...obj];
|
2102
|
+
return o;
|
2103
|
+
}
|
2104
|
+
return JSON.stringify(visit(data));
|
2105
|
+
}
|
2106
|
+
fromJSON(json) {
|
2107
|
+
return JSON.parse(json, (key, value) => {
|
2108
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
2109
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
2110
|
+
const constructor = this.classes[clazz];
|
2111
|
+
if (constructor) {
|
2112
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
2113
|
+
}
|
2114
|
+
if (clazz === "Date")
|
2115
|
+
return new Date(val);
|
2116
|
+
if (clazz === "Set")
|
2117
|
+
return new Set(val);
|
2118
|
+
if (clazz === "Map")
|
2119
|
+
return new Map(Object.entries(val));
|
2120
|
+
if (clazz === "bigint")
|
2121
|
+
return BigInt(val);
|
2122
|
+
if (clazz === "undefined")
|
2123
|
+
return void 0;
|
2124
|
+
return rest;
|
2125
|
+
}
|
2126
|
+
return value;
|
2127
|
+
});
|
2128
|
+
}
|
2129
|
+
}
|
2130
|
+
const defaultSerializer = new Serializer();
|
2131
|
+
const serialize = (data) => {
|
2132
|
+
return defaultSerializer.toJSON(data);
|
2133
|
+
};
|
2134
|
+
const deserialize = (json) => {
|
2135
|
+
return defaultSerializer.fromJSON(json);
|
2136
|
+
};
|
2137
|
+
|
2138
|
+
function buildWorkerRunner(config) {
|
2139
|
+
return function xataWorker(name, _worker) {
|
2140
|
+
return async (...args) => {
|
2141
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2142
|
+
const result = await fetch(url, {
|
2143
|
+
method: "POST",
|
2144
|
+
headers: { "Content-Type": "application/json" },
|
2145
|
+
body: serialize({ args })
|
2146
|
+
});
|
2147
|
+
const text = await result.text();
|
2148
|
+
return deserialize(text);
|
2149
|
+
};
|
2150
|
+
};
|
2151
|
+
}
|
2152
|
+
|
2000
2153
|
class XataError extends Error {
|
2001
2154
|
constructor(message, status) {
|
2002
2155
|
super(message);
|
@@ -2004,5 +2157,5 @@ class XataError extends Error {
|
|
2004
2157
|
}
|
2005
2158
|
}
|
2006
2159
|
|
2007
|
-
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, updateWorkspaceMemberRole, upsertRecordWithID };
|
2160
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, 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, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2008
2161
|
//# sourceMappingURL=index.mjs.map
|