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