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