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