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