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