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