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