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