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