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