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