@xata.io/client 0.0.0-alpha.vfde9dcf → 0.0.0-alpha.vfef462e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +120 -0
- package/README.md +271 -1
- package/Usage.md +428 -0
- package/dist/index.cjs +423 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +685 -150
- package/dist/index.mjs +404 -283
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -4
package/dist/index.cjs
CHANGED
@@ -2,6 +2,24 @@
|
|
2
2
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
4
4
|
|
5
|
+
function _interopNamespace(e) {
|
6
|
+
if (e && e.__esModule) return e;
|
7
|
+
var n = Object.create(null);
|
8
|
+
if (e) {
|
9
|
+
Object.keys(e).forEach(function (k) {
|
10
|
+
if (k !== 'default') {
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () { return e[k]; }
|
15
|
+
});
|
16
|
+
}
|
17
|
+
});
|
18
|
+
}
|
19
|
+
n["default"] = e;
|
20
|
+
return Object.freeze(n);
|
21
|
+
}
|
22
|
+
|
5
23
|
function notEmpty(value) {
|
6
24
|
return value !== null && value !== void 0;
|
7
25
|
}
|
@@ -17,43 +35,95 @@ function isDefined(value) {
|
|
17
35
|
function isString(value) {
|
18
36
|
return isDefined(value) && typeof value === "string";
|
19
37
|
}
|
38
|
+
function isStringArray(value) {
|
39
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
40
|
+
}
|
20
41
|
function toBase64(value) {
|
21
42
|
try {
|
22
43
|
return btoa(value);
|
23
44
|
} catch (err) {
|
24
|
-
|
45
|
+
const buf = Buffer;
|
46
|
+
return buf.from(value).toString("base64");
|
25
47
|
}
|
26
48
|
}
|
27
49
|
|
28
|
-
function
|
50
|
+
function getEnvironment() {
|
29
51
|
try {
|
30
|
-
if (isObject(process) &&
|
31
|
-
return
|
52
|
+
if (isObject(process) && isObject(process.env)) {
|
53
|
+
return {
|
54
|
+
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
55
|
+
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
56
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
57
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
|
58
|
+
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
59
|
+
};
|
32
60
|
}
|
33
61
|
} catch (err) {
|
34
62
|
}
|
35
63
|
try {
|
36
|
-
if (isObject(Deno) &&
|
37
|
-
return
|
64
|
+
if (isObject(Deno) && isObject(Deno.env)) {
|
65
|
+
return {
|
66
|
+
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
67
|
+
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
68
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
69
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
|
70
|
+
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
71
|
+
};
|
38
72
|
}
|
39
73
|
} catch (err) {
|
40
74
|
}
|
75
|
+
return {
|
76
|
+
apiKey: getGlobalApiKey(),
|
77
|
+
databaseURL: getGlobalDatabaseURL(),
|
78
|
+
branch: getGlobalBranch(),
|
79
|
+
envBranch: void 0,
|
80
|
+
fallbackBranch: getGlobalFallbackBranch()
|
81
|
+
};
|
82
|
+
}
|
83
|
+
function getGlobalApiKey() {
|
84
|
+
try {
|
85
|
+
return XATA_API_KEY;
|
86
|
+
} catch (err) {
|
87
|
+
return void 0;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
function getGlobalDatabaseURL() {
|
91
|
+
try {
|
92
|
+
return XATA_DATABASE_URL;
|
93
|
+
} catch (err) {
|
94
|
+
return void 0;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
function getGlobalBranch() {
|
98
|
+
try {
|
99
|
+
return XATA_BRANCH;
|
100
|
+
} catch (err) {
|
101
|
+
return void 0;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
function getGlobalFallbackBranch() {
|
105
|
+
try {
|
106
|
+
return XATA_FALLBACK_BRANCH;
|
107
|
+
} catch (err) {
|
108
|
+
return void 0;
|
109
|
+
}
|
41
110
|
}
|
42
111
|
async function getGitBranch() {
|
112
|
+
const cmd = ["git", "branch", "--show-current"];
|
113
|
+
const fullCmd = cmd.join(" ");
|
114
|
+
const nodeModule = ["child", "process"].join("_");
|
115
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
43
116
|
try {
|
44
117
|
if (typeof require === "function") {
|
45
|
-
|
46
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
118
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
47
119
|
}
|
120
|
+
const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
|
121
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
48
122
|
} catch (err) {
|
49
123
|
}
|
50
124
|
try {
|
51
125
|
if (isObject(Deno)) {
|
52
|
-
const process2 = Deno.run({
|
53
|
-
cmd: ["git", "branch", "--show-current"],
|
54
|
-
stdout: "piped",
|
55
|
-
stderr: "piped"
|
56
|
-
});
|
126
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
57
127
|
return new TextDecoder().decode(await process2.output()).trim();
|
58
128
|
}
|
59
129
|
} catch (err) {
|
@@ -62,7 +132,8 @@ async function getGitBranch() {
|
|
62
132
|
|
63
133
|
function getAPIKey() {
|
64
134
|
try {
|
65
|
-
|
135
|
+
const { apiKey } = getEnvironment();
|
136
|
+
return apiKey;
|
66
137
|
} catch (err) {
|
67
138
|
return void 0;
|
68
139
|
}
|
@@ -72,21 +143,35 @@ function getFetchImplementation(userFetch) {
|
|
72
143
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
73
144
|
const fetchImpl = userFetch ?? globalFetch;
|
74
145
|
if (!fetchImpl) {
|
75
|
-
throw new Error(
|
146
|
+
throw new Error(
|
147
|
+
`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
|
148
|
+
);
|
76
149
|
}
|
77
150
|
return fetchImpl;
|
78
151
|
}
|
79
152
|
|
80
|
-
|
81
|
-
|
153
|
+
const VERSION = "0.0.0-alpha.vfef462e";
|
154
|
+
|
155
|
+
class ErrorWithCause extends Error {
|
156
|
+
constructor(message, options) {
|
157
|
+
super(message, options);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
class FetcherError extends ErrorWithCause {
|
161
|
+
constructor(status, data, requestId) {
|
82
162
|
super(getMessage(data));
|
83
163
|
this.status = status;
|
84
164
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
165
|
+
this.requestId = requestId;
|
85
166
|
if (data instanceof Error) {
|
86
167
|
this.stack = data.stack;
|
87
168
|
this.cause = data.cause;
|
88
169
|
}
|
89
170
|
}
|
171
|
+
toString() {
|
172
|
+
const error = super.toString();
|
173
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
174
|
+
}
|
90
175
|
}
|
91
176
|
function isBulkError(error) {
|
92
177
|
return isObject(error) && Array.isArray(error.errors);
|
@@ -109,7 +194,12 @@ function getMessage(data) {
|
|
109
194
|
}
|
110
195
|
|
111
196
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
112
|
-
const
|
197
|
+
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
198
|
+
if (value === void 0 || value === null)
|
199
|
+
return acc;
|
200
|
+
return { ...acc, [key]: value };
|
201
|
+
}, {});
|
202
|
+
const query = new URLSearchParams(cleanQueryParams).toString();
|
113
203
|
const queryString = query.length > 0 ? `?${query}` : "";
|
114
204
|
return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
|
115
205
|
};
|
@@ -149,6 +239,7 @@ async function fetch$1({
|
|
149
239
|
body: body ? JSON.stringify(body) : void 0,
|
150
240
|
headers: {
|
151
241
|
"Content-Type": "application/json",
|
242
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
152
243
|
...headers,
|
153
244
|
...hostHeader(fullUrl),
|
154
245
|
Authorization: `Bearer ${apiKey}`
|
@@ -157,14 +248,15 @@ async function fetch$1({
|
|
157
248
|
if (response.status === 204) {
|
158
249
|
return {};
|
159
250
|
}
|
251
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
160
252
|
try {
|
161
253
|
const jsonResponse = await response.json();
|
162
254
|
if (response.ok) {
|
163
255
|
return jsonResponse;
|
164
256
|
}
|
165
|
-
throw new FetcherError(response.status, jsonResponse);
|
257
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
166
258
|
} catch (error) {
|
167
|
-
throw new FetcherError(response.status, error);
|
259
|
+
throw new FetcherError(response.status, error, requestId);
|
168
260
|
}
|
169
261
|
}
|
170
262
|
|
@@ -223,6 +315,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
|
|
223
315
|
...variables
|
224
316
|
});
|
225
317
|
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
318
|
+
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
226
319
|
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
227
320
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
228
321
|
method: "delete",
|
@@ -271,11 +364,7 @@ const getBranchDetails = (variables) => fetch$1({
|
|
271
364
|
method: "get",
|
272
365
|
...variables
|
273
366
|
});
|
274
|
-
const createBranch = (variables) => fetch$1({
|
275
|
-
url: "/db/{dbBranchName}",
|
276
|
-
method: "put",
|
277
|
-
...variables
|
278
|
-
});
|
367
|
+
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
279
368
|
const deleteBranch = (variables) => fetch$1({
|
280
369
|
url: "/db/{dbBranchName}",
|
281
370
|
method: "delete",
|
@@ -349,11 +438,7 @@ const updateColumn = (variables) => fetch$1({
|
|
349
438
|
method: "patch",
|
350
439
|
...variables
|
351
440
|
});
|
352
|
-
const insertRecord = (variables) => fetch$1({
|
353
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
354
|
-
method: "post",
|
355
|
-
...variables
|
356
|
-
});
|
441
|
+
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
357
442
|
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
358
443
|
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
359
444
|
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
@@ -395,6 +480,7 @@ const operationsByTag = {
|
|
395
480
|
updateWorkspaceMemberRole,
|
396
481
|
removeWorkspaceMember,
|
397
482
|
inviteWorkspaceMember,
|
483
|
+
updateWorkspaceMemberInvite,
|
398
484
|
cancelWorkspaceMemberInvite,
|
399
485
|
resendWorkspaceMemberInvite,
|
400
486
|
acceptWorkspaceMemberInvite
|
@@ -484,7 +570,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
484
570
|
throw TypeError("Cannot add the same private member more than once");
|
485
571
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
486
572
|
};
|
487
|
-
var __privateSet$
|
573
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
488
574
|
__accessCheck$7(obj, member, "write to private field");
|
489
575
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
490
576
|
return value;
|
@@ -499,7 +585,7 @@ class XataApiClient {
|
|
499
585
|
if (!apiKey) {
|
500
586
|
throw new Error("Could not resolve a valid apiKey");
|
501
587
|
}
|
502
|
-
__privateSet$
|
588
|
+
__privateSet$7(this, _extraProps, {
|
503
589
|
apiUrl: getHostUrl(provider, "main"),
|
504
590
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
505
591
|
fetchImpl: getFetchImplementation(options.fetch),
|
@@ -626,6 +712,13 @@ class WorkspaceApi {
|
|
626
712
|
...this.extraProps
|
627
713
|
});
|
628
714
|
}
|
715
|
+
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
716
|
+
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
717
|
+
pathParams: { workspaceId, inviteId },
|
718
|
+
body: { role },
|
719
|
+
...this.extraProps
|
720
|
+
});
|
721
|
+
}
|
629
722
|
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
630
723
|
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
631
724
|
pathParams: { workspaceId, inviteId },
|
@@ -688,10 +781,10 @@ class DatabaseApi {
|
|
688
781
|
...this.extraProps
|
689
782
|
});
|
690
783
|
}
|
691
|
-
resolveBranch(workspace, dbName, gitBranch) {
|
784
|
+
resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
|
692
785
|
return operationsByTag.database.resolveBranch({
|
693
786
|
pathParams: { workspace, dbName },
|
694
|
-
queryParams: { gitBranch },
|
787
|
+
queryParams: { gitBranch, fallbackBranch },
|
695
788
|
...this.extraProps
|
696
789
|
});
|
697
790
|
}
|
@@ -840,9 +933,10 @@ class RecordsApi {
|
|
840
933
|
constructor(extraProps) {
|
841
934
|
this.extraProps = extraProps;
|
842
935
|
}
|
843
|
-
insertRecord(workspace, database, branch, tableName, record) {
|
936
|
+
insertRecord(workspace, database, branch, tableName, record, options = {}) {
|
844
937
|
return operationsByTag.records.insertRecord({
|
845
938
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
939
|
+
queryParams: options,
|
846
940
|
body: record,
|
847
941
|
...this.extraProps
|
848
942
|
});
|
@@ -871,21 +965,24 @@ class RecordsApi {
|
|
871
965
|
...this.extraProps
|
872
966
|
});
|
873
967
|
}
|
874
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
968
|
+
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
875
969
|
return operationsByTag.records.deleteRecord({
|
876
970
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
971
|
+
queryParams: options,
|
877
972
|
...this.extraProps
|
878
973
|
});
|
879
974
|
}
|
880
975
|
getRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
881
976
|
return operationsByTag.records.getRecord({
|
882
977
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
978
|
+
queryParams: options,
|
883
979
|
...this.extraProps
|
884
980
|
});
|
885
981
|
}
|
886
|
-
bulkInsertTableRecords(workspace, database, branch, tableName, records) {
|
982
|
+
bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
|
887
983
|
return operationsByTag.records.bulkInsertTableRecords({
|
888
984
|
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
985
|
+
queryParams: options,
|
889
986
|
body: { records },
|
890
987
|
...this.extraProps
|
891
988
|
});
|
@@ -936,18 +1033,18 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
936
1033
|
throw TypeError("Cannot add the same private member more than once");
|
937
1034
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
938
1035
|
};
|
939
|
-
var __privateSet$
|
1036
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
940
1037
|
__accessCheck$6(obj, member, "write to private field");
|
941
1038
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
942
1039
|
return value;
|
943
1040
|
};
|
944
|
-
var _query;
|
1041
|
+
var _query, _page;
|
945
1042
|
class Page {
|
946
1043
|
constructor(query, meta, records = []) {
|
947
1044
|
__privateAdd$6(this, _query, void 0);
|
948
|
-
__privateSet$
|
1045
|
+
__privateSet$6(this, _query, query);
|
949
1046
|
this.meta = meta;
|
950
|
-
this.records = records;
|
1047
|
+
this.records = new RecordArray(this, records);
|
951
1048
|
}
|
952
1049
|
async nextPage(size, offset) {
|
953
1050
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
@@ -967,12 +1064,56 @@ class Page {
|
|
967
1064
|
}
|
968
1065
|
_query = new WeakMap();
|
969
1066
|
const PAGINATION_MAX_SIZE = 200;
|
970
|
-
const PAGINATION_DEFAULT_SIZE =
|
1067
|
+
const PAGINATION_DEFAULT_SIZE = 20;
|
971
1068
|
const PAGINATION_MAX_OFFSET = 800;
|
972
1069
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
973
1070
|
function isCursorPaginationOptions(options) {
|
974
1071
|
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
975
1072
|
}
|
1073
|
+
const _RecordArray = class extends Array {
|
1074
|
+
constructor(...args) {
|
1075
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
1076
|
+
__privateAdd$6(this, _page, void 0);
|
1077
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
1078
|
+
}
|
1079
|
+
static parseConstructorParams(...args) {
|
1080
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
1081
|
+
return new Array(args[0]);
|
1082
|
+
}
|
1083
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
1084
|
+
const result = args[1] ?? args[0].records ?? [];
|
1085
|
+
return new Array(...result);
|
1086
|
+
}
|
1087
|
+
return new Array(...args);
|
1088
|
+
}
|
1089
|
+
toArray() {
|
1090
|
+
return new Array(...this);
|
1091
|
+
}
|
1092
|
+
map(callbackfn, thisArg) {
|
1093
|
+
return this.toArray().map(callbackfn, thisArg);
|
1094
|
+
}
|
1095
|
+
async nextPage(size, offset) {
|
1096
|
+
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1097
|
+
return new _RecordArray(newPage);
|
1098
|
+
}
|
1099
|
+
async previousPage(size, offset) {
|
1100
|
+
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1101
|
+
return new _RecordArray(newPage);
|
1102
|
+
}
|
1103
|
+
async firstPage(size, offset) {
|
1104
|
+
const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
|
1105
|
+
return new _RecordArray(newPage);
|
1106
|
+
}
|
1107
|
+
async lastPage(size, offset) {
|
1108
|
+
const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
|
1109
|
+
return new _RecordArray(newPage);
|
1110
|
+
}
|
1111
|
+
hasNextPage() {
|
1112
|
+
return __privateGet$6(this, _page).meta.page.more;
|
1113
|
+
}
|
1114
|
+
};
|
1115
|
+
let RecordArray = _RecordArray;
|
1116
|
+
_page = new WeakMap();
|
976
1117
|
|
977
1118
|
var __accessCheck$5 = (obj, member, msg) => {
|
978
1119
|
if (!member.has(obj))
|
@@ -987,25 +1128,26 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
987
1128
|
throw TypeError("Cannot add the same private member more than once");
|
988
1129
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
989
1130
|
};
|
990
|
-
var __privateSet$
|
1131
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
991
1132
|
__accessCheck$5(obj, member, "write to private field");
|
992
1133
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
993
1134
|
return value;
|
994
1135
|
};
|
995
1136
|
var _table$1, _repository, _data;
|
996
1137
|
const _Query = class {
|
997
|
-
constructor(repository, table, data,
|
1138
|
+
constructor(repository, table, data, rawParent) {
|
998
1139
|
__privateAdd$5(this, _table$1, void 0);
|
999
1140
|
__privateAdd$5(this, _repository, void 0);
|
1000
1141
|
__privateAdd$5(this, _data, { filter: {} });
|
1001
1142
|
this.meta = { page: { cursor: "start", more: true } };
|
1002
|
-
this.records = [];
|
1003
|
-
__privateSet$
|
1143
|
+
this.records = new RecordArray(this, []);
|
1144
|
+
__privateSet$5(this, _table$1, table);
|
1004
1145
|
if (repository) {
|
1005
|
-
__privateSet$
|
1146
|
+
__privateSet$5(this, _repository, repository);
|
1006
1147
|
} else {
|
1007
|
-
__privateSet$
|
1148
|
+
__privateSet$5(this, _repository, this);
|
1008
1149
|
}
|
1150
|
+
const parent = cleanParent(data, rawParent);
|
1009
1151
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
1010
1152
|
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
1011
1153
|
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
@@ -1064,7 +1206,12 @@ const _Query = class {
|
|
1064
1206
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1065
1207
|
}
|
1066
1208
|
select(columns) {
|
1067
|
-
return new _Query(
|
1209
|
+
return new _Query(
|
1210
|
+
__privateGet$5(this, _repository),
|
1211
|
+
__privateGet$5(this, _table$1),
|
1212
|
+
{ columns },
|
1213
|
+
__privateGet$5(this, _data)
|
1214
|
+
);
|
1068
1215
|
}
|
1069
1216
|
getPaginated(options = {}) {
|
1070
1217
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1087,8 +1234,11 @@ const _Query = class {
|
|
1087
1234
|
}
|
1088
1235
|
}
|
1089
1236
|
async getMany(options = {}) {
|
1090
|
-
const
|
1091
|
-
|
1237
|
+
const page = await this.getPaginated(options);
|
1238
|
+
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1239
|
+
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1240
|
+
}
|
1241
|
+
return page.records;
|
1092
1242
|
}
|
1093
1243
|
async getAll(options = {}) {
|
1094
1244
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1125,12 +1275,20 @@ let Query = _Query;
|
|
1125
1275
|
_table$1 = new WeakMap();
|
1126
1276
|
_repository = new WeakMap();
|
1127
1277
|
_data = new WeakMap();
|
1278
|
+
function cleanParent(data, parent) {
|
1279
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
1280
|
+
return { ...parent, sorting: void 0, filter: void 0 };
|
1281
|
+
}
|
1282
|
+
return parent;
|
1283
|
+
}
|
1128
1284
|
|
1129
1285
|
function isIdentifiable(x) {
|
1130
1286
|
return isObject(x) && isString(x?.id);
|
1131
1287
|
}
|
1132
1288
|
function isXataRecord(x) {
|
1133
|
-
|
1289
|
+
const record = x;
|
1290
|
+
const metadata = record?.getMetadata();
|
1291
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
1134
1292
|
}
|
1135
1293
|
|
1136
1294
|
function isSortFilterString(value) {
|
@@ -1169,7 +1327,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
1169
1327
|
throw TypeError("Cannot add the same private member more than once");
|
1170
1328
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1171
1329
|
};
|
1172
|
-
var __privateSet$
|
1330
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
1173
1331
|
__accessCheck$4(obj, member, "write to private field");
|
1174
1332
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1175
1333
|
return value;
|
@@ -1178,7 +1336,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1178
1336
|
__accessCheck$4(obj, member, "access private method");
|
1179
1337
|
return method;
|
1180
1338
|
};
|
1181
|
-
var _table, _getFetchProps, _cache,
|
1339
|
+
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;
|
1182
1340
|
class Repository extends Query {
|
1183
1341
|
}
|
1184
1342
|
class RestRepository extends Query {
|
@@ -1190,111 +1348,122 @@ class RestRepository extends Query {
|
|
1190
1348
|
__privateAdd$4(this, _updateRecordWithID);
|
1191
1349
|
__privateAdd$4(this, _upsertRecordWithID);
|
1192
1350
|
__privateAdd$4(this, _deleteRecord);
|
1193
|
-
__privateAdd$4(this, _invalidateCache);
|
1194
|
-
__privateAdd$4(this, _setCacheRecord);
|
1195
|
-
__privateAdd$4(this, _getCacheRecord);
|
1196
1351
|
__privateAdd$4(this, _setCacheQuery);
|
1197
1352
|
__privateAdd$4(this, _getCacheQuery);
|
1198
|
-
__privateAdd$4(this,
|
1353
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
1199
1354
|
__privateAdd$4(this, _table, void 0);
|
1200
1355
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1356
|
+
__privateAdd$4(this, _db, void 0);
|
1201
1357
|
__privateAdd$4(this, _cache, void 0);
|
1202
|
-
__privateAdd$4(this,
|
1203
|
-
__privateSet$
|
1204
|
-
__privateSet$
|
1205
|
-
this
|
1206
|
-
__privateSet$
|
1207
|
-
|
1208
|
-
|
1358
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
1359
|
+
__privateSet$4(this, _table, options.table);
|
1360
|
+
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1361
|
+
__privateSet$4(this, _db, options.db);
|
1362
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1363
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
1364
|
+
}
|
1365
|
+
async create(a, b, c) {
|
1209
1366
|
if (Array.isArray(a)) {
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1367
|
+
if (a.length === 0)
|
1368
|
+
return [];
|
1369
|
+
const columns = isStringArray(b) ? b : void 0;
|
1370
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
1213
1371
|
}
|
1214
1372
|
if (isString(a) && isObject(b)) {
|
1215
1373
|
if (a === "")
|
1216
1374
|
throw new Error("The id can't be empty");
|
1217
|
-
const
|
1218
|
-
|
1219
|
-
return record;
|
1375
|
+
const columns = isStringArray(c) ? c : void 0;
|
1376
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
1220
1377
|
}
|
1221
1378
|
if (isObject(a) && isString(a.id)) {
|
1222
1379
|
if (a.id === "")
|
1223
1380
|
throw new Error("The id can't be empty");
|
1224
|
-
const
|
1225
|
-
|
1226
|
-
return record;
|
1381
|
+
const columns = isStringArray(b) ? b : void 0;
|
1382
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1227
1383
|
}
|
1228
1384
|
if (isObject(a)) {
|
1229
|
-
const
|
1230
|
-
|
1231
|
-
return record;
|
1385
|
+
const columns = isStringArray(b) ? b : void 0;
|
1386
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1232
1387
|
}
|
1233
1388
|
throw new Error("Invalid arguments for create method");
|
1234
1389
|
}
|
1235
|
-
async read(
|
1236
|
-
const
|
1237
|
-
if (
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
const
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
return
|
1247
|
-
}
|
1248
|
-
|
1249
|
-
|
1390
|
+
async read(a, b) {
|
1391
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1392
|
+
if (Array.isArray(a)) {
|
1393
|
+
if (a.length === 0)
|
1394
|
+
return [];
|
1395
|
+
const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
|
1396
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
1397
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
1398
|
+
acc[object.id] = object;
|
1399
|
+
return acc;
|
1400
|
+
}, {});
|
1401
|
+
return ids.map((id2) => dictionary[id2] ?? null);
|
1402
|
+
}
|
1403
|
+
const id = isString(a) ? a : a.id;
|
1404
|
+
if (isString(id)) {
|
1405
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1406
|
+
try {
|
1407
|
+
const response = await getRecord({
|
1408
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
|
1409
|
+
queryParams: { columns },
|
1410
|
+
...fetchProps
|
1411
|
+
});
|
1412
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1413
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1414
|
+
} catch (e) {
|
1415
|
+
if (isObject(e) && e.status === 404) {
|
1416
|
+
return null;
|
1417
|
+
}
|
1418
|
+
throw e;
|
1250
1419
|
}
|
1251
|
-
throw e;
|
1252
1420
|
}
|
1421
|
+
return null;
|
1253
1422
|
}
|
1254
|
-
async update(a, b) {
|
1423
|
+
async update(a, b, c) {
|
1255
1424
|
if (Array.isArray(a)) {
|
1425
|
+
if (a.length === 0)
|
1426
|
+
return [];
|
1256
1427
|
if (a.length > 100) {
|
1257
1428
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1258
1429
|
}
|
1259
|
-
|
1430
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1431
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
1260
1432
|
}
|
1261
1433
|
if (isString(a) && isObject(b)) {
|
1262
|
-
|
1263
|
-
|
1264
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1265
|
-
return record;
|
1434
|
+
const columns = isStringArray(c) ? c : void 0;
|
1435
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1266
1436
|
}
|
1267
1437
|
if (isObject(a) && isString(a.id)) {
|
1268
|
-
|
1269
|
-
|
1270
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1271
|
-
return record;
|
1438
|
+
const columns = isStringArray(b) ? b : void 0;
|
1439
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1272
1440
|
}
|
1273
1441
|
throw new Error("Invalid arguments for update method");
|
1274
1442
|
}
|
1275
|
-
async createOrUpdate(a, b) {
|
1443
|
+
async createOrUpdate(a, b, c) {
|
1276
1444
|
if (Array.isArray(a)) {
|
1445
|
+
if (a.length === 0)
|
1446
|
+
return [];
|
1277
1447
|
if (a.length > 100) {
|
1278
1448
|
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1279
1449
|
}
|
1280
|
-
|
1450
|
+
const columns = isStringArray(b) ? b : ["*"];
|
1451
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
1281
1452
|
}
|
1282
1453
|
if (isString(a) && isObject(b)) {
|
1283
|
-
|
1284
|
-
|
1285
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1286
|
-
return record;
|
1454
|
+
const columns = isStringArray(c) ? c : void 0;
|
1455
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1287
1456
|
}
|
1288
1457
|
if (isObject(a) && isString(a.id)) {
|
1289
|
-
|
1290
|
-
|
1291
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1292
|
-
return record;
|
1458
|
+
const columns = isStringArray(c) ? c : void 0;
|
1459
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1293
1460
|
}
|
1294
1461
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1295
1462
|
}
|
1296
1463
|
async delete(a) {
|
1297
1464
|
if (Array.isArray(a)) {
|
1465
|
+
if (a.length === 0)
|
1466
|
+
return;
|
1298
1467
|
if (a.length > 100) {
|
1299
1468
|
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1300
1469
|
}
|
@@ -1303,12 +1472,10 @@ class RestRepository extends Query {
|
|
1303
1472
|
}
|
1304
1473
|
if (isString(a)) {
|
1305
1474
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
|
1306
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1307
1475
|
return;
|
1308
1476
|
}
|
1309
1477
|
if (isObject(a) && isString(a.id)) {
|
1310
1478
|
await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
|
1311
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1312
1479
|
return;
|
1313
1480
|
}
|
1314
1481
|
throw new Error("Invalid arguments for delete method");
|
@@ -1320,24 +1487,24 @@ class RestRepository extends Query {
|
|
1320
1487
|
body: {
|
1321
1488
|
query,
|
1322
1489
|
fuzziness: options.fuzziness,
|
1323
|
-
|
1490
|
+
prefix: options.prefix,
|
1491
|
+
highlight: options.highlight,
|
1492
|
+
filter: options.filter,
|
1493
|
+
boosters: options.boosters
|
1324
1494
|
},
|
1325
1495
|
...fetchProps
|
1326
1496
|
});
|
1327
|
-
const
|
1328
|
-
return records.map((item) => initObject(this
|
1497
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1498
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1329
1499
|
}
|
1330
1500
|
async query(query) {
|
1331
1501
|
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
1332
1502
|
if (cacheQuery)
|
1333
1503
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1334
1504
|
const data = query.getQueryOptions();
|
1335
|
-
const filter = Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0;
|
1336
|
-
const sort = data.sort !== void 0 ? buildSortFilter(data.sort) : void 0;
|
1337
|
-
const isCursorPagination = isCursorPaginationOptions(data.pagination);
|
1338
1505
|
const body = {
|
1339
|
-
filter:
|
1340
|
-
sort:
|
1506
|
+
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1507
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1341
1508
|
page: data.pagination,
|
1342
1509
|
columns: data.columns
|
1343
1510
|
};
|
@@ -1347,18 +1514,19 @@ class RestRepository extends Query {
|
|
1347
1514
|
body,
|
1348
1515
|
...fetchProps
|
1349
1516
|
});
|
1350
|
-
const
|
1351
|
-
const records = objects.map((record) => initObject(this
|
1517
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1518
|
+
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1352
1519
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1353
1520
|
return new Page(query, meta, records);
|
1354
1521
|
}
|
1355
1522
|
}
|
1356
1523
|
_table = new WeakMap();
|
1357
1524
|
_getFetchProps = new WeakMap();
|
1525
|
+
_db = new WeakMap();
|
1358
1526
|
_cache = new WeakMap();
|
1359
|
-
|
1527
|
+
_schemaTables$2 = new WeakMap();
|
1360
1528
|
_insertRecordWithoutId = new WeakSet();
|
1361
|
-
insertRecordWithoutId_fn = async function(object) {
|
1529
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1362
1530
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1363
1531
|
const record = transformObjectLinks(object);
|
1364
1532
|
const response = await insertRecord({
|
@@ -1367,17 +1535,15 @@ insertRecordWithoutId_fn = async function(object) {
|
|
1367
1535
|
dbBranchName: "{dbBranch}",
|
1368
1536
|
tableName: __privateGet$4(this, _table)
|
1369
1537
|
},
|
1538
|
+
queryParams: { columns },
|
1370
1539
|
body: record,
|
1371
1540
|
...fetchProps
|
1372
1541
|
});
|
1373
|
-
const
|
1374
|
-
|
1375
|
-
throw new Error("The server failed to save the record");
|
1376
|
-
}
|
1377
|
-
return finalObject;
|
1542
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1543
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1378
1544
|
};
|
1379
1545
|
_insertRecordWithId = new WeakSet();
|
1380
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
1546
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1381
1547
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1382
1548
|
const record = transformObjectLinks(object);
|
1383
1549
|
const response = await insertRecordWithID({
|
@@ -1388,56 +1554,52 @@ insertRecordWithId_fn = async function(recordId, object) {
|
|
1388
1554
|
recordId
|
1389
1555
|
},
|
1390
1556
|
body: record,
|
1391
|
-
queryParams: { createOnly: true },
|
1557
|
+
queryParams: { createOnly: true, columns },
|
1392
1558
|
...fetchProps
|
1393
1559
|
});
|
1394
|
-
const
|
1395
|
-
|
1396
|
-
throw new Error("The server failed to save the record");
|
1397
|
-
}
|
1398
|
-
return finalObject;
|
1560
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1561
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1399
1562
|
};
|
1400
1563
|
_bulkInsertTableRecords = new WeakSet();
|
1401
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
1564
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
1402
1565
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1403
1566
|
const records = objects.map((object) => transformObjectLinks(object));
|
1404
1567
|
const response = await bulkInsertTableRecords({
|
1405
1568
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1569
|
+
queryParams: { columns },
|
1406
1570
|
body: { records },
|
1407
1571
|
...fetchProps
|
1408
1572
|
});
|
1409
|
-
|
1410
|
-
|
1411
|
-
throw new Error("The server failed to save some records");
|
1573
|
+
if (!isResponseWithRecords(response)) {
|
1574
|
+
throw new Error("Request included columns but server didn't include them");
|
1412
1575
|
}
|
1413
|
-
|
1576
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1577
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1414
1578
|
};
|
1415
1579
|
_updateRecordWithID = new WeakSet();
|
1416
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
1580
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1417
1581
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1418
1582
|
const record = transformObjectLinks(object);
|
1419
1583
|
const response = await updateRecordWithID({
|
1420
1584
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1585
|
+
queryParams: { columns },
|
1421
1586
|
body: record,
|
1422
1587
|
...fetchProps
|
1423
1588
|
});
|
1424
|
-
const
|
1425
|
-
|
1426
|
-
throw new Error("The server failed to save the record");
|
1427
|
-
return item;
|
1589
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1590
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1428
1591
|
};
|
1429
1592
|
_upsertRecordWithID = new WeakSet();
|
1430
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
1593
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1431
1594
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1432
1595
|
const response = await upsertRecordWithID({
|
1433
1596
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1597
|
+
queryParams: { columns },
|
1434
1598
|
body: object,
|
1435
1599
|
...fetchProps
|
1436
1600
|
});
|
1437
|
-
const
|
1438
|
-
|
1439
|
-
throw new Error("The server failed to save the record");
|
1440
|
-
return item;
|
1601
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1602
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1441
1603
|
};
|
1442
1604
|
_deleteRecord = new WeakSet();
|
1443
1605
|
deleteRecord_fn = async function(recordId) {
|
@@ -1447,29 +1609,6 @@ deleteRecord_fn = async function(recordId) {
|
|
1447
1609
|
...fetchProps
|
1448
1610
|
});
|
1449
1611
|
};
|
1450
|
-
_invalidateCache = new WeakSet();
|
1451
|
-
invalidateCache_fn = async function(recordId) {
|
1452
|
-
await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1453
|
-
const cacheItems = await __privateGet$4(this, _cache).getAll();
|
1454
|
-
const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
|
1455
|
-
for (const [key, value] of queries) {
|
1456
|
-
const ids = getIds(value);
|
1457
|
-
if (ids.includes(recordId))
|
1458
|
-
await __privateGet$4(this, _cache).delete(key);
|
1459
|
-
}
|
1460
|
-
};
|
1461
|
-
_setCacheRecord = new WeakSet();
|
1462
|
-
setCacheRecord_fn = async function(record) {
|
1463
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1464
|
-
return;
|
1465
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
1466
|
-
};
|
1467
|
-
_getCacheRecord = new WeakSet();
|
1468
|
-
getCacheRecord_fn = async function(recordId) {
|
1469
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1470
|
-
return null;
|
1471
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
1472
|
-
};
|
1473
1612
|
_setCacheQuery = new WeakSet();
|
1474
1613
|
setCacheQuery_fn = async function(query, meta, records) {
|
1475
1614
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
@@ -1486,17 +1625,17 @@ getCacheQuery_fn = async function(query) {
|
|
1486
1625
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
1487
1626
|
return hasExpired ? null : result;
|
1488
1627
|
};
|
1489
|
-
|
1490
|
-
|
1491
|
-
if (__privateGet$4(this,
|
1492
|
-
return __privateGet$4(this,
|
1628
|
+
_getSchemaTables$1 = new WeakSet();
|
1629
|
+
getSchemaTables_fn$1 = async function() {
|
1630
|
+
if (__privateGet$4(this, _schemaTables$2))
|
1631
|
+
return __privateGet$4(this, _schemaTables$2);
|
1493
1632
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1494
1633
|
const { schema } = await getBranchDetails({
|
1495
1634
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1496
1635
|
...fetchProps
|
1497
1636
|
});
|
1498
|
-
__privateSet$
|
1499
|
-
return schema;
|
1637
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1638
|
+
return schema.tables;
|
1500
1639
|
};
|
1501
1640
|
const transformObjectLinks = (object) => {
|
1502
1641
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
@@ -1505,20 +1644,21 @@ const transformObjectLinks = (object) => {
|
|
1505
1644
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1506
1645
|
}, {});
|
1507
1646
|
};
|
1508
|
-
const initObject = (db,
|
1647
|
+
const initObject = (db, schemaTables, table, object) => {
|
1509
1648
|
const result = {};
|
1510
|
-
|
1511
|
-
|
1649
|
+
const { xata, ...rest } = object ?? {};
|
1650
|
+
Object.assign(result, rest);
|
1651
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1512
1652
|
if (!columns)
|
1513
1653
|
console.error(`Table ${table} not found in schema`);
|
1514
1654
|
for (const column of columns ?? []) {
|
1515
1655
|
const value = result[column.name];
|
1516
1656
|
switch (column.type) {
|
1517
1657
|
case "datetime": {
|
1518
|
-
const date = new Date(value);
|
1519
|
-
if (isNaN(date.getTime())) {
|
1658
|
+
const date = value !== void 0 ? new Date(value) : void 0;
|
1659
|
+
if (date && isNaN(date.getTime())) {
|
1520
1660
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1521
|
-
} else {
|
1661
|
+
} else if (date) {
|
1522
1662
|
result[column.name] = date;
|
1523
1663
|
}
|
1524
1664
|
break;
|
@@ -1528,35 +1668,32 @@ const initObject = (db, schema, table, object) => {
|
|
1528
1668
|
if (!linkTable) {
|
1529
1669
|
console.error(`Failed to parse link for field ${column.name}`);
|
1530
1670
|
} else if (isObject(value)) {
|
1531
|
-
result[column.name] = initObject(db,
|
1671
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
1532
1672
|
}
|
1533
1673
|
break;
|
1534
1674
|
}
|
1535
1675
|
}
|
1536
1676
|
}
|
1537
|
-
result.read = function() {
|
1538
|
-
return db[table].read(result["id"]);
|
1677
|
+
result.read = function(columns2) {
|
1678
|
+
return db[table].read(result["id"], columns2);
|
1539
1679
|
};
|
1540
|
-
result.update = function(data) {
|
1541
|
-
return db[table].update(result["id"], data);
|
1680
|
+
result.update = function(data, columns2) {
|
1681
|
+
return db[table].update(result["id"], data, columns2);
|
1542
1682
|
};
|
1543
1683
|
result.delete = function() {
|
1544
1684
|
return db[table].delete(result["id"]);
|
1545
1685
|
};
|
1546
|
-
|
1686
|
+
result.getMetadata = function() {
|
1687
|
+
return xata;
|
1688
|
+
};
|
1689
|
+
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
1547
1690
|
Object.defineProperty(result, prop, { enumerable: false });
|
1548
1691
|
}
|
1549
1692
|
Object.freeze(result);
|
1550
1693
|
return result;
|
1551
1694
|
};
|
1552
|
-
function
|
1553
|
-
|
1554
|
-
return value.map((item) => getIds(item)).flat();
|
1555
|
-
}
|
1556
|
-
if (!isObject(value))
|
1557
|
-
return [];
|
1558
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1559
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
1695
|
+
function isResponseWithRecords(value) {
|
1696
|
+
return isObject(value) && Array.isArray(value.records);
|
1560
1697
|
}
|
1561
1698
|
|
1562
1699
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1572,7 +1709,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
1572
1709
|
throw TypeError("Cannot add the same private member more than once");
|
1573
1710
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1574
1711
|
};
|
1575
|
-
var __privateSet$
|
1712
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
1576
1713
|
__accessCheck$3(obj, member, "write to private field");
|
1577
1714
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1578
1715
|
return value;
|
@@ -1581,9 +1718,8 @@ var _map;
|
|
1581
1718
|
class SimpleCache {
|
1582
1719
|
constructor(options = {}) {
|
1583
1720
|
__privateAdd$3(this, _map, void 0);
|
1584
|
-
__privateSet$
|
1721
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1585
1722
|
this.capacity = options.max ?? 500;
|
1586
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1587
1723
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1588
1724
|
}
|
1589
1725
|
async getAll() {
|
@@ -1641,31 +1777,42 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
1641
1777
|
throw TypeError("Cannot add the same private member more than once");
|
1642
1778
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
1643
1779
|
};
|
1644
|
-
var
|
1780
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
1781
|
+
__accessCheck$2(obj, member, "write to private field");
|
1782
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
1783
|
+
return value;
|
1784
|
+
};
|
1785
|
+
var _tables, _schemaTables$1;
|
1645
1786
|
class SchemaPlugin extends XataPlugin {
|
1646
|
-
constructor(
|
1787
|
+
constructor(schemaTables) {
|
1647
1788
|
super();
|
1648
|
-
this.tableNames = tableNames;
|
1649
1789
|
__privateAdd$2(this, _tables, {});
|
1790
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
1791
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1650
1792
|
}
|
1651
1793
|
build(pluginOptions) {
|
1652
|
-
const db = new Proxy(
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1794
|
+
const db = new Proxy(
|
1795
|
+
{},
|
1796
|
+
{
|
1797
|
+
get: (_target, table) => {
|
1798
|
+
if (!isString(table))
|
1799
|
+
throw new Error("Invalid table name");
|
1800
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
1801
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1802
|
+
}
|
1803
|
+
return __privateGet$2(this, _tables)[table];
|
1658
1804
|
}
|
1659
|
-
return __privateGet$2(this, _tables)[table];
|
1660
1805
|
}
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1806
|
+
);
|
1807
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1808
|
+
for (const table of tableNames) {
|
1809
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
1664
1810
|
}
|
1665
1811
|
return db;
|
1666
1812
|
}
|
1667
1813
|
}
|
1668
1814
|
_tables = new WeakMap();
|
1815
|
+
_schemaTables$1 = new WeakMap();
|
1669
1816
|
|
1670
1817
|
var __accessCheck$1 = (obj, member, msg) => {
|
1671
1818
|
if (!member.has(obj))
|
@@ -1689,82 +1836,77 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
1689
1836
|
__accessCheck$1(obj, member, "access private method");
|
1690
1837
|
return method;
|
1691
1838
|
};
|
1692
|
-
var
|
1839
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
1693
1840
|
class SearchPlugin extends XataPlugin {
|
1694
|
-
constructor(db) {
|
1841
|
+
constructor(db, schemaTables) {
|
1695
1842
|
super();
|
1696
1843
|
this.db = db;
|
1697
1844
|
__privateAdd$1(this, _search);
|
1698
|
-
__privateAdd$1(this,
|
1699
|
-
__privateAdd$1(this,
|
1845
|
+
__privateAdd$1(this, _getSchemaTables);
|
1846
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
1847
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
1700
1848
|
}
|
1701
1849
|
build({ getFetchProps }) {
|
1702
1850
|
return {
|
1703
1851
|
all: async (query, options = {}) => {
|
1704
1852
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1705
|
-
const
|
1853
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1706
1854
|
return records.map((record) => {
|
1707
1855
|
const { table = "orphan" } = record.xata;
|
1708
|
-
return { table, record: initObject(this.db,
|
1856
|
+
return { table, record: initObject(this.db, schemaTables, table, record) };
|
1709
1857
|
});
|
1710
1858
|
},
|
1711
1859
|
byTable: async (query, options = {}) => {
|
1712
1860
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
1713
|
-
const
|
1861
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1714
1862
|
return records.reduce((acc, record) => {
|
1715
1863
|
const { table = "orphan" } = record.xata;
|
1716
1864
|
const items = acc[table] ?? [];
|
1717
|
-
const item = initObject(this.db,
|
1865
|
+
const item = initObject(this.db, schemaTables, table, record);
|
1718
1866
|
return { ...acc, [table]: [...items, item] };
|
1719
1867
|
}, {});
|
1720
1868
|
}
|
1721
1869
|
};
|
1722
1870
|
}
|
1723
1871
|
}
|
1724
|
-
|
1872
|
+
_schemaTables = new WeakMap();
|
1725
1873
|
_search = new WeakSet();
|
1726
1874
|
search_fn = async function(query, options, getFetchProps) {
|
1727
1875
|
const fetchProps = await getFetchProps();
|
1728
|
-
const { tables, fuzziness } = options ?? {};
|
1876
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1729
1877
|
const { records } = await searchBranch({
|
1730
1878
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1731
|
-
body: { tables, query, fuzziness },
|
1879
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1732
1880
|
...fetchProps
|
1733
1881
|
});
|
1734
1882
|
return records;
|
1735
1883
|
};
|
1736
|
-
|
1737
|
-
|
1738
|
-
if (__privateGet$1(this,
|
1739
|
-
return __privateGet$1(this,
|
1884
|
+
_getSchemaTables = new WeakSet();
|
1885
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
1886
|
+
if (__privateGet$1(this, _schemaTables))
|
1887
|
+
return __privateGet$1(this, _schemaTables);
|
1740
1888
|
const fetchProps = await getFetchProps();
|
1741
1889
|
const { schema } = await getBranchDetails({
|
1742
1890
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1743
1891
|
...fetchProps
|
1744
1892
|
});
|
1745
|
-
__privateSet$1(this,
|
1746
|
-
return schema;
|
1893
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
1894
|
+
return schema.tables;
|
1747
1895
|
};
|
1748
1896
|
|
1749
1897
|
const isBranchStrategyBuilder = (strategy) => {
|
1750
1898
|
return typeof strategy === "function";
|
1751
1899
|
};
|
1752
1900
|
|
1753
|
-
const envBranchNames = [
|
1754
|
-
"XATA_BRANCH",
|
1755
|
-
"VERCEL_GIT_COMMIT_REF",
|
1756
|
-
"CF_PAGES_BRANCH",
|
1757
|
-
"BRANCH"
|
1758
|
-
];
|
1759
1901
|
async function getCurrentBranchName(options) {
|
1760
|
-
const
|
1761
|
-
if (
|
1762
|
-
const details = await getDatabaseBranch(
|
1902
|
+
const { branch, envBranch } = getEnvironment();
|
1903
|
+
if (branch) {
|
1904
|
+
const details = await getDatabaseBranch(branch, options);
|
1763
1905
|
if (details)
|
1764
|
-
return
|
1765
|
-
console.warn(`Branch ${
|
1906
|
+
return branch;
|
1907
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1766
1908
|
}
|
1767
|
-
const gitBranch = await getGitBranch();
|
1909
|
+
const gitBranch = envBranch || await getGitBranch();
|
1768
1910
|
return resolveXataBranch(gitBranch, options);
|
1769
1911
|
}
|
1770
1912
|
async function getCurrentBranchDetails(options) {
|
@@ -1775,18 +1917,23 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1775
1917
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1776
1918
|
const apiKey = options?.apiKey || getAPIKey();
|
1777
1919
|
if (!databaseURL)
|
1778
|
-
throw new Error(
|
1920
|
+
throw new Error(
|
1921
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1922
|
+
);
|
1779
1923
|
if (!apiKey)
|
1780
|
-
throw new Error(
|
1924
|
+
throw new Error(
|
1925
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1926
|
+
);
|
1781
1927
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1782
1928
|
const [workspace] = host.split(".");
|
1929
|
+
const { fallbackBranch } = getEnvironment();
|
1783
1930
|
const { branch } = await resolveBranch({
|
1784
1931
|
apiKey,
|
1785
1932
|
apiUrl: databaseURL,
|
1786
1933
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1787
1934
|
workspacesApiUrl: `${protocol}//${host}`,
|
1788
1935
|
pathParams: { dbName, workspace },
|
1789
|
-
queryParams: { gitBranch, fallbackBranch
|
1936
|
+
queryParams: { gitBranch, fallbackBranch }
|
1790
1937
|
});
|
1791
1938
|
return branch;
|
1792
1939
|
}
|
@@ -1794,9 +1941,13 @@ async function getDatabaseBranch(branch, options) {
|
|
1794
1941
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1795
1942
|
const apiKey = options?.apiKey || getAPIKey();
|
1796
1943
|
if (!databaseURL)
|
1797
|
-
throw new Error(
|
1944
|
+
throw new Error(
|
1945
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1946
|
+
);
|
1798
1947
|
if (!apiKey)
|
1799
|
-
throw new Error(
|
1948
|
+
throw new Error(
|
1949
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1950
|
+
);
|
1800
1951
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1801
1952
|
const [workspace] = host.split(".");
|
1802
1953
|
const dbBranchName = `${database}:${branch}`;
|
@@ -1806,10 +1957,7 @@ async function getDatabaseBranch(branch, options) {
|
|
1806
1957
|
apiUrl: databaseURL,
|
1807
1958
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1808
1959
|
workspacesApiUrl: `${protocol}//${host}`,
|
1809
|
-
pathParams: {
|
1810
|
-
dbBranchName,
|
1811
|
-
workspace
|
1812
|
-
}
|
1960
|
+
pathParams: { dbBranchName, workspace }
|
1813
1961
|
});
|
1814
1962
|
} catch (err) {
|
1815
1963
|
if (isObject(err) && err.status === 404)
|
@@ -1817,21 +1965,10 @@ async function getDatabaseBranch(branch, options) {
|
|
1817
1965
|
throw err;
|
1818
1966
|
}
|
1819
1967
|
}
|
1820
|
-
function getBranchByEnvVariable() {
|
1821
|
-
for (const name of envBranchNames) {
|
1822
|
-
const value = getEnvVariable(name);
|
1823
|
-
if (value) {
|
1824
|
-
return value;
|
1825
|
-
}
|
1826
|
-
}
|
1827
|
-
try {
|
1828
|
-
return XATA_BRANCH;
|
1829
|
-
} catch (err) {
|
1830
|
-
}
|
1831
|
-
}
|
1832
1968
|
function getDatabaseURL() {
|
1833
1969
|
try {
|
1834
|
-
|
1970
|
+
const { databaseURL } = getEnvironment();
|
1971
|
+
return databaseURL;
|
1835
1972
|
} catch (err) {
|
1836
1973
|
return void 0;
|
1837
1974
|
}
|
@@ -1860,20 +1997,22 @@ var __privateMethod = (obj, member, method) => {
|
|
1860
1997
|
return method;
|
1861
1998
|
};
|
1862
1999
|
const buildClient = (plugins) => {
|
1863
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2000
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1864
2001
|
return _a = class {
|
1865
|
-
constructor(options = {},
|
2002
|
+
constructor(options = {}, schemaTables) {
|
1866
2003
|
__privateAdd(this, _parseOptions);
|
1867
2004
|
__privateAdd(this, _getFetchProps);
|
1868
2005
|
__privateAdd(this, _evaluateBranch);
|
1869
2006
|
__privateAdd(this, _branch, void 0);
|
2007
|
+
__privateAdd(this, _options, void 0);
|
1870
2008
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2009
|
+
__privateSet(this, _options, safeOptions);
|
1871
2010
|
const pluginOptions = {
|
1872
2011
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1873
2012
|
cache: safeOptions.cache
|
1874
2013
|
};
|
1875
|
-
const db = new SchemaPlugin(
|
1876
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
2014
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2015
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
1877
2016
|
this.db = db;
|
1878
2017
|
this.search = search;
|
1879
2018
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
@@ -1889,22 +2028,22 @@ const buildClient = (plugins) => {
|
|
1889
2028
|
}
|
1890
2029
|
}
|
1891
2030
|
}
|
1892
|
-
|
2031
|
+
async getConfig() {
|
2032
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
2033
|
+
const branch = await __privateGet(this, _options).branch();
|
2034
|
+
return { databaseURL, branch };
|
2035
|
+
}
|
2036
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
1893
2037
|
const fetch = getFetchImplementation(options?.fetch);
|
1894
2038
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1895
2039
|
const apiKey = options?.apiKey || getAPIKey();
|
1896
|
-
const cache = options?.cache ?? new SimpleCache({
|
2040
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
1897
2041
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
1898
2042
|
if (!databaseURL || !apiKey) {
|
1899
2043
|
throw new Error("Options databaseURL and apiKey are required");
|
1900
2044
|
}
|
1901
2045
|
return { fetch, databaseURL, apiKey, branch, cache };
|
1902
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
1903
|
-
fetch,
|
1904
|
-
apiKey,
|
1905
|
-
databaseURL,
|
1906
|
-
branch
|
1907
|
-
}) {
|
2046
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
|
1908
2047
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
1909
2048
|
if (!branchValue)
|
1910
2049
|
throw new Error("Unable to resolve branch value");
|
@@ -1954,6 +2093,7 @@ exports.PAGINATION_MAX_OFFSET = PAGINATION_MAX_OFFSET;
|
|
1954
2093
|
exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
1955
2094
|
exports.Page = Page;
|
1956
2095
|
exports.Query = Query;
|
2096
|
+
exports.RecordArray = RecordArray;
|
1957
2097
|
exports.Repository = Repository;
|
1958
2098
|
exports.RestRepository = RestRepository;
|
1959
2099
|
exports.SchemaPlugin = SchemaPlugin;
|
@@ -2043,6 +2183,7 @@ exports.updateRecordWithID = updateRecordWithID;
|
|
2043
2183
|
exports.updateTable = updateTable;
|
2044
2184
|
exports.updateUser = updateUser;
|
2045
2185
|
exports.updateWorkspace = updateWorkspace;
|
2186
|
+
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
2046
2187
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
2047
2188
|
exports.upsertRecordWithID = upsertRecordWithID;
|
2048
2189
|
//# sourceMappingURL=index.cjs.map
|