@xata.io/client 0.0.0-alpha.vecada6d → 0.0.0-alpha.vecdf10f
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 +258 -0
- package/README.md +273 -1
- package/Usage.md +451 -0
- package/dist/index.cjs +2144 -801
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4961 -1176
- package/dist/index.mjs +2084 -802
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -5
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
const defaultTrace = async (_name, fn, _options) => {
|
|
2
|
+
return await fn({
|
|
3
|
+
setAttributes: () => {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
const TraceAttributes = {
|
|
9
|
+
KIND: "xata.trace.kind",
|
|
10
|
+
VERSION: "xata.sdk.version",
|
|
11
|
+
TABLE: "xata.table",
|
|
12
|
+
HTTP_REQUEST_ID: "http.request_id",
|
|
13
|
+
HTTP_STATUS_CODE: "http.status_code",
|
|
14
|
+
HTTP_HOST: "http.host",
|
|
15
|
+
HTTP_SCHEME: "http.scheme",
|
|
16
|
+
HTTP_USER_AGENT: "http.user_agent",
|
|
17
|
+
HTTP_METHOD: "http.method",
|
|
18
|
+
HTTP_URL: "http.url",
|
|
19
|
+
HTTP_ROUTE: "http.route",
|
|
20
|
+
HTTP_TARGET: "http.target"
|
|
21
|
+
};
|
|
22
|
+
|
|
1
23
|
function notEmpty(value) {
|
|
2
24
|
return value !== null && value !== void 0;
|
|
3
25
|
}
|
|
@@ -7,46 +29,115 @@ function compact(arr) {
|
|
|
7
29
|
function isObject(value) {
|
|
8
30
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
9
31
|
}
|
|
32
|
+
function isDefined(value) {
|
|
33
|
+
return value !== null && value !== void 0;
|
|
34
|
+
}
|
|
10
35
|
function isString(value) {
|
|
11
|
-
return value
|
|
36
|
+
return isDefined(value) && typeof value === "string";
|
|
37
|
+
}
|
|
38
|
+
function isStringArray(value) {
|
|
39
|
+
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
|
40
|
+
}
|
|
41
|
+
function isNumber(value) {
|
|
42
|
+
return isDefined(value) && typeof value === "number";
|
|
12
43
|
}
|
|
13
44
|
function toBase64(value) {
|
|
14
45
|
try {
|
|
15
46
|
return btoa(value);
|
|
16
47
|
} catch (err) {
|
|
17
|
-
|
|
48
|
+
const buf = Buffer;
|
|
49
|
+
return buf.from(value).toString("base64");
|
|
18
50
|
}
|
|
19
51
|
}
|
|
52
|
+
function deepMerge(a, b) {
|
|
53
|
+
const result = { ...a };
|
|
54
|
+
for (const [key, value] of Object.entries(b)) {
|
|
55
|
+
if (isObject(value) && isObject(result[key])) {
|
|
56
|
+
result[key] = deepMerge(result[key], value);
|
|
57
|
+
} else {
|
|
58
|
+
result[key] = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
20
63
|
|
|
21
|
-
function
|
|
64
|
+
function getEnvironment() {
|
|
22
65
|
try {
|
|
23
|
-
if (isObject(process) &&
|
|
24
|
-
return
|
|
66
|
+
if (isObject(process) && isObject(process.env)) {
|
|
67
|
+
return {
|
|
68
|
+
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
|
69
|
+
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
|
70
|
+
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
|
71
|
+
envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
|
|
72
|
+
fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
|
|
73
|
+
};
|
|
25
74
|
}
|
|
26
75
|
} catch (err) {
|
|
27
76
|
}
|
|
28
77
|
try {
|
|
29
|
-
if (isObject(Deno) &&
|
|
30
|
-
return
|
|
78
|
+
if (isObject(Deno) && isObject(Deno.env)) {
|
|
79
|
+
return {
|
|
80
|
+
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
|
81
|
+
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
|
82
|
+
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
|
83
|
+
envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
|
|
84
|
+
fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
|
|
85
|
+
};
|
|
31
86
|
}
|
|
32
87
|
} catch (err) {
|
|
33
88
|
}
|
|
89
|
+
return {
|
|
90
|
+
apiKey: getGlobalApiKey(),
|
|
91
|
+
databaseURL: getGlobalDatabaseURL(),
|
|
92
|
+
branch: getGlobalBranch(),
|
|
93
|
+
envBranch: void 0,
|
|
94
|
+
fallbackBranch: getGlobalFallbackBranch()
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function getGlobalApiKey() {
|
|
98
|
+
try {
|
|
99
|
+
return XATA_API_KEY;
|
|
100
|
+
} catch (err) {
|
|
101
|
+
return void 0;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function getGlobalDatabaseURL() {
|
|
105
|
+
try {
|
|
106
|
+
return XATA_DATABASE_URL;
|
|
107
|
+
} catch (err) {
|
|
108
|
+
return void 0;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function getGlobalBranch() {
|
|
112
|
+
try {
|
|
113
|
+
return XATA_BRANCH;
|
|
114
|
+
} catch (err) {
|
|
115
|
+
return void 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function getGlobalFallbackBranch() {
|
|
119
|
+
try {
|
|
120
|
+
return XATA_FALLBACK_BRANCH;
|
|
121
|
+
} catch (err) {
|
|
122
|
+
return void 0;
|
|
123
|
+
}
|
|
34
124
|
}
|
|
35
125
|
async function getGitBranch() {
|
|
126
|
+
const cmd = ["git", "branch", "--show-current"];
|
|
127
|
+
const fullCmd = cmd.join(" ");
|
|
128
|
+
const nodeModule = ["child", "process"].join("_");
|
|
129
|
+
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
|
36
130
|
try {
|
|
37
131
|
if (typeof require === "function") {
|
|
38
|
-
|
|
39
|
-
return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
|
|
132
|
+
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
|
40
133
|
}
|
|
134
|
+
const { execSync } = await import(nodeModule);
|
|
135
|
+
return execSync(fullCmd, execOptions).toString().trim();
|
|
41
136
|
} catch (err) {
|
|
42
137
|
}
|
|
43
138
|
try {
|
|
44
139
|
if (isObject(Deno)) {
|
|
45
|
-
const process2 = Deno.run({
|
|
46
|
-
cmd: ["git", "branch", "--show-current"],
|
|
47
|
-
stdout: "piped",
|
|
48
|
-
stderr: "piped"
|
|
49
|
-
});
|
|
140
|
+
const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
|
|
50
141
|
return new TextDecoder().decode(await process2.output()).trim();
|
|
51
142
|
}
|
|
52
143
|
} catch (err) {
|
|
@@ -55,7 +146,8 @@ async function getGitBranch() {
|
|
|
55
146
|
|
|
56
147
|
function getAPIKey() {
|
|
57
148
|
try {
|
|
58
|
-
|
|
149
|
+
const { apiKey } = getEnvironment();
|
|
150
|
+
return apiKey;
|
|
59
151
|
} catch (err) {
|
|
60
152
|
return void 0;
|
|
61
153
|
}
|
|
@@ -65,21 +157,35 @@ function getFetchImplementation(userFetch) {
|
|
|
65
157
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
|
66
158
|
const fetchImpl = userFetch ?? globalFetch;
|
|
67
159
|
if (!fetchImpl) {
|
|
68
|
-
throw new Error(
|
|
160
|
+
throw new Error(
|
|
161
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
|
162
|
+
);
|
|
69
163
|
}
|
|
70
164
|
return fetchImpl;
|
|
71
165
|
}
|
|
72
166
|
|
|
73
|
-
|
|
74
|
-
|
|
167
|
+
const VERSION = "0.0.0-alpha.vecdf10f";
|
|
168
|
+
|
|
169
|
+
class ErrorWithCause extends Error {
|
|
170
|
+
constructor(message, options) {
|
|
171
|
+
super(message, options);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
class FetcherError extends ErrorWithCause {
|
|
175
|
+
constructor(status, data, requestId) {
|
|
75
176
|
super(getMessage(data));
|
|
76
177
|
this.status = status;
|
|
77
178
|
this.errors = isBulkError(data) ? data.errors : void 0;
|
|
179
|
+
this.requestId = requestId;
|
|
78
180
|
if (data instanceof Error) {
|
|
79
181
|
this.stack = data.stack;
|
|
80
182
|
this.cause = data.cause;
|
|
81
183
|
}
|
|
82
184
|
}
|
|
185
|
+
toString() {
|
|
186
|
+
const error = super.toString();
|
|
187
|
+
return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
|
|
188
|
+
}
|
|
83
189
|
}
|
|
84
190
|
function isBulkError(error) {
|
|
85
191
|
return isObject(error) && Array.isArray(error.errors);
|
|
@@ -102,20 +208,31 @@ function getMessage(data) {
|
|
|
102
208
|
}
|
|
103
209
|
|
|
104
210
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
105
|
-
const
|
|
211
|
+
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
|
212
|
+
if (value === void 0 || value === null)
|
|
213
|
+
return acc;
|
|
214
|
+
return { ...acc, [key]: value };
|
|
215
|
+
}, {});
|
|
216
|
+
const query = new URLSearchParams(cleanQueryParams).toString();
|
|
106
217
|
const queryString = query.length > 0 ? `?${query}` : "";
|
|
107
|
-
|
|
218
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
|
219
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
|
220
|
+
}, {});
|
|
221
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
|
108
222
|
};
|
|
109
223
|
function buildBaseUrl({
|
|
224
|
+
endpoint,
|
|
110
225
|
path,
|
|
111
226
|
workspacesApiUrl,
|
|
112
227
|
apiUrl,
|
|
113
|
-
pathParams
|
|
228
|
+
pathParams = {}
|
|
114
229
|
}) {
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
230
|
+
if (endpoint === "dataPlane") {
|
|
231
|
+
const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
|
232
|
+
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
|
233
|
+
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
|
234
|
+
}
|
|
235
|
+
return `${apiUrl}${path}`;
|
|
119
236
|
}
|
|
120
237
|
function hostHeader(url) {
|
|
121
238
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
|
@@ -131,275 +248,228 @@ async function fetch$1({
|
|
|
131
248
|
queryParams,
|
|
132
249
|
fetchImpl,
|
|
133
250
|
apiKey,
|
|
251
|
+
endpoint,
|
|
134
252
|
apiUrl,
|
|
135
|
-
workspacesApiUrl
|
|
253
|
+
workspacesApiUrl,
|
|
254
|
+
trace,
|
|
255
|
+
signal,
|
|
256
|
+
clientID,
|
|
257
|
+
sessionID
|
|
136
258
|
}) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
259
|
+
return trace(
|
|
260
|
+
`${method.toUpperCase()} ${path}`,
|
|
261
|
+
async ({ setAttributes }) => {
|
|
262
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
|
263
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
|
264
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
|
265
|
+
setAttributes({
|
|
266
|
+
[TraceAttributes.HTTP_URL]: url,
|
|
267
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
|
268
|
+
});
|
|
269
|
+
const response = await fetchImpl(url, {
|
|
270
|
+
method: method.toUpperCase(),
|
|
271
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
272
|
+
headers: {
|
|
273
|
+
"Content-Type": "application/json",
|
|
274
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
|
275
|
+
"X-Xata-Client-ID": clientID ?? "",
|
|
276
|
+
"X-Xata-Session-ID": sessionID ?? "",
|
|
277
|
+
...headers,
|
|
278
|
+
...hostHeader(fullUrl),
|
|
279
|
+
Authorization: `Bearer ${apiKey}`
|
|
280
|
+
},
|
|
281
|
+
signal
|
|
282
|
+
});
|
|
283
|
+
if (response.status === 204) {
|
|
284
|
+
return {};
|
|
285
|
+
}
|
|
286
|
+
const { host, protocol } = parseUrl(response.url);
|
|
287
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
|
288
|
+
setAttributes({
|
|
289
|
+
[TraceAttributes.KIND]: "http",
|
|
290
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
|
291
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
|
292
|
+
[TraceAttributes.HTTP_HOST]: host,
|
|
293
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
|
294
|
+
});
|
|
295
|
+
try {
|
|
296
|
+
const jsonResponse = await response.json();
|
|
297
|
+
if (response.ok) {
|
|
298
|
+
return jsonResponse;
|
|
299
|
+
}
|
|
300
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
|
301
|
+
} catch (error) {
|
|
302
|
+
throw new FetcherError(response.status, error, requestId);
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
function parseUrl(url) {
|
|
153
309
|
try {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
return jsonResponse;
|
|
157
|
-
}
|
|
158
|
-
throw new FetcherError(response.status, jsonResponse);
|
|
310
|
+
const { host, protocol } = new URL(url);
|
|
311
|
+
return { host, protocol };
|
|
159
312
|
} catch (error) {
|
|
160
|
-
|
|
313
|
+
return {};
|
|
161
314
|
}
|
|
162
315
|
}
|
|
163
316
|
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
url: "/user/keys",
|
|
169
|
-
method: "get",
|
|
170
|
-
...variables
|
|
171
|
-
});
|
|
172
|
-
const createUserAPIKey = (variables) => fetch$1({
|
|
173
|
-
url: "/user/keys/{keyName}",
|
|
174
|
-
method: "post",
|
|
175
|
-
...variables
|
|
176
|
-
});
|
|
177
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
|
178
|
-
url: "/user/keys/{keyName}",
|
|
179
|
-
method: "delete",
|
|
180
|
-
...variables
|
|
181
|
-
});
|
|
182
|
-
const createWorkspace = (variables) => fetch$1({
|
|
183
|
-
url: "/workspaces",
|
|
184
|
-
method: "post",
|
|
185
|
-
...variables
|
|
186
|
-
});
|
|
187
|
-
const getWorkspacesList = (variables) => fetch$1({
|
|
188
|
-
url: "/workspaces",
|
|
189
|
-
method: "get",
|
|
190
|
-
...variables
|
|
191
|
-
});
|
|
192
|
-
const getWorkspace = (variables) => fetch$1({
|
|
193
|
-
url: "/workspaces/{workspaceId}",
|
|
194
|
-
method: "get",
|
|
195
|
-
...variables
|
|
196
|
-
});
|
|
197
|
-
const updateWorkspace = (variables) => fetch$1({
|
|
198
|
-
url: "/workspaces/{workspaceId}",
|
|
199
|
-
method: "put",
|
|
200
|
-
...variables
|
|
201
|
-
});
|
|
202
|
-
const deleteWorkspace = (variables) => fetch$1({
|
|
203
|
-
url: "/workspaces/{workspaceId}",
|
|
204
|
-
method: "delete",
|
|
205
|
-
...variables
|
|
206
|
-
});
|
|
207
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
|
208
|
-
url: "/workspaces/{workspaceId}/members",
|
|
209
|
-
method: "get",
|
|
210
|
-
...variables
|
|
211
|
-
});
|
|
212
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
|
213
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
|
214
|
-
url: "/workspaces/{workspaceId}/members/{userId}",
|
|
215
|
-
method: "delete",
|
|
216
|
-
...variables
|
|
217
|
-
});
|
|
218
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
|
219
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
|
220
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
|
221
|
-
method: "delete",
|
|
222
|
-
...variables
|
|
223
|
-
});
|
|
224
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
|
225
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
|
226
|
-
method: "post",
|
|
227
|
-
...variables
|
|
228
|
-
});
|
|
229
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
|
230
|
-
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
|
231
|
-
method: "post",
|
|
232
|
-
...variables
|
|
233
|
-
});
|
|
234
|
-
const getDatabaseList = (variables) => fetch$1({
|
|
235
|
-
url: "/dbs",
|
|
236
|
-
method: "get",
|
|
237
|
-
...variables
|
|
238
|
-
});
|
|
239
|
-
const getBranchList = (variables) => fetch$1({
|
|
317
|
+
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
|
318
|
+
|
|
319
|
+
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
|
320
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
|
240
321
|
url: "/dbs/{dbName}",
|
|
241
322
|
method: "get",
|
|
242
|
-
...variables
|
|
323
|
+
...variables,
|
|
324
|
+
signal
|
|
243
325
|
});
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const deleteDatabase = (variables) => fetch$1({
|
|
250
|
-
url: "/dbs/{dbName}",
|
|
251
|
-
method: "delete",
|
|
252
|
-
...variables
|
|
253
|
-
});
|
|
254
|
-
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
|
255
|
-
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
|
256
|
-
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
|
257
|
-
const resolveBranch = (variables) => fetch$1({
|
|
258
|
-
url: "/dbs/{dbName}/resolveBranch",
|
|
259
|
-
method: "get",
|
|
260
|
-
...variables
|
|
261
|
-
});
|
|
262
|
-
const getBranchDetails = (variables) => fetch$1({
|
|
326
|
+
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
|
327
|
+
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
|
328
|
+
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
|
329
|
+
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
|
330
|
+
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
|
263
331
|
url: "/db/{dbBranchName}",
|
|
264
332
|
method: "get",
|
|
265
|
-
...variables
|
|
266
|
-
|
|
267
|
-
const createBranch = (variables) => fetch$1({
|
|
268
|
-
url: "/db/{dbBranchName}",
|
|
269
|
-
method: "put",
|
|
270
|
-
...variables
|
|
333
|
+
...variables,
|
|
334
|
+
signal
|
|
271
335
|
});
|
|
272
|
-
const
|
|
336
|
+
const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
|
337
|
+
const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
273
338
|
url: "/db/{dbBranchName}",
|
|
274
339
|
method: "delete",
|
|
275
|
-
...variables
|
|
340
|
+
...variables,
|
|
341
|
+
signal
|
|
276
342
|
});
|
|
277
|
-
const updateBranchMetadata = (variables) =>
|
|
343
|
+
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
|
278
344
|
url: "/db/{dbBranchName}/metadata",
|
|
279
345
|
method: "put",
|
|
280
|
-
...variables
|
|
346
|
+
...variables,
|
|
347
|
+
signal
|
|
281
348
|
});
|
|
282
|
-
const getBranchMetadata = (variables) =>
|
|
349
|
+
const getBranchMetadata = (variables, signal) => dataPlaneFetch({
|
|
283
350
|
url: "/db/{dbBranchName}/metadata",
|
|
284
351
|
method: "get",
|
|
285
|
-
...variables
|
|
352
|
+
...variables,
|
|
353
|
+
signal
|
|
286
354
|
});
|
|
287
|
-
const
|
|
288
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
|
289
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
|
290
|
-
const getBranchStats = (variables) => fetch$1({
|
|
355
|
+
const getBranchStats = (variables, signal) => dataPlaneFetch({
|
|
291
356
|
url: "/db/{dbBranchName}/stats",
|
|
292
357
|
method: "get",
|
|
293
|
-
...variables
|
|
358
|
+
...variables,
|
|
359
|
+
signal
|
|
360
|
+
});
|
|
361
|
+
const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
|
362
|
+
const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
|
363
|
+
const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
|
364
|
+
const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
|
|
365
|
+
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
|
366
|
+
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
|
367
|
+
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
|
368
|
+
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
|
369
|
+
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
|
370
|
+
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
|
371
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
|
372
|
+
method: "get",
|
|
373
|
+
...variables,
|
|
374
|
+
signal
|
|
375
|
+
});
|
|
376
|
+
const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
|
377
|
+
const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
|
378
|
+
const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
|
379
|
+
const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
|
380
|
+
const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
|
|
381
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
|
382
|
+
method: "post",
|
|
383
|
+
...variables,
|
|
384
|
+
signal
|
|
294
385
|
});
|
|
295
|
-
const
|
|
386
|
+
const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
|
387
|
+
const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
|
388
|
+
const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
|
389
|
+
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
|
390
|
+
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
|
391
|
+
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
|
392
|
+
const createTable = (variables, signal) => dataPlaneFetch({
|
|
296
393
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
|
297
394
|
method: "put",
|
|
298
|
-
...variables
|
|
395
|
+
...variables,
|
|
396
|
+
signal
|
|
299
397
|
});
|
|
300
|
-
const deleteTable = (variables) =>
|
|
398
|
+
const deleteTable = (variables, signal) => dataPlaneFetch({
|
|
301
399
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
|
302
400
|
method: "delete",
|
|
303
|
-
...variables
|
|
304
|
-
|
|
305
|
-
const updateTable = (variables) => fetch$1({
|
|
306
|
-
url: "/db/{dbBranchName}/tables/{tableName}",
|
|
307
|
-
method: "patch",
|
|
308
|
-
...variables
|
|
401
|
+
...variables,
|
|
402
|
+
signal
|
|
309
403
|
});
|
|
310
|
-
const
|
|
404
|
+
const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
|
|
405
|
+
const getTableSchema = (variables, signal) => dataPlaneFetch({
|
|
311
406
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
|
312
407
|
method: "get",
|
|
313
|
-
...variables
|
|
408
|
+
...variables,
|
|
409
|
+
signal
|
|
314
410
|
});
|
|
315
|
-
const setTableSchema = (variables) =>
|
|
316
|
-
|
|
317
|
-
method: "put",
|
|
318
|
-
...variables
|
|
319
|
-
});
|
|
320
|
-
const getTableColumns = (variables) => fetch$1({
|
|
411
|
+
const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
|
|
412
|
+
const getTableColumns = (variables, signal) => dataPlaneFetch({
|
|
321
413
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
|
322
414
|
method: "get",
|
|
323
|
-
...variables
|
|
415
|
+
...variables,
|
|
416
|
+
signal
|
|
324
417
|
});
|
|
325
|
-
const addTableColumn = (variables) =>
|
|
326
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
});
|
|
330
|
-
const getColumn = (variables) => fetch$1({
|
|
418
|
+
const addTableColumn = (variables, signal) => dataPlaneFetch(
|
|
419
|
+
{ url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
|
|
420
|
+
);
|
|
421
|
+
const getColumn = (variables, signal) => dataPlaneFetch({
|
|
331
422
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
|
332
423
|
method: "get",
|
|
333
|
-
...variables
|
|
424
|
+
...variables,
|
|
425
|
+
signal
|
|
334
426
|
});
|
|
335
|
-
const
|
|
427
|
+
const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
|
|
428
|
+
const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
336
429
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
|
337
430
|
method: "delete",
|
|
338
|
-
...variables
|
|
339
|
-
|
|
340
|
-
const updateColumn = (variables) => fetch$1({
|
|
341
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
|
342
|
-
method: "patch",
|
|
343
|
-
...variables
|
|
431
|
+
...variables,
|
|
432
|
+
signal
|
|
344
433
|
});
|
|
345
|
-
const insertRecord = (variables) =>
|
|
346
|
-
|
|
347
|
-
method: "post",
|
|
348
|
-
...variables
|
|
349
|
-
});
|
|
350
|
-
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
|
351
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
|
352
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
|
353
|
-
const deleteRecord = (variables) => fetch$1({
|
|
354
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
|
355
|
-
method: "delete",
|
|
356
|
-
...variables
|
|
357
|
-
});
|
|
358
|
-
const getRecord = (variables) => fetch$1({
|
|
434
|
+
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
|
435
|
+
const getRecord = (variables, signal) => dataPlaneFetch({
|
|
359
436
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
|
360
437
|
method: "get",
|
|
361
|
-
...variables
|
|
438
|
+
...variables,
|
|
439
|
+
signal
|
|
362
440
|
});
|
|
363
|
-
const
|
|
364
|
-
const
|
|
441
|
+
const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
|
442
|
+
const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
|
443
|
+
const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
|
444
|
+
const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
|
|
445
|
+
const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
|
446
|
+
const queryTable = (variables, signal) => dataPlaneFetch({
|
|
365
447
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
|
366
448
|
method: "post",
|
|
367
|
-
...variables
|
|
449
|
+
...variables,
|
|
450
|
+
signal
|
|
368
451
|
});
|
|
369
|
-
const
|
|
370
|
-
url: "/db/{dbBranchName}/
|
|
452
|
+
const searchBranch = (variables, signal) => dataPlaneFetch({
|
|
453
|
+
url: "/db/{dbBranchName}/search",
|
|
371
454
|
method: "post",
|
|
372
|
-
...variables
|
|
455
|
+
...variables,
|
|
456
|
+
signal
|
|
373
457
|
});
|
|
374
|
-
const
|
|
375
|
-
url: "/db/{dbBranchName}/search",
|
|
458
|
+
const searchTable = (variables, signal) => dataPlaneFetch({
|
|
459
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
|
376
460
|
method: "post",
|
|
377
|
-
...variables
|
|
461
|
+
...variables,
|
|
462
|
+
signal
|
|
378
463
|
});
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
createWorkspace,
|
|
383
|
-
getWorkspacesList,
|
|
384
|
-
getWorkspace,
|
|
385
|
-
updateWorkspace,
|
|
386
|
-
deleteWorkspace,
|
|
387
|
-
getWorkspaceMembersList,
|
|
388
|
-
updateWorkspaceMemberRole,
|
|
389
|
-
removeWorkspaceMember,
|
|
390
|
-
inviteWorkspaceMember,
|
|
391
|
-
cancelWorkspaceMemberInvite,
|
|
392
|
-
resendWorkspaceMemberInvite,
|
|
393
|
-
acceptWorkspaceMemberInvite
|
|
394
|
-
},
|
|
464
|
+
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
|
465
|
+
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
|
466
|
+
const operationsByTag$2 = {
|
|
395
467
|
database: {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
removeGitBranchesEntry,
|
|
402
|
-
resolveBranch
|
|
468
|
+
dEPRECATEDgetDatabaseList,
|
|
469
|
+
dEPRECATEDcreateDatabase,
|
|
470
|
+
dEPRECATEDdeleteDatabase,
|
|
471
|
+
dEPRECATEDgetDatabaseMetadata,
|
|
472
|
+
dEPRECATEDupdateDatabaseMetadata
|
|
403
473
|
},
|
|
404
474
|
branch: {
|
|
405
475
|
getBranchList,
|
|
@@ -408,10 +478,32 @@ const operationsByTag = {
|
|
|
408
478
|
deleteBranch,
|
|
409
479
|
updateBranchMetadata,
|
|
410
480
|
getBranchMetadata,
|
|
481
|
+
getBranchStats,
|
|
482
|
+
getGitBranchesMapping,
|
|
483
|
+
addGitBranchesEntry,
|
|
484
|
+
removeGitBranchesEntry,
|
|
485
|
+
resolveBranch
|
|
486
|
+
},
|
|
487
|
+
migrations: {
|
|
411
488
|
getBranchMigrationHistory,
|
|
412
|
-
executeBranchMigrationPlan,
|
|
413
489
|
getBranchMigrationPlan,
|
|
414
|
-
|
|
490
|
+
executeBranchMigrationPlan,
|
|
491
|
+
getBranchSchemaHistory,
|
|
492
|
+
compareBranchWithUserSchema,
|
|
493
|
+
compareBranchSchemas,
|
|
494
|
+
updateBranchSchema,
|
|
495
|
+
previewBranchSchemaEdit,
|
|
496
|
+
applyBranchSchemaEdit
|
|
497
|
+
},
|
|
498
|
+
migrationRequests: {
|
|
499
|
+
queryMigrationRequests,
|
|
500
|
+
createMigrationRequest,
|
|
501
|
+
getMigrationRequest,
|
|
502
|
+
updateMigrationRequest,
|
|
503
|
+
listMigrationRequestsCommits,
|
|
504
|
+
compareMigrationRequest,
|
|
505
|
+
getMigrationRequestIsMerged,
|
|
506
|
+
mergeMigrationRequest
|
|
415
507
|
},
|
|
416
508
|
table: {
|
|
417
509
|
createTable,
|
|
@@ -422,27 +514,159 @@ const operationsByTag = {
|
|
|
422
514
|
getTableColumns,
|
|
423
515
|
addTableColumn,
|
|
424
516
|
getColumn,
|
|
425
|
-
|
|
426
|
-
|
|
517
|
+
updateColumn,
|
|
518
|
+
deleteColumn
|
|
427
519
|
},
|
|
428
520
|
records: {
|
|
429
521
|
insertRecord,
|
|
522
|
+
getRecord,
|
|
430
523
|
insertRecordWithID,
|
|
431
524
|
updateRecordWithID,
|
|
432
525
|
upsertRecordWithID,
|
|
433
526
|
deleteRecord,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
527
|
+
bulkInsertTableRecords
|
|
528
|
+
},
|
|
529
|
+
searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
|
533
|
+
|
|
534
|
+
const getUser = (variables, signal) => controlPlaneFetch({
|
|
535
|
+
url: "/user",
|
|
536
|
+
method: "get",
|
|
537
|
+
...variables,
|
|
538
|
+
signal
|
|
539
|
+
});
|
|
540
|
+
const updateUser = (variables, signal) => controlPlaneFetch({
|
|
541
|
+
url: "/user",
|
|
542
|
+
method: "put",
|
|
543
|
+
...variables,
|
|
544
|
+
signal
|
|
545
|
+
});
|
|
546
|
+
const deleteUser = (variables, signal) => controlPlaneFetch({
|
|
547
|
+
url: "/user",
|
|
548
|
+
method: "delete",
|
|
549
|
+
...variables,
|
|
550
|
+
signal
|
|
551
|
+
});
|
|
552
|
+
const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
|
553
|
+
url: "/user/keys",
|
|
554
|
+
method: "get",
|
|
555
|
+
...variables,
|
|
556
|
+
signal
|
|
557
|
+
});
|
|
558
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
559
|
+
url: "/user/keys/{keyName}",
|
|
560
|
+
method: "post",
|
|
561
|
+
...variables,
|
|
562
|
+
signal
|
|
563
|
+
});
|
|
564
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
565
|
+
url: "/user/keys/{keyName}",
|
|
566
|
+
method: "delete",
|
|
567
|
+
...variables,
|
|
568
|
+
signal
|
|
569
|
+
});
|
|
570
|
+
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
|
571
|
+
url: "/workspaces",
|
|
572
|
+
method: "get",
|
|
573
|
+
...variables,
|
|
574
|
+
signal
|
|
575
|
+
});
|
|
576
|
+
const createWorkspace = (variables, signal) => controlPlaneFetch({
|
|
577
|
+
url: "/workspaces",
|
|
578
|
+
method: "post",
|
|
579
|
+
...variables,
|
|
580
|
+
signal
|
|
581
|
+
});
|
|
582
|
+
const getWorkspace = (variables, signal) => controlPlaneFetch({
|
|
583
|
+
url: "/workspaces/{workspaceId}",
|
|
584
|
+
method: "get",
|
|
585
|
+
...variables,
|
|
586
|
+
signal
|
|
587
|
+
});
|
|
588
|
+
const updateWorkspace = (variables, signal) => controlPlaneFetch({
|
|
589
|
+
url: "/workspaces/{workspaceId}",
|
|
590
|
+
method: "put",
|
|
591
|
+
...variables,
|
|
592
|
+
signal
|
|
593
|
+
});
|
|
594
|
+
const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
|
595
|
+
url: "/workspaces/{workspaceId}",
|
|
596
|
+
method: "delete",
|
|
597
|
+
...variables,
|
|
598
|
+
signal
|
|
599
|
+
});
|
|
600
|
+
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
|
601
|
+
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
|
602
|
+
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
|
603
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
|
604
|
+
method: "delete",
|
|
605
|
+
...variables,
|
|
606
|
+
signal
|
|
607
|
+
});
|
|
608
|
+
const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
|
609
|
+
const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
|
610
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
|
611
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
|
612
|
+
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
|
613
|
+
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
|
614
|
+
url: "/workspaces/{workspaceId}/dbs",
|
|
615
|
+
method: "get",
|
|
616
|
+
...variables,
|
|
617
|
+
signal
|
|
618
|
+
});
|
|
619
|
+
const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
|
620
|
+
const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
621
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
|
622
|
+
method: "delete",
|
|
623
|
+
...variables,
|
|
624
|
+
signal
|
|
625
|
+
});
|
|
626
|
+
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
|
627
|
+
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
|
628
|
+
const listRegions = (variables, signal) => controlPlaneFetch({
|
|
629
|
+
url: "/workspaces/{workspaceId}/regions",
|
|
630
|
+
method: "get",
|
|
631
|
+
...variables,
|
|
632
|
+
signal
|
|
633
|
+
});
|
|
634
|
+
const operationsByTag$1 = {
|
|
635
|
+
users: { getUser, updateUser, deleteUser },
|
|
636
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
|
637
|
+
workspaces: {
|
|
638
|
+
getWorkspacesList,
|
|
639
|
+
createWorkspace,
|
|
640
|
+
getWorkspace,
|
|
641
|
+
updateWorkspace,
|
|
642
|
+
deleteWorkspace,
|
|
643
|
+
getWorkspaceMembersList,
|
|
644
|
+
updateWorkspaceMemberRole,
|
|
645
|
+
removeWorkspaceMember
|
|
646
|
+
},
|
|
647
|
+
invites: {
|
|
648
|
+
inviteWorkspaceMember,
|
|
649
|
+
updateWorkspaceMemberInvite,
|
|
650
|
+
cancelWorkspaceMemberInvite,
|
|
651
|
+
acceptWorkspaceMemberInvite,
|
|
652
|
+
resendWorkspaceMemberInvite
|
|
653
|
+
},
|
|
654
|
+
databases: {
|
|
655
|
+
getDatabaseList,
|
|
656
|
+
createDatabase,
|
|
657
|
+
deleteDatabase,
|
|
658
|
+
getDatabaseMetadata,
|
|
659
|
+
updateDatabaseMetadata,
|
|
660
|
+
listRegions
|
|
439
661
|
}
|
|
440
662
|
};
|
|
441
663
|
|
|
664
|
+
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
|
665
|
+
|
|
442
666
|
function getHostUrl(provider, type) {
|
|
443
|
-
if (
|
|
667
|
+
if (isHostProviderAlias(provider)) {
|
|
444
668
|
return providers[provider][type];
|
|
445
|
-
} else if (
|
|
669
|
+
} else if (isHostProviderBuilder(provider)) {
|
|
446
670
|
return provider[type];
|
|
447
671
|
}
|
|
448
672
|
throw new Error("Invalid API provider");
|
|
@@ -450,19 +674,38 @@ function getHostUrl(provider, type) {
|
|
|
450
674
|
const providers = {
|
|
451
675
|
production: {
|
|
452
676
|
main: "https://api.xata.io",
|
|
453
|
-
workspaces: "https://{workspaceId}.xata.sh"
|
|
677
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
|
454
678
|
},
|
|
455
679
|
staging: {
|
|
456
680
|
main: "https://staging.xatabase.co",
|
|
457
|
-
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
|
681
|
+
workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
|
|
458
682
|
}
|
|
459
683
|
};
|
|
460
|
-
function
|
|
684
|
+
function isHostProviderAlias(alias) {
|
|
461
685
|
return isString(alias) && Object.keys(providers).includes(alias);
|
|
462
686
|
}
|
|
463
|
-
function
|
|
687
|
+
function isHostProviderBuilder(builder) {
|
|
464
688
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
|
465
689
|
}
|
|
690
|
+
function parseProviderString(provider = "production") {
|
|
691
|
+
if (isHostProviderAlias(provider)) {
|
|
692
|
+
return provider;
|
|
693
|
+
}
|
|
694
|
+
const [main, workspaces] = provider.split(",");
|
|
695
|
+
if (!main || !workspaces)
|
|
696
|
+
return null;
|
|
697
|
+
return { main, workspaces };
|
|
698
|
+
}
|
|
699
|
+
function parseWorkspacesUrlParts(url) {
|
|
700
|
+
if (!isString(url))
|
|
701
|
+
return null;
|
|
702
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
|
|
703
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
|
|
704
|
+
const match = url.match(regex) || url.match(regexStaging);
|
|
705
|
+
if (!match)
|
|
706
|
+
return null;
|
|
707
|
+
return { workspace: match[1], region: match[2] ?? "eu-west-1" };
|
|
708
|
+
}
|
|
466
709
|
|
|
467
710
|
var __accessCheck$7 = (obj, member, msg) => {
|
|
468
711
|
if (!member.has(obj))
|
|
@@ -477,7 +720,7 @@ var __privateAdd$7 = (obj, member, value) => {
|
|
|
477
720
|
throw TypeError("Cannot add the same private member more than once");
|
|
478
721
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
479
722
|
};
|
|
480
|
-
var __privateSet$
|
|
723
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
|
481
724
|
__accessCheck$7(obj, member, "write to private field");
|
|
482
725
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
483
726
|
return value;
|
|
@@ -488,15 +731,17 @@ class XataApiClient {
|
|
|
488
731
|
__privateAdd$7(this, _extraProps, void 0);
|
|
489
732
|
__privateAdd$7(this, _namespaces, {});
|
|
490
733
|
const provider = options.host ?? "production";
|
|
491
|
-
const apiKey = options
|
|
734
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
|
735
|
+
const trace = options.trace ?? defaultTrace;
|
|
492
736
|
if (!apiKey) {
|
|
493
737
|
throw new Error("Could not resolve a valid apiKey");
|
|
494
738
|
}
|
|
495
|
-
__privateSet$
|
|
739
|
+
__privateSet$7(this, _extraProps, {
|
|
496
740
|
apiUrl: getHostUrl(provider, "main"),
|
|
497
741
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
|
498
742
|
fetchImpl: getFetchImplementation(options.fetch),
|
|
499
|
-
apiKey
|
|
743
|
+
apiKey,
|
|
744
|
+
trace
|
|
500
745
|
});
|
|
501
746
|
}
|
|
502
747
|
get user() {
|
|
@@ -504,21 +749,41 @@ class XataApiClient {
|
|
|
504
749
|
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
|
505
750
|
return __privateGet$7(this, _namespaces).user;
|
|
506
751
|
}
|
|
752
|
+
get authentication() {
|
|
753
|
+
if (!__privateGet$7(this, _namespaces).authentication)
|
|
754
|
+
__privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
|
|
755
|
+
return __privateGet$7(this, _namespaces).authentication;
|
|
756
|
+
}
|
|
507
757
|
get workspaces() {
|
|
508
758
|
if (!__privateGet$7(this, _namespaces).workspaces)
|
|
509
759
|
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
|
510
760
|
return __privateGet$7(this, _namespaces).workspaces;
|
|
511
761
|
}
|
|
512
|
-
get
|
|
513
|
-
if (!__privateGet$7(this, _namespaces).
|
|
514
|
-
__privateGet$7(this, _namespaces).
|
|
515
|
-
return __privateGet$7(this, _namespaces).
|
|
762
|
+
get invites() {
|
|
763
|
+
if (!__privateGet$7(this, _namespaces).invites)
|
|
764
|
+
__privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
|
|
765
|
+
return __privateGet$7(this, _namespaces).invites;
|
|
766
|
+
}
|
|
767
|
+
get database() {
|
|
768
|
+
if (!__privateGet$7(this, _namespaces).database)
|
|
769
|
+
__privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
|
|
770
|
+
return __privateGet$7(this, _namespaces).database;
|
|
516
771
|
}
|
|
517
772
|
get branches() {
|
|
518
773
|
if (!__privateGet$7(this, _namespaces).branches)
|
|
519
774
|
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
|
520
775
|
return __privateGet$7(this, _namespaces).branches;
|
|
521
776
|
}
|
|
777
|
+
get migrations() {
|
|
778
|
+
if (!__privateGet$7(this, _namespaces).migrations)
|
|
779
|
+
__privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
|
|
780
|
+
return __privateGet$7(this, _namespaces).migrations;
|
|
781
|
+
}
|
|
782
|
+
get migrationRequests() {
|
|
783
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
|
784
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
|
785
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
|
786
|
+
}
|
|
522
787
|
get tables() {
|
|
523
788
|
if (!__privateGet$7(this, _namespaces).tables)
|
|
524
789
|
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
|
@@ -529,6 +794,11 @@ class XataApiClient {
|
|
|
529
794
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
|
530
795
|
return __privateGet$7(this, _namespaces).records;
|
|
531
796
|
}
|
|
797
|
+
get searchAndFilter() {
|
|
798
|
+
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
|
799
|
+
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
|
800
|
+
return __privateGet$7(this, _namespaces).searchAndFilter;
|
|
801
|
+
}
|
|
532
802
|
}
|
|
533
803
|
_extraProps = new WeakMap();
|
|
534
804
|
_namespaces = new WeakMap();
|
|
@@ -539,24 +809,29 @@ class UserApi {
|
|
|
539
809
|
getUser() {
|
|
540
810
|
return operationsByTag.users.getUser({ ...this.extraProps });
|
|
541
811
|
}
|
|
542
|
-
updateUser(user) {
|
|
812
|
+
updateUser({ user }) {
|
|
543
813
|
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
|
544
814
|
}
|
|
545
815
|
deleteUser() {
|
|
546
816
|
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
|
547
817
|
}
|
|
818
|
+
}
|
|
819
|
+
class AuthenticationApi {
|
|
820
|
+
constructor(extraProps) {
|
|
821
|
+
this.extraProps = extraProps;
|
|
822
|
+
}
|
|
548
823
|
getUserAPIKeys() {
|
|
549
|
-
return operationsByTag.
|
|
824
|
+
return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
|
|
550
825
|
}
|
|
551
|
-
createUserAPIKey(
|
|
552
|
-
return operationsByTag.
|
|
553
|
-
pathParams: { keyName },
|
|
826
|
+
createUserAPIKey({ name }) {
|
|
827
|
+
return operationsByTag.authentication.createUserAPIKey({
|
|
828
|
+
pathParams: { keyName: name },
|
|
554
829
|
...this.extraProps
|
|
555
830
|
});
|
|
556
831
|
}
|
|
557
|
-
deleteUserAPIKey(
|
|
558
|
-
return operationsByTag.
|
|
559
|
-
pathParams: { keyName },
|
|
832
|
+
deleteUserAPIKey({ name }) {
|
|
833
|
+
return operationsByTag.authentication.deleteUserAPIKey({
|
|
834
|
+
pathParams: { keyName: name },
|
|
560
835
|
...this.extraProps
|
|
561
836
|
});
|
|
562
837
|
}
|
|
@@ -565,342 +840,882 @@ class WorkspaceApi {
|
|
|
565
840
|
constructor(extraProps) {
|
|
566
841
|
this.extraProps = extraProps;
|
|
567
842
|
}
|
|
568
|
-
|
|
843
|
+
getWorkspacesList() {
|
|
844
|
+
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
|
845
|
+
}
|
|
846
|
+
createWorkspace({ data }) {
|
|
569
847
|
return operationsByTag.workspaces.createWorkspace({
|
|
570
|
-
body:
|
|
848
|
+
body: data,
|
|
571
849
|
...this.extraProps
|
|
572
850
|
});
|
|
573
851
|
}
|
|
574
|
-
|
|
575
|
-
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
|
576
|
-
}
|
|
577
|
-
getWorkspace(workspaceId) {
|
|
852
|
+
getWorkspace({ workspace }) {
|
|
578
853
|
return operationsByTag.workspaces.getWorkspace({
|
|
579
|
-
pathParams: { workspaceId },
|
|
854
|
+
pathParams: { workspaceId: workspace },
|
|
580
855
|
...this.extraProps
|
|
581
856
|
});
|
|
582
857
|
}
|
|
583
|
-
updateWorkspace(
|
|
858
|
+
updateWorkspace({
|
|
859
|
+
workspace,
|
|
860
|
+
update
|
|
861
|
+
}) {
|
|
584
862
|
return operationsByTag.workspaces.updateWorkspace({
|
|
585
|
-
pathParams: { workspaceId },
|
|
586
|
-
body:
|
|
863
|
+
pathParams: { workspaceId: workspace },
|
|
864
|
+
body: update,
|
|
587
865
|
...this.extraProps
|
|
588
866
|
});
|
|
589
867
|
}
|
|
590
|
-
deleteWorkspace(
|
|
868
|
+
deleteWorkspace({ workspace }) {
|
|
591
869
|
return operationsByTag.workspaces.deleteWorkspace({
|
|
592
|
-
pathParams: { workspaceId },
|
|
870
|
+
pathParams: { workspaceId: workspace },
|
|
593
871
|
...this.extraProps
|
|
594
872
|
});
|
|
595
873
|
}
|
|
596
|
-
getWorkspaceMembersList(
|
|
874
|
+
getWorkspaceMembersList({ workspace }) {
|
|
597
875
|
return operationsByTag.workspaces.getWorkspaceMembersList({
|
|
598
|
-
pathParams: { workspaceId },
|
|
876
|
+
pathParams: { workspaceId: workspace },
|
|
599
877
|
...this.extraProps
|
|
600
878
|
});
|
|
601
879
|
}
|
|
602
|
-
updateWorkspaceMemberRole(
|
|
880
|
+
updateWorkspaceMemberRole({
|
|
881
|
+
workspace,
|
|
882
|
+
user,
|
|
883
|
+
role
|
|
884
|
+
}) {
|
|
603
885
|
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
|
604
|
-
pathParams: { workspaceId, userId },
|
|
886
|
+
pathParams: { workspaceId: workspace, userId: user },
|
|
605
887
|
body: { role },
|
|
606
888
|
...this.extraProps
|
|
607
889
|
});
|
|
608
890
|
}
|
|
609
|
-
removeWorkspaceMember(
|
|
891
|
+
removeWorkspaceMember({
|
|
892
|
+
workspace,
|
|
893
|
+
user
|
|
894
|
+
}) {
|
|
610
895
|
return operationsByTag.workspaces.removeWorkspaceMember({
|
|
611
|
-
pathParams: { workspaceId, userId },
|
|
896
|
+
pathParams: { workspaceId: workspace, userId: user },
|
|
612
897
|
...this.extraProps
|
|
613
898
|
});
|
|
614
899
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
900
|
+
}
|
|
901
|
+
class InvitesApi {
|
|
902
|
+
constructor(extraProps) {
|
|
903
|
+
this.extraProps = extraProps;
|
|
904
|
+
}
|
|
905
|
+
inviteWorkspaceMember({
|
|
906
|
+
workspace,
|
|
907
|
+
email,
|
|
908
|
+
role
|
|
909
|
+
}) {
|
|
910
|
+
return operationsByTag.invites.inviteWorkspaceMember({
|
|
911
|
+
pathParams: { workspaceId: workspace },
|
|
618
912
|
body: { email, role },
|
|
619
913
|
...this.extraProps
|
|
620
914
|
});
|
|
621
915
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
916
|
+
updateWorkspaceMemberInvite({
|
|
917
|
+
workspace,
|
|
918
|
+
invite,
|
|
919
|
+
role
|
|
920
|
+
}) {
|
|
921
|
+
return operationsByTag.invites.updateWorkspaceMemberInvite({
|
|
922
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
|
923
|
+
body: { role },
|
|
625
924
|
...this.extraProps
|
|
626
925
|
});
|
|
627
926
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
927
|
+
cancelWorkspaceMemberInvite({
|
|
928
|
+
workspace,
|
|
929
|
+
invite
|
|
930
|
+
}) {
|
|
931
|
+
return operationsByTag.invites.cancelWorkspaceMemberInvite({
|
|
932
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
|
631
933
|
...this.extraProps
|
|
632
934
|
});
|
|
633
935
|
}
|
|
634
|
-
acceptWorkspaceMemberInvite(
|
|
635
|
-
|
|
636
|
-
|
|
936
|
+
acceptWorkspaceMemberInvite({
|
|
937
|
+
workspace,
|
|
938
|
+
key
|
|
939
|
+
}) {
|
|
940
|
+
return operationsByTag.invites.acceptWorkspaceMemberInvite({
|
|
941
|
+
pathParams: { workspaceId: workspace, inviteKey: key },
|
|
942
|
+
...this.extraProps
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
resendWorkspaceMemberInvite({
|
|
946
|
+
workspace,
|
|
947
|
+
invite
|
|
948
|
+
}) {
|
|
949
|
+
return operationsByTag.invites.resendWorkspaceMemberInvite({
|
|
950
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
|
637
951
|
...this.extraProps
|
|
638
952
|
});
|
|
639
953
|
}
|
|
640
954
|
}
|
|
641
|
-
class
|
|
955
|
+
class BranchApi {
|
|
642
956
|
constructor(extraProps) {
|
|
643
957
|
this.extraProps = extraProps;
|
|
644
958
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
959
|
+
getBranchList({
|
|
960
|
+
workspace,
|
|
961
|
+
region,
|
|
962
|
+
database
|
|
963
|
+
}) {
|
|
964
|
+
return operationsByTag.branch.getBranchList({
|
|
965
|
+
pathParams: { workspace, region, dbName: database },
|
|
966
|
+
...this.extraProps
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
getBranchDetails({
|
|
970
|
+
workspace,
|
|
971
|
+
region,
|
|
972
|
+
database,
|
|
973
|
+
branch
|
|
974
|
+
}) {
|
|
975
|
+
return operationsByTag.branch.getBranchDetails({
|
|
976
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
977
|
+
...this.extraProps
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
createBranch({
|
|
981
|
+
workspace,
|
|
982
|
+
region,
|
|
983
|
+
database,
|
|
984
|
+
branch,
|
|
985
|
+
from,
|
|
986
|
+
metadata
|
|
987
|
+
}) {
|
|
988
|
+
return operationsByTag.branch.createBranch({
|
|
989
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
990
|
+
body: { from, metadata },
|
|
648
991
|
...this.extraProps
|
|
649
992
|
});
|
|
650
993
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
994
|
+
deleteBranch({
|
|
995
|
+
workspace,
|
|
996
|
+
region,
|
|
997
|
+
database,
|
|
998
|
+
branch
|
|
999
|
+
}) {
|
|
1000
|
+
return operationsByTag.branch.deleteBranch({
|
|
1001
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
655
1002
|
...this.extraProps
|
|
656
1003
|
});
|
|
657
1004
|
}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
1005
|
+
updateBranchMetadata({
|
|
1006
|
+
workspace,
|
|
1007
|
+
region,
|
|
1008
|
+
database,
|
|
1009
|
+
branch,
|
|
1010
|
+
metadata
|
|
1011
|
+
}) {
|
|
1012
|
+
return operationsByTag.branch.updateBranchMetadata({
|
|
1013
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1014
|
+
body: metadata,
|
|
661
1015
|
...this.extraProps
|
|
662
1016
|
});
|
|
663
1017
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
1018
|
+
getBranchMetadata({
|
|
1019
|
+
workspace,
|
|
1020
|
+
region,
|
|
1021
|
+
database,
|
|
1022
|
+
branch
|
|
1023
|
+
}) {
|
|
1024
|
+
return operationsByTag.branch.getBranchMetadata({
|
|
1025
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
667
1026
|
...this.extraProps
|
|
668
1027
|
});
|
|
669
1028
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
1029
|
+
getBranchStats({
|
|
1030
|
+
workspace,
|
|
1031
|
+
region,
|
|
1032
|
+
database,
|
|
1033
|
+
branch
|
|
1034
|
+
}) {
|
|
1035
|
+
return operationsByTag.branch.getBranchStats({
|
|
1036
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
674
1037
|
...this.extraProps
|
|
675
1038
|
});
|
|
676
1039
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
1040
|
+
getGitBranchesMapping({
|
|
1041
|
+
workspace,
|
|
1042
|
+
region,
|
|
1043
|
+
database
|
|
1044
|
+
}) {
|
|
1045
|
+
return operationsByTag.branch.getGitBranchesMapping({
|
|
1046
|
+
pathParams: { workspace, region, dbName: database },
|
|
681
1047
|
...this.extraProps
|
|
682
1048
|
});
|
|
683
1049
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
1050
|
+
addGitBranchesEntry({
|
|
1051
|
+
workspace,
|
|
1052
|
+
region,
|
|
1053
|
+
database,
|
|
1054
|
+
gitBranch,
|
|
1055
|
+
xataBranch
|
|
1056
|
+
}) {
|
|
1057
|
+
return operationsByTag.branch.addGitBranchesEntry({
|
|
1058
|
+
pathParams: { workspace, region, dbName: database },
|
|
1059
|
+
body: { gitBranch, xataBranch },
|
|
1060
|
+
...this.extraProps
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
removeGitBranchesEntry({
|
|
1064
|
+
workspace,
|
|
1065
|
+
region,
|
|
1066
|
+
database,
|
|
1067
|
+
gitBranch
|
|
1068
|
+
}) {
|
|
1069
|
+
return operationsByTag.branch.removeGitBranchesEntry({
|
|
1070
|
+
pathParams: { workspace, region, dbName: database },
|
|
687
1071
|
queryParams: { gitBranch },
|
|
688
1072
|
...this.extraProps
|
|
689
1073
|
});
|
|
690
1074
|
}
|
|
1075
|
+
resolveBranch({
|
|
1076
|
+
workspace,
|
|
1077
|
+
region,
|
|
1078
|
+
database,
|
|
1079
|
+
gitBranch,
|
|
1080
|
+
fallbackBranch
|
|
1081
|
+
}) {
|
|
1082
|
+
return operationsByTag.branch.resolveBranch({
|
|
1083
|
+
pathParams: { workspace, region, dbName: database },
|
|
1084
|
+
queryParams: { gitBranch, fallbackBranch },
|
|
1085
|
+
...this.extraProps
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
691
1088
|
}
|
|
692
|
-
class
|
|
1089
|
+
class TableApi {
|
|
693
1090
|
constructor(extraProps) {
|
|
694
1091
|
this.extraProps = extraProps;
|
|
695
1092
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
1093
|
+
createTable({
|
|
1094
|
+
workspace,
|
|
1095
|
+
region,
|
|
1096
|
+
database,
|
|
1097
|
+
branch,
|
|
1098
|
+
table
|
|
1099
|
+
}) {
|
|
1100
|
+
return operationsByTag.table.createTable({
|
|
1101
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
699
1102
|
...this.extraProps
|
|
700
1103
|
});
|
|
701
1104
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
1105
|
+
deleteTable({
|
|
1106
|
+
workspace,
|
|
1107
|
+
region,
|
|
1108
|
+
database,
|
|
1109
|
+
branch,
|
|
1110
|
+
table
|
|
1111
|
+
}) {
|
|
1112
|
+
return operationsByTag.table.deleteTable({
|
|
1113
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
705
1114
|
...this.extraProps
|
|
706
1115
|
});
|
|
707
1116
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
1117
|
+
updateTable({
|
|
1118
|
+
workspace,
|
|
1119
|
+
region,
|
|
1120
|
+
database,
|
|
1121
|
+
branch,
|
|
1122
|
+
table,
|
|
1123
|
+
update
|
|
1124
|
+
}) {
|
|
1125
|
+
return operationsByTag.table.updateTable({
|
|
1126
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1127
|
+
body: update,
|
|
713
1128
|
...this.extraProps
|
|
714
1129
|
});
|
|
715
1130
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
1131
|
+
getTableSchema({
|
|
1132
|
+
workspace,
|
|
1133
|
+
region,
|
|
1134
|
+
database,
|
|
1135
|
+
branch,
|
|
1136
|
+
table
|
|
1137
|
+
}) {
|
|
1138
|
+
return operationsByTag.table.getTableSchema({
|
|
1139
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
719
1140
|
...this.extraProps
|
|
720
1141
|
});
|
|
721
1142
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
1143
|
+
setTableSchema({
|
|
1144
|
+
workspace,
|
|
1145
|
+
region,
|
|
1146
|
+
database,
|
|
1147
|
+
branch,
|
|
1148
|
+
table,
|
|
1149
|
+
schema
|
|
1150
|
+
}) {
|
|
1151
|
+
return operationsByTag.table.setTableSchema({
|
|
1152
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1153
|
+
body: schema,
|
|
726
1154
|
...this.extraProps
|
|
727
1155
|
});
|
|
728
1156
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1157
|
+
getTableColumns({
|
|
1158
|
+
workspace,
|
|
1159
|
+
region,
|
|
1160
|
+
database,
|
|
1161
|
+
branch,
|
|
1162
|
+
table
|
|
1163
|
+
}) {
|
|
1164
|
+
return operationsByTag.table.getTableColumns({
|
|
1165
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
732
1166
|
...this.extraProps
|
|
733
1167
|
});
|
|
734
1168
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
1169
|
+
addTableColumn({
|
|
1170
|
+
workspace,
|
|
1171
|
+
region,
|
|
1172
|
+
database,
|
|
1173
|
+
branch,
|
|
1174
|
+
table,
|
|
1175
|
+
column
|
|
1176
|
+
}) {
|
|
1177
|
+
return operationsByTag.table.addTableColumn({
|
|
1178
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1179
|
+
body: column,
|
|
739
1180
|
...this.extraProps
|
|
740
1181
|
});
|
|
741
1182
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
1183
|
+
getColumn({
|
|
1184
|
+
workspace,
|
|
1185
|
+
region,
|
|
1186
|
+
database,
|
|
1187
|
+
branch,
|
|
1188
|
+
table,
|
|
1189
|
+
column
|
|
1190
|
+
}) {
|
|
1191
|
+
return operationsByTag.table.getColumn({
|
|
1192
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
|
746
1193
|
...this.extraProps
|
|
747
1194
|
});
|
|
748
1195
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
1196
|
+
updateColumn({
|
|
1197
|
+
workspace,
|
|
1198
|
+
region,
|
|
1199
|
+
database,
|
|
1200
|
+
branch,
|
|
1201
|
+
table,
|
|
1202
|
+
column,
|
|
1203
|
+
update
|
|
1204
|
+
}) {
|
|
1205
|
+
return operationsByTag.table.updateColumn({
|
|
1206
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
|
1207
|
+
body: update,
|
|
753
1208
|
...this.extraProps
|
|
754
1209
|
});
|
|
755
1210
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
1211
|
+
deleteColumn({
|
|
1212
|
+
workspace,
|
|
1213
|
+
region,
|
|
1214
|
+
database,
|
|
1215
|
+
branch,
|
|
1216
|
+
table,
|
|
1217
|
+
column
|
|
1218
|
+
}) {
|
|
1219
|
+
return operationsByTag.table.deleteColumn({
|
|
1220
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
|
759
1221
|
...this.extraProps
|
|
760
1222
|
});
|
|
761
1223
|
}
|
|
762
1224
|
}
|
|
763
|
-
class
|
|
1225
|
+
class RecordsApi {
|
|
764
1226
|
constructor(extraProps) {
|
|
765
1227
|
this.extraProps = extraProps;
|
|
766
1228
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
1229
|
+
insertRecord({
|
|
1230
|
+
workspace,
|
|
1231
|
+
region,
|
|
1232
|
+
database,
|
|
1233
|
+
branch,
|
|
1234
|
+
table,
|
|
1235
|
+
record,
|
|
1236
|
+
columns
|
|
1237
|
+
}) {
|
|
1238
|
+
return operationsByTag.records.insertRecord({
|
|
1239
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1240
|
+
queryParams: { columns },
|
|
1241
|
+
body: record,
|
|
770
1242
|
...this.extraProps
|
|
771
1243
|
});
|
|
772
1244
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
1245
|
+
getRecord({
|
|
1246
|
+
workspace,
|
|
1247
|
+
region,
|
|
1248
|
+
database,
|
|
1249
|
+
branch,
|
|
1250
|
+
table,
|
|
1251
|
+
id,
|
|
1252
|
+
columns
|
|
1253
|
+
}) {
|
|
1254
|
+
return operationsByTag.records.getRecord({
|
|
1255
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
|
1256
|
+
queryParams: { columns },
|
|
776
1257
|
...this.extraProps
|
|
777
1258
|
});
|
|
778
1259
|
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
1260
|
+
insertRecordWithID({
|
|
1261
|
+
workspace,
|
|
1262
|
+
region,
|
|
1263
|
+
database,
|
|
1264
|
+
branch,
|
|
1265
|
+
table,
|
|
1266
|
+
id,
|
|
1267
|
+
record,
|
|
1268
|
+
columns,
|
|
1269
|
+
createOnly,
|
|
1270
|
+
ifVersion
|
|
1271
|
+
}) {
|
|
1272
|
+
return operationsByTag.records.insertRecordWithID({
|
|
1273
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
|
1274
|
+
queryParams: { columns, createOnly, ifVersion },
|
|
1275
|
+
body: record,
|
|
783
1276
|
...this.extraProps
|
|
784
1277
|
});
|
|
785
1278
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
1279
|
+
updateRecordWithID({
|
|
1280
|
+
workspace,
|
|
1281
|
+
region,
|
|
1282
|
+
database,
|
|
1283
|
+
branch,
|
|
1284
|
+
table,
|
|
1285
|
+
id,
|
|
1286
|
+
record,
|
|
1287
|
+
columns,
|
|
1288
|
+
ifVersion
|
|
1289
|
+
}) {
|
|
1290
|
+
return operationsByTag.records.updateRecordWithID({
|
|
1291
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
|
1292
|
+
queryParams: { columns, ifVersion },
|
|
1293
|
+
body: record,
|
|
1294
|
+
...this.extraProps
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
upsertRecordWithID({
|
|
1298
|
+
workspace,
|
|
1299
|
+
region,
|
|
1300
|
+
database,
|
|
1301
|
+
branch,
|
|
1302
|
+
table,
|
|
1303
|
+
id,
|
|
1304
|
+
record,
|
|
1305
|
+
columns,
|
|
1306
|
+
ifVersion
|
|
1307
|
+
}) {
|
|
1308
|
+
return operationsByTag.records.upsertRecordWithID({
|
|
1309
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
|
1310
|
+
queryParams: { columns, ifVersion },
|
|
1311
|
+
body: record,
|
|
1312
|
+
...this.extraProps
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
deleteRecord({
|
|
1316
|
+
workspace,
|
|
1317
|
+
region,
|
|
1318
|
+
database,
|
|
1319
|
+
branch,
|
|
1320
|
+
table,
|
|
1321
|
+
id,
|
|
1322
|
+
columns
|
|
1323
|
+
}) {
|
|
1324
|
+
return operationsByTag.records.deleteRecord({
|
|
1325
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
|
1326
|
+
queryParams: { columns },
|
|
789
1327
|
...this.extraProps
|
|
790
1328
|
});
|
|
791
1329
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
1330
|
+
bulkInsertTableRecords({
|
|
1331
|
+
workspace,
|
|
1332
|
+
region,
|
|
1333
|
+
database,
|
|
1334
|
+
branch,
|
|
1335
|
+
table,
|
|
1336
|
+
records,
|
|
1337
|
+
columns
|
|
1338
|
+
}) {
|
|
1339
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
|
1340
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1341
|
+
queryParams: { columns },
|
|
1342
|
+
body: { records },
|
|
1343
|
+
...this.extraProps
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
class SearchAndFilterApi {
|
|
1348
|
+
constructor(extraProps) {
|
|
1349
|
+
this.extraProps = extraProps;
|
|
1350
|
+
}
|
|
1351
|
+
queryTable({
|
|
1352
|
+
workspace,
|
|
1353
|
+
region,
|
|
1354
|
+
database,
|
|
1355
|
+
branch,
|
|
1356
|
+
table,
|
|
1357
|
+
filter,
|
|
1358
|
+
sort,
|
|
1359
|
+
page,
|
|
1360
|
+
columns
|
|
1361
|
+
}) {
|
|
1362
|
+
return operationsByTag.searchAndFilter.queryTable({
|
|
1363
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1364
|
+
body: { filter, sort, page, columns },
|
|
1365
|
+
...this.extraProps
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
searchTable({
|
|
1369
|
+
workspace,
|
|
1370
|
+
region,
|
|
1371
|
+
database,
|
|
1372
|
+
branch,
|
|
1373
|
+
table,
|
|
1374
|
+
query,
|
|
1375
|
+
fuzziness,
|
|
1376
|
+
target,
|
|
1377
|
+
prefix,
|
|
1378
|
+
filter,
|
|
1379
|
+
highlight,
|
|
1380
|
+
boosters
|
|
1381
|
+
}) {
|
|
1382
|
+
return operationsByTag.searchAndFilter.searchTable({
|
|
1383
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1384
|
+
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
|
1385
|
+
...this.extraProps
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
searchBranch({
|
|
1389
|
+
workspace,
|
|
1390
|
+
region,
|
|
1391
|
+
database,
|
|
1392
|
+
branch,
|
|
1393
|
+
tables,
|
|
1394
|
+
query,
|
|
1395
|
+
fuzziness,
|
|
1396
|
+
prefix,
|
|
1397
|
+
highlight
|
|
1398
|
+
}) {
|
|
1399
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
|
1400
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1401
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
|
1402
|
+
...this.extraProps
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
summarizeTable({
|
|
1406
|
+
workspace,
|
|
1407
|
+
region,
|
|
1408
|
+
database,
|
|
1409
|
+
branch,
|
|
1410
|
+
table,
|
|
1411
|
+
filter,
|
|
1412
|
+
columns,
|
|
1413
|
+
summaries,
|
|
1414
|
+
sort,
|
|
1415
|
+
summariesFilter,
|
|
1416
|
+
page
|
|
1417
|
+
}) {
|
|
1418
|
+
return operationsByTag.searchAndFilter.summarizeTable({
|
|
1419
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1420
|
+
body: { filter, columns, summaries, sort, summariesFilter, page },
|
|
1421
|
+
...this.extraProps
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
aggregateTable({
|
|
1425
|
+
workspace,
|
|
1426
|
+
region,
|
|
1427
|
+
database,
|
|
1428
|
+
branch,
|
|
1429
|
+
table,
|
|
1430
|
+
filter,
|
|
1431
|
+
aggs
|
|
1432
|
+
}) {
|
|
1433
|
+
return operationsByTag.searchAndFilter.aggregateTable({
|
|
1434
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
1435
|
+
body: { filter, aggs },
|
|
1436
|
+
...this.extraProps
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
class MigrationRequestsApi {
|
|
1441
|
+
constructor(extraProps) {
|
|
1442
|
+
this.extraProps = extraProps;
|
|
1443
|
+
}
|
|
1444
|
+
queryMigrationRequests({
|
|
1445
|
+
workspace,
|
|
1446
|
+
region,
|
|
1447
|
+
database,
|
|
1448
|
+
filter,
|
|
1449
|
+
sort,
|
|
1450
|
+
page,
|
|
1451
|
+
columns
|
|
1452
|
+
}) {
|
|
1453
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
|
1454
|
+
pathParams: { workspace, region, dbName: database },
|
|
1455
|
+
body: { filter, sort, page, columns },
|
|
1456
|
+
...this.extraProps
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
createMigrationRequest({
|
|
1460
|
+
workspace,
|
|
1461
|
+
region,
|
|
1462
|
+
database,
|
|
1463
|
+
migration
|
|
1464
|
+
}) {
|
|
1465
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
|
1466
|
+
pathParams: { workspace, region, dbName: database },
|
|
1467
|
+
body: migration,
|
|
1468
|
+
...this.extraProps
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
getMigrationRequest({
|
|
1472
|
+
workspace,
|
|
1473
|
+
region,
|
|
1474
|
+
database,
|
|
1475
|
+
migrationRequest
|
|
1476
|
+
}) {
|
|
1477
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
|
1478
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
|
1479
|
+
...this.extraProps
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
updateMigrationRequest({
|
|
1483
|
+
workspace,
|
|
1484
|
+
region,
|
|
1485
|
+
database,
|
|
1486
|
+
migrationRequest,
|
|
1487
|
+
update
|
|
1488
|
+
}) {
|
|
1489
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
|
1490
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
|
1491
|
+
body: update,
|
|
1492
|
+
...this.extraProps
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
listMigrationRequestsCommits({
|
|
1496
|
+
workspace,
|
|
1497
|
+
region,
|
|
1498
|
+
database,
|
|
1499
|
+
migrationRequest,
|
|
1500
|
+
page
|
|
1501
|
+
}) {
|
|
1502
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
|
1503
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
|
1504
|
+
body: { page },
|
|
1505
|
+
...this.extraProps
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
compareMigrationRequest({
|
|
1509
|
+
workspace,
|
|
1510
|
+
region,
|
|
1511
|
+
database,
|
|
1512
|
+
migrationRequest
|
|
1513
|
+
}) {
|
|
1514
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
|
1515
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
|
1516
|
+
...this.extraProps
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
getMigrationRequestIsMerged({
|
|
1520
|
+
workspace,
|
|
1521
|
+
region,
|
|
1522
|
+
database,
|
|
1523
|
+
migrationRequest
|
|
1524
|
+
}) {
|
|
1525
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
|
1526
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
|
1527
|
+
...this.extraProps
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
mergeMigrationRequest({
|
|
1531
|
+
workspace,
|
|
1532
|
+
region,
|
|
1533
|
+
database,
|
|
1534
|
+
migrationRequest
|
|
1535
|
+
}) {
|
|
1536
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
|
1537
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
|
1538
|
+
...this.extraProps
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
class MigrationsApi {
|
|
1543
|
+
constructor(extraProps) {
|
|
1544
|
+
this.extraProps = extraProps;
|
|
1545
|
+
}
|
|
1546
|
+
getBranchMigrationHistory({
|
|
1547
|
+
workspace,
|
|
1548
|
+
region,
|
|
1549
|
+
database,
|
|
1550
|
+
branch,
|
|
1551
|
+
limit,
|
|
1552
|
+
startFrom
|
|
1553
|
+
}) {
|
|
1554
|
+
return operationsByTag.migrations.getBranchMigrationHistory({
|
|
1555
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1556
|
+
body: { limit, startFrom },
|
|
796
1557
|
...this.extraProps
|
|
797
1558
|
});
|
|
798
1559
|
}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
1560
|
+
getBranchMigrationPlan({
|
|
1561
|
+
workspace,
|
|
1562
|
+
region,
|
|
1563
|
+
database,
|
|
1564
|
+
branch,
|
|
1565
|
+
schema
|
|
1566
|
+
}) {
|
|
1567
|
+
return operationsByTag.migrations.getBranchMigrationPlan({
|
|
1568
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1569
|
+
body: schema,
|
|
802
1570
|
...this.extraProps
|
|
803
1571
|
});
|
|
804
1572
|
}
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
1573
|
+
executeBranchMigrationPlan({
|
|
1574
|
+
workspace,
|
|
1575
|
+
region,
|
|
1576
|
+
database,
|
|
1577
|
+
branch,
|
|
1578
|
+
plan
|
|
1579
|
+
}) {
|
|
1580
|
+
return operationsByTag.migrations.executeBranchMigrationPlan({
|
|
1581
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1582
|
+
body: plan,
|
|
809
1583
|
...this.extraProps
|
|
810
1584
|
});
|
|
811
1585
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
1586
|
+
getBranchSchemaHistory({
|
|
1587
|
+
workspace,
|
|
1588
|
+
region,
|
|
1589
|
+
database,
|
|
1590
|
+
branch,
|
|
1591
|
+
page
|
|
1592
|
+
}) {
|
|
1593
|
+
return operationsByTag.migrations.getBranchSchemaHistory({
|
|
1594
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1595
|
+
body: { page },
|
|
815
1596
|
...this.extraProps
|
|
816
1597
|
});
|
|
817
1598
|
}
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
1599
|
+
compareBranchWithUserSchema({
|
|
1600
|
+
workspace,
|
|
1601
|
+
region,
|
|
1602
|
+
database,
|
|
1603
|
+
branch,
|
|
1604
|
+
schema
|
|
1605
|
+
}) {
|
|
1606
|
+
return operationsByTag.migrations.compareBranchWithUserSchema({
|
|
1607
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1608
|
+
body: { schema },
|
|
821
1609
|
...this.extraProps
|
|
822
1610
|
});
|
|
823
1611
|
}
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
1612
|
+
compareBranchSchemas({
|
|
1613
|
+
workspace,
|
|
1614
|
+
region,
|
|
1615
|
+
database,
|
|
1616
|
+
branch,
|
|
1617
|
+
compare,
|
|
1618
|
+
schema
|
|
1619
|
+
}) {
|
|
1620
|
+
return operationsByTag.migrations.compareBranchSchemas({
|
|
1621
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
|
1622
|
+
body: { schema },
|
|
828
1623
|
...this.extraProps
|
|
829
1624
|
});
|
|
830
1625
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
1626
|
+
updateBranchSchema({
|
|
1627
|
+
workspace,
|
|
1628
|
+
region,
|
|
1629
|
+
database,
|
|
1630
|
+
branch,
|
|
1631
|
+
migration
|
|
1632
|
+
}) {
|
|
1633
|
+
return operationsByTag.migrations.updateBranchSchema({
|
|
1634
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1635
|
+
body: migration,
|
|
840
1636
|
...this.extraProps
|
|
841
1637
|
});
|
|
842
1638
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
1639
|
+
previewBranchSchemaEdit({
|
|
1640
|
+
workspace,
|
|
1641
|
+
region,
|
|
1642
|
+
database,
|
|
1643
|
+
branch,
|
|
1644
|
+
data
|
|
1645
|
+
}) {
|
|
1646
|
+
return operationsByTag.migrations.previewBranchSchemaEdit({
|
|
1647
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1648
|
+
body: data,
|
|
848
1649
|
...this.extraProps
|
|
849
1650
|
});
|
|
850
1651
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1652
|
+
applyBranchSchemaEdit({
|
|
1653
|
+
workspace,
|
|
1654
|
+
region,
|
|
1655
|
+
database,
|
|
1656
|
+
branch,
|
|
1657
|
+
edits
|
|
1658
|
+
}) {
|
|
1659
|
+
return operationsByTag.migrations.applyBranchSchemaEdit({
|
|
1660
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1661
|
+
body: { edits },
|
|
856
1662
|
...this.extraProps
|
|
857
1663
|
});
|
|
858
1664
|
}
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
body: record,
|
|
864
|
-
...this.extraProps
|
|
865
|
-
});
|
|
1665
|
+
}
|
|
1666
|
+
class DatabaseApi {
|
|
1667
|
+
constructor(extraProps) {
|
|
1668
|
+
this.extraProps = extraProps;
|
|
866
1669
|
}
|
|
867
|
-
|
|
868
|
-
return operationsByTag.
|
|
869
|
-
pathParams: {
|
|
1670
|
+
getDatabaseList({ workspace }) {
|
|
1671
|
+
return operationsByTag.databases.getDatabaseList({
|
|
1672
|
+
pathParams: { workspaceId: workspace },
|
|
870
1673
|
...this.extraProps
|
|
871
1674
|
});
|
|
872
1675
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1676
|
+
createDatabase({
|
|
1677
|
+
workspace,
|
|
1678
|
+
database,
|
|
1679
|
+
data
|
|
1680
|
+
}) {
|
|
1681
|
+
return operationsByTag.databases.createDatabase({
|
|
1682
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
1683
|
+
body: data,
|
|
876
1684
|
...this.extraProps
|
|
877
1685
|
});
|
|
878
1686
|
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
1687
|
+
deleteDatabase({
|
|
1688
|
+
workspace,
|
|
1689
|
+
database
|
|
1690
|
+
}) {
|
|
1691
|
+
return operationsByTag.databases.deleteDatabase({
|
|
1692
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
883
1693
|
...this.extraProps
|
|
884
1694
|
});
|
|
885
1695
|
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
1696
|
+
getDatabaseMetadata({
|
|
1697
|
+
workspace,
|
|
1698
|
+
database
|
|
1699
|
+
}) {
|
|
1700
|
+
return operationsByTag.databases.getDatabaseMetadata({
|
|
1701
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
890
1702
|
...this.extraProps
|
|
891
1703
|
});
|
|
892
1704
|
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1705
|
+
updateDatabaseMetadata({
|
|
1706
|
+
workspace,
|
|
1707
|
+
database,
|
|
1708
|
+
metadata
|
|
1709
|
+
}) {
|
|
1710
|
+
return operationsByTag.databases.updateDatabaseMetadata({
|
|
1711
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
1712
|
+
body: metadata,
|
|
897
1713
|
...this.extraProps
|
|
898
1714
|
});
|
|
899
1715
|
}
|
|
900
|
-
|
|
901
|
-
return operationsByTag.
|
|
902
|
-
pathParams: {
|
|
903
|
-
body: query,
|
|
1716
|
+
listRegions({ workspace }) {
|
|
1717
|
+
return operationsByTag.databases.listRegions({
|
|
1718
|
+
pathParams: { workspaceId: workspace },
|
|
904
1719
|
...this.extraProps
|
|
905
1720
|
});
|
|
906
1721
|
}
|
|
@@ -916,6 +1731,20 @@ class XataApiPlugin {
|
|
|
916
1731
|
class XataPlugin {
|
|
917
1732
|
}
|
|
918
1733
|
|
|
1734
|
+
function generateUUID() {
|
|
1735
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
1736
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
1737
|
+
return v.toString(16);
|
|
1738
|
+
});
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
function cleanFilter(filter) {
|
|
1742
|
+
if (!filter)
|
|
1743
|
+
return void 0;
|
|
1744
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
|
1745
|
+
return values.length > 0 ? filter : void 0;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
919
1748
|
var __accessCheck$6 = (obj, member, msg) => {
|
|
920
1749
|
if (!member.has(obj))
|
|
921
1750
|
throw TypeError("Cannot " + msg);
|
|
@@ -929,18 +1758,18 @@ var __privateAdd$6 = (obj, member, value) => {
|
|
|
929
1758
|
throw TypeError("Cannot add the same private member more than once");
|
|
930
1759
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
931
1760
|
};
|
|
932
|
-
var __privateSet$
|
|
1761
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
|
933
1762
|
__accessCheck$6(obj, member, "write to private field");
|
|
934
1763
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
935
1764
|
return value;
|
|
936
1765
|
};
|
|
937
|
-
var _query;
|
|
1766
|
+
var _query, _page;
|
|
938
1767
|
class Page {
|
|
939
1768
|
constructor(query, meta, records = []) {
|
|
940
1769
|
__privateAdd$6(this, _query, void 0);
|
|
941
|
-
__privateSet$
|
|
1770
|
+
__privateSet$6(this, _query, query);
|
|
942
1771
|
this.meta = meta;
|
|
943
|
-
this.records = records;
|
|
1772
|
+
this.records = new RecordArray(this, records);
|
|
944
1773
|
}
|
|
945
1774
|
async nextPage(size, offset) {
|
|
946
1775
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
|
@@ -960,9 +1789,56 @@ class Page {
|
|
|
960
1789
|
}
|
|
961
1790
|
_query = new WeakMap();
|
|
962
1791
|
const PAGINATION_MAX_SIZE = 200;
|
|
963
|
-
const PAGINATION_DEFAULT_SIZE =
|
|
1792
|
+
const PAGINATION_DEFAULT_SIZE = 20;
|
|
964
1793
|
const PAGINATION_MAX_OFFSET = 800;
|
|
965
1794
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1795
|
+
function isCursorPaginationOptions(options) {
|
|
1796
|
+
return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
|
|
1797
|
+
}
|
|
1798
|
+
const _RecordArray = class extends Array {
|
|
1799
|
+
constructor(...args) {
|
|
1800
|
+
super(..._RecordArray.parseConstructorParams(...args));
|
|
1801
|
+
__privateAdd$6(this, _page, void 0);
|
|
1802
|
+
__privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
|
|
1803
|
+
}
|
|
1804
|
+
static parseConstructorParams(...args) {
|
|
1805
|
+
if (args.length === 1 && typeof args[0] === "number") {
|
|
1806
|
+
return new Array(args[0]);
|
|
1807
|
+
}
|
|
1808
|
+
if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
|
|
1809
|
+
const result = args[1] ?? args[0].records ?? [];
|
|
1810
|
+
return new Array(...result);
|
|
1811
|
+
}
|
|
1812
|
+
return new Array(...args);
|
|
1813
|
+
}
|
|
1814
|
+
toArray() {
|
|
1815
|
+
return new Array(...this);
|
|
1816
|
+
}
|
|
1817
|
+
map(callbackfn, thisArg) {
|
|
1818
|
+
return this.toArray().map(callbackfn, thisArg);
|
|
1819
|
+
}
|
|
1820
|
+
async nextPage(size, offset) {
|
|
1821
|
+
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
|
1822
|
+
return new _RecordArray(newPage);
|
|
1823
|
+
}
|
|
1824
|
+
async previousPage(size, offset) {
|
|
1825
|
+
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
|
1826
|
+
return new _RecordArray(newPage);
|
|
1827
|
+
}
|
|
1828
|
+
async firstPage(size, offset) {
|
|
1829
|
+
const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
|
|
1830
|
+
return new _RecordArray(newPage);
|
|
1831
|
+
}
|
|
1832
|
+
async lastPage(size, offset) {
|
|
1833
|
+
const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
|
|
1834
|
+
return new _RecordArray(newPage);
|
|
1835
|
+
}
|
|
1836
|
+
hasNextPage() {
|
|
1837
|
+
return __privateGet$6(this, _page).meta.page.more;
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
let RecordArray = _RecordArray;
|
|
1841
|
+
_page = new WeakMap();
|
|
966
1842
|
|
|
967
1843
|
var __accessCheck$5 = (obj, member, msg) => {
|
|
968
1844
|
if (!member.has(obj))
|
|
@@ -977,32 +1853,38 @@ var __privateAdd$5 = (obj, member, value) => {
|
|
|
977
1853
|
throw TypeError("Cannot add the same private member more than once");
|
|
978
1854
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
979
1855
|
};
|
|
980
|
-
var __privateSet$
|
|
1856
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
|
981
1857
|
__accessCheck$5(obj, member, "write to private field");
|
|
982
1858
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
983
1859
|
return value;
|
|
984
1860
|
};
|
|
985
|
-
var
|
|
1861
|
+
var __privateMethod$3 = (obj, member, method) => {
|
|
1862
|
+
__accessCheck$5(obj, member, "access private method");
|
|
1863
|
+
return method;
|
|
1864
|
+
};
|
|
1865
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
|
986
1866
|
const _Query = class {
|
|
987
|
-
constructor(repository, table, data,
|
|
1867
|
+
constructor(repository, table, data, rawParent) {
|
|
1868
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
|
988
1869
|
__privateAdd$5(this, _table$1, void 0);
|
|
989
1870
|
__privateAdd$5(this, _repository, void 0);
|
|
990
1871
|
__privateAdd$5(this, _data, { filter: {} });
|
|
991
1872
|
this.meta = { page: { cursor: "start", more: true } };
|
|
992
|
-
this.records = [];
|
|
993
|
-
__privateSet$
|
|
1873
|
+
this.records = new RecordArray(this, []);
|
|
1874
|
+
__privateSet$5(this, _table$1, table);
|
|
994
1875
|
if (repository) {
|
|
995
|
-
__privateSet$
|
|
1876
|
+
__privateSet$5(this, _repository, repository);
|
|
996
1877
|
} else {
|
|
997
|
-
__privateSet$
|
|
1878
|
+
__privateSet$5(this, _repository, this);
|
|
998
1879
|
}
|
|
1880
|
+
const parent = cleanParent(data, rawParent);
|
|
999
1881
|
__privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
|
|
1000
1882
|
__privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
|
|
1001
1883
|
__privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
|
|
1002
1884
|
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
|
1003
1885
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
|
1004
1886
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
|
1005
|
-
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns
|
|
1887
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
|
1006
1888
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
|
1007
1889
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
|
1008
1890
|
this.any = this.any.bind(this);
|
|
@@ -1040,21 +1922,29 @@ const _Query = class {
|
|
|
1040
1922
|
}
|
|
1041
1923
|
filter(a, b) {
|
|
1042
1924
|
if (arguments.length === 1) {
|
|
1043
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
|
1925
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
|
1926
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
|
1927
|
+
}));
|
|
1044
1928
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
|
1045
1929
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1046
1930
|
} else {
|
|
1047
|
-
const
|
|
1931
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
|
1932
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
|
1048
1933
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1049
1934
|
}
|
|
1050
1935
|
}
|
|
1051
|
-
sort(column, direction) {
|
|
1936
|
+
sort(column, direction = "asc") {
|
|
1052
1937
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
|
1053
1938
|
const sort = [...originalSort, { column, direction }];
|
|
1054
1939
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
|
1055
1940
|
}
|
|
1056
1941
|
select(columns) {
|
|
1057
|
-
return new _Query(
|
|
1942
|
+
return new _Query(
|
|
1943
|
+
__privateGet$5(this, _repository),
|
|
1944
|
+
__privateGet$5(this, _table$1),
|
|
1945
|
+
{ columns },
|
|
1946
|
+
__privateGet$5(this, _data)
|
|
1947
|
+
);
|
|
1058
1948
|
}
|
|
1059
1949
|
getPaginated(options = {}) {
|
|
1060
1950
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
|
@@ -1067,18 +1957,30 @@ const _Query = class {
|
|
|
1067
1957
|
}
|
|
1068
1958
|
async *getIterator(options = {}) {
|
|
1069
1959
|
const { batchSize = 1 } = options;
|
|
1070
|
-
let
|
|
1071
|
-
let
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1960
|
+
let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
|
|
1961
|
+
let more = page.hasNextPage();
|
|
1962
|
+
yield page.records;
|
|
1963
|
+
while (more) {
|
|
1964
|
+
page = await page.nextPage();
|
|
1965
|
+
more = page.hasNextPage();
|
|
1966
|
+
yield page.records;
|
|
1077
1967
|
}
|
|
1078
1968
|
}
|
|
1079
1969
|
async getMany(options = {}) {
|
|
1080
|
-
const {
|
|
1081
|
-
|
|
1970
|
+
const { pagination = {}, ...rest } = options;
|
|
1971
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
|
1972
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
|
1973
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
|
1974
|
+
const results = [...page.records];
|
|
1975
|
+
while (page.hasNextPage() && results.length < size) {
|
|
1976
|
+
page = await page.nextPage();
|
|
1977
|
+
results.push(...page.records);
|
|
1978
|
+
}
|
|
1979
|
+
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
|
1980
|
+
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
|
1981
|
+
}
|
|
1982
|
+
const array = new RecordArray(page, results.slice(0, size));
|
|
1983
|
+
return array;
|
|
1082
1984
|
}
|
|
1083
1985
|
async getAll(options = {}) {
|
|
1084
1986
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
|
@@ -1092,6 +1994,22 @@ const _Query = class {
|
|
|
1092
1994
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
|
1093
1995
|
return records[0] ?? null;
|
|
1094
1996
|
}
|
|
1997
|
+
async getFirstOrThrow(options = {}) {
|
|
1998
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
|
1999
|
+
if (records[0] === void 0)
|
|
2000
|
+
throw new Error("No results found.");
|
|
2001
|
+
return records[0];
|
|
2002
|
+
}
|
|
2003
|
+
async summarize(params = {}) {
|
|
2004
|
+
const { summaries, summariesFilter, ...options } = params;
|
|
2005
|
+
const query = new _Query(
|
|
2006
|
+
__privateGet$5(this, _repository),
|
|
2007
|
+
__privateGet$5(this, _table$1),
|
|
2008
|
+
options,
|
|
2009
|
+
__privateGet$5(this, _data)
|
|
2010
|
+
);
|
|
2011
|
+
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
|
2012
|
+
}
|
|
1095
2013
|
cache(ttl) {
|
|
1096
2014
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
|
1097
2015
|
}
|
|
@@ -1115,12 +2033,31 @@ let Query = _Query;
|
|
|
1115
2033
|
_table$1 = new WeakMap();
|
|
1116
2034
|
_repository = new WeakMap();
|
|
1117
2035
|
_data = new WeakMap();
|
|
2036
|
+
_cleanFilterConstraint = new WeakSet();
|
|
2037
|
+
cleanFilterConstraint_fn = function(column, value) {
|
|
2038
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
|
2039
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
|
2040
|
+
return { $includes: value };
|
|
2041
|
+
}
|
|
2042
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
|
2043
|
+
return value.id;
|
|
2044
|
+
}
|
|
2045
|
+
return value;
|
|
2046
|
+
};
|
|
2047
|
+
function cleanParent(data, parent) {
|
|
2048
|
+
if (isCursorPaginationOptions(data.pagination)) {
|
|
2049
|
+
return { ...parent, sort: void 0, filter: void 0 };
|
|
2050
|
+
}
|
|
2051
|
+
return parent;
|
|
2052
|
+
}
|
|
1118
2053
|
|
|
1119
2054
|
function isIdentifiable(x) {
|
|
1120
2055
|
return isObject(x) && isString(x?.id);
|
|
1121
2056
|
}
|
|
1122
2057
|
function isXataRecord(x) {
|
|
1123
|
-
|
|
2058
|
+
const record = x;
|
|
2059
|
+
const metadata = record?.getMetadata();
|
|
2060
|
+
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
|
1124
2061
|
}
|
|
1125
2062
|
|
|
1126
2063
|
function isSortFilterString(value) {
|
|
@@ -1159,7 +2096,7 @@ var __privateAdd$4 = (obj, member, value) => {
|
|
|
1159
2096
|
throw TypeError("Cannot add the same private member more than once");
|
|
1160
2097
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1161
2098
|
};
|
|
1162
|
-
var __privateSet$
|
|
2099
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
|
1163
2100
|
__accessCheck$4(obj, member, "write to private field");
|
|
1164
2101
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1165
2102
|
return value;
|
|
@@ -1168,295 +2105,486 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
|
1168
2105
|
__accessCheck$4(obj, member, "access private method");
|
|
1169
2106
|
return method;
|
|
1170
2107
|
};
|
|
1171
|
-
var _table, _getFetchProps, _cache,
|
|
2108
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _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;
|
|
1172
2109
|
class Repository extends Query {
|
|
1173
2110
|
}
|
|
1174
2111
|
class RestRepository extends Query {
|
|
1175
2112
|
constructor(options) {
|
|
1176
|
-
super(
|
|
2113
|
+
super(
|
|
2114
|
+
null,
|
|
2115
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
|
2116
|
+
{}
|
|
2117
|
+
);
|
|
1177
2118
|
__privateAdd$4(this, _insertRecordWithoutId);
|
|
1178
2119
|
__privateAdd$4(this, _insertRecordWithId);
|
|
1179
2120
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
|
1180
2121
|
__privateAdd$4(this, _updateRecordWithID);
|
|
1181
2122
|
__privateAdd$4(this, _upsertRecordWithID);
|
|
1182
2123
|
__privateAdd$4(this, _deleteRecord);
|
|
1183
|
-
__privateAdd$4(this, _invalidateCache);
|
|
1184
|
-
__privateAdd$4(this, _setCacheRecord);
|
|
1185
|
-
__privateAdd$4(this, _getCacheRecord);
|
|
1186
2124
|
__privateAdd$4(this, _setCacheQuery);
|
|
1187
2125
|
__privateAdd$4(this, _getCacheQuery);
|
|
1188
|
-
__privateAdd$4(this,
|
|
2126
|
+
__privateAdd$4(this, _getSchemaTables$1);
|
|
1189
2127
|
__privateAdd$4(this, _table, void 0);
|
|
1190
2128
|
__privateAdd$4(this, _getFetchProps, void 0);
|
|
2129
|
+
__privateAdd$4(this, _db, void 0);
|
|
1191
2130
|
__privateAdd$4(this, _cache, void 0);
|
|
1192
|
-
__privateAdd$4(this,
|
|
1193
|
-
|
|
1194
|
-
__privateSet$
|
|
1195
|
-
this
|
|
1196
|
-
__privateSet$
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
return record;
|
|
1210
|
-
}
|
|
1211
|
-
if (isObject(a) && isString(a.id)) {
|
|
1212
|
-
if (a.id === "")
|
|
1213
|
-
throw new Error("The id can't be empty");
|
|
1214
|
-
const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
|
|
1215
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1216
|
-
return record;
|
|
1217
|
-
}
|
|
1218
|
-
if (isObject(a)) {
|
|
1219
|
-
const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
|
|
1220
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1221
|
-
return record;
|
|
1222
|
-
}
|
|
1223
|
-
throw new Error("Invalid arguments for create method");
|
|
1224
|
-
}
|
|
1225
|
-
async read(recordId) {
|
|
1226
|
-
const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
|
|
1227
|
-
if (cacheRecord)
|
|
1228
|
-
return cacheRecord;
|
|
1229
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1230
|
-
try {
|
|
1231
|
-
const response = await getRecord({
|
|
1232
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
|
1233
|
-
...fetchProps
|
|
2131
|
+
__privateAdd$4(this, _schemaTables$2, void 0);
|
|
2132
|
+
__privateAdd$4(this, _trace, void 0);
|
|
2133
|
+
__privateSet$4(this, _table, options.table);
|
|
2134
|
+
__privateSet$4(this, _db, options.db);
|
|
2135
|
+
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
|
2136
|
+
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
|
2137
|
+
__privateSet$4(this, _getFetchProps, async () => {
|
|
2138
|
+
const props = await options.pluginOptions.getFetchProps();
|
|
2139
|
+
return { ...props, sessionID: generateUUID() };
|
|
2140
|
+
});
|
|
2141
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
|
2142
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
|
2143
|
+
return trace(name, fn, {
|
|
2144
|
+
...options2,
|
|
2145
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
|
2146
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
|
2147
|
+
[TraceAttributes.VERSION]: VERSION
|
|
1234
2148
|
});
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
2149
|
+
});
|
|
2150
|
+
}
|
|
2151
|
+
async create(a, b, c, d) {
|
|
2152
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
|
2153
|
+
const ifVersion = parseIfVersion(b, c, d);
|
|
2154
|
+
if (Array.isArray(a)) {
|
|
2155
|
+
if (a.length === 0)
|
|
2156
|
+
return [];
|
|
2157
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
2158
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
|
1240
2159
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
2160
|
+
if (isString(a) && isObject(b)) {
|
|
2161
|
+
if (a === "")
|
|
2162
|
+
throw new Error("The id can't be empty");
|
|
2163
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
2164
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
|
2165
|
+
}
|
|
2166
|
+
if (isObject(a) && isString(a.id)) {
|
|
2167
|
+
if (a.id === "")
|
|
2168
|
+
throw new Error("The id can't be empty");
|
|
2169
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
2170
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
|
2171
|
+
}
|
|
2172
|
+
if (isObject(a)) {
|
|
2173
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
2174
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
|
2175
|
+
}
|
|
2176
|
+
throw new Error("Invalid arguments for create method");
|
|
2177
|
+
});
|
|
1243
2178
|
}
|
|
1244
|
-
async
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
2179
|
+
async read(a, b) {
|
|
2180
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
|
2181
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
2182
|
+
if (Array.isArray(a)) {
|
|
2183
|
+
if (a.length === 0)
|
|
2184
|
+
return [];
|
|
2185
|
+
const ids = a.map((item) => extractId(item));
|
|
2186
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
|
2187
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
|
2188
|
+
acc[object.id] = object;
|
|
2189
|
+
return acc;
|
|
2190
|
+
}, {});
|
|
2191
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
|
1248
2192
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
2193
|
+
const id = extractId(a);
|
|
2194
|
+
if (id) {
|
|
2195
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2196
|
+
try {
|
|
2197
|
+
const response = await getRecord({
|
|
2198
|
+
pathParams: {
|
|
2199
|
+
workspace: "{workspaceId}",
|
|
2200
|
+
dbBranchName: "{dbBranch}",
|
|
2201
|
+
region: "{region}",
|
|
2202
|
+
tableName: __privateGet$4(this, _table),
|
|
2203
|
+
recordId: id
|
|
2204
|
+
},
|
|
2205
|
+
queryParams: { columns },
|
|
2206
|
+
...fetchProps
|
|
2207
|
+
});
|
|
2208
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2209
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2210
|
+
} catch (e) {
|
|
2211
|
+
if (isObject(e) && e.status === 404) {
|
|
2212
|
+
return null;
|
|
2213
|
+
}
|
|
2214
|
+
throw e;
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
return null;
|
|
2218
|
+
});
|
|
1264
2219
|
}
|
|
1265
|
-
async
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
2220
|
+
async readOrThrow(a, b) {
|
|
2221
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
|
2222
|
+
const result = await this.read(a, b);
|
|
2223
|
+
if (Array.isArray(result)) {
|
|
2224
|
+
const missingIds = compact(
|
|
2225
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
2226
|
+
);
|
|
2227
|
+
if (missingIds.length > 0) {
|
|
2228
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
2229
|
+
}
|
|
2230
|
+
return result;
|
|
1269
2231
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
return record;
|
|
1277
|
-
}
|
|
1278
|
-
if (isObject(a) && isString(a.id)) {
|
|
1279
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
|
1280
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
|
1281
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
|
1282
|
-
return record;
|
|
1283
|
-
}
|
|
1284
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
|
2232
|
+
if (result === null) {
|
|
2233
|
+
const id = extractId(a) ?? "unknown";
|
|
2234
|
+
throw new Error(`Record with id ${id} not found`);
|
|
2235
|
+
}
|
|
2236
|
+
return result;
|
|
2237
|
+
});
|
|
1285
2238
|
}
|
|
1286
|
-
async
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
2239
|
+
async update(a, b, c, d) {
|
|
2240
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
|
2241
|
+
const ifVersion = parseIfVersion(b, c, d);
|
|
2242
|
+
if (Array.isArray(a)) {
|
|
2243
|
+
if (a.length === 0)
|
|
2244
|
+
return [];
|
|
2245
|
+
if (a.length > 100) {
|
|
2246
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
2247
|
+
}
|
|
2248
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
2249
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
|
1290
2250
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
2251
|
+
if (isString(a) && isObject(b)) {
|
|
2252
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
2253
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
|
2254
|
+
}
|
|
2255
|
+
if (isObject(a) && isString(a.id)) {
|
|
2256
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
2257
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
|
2258
|
+
}
|
|
2259
|
+
throw new Error("Invalid arguments for update method");
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2262
|
+
async updateOrThrow(a, b, c, d) {
|
|
2263
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
|
2264
|
+
const result = await this.update(a, b, c, d);
|
|
2265
|
+
if (Array.isArray(result)) {
|
|
2266
|
+
const missingIds = compact(
|
|
2267
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
2268
|
+
);
|
|
2269
|
+
if (missingIds.length > 0) {
|
|
2270
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
2271
|
+
}
|
|
2272
|
+
return result;
|
|
2273
|
+
}
|
|
2274
|
+
if (result === null) {
|
|
2275
|
+
const id = extractId(a) ?? "unknown";
|
|
2276
|
+
throw new Error(`Record with id ${id} not found`);
|
|
2277
|
+
}
|
|
2278
|
+
return result;
|
|
2279
|
+
});
|
|
2280
|
+
}
|
|
2281
|
+
async createOrUpdate(a, b, c, d) {
|
|
2282
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
|
2283
|
+
const ifVersion = parseIfVersion(b, c, d);
|
|
2284
|
+
if (Array.isArray(a)) {
|
|
2285
|
+
if (a.length === 0)
|
|
2286
|
+
return [];
|
|
2287
|
+
if (a.length > 100) {
|
|
2288
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
2289
|
+
}
|
|
2290
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
2291
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
|
2292
|
+
}
|
|
2293
|
+
if (isString(a) && isObject(b)) {
|
|
2294
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
2295
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
|
2296
|
+
}
|
|
2297
|
+
if (isObject(a) && isString(a.id)) {
|
|
2298
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
2299
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
|
2300
|
+
}
|
|
2301
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
|
2302
|
+
});
|
|
2303
|
+
}
|
|
2304
|
+
async createOrReplace(a, b, c, d) {
|
|
2305
|
+
return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
|
|
2306
|
+
const ifVersion = parseIfVersion(b, c, d);
|
|
2307
|
+
if (Array.isArray(a)) {
|
|
2308
|
+
if (a.length === 0)
|
|
2309
|
+
return [];
|
|
2310
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
2311
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
|
2312
|
+
}
|
|
2313
|
+
if (isString(a) && isObject(b)) {
|
|
2314
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
2315
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
|
2316
|
+
}
|
|
2317
|
+
if (isObject(a) && isString(a.id)) {
|
|
2318
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
2319
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
|
2320
|
+
}
|
|
2321
|
+
throw new Error("Invalid arguments for createOrReplace method");
|
|
2322
|
+
});
|
|
2323
|
+
}
|
|
2324
|
+
async delete(a, b) {
|
|
2325
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
|
2326
|
+
if (Array.isArray(a)) {
|
|
2327
|
+
if (a.length === 0)
|
|
2328
|
+
return [];
|
|
2329
|
+
if (a.length > 100) {
|
|
2330
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
|
2331
|
+
}
|
|
2332
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
|
2333
|
+
}
|
|
2334
|
+
if (isString(a)) {
|
|
2335
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
|
2336
|
+
}
|
|
2337
|
+
if (isObject(a) && isString(a.id)) {
|
|
2338
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
|
2339
|
+
}
|
|
2340
|
+
throw new Error("Invalid arguments for delete method");
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
async deleteOrThrow(a, b) {
|
|
2344
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
|
2345
|
+
const result = await this.delete(a, b);
|
|
2346
|
+
if (Array.isArray(result)) {
|
|
2347
|
+
const missingIds = compact(
|
|
2348
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
2349
|
+
);
|
|
2350
|
+
if (missingIds.length > 0) {
|
|
2351
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
2352
|
+
}
|
|
2353
|
+
return result;
|
|
2354
|
+
} else if (result === null) {
|
|
2355
|
+
const id = extractId(a) ?? "unknown";
|
|
2356
|
+
throw new Error(`Record with id ${id} not found`);
|
|
2357
|
+
}
|
|
2358
|
+
return result;
|
|
2359
|
+
});
|
|
1305
2360
|
}
|
|
1306
2361
|
async search(query, options = {}) {
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
2362
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
|
2363
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2364
|
+
const { records } = await searchTable({
|
|
2365
|
+
pathParams: {
|
|
2366
|
+
workspace: "{workspaceId}",
|
|
2367
|
+
dbBranchName: "{dbBranch}",
|
|
2368
|
+
region: "{region}",
|
|
2369
|
+
tableName: __privateGet$4(this, _table)
|
|
2370
|
+
},
|
|
2371
|
+
body: {
|
|
2372
|
+
query,
|
|
2373
|
+
fuzziness: options.fuzziness,
|
|
2374
|
+
prefix: options.prefix,
|
|
2375
|
+
highlight: options.highlight,
|
|
2376
|
+
filter: options.filter,
|
|
2377
|
+
boosters: options.boosters
|
|
2378
|
+
},
|
|
2379
|
+
...fetchProps
|
|
2380
|
+
});
|
|
2381
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2382
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
async aggregate(aggs, filter) {
|
|
2386
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
|
2387
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2388
|
+
const result = await aggregateTable({
|
|
2389
|
+
pathParams: {
|
|
2390
|
+
workspace: "{workspaceId}",
|
|
2391
|
+
dbBranchName: "{dbBranch}",
|
|
2392
|
+
region: "{region}",
|
|
2393
|
+
tableName: __privateGet$4(this, _table)
|
|
2394
|
+
},
|
|
2395
|
+
body: { aggs, filter },
|
|
2396
|
+
...fetchProps
|
|
2397
|
+
});
|
|
2398
|
+
return result;
|
|
1316
2399
|
});
|
|
1317
|
-
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
|
1318
|
-
return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
|
|
1319
2400
|
}
|
|
1320
2401
|
async query(query) {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
2402
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
|
2403
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
|
2404
|
+
if (cacheQuery)
|
|
2405
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
|
2406
|
+
const data = query.getQueryOptions();
|
|
2407
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2408
|
+
const { meta, records: objects } = await queryTable({
|
|
2409
|
+
pathParams: {
|
|
2410
|
+
workspace: "{workspaceId}",
|
|
2411
|
+
dbBranchName: "{dbBranch}",
|
|
2412
|
+
region: "{region}",
|
|
2413
|
+
tableName: __privateGet$4(this, _table)
|
|
2414
|
+
},
|
|
2415
|
+
body: {
|
|
2416
|
+
filter: cleanFilter(data.filter),
|
|
2417
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
|
2418
|
+
page: data.pagination,
|
|
2419
|
+
columns: data.columns ?? ["*"]
|
|
2420
|
+
},
|
|
2421
|
+
...fetchProps
|
|
2422
|
+
});
|
|
2423
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2424
|
+
const records = objects.map(
|
|
2425
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
|
2426
|
+
);
|
|
2427
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
2428
|
+
return new Page(query, meta, records);
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
async summarizeTable(query, summaries, summariesFilter) {
|
|
2432
|
+
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
|
2433
|
+
const data = query.getQueryOptions();
|
|
2434
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2435
|
+
const result = await summarizeTable({
|
|
2436
|
+
pathParams: {
|
|
2437
|
+
workspace: "{workspaceId}",
|
|
2438
|
+
dbBranchName: "{dbBranch}",
|
|
2439
|
+
region: "{region}",
|
|
2440
|
+
tableName: __privateGet$4(this, _table)
|
|
2441
|
+
},
|
|
2442
|
+
body: {
|
|
2443
|
+
filter: cleanFilter(data.filter),
|
|
2444
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
|
2445
|
+
columns: data.columns,
|
|
2446
|
+
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
|
2447
|
+
summaries,
|
|
2448
|
+
summariesFilter
|
|
2449
|
+
},
|
|
2450
|
+
...fetchProps
|
|
2451
|
+
});
|
|
2452
|
+
return result;
|
|
1336
2453
|
});
|
|
1337
|
-
const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
|
|
1338
|
-
const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
|
|
1339
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
1340
|
-
return new Page(query, meta, records);
|
|
1341
2454
|
}
|
|
1342
2455
|
}
|
|
1343
2456
|
_table = new WeakMap();
|
|
1344
2457
|
_getFetchProps = new WeakMap();
|
|
2458
|
+
_db = new WeakMap();
|
|
1345
2459
|
_cache = new WeakMap();
|
|
1346
|
-
|
|
2460
|
+
_schemaTables$2 = new WeakMap();
|
|
2461
|
+
_trace = new WeakMap();
|
|
1347
2462
|
_insertRecordWithoutId = new WeakSet();
|
|
1348
|
-
insertRecordWithoutId_fn = async function(object) {
|
|
2463
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1349
2464
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1350
2465
|
const record = transformObjectLinks(object);
|
|
1351
2466
|
const response = await insertRecord({
|
|
1352
2467
|
pathParams: {
|
|
1353
2468
|
workspace: "{workspaceId}",
|
|
1354
2469
|
dbBranchName: "{dbBranch}",
|
|
2470
|
+
region: "{region}",
|
|
1355
2471
|
tableName: __privateGet$4(this, _table)
|
|
1356
2472
|
},
|
|
2473
|
+
queryParams: { columns },
|
|
1357
2474
|
body: record,
|
|
1358
2475
|
...fetchProps
|
|
1359
2476
|
});
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
throw new Error("The server failed to save the record");
|
|
1363
|
-
}
|
|
1364
|
-
return finalObject;
|
|
2477
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2478
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
1365
2479
|
};
|
|
1366
2480
|
_insertRecordWithId = new WeakSet();
|
|
1367
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
|
2481
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
|
1368
2482
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1369
2483
|
const record = transformObjectLinks(object);
|
|
1370
2484
|
const response = await insertRecordWithID({
|
|
1371
2485
|
pathParams: {
|
|
1372
2486
|
workspace: "{workspaceId}",
|
|
1373
2487
|
dbBranchName: "{dbBranch}",
|
|
2488
|
+
region: "{region}",
|
|
1374
2489
|
tableName: __privateGet$4(this, _table),
|
|
1375
2490
|
recordId
|
|
1376
2491
|
},
|
|
1377
2492
|
body: record,
|
|
1378
|
-
queryParams: { createOnly
|
|
2493
|
+
queryParams: { createOnly, columns, ifVersion },
|
|
1379
2494
|
...fetchProps
|
|
1380
2495
|
});
|
|
1381
|
-
const
|
|
1382
|
-
|
|
1383
|
-
throw new Error("The server failed to save the record");
|
|
1384
|
-
}
|
|
1385
|
-
return finalObject;
|
|
2496
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2497
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
1386
2498
|
};
|
|
1387
2499
|
_bulkInsertTableRecords = new WeakSet();
|
|
1388
|
-
bulkInsertTableRecords_fn = async function(objects) {
|
|
2500
|
+
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1389
2501
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1390
2502
|
const records = objects.map((object) => transformObjectLinks(object));
|
|
1391
2503
|
const response = await bulkInsertTableRecords({
|
|
1392
|
-
pathParams: {
|
|
2504
|
+
pathParams: {
|
|
2505
|
+
workspace: "{workspaceId}",
|
|
2506
|
+
dbBranchName: "{dbBranch}",
|
|
2507
|
+
region: "{region}",
|
|
2508
|
+
tableName: __privateGet$4(this, _table)
|
|
2509
|
+
},
|
|
2510
|
+
queryParams: { columns },
|
|
1393
2511
|
body: { records },
|
|
1394
2512
|
...fetchProps
|
|
1395
2513
|
});
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
throw new Error("The server failed to save some records");
|
|
2514
|
+
if (!isResponseWithRecords(response)) {
|
|
2515
|
+
throw new Error("Request included columns but server didn't include them");
|
|
1399
2516
|
}
|
|
1400
|
-
|
|
2517
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2518
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
|
1401
2519
|
};
|
|
1402
2520
|
_updateRecordWithID = new WeakSet();
|
|
1403
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
|
2521
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
|
1404
2522
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1405
2523
|
const record = transformObjectLinks(object);
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
2524
|
+
try {
|
|
2525
|
+
const response = await updateRecordWithID({
|
|
2526
|
+
pathParams: {
|
|
2527
|
+
workspace: "{workspaceId}",
|
|
2528
|
+
dbBranchName: "{dbBranch}",
|
|
2529
|
+
region: "{region}",
|
|
2530
|
+
tableName: __privateGet$4(this, _table),
|
|
2531
|
+
recordId
|
|
2532
|
+
},
|
|
2533
|
+
queryParams: { columns, ifVersion },
|
|
2534
|
+
body: record,
|
|
2535
|
+
...fetchProps
|
|
2536
|
+
});
|
|
2537
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2538
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2539
|
+
} catch (e) {
|
|
2540
|
+
if (isObject(e) && e.status === 404) {
|
|
2541
|
+
return null;
|
|
2542
|
+
}
|
|
2543
|
+
throw e;
|
|
2544
|
+
}
|
|
1415
2545
|
};
|
|
1416
2546
|
_upsertRecordWithID = new WeakSet();
|
|
1417
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
|
2547
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
|
1418
2548
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1419
2549
|
const response = await upsertRecordWithID({
|
|
1420
|
-
pathParams: {
|
|
2550
|
+
pathParams: {
|
|
2551
|
+
workspace: "{workspaceId}",
|
|
2552
|
+
dbBranchName: "{dbBranch}",
|
|
2553
|
+
region: "{region}",
|
|
2554
|
+
tableName: __privateGet$4(this, _table),
|
|
2555
|
+
recordId
|
|
2556
|
+
},
|
|
2557
|
+
queryParams: { columns, ifVersion },
|
|
1421
2558
|
body: object,
|
|
1422
2559
|
...fetchProps
|
|
1423
2560
|
});
|
|
1424
|
-
const
|
|
1425
|
-
|
|
1426
|
-
throw new Error("The server failed to save the record");
|
|
1427
|
-
return item;
|
|
2561
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2562
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
1428
2563
|
};
|
|
1429
2564
|
_deleteRecord = new WeakSet();
|
|
1430
|
-
deleteRecord_fn = async function(recordId) {
|
|
2565
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
1431
2566
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
2567
|
+
try {
|
|
2568
|
+
const response = await deleteRecord({
|
|
2569
|
+
pathParams: {
|
|
2570
|
+
workspace: "{workspaceId}",
|
|
2571
|
+
dbBranchName: "{dbBranch}",
|
|
2572
|
+
region: "{region}",
|
|
2573
|
+
tableName: __privateGet$4(this, _table),
|
|
2574
|
+
recordId
|
|
2575
|
+
},
|
|
2576
|
+
queryParams: { columns },
|
|
2577
|
+
...fetchProps
|
|
2578
|
+
});
|
|
2579
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2580
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2581
|
+
} catch (e) {
|
|
2582
|
+
if (isObject(e) && e.status === 404) {
|
|
2583
|
+
return null;
|
|
2584
|
+
}
|
|
2585
|
+
throw e;
|
|
1446
2586
|
}
|
|
1447
2587
|
};
|
|
1448
|
-
_setCacheRecord = new WeakSet();
|
|
1449
|
-
setCacheRecord_fn = async function(record) {
|
|
1450
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
|
1451
|
-
return;
|
|
1452
|
-
await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
|
|
1453
|
-
};
|
|
1454
|
-
_getCacheRecord = new WeakSet();
|
|
1455
|
-
getCacheRecord_fn = async function(recordId) {
|
|
1456
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
|
1457
|
-
return null;
|
|
1458
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
|
1459
|
-
};
|
|
1460
2588
|
_setCacheQuery = new WeakSet();
|
|
1461
2589
|
setCacheQuery_fn = async function(query, meta, records) {
|
|
1462
2590
|
await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
|
@@ -1473,17 +2601,17 @@ getCacheQuery_fn = async function(query) {
|
|
|
1473
2601
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
|
1474
2602
|
return hasExpired ? null : result;
|
|
1475
2603
|
};
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
if (__privateGet$4(this,
|
|
1479
|
-
return __privateGet$4(this,
|
|
2604
|
+
_getSchemaTables$1 = new WeakSet();
|
|
2605
|
+
getSchemaTables_fn$1 = async function() {
|
|
2606
|
+
if (__privateGet$4(this, _schemaTables$2))
|
|
2607
|
+
return __privateGet$4(this, _schemaTables$2);
|
|
1480
2608
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1481
2609
|
const { schema } = await getBranchDetails({
|
|
1482
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
|
2610
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
1483
2611
|
...fetchProps
|
|
1484
2612
|
});
|
|
1485
|
-
__privateSet$
|
|
1486
|
-
return schema;
|
|
2613
|
+
__privateSet$4(this, _schemaTables$2, schema.tables);
|
|
2614
|
+
return schema.tables;
|
|
1487
2615
|
};
|
|
1488
2616
|
const transformObjectLinks = (object) => {
|
|
1489
2617
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
|
@@ -1492,20 +2620,23 @@ const transformObjectLinks = (object) => {
|
|
|
1492
2620
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
|
1493
2621
|
}, {});
|
|
1494
2622
|
};
|
|
1495
|
-
const initObject = (db,
|
|
2623
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
1496
2624
|
const result = {};
|
|
1497
|
-
|
|
1498
|
-
|
|
2625
|
+
const { xata, ...rest } = object ?? {};
|
|
2626
|
+
Object.assign(result, rest);
|
|
2627
|
+
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
|
1499
2628
|
if (!columns)
|
|
1500
2629
|
console.error(`Table ${table} not found in schema`);
|
|
1501
2630
|
for (const column of columns ?? []) {
|
|
2631
|
+
if (!isValidColumn(selectedColumns, column))
|
|
2632
|
+
continue;
|
|
1502
2633
|
const value = result[column.name];
|
|
1503
2634
|
switch (column.type) {
|
|
1504
2635
|
case "datetime": {
|
|
1505
|
-
const date = new Date(value);
|
|
1506
|
-
if (isNaN(date.getTime())) {
|
|
2636
|
+
const date = value !== void 0 ? new Date(value) : void 0;
|
|
2637
|
+
if (date && isNaN(date.getTime())) {
|
|
1507
2638
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
|
1508
|
-
} else {
|
|
2639
|
+
} else if (date) {
|
|
1509
2640
|
result[column.name] = date;
|
|
1510
2641
|
}
|
|
1511
2642
|
break;
|
|
@@ -1515,35 +2646,81 @@ const initObject = (db, schema, table, object) => {
|
|
|
1515
2646
|
if (!linkTable) {
|
|
1516
2647
|
console.error(`Failed to parse link for field ${column.name}`);
|
|
1517
2648
|
} else if (isObject(value)) {
|
|
1518
|
-
|
|
2649
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
|
2650
|
+
if (item === column.name) {
|
|
2651
|
+
return [...acc, "*"];
|
|
2652
|
+
}
|
|
2653
|
+
if (item.startsWith(`${column.name}.`)) {
|
|
2654
|
+
const [, ...path] = item.split(".");
|
|
2655
|
+
return [...acc, path.join(".")];
|
|
2656
|
+
}
|
|
2657
|
+
return acc;
|
|
2658
|
+
}, []);
|
|
2659
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
|
2660
|
+
} else {
|
|
2661
|
+
result[column.name] = null;
|
|
1519
2662
|
}
|
|
1520
2663
|
break;
|
|
1521
2664
|
}
|
|
2665
|
+
default:
|
|
2666
|
+
result[column.name] = value ?? null;
|
|
2667
|
+
if (column.notNull === true && value === null) {
|
|
2668
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
|
2669
|
+
}
|
|
2670
|
+
break;
|
|
1522
2671
|
}
|
|
1523
2672
|
}
|
|
1524
|
-
result.read = function() {
|
|
1525
|
-
return db[table].read(result["id"]);
|
|
2673
|
+
result.read = function(columns2) {
|
|
2674
|
+
return db[table].read(result["id"], columns2);
|
|
2675
|
+
};
|
|
2676
|
+
result.update = function(data, b, c) {
|
|
2677
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
|
2678
|
+
const ifVersion = parseIfVersion(b, c);
|
|
2679
|
+
return db[table].update(result["id"], data, columns2, { ifVersion });
|
|
1526
2680
|
};
|
|
1527
|
-
result.
|
|
1528
|
-
|
|
2681
|
+
result.replace = function(data, b, c) {
|
|
2682
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
|
2683
|
+
const ifVersion = parseIfVersion(b, c);
|
|
2684
|
+
return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
|
|
1529
2685
|
};
|
|
1530
2686
|
result.delete = function() {
|
|
1531
2687
|
return db[table].delete(result["id"]);
|
|
1532
2688
|
};
|
|
1533
|
-
|
|
2689
|
+
result.getMetadata = function() {
|
|
2690
|
+
return xata;
|
|
2691
|
+
};
|
|
2692
|
+
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
|
1534
2693
|
Object.defineProperty(result, prop, { enumerable: false });
|
|
1535
2694
|
}
|
|
1536
2695
|
Object.freeze(result);
|
|
1537
2696
|
return result;
|
|
1538
2697
|
};
|
|
1539
|
-
function
|
|
1540
|
-
|
|
1541
|
-
|
|
2698
|
+
function isResponseWithRecords(value) {
|
|
2699
|
+
return isObject(value) && Array.isArray(value.records);
|
|
2700
|
+
}
|
|
2701
|
+
function extractId(value) {
|
|
2702
|
+
if (isString(value))
|
|
2703
|
+
return value;
|
|
2704
|
+
if (isObject(value) && isString(value.id))
|
|
2705
|
+
return value.id;
|
|
2706
|
+
return void 0;
|
|
2707
|
+
}
|
|
2708
|
+
function isValidColumn(columns, column) {
|
|
2709
|
+
if (columns.includes("*"))
|
|
2710
|
+
return true;
|
|
2711
|
+
if (column.type === "link") {
|
|
2712
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
|
2713
|
+
return linkColumns.length > 0;
|
|
2714
|
+
}
|
|
2715
|
+
return columns.includes(column.name);
|
|
2716
|
+
}
|
|
2717
|
+
function parseIfVersion(...args) {
|
|
2718
|
+
for (const arg of args) {
|
|
2719
|
+
if (isObject(arg) && isNumber(arg.ifVersion)) {
|
|
2720
|
+
return arg.ifVersion;
|
|
2721
|
+
}
|
|
1542
2722
|
}
|
|
1543
|
-
|
|
1544
|
-
return [];
|
|
1545
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
|
1546
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
|
2723
|
+
return void 0;
|
|
1547
2724
|
}
|
|
1548
2725
|
|
|
1549
2726
|
var __accessCheck$3 = (obj, member, msg) => {
|
|
@@ -1559,7 +2736,7 @@ var __privateAdd$3 = (obj, member, value) => {
|
|
|
1559
2736
|
throw TypeError("Cannot add the same private member more than once");
|
|
1560
2737
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1561
2738
|
};
|
|
1562
|
-
var __privateSet$
|
|
2739
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
|
1563
2740
|
__accessCheck$3(obj, member, "write to private field");
|
|
1564
2741
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1565
2742
|
return value;
|
|
@@ -1568,9 +2745,8 @@ var _map;
|
|
|
1568
2745
|
class SimpleCache {
|
|
1569
2746
|
constructor(options = {}) {
|
|
1570
2747
|
__privateAdd$3(this, _map, void 0);
|
|
1571
|
-
__privateSet$
|
|
2748
|
+
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
|
1572
2749
|
this.capacity = options.max ?? 500;
|
|
1573
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
|
1574
2750
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
|
1575
2751
|
}
|
|
1576
2752
|
async getAll() {
|
|
@@ -1596,18 +2772,25 @@ class SimpleCache {
|
|
|
1596
2772
|
}
|
|
1597
2773
|
_map = new WeakMap();
|
|
1598
2774
|
|
|
1599
|
-
const
|
|
1600
|
-
const
|
|
1601
|
-
const
|
|
1602
|
-
const
|
|
1603
|
-
const
|
|
1604
|
-
const
|
|
2775
|
+
const greaterThan = (value) => ({ $gt: value });
|
|
2776
|
+
const gt = greaterThan;
|
|
2777
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
|
2778
|
+
const greaterEquals = greaterThanEquals;
|
|
2779
|
+
const gte = greaterThanEquals;
|
|
2780
|
+
const ge = greaterThanEquals;
|
|
2781
|
+
const lessThan = (value) => ({ $lt: value });
|
|
2782
|
+
const lt = lessThan;
|
|
2783
|
+
const lessThanEquals = (value) => ({ $le: value });
|
|
2784
|
+
const lessEquals = lessThanEquals;
|
|
2785
|
+
const lte = lessThanEquals;
|
|
2786
|
+
const le = lessThanEquals;
|
|
1605
2787
|
const exists = (column) => ({ $exists: column });
|
|
1606
2788
|
const notExists = (column) => ({ $notExists: column });
|
|
1607
2789
|
const startsWith = (value) => ({ $startsWith: value });
|
|
1608
2790
|
const endsWith = (value) => ({ $endsWith: value });
|
|
1609
2791
|
const pattern = (value) => ({ $pattern: value });
|
|
1610
2792
|
const is = (value) => ({ $is: value });
|
|
2793
|
+
const equals = is;
|
|
1611
2794
|
const isNot = (value) => ({ $isNot: value });
|
|
1612
2795
|
const contains = (value) => ({ $contains: value });
|
|
1613
2796
|
const includes = (value) => ({ $includes: value });
|
|
@@ -1628,31 +2811,42 @@ var __privateAdd$2 = (obj, member, value) => {
|
|
|
1628
2811
|
throw TypeError("Cannot add the same private member more than once");
|
|
1629
2812
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1630
2813
|
};
|
|
1631
|
-
var
|
|
2814
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
|
2815
|
+
__accessCheck$2(obj, member, "write to private field");
|
|
2816
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
2817
|
+
return value;
|
|
2818
|
+
};
|
|
2819
|
+
var _tables, _schemaTables$1;
|
|
1632
2820
|
class SchemaPlugin extends XataPlugin {
|
|
1633
|
-
constructor(
|
|
2821
|
+
constructor(schemaTables) {
|
|
1634
2822
|
super();
|
|
1635
|
-
this.tableNames = tableNames;
|
|
1636
2823
|
__privateAdd$2(this, _tables, {});
|
|
2824
|
+
__privateAdd$2(this, _schemaTables$1, void 0);
|
|
2825
|
+
__privateSet$2(this, _schemaTables$1, schemaTables);
|
|
1637
2826
|
}
|
|
1638
2827
|
build(pluginOptions) {
|
|
1639
|
-
const db = new Proxy(
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
2828
|
+
const db = new Proxy(
|
|
2829
|
+
{},
|
|
2830
|
+
{
|
|
2831
|
+
get: (_target, table) => {
|
|
2832
|
+
if (!isString(table))
|
|
2833
|
+
throw new Error("Invalid table name");
|
|
2834
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
|
2835
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
|
2836
|
+
}
|
|
2837
|
+
return __privateGet$2(this, _tables)[table];
|
|
1645
2838
|
}
|
|
1646
|
-
return __privateGet$2(this, _tables)[table];
|
|
1647
2839
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
2840
|
+
);
|
|
2841
|
+
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
|
2842
|
+
for (const table of tableNames) {
|
|
2843
|
+
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
|
1651
2844
|
}
|
|
1652
2845
|
return db;
|
|
1653
2846
|
}
|
|
1654
2847
|
}
|
|
1655
2848
|
_tables = new WeakMap();
|
|
2849
|
+
_schemaTables$1 = new WeakMap();
|
|
1656
2850
|
|
|
1657
2851
|
var __accessCheck$1 = (obj, member, msg) => {
|
|
1658
2852
|
if (!member.has(obj))
|
|
@@ -1676,82 +2870,77 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
|
1676
2870
|
__accessCheck$1(obj, member, "access private method");
|
|
1677
2871
|
return method;
|
|
1678
2872
|
};
|
|
1679
|
-
var
|
|
2873
|
+
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
|
1680
2874
|
class SearchPlugin extends XataPlugin {
|
|
1681
|
-
constructor(db) {
|
|
2875
|
+
constructor(db, schemaTables) {
|
|
1682
2876
|
super();
|
|
1683
2877
|
this.db = db;
|
|
1684
2878
|
__privateAdd$1(this, _search);
|
|
1685
|
-
__privateAdd$1(this,
|
|
1686
|
-
__privateAdd$1(this,
|
|
2879
|
+
__privateAdd$1(this, _getSchemaTables);
|
|
2880
|
+
__privateAdd$1(this, _schemaTables, void 0);
|
|
2881
|
+
__privateSet$1(this, _schemaTables, schemaTables);
|
|
1687
2882
|
}
|
|
1688
2883
|
build({ getFetchProps }) {
|
|
1689
2884
|
return {
|
|
1690
2885
|
all: async (query, options = {}) => {
|
|
1691
2886
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
|
1692
|
-
const
|
|
2887
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
|
1693
2888
|
return records.map((record) => {
|
|
1694
2889
|
const { table = "orphan" } = record.xata;
|
|
1695
|
-
return { table, record: initObject(this.db,
|
|
2890
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
|
1696
2891
|
});
|
|
1697
2892
|
},
|
|
1698
2893
|
byTable: async (query, options = {}) => {
|
|
1699
2894
|
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
|
|
1700
|
-
const
|
|
2895
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
|
1701
2896
|
return records.reduce((acc, record) => {
|
|
1702
2897
|
const { table = "orphan" } = record.xata;
|
|
1703
2898
|
const items = acc[table] ?? [];
|
|
1704
|
-
const item = initObject(this.db,
|
|
2899
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
|
1705
2900
|
return { ...acc, [table]: [...items, item] };
|
|
1706
2901
|
}, {});
|
|
1707
2902
|
}
|
|
1708
2903
|
};
|
|
1709
2904
|
}
|
|
1710
2905
|
}
|
|
1711
|
-
|
|
2906
|
+
_schemaTables = new WeakMap();
|
|
1712
2907
|
_search = new WeakSet();
|
|
1713
2908
|
search_fn = async function(query, options, getFetchProps) {
|
|
1714
2909
|
const fetchProps = await getFetchProps();
|
|
1715
|
-
const { tables, fuzziness } = options ?? {};
|
|
2910
|
+
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
|
1716
2911
|
const { records } = await searchBranch({
|
|
1717
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
|
1718
|
-
body: { tables, query, fuzziness },
|
|
2912
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
2913
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
|
1719
2914
|
...fetchProps
|
|
1720
2915
|
});
|
|
1721
2916
|
return records;
|
|
1722
2917
|
};
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
if (__privateGet$1(this,
|
|
1726
|
-
return __privateGet$1(this,
|
|
2918
|
+
_getSchemaTables = new WeakSet();
|
|
2919
|
+
getSchemaTables_fn = async function(getFetchProps) {
|
|
2920
|
+
if (__privateGet$1(this, _schemaTables))
|
|
2921
|
+
return __privateGet$1(this, _schemaTables);
|
|
1727
2922
|
const fetchProps = await getFetchProps();
|
|
1728
2923
|
const { schema } = await getBranchDetails({
|
|
1729
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
|
2924
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
1730
2925
|
...fetchProps
|
|
1731
2926
|
});
|
|
1732
|
-
__privateSet$1(this,
|
|
1733
|
-
return schema;
|
|
2927
|
+
__privateSet$1(this, _schemaTables, schema.tables);
|
|
2928
|
+
return schema.tables;
|
|
1734
2929
|
};
|
|
1735
2930
|
|
|
1736
2931
|
const isBranchStrategyBuilder = (strategy) => {
|
|
1737
2932
|
return typeof strategy === "function";
|
|
1738
2933
|
};
|
|
1739
2934
|
|
|
1740
|
-
const envBranchNames = [
|
|
1741
|
-
"XATA_BRANCH",
|
|
1742
|
-
"VERCEL_GIT_COMMIT_REF",
|
|
1743
|
-
"CF_PAGES_BRANCH",
|
|
1744
|
-
"BRANCH"
|
|
1745
|
-
];
|
|
1746
2935
|
async function getCurrentBranchName(options) {
|
|
1747
|
-
const
|
|
1748
|
-
if (
|
|
1749
|
-
const details = await getDatabaseBranch(
|
|
2936
|
+
const { branch, envBranch } = getEnvironment();
|
|
2937
|
+
if (branch) {
|
|
2938
|
+
const details = await getDatabaseBranch(branch, options);
|
|
1750
2939
|
if (details)
|
|
1751
|
-
return
|
|
1752
|
-
console.warn(`Branch ${
|
|
2940
|
+
return branch;
|
|
2941
|
+
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
|
1753
2942
|
}
|
|
1754
|
-
const gitBranch = await getGitBranch();
|
|
2943
|
+
const gitBranch = envBranch || await getGitBranch();
|
|
1755
2944
|
return resolveXataBranch(gitBranch, options);
|
|
1756
2945
|
}
|
|
1757
2946
|
async function getCurrentBranchDetails(options) {
|
|
@@ -1762,18 +2951,27 @@ async function resolveXataBranch(gitBranch, options) {
|
|
|
1762
2951
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1763
2952
|
const apiKey = options?.apiKey || getAPIKey();
|
|
1764
2953
|
if (!databaseURL)
|
|
1765
|
-
throw new Error(
|
|
2954
|
+
throw new Error(
|
|
2955
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
2956
|
+
);
|
|
1766
2957
|
if (!apiKey)
|
|
1767
|
-
throw new Error(
|
|
2958
|
+
throw new Error(
|
|
2959
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
2960
|
+
);
|
|
1768
2961
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
|
1769
|
-
const
|
|
2962
|
+
const urlParts = parseWorkspacesUrlParts(host);
|
|
2963
|
+
if (!urlParts)
|
|
2964
|
+
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
|
2965
|
+
const { workspace, region } = urlParts;
|
|
2966
|
+
const { fallbackBranch } = getEnvironment();
|
|
1770
2967
|
const { branch } = await resolveBranch({
|
|
1771
2968
|
apiKey,
|
|
1772
2969
|
apiUrl: databaseURL,
|
|
1773
2970
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1774
2971
|
workspacesApiUrl: `${protocol}//${host}`,
|
|
1775
|
-
pathParams: { dbName, workspace },
|
|
1776
|
-
queryParams: { gitBranch, fallbackBranch
|
|
2972
|
+
pathParams: { dbName, workspace, region },
|
|
2973
|
+
queryParams: { gitBranch, fallbackBranch },
|
|
2974
|
+
trace: defaultTrace
|
|
1777
2975
|
});
|
|
1778
2976
|
return branch;
|
|
1779
2977
|
}
|
|
@@ -1781,22 +2979,26 @@ async function getDatabaseBranch(branch, options) {
|
|
|
1781
2979
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1782
2980
|
const apiKey = options?.apiKey || getAPIKey();
|
|
1783
2981
|
if (!databaseURL)
|
|
1784
|
-
throw new Error(
|
|
2982
|
+
throw new Error(
|
|
2983
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
2984
|
+
);
|
|
1785
2985
|
if (!apiKey)
|
|
1786
|
-
throw new Error(
|
|
2986
|
+
throw new Error(
|
|
2987
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
2988
|
+
);
|
|
1787
2989
|
const [protocol, , host, , database] = databaseURL.split("/");
|
|
1788
|
-
const
|
|
1789
|
-
|
|
2990
|
+
const urlParts = parseWorkspacesUrlParts(host);
|
|
2991
|
+
if (!urlParts)
|
|
2992
|
+
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
|
2993
|
+
const { workspace, region } = urlParts;
|
|
1790
2994
|
try {
|
|
1791
2995
|
return await getBranchDetails({
|
|
1792
2996
|
apiKey,
|
|
1793
2997
|
apiUrl: databaseURL,
|
|
1794
2998
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1795
2999
|
workspacesApiUrl: `${protocol}//${host}`,
|
|
1796
|
-
pathParams: {
|
|
1797
|
-
|
|
1798
|
-
workspace
|
|
1799
|
-
}
|
|
3000
|
+
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
|
3001
|
+
trace: defaultTrace
|
|
1800
3002
|
});
|
|
1801
3003
|
} catch (err) {
|
|
1802
3004
|
if (isObject(err) && err.status === 404)
|
|
@@ -1804,21 +3006,10 @@ async function getDatabaseBranch(branch, options) {
|
|
|
1804
3006
|
throw err;
|
|
1805
3007
|
}
|
|
1806
3008
|
}
|
|
1807
|
-
function getBranchByEnvVariable() {
|
|
1808
|
-
for (const name of envBranchNames) {
|
|
1809
|
-
const value = getEnvVariable(name);
|
|
1810
|
-
if (value) {
|
|
1811
|
-
return value;
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
try {
|
|
1815
|
-
return XATA_BRANCH;
|
|
1816
|
-
} catch (err) {
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
3009
|
function getDatabaseURL() {
|
|
1820
3010
|
try {
|
|
1821
|
-
|
|
3011
|
+
const { databaseURL } = getEnvironment();
|
|
3012
|
+
return databaseURL;
|
|
1822
3013
|
} catch (err) {
|
|
1823
3014
|
return void 0;
|
|
1824
3015
|
}
|
|
@@ -1847,20 +3038,23 @@ var __privateMethod = (obj, member, method) => {
|
|
|
1847
3038
|
return method;
|
|
1848
3039
|
};
|
|
1849
3040
|
const buildClient = (plugins) => {
|
|
1850
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
|
3041
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
|
1851
3042
|
return _a = class {
|
|
1852
|
-
constructor(options = {},
|
|
3043
|
+
constructor(options = {}, schemaTables) {
|
|
1853
3044
|
__privateAdd(this, _parseOptions);
|
|
1854
3045
|
__privateAdd(this, _getFetchProps);
|
|
1855
3046
|
__privateAdd(this, _evaluateBranch);
|
|
1856
3047
|
__privateAdd(this, _branch, void 0);
|
|
3048
|
+
__privateAdd(this, _options, void 0);
|
|
1857
3049
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
|
3050
|
+
__privateSet(this, _options, safeOptions);
|
|
1858
3051
|
const pluginOptions = {
|
|
1859
3052
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
|
1860
|
-
cache: safeOptions.cache
|
|
3053
|
+
cache: safeOptions.cache,
|
|
3054
|
+
trace: safeOptions.trace
|
|
1861
3055
|
};
|
|
1862
|
-
const db = new SchemaPlugin(
|
|
1863
|
-
const search = new SearchPlugin(db).build(pluginOptions);
|
|
3056
|
+
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
|
3057
|
+
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
|
1864
3058
|
this.db = db;
|
|
1865
3059
|
this.search = search;
|
|
1866
3060
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
|
@@ -1876,22 +3070,26 @@ const buildClient = (plugins) => {
|
|
|
1876
3070
|
}
|
|
1877
3071
|
}
|
|
1878
3072
|
}
|
|
1879
|
-
|
|
3073
|
+
async getConfig() {
|
|
3074
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
|
3075
|
+
const branch = await __privateGet(this, _options).branch();
|
|
3076
|
+
return { databaseURL, branch };
|
|
3077
|
+
}
|
|
3078
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
|
1880
3079
|
const fetch = getFetchImplementation(options?.fetch);
|
|
1881
3080
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1882
3081
|
const apiKey = options?.apiKey || getAPIKey();
|
|
1883
|
-
const cache = options?.cache ?? new SimpleCache({
|
|
3082
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
|
3083
|
+
const trace = options?.trace ?? defaultTrace;
|
|
1884
3084
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
|
1885
|
-
if (!
|
|
1886
|
-
throw new Error("
|
|
3085
|
+
if (!apiKey) {
|
|
3086
|
+
throw new Error("Option apiKey is required");
|
|
1887
3087
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
apiKey,
|
|
1892
|
-
|
|
1893
|
-
branch
|
|
1894
|
-
}) {
|
|
3088
|
+
if (!databaseURL) {
|
|
3089
|
+
throw new Error("Option databaseURL is required");
|
|
3090
|
+
}
|
|
3091
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID() };
|
|
3092
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
|
|
1895
3093
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
|
1896
3094
|
if (!branchValue)
|
|
1897
3095
|
throw new Error("Unable to resolve branch value");
|
|
@@ -1901,9 +3099,11 @@ const buildClient = (plugins) => {
|
|
|
1901
3099
|
apiUrl: "",
|
|
1902
3100
|
workspacesApiUrl: (path, params) => {
|
|
1903
3101
|
const hasBranch = params.dbBranchName ?? params.branch;
|
|
1904
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
|
3102
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
|
1905
3103
|
return databaseURL + newPath;
|
|
1906
|
-
}
|
|
3104
|
+
},
|
|
3105
|
+
trace,
|
|
3106
|
+
clientID
|
|
1907
3107
|
};
|
|
1908
3108
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
|
1909
3109
|
if (__privateGet(this, _branch))
|
|
@@ -1926,6 +3126,88 @@ const buildClient = (plugins) => {
|
|
|
1926
3126
|
class BaseClient extends buildClient() {
|
|
1927
3127
|
}
|
|
1928
3128
|
|
|
3129
|
+
const META = "__";
|
|
3130
|
+
const VALUE = "___";
|
|
3131
|
+
class Serializer {
|
|
3132
|
+
constructor() {
|
|
3133
|
+
this.classes = {};
|
|
3134
|
+
}
|
|
3135
|
+
add(clazz) {
|
|
3136
|
+
this.classes[clazz.name] = clazz;
|
|
3137
|
+
}
|
|
3138
|
+
toJSON(data) {
|
|
3139
|
+
function visit(obj) {
|
|
3140
|
+
if (Array.isArray(obj))
|
|
3141
|
+
return obj.map(visit);
|
|
3142
|
+
const type = typeof obj;
|
|
3143
|
+
if (type === "undefined")
|
|
3144
|
+
return { [META]: "undefined" };
|
|
3145
|
+
if (type === "bigint")
|
|
3146
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
|
3147
|
+
if (obj === null || type !== "object")
|
|
3148
|
+
return obj;
|
|
3149
|
+
const constructor = obj.constructor;
|
|
3150
|
+
const o = { [META]: constructor.name };
|
|
3151
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
3152
|
+
o[key] = visit(value);
|
|
3153
|
+
}
|
|
3154
|
+
if (constructor === Date)
|
|
3155
|
+
o[VALUE] = obj.toISOString();
|
|
3156
|
+
if (constructor === Map)
|
|
3157
|
+
o[VALUE] = Object.fromEntries(obj);
|
|
3158
|
+
if (constructor === Set)
|
|
3159
|
+
o[VALUE] = [...obj];
|
|
3160
|
+
return o;
|
|
3161
|
+
}
|
|
3162
|
+
return JSON.stringify(visit(data));
|
|
3163
|
+
}
|
|
3164
|
+
fromJSON(json) {
|
|
3165
|
+
return JSON.parse(json, (key, value) => {
|
|
3166
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
3167
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
|
3168
|
+
const constructor = this.classes[clazz];
|
|
3169
|
+
if (constructor) {
|
|
3170
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
|
3171
|
+
}
|
|
3172
|
+
if (clazz === "Date")
|
|
3173
|
+
return new Date(val);
|
|
3174
|
+
if (clazz === "Set")
|
|
3175
|
+
return new Set(val);
|
|
3176
|
+
if (clazz === "Map")
|
|
3177
|
+
return new Map(Object.entries(val));
|
|
3178
|
+
if (clazz === "bigint")
|
|
3179
|
+
return BigInt(val);
|
|
3180
|
+
if (clazz === "undefined")
|
|
3181
|
+
return void 0;
|
|
3182
|
+
return rest;
|
|
3183
|
+
}
|
|
3184
|
+
return value;
|
|
3185
|
+
});
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3188
|
+
const defaultSerializer = new Serializer();
|
|
3189
|
+
const serialize = (data) => {
|
|
3190
|
+
return defaultSerializer.toJSON(data);
|
|
3191
|
+
};
|
|
3192
|
+
const deserialize = (json) => {
|
|
3193
|
+
return defaultSerializer.fromJSON(json);
|
|
3194
|
+
};
|
|
3195
|
+
|
|
3196
|
+
function buildWorkerRunner(config) {
|
|
3197
|
+
return function xataWorker(name, _worker) {
|
|
3198
|
+
return async (...args) => {
|
|
3199
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
|
3200
|
+
const result = await fetch(url, {
|
|
3201
|
+
method: "POST",
|
|
3202
|
+
headers: { "Content-Type": "application/json" },
|
|
3203
|
+
body: serialize({ args })
|
|
3204
|
+
});
|
|
3205
|
+
const text = await result.text();
|
|
3206
|
+
return deserialize(text);
|
|
3207
|
+
};
|
|
3208
|
+
};
|
|
3209
|
+
}
|
|
3210
|
+
|
|
1929
3211
|
class XataError extends Error {
|
|
1930
3212
|
constructor(message, status) {
|
|
1931
3213
|
super(message);
|
|
@@ -1933,5 +3215,5 @@ class XataError extends Error {
|
|
|
1933
3215
|
}
|
|
1934
3216
|
}
|
|
1935
3217
|
|
|
1936
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, 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 };
|
|
3218
|
+
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, aggregateTable, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, dEPRECATEDcreateDatabase, dEPRECATEDdeleteDatabase, dEPRECATEDgetDatabaseList, dEPRECATEDgetDatabaseMetadata, dEPRECATEDupdateDatabaseMetadata, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
|
1937
3219
|
//# sourceMappingURL=index.mjs.map
|