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