@xata.io/client 0.0.0-alpha.vfc692f9 → 0.0.0-alpha.vfca6c5f
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 +182 -0
- package/README.md +32 -30
- package/Usage.md +34 -11
- package/dist/index.cjs +2191 -719
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4872 -1212
- package/dist/index.mjs +2151 -700
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- /package/{rollup.config.js → rollup.config.mjs} +0 -0
package/dist/index.cjs
CHANGED
@@ -1,24 +1,27 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
3
|
+
const defaultTrace = async (name, fn, _options) => {
|
4
|
+
return await fn({
|
5
|
+
name,
|
6
|
+
setAttributes: () => {
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
});
|
10
|
+
};
|
11
|
+
const TraceAttributes = {
|
12
|
+
KIND: "xata.trace.kind",
|
13
|
+
VERSION: "xata.sdk.version",
|
14
|
+
TABLE: "xata.table",
|
15
|
+
HTTP_REQUEST_ID: "http.request_id",
|
16
|
+
HTTP_STATUS_CODE: "http.status_code",
|
17
|
+
HTTP_HOST: "http.host",
|
18
|
+
HTTP_SCHEME: "http.scheme",
|
19
|
+
HTTP_USER_AGENT: "http.user_agent",
|
20
|
+
HTTP_METHOD: "http.method",
|
21
|
+
HTTP_URL: "http.url",
|
22
|
+
HTTP_ROUTE: "http.route",
|
23
|
+
HTTP_TARGET: "http.target"
|
24
|
+
};
|
22
25
|
|
23
26
|
function notEmpty(value) {
|
24
27
|
return value !== null && value !== void 0;
|
@@ -38,6 +41,21 @@ function isString(value) {
|
|
38
41
|
function isStringArray(value) {
|
39
42
|
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
40
43
|
}
|
44
|
+
function isNumber(value) {
|
45
|
+
return isDefined(value) && typeof value === "number";
|
46
|
+
}
|
47
|
+
function parseNumber(value) {
|
48
|
+
if (isNumber(value)) {
|
49
|
+
return value;
|
50
|
+
}
|
51
|
+
if (isString(value)) {
|
52
|
+
const parsed = Number(value);
|
53
|
+
if (!Number.isNaN(parsed)) {
|
54
|
+
return parsed;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
return void 0;
|
58
|
+
}
|
41
59
|
function toBase64(value) {
|
42
60
|
try {
|
43
61
|
return btoa(value);
|
@@ -46,10 +64,31 @@ function toBase64(value) {
|
|
46
64
|
return buf.from(value).toString("base64");
|
47
65
|
}
|
48
66
|
}
|
67
|
+
function deepMerge(a, b) {
|
68
|
+
const result = { ...a };
|
69
|
+
for (const [key, value] of Object.entries(b)) {
|
70
|
+
if (isObject(value) && isObject(result[key])) {
|
71
|
+
result[key] = deepMerge(result[key], value);
|
72
|
+
} else {
|
73
|
+
result[key] = value;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
return result;
|
77
|
+
}
|
78
|
+
function chunk(array, chunkSize) {
|
79
|
+
const result = [];
|
80
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
81
|
+
result.push(array.slice(i, i + chunkSize));
|
82
|
+
}
|
83
|
+
return result;
|
84
|
+
}
|
85
|
+
async function timeout(ms) {
|
86
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
87
|
+
}
|
49
88
|
|
50
89
|
function getEnvironment() {
|
51
90
|
try {
|
52
|
-
if (
|
91
|
+
if (isDefined(process) && isDefined(process.env)) {
|
53
92
|
return {
|
54
93
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
55
94
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
@@ -80,6 +119,25 @@ function getEnvironment() {
|
|
80
119
|
fallbackBranch: getGlobalFallbackBranch()
|
81
120
|
};
|
82
121
|
}
|
122
|
+
function getEnableBrowserVariable() {
|
123
|
+
try {
|
124
|
+
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
125
|
+
return process.env.XATA_ENABLE_BROWSER === "true";
|
126
|
+
}
|
127
|
+
} catch (err) {
|
128
|
+
}
|
129
|
+
try {
|
130
|
+
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
131
|
+
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
132
|
+
}
|
133
|
+
} catch (err) {
|
134
|
+
}
|
135
|
+
try {
|
136
|
+
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
137
|
+
} catch (err) {
|
138
|
+
return void 0;
|
139
|
+
}
|
140
|
+
}
|
83
141
|
function getGlobalApiKey() {
|
84
142
|
try {
|
85
143
|
return XATA_API_KEY;
|
@@ -117,7 +175,7 @@ async function getGitBranch() {
|
|
117
175
|
if (typeof require === "function") {
|
118
176
|
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
119
177
|
}
|
120
|
-
const { execSync } = await (
|
178
|
+
const { execSync } = await import(nodeModule);
|
121
179
|
return execSync(fullCmd, execOptions).toString().trim();
|
122
180
|
} catch (err) {
|
123
181
|
}
|
@@ -139,16 +197,107 @@ function getAPIKey() {
|
|
139
197
|
}
|
140
198
|
}
|
141
199
|
|
200
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
201
|
+
if (!member.has(obj))
|
202
|
+
throw TypeError("Cannot " + msg);
|
203
|
+
};
|
204
|
+
var __privateGet$8 = (obj, member, getter) => {
|
205
|
+
__accessCheck$8(obj, member, "read from private field");
|
206
|
+
return getter ? getter.call(obj) : member.get(obj);
|
207
|
+
};
|
208
|
+
var __privateAdd$8 = (obj, member, value) => {
|
209
|
+
if (member.has(obj))
|
210
|
+
throw TypeError("Cannot add the same private member more than once");
|
211
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
212
|
+
};
|
213
|
+
var __privateSet$8 = (obj, member, value, setter) => {
|
214
|
+
__accessCheck$8(obj, member, "write to private field");
|
215
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
216
|
+
return value;
|
217
|
+
};
|
218
|
+
var __privateMethod$4 = (obj, member, method) => {
|
219
|
+
__accessCheck$8(obj, member, "access private method");
|
220
|
+
return method;
|
221
|
+
};
|
222
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
142
223
|
function getFetchImplementation(userFetch) {
|
143
224
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
144
225
|
const fetchImpl = userFetch ?? globalFetch;
|
145
226
|
if (!fetchImpl) {
|
146
|
-
throw new Error(
|
227
|
+
throw new Error(
|
228
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
229
|
+
);
|
147
230
|
}
|
148
231
|
return fetchImpl;
|
149
232
|
}
|
233
|
+
class ApiRequestPool {
|
234
|
+
constructor(concurrency = 10) {
|
235
|
+
__privateAdd$8(this, _enqueue);
|
236
|
+
__privateAdd$8(this, _fetch, void 0);
|
237
|
+
__privateAdd$8(this, _queue, void 0);
|
238
|
+
__privateAdd$8(this, _concurrency, void 0);
|
239
|
+
__privateSet$8(this, _queue, []);
|
240
|
+
__privateSet$8(this, _concurrency, concurrency);
|
241
|
+
this.running = 0;
|
242
|
+
this.started = 0;
|
243
|
+
}
|
244
|
+
setFetch(fetch2) {
|
245
|
+
__privateSet$8(this, _fetch, fetch2);
|
246
|
+
}
|
247
|
+
getFetch() {
|
248
|
+
if (!__privateGet$8(this, _fetch)) {
|
249
|
+
throw new Error("Fetch not set");
|
250
|
+
}
|
251
|
+
return __privateGet$8(this, _fetch);
|
252
|
+
}
|
253
|
+
request(url, options) {
|
254
|
+
const start = new Date();
|
255
|
+
const fetch2 = this.getFetch();
|
256
|
+
const runRequest = async (stalled = false) => {
|
257
|
+
const response = await fetch2(url, options);
|
258
|
+
if (response.status === 429) {
|
259
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
260
|
+
await timeout(rateLimitReset * 1e3);
|
261
|
+
return await runRequest(true);
|
262
|
+
}
|
263
|
+
if (stalled) {
|
264
|
+
const stalledTime = new Date().getTime() - start.getTime();
|
265
|
+
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
266
|
+
}
|
267
|
+
return response;
|
268
|
+
};
|
269
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
270
|
+
return await runRequest();
|
271
|
+
});
|
272
|
+
}
|
273
|
+
}
|
274
|
+
_fetch = new WeakMap();
|
275
|
+
_queue = new WeakMap();
|
276
|
+
_concurrency = new WeakMap();
|
277
|
+
_enqueue = new WeakSet();
|
278
|
+
enqueue_fn = function(task) {
|
279
|
+
const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
|
280
|
+
this.started--;
|
281
|
+
this.running++;
|
282
|
+
}).then(() => task()).finally(() => {
|
283
|
+
this.running--;
|
284
|
+
const next = __privateGet$8(this, _queue).shift();
|
285
|
+
if (next !== void 0) {
|
286
|
+
this.started++;
|
287
|
+
next();
|
288
|
+
}
|
289
|
+
});
|
290
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
291
|
+
const next = __privateGet$8(this, _queue).shift();
|
292
|
+
if (next !== void 0) {
|
293
|
+
this.started++;
|
294
|
+
next();
|
295
|
+
}
|
296
|
+
}
|
297
|
+
return promise;
|
298
|
+
};
|
150
299
|
|
151
|
-
const VERSION = "0.0.0-alpha.
|
300
|
+
const VERSION = "0.0.0-alpha.vfca6c5f";
|
152
301
|
|
153
302
|
class ErrorWithCause extends Error {
|
154
303
|
constructor(message, options) {
|
@@ -191,6 +340,7 @@ function getMessage(data) {
|
|
191
340
|
}
|
192
341
|
}
|
193
342
|
|
343
|
+
const pool = new ApiRequestPool();
|
194
344
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
195
345
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
196
346
|
if (value === void 0 || value === null)
|
@@ -199,18 +349,24 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
199
349
|
}, {});
|
200
350
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
201
351
|
const queryString = query.length > 0 ? `?${query}` : "";
|
202
|
-
|
352
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
353
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
354
|
+
}, {});
|
355
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
203
356
|
};
|
204
357
|
function buildBaseUrl({
|
358
|
+
endpoint,
|
205
359
|
path,
|
206
360
|
workspacesApiUrl,
|
207
361
|
apiUrl,
|
208
|
-
pathParams
|
362
|
+
pathParams = {}
|
209
363
|
}) {
|
210
|
-
if (
|
211
|
-
|
212
|
-
|
213
|
-
|
364
|
+
if (endpoint === "dataPlane") {
|
365
|
+
const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
366
|
+
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
367
|
+
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
368
|
+
}
|
369
|
+
return `${apiUrl}${path}`;
|
214
370
|
}
|
215
371
|
function hostHeader(url) {
|
216
372
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -226,271 +382,242 @@ async function fetch$1({
|
|
226
382
|
queryParams,
|
227
383
|
fetchImpl,
|
228
384
|
apiKey,
|
385
|
+
endpoint,
|
229
386
|
apiUrl,
|
230
|
-
workspacesApiUrl
|
387
|
+
workspacesApiUrl,
|
388
|
+
trace,
|
389
|
+
signal,
|
390
|
+
clientID,
|
391
|
+
sessionID,
|
392
|
+
clientName,
|
393
|
+
fetchOptions = {}
|
231
394
|
}) {
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
395
|
+
pool.setFetch(fetchImpl);
|
396
|
+
return await trace(
|
397
|
+
`${method.toUpperCase()} ${path}`,
|
398
|
+
async ({ name, setAttributes }) => {
|
399
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
400
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
401
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
402
|
+
setAttributes({
|
403
|
+
[TraceAttributes.HTTP_URL]: url,
|
404
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
405
|
+
});
|
406
|
+
const xataAgent = compact([
|
407
|
+
["client", "TS_SDK"],
|
408
|
+
["version", VERSION],
|
409
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
410
|
+
isDefined(name) ? ["operation", name] : void 0
|
411
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
412
|
+
const response = await pool.request(url, {
|
413
|
+
...fetchOptions,
|
414
|
+
method: method.toUpperCase(),
|
415
|
+
body: body ? JSON.stringify(body) : void 0,
|
416
|
+
headers: {
|
417
|
+
"Content-Type": "application/json",
|
418
|
+
"X-Xata-Client-ID": clientID ?? "",
|
419
|
+
"X-Xata-Session-ID": sessionID ?? "",
|
420
|
+
"X-Xata-Agent": xataAgent,
|
421
|
+
...headers,
|
422
|
+
...hostHeader(fullUrl),
|
423
|
+
Authorization: `Bearer ${apiKey}`
|
424
|
+
},
|
425
|
+
signal
|
426
|
+
});
|
427
|
+
const { host, protocol } = parseUrl(response.url);
|
428
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
429
|
+
setAttributes({
|
430
|
+
[TraceAttributes.KIND]: "http",
|
431
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
432
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
433
|
+
[TraceAttributes.HTTP_HOST]: host,
|
434
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
435
|
+
});
|
436
|
+
if (response.status === 204) {
|
437
|
+
return {};
|
438
|
+
}
|
439
|
+
if (response.status === 429) {
|
440
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
441
|
+
}
|
442
|
+
try {
|
443
|
+
const jsonResponse = await response.json();
|
444
|
+
if (response.ok) {
|
445
|
+
return jsonResponse;
|
446
|
+
}
|
447
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
448
|
+
} catch (error) {
|
449
|
+
throw new FetcherError(response.status, error, requestId);
|
450
|
+
}
|
451
|
+
},
|
452
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
453
|
+
);
|
454
|
+
}
|
455
|
+
function parseUrl(url) {
|
250
456
|
try {
|
251
|
-
const
|
252
|
-
|
253
|
-
return jsonResponse;
|
254
|
-
}
|
255
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
457
|
+
const { host, protocol } = new URL(url);
|
458
|
+
return { host, protocol };
|
256
459
|
} catch (error) {
|
257
|
-
|
460
|
+
return {};
|
258
461
|
}
|
259
462
|
}
|
260
463
|
|
261
|
-
const
|
262
|
-
|
263
|
-
const
|
264
|
-
const
|
265
|
-
url: "/user/keys",
|
266
|
-
method: "get",
|
267
|
-
...variables
|
268
|
-
});
|
269
|
-
const createUserAPIKey = (variables) => fetch$1({
|
270
|
-
url: "/user/keys/{keyName}",
|
271
|
-
method: "post",
|
272
|
-
...variables
|
273
|
-
});
|
274
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
275
|
-
url: "/user/keys/{keyName}",
|
276
|
-
method: "delete",
|
277
|
-
...variables
|
278
|
-
});
|
279
|
-
const createWorkspace = (variables) => fetch$1({
|
280
|
-
url: "/workspaces",
|
281
|
-
method: "post",
|
282
|
-
...variables
|
283
|
-
});
|
284
|
-
const getWorkspacesList = (variables) => fetch$1({
|
285
|
-
url: "/workspaces",
|
286
|
-
method: "get",
|
287
|
-
...variables
|
288
|
-
});
|
289
|
-
const getWorkspace = (variables) => fetch$1({
|
290
|
-
url: "/workspaces/{workspaceId}",
|
291
|
-
method: "get",
|
292
|
-
...variables
|
293
|
-
});
|
294
|
-
const updateWorkspace = (variables) => fetch$1({
|
295
|
-
url: "/workspaces/{workspaceId}",
|
296
|
-
method: "put",
|
297
|
-
...variables
|
298
|
-
});
|
299
|
-
const deleteWorkspace = (variables) => fetch$1({
|
300
|
-
url: "/workspaces/{workspaceId}",
|
301
|
-
method: "delete",
|
302
|
-
...variables
|
303
|
-
});
|
304
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
305
|
-
url: "/workspaces/{workspaceId}/members",
|
306
|
-
method: "get",
|
307
|
-
...variables
|
308
|
-
});
|
309
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
310
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
311
|
-
url: "/workspaces/{workspaceId}/members/{userId}",
|
312
|
-
method: "delete",
|
313
|
-
...variables
|
314
|
-
});
|
315
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
316
|
-
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
317
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
318
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
319
|
-
method: "delete",
|
320
|
-
...variables
|
321
|
-
});
|
322
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
323
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
324
|
-
method: "post",
|
325
|
-
...variables
|
326
|
-
});
|
327
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
328
|
-
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
329
|
-
method: "post",
|
330
|
-
...variables
|
331
|
-
});
|
332
|
-
const getDatabaseList = (variables) => fetch$1({
|
333
|
-
url: "/dbs",
|
334
|
-
method: "get",
|
335
|
-
...variables
|
336
|
-
});
|
337
|
-
const getBranchList = (variables) => fetch$1({
|
338
|
-
url: "/dbs/{dbName}",
|
339
|
-
method: "get",
|
340
|
-
...variables
|
341
|
-
});
|
342
|
-
const createDatabase = (variables) => fetch$1({
|
343
|
-
url: "/dbs/{dbName}",
|
344
|
-
method: "put",
|
345
|
-
...variables
|
346
|
-
});
|
347
|
-
const deleteDatabase = (variables) => fetch$1({
|
464
|
+
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
465
|
+
|
466
|
+
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
467
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
348
468
|
url: "/dbs/{dbName}",
|
349
|
-
method: "delete",
|
350
|
-
...variables
|
351
|
-
});
|
352
|
-
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
353
|
-
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
354
|
-
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
355
|
-
const resolveBranch = (variables) => fetch$1({
|
356
|
-
url: "/dbs/{dbName}/resolveBranch",
|
357
469
|
method: "get",
|
358
|
-
...variables
|
470
|
+
...variables,
|
471
|
+
signal
|
359
472
|
});
|
360
|
-
const
|
473
|
+
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
474
|
+
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
475
|
+
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
476
|
+
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
477
|
+
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
361
478
|
url: "/db/{dbBranchName}",
|
362
479
|
method: "get",
|
363
|
-
...variables
|
480
|
+
...variables,
|
481
|
+
signal
|
364
482
|
});
|
365
|
-
const createBranch = (variables) =>
|
366
|
-
const deleteBranch = (variables) =>
|
483
|
+
const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
484
|
+
const deleteBranch = (variables, signal) => dataPlaneFetch({
|
367
485
|
url: "/db/{dbBranchName}",
|
368
486
|
method: "delete",
|
369
|
-
...variables
|
487
|
+
...variables,
|
488
|
+
signal
|
370
489
|
});
|
371
|
-
const updateBranchMetadata = (variables) =>
|
490
|
+
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
372
491
|
url: "/db/{dbBranchName}/metadata",
|
373
492
|
method: "put",
|
374
|
-
...variables
|
493
|
+
...variables,
|
494
|
+
signal
|
375
495
|
});
|
376
|
-
const getBranchMetadata = (variables) =>
|
496
|
+
const getBranchMetadata = (variables, signal) => dataPlaneFetch({
|
377
497
|
url: "/db/{dbBranchName}/metadata",
|
378
498
|
method: "get",
|
379
|
-
...variables
|
499
|
+
...variables,
|
500
|
+
signal
|
380
501
|
});
|
381
|
-
const
|
382
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
383
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
384
|
-
const getBranchStats = (variables) => fetch$1({
|
502
|
+
const getBranchStats = (variables, signal) => dataPlaneFetch({
|
385
503
|
url: "/db/{dbBranchName}/stats",
|
386
504
|
method: "get",
|
387
|
-
...variables
|
505
|
+
...variables,
|
506
|
+
signal
|
507
|
+
});
|
508
|
+
const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
509
|
+
const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
510
|
+
const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
511
|
+
const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
|
512
|
+
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
513
|
+
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
514
|
+
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
515
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
516
|
+
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
517
|
+
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
518
|
+
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
519
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
520
|
+
method: "get",
|
521
|
+
...variables,
|
522
|
+
signal
|
523
|
+
});
|
524
|
+
const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
525
|
+
const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
526
|
+
const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
527
|
+
const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
528
|
+
const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
|
529
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
530
|
+
method: "post",
|
531
|
+
...variables,
|
532
|
+
signal
|
388
533
|
});
|
389
|
-
const
|
534
|
+
const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
535
|
+
const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
536
|
+
const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
537
|
+
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
538
|
+
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
539
|
+
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
540
|
+
const createTable = (variables, signal) => dataPlaneFetch({
|
390
541
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
391
542
|
method: "put",
|
392
|
-
...variables
|
543
|
+
...variables,
|
544
|
+
signal
|
393
545
|
});
|
394
|
-
const deleteTable = (variables) =>
|
546
|
+
const deleteTable = (variables, signal) => dataPlaneFetch({
|
395
547
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
396
548
|
method: "delete",
|
397
|
-
...variables
|
549
|
+
...variables,
|
550
|
+
signal
|
398
551
|
});
|
399
|
-
const updateTable = (variables) =>
|
400
|
-
|
401
|
-
method: "patch",
|
402
|
-
...variables
|
403
|
-
});
|
404
|
-
const getTableSchema = (variables) => fetch$1({
|
552
|
+
const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
|
553
|
+
const getTableSchema = (variables, signal) => dataPlaneFetch({
|
405
554
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
406
555
|
method: "get",
|
407
|
-
...variables
|
556
|
+
...variables,
|
557
|
+
signal
|
408
558
|
});
|
409
|
-
const setTableSchema = (variables) =>
|
410
|
-
|
411
|
-
method: "put",
|
412
|
-
...variables
|
413
|
-
});
|
414
|
-
const getTableColumns = (variables) => fetch$1({
|
559
|
+
const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
|
560
|
+
const getTableColumns = (variables, signal) => dataPlaneFetch({
|
415
561
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
416
562
|
method: "get",
|
417
|
-
...variables
|
418
|
-
|
419
|
-
const addTableColumn = (variables) => fetch$1({
|
420
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
421
|
-
method: "post",
|
422
|
-
...variables
|
563
|
+
...variables,
|
564
|
+
signal
|
423
565
|
});
|
424
|
-
const
|
566
|
+
const addTableColumn = (variables, signal) => dataPlaneFetch(
|
567
|
+
{ url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
|
568
|
+
);
|
569
|
+
const getColumn = (variables, signal) => dataPlaneFetch({
|
425
570
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
426
571
|
method: "get",
|
427
|
-
...variables
|
572
|
+
...variables,
|
573
|
+
signal
|
428
574
|
});
|
429
|
-
const
|
575
|
+
const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
|
576
|
+
const deleteColumn = (variables, signal) => dataPlaneFetch({
|
430
577
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
431
578
|
method: "delete",
|
432
|
-
...variables
|
433
|
-
|
434
|
-
const updateColumn = (variables) => fetch$1({
|
435
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
436
|
-
method: "patch",
|
437
|
-
...variables
|
579
|
+
...variables,
|
580
|
+
signal
|
438
581
|
});
|
439
|
-
const insertRecord = (variables) =>
|
440
|
-
const
|
441
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
442
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
443
|
-
const deleteRecord = (variables) => fetch$1({
|
444
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
445
|
-
method: "delete",
|
446
|
-
...variables
|
447
|
-
});
|
448
|
-
const getRecord = (variables) => fetch$1({
|
582
|
+
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
583
|
+
const getRecord = (variables, signal) => dataPlaneFetch({
|
449
584
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
450
585
|
method: "get",
|
451
|
-
...variables
|
586
|
+
...variables,
|
587
|
+
signal
|
452
588
|
});
|
453
|
-
const
|
454
|
-
const
|
589
|
+
const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
590
|
+
const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
591
|
+
const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
592
|
+
const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
|
593
|
+
const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
594
|
+
const queryTable = (variables, signal) => dataPlaneFetch({
|
455
595
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
456
596
|
method: "post",
|
457
|
-
...variables
|
597
|
+
...variables,
|
598
|
+
signal
|
458
599
|
});
|
459
|
-
const
|
460
|
-
url: "/db/{dbBranchName}/
|
600
|
+
const searchBranch = (variables, signal) => dataPlaneFetch({
|
601
|
+
url: "/db/{dbBranchName}/search",
|
461
602
|
method: "post",
|
462
|
-
...variables
|
603
|
+
...variables,
|
604
|
+
signal
|
463
605
|
});
|
464
|
-
const
|
465
|
-
url: "/db/{dbBranchName}/search",
|
606
|
+
const searchTable = (variables, signal) => dataPlaneFetch({
|
607
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
466
608
|
method: "post",
|
467
|
-
...variables
|
609
|
+
...variables,
|
610
|
+
signal
|
468
611
|
});
|
469
|
-
const
|
470
|
-
|
471
|
-
|
472
|
-
createWorkspace,
|
473
|
-
getWorkspacesList,
|
474
|
-
getWorkspace,
|
475
|
-
updateWorkspace,
|
476
|
-
deleteWorkspace,
|
477
|
-
getWorkspaceMembersList,
|
478
|
-
updateWorkspaceMemberRole,
|
479
|
-
removeWorkspaceMember,
|
480
|
-
inviteWorkspaceMember,
|
481
|
-
updateWorkspaceMemberInvite,
|
482
|
-
cancelWorkspaceMemberInvite,
|
483
|
-
resendWorkspaceMemberInvite,
|
484
|
-
acceptWorkspaceMemberInvite
|
485
|
-
},
|
612
|
+
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
613
|
+
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
614
|
+
const operationsByTag$2 = {
|
486
615
|
database: {
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
removeGitBranchesEntry,
|
493
|
-
resolveBranch
|
616
|
+
dEPRECATEDgetDatabaseList,
|
617
|
+
dEPRECATEDcreateDatabase,
|
618
|
+
dEPRECATEDdeleteDatabase,
|
619
|
+
dEPRECATEDgetDatabaseMetadata,
|
620
|
+
dEPRECATEDupdateDatabaseMetadata
|
494
621
|
},
|
495
622
|
branch: {
|
496
623
|
getBranchList,
|
@@ -499,10 +626,42 @@ const operationsByTag = {
|
|
499
626
|
deleteBranch,
|
500
627
|
updateBranchMetadata,
|
501
628
|
getBranchMetadata,
|
629
|
+
getBranchStats,
|
630
|
+
getGitBranchesMapping,
|
631
|
+
addGitBranchesEntry,
|
632
|
+
removeGitBranchesEntry,
|
633
|
+
resolveBranch
|
634
|
+
},
|
635
|
+
migrations: {
|
502
636
|
getBranchMigrationHistory,
|
503
|
-
executeBranchMigrationPlan,
|
504
637
|
getBranchMigrationPlan,
|
505
|
-
|
638
|
+
executeBranchMigrationPlan,
|
639
|
+
getBranchSchemaHistory,
|
640
|
+
compareBranchWithUserSchema,
|
641
|
+
compareBranchSchemas,
|
642
|
+
updateBranchSchema,
|
643
|
+
previewBranchSchemaEdit,
|
644
|
+
applyBranchSchemaEdit
|
645
|
+
},
|
646
|
+
records: {
|
647
|
+
branchTransaction,
|
648
|
+
insertRecord,
|
649
|
+
getRecord,
|
650
|
+
insertRecordWithID,
|
651
|
+
updateRecordWithID,
|
652
|
+
upsertRecordWithID,
|
653
|
+
deleteRecord,
|
654
|
+
bulkInsertTableRecords
|
655
|
+
},
|
656
|
+
migrationRequests: {
|
657
|
+
queryMigrationRequests,
|
658
|
+
createMigrationRequest,
|
659
|
+
getMigrationRequest,
|
660
|
+
updateMigrationRequest,
|
661
|
+
listMigrationRequestsCommits,
|
662
|
+
compareMigrationRequest,
|
663
|
+
getMigrationRequestIsMerged,
|
664
|
+
mergeMigrationRequest
|
506
665
|
},
|
507
666
|
table: {
|
508
667
|
createTable,
|
@@ -513,27 +672,150 @@ const operationsByTag = {
|
|
513
672
|
getTableColumns,
|
514
673
|
addTableColumn,
|
515
674
|
getColumn,
|
516
|
-
|
517
|
-
|
675
|
+
updateColumn,
|
676
|
+
deleteColumn
|
518
677
|
},
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
678
|
+
searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
|
679
|
+
};
|
680
|
+
|
681
|
+
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
682
|
+
|
683
|
+
const getUser = (variables, signal) => controlPlaneFetch({
|
684
|
+
url: "/user",
|
685
|
+
method: "get",
|
686
|
+
...variables,
|
687
|
+
signal
|
688
|
+
});
|
689
|
+
const updateUser = (variables, signal) => controlPlaneFetch({
|
690
|
+
url: "/user",
|
691
|
+
method: "put",
|
692
|
+
...variables,
|
693
|
+
signal
|
694
|
+
});
|
695
|
+
const deleteUser = (variables, signal) => controlPlaneFetch({
|
696
|
+
url: "/user",
|
697
|
+
method: "delete",
|
698
|
+
...variables,
|
699
|
+
signal
|
700
|
+
});
|
701
|
+
const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
702
|
+
url: "/user/keys",
|
703
|
+
method: "get",
|
704
|
+
...variables,
|
705
|
+
signal
|
706
|
+
});
|
707
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
708
|
+
url: "/user/keys/{keyName}",
|
709
|
+
method: "post",
|
710
|
+
...variables,
|
711
|
+
signal
|
712
|
+
});
|
713
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
714
|
+
url: "/user/keys/{keyName}",
|
715
|
+
method: "delete",
|
716
|
+
...variables,
|
717
|
+
signal
|
718
|
+
});
|
719
|
+
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
720
|
+
url: "/workspaces",
|
721
|
+
method: "get",
|
722
|
+
...variables,
|
723
|
+
signal
|
724
|
+
});
|
725
|
+
const createWorkspace = (variables, signal) => controlPlaneFetch({
|
726
|
+
url: "/workspaces",
|
727
|
+
method: "post",
|
728
|
+
...variables,
|
729
|
+
signal
|
730
|
+
});
|
731
|
+
const getWorkspace = (variables, signal) => controlPlaneFetch({
|
732
|
+
url: "/workspaces/{workspaceId}",
|
733
|
+
method: "get",
|
734
|
+
...variables,
|
735
|
+
signal
|
736
|
+
});
|
737
|
+
const updateWorkspace = (variables, signal) => controlPlaneFetch({
|
738
|
+
url: "/workspaces/{workspaceId}",
|
739
|
+
method: "put",
|
740
|
+
...variables,
|
741
|
+
signal
|
742
|
+
});
|
743
|
+
const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
744
|
+
url: "/workspaces/{workspaceId}",
|
745
|
+
method: "delete",
|
746
|
+
...variables,
|
747
|
+
signal
|
748
|
+
});
|
749
|
+
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
750
|
+
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
751
|
+
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
752
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
753
|
+
method: "delete",
|
754
|
+
...variables,
|
755
|
+
signal
|
756
|
+
});
|
757
|
+
const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
758
|
+
const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
759
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
760
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
761
|
+
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
762
|
+
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
763
|
+
url: "/workspaces/{workspaceId}/dbs",
|
764
|
+
method: "get",
|
765
|
+
...variables,
|
766
|
+
signal
|
767
|
+
});
|
768
|
+
const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
769
|
+
const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
770
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
771
|
+
method: "delete",
|
772
|
+
...variables,
|
773
|
+
signal
|
774
|
+
});
|
775
|
+
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
776
|
+
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
777
|
+
const listRegions = (variables, signal) => controlPlaneFetch({
|
778
|
+
url: "/workspaces/{workspaceId}/regions",
|
779
|
+
method: "get",
|
780
|
+
...variables,
|
781
|
+
signal
|
782
|
+
});
|
783
|
+
const operationsByTag$1 = {
|
784
|
+
users: { getUser, updateUser, deleteUser },
|
785
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
786
|
+
workspaces: {
|
787
|
+
getWorkspacesList,
|
788
|
+
createWorkspace,
|
789
|
+
getWorkspace,
|
790
|
+
updateWorkspace,
|
791
|
+
deleteWorkspace,
|
792
|
+
getWorkspaceMembersList,
|
793
|
+
updateWorkspaceMemberRole,
|
794
|
+
removeWorkspaceMember
|
795
|
+
},
|
796
|
+
invites: {
|
797
|
+
inviteWorkspaceMember,
|
798
|
+
updateWorkspaceMemberInvite,
|
799
|
+
cancelWorkspaceMemberInvite,
|
800
|
+
acceptWorkspaceMemberInvite,
|
801
|
+
resendWorkspaceMemberInvite
|
802
|
+
},
|
803
|
+
databases: {
|
804
|
+
getDatabaseList,
|
805
|
+
createDatabase,
|
806
|
+
deleteDatabase,
|
807
|
+
getDatabaseMetadata,
|
808
|
+
updateDatabaseMetadata,
|
809
|
+
listRegions
|
530
810
|
}
|
531
811
|
};
|
532
812
|
|
813
|
+
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
814
|
+
|
533
815
|
function getHostUrl(provider, type) {
|
534
|
-
if (
|
816
|
+
if (isHostProviderAlias(provider)) {
|
535
817
|
return providers[provider][type];
|
536
|
-
} else if (
|
818
|
+
} else if (isHostProviderBuilder(provider)) {
|
537
819
|
return provider[type];
|
538
820
|
}
|
539
821
|
throw new Error("Invalid API provider");
|
@@ -541,19 +823,38 @@ function getHostUrl(provider, type) {
|
|
541
823
|
const providers = {
|
542
824
|
production: {
|
543
825
|
main: "https://api.xata.io",
|
544
|
-
workspaces: "https://{workspaceId}.xata.sh"
|
826
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
545
827
|
},
|
546
828
|
staging: {
|
547
829
|
main: "https://staging.xatabase.co",
|
548
|
-
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
830
|
+
workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
|
549
831
|
}
|
550
832
|
};
|
551
|
-
function
|
833
|
+
function isHostProviderAlias(alias) {
|
552
834
|
return isString(alias) && Object.keys(providers).includes(alias);
|
553
835
|
}
|
554
|
-
function
|
836
|
+
function isHostProviderBuilder(builder) {
|
555
837
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
556
838
|
}
|
839
|
+
function parseProviderString(provider = "production") {
|
840
|
+
if (isHostProviderAlias(provider)) {
|
841
|
+
return provider;
|
842
|
+
}
|
843
|
+
const [main, workspaces] = provider.split(",");
|
844
|
+
if (!main || !workspaces)
|
845
|
+
return null;
|
846
|
+
return { main, workspaces };
|
847
|
+
}
|
848
|
+
function parseWorkspacesUrlParts(url) {
|
849
|
+
if (!isString(url))
|
850
|
+
return null;
|
851
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
|
852
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
|
853
|
+
const match = url.match(regex) || url.match(regexStaging);
|
854
|
+
if (!match)
|
855
|
+
return null;
|
856
|
+
return { workspace: match[1], region: match[2] ?? "eu-west-1" };
|
857
|
+
}
|
557
858
|
|
558
859
|
var __accessCheck$7 = (obj, member, msg) => {
|
559
860
|
if (!member.has(obj))
|
@@ -579,7 +880,8 @@ class XataApiClient {
|
|
579
880
|
__privateAdd$7(this, _extraProps, void 0);
|
580
881
|
__privateAdd$7(this, _namespaces, {});
|
581
882
|
const provider = options.host ?? "production";
|
582
|
-
const apiKey = options
|
883
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
884
|
+
const trace = options.trace ?? defaultTrace;
|
583
885
|
if (!apiKey) {
|
584
886
|
throw new Error("Could not resolve a valid apiKey");
|
585
887
|
}
|
@@ -587,7 +889,9 @@ class XataApiClient {
|
|
587
889
|
apiUrl: getHostUrl(provider, "main"),
|
588
890
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
589
891
|
fetchImpl: getFetchImplementation(options.fetch),
|
590
|
-
apiKey
|
892
|
+
apiKey,
|
893
|
+
trace,
|
894
|
+
clientName: options.clientName
|
591
895
|
});
|
592
896
|
}
|
593
897
|
get user() {
|
@@ -595,21 +899,41 @@ class XataApiClient {
|
|
595
899
|
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
596
900
|
return __privateGet$7(this, _namespaces).user;
|
597
901
|
}
|
902
|
+
get authentication() {
|
903
|
+
if (!__privateGet$7(this, _namespaces).authentication)
|
904
|
+
__privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
|
905
|
+
return __privateGet$7(this, _namespaces).authentication;
|
906
|
+
}
|
598
907
|
get workspaces() {
|
599
908
|
if (!__privateGet$7(this, _namespaces).workspaces)
|
600
909
|
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
601
910
|
return __privateGet$7(this, _namespaces).workspaces;
|
602
911
|
}
|
603
|
-
get
|
604
|
-
if (!__privateGet$7(this, _namespaces).
|
605
|
-
__privateGet$7(this, _namespaces).
|
606
|
-
return __privateGet$7(this, _namespaces).
|
912
|
+
get invites() {
|
913
|
+
if (!__privateGet$7(this, _namespaces).invites)
|
914
|
+
__privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
|
915
|
+
return __privateGet$7(this, _namespaces).invites;
|
916
|
+
}
|
917
|
+
get database() {
|
918
|
+
if (!__privateGet$7(this, _namespaces).database)
|
919
|
+
__privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
|
920
|
+
return __privateGet$7(this, _namespaces).database;
|
607
921
|
}
|
608
922
|
get branches() {
|
609
923
|
if (!__privateGet$7(this, _namespaces).branches)
|
610
924
|
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
611
925
|
return __privateGet$7(this, _namespaces).branches;
|
612
926
|
}
|
927
|
+
get migrations() {
|
928
|
+
if (!__privateGet$7(this, _namespaces).migrations)
|
929
|
+
__privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
|
930
|
+
return __privateGet$7(this, _namespaces).migrations;
|
931
|
+
}
|
932
|
+
get migrationRequests() {
|
933
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
934
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
935
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
936
|
+
}
|
613
937
|
get tables() {
|
614
938
|
if (!__privateGet$7(this, _namespaces).tables)
|
615
939
|
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
@@ -620,6 +944,11 @@ class XataApiClient {
|
|
620
944
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
621
945
|
return __privateGet$7(this, _namespaces).records;
|
622
946
|
}
|
947
|
+
get searchAndFilter() {
|
948
|
+
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
949
|
+
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
950
|
+
return __privateGet$7(this, _namespaces).searchAndFilter;
|
951
|
+
}
|
623
952
|
}
|
624
953
|
_extraProps = new WeakMap();
|
625
954
|
_namespaces = new WeakMap();
|
@@ -630,24 +959,29 @@ class UserApi {
|
|
630
959
|
getUser() {
|
631
960
|
return operationsByTag.users.getUser({ ...this.extraProps });
|
632
961
|
}
|
633
|
-
updateUser(user) {
|
962
|
+
updateUser({ user }) {
|
634
963
|
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
635
964
|
}
|
636
965
|
deleteUser() {
|
637
966
|
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
638
967
|
}
|
968
|
+
}
|
969
|
+
class AuthenticationApi {
|
970
|
+
constructor(extraProps) {
|
971
|
+
this.extraProps = extraProps;
|
972
|
+
}
|
639
973
|
getUserAPIKeys() {
|
640
|
-
return operationsByTag.
|
974
|
+
return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
|
641
975
|
}
|
642
|
-
createUserAPIKey(
|
643
|
-
return operationsByTag.
|
644
|
-
pathParams: { keyName },
|
976
|
+
createUserAPIKey({ name }) {
|
977
|
+
return operationsByTag.authentication.createUserAPIKey({
|
978
|
+
pathParams: { keyName: name },
|
645
979
|
...this.extraProps
|
646
980
|
});
|
647
981
|
}
|
648
|
-
deleteUserAPIKey(
|
649
|
-
return operationsByTag.
|
650
|
-
pathParams: { keyName },
|
982
|
+
deleteUserAPIKey({ name }) {
|
983
|
+
return operationsByTag.authentication.deleteUserAPIKey({
|
984
|
+
pathParams: { keyName: name },
|
651
985
|
...this.extraProps
|
652
986
|
});
|
653
987
|
}
|
@@ -656,353 +990,897 @@ class WorkspaceApi {
|
|
656
990
|
constructor(extraProps) {
|
657
991
|
this.extraProps = extraProps;
|
658
992
|
}
|
659
|
-
|
993
|
+
getWorkspacesList() {
|
994
|
+
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
995
|
+
}
|
996
|
+
createWorkspace({ data }) {
|
660
997
|
return operationsByTag.workspaces.createWorkspace({
|
661
|
-
body:
|
998
|
+
body: data,
|
662
999
|
...this.extraProps
|
663
1000
|
});
|
664
1001
|
}
|
665
|
-
|
666
|
-
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
667
|
-
}
|
668
|
-
getWorkspace(workspaceId) {
|
1002
|
+
getWorkspace({ workspace }) {
|
669
1003
|
return operationsByTag.workspaces.getWorkspace({
|
670
|
-
pathParams: { workspaceId },
|
1004
|
+
pathParams: { workspaceId: workspace },
|
671
1005
|
...this.extraProps
|
672
1006
|
});
|
673
1007
|
}
|
674
|
-
updateWorkspace(
|
1008
|
+
updateWorkspace({
|
1009
|
+
workspace,
|
1010
|
+
update
|
1011
|
+
}) {
|
675
1012
|
return operationsByTag.workspaces.updateWorkspace({
|
676
|
-
pathParams: { workspaceId },
|
677
|
-
body:
|
1013
|
+
pathParams: { workspaceId: workspace },
|
1014
|
+
body: update,
|
678
1015
|
...this.extraProps
|
679
1016
|
});
|
680
1017
|
}
|
681
|
-
deleteWorkspace(
|
1018
|
+
deleteWorkspace({ workspace }) {
|
682
1019
|
return operationsByTag.workspaces.deleteWorkspace({
|
683
|
-
pathParams: { workspaceId },
|
1020
|
+
pathParams: { workspaceId: workspace },
|
684
1021
|
...this.extraProps
|
685
1022
|
});
|
686
1023
|
}
|
687
|
-
getWorkspaceMembersList(
|
1024
|
+
getWorkspaceMembersList({ workspace }) {
|
688
1025
|
return operationsByTag.workspaces.getWorkspaceMembersList({
|
689
|
-
pathParams: { workspaceId },
|
1026
|
+
pathParams: { workspaceId: workspace },
|
690
1027
|
...this.extraProps
|
691
1028
|
});
|
692
1029
|
}
|
693
|
-
updateWorkspaceMemberRole(
|
1030
|
+
updateWorkspaceMemberRole({
|
1031
|
+
workspace,
|
1032
|
+
user,
|
1033
|
+
role
|
1034
|
+
}) {
|
694
1035
|
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
695
|
-
pathParams: { workspaceId, userId },
|
1036
|
+
pathParams: { workspaceId: workspace, userId: user },
|
696
1037
|
body: { role },
|
697
1038
|
...this.extraProps
|
698
1039
|
});
|
699
1040
|
}
|
700
|
-
removeWorkspaceMember(
|
1041
|
+
removeWorkspaceMember({
|
1042
|
+
workspace,
|
1043
|
+
user
|
1044
|
+
}) {
|
701
1045
|
return operationsByTag.workspaces.removeWorkspaceMember({
|
702
|
-
pathParams: { workspaceId, userId },
|
1046
|
+
pathParams: { workspaceId: workspace, userId: user },
|
703
1047
|
...this.extraProps
|
704
1048
|
});
|
705
1049
|
}
|
706
|
-
|
707
|
-
|
708
|
-
|
1050
|
+
}
|
1051
|
+
class InvitesApi {
|
1052
|
+
constructor(extraProps) {
|
1053
|
+
this.extraProps = extraProps;
|
1054
|
+
}
|
1055
|
+
inviteWorkspaceMember({
|
1056
|
+
workspace,
|
1057
|
+
email,
|
1058
|
+
role
|
1059
|
+
}) {
|
1060
|
+
return operationsByTag.invites.inviteWorkspaceMember({
|
1061
|
+
pathParams: { workspaceId: workspace },
|
709
1062
|
body: { email, role },
|
710
1063
|
...this.extraProps
|
711
1064
|
});
|
712
1065
|
}
|
713
|
-
updateWorkspaceMemberInvite(
|
714
|
-
|
715
|
-
|
1066
|
+
updateWorkspaceMemberInvite({
|
1067
|
+
workspace,
|
1068
|
+
invite,
|
1069
|
+
role
|
1070
|
+
}) {
|
1071
|
+
return operationsByTag.invites.updateWorkspaceMemberInvite({
|
1072
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
716
1073
|
body: { role },
|
717
1074
|
...this.extraProps
|
718
1075
|
});
|
719
1076
|
}
|
720
|
-
cancelWorkspaceMemberInvite(
|
721
|
-
|
722
|
-
|
1077
|
+
cancelWorkspaceMemberInvite({
|
1078
|
+
workspace,
|
1079
|
+
invite
|
1080
|
+
}) {
|
1081
|
+
return operationsByTag.invites.cancelWorkspaceMemberInvite({
|
1082
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
723
1083
|
...this.extraProps
|
724
1084
|
});
|
725
1085
|
}
|
726
|
-
|
727
|
-
|
728
|
-
|
1086
|
+
acceptWorkspaceMemberInvite({
|
1087
|
+
workspace,
|
1088
|
+
key
|
1089
|
+
}) {
|
1090
|
+
return operationsByTag.invites.acceptWorkspaceMemberInvite({
|
1091
|
+
pathParams: { workspaceId: workspace, inviteKey: key },
|
729
1092
|
...this.extraProps
|
730
1093
|
});
|
731
1094
|
}
|
732
|
-
|
733
|
-
|
734
|
-
|
1095
|
+
resendWorkspaceMemberInvite({
|
1096
|
+
workspace,
|
1097
|
+
invite
|
1098
|
+
}) {
|
1099
|
+
return operationsByTag.invites.resendWorkspaceMemberInvite({
|
1100
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
735
1101
|
...this.extraProps
|
736
1102
|
});
|
737
1103
|
}
|
738
1104
|
}
|
739
|
-
class
|
1105
|
+
class BranchApi {
|
740
1106
|
constructor(extraProps) {
|
741
1107
|
this.extraProps = extraProps;
|
742
1108
|
}
|
743
|
-
|
744
|
-
|
745
|
-
|
1109
|
+
getBranchList({
|
1110
|
+
workspace,
|
1111
|
+
region,
|
1112
|
+
database
|
1113
|
+
}) {
|
1114
|
+
return operationsByTag.branch.getBranchList({
|
1115
|
+
pathParams: { workspace, region, dbName: database },
|
1116
|
+
...this.extraProps
|
1117
|
+
});
|
1118
|
+
}
|
1119
|
+
getBranchDetails({
|
1120
|
+
workspace,
|
1121
|
+
region,
|
1122
|
+
database,
|
1123
|
+
branch
|
1124
|
+
}) {
|
1125
|
+
return operationsByTag.branch.getBranchDetails({
|
1126
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
746
1127
|
...this.extraProps
|
747
1128
|
});
|
748
1129
|
}
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
1130
|
+
createBranch({
|
1131
|
+
workspace,
|
1132
|
+
region,
|
1133
|
+
database,
|
1134
|
+
branch,
|
1135
|
+
from,
|
1136
|
+
metadata
|
1137
|
+
}) {
|
1138
|
+
return operationsByTag.branch.createBranch({
|
1139
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1140
|
+
body: { from, metadata },
|
753
1141
|
...this.extraProps
|
754
1142
|
});
|
755
1143
|
}
|
756
|
-
|
757
|
-
|
758
|
-
|
1144
|
+
deleteBranch({
|
1145
|
+
workspace,
|
1146
|
+
region,
|
1147
|
+
database,
|
1148
|
+
branch
|
1149
|
+
}) {
|
1150
|
+
return operationsByTag.branch.deleteBranch({
|
1151
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
759
1152
|
...this.extraProps
|
760
1153
|
});
|
761
1154
|
}
|
762
|
-
|
763
|
-
|
764
|
-
|
1155
|
+
updateBranchMetadata({
|
1156
|
+
workspace,
|
1157
|
+
region,
|
1158
|
+
database,
|
1159
|
+
branch,
|
1160
|
+
metadata
|
1161
|
+
}) {
|
1162
|
+
return operationsByTag.branch.updateBranchMetadata({
|
1163
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1164
|
+
body: metadata,
|
765
1165
|
...this.extraProps
|
766
1166
|
});
|
767
1167
|
}
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
1168
|
+
getBranchMetadata({
|
1169
|
+
workspace,
|
1170
|
+
region,
|
1171
|
+
database,
|
1172
|
+
branch
|
1173
|
+
}) {
|
1174
|
+
return operationsByTag.branch.getBranchMetadata({
|
1175
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1176
|
+
...this.extraProps
|
1177
|
+
});
|
1178
|
+
}
|
1179
|
+
getBranchStats({
|
1180
|
+
workspace,
|
1181
|
+
region,
|
1182
|
+
database,
|
1183
|
+
branch
|
1184
|
+
}) {
|
1185
|
+
return operationsByTag.branch.getBranchStats({
|
1186
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
772
1187
|
...this.extraProps
|
773
1188
|
});
|
774
1189
|
}
|
775
|
-
|
776
|
-
|
777
|
-
|
1190
|
+
getGitBranchesMapping({
|
1191
|
+
workspace,
|
1192
|
+
region,
|
1193
|
+
database
|
1194
|
+
}) {
|
1195
|
+
return operationsByTag.branch.getGitBranchesMapping({
|
1196
|
+
pathParams: { workspace, region, dbName: database },
|
1197
|
+
...this.extraProps
|
1198
|
+
});
|
1199
|
+
}
|
1200
|
+
addGitBranchesEntry({
|
1201
|
+
workspace,
|
1202
|
+
region,
|
1203
|
+
database,
|
1204
|
+
gitBranch,
|
1205
|
+
xataBranch
|
1206
|
+
}) {
|
1207
|
+
return operationsByTag.branch.addGitBranchesEntry({
|
1208
|
+
pathParams: { workspace, region, dbName: database },
|
1209
|
+
body: { gitBranch, xataBranch },
|
1210
|
+
...this.extraProps
|
1211
|
+
});
|
1212
|
+
}
|
1213
|
+
removeGitBranchesEntry({
|
1214
|
+
workspace,
|
1215
|
+
region,
|
1216
|
+
database,
|
1217
|
+
gitBranch
|
1218
|
+
}) {
|
1219
|
+
return operationsByTag.branch.removeGitBranchesEntry({
|
1220
|
+
pathParams: { workspace, region, dbName: database },
|
778
1221
|
queryParams: { gitBranch },
|
779
1222
|
...this.extraProps
|
780
1223
|
});
|
781
1224
|
}
|
782
|
-
resolveBranch(
|
783
|
-
|
784
|
-
|
1225
|
+
resolveBranch({
|
1226
|
+
workspace,
|
1227
|
+
region,
|
1228
|
+
database,
|
1229
|
+
gitBranch,
|
1230
|
+
fallbackBranch
|
1231
|
+
}) {
|
1232
|
+
return operationsByTag.branch.resolveBranch({
|
1233
|
+
pathParams: { workspace, region, dbName: database },
|
785
1234
|
queryParams: { gitBranch, fallbackBranch },
|
786
1235
|
...this.extraProps
|
787
1236
|
});
|
788
1237
|
}
|
789
1238
|
}
|
790
|
-
class
|
1239
|
+
class TableApi {
|
791
1240
|
constructor(extraProps) {
|
792
1241
|
this.extraProps = extraProps;
|
793
1242
|
}
|
794
|
-
|
795
|
-
|
796
|
-
|
1243
|
+
createTable({
|
1244
|
+
workspace,
|
1245
|
+
region,
|
1246
|
+
database,
|
1247
|
+
branch,
|
1248
|
+
table
|
1249
|
+
}) {
|
1250
|
+
return operationsByTag.table.createTable({
|
1251
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
797
1252
|
...this.extraProps
|
798
1253
|
});
|
799
1254
|
}
|
800
|
-
|
801
|
-
|
802
|
-
|
1255
|
+
deleteTable({
|
1256
|
+
workspace,
|
1257
|
+
region,
|
1258
|
+
database,
|
1259
|
+
branch,
|
1260
|
+
table
|
1261
|
+
}) {
|
1262
|
+
return operationsByTag.table.deleteTable({
|
1263
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
803
1264
|
...this.extraProps
|
804
1265
|
});
|
805
1266
|
}
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
1267
|
+
updateTable({
|
1268
|
+
workspace,
|
1269
|
+
region,
|
1270
|
+
database,
|
1271
|
+
branch,
|
1272
|
+
table,
|
1273
|
+
update
|
1274
|
+
}) {
|
1275
|
+
return operationsByTag.table.updateTable({
|
1276
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1277
|
+
body: update,
|
811
1278
|
...this.extraProps
|
812
1279
|
});
|
813
1280
|
}
|
814
|
-
|
815
|
-
|
816
|
-
|
1281
|
+
getTableSchema({
|
1282
|
+
workspace,
|
1283
|
+
region,
|
1284
|
+
database,
|
1285
|
+
branch,
|
1286
|
+
table
|
1287
|
+
}) {
|
1288
|
+
return operationsByTag.table.getTableSchema({
|
1289
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
817
1290
|
...this.extraProps
|
818
1291
|
});
|
819
1292
|
}
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
1293
|
+
setTableSchema({
|
1294
|
+
workspace,
|
1295
|
+
region,
|
1296
|
+
database,
|
1297
|
+
branch,
|
1298
|
+
table,
|
1299
|
+
schema
|
1300
|
+
}) {
|
1301
|
+
return operationsByTag.table.setTableSchema({
|
1302
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1303
|
+
body: schema,
|
824
1304
|
...this.extraProps
|
825
1305
|
});
|
826
1306
|
}
|
827
|
-
|
828
|
-
|
829
|
-
|
1307
|
+
getTableColumns({
|
1308
|
+
workspace,
|
1309
|
+
region,
|
1310
|
+
database,
|
1311
|
+
branch,
|
1312
|
+
table
|
1313
|
+
}) {
|
1314
|
+
return operationsByTag.table.getTableColumns({
|
1315
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
830
1316
|
...this.extraProps
|
831
1317
|
});
|
832
1318
|
}
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
1319
|
+
addTableColumn({
|
1320
|
+
workspace,
|
1321
|
+
region,
|
1322
|
+
database,
|
1323
|
+
branch,
|
1324
|
+
table,
|
1325
|
+
column
|
1326
|
+
}) {
|
1327
|
+
return operationsByTag.table.addTableColumn({
|
1328
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1329
|
+
body: column,
|
1330
|
+
...this.extraProps
|
1331
|
+
});
|
1332
|
+
}
|
1333
|
+
getColumn({
|
1334
|
+
workspace,
|
1335
|
+
region,
|
1336
|
+
database,
|
1337
|
+
branch,
|
1338
|
+
table,
|
1339
|
+
column
|
1340
|
+
}) {
|
1341
|
+
return operationsByTag.table.getColumn({
|
1342
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1343
|
+
...this.extraProps
|
1344
|
+
});
|
1345
|
+
}
|
1346
|
+
updateColumn({
|
1347
|
+
workspace,
|
1348
|
+
region,
|
1349
|
+
database,
|
1350
|
+
branch,
|
1351
|
+
table,
|
1352
|
+
column,
|
1353
|
+
update
|
1354
|
+
}) {
|
1355
|
+
return operationsByTag.table.updateColumn({
|
1356
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1357
|
+
body: update,
|
1358
|
+
...this.extraProps
|
1359
|
+
});
|
1360
|
+
}
|
1361
|
+
deleteColumn({
|
1362
|
+
workspace,
|
1363
|
+
region,
|
1364
|
+
database,
|
1365
|
+
branch,
|
1366
|
+
table,
|
1367
|
+
column
|
1368
|
+
}) {
|
1369
|
+
return operationsByTag.table.deleteColumn({
|
1370
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1371
|
+
...this.extraProps
|
1372
|
+
});
|
1373
|
+
}
|
1374
|
+
}
|
1375
|
+
class RecordsApi {
|
1376
|
+
constructor(extraProps) {
|
1377
|
+
this.extraProps = extraProps;
|
1378
|
+
}
|
1379
|
+
insertRecord({
|
1380
|
+
workspace,
|
1381
|
+
region,
|
1382
|
+
database,
|
1383
|
+
branch,
|
1384
|
+
table,
|
1385
|
+
record,
|
1386
|
+
columns
|
1387
|
+
}) {
|
1388
|
+
return operationsByTag.records.insertRecord({
|
1389
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1390
|
+
queryParams: { columns },
|
1391
|
+
body: record,
|
1392
|
+
...this.extraProps
|
1393
|
+
});
|
1394
|
+
}
|
1395
|
+
getRecord({
|
1396
|
+
workspace,
|
1397
|
+
region,
|
1398
|
+
database,
|
1399
|
+
branch,
|
1400
|
+
table,
|
1401
|
+
id,
|
1402
|
+
columns
|
1403
|
+
}) {
|
1404
|
+
return operationsByTag.records.getRecord({
|
1405
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1406
|
+
queryParams: { columns },
|
1407
|
+
...this.extraProps
|
1408
|
+
});
|
1409
|
+
}
|
1410
|
+
insertRecordWithID({
|
1411
|
+
workspace,
|
1412
|
+
region,
|
1413
|
+
database,
|
1414
|
+
branch,
|
1415
|
+
table,
|
1416
|
+
id,
|
1417
|
+
record,
|
1418
|
+
columns,
|
1419
|
+
createOnly,
|
1420
|
+
ifVersion
|
1421
|
+
}) {
|
1422
|
+
return operationsByTag.records.insertRecordWithID({
|
1423
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1424
|
+
queryParams: { columns, createOnly, ifVersion },
|
1425
|
+
body: record,
|
1426
|
+
...this.extraProps
|
1427
|
+
});
|
1428
|
+
}
|
1429
|
+
updateRecordWithID({
|
1430
|
+
workspace,
|
1431
|
+
region,
|
1432
|
+
database,
|
1433
|
+
branch,
|
1434
|
+
table,
|
1435
|
+
id,
|
1436
|
+
record,
|
1437
|
+
columns,
|
1438
|
+
ifVersion
|
1439
|
+
}) {
|
1440
|
+
return operationsByTag.records.updateRecordWithID({
|
1441
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1442
|
+
queryParams: { columns, ifVersion },
|
1443
|
+
body: record,
|
1444
|
+
...this.extraProps
|
1445
|
+
});
|
1446
|
+
}
|
1447
|
+
upsertRecordWithID({
|
1448
|
+
workspace,
|
1449
|
+
region,
|
1450
|
+
database,
|
1451
|
+
branch,
|
1452
|
+
table,
|
1453
|
+
id,
|
1454
|
+
record,
|
1455
|
+
columns,
|
1456
|
+
ifVersion
|
1457
|
+
}) {
|
1458
|
+
return operationsByTag.records.upsertRecordWithID({
|
1459
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1460
|
+
queryParams: { columns, ifVersion },
|
1461
|
+
body: record,
|
1462
|
+
...this.extraProps
|
1463
|
+
});
|
1464
|
+
}
|
1465
|
+
deleteRecord({
|
1466
|
+
workspace,
|
1467
|
+
region,
|
1468
|
+
database,
|
1469
|
+
branch,
|
1470
|
+
table,
|
1471
|
+
id,
|
1472
|
+
columns
|
1473
|
+
}) {
|
1474
|
+
return operationsByTag.records.deleteRecord({
|
1475
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1476
|
+
queryParams: { columns },
|
1477
|
+
...this.extraProps
|
1478
|
+
});
|
1479
|
+
}
|
1480
|
+
bulkInsertTableRecords({
|
1481
|
+
workspace,
|
1482
|
+
region,
|
1483
|
+
database,
|
1484
|
+
branch,
|
1485
|
+
table,
|
1486
|
+
records,
|
1487
|
+
columns
|
1488
|
+
}) {
|
1489
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
1490
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1491
|
+
queryParams: { columns },
|
1492
|
+
body: { records },
|
1493
|
+
...this.extraProps
|
1494
|
+
});
|
1495
|
+
}
|
1496
|
+
branchTransaction({
|
1497
|
+
workspace,
|
1498
|
+
region,
|
1499
|
+
database,
|
1500
|
+
branch,
|
1501
|
+
operations
|
1502
|
+
}) {
|
1503
|
+
return operationsByTag.records.branchTransaction({
|
1504
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1505
|
+
body: { operations },
|
1506
|
+
...this.extraProps
|
1507
|
+
});
|
1508
|
+
}
|
1509
|
+
}
|
1510
|
+
class SearchAndFilterApi {
|
1511
|
+
constructor(extraProps) {
|
1512
|
+
this.extraProps = extraProps;
|
1513
|
+
}
|
1514
|
+
queryTable({
|
1515
|
+
workspace,
|
1516
|
+
region,
|
1517
|
+
database,
|
1518
|
+
branch,
|
1519
|
+
table,
|
1520
|
+
filter,
|
1521
|
+
sort,
|
1522
|
+
page,
|
1523
|
+
columns,
|
1524
|
+
consistency
|
1525
|
+
}) {
|
1526
|
+
return operationsByTag.searchAndFilter.queryTable({
|
1527
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1528
|
+
body: { filter, sort, page, columns, consistency },
|
1529
|
+
...this.extraProps
|
1530
|
+
});
|
1531
|
+
}
|
1532
|
+
searchTable({
|
1533
|
+
workspace,
|
1534
|
+
region,
|
1535
|
+
database,
|
1536
|
+
branch,
|
1537
|
+
table,
|
1538
|
+
query,
|
1539
|
+
fuzziness,
|
1540
|
+
target,
|
1541
|
+
prefix,
|
1542
|
+
filter,
|
1543
|
+
highlight,
|
1544
|
+
boosters
|
1545
|
+
}) {
|
1546
|
+
return operationsByTag.searchAndFilter.searchTable({
|
1547
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1548
|
+
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
1549
|
+
...this.extraProps
|
1550
|
+
});
|
1551
|
+
}
|
1552
|
+
searchBranch({
|
1553
|
+
workspace,
|
1554
|
+
region,
|
1555
|
+
database,
|
1556
|
+
branch,
|
1557
|
+
tables,
|
1558
|
+
query,
|
1559
|
+
fuzziness,
|
1560
|
+
prefix,
|
1561
|
+
highlight
|
1562
|
+
}) {
|
1563
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
1564
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1565
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1566
|
+
...this.extraProps
|
1567
|
+
});
|
1568
|
+
}
|
1569
|
+
summarizeTable({
|
1570
|
+
workspace,
|
1571
|
+
region,
|
1572
|
+
database,
|
1573
|
+
branch,
|
1574
|
+
table,
|
1575
|
+
filter,
|
1576
|
+
columns,
|
1577
|
+
summaries,
|
1578
|
+
sort,
|
1579
|
+
summariesFilter,
|
1580
|
+
page,
|
1581
|
+
consistency
|
1582
|
+
}) {
|
1583
|
+
return operationsByTag.searchAndFilter.summarizeTable({
|
1584
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1585
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
1586
|
+
...this.extraProps
|
1587
|
+
});
|
1588
|
+
}
|
1589
|
+
aggregateTable({
|
1590
|
+
workspace,
|
1591
|
+
region,
|
1592
|
+
database,
|
1593
|
+
branch,
|
1594
|
+
table,
|
1595
|
+
filter,
|
1596
|
+
aggs
|
1597
|
+
}) {
|
1598
|
+
return operationsByTag.searchAndFilter.aggregateTable({
|
1599
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1600
|
+
body: { filter, aggs },
|
1601
|
+
...this.extraProps
|
1602
|
+
});
|
1603
|
+
}
|
1604
|
+
}
|
1605
|
+
class MigrationRequestsApi {
|
1606
|
+
constructor(extraProps) {
|
1607
|
+
this.extraProps = extraProps;
|
1608
|
+
}
|
1609
|
+
queryMigrationRequests({
|
1610
|
+
workspace,
|
1611
|
+
region,
|
1612
|
+
database,
|
1613
|
+
filter,
|
1614
|
+
sort,
|
1615
|
+
page,
|
1616
|
+
columns
|
1617
|
+
}) {
|
1618
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
1619
|
+
pathParams: { workspace, region, dbName: database },
|
1620
|
+
body: { filter, sort, page, columns },
|
1621
|
+
...this.extraProps
|
1622
|
+
});
|
1623
|
+
}
|
1624
|
+
createMigrationRequest({
|
1625
|
+
workspace,
|
1626
|
+
region,
|
1627
|
+
database,
|
1628
|
+
migration
|
1629
|
+
}) {
|
1630
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1631
|
+
pathParams: { workspace, region, dbName: database },
|
1632
|
+
body: migration,
|
1633
|
+
...this.extraProps
|
1634
|
+
});
|
1635
|
+
}
|
1636
|
+
getMigrationRequest({
|
1637
|
+
workspace,
|
1638
|
+
region,
|
1639
|
+
database,
|
1640
|
+
migrationRequest
|
1641
|
+
}) {
|
1642
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1643
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1644
|
+
...this.extraProps
|
1645
|
+
});
|
1646
|
+
}
|
1647
|
+
updateMigrationRequest({
|
1648
|
+
workspace,
|
1649
|
+
region,
|
1650
|
+
database,
|
1651
|
+
migrationRequest,
|
1652
|
+
update
|
1653
|
+
}) {
|
1654
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1655
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1656
|
+
body: update,
|
1657
|
+
...this.extraProps
|
1658
|
+
});
|
1659
|
+
}
|
1660
|
+
listMigrationRequestsCommits({
|
1661
|
+
workspace,
|
1662
|
+
region,
|
1663
|
+
database,
|
1664
|
+
migrationRequest,
|
1665
|
+
page
|
1666
|
+
}) {
|
1667
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1668
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1669
|
+
body: { page },
|
837
1670
|
...this.extraProps
|
838
1671
|
});
|
839
1672
|
}
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
1673
|
+
compareMigrationRequest({
|
1674
|
+
workspace,
|
1675
|
+
region,
|
1676
|
+
database,
|
1677
|
+
migrationRequest
|
1678
|
+
}) {
|
1679
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1680
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
844
1681
|
...this.extraProps
|
845
1682
|
});
|
846
1683
|
}
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
1684
|
+
getMigrationRequestIsMerged({
|
1685
|
+
workspace,
|
1686
|
+
region,
|
1687
|
+
database,
|
1688
|
+
migrationRequest
|
1689
|
+
}) {
|
1690
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1691
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
851
1692
|
...this.extraProps
|
852
1693
|
});
|
853
1694
|
}
|
854
|
-
|
855
|
-
|
856
|
-
|
1695
|
+
mergeMigrationRequest({
|
1696
|
+
workspace,
|
1697
|
+
region,
|
1698
|
+
database,
|
1699
|
+
migrationRequest
|
1700
|
+
}) {
|
1701
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1702
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
857
1703
|
...this.extraProps
|
858
1704
|
});
|
859
1705
|
}
|
860
1706
|
}
|
861
|
-
class
|
1707
|
+
class MigrationsApi {
|
862
1708
|
constructor(extraProps) {
|
863
1709
|
this.extraProps = extraProps;
|
864
1710
|
}
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
1711
|
+
getBranchMigrationHistory({
|
1712
|
+
workspace,
|
1713
|
+
region,
|
1714
|
+
database,
|
1715
|
+
branch,
|
1716
|
+
limit,
|
1717
|
+
startFrom
|
1718
|
+
}) {
|
1719
|
+
return operationsByTag.migrations.getBranchMigrationHistory({
|
1720
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1721
|
+
body: { limit, startFrom },
|
874
1722
|
...this.extraProps
|
875
1723
|
});
|
876
1724
|
}
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
1725
|
+
getBranchMigrationPlan({
|
1726
|
+
workspace,
|
1727
|
+
region,
|
1728
|
+
database,
|
1729
|
+
branch,
|
1730
|
+
schema
|
1731
|
+
}) {
|
1732
|
+
return operationsByTag.migrations.getBranchMigrationPlan({
|
1733
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1734
|
+
body: schema,
|
881
1735
|
...this.extraProps
|
882
1736
|
});
|
883
1737
|
}
|
884
|
-
|
885
|
-
|
886
|
-
|
1738
|
+
executeBranchMigrationPlan({
|
1739
|
+
workspace,
|
1740
|
+
region,
|
1741
|
+
database,
|
1742
|
+
branch,
|
1743
|
+
plan
|
1744
|
+
}) {
|
1745
|
+
return operationsByTag.migrations.executeBranchMigrationPlan({
|
1746
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1747
|
+
body: plan,
|
887
1748
|
...this.extraProps
|
888
1749
|
});
|
889
1750
|
}
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
1751
|
+
getBranchSchemaHistory({
|
1752
|
+
workspace,
|
1753
|
+
region,
|
1754
|
+
database,
|
1755
|
+
branch,
|
1756
|
+
page
|
1757
|
+
}) {
|
1758
|
+
return operationsByTag.migrations.getBranchSchemaHistory({
|
1759
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1760
|
+
body: { page },
|
894
1761
|
...this.extraProps
|
895
1762
|
});
|
896
1763
|
}
|
897
|
-
|
898
|
-
|
899
|
-
|
1764
|
+
compareBranchWithUserSchema({
|
1765
|
+
workspace,
|
1766
|
+
region,
|
1767
|
+
database,
|
1768
|
+
branch,
|
1769
|
+
schema
|
1770
|
+
}) {
|
1771
|
+
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1772
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1773
|
+
body: { schema },
|
900
1774
|
...this.extraProps
|
901
1775
|
});
|
902
1776
|
}
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
1777
|
+
compareBranchSchemas({
|
1778
|
+
workspace,
|
1779
|
+
region,
|
1780
|
+
database,
|
1781
|
+
branch,
|
1782
|
+
compare,
|
1783
|
+
schema
|
1784
|
+
}) {
|
1785
|
+
return operationsByTag.migrations.compareBranchSchemas({
|
1786
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1787
|
+
body: { schema },
|
907
1788
|
...this.extraProps
|
908
1789
|
});
|
909
1790
|
}
|
910
|
-
|
911
|
-
|
912
|
-
|
1791
|
+
updateBranchSchema({
|
1792
|
+
workspace,
|
1793
|
+
region,
|
1794
|
+
database,
|
1795
|
+
branch,
|
1796
|
+
migration
|
1797
|
+
}) {
|
1798
|
+
return operationsByTag.migrations.updateBranchSchema({
|
1799
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1800
|
+
body: migration,
|
913
1801
|
...this.extraProps
|
914
1802
|
});
|
915
1803
|
}
|
916
|
-
|
917
|
-
|
918
|
-
|
1804
|
+
previewBranchSchemaEdit({
|
1805
|
+
workspace,
|
1806
|
+
region,
|
1807
|
+
database,
|
1808
|
+
branch,
|
1809
|
+
data
|
1810
|
+
}) {
|
1811
|
+
return operationsByTag.migrations.previewBranchSchemaEdit({
|
1812
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1813
|
+
body: data,
|
919
1814
|
...this.extraProps
|
920
1815
|
});
|
921
1816
|
}
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
1817
|
+
applyBranchSchemaEdit({
|
1818
|
+
workspace,
|
1819
|
+
region,
|
1820
|
+
database,
|
1821
|
+
branch,
|
1822
|
+
edits
|
1823
|
+
}) {
|
1824
|
+
return operationsByTag.migrations.applyBranchSchemaEdit({
|
1825
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1826
|
+
body: { edits },
|
926
1827
|
...this.extraProps
|
927
1828
|
});
|
928
1829
|
}
|
929
1830
|
}
|
930
|
-
class
|
1831
|
+
class DatabaseApi {
|
931
1832
|
constructor(extraProps) {
|
932
1833
|
this.extraProps = extraProps;
|
933
1834
|
}
|
934
|
-
|
935
|
-
return operationsByTag.
|
936
|
-
pathParams: {
|
937
|
-
queryParams: options,
|
938
|
-
body: record,
|
939
|
-
...this.extraProps
|
940
|
-
});
|
941
|
-
}
|
942
|
-
insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
943
|
-
return operationsByTag.records.insertRecordWithID({
|
944
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
945
|
-
queryParams: options,
|
946
|
-
body: record,
|
947
|
-
...this.extraProps
|
948
|
-
});
|
949
|
-
}
|
950
|
-
updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
951
|
-
return operationsByTag.records.updateRecordWithID({
|
952
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
953
|
-
queryParams: options,
|
954
|
-
body: record,
|
955
|
-
...this.extraProps
|
956
|
-
});
|
957
|
-
}
|
958
|
-
upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
959
|
-
return operationsByTag.records.upsertRecordWithID({
|
960
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
961
|
-
queryParams: options,
|
962
|
-
body: record,
|
963
|
-
...this.extraProps
|
964
|
-
});
|
965
|
-
}
|
966
|
-
deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
|
967
|
-
return operationsByTag.records.deleteRecord({
|
968
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
969
|
-
queryParams: options,
|
1835
|
+
getDatabaseList({ workspace }) {
|
1836
|
+
return operationsByTag.databases.getDatabaseList({
|
1837
|
+
pathParams: { workspaceId: workspace },
|
970
1838
|
...this.extraProps
|
971
1839
|
});
|
972
1840
|
}
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
1841
|
+
createDatabase({
|
1842
|
+
workspace,
|
1843
|
+
database,
|
1844
|
+
data
|
1845
|
+
}) {
|
1846
|
+
return operationsByTag.databases.createDatabase({
|
1847
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1848
|
+
body: data,
|
977
1849
|
...this.extraProps
|
978
1850
|
});
|
979
1851
|
}
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
1852
|
+
deleteDatabase({
|
1853
|
+
workspace,
|
1854
|
+
database
|
1855
|
+
}) {
|
1856
|
+
return operationsByTag.databases.deleteDatabase({
|
1857
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
985
1858
|
...this.extraProps
|
986
1859
|
});
|
987
1860
|
}
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
1861
|
+
getDatabaseMetadata({
|
1862
|
+
workspace,
|
1863
|
+
database
|
1864
|
+
}) {
|
1865
|
+
return operationsByTag.databases.getDatabaseMetadata({
|
1866
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
992
1867
|
...this.extraProps
|
993
1868
|
});
|
994
1869
|
}
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
1870
|
+
updateDatabaseMetadata({
|
1871
|
+
workspace,
|
1872
|
+
database,
|
1873
|
+
metadata
|
1874
|
+
}) {
|
1875
|
+
return operationsByTag.databases.updateDatabaseMetadata({
|
1876
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1877
|
+
body: metadata,
|
999
1878
|
...this.extraProps
|
1000
1879
|
});
|
1001
1880
|
}
|
1002
|
-
|
1003
|
-
return operationsByTag.
|
1004
|
-
pathParams: {
|
1005
|
-
body: query,
|
1881
|
+
listRegions({ workspace }) {
|
1882
|
+
return operationsByTag.databases.listRegions({
|
1883
|
+
pathParams: { workspaceId: workspace },
|
1006
1884
|
...this.extraProps
|
1007
1885
|
});
|
1008
1886
|
}
|
@@ -1018,6 +1896,20 @@ class XataApiPlugin {
|
|
1018
1896
|
class XataPlugin {
|
1019
1897
|
}
|
1020
1898
|
|
1899
|
+
function generateUUID() {
|
1900
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1901
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1902
|
+
return v.toString(16);
|
1903
|
+
});
|
1904
|
+
}
|
1905
|
+
|
1906
|
+
function cleanFilter(filter) {
|
1907
|
+
if (!filter)
|
1908
|
+
return void 0;
|
1909
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
1910
|
+
return values.length > 0 ? filter : void 0;
|
1911
|
+
}
|
1912
|
+
|
1021
1913
|
var __accessCheck$6 = (obj, member, msg) => {
|
1022
1914
|
if (!member.has(obj))
|
1023
1915
|
throw TypeError("Cannot " + msg);
|
@@ -1050,11 +1942,11 @@ class Page {
|
|
1050
1942
|
async previousPage(size, offset) {
|
1051
1943
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1052
1944
|
}
|
1053
|
-
async
|
1054
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
1945
|
+
async startPage(size, offset) {
|
1946
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1055
1947
|
}
|
1056
|
-
async
|
1057
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
1948
|
+
async endPage(size, offset) {
|
1949
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1058
1950
|
}
|
1059
1951
|
hasNextPage() {
|
1060
1952
|
return this.meta.page.more;
|
@@ -1066,7 +1958,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
|
|
1066
1958
|
const PAGINATION_MAX_OFFSET = 800;
|
1067
1959
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1068
1960
|
function isCursorPaginationOptions(options) {
|
1069
|
-
return isDefined(options) && (isDefined(options.
|
1961
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1070
1962
|
}
|
1071
1963
|
const _RecordArray = class extends Array {
|
1072
1964
|
constructor(...args) {
|
@@ -1098,12 +1990,12 @@ const _RecordArray = class extends Array {
|
|
1098
1990
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1099
1991
|
return new _RecordArray(newPage);
|
1100
1992
|
}
|
1101
|
-
async
|
1102
|
-
const newPage = await __privateGet$6(this, _page).
|
1993
|
+
async startPage(size, offset) {
|
1994
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1103
1995
|
return new _RecordArray(newPage);
|
1104
1996
|
}
|
1105
|
-
async
|
1106
|
-
const newPage = await __privateGet$6(this, _page).
|
1997
|
+
async endPage(size, offset) {
|
1998
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1107
1999
|
return new _RecordArray(newPage);
|
1108
2000
|
}
|
1109
2001
|
hasNextPage() {
|
@@ -1131,9 +2023,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1131
2023
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1132
2024
|
return value;
|
1133
2025
|
};
|
1134
|
-
var
|
2026
|
+
var __privateMethod$3 = (obj, member, method) => {
|
2027
|
+
__accessCheck$5(obj, member, "access private method");
|
2028
|
+
return method;
|
2029
|
+
};
|
2030
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1135
2031
|
const _Query = class {
|
1136
2032
|
constructor(repository, table, data, rawParent) {
|
2033
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1137
2034
|
__privateAdd$5(this, _table$1, void 0);
|
1138
2035
|
__privateAdd$5(this, _repository, void 0);
|
1139
2036
|
__privateAdd$5(this, _data, { filter: {} });
|
@@ -1152,9 +2049,10 @@ const _Query = class {
|
|
1152
2049
|
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1153
2050
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1154
2051
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1155
|
-
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns
|
2052
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
1156
2053
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1157
2054
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2055
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1158
2056
|
this.any = this.any.bind(this);
|
1159
2057
|
this.all = this.all.bind(this);
|
1160
2058
|
this.not = this.not.bind(this);
|
@@ -1190,21 +2088,29 @@ const _Query = class {
|
|
1190
2088
|
}
|
1191
2089
|
filter(a, b) {
|
1192
2090
|
if (arguments.length === 1) {
|
1193
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
2091
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
2092
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
2093
|
+
}));
|
1194
2094
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1195
2095
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1196
2096
|
} else {
|
1197
|
-
const
|
2097
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
2098
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1198
2099
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1199
2100
|
}
|
1200
2101
|
}
|
1201
|
-
sort(column, direction) {
|
2102
|
+
sort(column, direction = "asc") {
|
1202
2103
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1203
2104
|
const sort = [...originalSort, { column, direction }];
|
1204
2105
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1205
2106
|
}
|
1206
2107
|
select(columns) {
|
1207
|
-
return new _Query(
|
2108
|
+
return new _Query(
|
2109
|
+
__privateGet$5(this, _repository),
|
2110
|
+
__privateGet$5(this, _table$1),
|
2111
|
+
{ columns },
|
2112
|
+
__privateGet$5(this, _data)
|
2113
|
+
);
|
1208
2114
|
}
|
1209
2115
|
getPaginated(options = {}) {
|
1210
2116
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1227,11 +2133,20 @@ const _Query = class {
|
|
1227
2133
|
}
|
1228
2134
|
}
|
1229
2135
|
async getMany(options = {}) {
|
1230
|
-
const
|
2136
|
+
const { pagination = {}, ...rest } = options;
|
2137
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
2138
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
2139
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
2140
|
+
const results = [...page.records];
|
2141
|
+
while (page.hasNextPage() && results.length < size) {
|
2142
|
+
page = await page.nextPage();
|
2143
|
+
results.push(...page.records);
|
2144
|
+
}
|
1231
2145
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1232
2146
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1233
2147
|
}
|
1234
|
-
|
2148
|
+
const array = new RecordArray(page, results.slice(0, size));
|
2149
|
+
return array;
|
1235
2150
|
}
|
1236
2151
|
async getAll(options = {}) {
|
1237
2152
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1245,19 +2160,35 @@ const _Query = class {
|
|
1245
2160
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1246
2161
|
return records[0] ?? null;
|
1247
2162
|
}
|
2163
|
+
async getFirstOrThrow(options = {}) {
|
2164
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
2165
|
+
if (records[0] === void 0)
|
2166
|
+
throw new Error("No results found.");
|
2167
|
+
return records[0];
|
2168
|
+
}
|
2169
|
+
async summarize(params = {}) {
|
2170
|
+
const { summaries, summariesFilter, ...options } = params;
|
2171
|
+
const query = new _Query(
|
2172
|
+
__privateGet$5(this, _repository),
|
2173
|
+
__privateGet$5(this, _table$1),
|
2174
|
+
options,
|
2175
|
+
__privateGet$5(this, _data)
|
2176
|
+
);
|
2177
|
+
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2178
|
+
}
|
1248
2179
|
cache(ttl) {
|
1249
2180
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1250
2181
|
}
|
1251
2182
|
nextPage(size, offset) {
|
1252
|
-
return this.
|
2183
|
+
return this.startPage(size, offset);
|
1253
2184
|
}
|
1254
2185
|
previousPage(size, offset) {
|
1255
|
-
return this.
|
2186
|
+
return this.startPage(size, offset);
|
1256
2187
|
}
|
1257
|
-
|
2188
|
+
startPage(size, offset) {
|
1258
2189
|
return this.getPaginated({ pagination: { size, offset } });
|
1259
2190
|
}
|
1260
|
-
|
2191
|
+
endPage(size, offset) {
|
1261
2192
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
1262
2193
|
}
|
1263
2194
|
hasNextPage() {
|
@@ -1268,9 +2199,20 @@ let Query = _Query;
|
|
1268
2199
|
_table$1 = new WeakMap();
|
1269
2200
|
_repository = new WeakMap();
|
1270
2201
|
_data = new WeakMap();
|
2202
|
+
_cleanFilterConstraint = new WeakSet();
|
2203
|
+
cleanFilterConstraint_fn = function(column, value) {
|
2204
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
2205
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
2206
|
+
return { $includes: value };
|
2207
|
+
}
|
2208
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
2209
|
+
return value.id;
|
2210
|
+
}
|
2211
|
+
return value;
|
2212
|
+
};
|
1271
2213
|
function cleanParent(data, parent) {
|
1272
2214
|
if (isCursorPaginationOptions(data.pagination)) {
|
1273
|
-
return { ...parent,
|
2215
|
+
return { ...parent, sort: void 0, filter: void 0 };
|
1274
2216
|
}
|
1275
2217
|
return parent;
|
1276
2218
|
}
|
@@ -1329,193 +2271,383 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1329
2271
|
__accessCheck$4(obj, member, "access private method");
|
1330
2272
|
return method;
|
1331
2273
|
};
|
1332
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2274
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
2275
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
1333
2276
|
class Repository extends Query {
|
1334
2277
|
}
|
1335
2278
|
class RestRepository extends Query {
|
1336
2279
|
constructor(options) {
|
1337
|
-
super(
|
2280
|
+
super(
|
2281
|
+
null,
|
2282
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
2283
|
+
{}
|
2284
|
+
);
|
1338
2285
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1339
2286
|
__privateAdd$4(this, _insertRecordWithId);
|
1340
|
-
__privateAdd$4(this,
|
2287
|
+
__privateAdd$4(this, _insertRecords);
|
1341
2288
|
__privateAdd$4(this, _updateRecordWithID);
|
2289
|
+
__privateAdd$4(this, _updateRecords);
|
1342
2290
|
__privateAdd$4(this, _upsertRecordWithID);
|
1343
2291
|
__privateAdd$4(this, _deleteRecord);
|
2292
|
+
__privateAdd$4(this, _deleteRecords);
|
1344
2293
|
__privateAdd$4(this, _setCacheQuery);
|
1345
2294
|
__privateAdd$4(this, _getCacheQuery);
|
1346
2295
|
__privateAdd$4(this, _getSchemaTables$1);
|
1347
2296
|
__privateAdd$4(this, _table, void 0);
|
1348
2297
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2298
|
+
__privateAdd$4(this, _db, void 0);
|
1349
2299
|
__privateAdd$4(this, _cache, void 0);
|
1350
2300
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
2301
|
+
__privateAdd$4(this, _trace, void 0);
|
1351
2302
|
__privateSet$4(this, _table, options.table);
|
1352
|
-
__privateSet$4(this,
|
1353
|
-
this.db = options.db;
|
2303
|
+
__privateSet$4(this, _db, options.db);
|
1354
2304
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1355
2305
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2306
|
+
__privateSet$4(this, _getFetchProps, async () => {
|
2307
|
+
const props = await options.pluginOptions.getFetchProps();
|
2308
|
+
return { ...props, sessionID: generateUUID() };
|
2309
|
+
});
|
2310
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2311
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2312
|
+
return trace(name, fn, {
|
2313
|
+
...options2,
|
2314
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
2315
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
2316
|
+
[TraceAttributes.VERSION]: VERSION
|
2317
|
+
});
|
2318
|
+
});
|
1356
2319
|
}
|
1357
|
-
async create(a, b, c) {
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
2320
|
+
async create(a, b, c, d) {
|
2321
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
2322
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2323
|
+
if (Array.isArray(a)) {
|
2324
|
+
if (a.length === 0)
|
2325
|
+
return [];
|
2326
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2327
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2328
|
+
const result = await this.read(ids, columns);
|
2329
|
+
return result;
|
2330
|
+
}
|
2331
|
+
if (isString(a) && isObject(b)) {
|
2332
|
+
if (a === "")
|
2333
|
+
throw new Error("The id can't be empty");
|
2334
|
+
const columns = isStringArray(c) ? c : void 0;
|
2335
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2336
|
+
}
|
2337
|
+
if (isObject(a) && isString(a.id)) {
|
2338
|
+
if (a.id === "")
|
2339
|
+
throw new Error("The id can't be empty");
|
2340
|
+
const columns = isStringArray(b) ? b : void 0;
|
2341
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2342
|
+
}
|
2343
|
+
if (isObject(a)) {
|
2344
|
+
const columns = isStringArray(b) ? b : void 0;
|
2345
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2346
|
+
}
|
2347
|
+
throw new Error("Invalid arguments for create method");
|
2348
|
+
});
|
1381
2349
|
}
|
1382
2350
|
async read(a, b) {
|
1383
|
-
|
1384
|
-
|
1385
|
-
if (a
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
acc
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
2351
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2352
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2353
|
+
if (Array.isArray(a)) {
|
2354
|
+
if (a.length === 0)
|
2355
|
+
return [];
|
2356
|
+
const ids = a.map((item) => extractId(item));
|
2357
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
2358
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
2359
|
+
acc[object.id] = object;
|
2360
|
+
return acc;
|
2361
|
+
}, {});
|
2362
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
2363
|
+
}
|
2364
|
+
const id = extractId(a);
|
2365
|
+
if (id) {
|
2366
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2367
|
+
try {
|
2368
|
+
const response = await getRecord({
|
2369
|
+
pathParams: {
|
2370
|
+
workspace: "{workspaceId}",
|
2371
|
+
dbBranchName: "{dbBranch}",
|
2372
|
+
region: "{region}",
|
2373
|
+
tableName: __privateGet$4(this, _table),
|
2374
|
+
recordId: id
|
2375
|
+
},
|
2376
|
+
queryParams: { columns },
|
2377
|
+
...fetchProps
|
2378
|
+
});
|
2379
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2380
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2381
|
+
} catch (e) {
|
2382
|
+
if (isObject(e) && e.status === 404) {
|
2383
|
+
return null;
|
2384
|
+
}
|
2385
|
+
throw e;
|
2386
|
+
}
|
2387
|
+
}
|
2388
|
+
return null;
|
2389
|
+
});
|
2390
|
+
}
|
2391
|
+
async readOrThrow(a, b) {
|
2392
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
2393
|
+
const result = await this.read(a, b);
|
2394
|
+
if (Array.isArray(result)) {
|
2395
|
+
const missingIds = compact(
|
2396
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2397
|
+
);
|
2398
|
+
if (missingIds.length > 0) {
|
2399
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2400
|
+
}
|
2401
|
+
return result;
|
2402
|
+
}
|
2403
|
+
if (result === null) {
|
2404
|
+
const id = extractId(a) ?? "unknown";
|
2405
|
+
throw new Error(`Record with id ${id} not found`);
|
2406
|
+
}
|
2407
|
+
return result;
|
2408
|
+
});
|
2409
|
+
}
|
2410
|
+
async update(a, b, c, d) {
|
2411
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
2412
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2413
|
+
if (Array.isArray(a)) {
|
2414
|
+
if (a.length === 0)
|
2415
|
+
return [];
|
2416
|
+
const existing = await this.read(a, ["id"]);
|
2417
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
2418
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2419
|
+
ifVersion,
|
2420
|
+
upsert: false
|
1403
2421
|
});
|
1404
|
-
const
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
2422
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2423
|
+
const result = await this.read(a, columns);
|
2424
|
+
return result;
|
2425
|
+
}
|
2426
|
+
if (isString(a) && isObject(b)) {
|
2427
|
+
const columns = isStringArray(c) ? c : void 0;
|
2428
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2429
|
+
}
|
2430
|
+
if (isObject(a) && isString(a.id)) {
|
2431
|
+
const columns = isStringArray(b) ? b : void 0;
|
2432
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2433
|
+
}
|
2434
|
+
throw new Error("Invalid arguments for update method");
|
2435
|
+
});
|
2436
|
+
}
|
2437
|
+
async updateOrThrow(a, b, c, d) {
|
2438
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
2439
|
+
const result = await this.update(a, b, c, d);
|
2440
|
+
if (Array.isArray(result)) {
|
2441
|
+
const missingIds = compact(
|
2442
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2443
|
+
);
|
2444
|
+
if (missingIds.length > 0) {
|
2445
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1409
2446
|
}
|
1410
|
-
|
2447
|
+
return result;
|
1411
2448
|
}
|
1412
|
-
|
1413
|
-
|
2449
|
+
if (result === null) {
|
2450
|
+
const id = extractId(a) ?? "unknown";
|
2451
|
+
throw new Error(`Record with id ${id} not found`);
|
2452
|
+
}
|
2453
|
+
return result;
|
2454
|
+
});
|
1414
2455
|
}
|
1415
|
-
async
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
2456
|
+
async createOrUpdate(a, b, c, d) {
|
2457
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
2458
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2459
|
+
if (Array.isArray(a)) {
|
2460
|
+
if (a.length === 0)
|
2461
|
+
return [];
|
2462
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
2463
|
+
ifVersion,
|
2464
|
+
upsert: true
|
2465
|
+
});
|
2466
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2467
|
+
const result = await this.read(a, columns);
|
2468
|
+
return result;
|
1421
2469
|
}
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
if (isString(a) && isObject(b)) {
|
1426
|
-
const columns = isStringArray(c) ? c : void 0;
|
1427
|
-
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1428
|
-
}
|
1429
|
-
if (isObject(a) && isString(a.id)) {
|
1430
|
-
const columns = isStringArray(b) ? b : void 0;
|
1431
|
-
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1432
|
-
}
|
1433
|
-
throw new Error("Invalid arguments for update method");
|
1434
|
-
}
|
1435
|
-
async createOrUpdate(a, b, c) {
|
1436
|
-
if (Array.isArray(a)) {
|
1437
|
-
if (a.length === 0)
|
1438
|
-
return [];
|
1439
|
-
if (a.length > 100) {
|
1440
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
2470
|
+
if (isString(a) && isObject(b)) {
|
2471
|
+
const columns = isStringArray(c) ? c : void 0;
|
2472
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
1441
2473
|
}
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
if (isString(a) && isObject(b)) {
|
1446
|
-
const columns = isStringArray(c) ? c : void 0;
|
1447
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1448
|
-
}
|
1449
|
-
if (isObject(a) && isString(a.id)) {
|
1450
|
-
const columns = isStringArray(c) ? c : void 0;
|
1451
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1452
|
-
}
|
1453
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1454
|
-
}
|
1455
|
-
async delete(a) {
|
1456
|
-
if (Array.isArray(a)) {
|
1457
|
-
if (a.length === 0)
|
1458
|
-
return;
|
1459
|
-
if (a.length > 100) {
|
1460
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
2474
|
+
if (isObject(a) && isString(a.id)) {
|
2475
|
+
const columns = isStringArray(c) ? c : void 0;
|
2476
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
1461
2477
|
}
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
2478
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
2479
|
+
});
|
2480
|
+
}
|
2481
|
+
async createOrReplace(a, b, c, d) {
|
2482
|
+
return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
|
2483
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2484
|
+
if (Array.isArray(a)) {
|
2485
|
+
if (a.length === 0)
|
2486
|
+
return [];
|
2487
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2488
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2489
|
+
const result = await this.read(ids, columns);
|
2490
|
+
return result;
|
2491
|
+
}
|
2492
|
+
if (isString(a) && isObject(b)) {
|
2493
|
+
const columns = isStringArray(c) ? c : void 0;
|
2494
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2495
|
+
}
|
2496
|
+
if (isObject(a) && isString(a.id)) {
|
2497
|
+
const columns = isStringArray(c) ? c : void 0;
|
2498
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
2499
|
+
}
|
2500
|
+
throw new Error("Invalid arguments for createOrReplace method");
|
2501
|
+
});
|
2502
|
+
}
|
2503
|
+
async delete(a, b) {
|
2504
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
2505
|
+
if (Array.isArray(a)) {
|
2506
|
+
if (a.length === 0)
|
2507
|
+
return [];
|
2508
|
+
const ids = a.map((o) => {
|
2509
|
+
if (isString(o))
|
2510
|
+
return o;
|
2511
|
+
if (isString(o.id))
|
2512
|
+
return o.id;
|
2513
|
+
throw new Error("Invalid arguments for delete method");
|
2514
|
+
});
|
2515
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2516
|
+
const result = await this.read(a, columns);
|
2517
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2518
|
+
return result;
|
2519
|
+
}
|
2520
|
+
if (isString(a)) {
|
2521
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
2522
|
+
}
|
2523
|
+
if (isObject(a) && isString(a.id)) {
|
2524
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
2525
|
+
}
|
2526
|
+
throw new Error("Invalid arguments for delete method");
|
2527
|
+
});
|
2528
|
+
}
|
2529
|
+
async deleteOrThrow(a, b) {
|
2530
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
2531
|
+
const result = await this.delete(a, b);
|
2532
|
+
if (Array.isArray(result)) {
|
2533
|
+
const missingIds = compact(
|
2534
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2535
|
+
);
|
2536
|
+
if (missingIds.length > 0) {
|
2537
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2538
|
+
}
|
2539
|
+
return result;
|
2540
|
+
} else if (result === null) {
|
2541
|
+
const id = extractId(a) ?? "unknown";
|
2542
|
+
throw new Error(`Record with id ${id} not found`);
|
2543
|
+
}
|
2544
|
+
return result;
|
2545
|
+
});
|
1474
2546
|
}
|
1475
2547
|
async search(query, options = {}) {
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
2548
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2549
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2550
|
+
const { records } = await searchTable({
|
2551
|
+
pathParams: {
|
2552
|
+
workspace: "{workspaceId}",
|
2553
|
+
dbBranchName: "{dbBranch}",
|
2554
|
+
region: "{region}",
|
2555
|
+
tableName: __privateGet$4(this, _table)
|
2556
|
+
},
|
2557
|
+
body: {
|
2558
|
+
query,
|
2559
|
+
fuzziness: options.fuzziness,
|
2560
|
+
prefix: options.prefix,
|
2561
|
+
highlight: options.highlight,
|
2562
|
+
filter: options.filter,
|
2563
|
+
boosters: options.boosters,
|
2564
|
+
page: options.page,
|
2565
|
+
target: options.target
|
2566
|
+
},
|
2567
|
+
...fetchProps
|
2568
|
+
});
|
2569
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2570
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
2571
|
+
});
|
2572
|
+
}
|
2573
|
+
async aggregate(aggs, filter) {
|
2574
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2575
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2576
|
+
const result = await aggregateTable({
|
2577
|
+
pathParams: {
|
2578
|
+
workspace: "{workspaceId}",
|
2579
|
+
dbBranchName: "{dbBranch}",
|
2580
|
+
region: "{region}",
|
2581
|
+
tableName: __privateGet$4(this, _table)
|
2582
|
+
},
|
2583
|
+
body: { aggs, filter },
|
2584
|
+
...fetchProps
|
2585
|
+
});
|
2586
|
+
return result;
|
1488
2587
|
});
|
1489
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1490
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1491
2588
|
}
|
1492
2589
|
async query(query) {
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
2590
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
2591
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
2592
|
+
if (cacheQuery)
|
2593
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2594
|
+
const data = query.getQueryOptions();
|
2595
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2596
|
+
const { meta, records: objects } = await queryTable({
|
2597
|
+
pathParams: {
|
2598
|
+
workspace: "{workspaceId}",
|
2599
|
+
dbBranchName: "{dbBranch}",
|
2600
|
+
region: "{region}",
|
2601
|
+
tableName: __privateGet$4(this, _table)
|
2602
|
+
},
|
2603
|
+
body: {
|
2604
|
+
filter: cleanFilter(data.filter),
|
2605
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2606
|
+
page: data.pagination,
|
2607
|
+
columns: data.columns ?? ["*"]
|
2608
|
+
},
|
2609
|
+
fetchOptions: data.fetchOptions,
|
2610
|
+
...fetchProps
|
2611
|
+
});
|
2612
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2613
|
+
const records = objects.map(
|
2614
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
2615
|
+
);
|
2616
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2617
|
+
return new Page(query, meta, records);
|
2618
|
+
});
|
2619
|
+
}
|
2620
|
+
async summarizeTable(query, summaries, summariesFilter) {
|
2621
|
+
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2622
|
+
const data = query.getQueryOptions();
|
2623
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2624
|
+
const result = await summarizeTable({
|
2625
|
+
pathParams: {
|
2626
|
+
workspace: "{workspaceId}",
|
2627
|
+
dbBranchName: "{dbBranch}",
|
2628
|
+
region: "{region}",
|
2629
|
+
tableName: __privateGet$4(this, _table)
|
2630
|
+
},
|
2631
|
+
body: {
|
2632
|
+
filter: cleanFilter(data.filter),
|
2633
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2634
|
+
columns: data.columns,
|
2635
|
+
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2636
|
+
summaries,
|
2637
|
+
summariesFilter
|
2638
|
+
},
|
2639
|
+
...fetchProps
|
2640
|
+
});
|
2641
|
+
return result;
|
1508
2642
|
});
|
1509
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1510
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1511
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1512
|
-
return new Page(query, meta, records);
|
1513
2643
|
}
|
1514
2644
|
}
|
1515
2645
|
_table = new WeakMap();
|
1516
2646
|
_getFetchProps = new WeakMap();
|
2647
|
+
_db = new WeakMap();
|
1517
2648
|
_cache = new WeakMap();
|
1518
2649
|
_schemaTables$2 = new WeakMap();
|
2650
|
+
_trace = new WeakMap();
|
1519
2651
|
_insertRecordWithoutId = new WeakSet();
|
1520
2652
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1521
2653
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1524,6 +2656,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1524
2656
|
pathParams: {
|
1525
2657
|
workspace: "{workspaceId}",
|
1526
2658
|
dbBranchName: "{dbBranch}",
|
2659
|
+
region: "{region}",
|
1527
2660
|
tableName: __privateGet$4(this, _table)
|
1528
2661
|
},
|
1529
2662
|
queryParams: { columns },
|
@@ -1531,74 +2664,173 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1531
2664
|
...fetchProps
|
1532
2665
|
});
|
1533
2666
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1534
|
-
return initObject(this
|
2667
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1535
2668
|
};
|
1536
2669
|
_insertRecordWithId = new WeakSet();
|
1537
|
-
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
2670
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
1538
2671
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1539
2672
|
const record = transformObjectLinks(object);
|
1540
2673
|
const response = await insertRecordWithID({
|
1541
2674
|
pathParams: {
|
1542
2675
|
workspace: "{workspaceId}",
|
1543
2676
|
dbBranchName: "{dbBranch}",
|
2677
|
+
region: "{region}",
|
1544
2678
|
tableName: __privateGet$4(this, _table),
|
1545
2679
|
recordId
|
1546
2680
|
},
|
1547
2681
|
body: record,
|
1548
|
-
queryParams: { createOnly
|
2682
|
+
queryParams: { createOnly, columns, ifVersion },
|
1549
2683
|
...fetchProps
|
1550
2684
|
});
|
1551
2685
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1552
|
-
return initObject(this
|
2686
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1553
2687
|
};
|
1554
|
-
|
1555
|
-
|
2688
|
+
_insertRecords = new WeakSet();
|
2689
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
1556
2690
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1557
|
-
const
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
2691
|
+
const chunkedOperations = chunk(
|
2692
|
+
objects.map((object) => ({
|
2693
|
+
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
2694
|
+
})),
|
2695
|
+
BULK_OPERATION_MAX_SIZE
|
2696
|
+
);
|
2697
|
+
const ids = [];
|
2698
|
+
for (const operations of chunkedOperations) {
|
2699
|
+
const { results } = await branchTransaction({
|
2700
|
+
pathParams: {
|
2701
|
+
workspace: "{workspaceId}",
|
2702
|
+
dbBranchName: "{dbBranch}",
|
2703
|
+
region: "{region}"
|
2704
|
+
},
|
2705
|
+
body: { operations },
|
2706
|
+
...fetchProps
|
2707
|
+
});
|
2708
|
+
for (const result of results) {
|
2709
|
+
if (result.operation === "insert") {
|
2710
|
+
ids.push(result.id);
|
2711
|
+
} else {
|
2712
|
+
ids.push(null);
|
2713
|
+
}
|
2714
|
+
}
|
1566
2715
|
}
|
1567
|
-
|
1568
|
-
return response.records?.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
2716
|
+
return ids;
|
1569
2717
|
};
|
1570
2718
|
_updateRecordWithID = new WeakSet();
|
1571
|
-
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
2719
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
1572
2720
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1573
|
-
const record = transformObjectLinks(object);
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
2721
|
+
const { id: _id, ...record } = transformObjectLinks(object);
|
2722
|
+
try {
|
2723
|
+
const response = await updateRecordWithID({
|
2724
|
+
pathParams: {
|
2725
|
+
workspace: "{workspaceId}",
|
2726
|
+
dbBranchName: "{dbBranch}",
|
2727
|
+
region: "{region}",
|
2728
|
+
tableName: __privateGet$4(this, _table),
|
2729
|
+
recordId
|
2730
|
+
},
|
2731
|
+
queryParams: { columns, ifVersion },
|
2732
|
+
body: record,
|
2733
|
+
...fetchProps
|
2734
|
+
});
|
2735
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2736
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2737
|
+
} catch (e) {
|
2738
|
+
if (isObject(e) && e.status === 404) {
|
2739
|
+
return null;
|
2740
|
+
}
|
2741
|
+
throw e;
|
2742
|
+
}
|
2743
|
+
};
|
2744
|
+
_updateRecords = new WeakSet();
|
2745
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2746
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2747
|
+
const chunkedOperations = chunk(
|
2748
|
+
objects.map(({ id, ...object }) => ({
|
2749
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
2750
|
+
})),
|
2751
|
+
BULK_OPERATION_MAX_SIZE
|
2752
|
+
);
|
2753
|
+
const ids = [];
|
2754
|
+
for (const operations of chunkedOperations) {
|
2755
|
+
const { results } = await branchTransaction({
|
2756
|
+
pathParams: {
|
2757
|
+
workspace: "{workspaceId}",
|
2758
|
+
dbBranchName: "{dbBranch}",
|
2759
|
+
region: "{region}"
|
2760
|
+
},
|
2761
|
+
body: { operations },
|
2762
|
+
...fetchProps
|
2763
|
+
});
|
2764
|
+
for (const result of results) {
|
2765
|
+
if (result.operation === "update") {
|
2766
|
+
ids.push(result.id);
|
2767
|
+
} else {
|
2768
|
+
ids.push(null);
|
2769
|
+
}
|
2770
|
+
}
|
2771
|
+
}
|
2772
|
+
return ids;
|
1582
2773
|
};
|
1583
2774
|
_upsertRecordWithID = new WeakSet();
|
1584
|
-
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
2775
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
1585
2776
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1586
2777
|
const response = await upsertRecordWithID({
|
1587
|
-
pathParams: {
|
1588
|
-
|
2778
|
+
pathParams: {
|
2779
|
+
workspace: "{workspaceId}",
|
2780
|
+
dbBranchName: "{dbBranch}",
|
2781
|
+
region: "{region}",
|
2782
|
+
tableName: __privateGet$4(this, _table),
|
2783
|
+
recordId
|
2784
|
+
},
|
2785
|
+
queryParams: { columns, ifVersion },
|
1589
2786
|
body: object,
|
1590
2787
|
...fetchProps
|
1591
2788
|
});
|
1592
2789
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1593
|
-
return initObject(this
|
2790
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1594
2791
|
};
|
1595
2792
|
_deleteRecord = new WeakSet();
|
1596
|
-
deleteRecord_fn = async function(recordId) {
|
2793
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1597
2794
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
2795
|
+
try {
|
2796
|
+
const response = await deleteRecord({
|
2797
|
+
pathParams: {
|
2798
|
+
workspace: "{workspaceId}",
|
2799
|
+
dbBranchName: "{dbBranch}",
|
2800
|
+
region: "{region}",
|
2801
|
+
tableName: __privateGet$4(this, _table),
|
2802
|
+
recordId
|
2803
|
+
},
|
2804
|
+
queryParams: { columns },
|
2805
|
+
...fetchProps
|
2806
|
+
});
|
2807
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2808
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2809
|
+
} catch (e) {
|
2810
|
+
if (isObject(e) && e.status === 404) {
|
2811
|
+
return null;
|
2812
|
+
}
|
2813
|
+
throw e;
|
2814
|
+
}
|
2815
|
+
};
|
2816
|
+
_deleteRecords = new WeakSet();
|
2817
|
+
deleteRecords_fn = async function(recordIds) {
|
2818
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2819
|
+
const chunkedOperations = chunk(
|
2820
|
+
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2821
|
+
BULK_OPERATION_MAX_SIZE
|
2822
|
+
);
|
2823
|
+
for (const operations of chunkedOperations) {
|
2824
|
+
await branchTransaction({
|
2825
|
+
pathParams: {
|
2826
|
+
workspace: "{workspaceId}",
|
2827
|
+
dbBranchName: "{dbBranch}",
|
2828
|
+
region: "{region}"
|
2829
|
+
},
|
2830
|
+
body: { operations },
|
2831
|
+
...fetchProps
|
2832
|
+
});
|
2833
|
+
}
|
1602
2834
|
};
|
1603
2835
|
_setCacheQuery = new WeakSet();
|
1604
2836
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1622,7 +2854,7 @@ getSchemaTables_fn$1 = async function() {
|
|
1622
2854
|
return __privateGet$4(this, _schemaTables$2);
|
1623
2855
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1624
2856
|
const { schema } = await getBranchDetails({
|
1625
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
2857
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
1626
2858
|
...fetchProps
|
1627
2859
|
});
|
1628
2860
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
@@ -1635,7 +2867,7 @@ const transformObjectLinks = (object) => {
|
|
1635
2867
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1636
2868
|
}, {});
|
1637
2869
|
};
|
1638
|
-
const initObject = (db, schemaTables, table, object) => {
|
2870
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
1639
2871
|
const result = {};
|
1640
2872
|
const { xata, ...rest } = object ?? {};
|
1641
2873
|
Object.assign(result, rest);
|
@@ -1643,13 +2875,15 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1643
2875
|
if (!columns)
|
1644
2876
|
console.error(`Table ${table} not found in schema`);
|
1645
2877
|
for (const column of columns ?? []) {
|
2878
|
+
if (!isValidColumn(selectedColumns, column))
|
2879
|
+
continue;
|
1646
2880
|
const value = result[column.name];
|
1647
2881
|
switch (column.type) {
|
1648
2882
|
case "datetime": {
|
1649
|
-
const date = value !== void 0 ? new Date(value) :
|
1650
|
-
if (date && isNaN(date.getTime())) {
|
2883
|
+
const date = value !== void 0 ? new Date(value) : null;
|
2884
|
+
if (date !== null && isNaN(date.getTime())) {
|
1651
2885
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1652
|
-
} else
|
2886
|
+
} else {
|
1653
2887
|
result[column.name] = date;
|
1654
2888
|
}
|
1655
2889
|
break;
|
@@ -1659,17 +2893,42 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1659
2893
|
if (!linkTable) {
|
1660
2894
|
console.error(`Failed to parse link for field ${column.name}`);
|
1661
2895
|
} else if (isObject(value)) {
|
1662
|
-
|
2896
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2897
|
+
if (item === column.name) {
|
2898
|
+
return [...acc, "*"];
|
2899
|
+
}
|
2900
|
+
if (item.startsWith(`${column.name}.`)) {
|
2901
|
+
const [, ...path] = item.split(".");
|
2902
|
+
return [...acc, path.join(".")];
|
2903
|
+
}
|
2904
|
+
return acc;
|
2905
|
+
}, []);
|
2906
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2907
|
+
} else {
|
2908
|
+
result[column.name] = null;
|
1663
2909
|
}
|
1664
2910
|
break;
|
1665
2911
|
}
|
2912
|
+
default:
|
2913
|
+
result[column.name] = value ?? null;
|
2914
|
+
if (column.notNull === true && value === null) {
|
2915
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2916
|
+
}
|
2917
|
+
break;
|
1666
2918
|
}
|
1667
2919
|
}
|
1668
2920
|
result.read = function(columns2) {
|
1669
2921
|
return db[table].read(result["id"], columns2);
|
1670
2922
|
};
|
1671
|
-
result.update = function(data,
|
1672
|
-
|
2923
|
+
result.update = function(data, b, c) {
|
2924
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
2925
|
+
const ifVersion = parseIfVersion(b, c);
|
2926
|
+
return db[table].update(result["id"], data, columns2, { ifVersion });
|
2927
|
+
};
|
2928
|
+
result.replace = function(data, b, c) {
|
2929
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
2930
|
+
const ifVersion = parseIfVersion(b, c);
|
2931
|
+
return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
|
1673
2932
|
};
|
1674
2933
|
result.delete = function() {
|
1675
2934
|
return db[table].delete(result["id"]);
|
@@ -1677,14 +2936,35 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1677
2936
|
result.getMetadata = function() {
|
1678
2937
|
return xata;
|
1679
2938
|
};
|
1680
|
-
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
2939
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
1681
2940
|
Object.defineProperty(result, prop, { enumerable: false });
|
1682
2941
|
}
|
1683
2942
|
Object.freeze(result);
|
1684
2943
|
return result;
|
1685
2944
|
};
|
1686
|
-
function
|
1687
|
-
|
2945
|
+
function extractId(value) {
|
2946
|
+
if (isString(value))
|
2947
|
+
return value;
|
2948
|
+
if (isObject(value) && isString(value.id))
|
2949
|
+
return value.id;
|
2950
|
+
return void 0;
|
2951
|
+
}
|
2952
|
+
function isValidColumn(columns, column) {
|
2953
|
+
if (columns.includes("*"))
|
2954
|
+
return true;
|
2955
|
+
if (column.type === "link") {
|
2956
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2957
|
+
return linkColumns.length > 0;
|
2958
|
+
}
|
2959
|
+
return columns.includes(column.name);
|
2960
|
+
}
|
2961
|
+
function parseIfVersion(...args) {
|
2962
|
+
for (const arg of args) {
|
2963
|
+
if (isObject(arg) && isNumber(arg.ifVersion)) {
|
2964
|
+
return arg.ifVersion;
|
2965
|
+
}
|
2966
|
+
}
|
2967
|
+
return void 0;
|
1688
2968
|
}
|
1689
2969
|
|
1690
2970
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1736,18 +3016,25 @@ class SimpleCache {
|
|
1736
3016
|
}
|
1737
3017
|
_map = new WeakMap();
|
1738
3018
|
|
1739
|
-
const
|
1740
|
-
const
|
1741
|
-
const
|
1742
|
-
const
|
1743
|
-
const
|
1744
|
-
const
|
3019
|
+
const greaterThan = (value) => ({ $gt: value });
|
3020
|
+
const gt = greaterThan;
|
3021
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
3022
|
+
const greaterEquals = greaterThanEquals;
|
3023
|
+
const gte = greaterThanEquals;
|
3024
|
+
const ge = greaterThanEquals;
|
3025
|
+
const lessThan = (value) => ({ $lt: value });
|
3026
|
+
const lt = lessThan;
|
3027
|
+
const lessThanEquals = (value) => ({ $le: value });
|
3028
|
+
const lessEquals = lessThanEquals;
|
3029
|
+
const lte = lessThanEquals;
|
3030
|
+
const le = lessThanEquals;
|
1745
3031
|
const exists = (column) => ({ $exists: column });
|
1746
3032
|
const notExists = (column) => ({ $notExists: column });
|
1747
3033
|
const startsWith = (value) => ({ $startsWith: value });
|
1748
3034
|
const endsWith = (value) => ({ $endsWith: value });
|
1749
3035
|
const pattern = (value) => ({ $pattern: value });
|
1750
3036
|
const is = (value) => ({ $is: value });
|
3037
|
+
const equals = is;
|
1751
3038
|
const isNot = (value) => ({ $isNot: value });
|
1752
3039
|
const contains = (value) => ({ $contains: value });
|
1753
3040
|
const includes = (value) => ({ $includes: value });
|
@@ -1782,16 +3069,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1782
3069
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1783
3070
|
}
|
1784
3071
|
build(pluginOptions) {
|
1785
|
-
const db = new Proxy(
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
3072
|
+
const db = new Proxy(
|
3073
|
+
{},
|
3074
|
+
{
|
3075
|
+
get: (_target, table) => {
|
3076
|
+
if (!isString(table))
|
3077
|
+
throw new Error("Invalid table name");
|
3078
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
3079
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
3080
|
+
}
|
3081
|
+
return __privateGet$2(this, _tables)[table];
|
1791
3082
|
}
|
1792
|
-
return __privateGet$2(this, _tables)[table];
|
1793
3083
|
}
|
1794
|
-
|
3084
|
+
);
|
1795
3085
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1796
3086
|
for (const table of tableNames) {
|
1797
3087
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1841,7 +3131,7 @@ class SearchPlugin extends XataPlugin {
|
|
1841
3131
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1842
3132
|
return records.map((record) => {
|
1843
3133
|
const { table = "orphan" } = record.xata;
|
1844
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
3134
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
1845
3135
|
});
|
1846
3136
|
},
|
1847
3137
|
byTable: async (query, options = {}) => {
|
@@ -1850,7 +3140,7 @@ class SearchPlugin extends XataPlugin {
|
|
1850
3140
|
return records.reduce((acc, record) => {
|
1851
3141
|
const { table = "orphan" } = record.xata;
|
1852
3142
|
const items = acc[table] ?? [];
|
1853
|
-
const item = initObject(this.db, schemaTables, table, record);
|
3143
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1854
3144
|
return { ...acc, [table]: [...items, item] };
|
1855
3145
|
}, {});
|
1856
3146
|
}
|
@@ -1861,10 +3151,10 @@ _schemaTables = new WeakMap();
|
|
1861
3151
|
_search = new WeakSet();
|
1862
3152
|
search_fn = async function(query, options, getFetchProps) {
|
1863
3153
|
const fetchProps = await getFetchProps();
|
1864
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
3154
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
1865
3155
|
const { records } = await searchBranch({
|
1866
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1867
|
-
body: { tables, query, fuzziness, prefix, highlight },
|
3156
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3157
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
1868
3158
|
...fetchProps
|
1869
3159
|
});
|
1870
3160
|
return records;
|
@@ -1875,13 +3165,29 @@ getSchemaTables_fn = async function(getFetchProps) {
|
|
1875
3165
|
return __privateGet$1(this, _schemaTables);
|
1876
3166
|
const fetchProps = await getFetchProps();
|
1877
3167
|
const { schema } = await getBranchDetails({
|
1878
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
3168
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
1879
3169
|
...fetchProps
|
1880
3170
|
});
|
1881
3171
|
__privateSet$1(this, _schemaTables, schema.tables);
|
1882
3172
|
return schema.tables;
|
1883
3173
|
};
|
1884
3174
|
|
3175
|
+
class TransactionPlugin extends XataPlugin {
|
3176
|
+
build({ getFetchProps }) {
|
3177
|
+
return {
|
3178
|
+
run: async (operations) => {
|
3179
|
+
const fetchProps = await getFetchProps();
|
3180
|
+
const response = await branchTransaction({
|
3181
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3182
|
+
body: { operations },
|
3183
|
+
...fetchProps
|
3184
|
+
});
|
3185
|
+
return response;
|
3186
|
+
}
|
3187
|
+
};
|
3188
|
+
}
|
3189
|
+
}
|
3190
|
+
|
1885
3191
|
const isBranchStrategyBuilder = (strategy) => {
|
1886
3192
|
return typeof strategy === "function";
|
1887
3193
|
};
|
@@ -1905,19 +3211,27 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1905
3211
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1906
3212
|
const apiKey = options?.apiKey || getAPIKey();
|
1907
3213
|
if (!databaseURL)
|
1908
|
-
throw new Error(
|
3214
|
+
throw new Error(
|
3215
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3216
|
+
);
|
1909
3217
|
if (!apiKey)
|
1910
|
-
throw new Error(
|
3218
|
+
throw new Error(
|
3219
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3220
|
+
);
|
1911
3221
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1912
|
-
const
|
3222
|
+
const urlParts = parseWorkspacesUrlParts(host);
|
3223
|
+
if (!urlParts)
|
3224
|
+
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3225
|
+
const { workspace, region } = urlParts;
|
1913
3226
|
const { fallbackBranch } = getEnvironment();
|
1914
3227
|
const { branch } = await resolveBranch({
|
1915
3228
|
apiKey,
|
1916
3229
|
apiUrl: databaseURL,
|
1917
3230
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1918
3231
|
workspacesApiUrl: `${protocol}//${host}`,
|
1919
|
-
pathParams: { dbName, workspace },
|
1920
|
-
queryParams: { gitBranch, fallbackBranch }
|
3232
|
+
pathParams: { dbName, workspace, region },
|
3233
|
+
queryParams: { gitBranch, fallbackBranch },
|
3234
|
+
trace: defaultTrace
|
1921
3235
|
});
|
1922
3236
|
return branch;
|
1923
3237
|
}
|
@@ -1925,19 +3239,26 @@ async function getDatabaseBranch(branch, options) {
|
|
1925
3239
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1926
3240
|
const apiKey = options?.apiKey || getAPIKey();
|
1927
3241
|
if (!databaseURL)
|
1928
|
-
throw new Error(
|
3242
|
+
throw new Error(
|
3243
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3244
|
+
);
|
1929
3245
|
if (!apiKey)
|
1930
|
-
throw new Error(
|
3246
|
+
throw new Error(
|
3247
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3248
|
+
);
|
1931
3249
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1932
|
-
const
|
1933
|
-
|
3250
|
+
const urlParts = parseWorkspacesUrlParts(host);
|
3251
|
+
if (!urlParts)
|
3252
|
+
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3253
|
+
const { workspace, region } = urlParts;
|
1934
3254
|
try {
|
1935
3255
|
return await getBranchDetails({
|
1936
3256
|
apiKey,
|
1937
3257
|
apiUrl: databaseURL,
|
1938
3258
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1939
3259
|
workspacesApiUrl: `${protocol}//${host}`,
|
1940
|
-
pathParams: { dbBranchName
|
3260
|
+
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3261
|
+
trace: defaultTrace
|
1941
3262
|
});
|
1942
3263
|
} catch (err) {
|
1943
3264
|
if (isObject(err) && err.status === 404)
|
@@ -1977,22 +3298,27 @@ var __privateMethod = (obj, member, method) => {
|
|
1977
3298
|
return method;
|
1978
3299
|
};
|
1979
3300
|
const buildClient = (plugins) => {
|
1980
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
3301
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
1981
3302
|
return _a = class {
|
1982
3303
|
constructor(options = {}, schemaTables) {
|
1983
3304
|
__privateAdd(this, _parseOptions);
|
1984
3305
|
__privateAdd(this, _getFetchProps);
|
1985
3306
|
__privateAdd(this, _evaluateBranch);
|
1986
3307
|
__privateAdd(this, _branch, void 0);
|
3308
|
+
__privateAdd(this, _options, void 0);
|
1987
3309
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3310
|
+
__privateSet(this, _options, safeOptions);
|
1988
3311
|
const pluginOptions = {
|
1989
3312
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
1990
|
-
cache: safeOptions.cache
|
3313
|
+
cache: safeOptions.cache,
|
3314
|
+
trace: safeOptions.trace
|
1991
3315
|
};
|
1992
3316
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
1993
3317
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3318
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
1994
3319
|
this.db = db;
|
1995
3320
|
this.search = search;
|
3321
|
+
this.transactions = transactions;
|
1996
3322
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
1997
3323
|
if (namespace === void 0)
|
1998
3324
|
continue;
|
@@ -2006,21 +3332,41 @@ const buildClient = (plugins) => {
|
|
2006
3332
|
}
|
2007
3333
|
}
|
2008
3334
|
}
|
2009
|
-
|
3335
|
+
async getConfig() {
|
3336
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
3337
|
+
const branch = await __privateGet(this, _options).branch();
|
3338
|
+
return { databaseURL, branch };
|
3339
|
+
}
|
3340
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3341
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3342
|
+
const isBrowser = typeof window !== "undefined";
|
3343
|
+
if (isBrowser && !enableBrowser) {
|
3344
|
+
throw new Error(
|
3345
|
+
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
3346
|
+
);
|
3347
|
+
}
|
2010
3348
|
const fetch = getFetchImplementation(options?.fetch);
|
2011
3349
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2012
3350
|
const apiKey = options?.apiKey || getAPIKey();
|
2013
3351
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3352
|
+
const trace = options?.trace ?? defaultTrace;
|
3353
|
+
const clientName = options?.clientName;
|
2014
3354
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2015
|
-
if (!
|
2016
|
-
throw new Error("
|
3355
|
+
if (!apiKey) {
|
3356
|
+
throw new Error("Option apiKey is required");
|
2017
3357
|
}
|
2018
|
-
|
3358
|
+
if (!databaseURL) {
|
3359
|
+
throw new Error("Option databaseURL is required");
|
3360
|
+
}
|
3361
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser, clientName };
|
2019
3362
|
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
2020
3363
|
fetch,
|
2021
3364
|
apiKey,
|
2022
3365
|
databaseURL,
|
2023
|
-
branch
|
3366
|
+
branch,
|
3367
|
+
trace,
|
3368
|
+
clientID,
|
3369
|
+
clientName
|
2024
3370
|
}) {
|
2025
3371
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2026
3372
|
if (!branchValue)
|
@@ -2031,9 +3377,12 @@ const buildClient = (plugins) => {
|
|
2031
3377
|
apiUrl: "",
|
2032
3378
|
workspacesApiUrl: (path, params) => {
|
2033
3379
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2034
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
3380
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2035
3381
|
return databaseURL + newPath;
|
2036
|
-
}
|
3382
|
+
},
|
3383
|
+
trace,
|
3384
|
+
clientID,
|
3385
|
+
clientName
|
2037
3386
|
};
|
2038
3387
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2039
3388
|
if (__privateGet(this, _branch))
|
@@ -2056,6 +3405,88 @@ const buildClient = (plugins) => {
|
|
2056
3405
|
class BaseClient extends buildClient() {
|
2057
3406
|
}
|
2058
3407
|
|
3408
|
+
const META = "__";
|
3409
|
+
const VALUE = "___";
|
3410
|
+
class Serializer {
|
3411
|
+
constructor() {
|
3412
|
+
this.classes = {};
|
3413
|
+
}
|
3414
|
+
add(clazz) {
|
3415
|
+
this.classes[clazz.name] = clazz;
|
3416
|
+
}
|
3417
|
+
toJSON(data) {
|
3418
|
+
function visit(obj) {
|
3419
|
+
if (Array.isArray(obj))
|
3420
|
+
return obj.map(visit);
|
3421
|
+
const type = typeof obj;
|
3422
|
+
if (type === "undefined")
|
3423
|
+
return { [META]: "undefined" };
|
3424
|
+
if (type === "bigint")
|
3425
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
3426
|
+
if (obj === null || type !== "object")
|
3427
|
+
return obj;
|
3428
|
+
const constructor = obj.constructor;
|
3429
|
+
const o = { [META]: constructor.name };
|
3430
|
+
for (const [key, value] of Object.entries(obj)) {
|
3431
|
+
o[key] = visit(value);
|
3432
|
+
}
|
3433
|
+
if (constructor === Date)
|
3434
|
+
o[VALUE] = obj.toISOString();
|
3435
|
+
if (constructor === Map)
|
3436
|
+
o[VALUE] = Object.fromEntries(obj);
|
3437
|
+
if (constructor === Set)
|
3438
|
+
o[VALUE] = [...obj];
|
3439
|
+
return o;
|
3440
|
+
}
|
3441
|
+
return JSON.stringify(visit(data));
|
3442
|
+
}
|
3443
|
+
fromJSON(json) {
|
3444
|
+
return JSON.parse(json, (key, value) => {
|
3445
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
3446
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
3447
|
+
const constructor = this.classes[clazz];
|
3448
|
+
if (constructor) {
|
3449
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
3450
|
+
}
|
3451
|
+
if (clazz === "Date")
|
3452
|
+
return new Date(val);
|
3453
|
+
if (clazz === "Set")
|
3454
|
+
return new Set(val);
|
3455
|
+
if (clazz === "Map")
|
3456
|
+
return new Map(Object.entries(val));
|
3457
|
+
if (clazz === "bigint")
|
3458
|
+
return BigInt(val);
|
3459
|
+
if (clazz === "undefined")
|
3460
|
+
return void 0;
|
3461
|
+
return rest;
|
3462
|
+
}
|
3463
|
+
return value;
|
3464
|
+
});
|
3465
|
+
}
|
3466
|
+
}
|
3467
|
+
const defaultSerializer = new Serializer();
|
3468
|
+
const serialize = (data) => {
|
3469
|
+
return defaultSerializer.toJSON(data);
|
3470
|
+
};
|
3471
|
+
const deserialize = (json) => {
|
3472
|
+
return defaultSerializer.fromJSON(json);
|
3473
|
+
};
|
3474
|
+
|
3475
|
+
function buildWorkerRunner(config) {
|
3476
|
+
return function xataWorker(name, _worker) {
|
3477
|
+
return async (...args) => {
|
3478
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3479
|
+
const result = await fetch(url, {
|
3480
|
+
method: "POST",
|
3481
|
+
headers: { "Content-Type": "application/json" },
|
3482
|
+
body: serialize({ args })
|
3483
|
+
});
|
3484
|
+
const text = await result.text();
|
3485
|
+
return deserialize(text);
|
3486
|
+
};
|
3487
|
+
};
|
3488
|
+
}
|
3489
|
+
|
2059
3490
|
class XataError extends Error {
|
2060
3491
|
constructor(message, status) {
|
2061
3492
|
super(message);
|
@@ -2076,6 +3507,7 @@ exports.Repository = Repository;
|
|
2076
3507
|
exports.RestRepository = RestRepository;
|
2077
3508
|
exports.SchemaPlugin = SchemaPlugin;
|
2078
3509
|
exports.SearchPlugin = SearchPlugin;
|
3510
|
+
exports.Serializer = Serializer;
|
2079
3511
|
exports.SimpleCache = SimpleCache;
|
2080
3512
|
exports.XataApiClient = XataApiClient;
|
2081
3513
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2084,15 +3516,28 @@ exports.XataPlugin = XataPlugin;
|
|
2084
3516
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
2085
3517
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2086
3518
|
exports.addTableColumn = addTableColumn;
|
3519
|
+
exports.aggregateTable = aggregateTable;
|
3520
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
3521
|
+
exports.branchTransaction = branchTransaction;
|
2087
3522
|
exports.buildClient = buildClient;
|
3523
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2088
3524
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2089
3525
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
3526
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
3527
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3528
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
2090
3529
|
exports.contains = contains;
|
2091
3530
|
exports.createBranch = createBranch;
|
2092
3531
|
exports.createDatabase = createDatabase;
|
3532
|
+
exports.createMigrationRequest = createMigrationRequest;
|
2093
3533
|
exports.createTable = createTable;
|
2094
3534
|
exports.createUserAPIKey = createUserAPIKey;
|
2095
3535
|
exports.createWorkspace = createWorkspace;
|
3536
|
+
exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
|
3537
|
+
exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
|
3538
|
+
exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
|
3539
|
+
exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
|
3540
|
+
exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
|
2096
3541
|
exports.deleteBranch = deleteBranch;
|
2097
3542
|
exports.deleteColumn = deleteColumn;
|
2098
3543
|
exports.deleteDatabase = deleteDatabase;
|
@@ -2101,7 +3546,9 @@ exports.deleteTable = deleteTable;
|
|
2101
3546
|
exports.deleteUser = deleteUser;
|
2102
3547
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2103
3548
|
exports.deleteWorkspace = deleteWorkspace;
|
3549
|
+
exports.deserialize = deserialize;
|
2104
3550
|
exports.endsWith = endsWith;
|
3551
|
+
exports.equals = equals;
|
2105
3552
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2106
3553
|
exports.exists = exists;
|
2107
3554
|
exports.ge = ge;
|
@@ -2111,13 +3558,18 @@ exports.getBranchList = getBranchList;
|
|
2111
3558
|
exports.getBranchMetadata = getBranchMetadata;
|
2112
3559
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
2113
3560
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
3561
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
2114
3562
|
exports.getBranchStats = getBranchStats;
|
2115
3563
|
exports.getColumn = getColumn;
|
2116
3564
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
2117
3565
|
exports.getCurrentBranchName = getCurrentBranchName;
|
2118
3566
|
exports.getDatabaseList = getDatabaseList;
|
3567
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2119
3568
|
exports.getDatabaseURL = getDatabaseURL;
|
2120
3569
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3570
|
+
exports.getHostUrl = getHostUrl;
|
3571
|
+
exports.getMigrationRequest = getMigrationRequest;
|
3572
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
2121
3573
|
exports.getRecord = getRecord;
|
2122
3574
|
exports.getTableColumns = getTableColumns;
|
2123
3575
|
exports.getTableSchema = getTableSchema;
|
@@ -2126,6 +3578,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2126
3578
|
exports.getWorkspace = getWorkspace;
|
2127
3579
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2128
3580
|
exports.getWorkspacesList = getWorkspacesList;
|
3581
|
+
exports.greaterEquals = greaterEquals;
|
3582
|
+
exports.greaterThan = greaterThan;
|
3583
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2129
3584
|
exports.gt = gt;
|
2130
3585
|
exports.gte = gte;
|
2131
3586
|
exports.includes = includes;
|
@@ -2137,15 +3592,27 @@ exports.insertRecordWithID = insertRecordWithID;
|
|
2137
3592
|
exports.inviteWorkspaceMember = inviteWorkspaceMember;
|
2138
3593
|
exports.is = is;
|
2139
3594
|
exports.isCursorPaginationOptions = isCursorPaginationOptions;
|
3595
|
+
exports.isHostProviderAlias = isHostProviderAlias;
|
3596
|
+
exports.isHostProviderBuilder = isHostProviderBuilder;
|
2140
3597
|
exports.isIdentifiable = isIdentifiable;
|
2141
3598
|
exports.isNot = isNot;
|
2142
3599
|
exports.isXataRecord = isXataRecord;
|
2143
3600
|
exports.le = le;
|
3601
|
+
exports.lessEquals = lessEquals;
|
3602
|
+
exports.lessThan = lessThan;
|
3603
|
+
exports.lessThanEquals = lessThanEquals;
|
3604
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
3605
|
+
exports.listRegions = listRegions;
|
2144
3606
|
exports.lt = lt;
|
2145
3607
|
exports.lte = lte;
|
3608
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
2146
3609
|
exports.notExists = notExists;
|
2147
3610
|
exports.operationsByTag = operationsByTag;
|
3611
|
+
exports.parseProviderString = parseProviderString;
|
3612
|
+
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
2148
3613
|
exports.pattern = pattern;
|
3614
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
3615
|
+
exports.queryMigrationRequests = queryMigrationRequests;
|
2149
3616
|
exports.queryTable = queryTable;
|
2150
3617
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
2151
3618
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
@@ -2153,10 +3620,15 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
2153
3620
|
exports.resolveBranch = resolveBranch;
|
2154
3621
|
exports.searchBranch = searchBranch;
|
2155
3622
|
exports.searchTable = searchTable;
|
3623
|
+
exports.serialize = serialize;
|
2156
3624
|
exports.setTableSchema = setTableSchema;
|
2157
3625
|
exports.startsWith = startsWith;
|
3626
|
+
exports.summarizeTable = summarizeTable;
|
2158
3627
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3628
|
+
exports.updateBranchSchema = updateBranchSchema;
|
2159
3629
|
exports.updateColumn = updateColumn;
|
3630
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3631
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
2160
3632
|
exports.updateRecordWithID = updateRecordWithID;
|
2161
3633
|
exports.updateTable = updateTable;
|
2162
3634
|
exports.updateUser = updateUser;
|