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