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