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