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