@xata.io/client 0.0.0-alpha.vfd68f4d → 0.0.0-alpha.vfd6ce53
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/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +241 -1
- package/dist/index.cjs +1621 -377
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2501 -435
- package/dist/index.mjs +1581 -375
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/.eslintrc.cjs +0 -13
- package/rollup.config.mjs +0 -44
- package/tsconfig.json +0 -23
package/dist/index.cjs
CHANGED
@@ -20,7 +20,8 @@ const TraceAttributes = {
|
|
20
20
|
HTTP_METHOD: "http.method",
|
21
21
|
HTTP_URL: "http.url",
|
22
22
|
HTTP_ROUTE: "http.route",
|
23
|
-
HTTP_TARGET: "http.target"
|
23
|
+
HTTP_TARGET: "http.target",
|
24
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
24
25
|
};
|
25
26
|
|
26
27
|
function notEmpty(value) {
|
@@ -29,8 +30,18 @@ function notEmpty(value) {
|
|
29
30
|
function compact(arr) {
|
30
31
|
return arr.filter(notEmpty);
|
31
32
|
}
|
33
|
+
function compactObject(obj) {
|
34
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
35
|
+
}
|
36
|
+
function isBlob(value) {
|
37
|
+
try {
|
38
|
+
return value instanceof Blob;
|
39
|
+
} catch (error) {
|
40
|
+
return false;
|
41
|
+
}
|
42
|
+
}
|
32
43
|
function isObject(value) {
|
33
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
44
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
34
45
|
}
|
35
46
|
function isDefined(value) {
|
36
47
|
return value !== null && value !== void 0;
|
@@ -85,6 +96,27 @@ function chunk(array, chunkSize) {
|
|
85
96
|
async function timeout(ms) {
|
86
97
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
87
98
|
}
|
99
|
+
function timeoutWithCancel(ms) {
|
100
|
+
let timeoutId;
|
101
|
+
const promise = new Promise((resolve) => {
|
102
|
+
timeoutId = setTimeout(() => {
|
103
|
+
resolve();
|
104
|
+
}, ms);
|
105
|
+
});
|
106
|
+
return {
|
107
|
+
cancel: () => clearTimeout(timeoutId),
|
108
|
+
promise
|
109
|
+
};
|
110
|
+
}
|
111
|
+
function promiseMap(inputValues, mapper) {
|
112
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
113
|
+
(acc) => mapper(inputValue).then((result) => {
|
114
|
+
acc.push(result);
|
115
|
+
return acc;
|
116
|
+
})
|
117
|
+
);
|
118
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
119
|
+
}
|
88
120
|
|
89
121
|
function getEnvironment() {
|
90
122
|
try {
|
@@ -93,8 +125,10 @@ function getEnvironment() {
|
|
93
125
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
94
126
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
95
127
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
96
|
-
|
97
|
-
|
128
|
+
deployPreview: process.env.XATA_PREVIEW,
|
129
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
130
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
131
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
98
132
|
};
|
99
133
|
}
|
100
134
|
} catch (err) {
|
@@ -105,8 +139,10 @@ function getEnvironment() {
|
|
105
139
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
106
140
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
107
141
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
108
|
-
|
109
|
-
|
142
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
143
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
144
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
145
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
110
146
|
};
|
111
147
|
}
|
112
148
|
} catch (err) {
|
@@ -115,8 +151,10 @@ function getEnvironment() {
|
|
115
151
|
apiKey: getGlobalApiKey(),
|
116
152
|
databaseURL: getGlobalDatabaseURL(),
|
117
153
|
branch: getGlobalBranch(),
|
118
|
-
|
119
|
-
|
154
|
+
deployPreview: void 0,
|
155
|
+
deployPreviewBranch: void 0,
|
156
|
+
vercelGitCommitRef: void 0,
|
157
|
+
vercelGitRepoOwner: void 0
|
120
158
|
};
|
121
159
|
}
|
122
160
|
function getEnableBrowserVariable() {
|
@@ -159,37 +197,48 @@ function getGlobalBranch() {
|
|
159
197
|
return void 0;
|
160
198
|
}
|
161
199
|
}
|
162
|
-
function
|
200
|
+
function getDatabaseURL() {
|
163
201
|
try {
|
164
|
-
|
202
|
+
const { databaseURL } = getEnvironment();
|
203
|
+
return databaseURL;
|
165
204
|
} catch (err) {
|
166
205
|
return void 0;
|
167
206
|
}
|
168
207
|
}
|
169
|
-
|
170
|
-
const cmd = ["git", "branch", "--show-current"];
|
171
|
-
const fullCmd = cmd.join(" ");
|
172
|
-
const nodeModule = ["child", "process"].join("_");
|
173
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
208
|
+
function getAPIKey() {
|
174
209
|
try {
|
175
|
-
|
176
|
-
|
177
|
-
}
|
210
|
+
const { apiKey } = getEnvironment();
|
211
|
+
return apiKey;
|
178
212
|
} catch (err) {
|
213
|
+
return void 0;
|
179
214
|
}
|
215
|
+
}
|
216
|
+
function getBranch() {
|
180
217
|
try {
|
181
|
-
|
182
|
-
|
183
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
184
|
-
}
|
218
|
+
const { branch } = getEnvironment();
|
219
|
+
return branch;
|
185
220
|
} catch (err) {
|
221
|
+
return void 0;
|
186
222
|
}
|
187
223
|
}
|
188
|
-
|
189
|
-
|
224
|
+
function buildPreviewBranchName({ org, branch }) {
|
225
|
+
return `preview-${org}-${branch}`;
|
226
|
+
}
|
227
|
+
function getPreviewBranch() {
|
190
228
|
try {
|
191
|
-
const {
|
192
|
-
|
229
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
230
|
+
if (deployPreviewBranch)
|
231
|
+
return deployPreviewBranch;
|
232
|
+
switch (deployPreview) {
|
233
|
+
case "vercel": {
|
234
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
235
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
236
|
+
return void 0;
|
237
|
+
}
|
238
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
239
|
+
}
|
240
|
+
}
|
241
|
+
return void 0;
|
193
242
|
} catch (err) {
|
194
243
|
return void 0;
|
195
244
|
}
|
@@ -218,13 +267,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
218
267
|
return method;
|
219
268
|
};
|
220
269
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
270
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
221
271
|
function getFetchImplementation(userFetch) {
|
222
272
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
223
|
-
const
|
273
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
274
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
224
275
|
if (!fetchImpl) {
|
225
|
-
throw new Error(
|
226
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
227
|
-
);
|
276
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
228
277
|
}
|
229
278
|
return fetchImpl;
|
230
279
|
}
|
@@ -249,18 +298,22 @@ class ApiRequestPool {
|
|
249
298
|
return __privateGet$8(this, _fetch);
|
250
299
|
}
|
251
300
|
request(url, options) {
|
252
|
-
const start = new Date();
|
253
|
-
const
|
301
|
+
const start = /* @__PURE__ */ new Date();
|
302
|
+
const fetchImpl = this.getFetch();
|
254
303
|
const runRequest = async (stalled = false) => {
|
255
|
-
const
|
304
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
305
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
306
|
+
if (!response) {
|
307
|
+
throw new Error("Request timed out");
|
308
|
+
}
|
256
309
|
if (response.status === 429) {
|
257
310
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
258
311
|
await timeout(rateLimitReset * 1e3);
|
259
312
|
return await runRequest(true);
|
260
313
|
}
|
261
314
|
if (stalled) {
|
262
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
263
|
-
console.warn(`A request to Xata hit
|
315
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
316
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
264
317
|
}
|
265
318
|
return response;
|
266
319
|
};
|
@@ -302,7 +355,180 @@ function generateUUID() {
|
|
302
355
|
});
|
303
356
|
}
|
304
357
|
|
305
|
-
|
358
|
+
async function getBytes(stream, onChunk) {
|
359
|
+
const reader = stream.getReader();
|
360
|
+
let result;
|
361
|
+
while (!(result = await reader.read()).done) {
|
362
|
+
onChunk(result.value);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
function getLines(onLine) {
|
366
|
+
let buffer;
|
367
|
+
let position;
|
368
|
+
let fieldLength;
|
369
|
+
let discardTrailingNewline = false;
|
370
|
+
return function onChunk(arr) {
|
371
|
+
if (buffer === void 0) {
|
372
|
+
buffer = arr;
|
373
|
+
position = 0;
|
374
|
+
fieldLength = -1;
|
375
|
+
} else {
|
376
|
+
buffer = concat(buffer, arr);
|
377
|
+
}
|
378
|
+
const bufLength = buffer.length;
|
379
|
+
let lineStart = 0;
|
380
|
+
while (position < bufLength) {
|
381
|
+
if (discardTrailingNewline) {
|
382
|
+
if (buffer[position] === 10 /* NewLine */) {
|
383
|
+
lineStart = ++position;
|
384
|
+
}
|
385
|
+
discardTrailingNewline = false;
|
386
|
+
}
|
387
|
+
let lineEnd = -1;
|
388
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
389
|
+
switch (buffer[position]) {
|
390
|
+
case 58 /* Colon */:
|
391
|
+
if (fieldLength === -1) {
|
392
|
+
fieldLength = position - lineStart;
|
393
|
+
}
|
394
|
+
break;
|
395
|
+
case 13 /* CarriageReturn */:
|
396
|
+
discardTrailingNewline = true;
|
397
|
+
case 10 /* NewLine */:
|
398
|
+
lineEnd = position;
|
399
|
+
break;
|
400
|
+
}
|
401
|
+
}
|
402
|
+
if (lineEnd === -1) {
|
403
|
+
break;
|
404
|
+
}
|
405
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
406
|
+
lineStart = position;
|
407
|
+
fieldLength = -1;
|
408
|
+
}
|
409
|
+
if (lineStart === bufLength) {
|
410
|
+
buffer = void 0;
|
411
|
+
} else if (lineStart !== 0) {
|
412
|
+
buffer = buffer.subarray(lineStart);
|
413
|
+
position -= lineStart;
|
414
|
+
}
|
415
|
+
};
|
416
|
+
}
|
417
|
+
function getMessages(onId, onRetry, onMessage) {
|
418
|
+
let message = newMessage();
|
419
|
+
const decoder = new TextDecoder();
|
420
|
+
return function onLine(line, fieldLength) {
|
421
|
+
if (line.length === 0) {
|
422
|
+
onMessage?.(message);
|
423
|
+
message = newMessage();
|
424
|
+
} else if (fieldLength > 0) {
|
425
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
426
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
427
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
428
|
+
switch (field) {
|
429
|
+
case "data":
|
430
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
431
|
+
break;
|
432
|
+
case "event":
|
433
|
+
message.event = value;
|
434
|
+
break;
|
435
|
+
case "id":
|
436
|
+
onId(message.id = value);
|
437
|
+
break;
|
438
|
+
case "retry":
|
439
|
+
const retry = parseInt(value, 10);
|
440
|
+
if (!isNaN(retry)) {
|
441
|
+
onRetry(message.retry = retry);
|
442
|
+
}
|
443
|
+
break;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
};
|
447
|
+
}
|
448
|
+
function concat(a, b) {
|
449
|
+
const res = new Uint8Array(a.length + b.length);
|
450
|
+
res.set(a);
|
451
|
+
res.set(b, a.length);
|
452
|
+
return res;
|
453
|
+
}
|
454
|
+
function newMessage() {
|
455
|
+
return {
|
456
|
+
data: "",
|
457
|
+
event: "",
|
458
|
+
id: "",
|
459
|
+
retry: void 0
|
460
|
+
};
|
461
|
+
}
|
462
|
+
const EventStreamContentType = "text/event-stream";
|
463
|
+
const LastEventId = "last-event-id";
|
464
|
+
function fetchEventSource(input, {
|
465
|
+
signal: inputSignal,
|
466
|
+
headers: inputHeaders,
|
467
|
+
onopen: inputOnOpen,
|
468
|
+
onmessage,
|
469
|
+
onclose,
|
470
|
+
onerror,
|
471
|
+
fetch: inputFetch,
|
472
|
+
...rest
|
473
|
+
}) {
|
474
|
+
return new Promise((resolve, reject) => {
|
475
|
+
const headers = { ...inputHeaders };
|
476
|
+
if (!headers.accept) {
|
477
|
+
headers.accept = EventStreamContentType;
|
478
|
+
}
|
479
|
+
let curRequestController;
|
480
|
+
function dispose() {
|
481
|
+
curRequestController.abort();
|
482
|
+
}
|
483
|
+
inputSignal?.addEventListener("abort", () => {
|
484
|
+
dispose();
|
485
|
+
resolve();
|
486
|
+
});
|
487
|
+
const fetchImpl = inputFetch ?? fetch;
|
488
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
489
|
+
async function create() {
|
490
|
+
curRequestController = new AbortController();
|
491
|
+
try {
|
492
|
+
const response = await fetchImpl(input, {
|
493
|
+
...rest,
|
494
|
+
headers,
|
495
|
+
signal: curRequestController.signal
|
496
|
+
});
|
497
|
+
await onopen(response);
|
498
|
+
await getBytes(
|
499
|
+
response.body,
|
500
|
+
getLines(
|
501
|
+
getMessages(
|
502
|
+
(id) => {
|
503
|
+
if (id) {
|
504
|
+
headers[LastEventId] = id;
|
505
|
+
} else {
|
506
|
+
delete headers[LastEventId];
|
507
|
+
}
|
508
|
+
},
|
509
|
+
(_retry) => {
|
510
|
+
},
|
511
|
+
onmessage
|
512
|
+
)
|
513
|
+
)
|
514
|
+
);
|
515
|
+
onclose?.();
|
516
|
+
dispose();
|
517
|
+
resolve();
|
518
|
+
} catch (err) {
|
519
|
+
}
|
520
|
+
}
|
521
|
+
create();
|
522
|
+
});
|
523
|
+
}
|
524
|
+
function defaultOnOpen(response) {
|
525
|
+
const contentType = response.headers?.get("content-type");
|
526
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
527
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
528
|
+
}
|
529
|
+
}
|
530
|
+
|
531
|
+
const VERSION = "0.28.0";
|
306
532
|
|
307
533
|
class ErrorWithCause extends Error {
|
308
534
|
constructor(message, options) {
|
@@ -378,6 +604,18 @@ function hostHeader(url) {
|
|
378
604
|
const { groups } = pattern.exec(url) ?? {};
|
379
605
|
return groups?.host ? { Host: groups.host } : {};
|
380
606
|
}
|
607
|
+
async function parseBody(body, headers) {
|
608
|
+
if (!isDefined(body))
|
609
|
+
return void 0;
|
610
|
+
if (isBlob(body) || typeof body.text === "function") {
|
611
|
+
return body;
|
612
|
+
}
|
613
|
+
const { "Content-Type": contentType } = headers ?? {};
|
614
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
615
|
+
return JSON.stringify(body);
|
616
|
+
}
|
617
|
+
return body;
|
618
|
+
}
|
381
619
|
const defaultClientID = generateUUID();
|
382
620
|
async function fetch$1({
|
383
621
|
url: path,
|
@@ -386,7 +624,7 @@ async function fetch$1({
|
|
386
624
|
headers: customHeaders,
|
387
625
|
pathParams,
|
388
626
|
queryParams,
|
389
|
-
|
627
|
+
fetch: fetch2,
|
390
628
|
apiKey,
|
391
629
|
endpoint,
|
392
630
|
apiUrl,
|
@@ -397,9 +635,10 @@ async function fetch$1({
|
|
397
635
|
sessionID,
|
398
636
|
clientName,
|
399
637
|
xataAgentExtra,
|
400
|
-
fetchOptions = {}
|
638
|
+
fetchOptions = {},
|
639
|
+
rawResponse = false
|
401
640
|
}) {
|
402
|
-
pool.setFetch(
|
641
|
+
pool.setFetch(fetch2);
|
403
642
|
return await trace(
|
404
643
|
`${method.toUpperCase()} ${path}`,
|
405
644
|
async ({ setAttributes }) => {
|
@@ -416,7 +655,7 @@ async function fetch$1({
|
|
416
655
|
isDefined(clientName) ? ["service", clientName] : void 0,
|
417
656
|
...Object.entries(xataAgentExtra ?? {})
|
418
657
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
419
|
-
const headers = {
|
658
|
+
const headers = compactObject({
|
420
659
|
"Accept-Encoding": "identity",
|
421
660
|
"Content-Type": "application/json",
|
422
661
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
@@ -425,11 +664,11 @@ async function fetch$1({
|
|
425
664
|
...customHeaders,
|
426
665
|
...hostHeader(fullUrl),
|
427
666
|
Authorization: `Bearer ${apiKey}`
|
428
|
-
};
|
667
|
+
});
|
429
668
|
const response = await pool.request(url, {
|
430
669
|
...fetchOptions,
|
431
670
|
method: method.toUpperCase(),
|
432
|
-
body:
|
671
|
+
body: await parseBody(body, headers),
|
433
672
|
headers,
|
434
673
|
signal
|
435
674
|
});
|
@@ -440,8 +679,12 @@ async function fetch$1({
|
|
440
679
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
441
680
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
442
681
|
[TraceAttributes.HTTP_HOST]: host,
|
443
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
682
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
683
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
444
684
|
});
|
685
|
+
const message = response.headers?.get("x-xata-message");
|
686
|
+
if (message)
|
687
|
+
console.warn(message);
|
445
688
|
if (response.status === 204) {
|
446
689
|
return {};
|
447
690
|
}
|
@@ -449,7 +692,7 @@ async function fetch$1({
|
|
449
692
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
450
693
|
}
|
451
694
|
try {
|
452
|
-
const jsonResponse = await response.json();
|
695
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
453
696
|
if (response.ok) {
|
454
697
|
return jsonResponse;
|
455
698
|
}
|
@@ -461,6 +704,59 @@ async function fetch$1({
|
|
461
704
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
462
705
|
);
|
463
706
|
}
|
707
|
+
function fetchSSERequest({
|
708
|
+
url: path,
|
709
|
+
method,
|
710
|
+
body,
|
711
|
+
headers: customHeaders,
|
712
|
+
pathParams,
|
713
|
+
queryParams,
|
714
|
+
fetch: fetch2,
|
715
|
+
apiKey,
|
716
|
+
endpoint,
|
717
|
+
apiUrl,
|
718
|
+
workspacesApiUrl,
|
719
|
+
onMessage,
|
720
|
+
onError,
|
721
|
+
onClose,
|
722
|
+
signal,
|
723
|
+
clientID,
|
724
|
+
sessionID,
|
725
|
+
clientName,
|
726
|
+
xataAgentExtra
|
727
|
+
}) {
|
728
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
729
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
730
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
731
|
+
void fetchEventSource(url, {
|
732
|
+
method,
|
733
|
+
body: JSON.stringify(body),
|
734
|
+
fetch: fetch2,
|
735
|
+
signal,
|
736
|
+
headers: {
|
737
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
738
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
739
|
+
"X-Xata-Agent": compact([
|
740
|
+
["client", "TS_SDK"],
|
741
|
+
["version", VERSION],
|
742
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
743
|
+
...Object.entries(xataAgentExtra ?? {})
|
744
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
745
|
+
...customHeaders,
|
746
|
+
Authorization: `Bearer ${apiKey}`,
|
747
|
+
"Content-Type": "application/json"
|
748
|
+
},
|
749
|
+
onmessage(ev) {
|
750
|
+
onMessage?.(JSON.parse(ev.data));
|
751
|
+
},
|
752
|
+
onerror(ev) {
|
753
|
+
onError?.(JSON.parse(ev.data));
|
754
|
+
},
|
755
|
+
onclose() {
|
756
|
+
onClose?.();
|
757
|
+
}
|
758
|
+
});
|
759
|
+
}
|
464
760
|
function parseUrl(url) {
|
465
761
|
try {
|
466
762
|
const { host, protocol } = new URL(url);
|
@@ -472,6 +768,13 @@ function parseUrl(url) {
|
|
472
768
|
|
473
769
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
474
770
|
|
771
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
772
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
773
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
774
|
+
method: "get",
|
775
|
+
...variables,
|
776
|
+
signal
|
777
|
+
});
|
475
778
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
476
779
|
url: "/dbs/{dbName}",
|
477
780
|
method: "get",
|
@@ -491,6 +794,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
491
794
|
...variables,
|
492
795
|
signal
|
493
796
|
});
|
797
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
798
|
+
url: "/db/{dbBranchName}/schema",
|
799
|
+
method: "get",
|
800
|
+
...variables,
|
801
|
+
signal
|
802
|
+
});
|
803
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
804
|
+
url: "/db/{dbBranchName}/copy",
|
805
|
+
method: "post",
|
806
|
+
...variables,
|
807
|
+
signal
|
808
|
+
});
|
494
809
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
495
810
|
url: "/db/{dbBranchName}/metadata",
|
496
811
|
method: "put",
|
@@ -540,6 +855,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
540
855
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
541
856
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
542
857
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
858
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
543
859
|
const createTable = (variables, signal) => dataPlaneFetch({
|
544
860
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
545
861
|
method: "put",
|
@@ -584,6 +900,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
584
900
|
});
|
585
901
|
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
586
902
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
903
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
904
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
905
|
+
method: "get",
|
906
|
+
...variables,
|
907
|
+
signal
|
908
|
+
});
|
909
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
910
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
911
|
+
method: "put",
|
912
|
+
...variables,
|
913
|
+
signal
|
914
|
+
});
|
915
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
916
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
917
|
+
method: "delete",
|
918
|
+
...variables,
|
919
|
+
signal
|
920
|
+
});
|
921
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
922
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
923
|
+
method: "get",
|
924
|
+
...variables,
|
925
|
+
signal
|
926
|
+
});
|
927
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
928
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
929
|
+
method: "put",
|
930
|
+
...variables,
|
931
|
+
signal
|
932
|
+
});
|
933
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
934
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
935
|
+
method: "delete",
|
936
|
+
...variables,
|
937
|
+
signal
|
938
|
+
});
|
587
939
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
588
940
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
589
941
|
method: "get",
|
@@ -613,14 +965,37 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
613
965
|
...variables,
|
614
966
|
signal
|
615
967
|
});
|
968
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
969
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
970
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
971
|
+
method: "post",
|
972
|
+
...variables,
|
973
|
+
signal
|
974
|
+
});
|
975
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
616
976
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
617
977
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
978
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
979
|
+
url: "/file/{fileId}",
|
980
|
+
method: "get",
|
981
|
+
...variables,
|
982
|
+
signal
|
983
|
+
});
|
984
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
985
|
+
url: "/db/{dbBranchName}/sql",
|
986
|
+
method: "post",
|
987
|
+
...variables,
|
988
|
+
signal
|
989
|
+
});
|
618
990
|
const operationsByTag$2 = {
|
619
991
|
branch: {
|
992
|
+
applyMigration,
|
993
|
+
pgRollStatus,
|
620
994
|
getBranchList,
|
621
995
|
getBranchDetails,
|
622
996
|
createBranch,
|
623
997
|
deleteBranch,
|
998
|
+
copyBranch,
|
624
999
|
updateBranchMetadata,
|
625
1000
|
getBranchMetadata,
|
626
1001
|
getBranchStats,
|
@@ -630,6 +1005,7 @@ const operationsByTag$2 = {
|
|
630
1005
|
resolveBranch
|
631
1006
|
},
|
632
1007
|
migrations: {
|
1008
|
+
getSchema,
|
633
1009
|
getBranchMigrationHistory,
|
634
1010
|
getBranchMigrationPlan,
|
635
1011
|
executeBranchMigrationPlan,
|
@@ -638,7 +1014,8 @@ const operationsByTag$2 = {
|
|
638
1014
|
compareBranchSchemas,
|
639
1015
|
updateBranchSchema,
|
640
1016
|
previewBranchSchemaEdit,
|
641
|
-
applyBranchSchemaEdit
|
1017
|
+
applyBranchSchemaEdit,
|
1018
|
+
pushBranchMigrations
|
642
1019
|
},
|
643
1020
|
migrationRequests: {
|
644
1021
|
queryMigrationRequests,
|
@@ -672,11 +1049,24 @@ const operationsByTag$2 = {
|
|
672
1049
|
deleteRecord,
|
673
1050
|
bulkInsertTableRecords
|
674
1051
|
},
|
675
|
-
|
1052
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1053
|
+
searchAndFilter: {
|
1054
|
+
queryTable,
|
1055
|
+
searchBranch,
|
1056
|
+
searchTable,
|
1057
|
+
vectorSearchTable,
|
1058
|
+
askTable,
|
1059
|
+
askTableSession,
|
1060
|
+
summarizeTable,
|
1061
|
+
aggregateTable
|
1062
|
+
},
|
1063
|
+
sql: { sqlQuery }
|
676
1064
|
};
|
677
1065
|
|
678
1066
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
679
1067
|
|
1068
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1069
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
680
1070
|
const getUser = (variables, signal) => controlPlaneFetch({
|
681
1071
|
url: "/user",
|
682
1072
|
method: "get",
|
@@ -713,6 +1103,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
713
1103
|
...variables,
|
714
1104
|
signal
|
715
1105
|
});
|
1106
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1107
|
+
url: "/user/oauth/clients",
|
1108
|
+
method: "get",
|
1109
|
+
...variables,
|
1110
|
+
signal
|
1111
|
+
});
|
1112
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1113
|
+
url: "/user/oauth/clients/{clientId}",
|
1114
|
+
method: "delete",
|
1115
|
+
...variables,
|
1116
|
+
signal
|
1117
|
+
});
|
1118
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1119
|
+
url: "/user/oauth/tokens",
|
1120
|
+
method: "get",
|
1121
|
+
...variables,
|
1122
|
+
signal
|
1123
|
+
});
|
1124
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1125
|
+
url: "/user/oauth/tokens/{token}",
|
1126
|
+
method: "delete",
|
1127
|
+
...variables,
|
1128
|
+
signal
|
1129
|
+
});
|
1130
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
716
1131
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
717
1132
|
url: "/workspaces",
|
718
1133
|
method: "get",
|
@@ -756,6 +1171,20 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
756
1171
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
757
1172
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
758
1173
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1174
|
+
const listClusters = (variables, signal) => controlPlaneFetch({
|
1175
|
+
url: "/workspaces/{workspaceId}/clusters",
|
1176
|
+
method: "get",
|
1177
|
+
...variables,
|
1178
|
+
signal
|
1179
|
+
});
|
1180
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1181
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1182
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1183
|
+
method: "get",
|
1184
|
+
...variables,
|
1185
|
+
signal
|
1186
|
+
});
|
1187
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
759
1188
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
760
1189
|
url: "/workspaces/{workspaceId}/dbs",
|
761
1190
|
method: "get",
|
@@ -771,6 +1200,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
771
1200
|
});
|
772
1201
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
773
1202
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1203
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
774
1204
|
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
775
1205
|
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
776
1206
|
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
@@ -781,6 +1211,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
781
1211
|
signal
|
782
1212
|
});
|
783
1213
|
const operationsByTag$1 = {
|
1214
|
+
oAuth: {
|
1215
|
+
getAuthorizationCode,
|
1216
|
+
grantAuthorizationCode,
|
1217
|
+
getUserOAuthClients,
|
1218
|
+
deleteUserOAuthClient,
|
1219
|
+
getUserOAuthAccessTokens,
|
1220
|
+
deleteOAuthAccessToken,
|
1221
|
+
updateOAuthAccessToken
|
1222
|
+
},
|
784
1223
|
users: { getUser, updateUser, deleteUser },
|
785
1224
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
786
1225
|
workspaces: {
|
@@ -800,12 +1239,14 @@ const operationsByTag$1 = {
|
|
800
1239
|
acceptWorkspaceMemberInvite,
|
801
1240
|
resendWorkspaceMemberInvite
|
802
1241
|
},
|
1242
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
803
1243
|
databases: {
|
804
1244
|
getDatabaseList,
|
805
1245
|
createDatabase,
|
806
1246
|
deleteDatabase,
|
807
1247
|
getDatabaseMetadata,
|
808
1248
|
updateDatabaseMetadata,
|
1249
|
+
renameDatabase,
|
809
1250
|
getDatabaseGithubSettings,
|
810
1251
|
updateDatabaseGithubSettings,
|
811
1252
|
deleteDatabaseGithubSettings,
|
@@ -829,8 +1270,12 @@ const providers = {
|
|
829
1270
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
830
1271
|
},
|
831
1272
|
staging: {
|
832
|
-
main: "https://staging.
|
833
|
-
workspaces: "https://{workspaceId}.
|
1273
|
+
main: "https://api.staging-xata.dev",
|
1274
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1275
|
+
},
|
1276
|
+
dev: {
|
1277
|
+
main: "https://api.dev-xata.dev",
|
1278
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
834
1279
|
}
|
835
1280
|
};
|
836
1281
|
function isHostProviderAlias(alias) {
|
@@ -848,13 +1293,19 @@ function parseProviderString(provider = "production") {
|
|
848
1293
|
return null;
|
849
1294
|
return { main, workspaces };
|
850
1295
|
}
|
1296
|
+
function buildProviderString(provider) {
|
1297
|
+
if (isHostProviderAlias(provider))
|
1298
|
+
return provider;
|
1299
|
+
return `${provider.main},${provider.workspaces}`;
|
1300
|
+
}
|
851
1301
|
function parseWorkspacesUrlParts(url) {
|
852
1302
|
if (!isString(url))
|
853
1303
|
return null;
|
854
1304
|
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
855
|
-
const
|
856
|
-
const
|
857
|
-
const
|
1305
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1306
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1307
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1308
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
858
1309
|
if (!match)
|
859
1310
|
return null;
|
860
1311
|
return { workspace: match[1], region: match[2] };
|
@@ -893,7 +1344,7 @@ class XataApiClient {
|
|
893
1344
|
__privateSet$7(this, _extraProps, {
|
894
1345
|
apiUrl: getHostUrl(provider, "main"),
|
895
1346
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
896
|
-
|
1347
|
+
fetch: getFetchImplementation(options.fetch),
|
897
1348
|
apiKey,
|
898
1349
|
trace,
|
899
1350
|
clientName: options.clientName,
|
@@ -951,6 +1402,11 @@ class XataApiClient {
|
|
951
1402
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
952
1403
|
return __privateGet$7(this, _namespaces).records;
|
953
1404
|
}
|
1405
|
+
get files() {
|
1406
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1407
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1408
|
+
return __privateGet$7(this, _namespaces).files;
|
1409
|
+
}
|
954
1410
|
get searchAndFilter() {
|
955
1411
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
956
1412
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1159,6 +1615,20 @@ class BranchApi {
|
|
1159
1615
|
...this.extraProps
|
1160
1616
|
});
|
1161
1617
|
}
|
1618
|
+
copyBranch({
|
1619
|
+
workspace,
|
1620
|
+
region,
|
1621
|
+
database,
|
1622
|
+
branch,
|
1623
|
+
destinationBranch,
|
1624
|
+
limit
|
1625
|
+
}) {
|
1626
|
+
return operationsByTag.branch.copyBranch({
|
1627
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1628
|
+
body: { destinationBranch, limit },
|
1629
|
+
...this.extraProps
|
1630
|
+
});
|
1631
|
+
}
|
1162
1632
|
updateBranchMetadata({
|
1163
1633
|
workspace,
|
1164
1634
|
region,
|
@@ -1514,95 +1984,300 @@ class RecordsApi {
|
|
1514
1984
|
});
|
1515
1985
|
}
|
1516
1986
|
}
|
1517
|
-
class
|
1987
|
+
class FilesApi {
|
1518
1988
|
constructor(extraProps) {
|
1519
1989
|
this.extraProps = extraProps;
|
1520
1990
|
}
|
1521
|
-
|
1991
|
+
getFileItem({
|
1522
1992
|
workspace,
|
1523
1993
|
region,
|
1524
1994
|
database,
|
1525
1995
|
branch,
|
1526
1996
|
table,
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
columns,
|
1531
|
-
consistency
|
1997
|
+
record,
|
1998
|
+
column,
|
1999
|
+
fileId
|
1532
2000
|
}) {
|
1533
|
-
return operationsByTag.
|
1534
|
-
pathParams: {
|
1535
|
-
|
2001
|
+
return operationsByTag.files.getFileItem({
|
2002
|
+
pathParams: {
|
2003
|
+
workspace,
|
2004
|
+
region,
|
2005
|
+
dbBranchName: `${database}:${branch}`,
|
2006
|
+
tableName: table,
|
2007
|
+
recordId: record,
|
2008
|
+
columnName: column,
|
2009
|
+
fileId
|
2010
|
+
},
|
1536
2011
|
...this.extraProps
|
1537
2012
|
});
|
1538
2013
|
}
|
1539
|
-
|
2014
|
+
putFileItem({
|
1540
2015
|
workspace,
|
1541
2016
|
region,
|
1542
2017
|
database,
|
1543
2018
|
branch,
|
1544
2019
|
table,
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
filter,
|
1550
|
-
highlight,
|
1551
|
-
boosters
|
2020
|
+
record,
|
2021
|
+
column,
|
2022
|
+
fileId,
|
2023
|
+
file
|
1552
2024
|
}) {
|
1553
|
-
return operationsByTag.
|
1554
|
-
pathParams: {
|
1555
|
-
|
2025
|
+
return operationsByTag.files.putFileItem({
|
2026
|
+
pathParams: {
|
2027
|
+
workspace,
|
2028
|
+
region,
|
2029
|
+
dbBranchName: `${database}:${branch}`,
|
2030
|
+
tableName: table,
|
2031
|
+
recordId: record,
|
2032
|
+
columnName: column,
|
2033
|
+
fileId
|
2034
|
+
},
|
2035
|
+
// @ts-ignore
|
2036
|
+
body: file,
|
1556
2037
|
...this.extraProps
|
1557
2038
|
});
|
1558
2039
|
}
|
1559
|
-
|
2040
|
+
deleteFileItem({
|
1560
2041
|
workspace,
|
1561
2042
|
region,
|
1562
2043
|
database,
|
1563
2044
|
branch,
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
highlight
|
2045
|
+
table,
|
2046
|
+
record,
|
2047
|
+
column,
|
2048
|
+
fileId
|
1569
2049
|
}) {
|
1570
|
-
return operationsByTag.
|
1571
|
-
pathParams: {
|
1572
|
-
|
2050
|
+
return operationsByTag.files.deleteFileItem({
|
2051
|
+
pathParams: {
|
2052
|
+
workspace,
|
2053
|
+
region,
|
2054
|
+
dbBranchName: `${database}:${branch}`,
|
2055
|
+
tableName: table,
|
2056
|
+
recordId: record,
|
2057
|
+
columnName: column,
|
2058
|
+
fileId
|
2059
|
+
},
|
1573
2060
|
...this.extraProps
|
1574
2061
|
});
|
1575
2062
|
}
|
1576
|
-
|
2063
|
+
getFile({
|
1577
2064
|
workspace,
|
1578
2065
|
region,
|
1579
2066
|
database,
|
1580
2067
|
branch,
|
1581
2068
|
table,
|
1582
|
-
|
1583
|
-
|
1584
|
-
summaries,
|
1585
|
-
sort,
|
1586
|
-
summariesFilter,
|
1587
|
-
page,
|
1588
|
-
consistency
|
2069
|
+
record,
|
2070
|
+
column
|
1589
2071
|
}) {
|
1590
|
-
return operationsByTag.
|
1591
|
-
pathParams: {
|
1592
|
-
|
2072
|
+
return operationsByTag.files.getFile({
|
2073
|
+
pathParams: {
|
2074
|
+
workspace,
|
2075
|
+
region,
|
2076
|
+
dbBranchName: `${database}:${branch}`,
|
2077
|
+
tableName: table,
|
2078
|
+
recordId: record,
|
2079
|
+
columnName: column
|
2080
|
+
},
|
1593
2081
|
...this.extraProps
|
1594
2082
|
});
|
1595
2083
|
}
|
1596
|
-
|
2084
|
+
putFile({
|
1597
2085
|
workspace,
|
1598
2086
|
region,
|
1599
2087
|
database,
|
1600
2088
|
branch,
|
1601
2089
|
table,
|
1602
|
-
|
1603
|
-
|
2090
|
+
record,
|
2091
|
+
column,
|
2092
|
+
file
|
1604
2093
|
}) {
|
1605
|
-
return operationsByTag.
|
2094
|
+
return operationsByTag.files.putFile({
|
2095
|
+
pathParams: {
|
2096
|
+
workspace,
|
2097
|
+
region,
|
2098
|
+
dbBranchName: `${database}:${branch}`,
|
2099
|
+
tableName: table,
|
2100
|
+
recordId: record,
|
2101
|
+
columnName: column
|
2102
|
+
},
|
2103
|
+
body: file,
|
2104
|
+
...this.extraProps
|
2105
|
+
});
|
2106
|
+
}
|
2107
|
+
deleteFile({
|
2108
|
+
workspace,
|
2109
|
+
region,
|
2110
|
+
database,
|
2111
|
+
branch,
|
2112
|
+
table,
|
2113
|
+
record,
|
2114
|
+
column
|
2115
|
+
}) {
|
2116
|
+
return operationsByTag.files.deleteFile({
|
2117
|
+
pathParams: {
|
2118
|
+
workspace,
|
2119
|
+
region,
|
2120
|
+
dbBranchName: `${database}:${branch}`,
|
2121
|
+
tableName: table,
|
2122
|
+
recordId: record,
|
2123
|
+
columnName: column
|
2124
|
+
},
|
2125
|
+
...this.extraProps
|
2126
|
+
});
|
2127
|
+
}
|
2128
|
+
fileAccess({
|
2129
|
+
workspace,
|
2130
|
+
region,
|
2131
|
+
fileId,
|
2132
|
+
verify
|
2133
|
+
}) {
|
2134
|
+
return operationsByTag.files.fileAccess({
|
2135
|
+
pathParams: {
|
2136
|
+
workspace,
|
2137
|
+
region,
|
2138
|
+
fileId
|
2139
|
+
},
|
2140
|
+
queryParams: { verify },
|
2141
|
+
...this.extraProps
|
2142
|
+
});
|
2143
|
+
}
|
2144
|
+
}
|
2145
|
+
class SearchAndFilterApi {
|
2146
|
+
constructor(extraProps) {
|
2147
|
+
this.extraProps = extraProps;
|
2148
|
+
}
|
2149
|
+
queryTable({
|
2150
|
+
workspace,
|
2151
|
+
region,
|
2152
|
+
database,
|
2153
|
+
branch,
|
2154
|
+
table,
|
2155
|
+
filter,
|
2156
|
+
sort,
|
2157
|
+
page,
|
2158
|
+
columns,
|
2159
|
+
consistency
|
2160
|
+
}) {
|
2161
|
+
return operationsByTag.searchAndFilter.queryTable({
|
2162
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2163
|
+
body: { filter, sort, page, columns, consistency },
|
2164
|
+
...this.extraProps
|
2165
|
+
});
|
2166
|
+
}
|
2167
|
+
searchTable({
|
2168
|
+
workspace,
|
2169
|
+
region,
|
2170
|
+
database,
|
2171
|
+
branch,
|
2172
|
+
table,
|
2173
|
+
query,
|
2174
|
+
fuzziness,
|
2175
|
+
target,
|
2176
|
+
prefix,
|
2177
|
+
filter,
|
2178
|
+
highlight,
|
2179
|
+
boosters
|
2180
|
+
}) {
|
2181
|
+
return operationsByTag.searchAndFilter.searchTable({
|
2182
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2183
|
+
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
2184
|
+
...this.extraProps
|
2185
|
+
});
|
2186
|
+
}
|
2187
|
+
searchBranch({
|
2188
|
+
workspace,
|
2189
|
+
region,
|
2190
|
+
database,
|
2191
|
+
branch,
|
2192
|
+
tables,
|
2193
|
+
query,
|
2194
|
+
fuzziness,
|
2195
|
+
prefix,
|
2196
|
+
highlight
|
2197
|
+
}) {
|
2198
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
2199
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2200
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
2201
|
+
...this.extraProps
|
2202
|
+
});
|
2203
|
+
}
|
2204
|
+
vectorSearchTable({
|
2205
|
+
workspace,
|
2206
|
+
region,
|
2207
|
+
database,
|
2208
|
+
branch,
|
2209
|
+
table,
|
2210
|
+
queryVector,
|
2211
|
+
column,
|
2212
|
+
similarityFunction,
|
2213
|
+
size,
|
2214
|
+
filter
|
2215
|
+
}) {
|
2216
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2217
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2218
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2219
|
+
...this.extraProps
|
2220
|
+
});
|
2221
|
+
}
|
2222
|
+
askTable({
|
2223
|
+
workspace,
|
2224
|
+
region,
|
2225
|
+
database,
|
2226
|
+
branch,
|
2227
|
+
table,
|
2228
|
+
options
|
2229
|
+
}) {
|
2230
|
+
return operationsByTag.searchAndFilter.askTable({
|
2231
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2232
|
+
body: { ...options },
|
2233
|
+
...this.extraProps
|
2234
|
+
});
|
2235
|
+
}
|
2236
|
+
askTableSession({
|
2237
|
+
workspace,
|
2238
|
+
region,
|
2239
|
+
database,
|
2240
|
+
branch,
|
2241
|
+
table,
|
2242
|
+
sessionId,
|
2243
|
+
message
|
2244
|
+
}) {
|
2245
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2246
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2247
|
+
body: { message },
|
2248
|
+
...this.extraProps
|
2249
|
+
});
|
2250
|
+
}
|
2251
|
+
summarizeTable({
|
2252
|
+
workspace,
|
2253
|
+
region,
|
2254
|
+
database,
|
2255
|
+
branch,
|
2256
|
+
table,
|
2257
|
+
filter,
|
2258
|
+
columns,
|
2259
|
+
summaries,
|
2260
|
+
sort,
|
2261
|
+
summariesFilter,
|
2262
|
+
page,
|
2263
|
+
consistency
|
2264
|
+
}) {
|
2265
|
+
return operationsByTag.searchAndFilter.summarizeTable({
|
2266
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2267
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
2268
|
+
...this.extraProps
|
2269
|
+
});
|
2270
|
+
}
|
2271
|
+
aggregateTable({
|
2272
|
+
workspace,
|
2273
|
+
region,
|
2274
|
+
database,
|
2275
|
+
branch,
|
2276
|
+
table,
|
2277
|
+
filter,
|
2278
|
+
aggs
|
2279
|
+
}) {
|
2280
|
+
return operationsByTag.searchAndFilter.aggregateTable({
|
1606
2281
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1607
2282
|
body: { filter, aggs },
|
1608
2283
|
...this.extraProps
|
@@ -1837,6 +2512,19 @@ class MigrationsApi {
|
|
1837
2512
|
...this.extraProps
|
1838
2513
|
});
|
1839
2514
|
}
|
2515
|
+
pushBranchMigrations({
|
2516
|
+
workspace,
|
2517
|
+
region,
|
2518
|
+
database,
|
2519
|
+
branch,
|
2520
|
+
migrations
|
2521
|
+
}) {
|
2522
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2523
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2524
|
+
body: { migrations },
|
2525
|
+
...this.extraProps
|
2526
|
+
});
|
2527
|
+
}
|
1840
2528
|
}
|
1841
2529
|
class DatabaseApi {
|
1842
2530
|
constructor(extraProps) {
|
@@ -1851,11 +2539,13 @@ class DatabaseApi {
|
|
1851
2539
|
createDatabase({
|
1852
2540
|
workspace,
|
1853
2541
|
database,
|
1854
|
-
data
|
2542
|
+
data,
|
2543
|
+
headers
|
1855
2544
|
}) {
|
1856
2545
|
return operationsByTag.databases.createDatabase({
|
1857
2546
|
pathParams: { workspaceId: workspace, dbName: database },
|
1858
2547
|
body: data,
|
2548
|
+
headers,
|
1859
2549
|
...this.extraProps
|
1860
2550
|
});
|
1861
2551
|
}
|
@@ -1888,6 +2578,17 @@ class DatabaseApi {
|
|
1888
2578
|
...this.extraProps
|
1889
2579
|
});
|
1890
2580
|
}
|
2581
|
+
renameDatabase({
|
2582
|
+
workspace,
|
2583
|
+
database,
|
2584
|
+
newName
|
2585
|
+
}) {
|
2586
|
+
return operationsByTag.databases.renameDatabase({
|
2587
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2588
|
+
body: { newName },
|
2589
|
+
...this.extraProps
|
2590
|
+
});
|
2591
|
+
}
|
1891
2592
|
getDatabaseGithubSettings({
|
1892
2593
|
workspace,
|
1893
2594
|
database
|
@@ -1926,20 +2627,200 @@ class DatabaseApi {
|
|
1926
2627
|
}
|
1927
2628
|
|
1928
2629
|
class XataApiPlugin {
|
1929
|
-
|
1930
|
-
|
1931
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2630
|
+
build(options) {
|
2631
|
+
return new XataApiClient(options);
|
1932
2632
|
}
|
1933
2633
|
}
|
1934
2634
|
|
1935
2635
|
class XataPlugin {
|
1936
2636
|
}
|
1937
2637
|
|
2638
|
+
function buildTransformString(transformations) {
|
2639
|
+
return transformations.flatMap(
|
2640
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2641
|
+
if (key === "trim") {
|
2642
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2643
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2644
|
+
}
|
2645
|
+
if (key === "gravity" && typeof value === "object") {
|
2646
|
+
const { x = 0.5, y = 0.5 } = value;
|
2647
|
+
return `${key}=${[x, y].join("x")}`;
|
2648
|
+
}
|
2649
|
+
return `${key}=${value}`;
|
2650
|
+
})
|
2651
|
+
).join(",");
|
2652
|
+
}
|
2653
|
+
function transformImage(url, ...transformations) {
|
2654
|
+
if (!isDefined(url))
|
2655
|
+
return void 0;
|
2656
|
+
const newTransformations = buildTransformString(transformations);
|
2657
|
+
const { hostname, pathname, search } = new URL(url);
|
2658
|
+
const pathParts = pathname.split("/");
|
2659
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2660
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2661
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2662
|
+
const path = pathParts.join("/");
|
2663
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2664
|
+
}
|
2665
|
+
|
2666
|
+
class XataFile {
|
2667
|
+
constructor(file) {
|
2668
|
+
this.id = file.id;
|
2669
|
+
this.name = file.name || "";
|
2670
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2671
|
+
this.base64Content = file.base64Content;
|
2672
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2673
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2674
|
+
this.size = file.size ?? 0;
|
2675
|
+
this.version = file.version ?? 1;
|
2676
|
+
this.url = file.url || "";
|
2677
|
+
this.signedUrl = file.signedUrl;
|
2678
|
+
this.attributes = file.attributes || {};
|
2679
|
+
}
|
2680
|
+
static fromBuffer(buffer, options = {}) {
|
2681
|
+
const base64Content = buffer.toString("base64");
|
2682
|
+
return new XataFile({ ...options, base64Content });
|
2683
|
+
}
|
2684
|
+
toBuffer() {
|
2685
|
+
if (!this.base64Content) {
|
2686
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2687
|
+
}
|
2688
|
+
return Buffer.from(this.base64Content, "base64");
|
2689
|
+
}
|
2690
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2691
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2692
|
+
return this.fromUint8Array(uint8Array, options);
|
2693
|
+
}
|
2694
|
+
toArrayBuffer() {
|
2695
|
+
if (!this.base64Content) {
|
2696
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2697
|
+
}
|
2698
|
+
const binary = atob(this.base64Content);
|
2699
|
+
return new ArrayBuffer(binary.length);
|
2700
|
+
}
|
2701
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2702
|
+
let binary = "";
|
2703
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2704
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2705
|
+
}
|
2706
|
+
const base64Content = btoa(binary);
|
2707
|
+
return new XataFile({ ...options, base64Content });
|
2708
|
+
}
|
2709
|
+
toUint8Array() {
|
2710
|
+
if (!this.base64Content) {
|
2711
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2712
|
+
}
|
2713
|
+
const binary = atob(this.base64Content);
|
2714
|
+
const uint8Array = new Uint8Array(binary.length);
|
2715
|
+
for (let i = 0; i < binary.length; i++) {
|
2716
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2717
|
+
}
|
2718
|
+
return uint8Array;
|
2719
|
+
}
|
2720
|
+
static async fromBlob(file, options = {}) {
|
2721
|
+
const name = options.name ?? file.name;
|
2722
|
+
const mediaType = file.type;
|
2723
|
+
const arrayBuffer = await file.arrayBuffer();
|
2724
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2725
|
+
}
|
2726
|
+
toBlob() {
|
2727
|
+
if (!this.base64Content) {
|
2728
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2729
|
+
}
|
2730
|
+
const binary = atob(this.base64Content);
|
2731
|
+
const uint8Array = new Uint8Array(binary.length);
|
2732
|
+
for (let i = 0; i < binary.length; i++) {
|
2733
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2734
|
+
}
|
2735
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2736
|
+
}
|
2737
|
+
static fromString(string, options = {}) {
|
2738
|
+
const base64Content = btoa(string);
|
2739
|
+
return new XataFile({ ...options, base64Content });
|
2740
|
+
}
|
2741
|
+
toString() {
|
2742
|
+
if (!this.base64Content) {
|
2743
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2744
|
+
}
|
2745
|
+
return atob(this.base64Content);
|
2746
|
+
}
|
2747
|
+
static fromBase64(base64Content, options = {}) {
|
2748
|
+
return new XataFile({ ...options, base64Content });
|
2749
|
+
}
|
2750
|
+
toBase64() {
|
2751
|
+
if (!this.base64Content) {
|
2752
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2753
|
+
}
|
2754
|
+
return this.base64Content;
|
2755
|
+
}
|
2756
|
+
transform(...options) {
|
2757
|
+
return {
|
2758
|
+
url: transformImage(this.url, ...options),
|
2759
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2760
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2761
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2762
|
+
};
|
2763
|
+
}
|
2764
|
+
}
|
2765
|
+
const parseInputFileEntry = async (entry) => {
|
2766
|
+
if (!isDefined(entry))
|
2767
|
+
return null;
|
2768
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2769
|
+
return compactObject({
|
2770
|
+
id,
|
2771
|
+
// Name cannot be an empty string in our API
|
2772
|
+
name: name ? name : void 0,
|
2773
|
+
mediaType,
|
2774
|
+
base64Content,
|
2775
|
+
enablePublicUrl,
|
2776
|
+
signedUrlTimeout
|
2777
|
+
});
|
2778
|
+
};
|
2779
|
+
|
1938
2780
|
function cleanFilter(filter) {
|
1939
|
-
if (!filter)
|
2781
|
+
if (!isDefined(filter))
|
1940
2782
|
return void 0;
|
1941
|
-
|
1942
|
-
|
2783
|
+
if (!isObject(filter))
|
2784
|
+
return filter;
|
2785
|
+
const values = Object.fromEntries(
|
2786
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2787
|
+
if (!isDefined(value))
|
2788
|
+
return acc;
|
2789
|
+
if (Array.isArray(value)) {
|
2790
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2791
|
+
if (clean.length === 0)
|
2792
|
+
return acc;
|
2793
|
+
return [...acc, [key, clean]];
|
2794
|
+
}
|
2795
|
+
if (isObject(value)) {
|
2796
|
+
const clean = cleanFilter(value);
|
2797
|
+
if (!isDefined(clean))
|
2798
|
+
return acc;
|
2799
|
+
return [...acc, [key, clean]];
|
2800
|
+
}
|
2801
|
+
return [...acc, [key, value]];
|
2802
|
+
}, [])
|
2803
|
+
);
|
2804
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
2805
|
+
}
|
2806
|
+
|
2807
|
+
function stringifyJson(value) {
|
2808
|
+
if (!isDefined(value))
|
2809
|
+
return value;
|
2810
|
+
if (isString(value))
|
2811
|
+
return value;
|
2812
|
+
try {
|
2813
|
+
return JSON.stringify(value);
|
2814
|
+
} catch (e) {
|
2815
|
+
return value;
|
2816
|
+
}
|
2817
|
+
}
|
2818
|
+
function parseJson(value) {
|
2819
|
+
try {
|
2820
|
+
return JSON.parse(value);
|
2821
|
+
} catch (e) {
|
2822
|
+
return value;
|
2823
|
+
}
|
1943
2824
|
}
|
1944
2825
|
|
1945
2826
|
var __accessCheck$6 = (obj, member, msg) => {
|
@@ -1968,31 +2849,59 @@ class Page {
|
|
1968
2849
|
this.meta = meta;
|
1969
2850
|
this.records = new RecordArray(this, records);
|
1970
2851
|
}
|
2852
|
+
/**
|
2853
|
+
* Retrieves the next page of results.
|
2854
|
+
* @param size Maximum number of results to be retrieved.
|
2855
|
+
* @param offset Number of results to skip when retrieving the results.
|
2856
|
+
* @returns The next page or results.
|
2857
|
+
*/
|
1971
2858
|
async nextPage(size, offset) {
|
1972
2859
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1973
2860
|
}
|
2861
|
+
/**
|
2862
|
+
* Retrieves the previous page of results.
|
2863
|
+
* @param size Maximum number of results to be retrieved.
|
2864
|
+
* @param offset Number of results to skip when retrieving the results.
|
2865
|
+
* @returns The previous page or results.
|
2866
|
+
*/
|
1974
2867
|
async previousPage(size, offset) {
|
1975
2868
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1976
2869
|
}
|
2870
|
+
/**
|
2871
|
+
* Retrieves the start page of results.
|
2872
|
+
* @param size Maximum number of results to be retrieved.
|
2873
|
+
* @param offset Number of results to skip when retrieving the results.
|
2874
|
+
* @returns The start page or results.
|
2875
|
+
*/
|
1977
2876
|
async startPage(size, offset) {
|
1978
2877
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1979
2878
|
}
|
2879
|
+
/**
|
2880
|
+
* Retrieves the end page of results.
|
2881
|
+
* @param size Maximum number of results to be retrieved.
|
2882
|
+
* @param offset Number of results to skip when retrieving the results.
|
2883
|
+
* @returns The end page or results.
|
2884
|
+
*/
|
1980
2885
|
async endPage(size, offset) {
|
1981
2886
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1982
2887
|
}
|
2888
|
+
/**
|
2889
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2890
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2891
|
+
*/
|
1983
2892
|
hasNextPage() {
|
1984
2893
|
return this.meta.page.more;
|
1985
2894
|
}
|
1986
2895
|
}
|
1987
2896
|
_query = new WeakMap();
|
1988
|
-
const PAGINATION_MAX_SIZE =
|
2897
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
1989
2898
|
const PAGINATION_DEFAULT_SIZE = 20;
|
1990
|
-
const PAGINATION_MAX_OFFSET =
|
2899
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
1991
2900
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1992
2901
|
function isCursorPaginationOptions(options) {
|
1993
2902
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1994
2903
|
}
|
1995
|
-
const _RecordArray = class extends Array {
|
2904
|
+
const _RecordArray = class _RecordArray extends Array {
|
1996
2905
|
constructor(...args) {
|
1997
2906
|
super(..._RecordArray.parseConstructorParams(...args));
|
1998
2907
|
__privateAdd$6(this, _page, void 0);
|
@@ -2020,28 +2929,51 @@ const _RecordArray = class extends Array {
|
|
2020
2929
|
map(callbackfn, thisArg) {
|
2021
2930
|
return this.toArray().map(callbackfn, thisArg);
|
2022
2931
|
}
|
2932
|
+
/**
|
2933
|
+
* Retrieve next page of records
|
2934
|
+
*
|
2935
|
+
* @returns A new array of objects
|
2936
|
+
*/
|
2023
2937
|
async nextPage(size, offset) {
|
2024
2938
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
2025
2939
|
return new _RecordArray(newPage);
|
2026
2940
|
}
|
2941
|
+
/**
|
2942
|
+
* Retrieve previous page of records
|
2943
|
+
*
|
2944
|
+
* @returns A new array of objects
|
2945
|
+
*/
|
2027
2946
|
async previousPage(size, offset) {
|
2028
2947
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
2029
2948
|
return new _RecordArray(newPage);
|
2030
2949
|
}
|
2950
|
+
/**
|
2951
|
+
* Retrieve start page of records
|
2952
|
+
*
|
2953
|
+
* @returns A new array of objects
|
2954
|
+
*/
|
2031
2955
|
async startPage(size, offset) {
|
2032
2956
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
2033
2957
|
return new _RecordArray(newPage);
|
2034
2958
|
}
|
2959
|
+
/**
|
2960
|
+
* Retrieve end page of records
|
2961
|
+
*
|
2962
|
+
* @returns A new array of objects
|
2963
|
+
*/
|
2035
2964
|
async endPage(size, offset) {
|
2036
2965
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
2037
2966
|
return new _RecordArray(newPage);
|
2038
2967
|
}
|
2968
|
+
/**
|
2969
|
+
* @returns Boolean indicating if there is a next page
|
2970
|
+
*/
|
2039
2971
|
hasNextPage() {
|
2040
2972
|
return __privateGet$6(this, _page).meta.page.more;
|
2041
2973
|
}
|
2042
2974
|
};
|
2043
|
-
let RecordArray = _RecordArray;
|
2044
2975
|
_page = new WeakMap();
|
2976
|
+
let RecordArray = _RecordArray;
|
2045
2977
|
|
2046
2978
|
var __accessCheck$5 = (obj, member, msg) => {
|
2047
2979
|
if (!member.has(obj))
|
@@ -2066,13 +2998,14 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2066
2998
|
return method;
|
2067
2999
|
};
|
2068
3000
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2069
|
-
const _Query = class {
|
3001
|
+
const _Query = class _Query {
|
2070
3002
|
constructor(repository, table, data, rawParent) {
|
2071
3003
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2072
3004
|
__privateAdd$5(this, _table$1, void 0);
|
2073
3005
|
__privateAdd$5(this, _repository, void 0);
|
2074
3006
|
__privateAdd$5(this, _data, { filter: {} });
|
2075
|
-
|
3007
|
+
// Implements pagination
|
3008
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
2076
3009
|
this.records = new RecordArray(this, []);
|
2077
3010
|
__privateSet$5(this, _table$1, table);
|
2078
3011
|
if (repository) {
|
@@ -2109,18 +3042,38 @@ const _Query = class {
|
|
2109
3042
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2110
3043
|
return toBase64(key);
|
2111
3044
|
}
|
3045
|
+
/**
|
3046
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3047
|
+
* @param queries An array of subqueries.
|
3048
|
+
* @returns A new Query object.
|
3049
|
+
*/
|
2112
3050
|
any(...queries) {
|
2113
3051
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2114
3052
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2115
3053
|
}
|
3054
|
+
/**
|
3055
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3056
|
+
* @param queries An array of subqueries.
|
3057
|
+
* @returns A new Query object.
|
3058
|
+
*/
|
2116
3059
|
all(...queries) {
|
2117
3060
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2118
3061
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2119
3062
|
}
|
3063
|
+
/**
|
3064
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3065
|
+
* @param queries An array of subqueries.
|
3066
|
+
* @returns A new Query object.
|
3067
|
+
*/
|
2120
3068
|
not(...queries) {
|
2121
3069
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2122
3070
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2123
3071
|
}
|
3072
|
+
/**
|
3073
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3074
|
+
* @param queries An array of subqueries.
|
3075
|
+
* @returns A new Query object.
|
3076
|
+
*/
|
2124
3077
|
none(...queries) {
|
2125
3078
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2126
3079
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2143,6 +3096,11 @@ const _Query = class {
|
|
2143
3096
|
const sort = [...originalSort, { column, direction }];
|
2144
3097
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2145
3098
|
}
|
3099
|
+
/**
|
3100
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3101
|
+
* @param columns Array of column names to be returned by the query.
|
3102
|
+
* @returns A new Query object.
|
3103
|
+
*/
|
2146
3104
|
select(columns) {
|
2147
3105
|
return new _Query(
|
2148
3106
|
__privateGet$5(this, _repository),
|
@@ -2155,6 +3113,12 @@ const _Query = class {
|
|
2155
3113
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2156
3114
|
return __privateGet$5(this, _repository).query(query);
|
2157
3115
|
}
|
3116
|
+
/**
|
3117
|
+
* Get results in an iterator
|
3118
|
+
*
|
3119
|
+
* @async
|
3120
|
+
* @returns Async interable of results
|
3121
|
+
*/
|
2158
3122
|
async *[Symbol.asyncIterator]() {
|
2159
3123
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2160
3124
|
yield record;
|
@@ -2215,26 +3179,53 @@ const _Query = class {
|
|
2215
3179
|
);
|
2216
3180
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2217
3181
|
}
|
3182
|
+
/**
|
3183
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3184
|
+
* @param ttl The cache TTL in milliseconds.
|
3185
|
+
* @returns A new Query object.
|
3186
|
+
*/
|
2218
3187
|
cache(ttl) {
|
2219
3188
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2220
3189
|
}
|
3190
|
+
/**
|
3191
|
+
* Retrieve next page of records
|
3192
|
+
*
|
3193
|
+
* @returns A new page object.
|
3194
|
+
*/
|
2221
3195
|
nextPage(size, offset) {
|
2222
3196
|
return this.startPage(size, offset);
|
2223
3197
|
}
|
3198
|
+
/**
|
3199
|
+
* Retrieve previous page of records
|
3200
|
+
*
|
3201
|
+
* @returns A new page object
|
3202
|
+
*/
|
2224
3203
|
previousPage(size, offset) {
|
2225
3204
|
return this.startPage(size, offset);
|
2226
3205
|
}
|
3206
|
+
/**
|
3207
|
+
* Retrieve start page of records
|
3208
|
+
*
|
3209
|
+
* @returns A new page object
|
3210
|
+
*/
|
2227
3211
|
startPage(size, offset) {
|
2228
3212
|
return this.getPaginated({ pagination: { size, offset } });
|
2229
3213
|
}
|
3214
|
+
/**
|
3215
|
+
* Retrieve last page of records
|
3216
|
+
*
|
3217
|
+
* @returns A new page object
|
3218
|
+
*/
|
2230
3219
|
endPage(size, offset) {
|
2231
3220
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2232
3221
|
}
|
3222
|
+
/**
|
3223
|
+
* @returns Boolean indicating if there is a next page
|
3224
|
+
*/
|
2233
3225
|
hasNextPage() {
|
2234
3226
|
return this.meta.page.more;
|
2235
3227
|
}
|
2236
3228
|
};
|
2237
|
-
let Query = _Query;
|
2238
3229
|
_table$1 = new WeakMap();
|
2239
3230
|
_repository = new WeakMap();
|
2240
3231
|
_data = new WeakMap();
|
@@ -2249,6 +3240,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2249
3240
|
}
|
2250
3241
|
return value;
|
2251
3242
|
};
|
3243
|
+
let Query = _Query;
|
2252
3244
|
function cleanParent(data, parent) {
|
2253
3245
|
if (isCursorPaginationOptions(data.pagination)) {
|
2254
3246
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2256,6 +3248,22 @@ function cleanParent(data, parent) {
|
|
2256
3248
|
return parent;
|
2257
3249
|
}
|
2258
3250
|
|
3251
|
+
const RecordColumnTypes = [
|
3252
|
+
"bool",
|
3253
|
+
"int",
|
3254
|
+
"float",
|
3255
|
+
"string",
|
3256
|
+
"text",
|
3257
|
+
"email",
|
3258
|
+
"multiple",
|
3259
|
+
"link",
|
3260
|
+
"object",
|
3261
|
+
"datetime",
|
3262
|
+
"vector",
|
3263
|
+
"file[]",
|
3264
|
+
"file",
|
3265
|
+
"json"
|
3266
|
+
];
|
2259
3267
|
function isIdentifiable(x) {
|
2260
3268
|
return isObject(x) && isString(x?.id);
|
2261
3269
|
}
|
@@ -2265,11 +3273,33 @@ function isXataRecord(x) {
|
|
2265
3273
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2266
3274
|
}
|
2267
3275
|
|
3276
|
+
function isValidExpandedColumn(column) {
|
3277
|
+
return isObject(column) && isString(column.name);
|
3278
|
+
}
|
3279
|
+
function isValidSelectableColumns(columns) {
|
3280
|
+
if (!Array.isArray(columns)) {
|
3281
|
+
return false;
|
3282
|
+
}
|
3283
|
+
return columns.every((column) => {
|
3284
|
+
if (typeof column === "string") {
|
3285
|
+
return true;
|
3286
|
+
}
|
3287
|
+
if (typeof column === "object") {
|
3288
|
+
return isValidExpandedColumn(column);
|
3289
|
+
}
|
3290
|
+
return false;
|
3291
|
+
});
|
3292
|
+
}
|
3293
|
+
|
2268
3294
|
function isSortFilterString(value) {
|
2269
3295
|
return isString(value);
|
2270
3296
|
}
|
2271
3297
|
function isSortFilterBase(filter) {
|
2272
|
-
return isObject(filter) && Object.
|
3298
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3299
|
+
if (key === "*")
|
3300
|
+
return value === "random";
|
3301
|
+
return value === "asc" || value === "desc";
|
3302
|
+
});
|
2273
3303
|
}
|
2274
3304
|
function isSortFilterObject(filter) {
|
2275
3305
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2310,7 +3340,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2310
3340
|
__accessCheck$4(obj, member, "access private method");
|
2311
3341
|
return method;
|
2312
3342
|
};
|
2313
|
-
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;
|
3343
|
+
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, _transformObjectToApi, transformObjectToApi_fn;
|
2314
3344
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2315
3345
|
class Repository extends Query {
|
2316
3346
|
}
|
@@ -2332,6 +3362,7 @@ class RestRepository extends Query {
|
|
2332
3362
|
__privateAdd$4(this, _setCacheQuery);
|
2333
3363
|
__privateAdd$4(this, _getCacheQuery);
|
2334
3364
|
__privateAdd$4(this, _getSchemaTables$1);
|
3365
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2335
3366
|
__privateAdd$4(this, _table, void 0);
|
2336
3367
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2337
3368
|
__privateAdd$4(this, _db, void 0);
|
@@ -2342,10 +3373,7 @@ class RestRepository extends Query {
|
|
2342
3373
|
__privateSet$4(this, _db, options.db);
|
2343
3374
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2344
3375
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2345
|
-
__privateSet$4(this, _getFetchProps,
|
2346
|
-
const props = await options.pluginOptions.getFetchProps();
|
2347
|
-
return { ...props, sessionID: generateUUID() };
|
2348
|
-
});
|
3376
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2349
3377
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2350
3378
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2351
3379
|
return trace(name, fn, {
|
@@ -2363,24 +3391,24 @@ class RestRepository extends Query {
|
|
2363
3391
|
if (a.length === 0)
|
2364
3392
|
return [];
|
2365
3393
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2366
|
-
const columns =
|
3394
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2367
3395
|
const result = await this.read(ids, columns);
|
2368
3396
|
return result;
|
2369
3397
|
}
|
2370
3398
|
if (isString(a) && isObject(b)) {
|
2371
3399
|
if (a === "")
|
2372
3400
|
throw new Error("The id can't be empty");
|
2373
|
-
const columns =
|
3401
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2374
3402
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2375
3403
|
}
|
2376
3404
|
if (isObject(a) && isString(a.id)) {
|
2377
3405
|
if (a.id === "")
|
2378
3406
|
throw new Error("The id can't be empty");
|
2379
|
-
const columns =
|
3407
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2380
3408
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2381
3409
|
}
|
2382
3410
|
if (isObject(a)) {
|
2383
|
-
const columns =
|
3411
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2384
3412
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2385
3413
|
}
|
2386
3414
|
throw new Error("Invalid arguments for create method");
|
@@ -2388,7 +3416,7 @@ class RestRepository extends Query {
|
|
2388
3416
|
}
|
2389
3417
|
async read(a, b) {
|
2390
3418
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2391
|
-
const columns =
|
3419
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2392
3420
|
if (Array.isArray(a)) {
|
2393
3421
|
if (a.length === 0)
|
2394
3422
|
return [];
|
@@ -2402,7 +3430,6 @@ class RestRepository extends Query {
|
|
2402
3430
|
}
|
2403
3431
|
const id = extractId(a);
|
2404
3432
|
if (id) {
|
2405
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2406
3433
|
try {
|
2407
3434
|
const response = await getRecord({
|
2408
3435
|
pathParams: {
|
@@ -2413,10 +3440,16 @@ class RestRepository extends Query {
|
|
2413
3440
|
recordId: id
|
2414
3441
|
},
|
2415
3442
|
queryParams: { columns },
|
2416
|
-
...
|
3443
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2417
3444
|
});
|
2418
3445
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2419
|
-
return initObject(
|
3446
|
+
return initObject(
|
3447
|
+
__privateGet$4(this, _db),
|
3448
|
+
schemaTables,
|
3449
|
+
__privateGet$4(this, _table),
|
3450
|
+
response,
|
3451
|
+
columns
|
3452
|
+
);
|
2420
3453
|
} catch (e) {
|
2421
3454
|
if (isObject(e) && e.status === 404) {
|
2422
3455
|
return null;
|
@@ -2458,17 +3491,17 @@ class RestRepository extends Query {
|
|
2458
3491
|
ifVersion,
|
2459
3492
|
upsert: false
|
2460
3493
|
});
|
2461
|
-
const columns =
|
3494
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2462
3495
|
const result = await this.read(a, columns);
|
2463
3496
|
return result;
|
2464
3497
|
}
|
2465
3498
|
try {
|
2466
3499
|
if (isString(a) && isObject(b)) {
|
2467
|
-
const columns =
|
3500
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2468
3501
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2469
3502
|
}
|
2470
3503
|
if (isObject(a) && isString(a.id)) {
|
2471
|
-
const columns =
|
3504
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2472
3505
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2473
3506
|
}
|
2474
3507
|
} catch (error) {
|
@@ -2508,17 +3541,27 @@ class RestRepository extends Query {
|
|
2508
3541
|
ifVersion,
|
2509
3542
|
upsert: true
|
2510
3543
|
});
|
2511
|
-
const columns =
|
3544
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2512
3545
|
const result = await this.read(a, columns);
|
2513
3546
|
return result;
|
2514
3547
|
}
|
2515
3548
|
if (isString(a) && isObject(b)) {
|
2516
|
-
|
2517
|
-
|
3549
|
+
if (a === "")
|
3550
|
+
throw new Error("The id can't be empty");
|
3551
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3552
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2518
3553
|
}
|
2519
3554
|
if (isObject(a) && isString(a.id)) {
|
2520
|
-
|
2521
|
-
|
3555
|
+
if (a.id === "")
|
3556
|
+
throw new Error("The id can't be empty");
|
3557
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3558
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3559
|
+
}
|
3560
|
+
if (!isDefined(a) && isObject(b)) {
|
3561
|
+
return await this.create(b, c);
|
3562
|
+
}
|
3563
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3564
|
+
return await this.create(a, b);
|
2522
3565
|
}
|
2523
3566
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2524
3567
|
});
|
@@ -2530,17 +3573,27 @@ class RestRepository extends Query {
|
|
2530
3573
|
if (a.length === 0)
|
2531
3574
|
return [];
|
2532
3575
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2533
|
-
const columns =
|
3576
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2534
3577
|
const result = await this.read(ids, columns);
|
2535
3578
|
return result;
|
2536
3579
|
}
|
2537
3580
|
if (isString(a) && isObject(b)) {
|
2538
|
-
|
2539
|
-
|
3581
|
+
if (a === "")
|
3582
|
+
throw new Error("The id can't be empty");
|
3583
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3584
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2540
3585
|
}
|
2541
3586
|
if (isObject(a) && isString(a.id)) {
|
2542
|
-
|
2543
|
-
|
3587
|
+
if (a.id === "")
|
3588
|
+
throw new Error("The id can't be empty");
|
3589
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3590
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3591
|
+
}
|
3592
|
+
if (!isDefined(a) && isObject(b)) {
|
3593
|
+
return await this.create(b, c);
|
3594
|
+
}
|
3595
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3596
|
+
return await this.create(a, b);
|
2544
3597
|
}
|
2545
3598
|
throw new Error("Invalid arguments for createOrReplace method");
|
2546
3599
|
});
|
@@ -2557,7 +3610,7 @@ class RestRepository extends Query {
|
|
2557
3610
|
return o.id;
|
2558
3611
|
throw new Error("Invalid arguments for delete method");
|
2559
3612
|
});
|
2560
|
-
const columns =
|
3613
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2561
3614
|
const result = await this.read(a, columns);
|
2562
3615
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2563
3616
|
return result;
|
@@ -2591,8 +3644,7 @@ class RestRepository extends Query {
|
|
2591
3644
|
}
|
2592
3645
|
async search(query, options = {}) {
|
2593
3646
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2594
|
-
const
|
2595
|
-
const { records } = await searchTable({
|
3647
|
+
const { records, totalCount } = await searchTable({
|
2596
3648
|
pathParams: {
|
2597
3649
|
workspace: "{workspaceId}",
|
2598
3650
|
dbBranchName: "{dbBranch}",
|
@@ -2609,15 +3661,42 @@ class RestRepository extends Query {
|
|
2609
3661
|
page: options.page,
|
2610
3662
|
target: options.target
|
2611
3663
|
},
|
2612
|
-
...
|
3664
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3665
|
+
});
|
3666
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3667
|
+
return {
|
3668
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3669
|
+
totalCount
|
3670
|
+
};
|
3671
|
+
});
|
3672
|
+
}
|
3673
|
+
async vectorSearch(column, query, options) {
|
3674
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3675
|
+
const { records, totalCount } = await vectorSearchTable({
|
3676
|
+
pathParams: {
|
3677
|
+
workspace: "{workspaceId}",
|
3678
|
+
dbBranchName: "{dbBranch}",
|
3679
|
+
region: "{region}",
|
3680
|
+
tableName: __privateGet$4(this, _table)
|
3681
|
+
},
|
3682
|
+
body: {
|
3683
|
+
column,
|
3684
|
+
queryVector: query,
|
3685
|
+
similarityFunction: options?.similarityFunction,
|
3686
|
+
size: options?.size,
|
3687
|
+
filter: options?.filter
|
3688
|
+
},
|
3689
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2613
3690
|
});
|
2614
3691
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2615
|
-
return
|
3692
|
+
return {
|
3693
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3694
|
+
totalCount
|
3695
|
+
};
|
2616
3696
|
});
|
2617
3697
|
}
|
2618
3698
|
async aggregate(aggs, filter) {
|
2619
3699
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2620
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2621
3700
|
const result = await aggregateTable({
|
2622
3701
|
pathParams: {
|
2623
3702
|
workspace: "{workspaceId}",
|
@@ -2626,7 +3705,7 @@ class RestRepository extends Query {
|
|
2626
3705
|
tableName: __privateGet$4(this, _table)
|
2627
3706
|
},
|
2628
3707
|
body: { aggs, filter },
|
2629
|
-
...
|
3708
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2630
3709
|
});
|
2631
3710
|
return result;
|
2632
3711
|
});
|
@@ -2637,7 +3716,6 @@ class RestRepository extends Query {
|
|
2637
3716
|
if (cacheQuery)
|
2638
3717
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2639
3718
|
const data = query.getQueryOptions();
|
2640
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2641
3719
|
const { meta, records: objects } = await queryTable({
|
2642
3720
|
pathParams: {
|
2643
3721
|
workspace: "{workspaceId}",
|
@@ -2653,11 +3731,17 @@ class RestRepository extends Query {
|
|
2653
3731
|
consistency: data.consistency
|
2654
3732
|
},
|
2655
3733
|
fetchOptions: data.fetchOptions,
|
2656
|
-
...
|
3734
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2657
3735
|
});
|
2658
3736
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2659
3737
|
const records = objects.map(
|
2660
|
-
(record) => initObject(
|
3738
|
+
(record) => initObject(
|
3739
|
+
__privateGet$4(this, _db),
|
3740
|
+
schemaTables,
|
3741
|
+
__privateGet$4(this, _table),
|
3742
|
+
record,
|
3743
|
+
data.columns ?? ["*"]
|
3744
|
+
)
|
2661
3745
|
);
|
2662
3746
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2663
3747
|
return new Page(query, meta, records);
|
@@ -2666,7 +3750,6 @@ class RestRepository extends Query {
|
|
2666
3750
|
async summarizeTable(query, summaries, summariesFilter) {
|
2667
3751
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2668
3752
|
const data = query.getQueryOptions();
|
2669
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2670
3753
|
const result = await summarizeTable({
|
2671
3754
|
pathParams: {
|
2672
3755
|
workspace: "{workspaceId}",
|
@@ -2683,11 +3766,50 @@ class RestRepository extends Query {
|
|
2683
3766
|
summaries,
|
2684
3767
|
summariesFilter
|
2685
3768
|
},
|
2686
|
-
...
|
3769
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2687
3770
|
});
|
2688
|
-
|
3771
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3772
|
+
return {
|
3773
|
+
...result,
|
3774
|
+
summaries: result.summaries.map(
|
3775
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3776
|
+
)
|
3777
|
+
};
|
2689
3778
|
});
|
2690
3779
|
}
|
3780
|
+
ask(question, options) {
|
3781
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3782
|
+
const params = {
|
3783
|
+
pathParams: {
|
3784
|
+
workspace: "{workspaceId}",
|
3785
|
+
dbBranchName: "{dbBranch}",
|
3786
|
+
region: "{region}",
|
3787
|
+
tableName: __privateGet$4(this, _table),
|
3788
|
+
sessionId: options?.sessionId
|
3789
|
+
},
|
3790
|
+
body: {
|
3791
|
+
...questionParam,
|
3792
|
+
rules: options?.rules,
|
3793
|
+
searchType: options?.searchType,
|
3794
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3795
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3796
|
+
},
|
3797
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3798
|
+
};
|
3799
|
+
if (options?.onMessage) {
|
3800
|
+
fetchSSERequest({
|
3801
|
+
endpoint: "dataPlane",
|
3802
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3803
|
+
method: "POST",
|
3804
|
+
onMessage: (message) => {
|
3805
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3806
|
+
},
|
3807
|
+
...params
|
3808
|
+
});
|
3809
|
+
} else {
|
3810
|
+
return askTableSession(params);
|
3811
|
+
}
|
3812
|
+
}
|
2691
3813
|
}
|
2692
3814
|
_table = new WeakMap();
|
2693
3815
|
_getFetchProps = new WeakMap();
|
@@ -2697,8 +3819,7 @@ _schemaTables$2 = new WeakMap();
|
|
2697
3819
|
_trace = new WeakMap();
|
2698
3820
|
_insertRecordWithoutId = new WeakSet();
|
2699
3821
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2700
|
-
const
|
2701
|
-
const record = transformObjectLinks(object);
|
3822
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2702
3823
|
const response = await insertRecord({
|
2703
3824
|
pathParams: {
|
2704
3825
|
workspace: "{workspaceId}",
|
@@ -2708,15 +3829,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2708
3829
|
},
|
2709
3830
|
queryParams: { columns },
|
2710
3831
|
body: record,
|
2711
|
-
...
|
3832
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2712
3833
|
});
|
2713
3834
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2714
3835
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2715
3836
|
};
|
2716
3837
|
_insertRecordWithId = new WeakSet();
|
2717
3838
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2718
|
-
|
2719
|
-
|
3839
|
+
if (!recordId)
|
3840
|
+
return null;
|
3841
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2720
3842
|
const response = await insertRecordWithID({
|
2721
3843
|
pathParams: {
|
2722
3844
|
workspace: "{workspaceId}",
|
@@ -2727,30 +3849,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2727
3849
|
},
|
2728
3850
|
body: record,
|
2729
3851
|
queryParams: { createOnly, columns, ifVersion },
|
2730
|
-
...
|
3852
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2731
3853
|
});
|
2732
3854
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2733
3855
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2734
3856
|
};
|
2735
3857
|
_insertRecords = new WeakSet();
|
2736
3858
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2737
|
-
const
|
2738
|
-
|
2739
|
-
|
2740
|
-
|
2741
|
-
|
2742
|
-
BULK_OPERATION_MAX_SIZE
|
2743
|
-
);
|
3859
|
+
const operations = await promiseMap(objects, async (object) => {
|
3860
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3861
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3862
|
+
});
|
3863
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2744
3864
|
const ids = [];
|
2745
|
-
for (const
|
3865
|
+
for (const operations2 of chunkedOperations) {
|
2746
3866
|
const { results } = await branchTransaction({
|
2747
3867
|
pathParams: {
|
2748
3868
|
workspace: "{workspaceId}",
|
2749
3869
|
dbBranchName: "{dbBranch}",
|
2750
3870
|
region: "{region}"
|
2751
3871
|
},
|
2752
|
-
body: { operations },
|
2753
|
-
...
|
3872
|
+
body: { operations: operations2 },
|
3873
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2754
3874
|
});
|
2755
3875
|
for (const result of results) {
|
2756
3876
|
if (result.operation === "insert") {
|
@@ -2764,8 +3884,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2764
3884
|
};
|
2765
3885
|
_updateRecordWithID = new WeakSet();
|
2766
3886
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2767
|
-
|
2768
|
-
|
3887
|
+
if (!recordId)
|
3888
|
+
return null;
|
3889
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2769
3890
|
try {
|
2770
3891
|
const response = await updateRecordWithID({
|
2771
3892
|
pathParams: {
|
@@ -2777,7 +3898,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2777
3898
|
},
|
2778
3899
|
queryParams: { columns, ifVersion },
|
2779
3900
|
body: record,
|
2780
|
-
...
|
3901
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2781
3902
|
});
|
2782
3903
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2783
3904
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2790,23 +3911,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2790
3911
|
};
|
2791
3912
|
_updateRecords = new WeakSet();
|
2792
3913
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2793
|
-
const
|
2794
|
-
|
2795
|
-
|
2796
|
-
|
2797
|
-
|
2798
|
-
BULK_OPERATION_MAX_SIZE
|
2799
|
-
);
|
3914
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3915
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3916
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3917
|
+
});
|
3918
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2800
3919
|
const ids = [];
|
2801
|
-
for (const
|
3920
|
+
for (const operations2 of chunkedOperations) {
|
2802
3921
|
const { results } = await branchTransaction({
|
2803
3922
|
pathParams: {
|
2804
3923
|
workspace: "{workspaceId}",
|
2805
3924
|
dbBranchName: "{dbBranch}",
|
2806
3925
|
region: "{region}"
|
2807
3926
|
},
|
2808
|
-
body: { operations },
|
2809
|
-
...
|
3927
|
+
body: { operations: operations2 },
|
3928
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2810
3929
|
});
|
2811
3930
|
for (const result of results) {
|
2812
3931
|
if (result.operation === "update") {
|
@@ -2820,7 +3939,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2820
3939
|
};
|
2821
3940
|
_upsertRecordWithID = new WeakSet();
|
2822
3941
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2823
|
-
|
3942
|
+
if (!recordId)
|
3943
|
+
return null;
|
2824
3944
|
const response = await upsertRecordWithID({
|
2825
3945
|
pathParams: {
|
2826
3946
|
workspace: "{workspaceId}",
|
@@ -2831,14 +3951,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2831
3951
|
},
|
2832
3952
|
queryParams: { columns, ifVersion },
|
2833
3953
|
body: object,
|
2834
|
-
...
|
3954
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2835
3955
|
});
|
2836
3956
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2837
3957
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2838
3958
|
};
|
2839
3959
|
_deleteRecord = new WeakSet();
|
2840
3960
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2841
|
-
|
3961
|
+
if (!recordId)
|
3962
|
+
return null;
|
2842
3963
|
try {
|
2843
3964
|
const response = await deleteRecord({
|
2844
3965
|
pathParams: {
|
@@ -2849,7 +3970,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2849
3970
|
recordId
|
2850
3971
|
},
|
2851
3972
|
queryParams: { columns },
|
2852
|
-
...
|
3973
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2853
3974
|
});
|
2854
3975
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2855
3976
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2862,9 +3983,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2862
3983
|
};
|
2863
3984
|
_deleteRecords = new WeakSet();
|
2864
3985
|
deleteRecords_fn = async function(recordIds) {
|
2865
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2866
3986
|
const chunkedOperations = chunk(
|
2867
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3987
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2868
3988
|
BULK_OPERATION_MAX_SIZE
|
2869
3989
|
);
|
2870
3990
|
for (const operations of chunkedOperations) {
|
@@ -2875,21 +3995,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2875
3995
|
region: "{region}"
|
2876
3996
|
},
|
2877
3997
|
body: { operations },
|
2878
|
-
...
|
3998
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2879
3999
|
});
|
2880
4000
|
}
|
2881
4001
|
};
|
2882
4002
|
_setCacheQuery = new WeakSet();
|
2883
4003
|
setCacheQuery_fn = async function(query, meta, records) {
|
2884
|
-
await __privateGet$4(this, _cache)
|
4004
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2885
4005
|
};
|
2886
4006
|
_getCacheQuery = new WeakSet();
|
2887
4007
|
getCacheQuery_fn = async function(query) {
|
2888
4008
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2889
|
-
const result = await __privateGet$4(this, _cache)
|
4009
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2890
4010
|
if (!result)
|
2891
4011
|
return null;
|
2892
|
-
const
|
4012
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4013
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2893
4014
|
if (ttl < 0)
|
2894
4015
|
return null;
|
2895
4016
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2899,20 +4020,47 @@ _getSchemaTables$1 = new WeakSet();
|
|
2899
4020
|
getSchemaTables_fn$1 = async function() {
|
2900
4021
|
if (__privateGet$4(this, _schemaTables$2))
|
2901
4022
|
return __privateGet$4(this, _schemaTables$2);
|
2902
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2903
4023
|
const { schema } = await getBranchDetails({
|
2904
4024
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2905
|
-
...
|
4025
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2906
4026
|
});
|
2907
4027
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2908
4028
|
return schema.tables;
|
2909
4029
|
};
|
2910
|
-
|
2911
|
-
|
4030
|
+
_transformObjectToApi = new WeakSet();
|
4031
|
+
transformObjectToApi_fn = async function(object) {
|
4032
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4033
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4034
|
+
if (!schema)
|
4035
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4036
|
+
const result = {};
|
4037
|
+
for (const [key, value] of Object.entries(object)) {
|
2912
4038
|
if (key === "xata")
|
2913
|
-
|
2914
|
-
|
2915
|
-
|
4039
|
+
continue;
|
4040
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4041
|
+
switch (type) {
|
4042
|
+
case "link": {
|
4043
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4044
|
+
break;
|
4045
|
+
}
|
4046
|
+
case "datetime": {
|
4047
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4048
|
+
break;
|
4049
|
+
}
|
4050
|
+
case `file`:
|
4051
|
+
result[key] = await parseInputFileEntry(value);
|
4052
|
+
break;
|
4053
|
+
case "file[]":
|
4054
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4055
|
+
break;
|
4056
|
+
case "json":
|
4057
|
+
result[key] = stringifyJson(value);
|
4058
|
+
break;
|
4059
|
+
default:
|
4060
|
+
result[key] = value;
|
4061
|
+
}
|
4062
|
+
}
|
4063
|
+
return result;
|
2916
4064
|
};
|
2917
4065
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2918
4066
|
const data = {};
|
@@ -2944,18 +4092,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2944
4092
|
if (item === column.name) {
|
2945
4093
|
return [...acc, "*"];
|
2946
4094
|
}
|
2947
|
-
if (item.startsWith(`${column.name}.`)) {
|
4095
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2948
4096
|
const [, ...path] = item.split(".");
|
2949
4097
|
return [...acc, path.join(".")];
|
2950
4098
|
}
|
2951
4099
|
return acc;
|
2952
4100
|
}, []);
|
2953
|
-
data[column.name] = initObject(
|
4101
|
+
data[column.name] = initObject(
|
4102
|
+
db,
|
4103
|
+
schemaTables,
|
4104
|
+
linkTable,
|
4105
|
+
value,
|
4106
|
+
selectedLinkColumns
|
4107
|
+
);
|
2954
4108
|
} else {
|
2955
4109
|
data[column.name] = null;
|
2956
4110
|
}
|
2957
4111
|
break;
|
2958
4112
|
}
|
4113
|
+
case "file":
|
4114
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4115
|
+
break;
|
4116
|
+
case "file[]":
|
4117
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4118
|
+
break;
|
4119
|
+
case "json":
|
4120
|
+
data[column.name] = parseJson(value);
|
4121
|
+
break;
|
2959
4122
|
default:
|
2960
4123
|
data[column.name] = value ?? null;
|
2961
4124
|
if (column.notNull === true && value === null) {
|
@@ -2965,30 +4128,34 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2965
4128
|
}
|
2966
4129
|
}
|
2967
4130
|
const record = { ...data };
|
4131
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2968
4132
|
record.read = function(columns2) {
|
2969
4133
|
return db[table].read(record["id"], columns2);
|
2970
4134
|
};
|
2971
4135
|
record.update = function(data2, b, c) {
|
2972
|
-
const columns2 =
|
4136
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2973
4137
|
const ifVersion = parseIfVersion(b, c);
|
2974
4138
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2975
4139
|
};
|
2976
4140
|
record.replace = function(data2, b, c) {
|
2977
|
-
const columns2 =
|
4141
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2978
4142
|
const ifVersion = parseIfVersion(b, c);
|
2979
4143
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
2980
4144
|
};
|
2981
4145
|
record.delete = function() {
|
2982
4146
|
return db[table].delete(record["id"]);
|
2983
4147
|
};
|
4148
|
+
if (metadata !== void 0) {
|
4149
|
+
record.xata = Object.freeze(metadata);
|
4150
|
+
}
|
2984
4151
|
record.getMetadata = function() {
|
2985
|
-
return xata;
|
4152
|
+
return record.xata;
|
2986
4153
|
};
|
2987
4154
|
record.toSerializable = function() {
|
2988
|
-
return JSON.parse(JSON.stringify(
|
4155
|
+
return JSON.parse(JSON.stringify(record));
|
2989
4156
|
};
|
2990
4157
|
record.toString = function() {
|
2991
|
-
return JSON.stringify(
|
4158
|
+
return JSON.stringify(record);
|
2992
4159
|
};
|
2993
4160
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2994
4161
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -3006,11 +4173,7 @@ function extractId(value) {
|
|
3006
4173
|
function isValidColumn(columns, column) {
|
3007
4174
|
if (columns.includes("*"))
|
3008
4175
|
return true;
|
3009
|
-
|
3010
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
3011
|
-
return linkColumns.length > 0;
|
3012
|
-
}
|
3013
|
-
return columns.includes(column.name);
|
4176
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
3014
4177
|
}
|
3015
4178
|
function parseIfVersion(...args) {
|
3016
4179
|
for (const arg of args) {
|
@@ -3087,10 +4250,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
3087
4250
|
const startsWith = (value) => ({ $startsWith: value });
|
3088
4251
|
const endsWith = (value) => ({ $endsWith: value });
|
3089
4252
|
const pattern = (value) => ({ $pattern: value });
|
4253
|
+
const iPattern = (value) => ({ $iPattern: value });
|
3090
4254
|
const is = (value) => ({ $is: value });
|
3091
4255
|
const equals = is;
|
3092
4256
|
const isNot = (value) => ({ $isNot: value });
|
3093
4257
|
const contains = (value) => ({ $contains: value });
|
4258
|
+
const iContains = (value) => ({ $iContains: value });
|
3094
4259
|
const includes = (value) => ({ $includes: value });
|
3095
4260
|
const includesAll = (value) => ({ $includesAll: value });
|
3096
4261
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -3146,6 +4311,80 @@ class SchemaPlugin extends XataPlugin {
|
|
3146
4311
|
_tables = new WeakMap();
|
3147
4312
|
_schemaTables$1 = new WeakMap();
|
3148
4313
|
|
4314
|
+
class FilesPlugin extends XataPlugin {
|
4315
|
+
build(pluginOptions) {
|
4316
|
+
return {
|
4317
|
+
download: async (location) => {
|
4318
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4319
|
+
return await getFileItem({
|
4320
|
+
pathParams: {
|
4321
|
+
workspace: "{workspaceId}",
|
4322
|
+
dbBranchName: "{dbBranch}",
|
4323
|
+
region: "{region}",
|
4324
|
+
tableName: table ?? "",
|
4325
|
+
recordId: record ?? "",
|
4326
|
+
columnName: column ?? "",
|
4327
|
+
fileId
|
4328
|
+
},
|
4329
|
+
...pluginOptions,
|
4330
|
+
rawResponse: true
|
4331
|
+
});
|
4332
|
+
},
|
4333
|
+
upload: async (location, file, options) => {
|
4334
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4335
|
+
const resolvedFile = await file;
|
4336
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4337
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4338
|
+
return await putFileItem({
|
4339
|
+
...pluginOptions,
|
4340
|
+
pathParams: {
|
4341
|
+
workspace: "{workspaceId}",
|
4342
|
+
dbBranchName: "{dbBranch}",
|
4343
|
+
region: "{region}",
|
4344
|
+
tableName: table ?? "",
|
4345
|
+
recordId: record ?? "",
|
4346
|
+
columnName: column ?? "",
|
4347
|
+
fileId
|
4348
|
+
},
|
4349
|
+
body,
|
4350
|
+
headers: { "Content-Type": contentType }
|
4351
|
+
});
|
4352
|
+
},
|
4353
|
+
delete: async (location) => {
|
4354
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4355
|
+
return await deleteFileItem({
|
4356
|
+
pathParams: {
|
4357
|
+
workspace: "{workspaceId}",
|
4358
|
+
dbBranchName: "{dbBranch}",
|
4359
|
+
region: "{region}",
|
4360
|
+
tableName: table ?? "",
|
4361
|
+
recordId: record ?? "",
|
4362
|
+
columnName: column ?? "",
|
4363
|
+
fileId
|
4364
|
+
},
|
4365
|
+
...pluginOptions
|
4366
|
+
});
|
4367
|
+
}
|
4368
|
+
};
|
4369
|
+
}
|
4370
|
+
}
|
4371
|
+
function getContentType(file) {
|
4372
|
+
if (typeof file === "string") {
|
4373
|
+
return "text/plain";
|
4374
|
+
}
|
4375
|
+
if ("mediaType" in file) {
|
4376
|
+
return file.mediaType;
|
4377
|
+
}
|
4378
|
+
if (isBlob(file)) {
|
4379
|
+
return file.type;
|
4380
|
+
}
|
4381
|
+
try {
|
4382
|
+
return file.type;
|
4383
|
+
} catch (e) {
|
4384
|
+
}
|
4385
|
+
return "application/octet-stream";
|
4386
|
+
}
|
4387
|
+
|
3149
4388
|
var __accessCheck$1 = (obj, member, msg) => {
|
3150
4389
|
if (!member.has(obj))
|
3151
4390
|
throw TypeError("Cannot " + msg);
|
@@ -3178,63 +4417,137 @@ class SearchPlugin extends XataPlugin {
|
|
3178
4417
|
__privateAdd$1(this, _schemaTables, void 0);
|
3179
4418
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3180
4419
|
}
|
3181
|
-
build(
|
4420
|
+
build(pluginOptions) {
|
3182
4421
|
return {
|
3183
4422
|
all: async (query, options = {}) => {
|
3184
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3185
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3186
|
-
return
|
3187
|
-
|
3188
|
-
|
3189
|
-
|
4423
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4424
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4425
|
+
return {
|
4426
|
+
totalCount,
|
4427
|
+
records: records.map((record) => {
|
4428
|
+
const { table = "orphan" } = record.xata;
|
4429
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4430
|
+
})
|
4431
|
+
};
|
3190
4432
|
},
|
3191
4433
|
byTable: async (query, options = {}) => {
|
3192
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3193
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3194
|
-
|
4434
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4435
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4436
|
+
const records = rawRecords.reduce((acc, record) => {
|
3195
4437
|
const { table = "orphan" } = record.xata;
|
3196
4438
|
const items = acc[table] ?? [];
|
3197
4439
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
3198
4440
|
return { ...acc, [table]: [...items, item] };
|
3199
4441
|
}, {});
|
4442
|
+
return { totalCount, records };
|
3200
4443
|
}
|
3201
4444
|
};
|
3202
4445
|
}
|
3203
4446
|
}
|
3204
4447
|
_schemaTables = new WeakMap();
|
3205
4448
|
_search = new WeakSet();
|
3206
|
-
search_fn = async function(query, options,
|
3207
|
-
const fetchProps = await getFetchProps();
|
4449
|
+
search_fn = async function(query, options, pluginOptions) {
|
3208
4450
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3209
|
-
const { records } = await searchBranch({
|
4451
|
+
const { records, totalCount } = await searchBranch({
|
3210
4452
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4453
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3211
4454
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3212
|
-
...
|
4455
|
+
...pluginOptions
|
3213
4456
|
});
|
3214
|
-
return records;
|
4457
|
+
return { records, totalCount };
|
3215
4458
|
};
|
3216
4459
|
_getSchemaTables = new WeakSet();
|
3217
|
-
getSchemaTables_fn = async function(
|
4460
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3218
4461
|
if (__privateGet$1(this, _schemaTables))
|
3219
4462
|
return __privateGet$1(this, _schemaTables);
|
3220
|
-
const fetchProps = await getFetchProps();
|
3221
4463
|
const { schema } = await getBranchDetails({
|
3222
4464
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3223
|
-
...
|
4465
|
+
...pluginOptions
|
3224
4466
|
});
|
3225
4467
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3226
4468
|
return schema.tables;
|
3227
4469
|
};
|
3228
4470
|
|
4471
|
+
function escapeElement(elementRepresentation) {
|
4472
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4473
|
+
return '"' + escaped + '"';
|
4474
|
+
}
|
4475
|
+
function arrayString(val) {
|
4476
|
+
let result = "{";
|
4477
|
+
for (let i = 0; i < val.length; i++) {
|
4478
|
+
if (i > 0) {
|
4479
|
+
result = result + ",";
|
4480
|
+
}
|
4481
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4482
|
+
result = result + "NULL";
|
4483
|
+
} else if (Array.isArray(val[i])) {
|
4484
|
+
result = result + arrayString(val[i]);
|
4485
|
+
} else if (val[i] instanceof Buffer) {
|
4486
|
+
result += "\\\\x" + val[i].toString("hex");
|
4487
|
+
} else {
|
4488
|
+
result += escapeElement(prepareValue(val[i]));
|
4489
|
+
}
|
4490
|
+
}
|
4491
|
+
result = result + "}";
|
4492
|
+
return result;
|
4493
|
+
}
|
4494
|
+
function prepareValue(value) {
|
4495
|
+
if (!isDefined(value))
|
4496
|
+
return null;
|
4497
|
+
if (value instanceof Date) {
|
4498
|
+
return value.toISOString();
|
4499
|
+
}
|
4500
|
+
if (Array.isArray(value)) {
|
4501
|
+
return arrayString(value);
|
4502
|
+
}
|
4503
|
+
if (isObject(value)) {
|
4504
|
+
return JSON.stringify(value);
|
4505
|
+
}
|
4506
|
+
try {
|
4507
|
+
return value.toString();
|
4508
|
+
} catch (e) {
|
4509
|
+
return value;
|
4510
|
+
}
|
4511
|
+
}
|
4512
|
+
function prepareParams(param1, param2) {
|
4513
|
+
if (isString(param1)) {
|
4514
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4515
|
+
}
|
4516
|
+
if (isStringArray(param1)) {
|
4517
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4518
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4519
|
+
}, "");
|
4520
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4521
|
+
}
|
4522
|
+
if (isObject(param1)) {
|
4523
|
+
const { statement, params, consistency } = param1;
|
4524
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4525
|
+
}
|
4526
|
+
throw new Error("Invalid query");
|
4527
|
+
}
|
4528
|
+
|
4529
|
+
class SQLPlugin extends XataPlugin {
|
4530
|
+
build(pluginOptions) {
|
4531
|
+
return async (param1, ...param2) => {
|
4532
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4533
|
+
const { records, warning } = await sqlQuery({
|
4534
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4535
|
+
body: { statement, params, consistency },
|
4536
|
+
...pluginOptions
|
4537
|
+
});
|
4538
|
+
return { records, warning };
|
4539
|
+
};
|
4540
|
+
}
|
4541
|
+
}
|
4542
|
+
|
3229
4543
|
class TransactionPlugin extends XataPlugin {
|
3230
|
-
build(
|
4544
|
+
build(pluginOptions) {
|
3231
4545
|
return {
|
3232
4546
|
run: async (operations) => {
|
3233
|
-
const fetchProps = await getFetchProps();
|
3234
4547
|
const response = await branchTransaction({
|
3235
4548
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3236
4549
|
body: { operations },
|
3237
|
-
...
|
4550
|
+
...pluginOptions
|
3238
4551
|
});
|
3239
4552
|
return response;
|
3240
4553
|
}
|
@@ -3242,91 +4555,6 @@ class TransactionPlugin extends XataPlugin {
|
|
3242
4555
|
}
|
3243
4556
|
}
|
3244
4557
|
|
3245
|
-
const isBranchStrategyBuilder = (strategy) => {
|
3246
|
-
return typeof strategy === "function";
|
3247
|
-
};
|
3248
|
-
|
3249
|
-
async function getCurrentBranchName(options) {
|
3250
|
-
const { branch, envBranch } = getEnvironment();
|
3251
|
-
if (branch)
|
3252
|
-
return branch;
|
3253
|
-
const gitBranch = envBranch || await getGitBranch();
|
3254
|
-
return resolveXataBranch(gitBranch, options);
|
3255
|
-
}
|
3256
|
-
async function getCurrentBranchDetails(options) {
|
3257
|
-
const branch = await getCurrentBranchName(options);
|
3258
|
-
return getDatabaseBranch(branch, options);
|
3259
|
-
}
|
3260
|
-
async function resolveXataBranch(gitBranch, options) {
|
3261
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3262
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3263
|
-
if (!databaseURL)
|
3264
|
-
throw new Error(
|
3265
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3266
|
-
);
|
3267
|
-
if (!apiKey)
|
3268
|
-
throw new Error(
|
3269
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3270
|
-
);
|
3271
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3272
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3273
|
-
if (!urlParts)
|
3274
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3275
|
-
const { workspace, region } = urlParts;
|
3276
|
-
const { fallbackBranch } = getEnvironment();
|
3277
|
-
const { branch } = await resolveBranch({
|
3278
|
-
apiKey,
|
3279
|
-
apiUrl: databaseURL,
|
3280
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3281
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3282
|
-
pathParams: { dbName, workspace, region },
|
3283
|
-
queryParams: { gitBranch, fallbackBranch },
|
3284
|
-
trace: defaultTrace,
|
3285
|
-
clientName: options?.clientName,
|
3286
|
-
xataAgentExtra: options?.xataAgentExtra
|
3287
|
-
});
|
3288
|
-
return branch;
|
3289
|
-
}
|
3290
|
-
async function getDatabaseBranch(branch, options) {
|
3291
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3292
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3293
|
-
if (!databaseURL)
|
3294
|
-
throw new Error(
|
3295
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3296
|
-
);
|
3297
|
-
if (!apiKey)
|
3298
|
-
throw new Error(
|
3299
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3300
|
-
);
|
3301
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3302
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3303
|
-
if (!urlParts)
|
3304
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3305
|
-
const { workspace, region } = urlParts;
|
3306
|
-
try {
|
3307
|
-
return await getBranchDetails({
|
3308
|
-
apiKey,
|
3309
|
-
apiUrl: databaseURL,
|
3310
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3311
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3312
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3313
|
-
trace: defaultTrace
|
3314
|
-
});
|
3315
|
-
} catch (err) {
|
3316
|
-
if (isObject(err) && err.status === 404)
|
3317
|
-
return null;
|
3318
|
-
throw err;
|
3319
|
-
}
|
3320
|
-
}
|
3321
|
-
function getDatabaseURL() {
|
3322
|
-
try {
|
3323
|
-
const { databaseURL } = getEnvironment();
|
3324
|
-
return databaseURL;
|
3325
|
-
} catch (err) {
|
3326
|
-
return void 0;
|
3327
|
-
}
|
3328
|
-
}
|
3329
|
-
|
3330
4558
|
var __accessCheck = (obj, member, msg) => {
|
3331
4559
|
if (!member.has(obj))
|
3332
4560
|
throw TypeError("Cannot " + msg);
|
@@ -3350,46 +4578,41 @@ var __privateMethod = (obj, member, method) => {
|
|
3350
4578
|
return method;
|
3351
4579
|
};
|
3352
4580
|
const buildClient = (plugins) => {
|
3353
|
-
var
|
4581
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3354
4582
|
return _a = class {
|
3355
4583
|
constructor(options = {}, schemaTables) {
|
3356
4584
|
__privateAdd(this, _parseOptions);
|
3357
4585
|
__privateAdd(this, _getFetchProps);
|
3358
|
-
__privateAdd(this, _evaluateBranch);
|
3359
|
-
__privateAdd(this, _branch, void 0);
|
3360
4586
|
__privateAdd(this, _options, void 0);
|
3361
4587
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3362
4588
|
__privateSet(this, _options, safeOptions);
|
3363
4589
|
const pluginOptions = {
|
3364
|
-
|
4590
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3365
4591
|
cache: safeOptions.cache,
|
3366
|
-
|
4592
|
+
host: safeOptions.host
|
3367
4593
|
};
|
3368
4594
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3369
4595
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3370
4596
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4597
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4598
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3371
4599
|
this.db = db;
|
3372
4600
|
this.search = search;
|
3373
4601
|
this.transactions = transactions;
|
4602
|
+
this.sql = sql;
|
4603
|
+
this.files = files;
|
3374
4604
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3375
4605
|
if (namespace === void 0)
|
3376
4606
|
continue;
|
3377
|
-
|
3378
|
-
if (result instanceof Promise) {
|
3379
|
-
void result.then((namespace2) => {
|
3380
|
-
this[key] = namespace2;
|
3381
|
-
});
|
3382
|
-
} else {
|
3383
|
-
this[key] = result;
|
3384
|
-
}
|
4607
|
+
this[key] = namespace.build(pluginOptions);
|
3385
4608
|
}
|
3386
4609
|
}
|
3387
4610
|
async getConfig() {
|
3388
4611
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3389
|
-
const branch =
|
4612
|
+
const branch = __privateGet(this, _options).branch;
|
3390
4613
|
return { databaseURL, branch };
|
3391
4614
|
}
|
3392
|
-
},
|
4615
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3393
4616
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3394
4617
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3395
4618
|
if (isBrowser && !enableBrowser) {
|
@@ -3403,20 +4626,34 @@ const buildClient = (plugins) => {
|
|
3403
4626
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3404
4627
|
const trace = options?.trace ?? defaultTrace;
|
3405
4628
|
const clientName = options?.clientName;
|
4629
|
+
const host = options?.host ?? "production";
|
3406
4630
|
const xataAgentExtra = options?.xataAgentExtra;
|
3407
|
-
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
|
3408
|
-
apiKey,
|
3409
|
-
databaseURL,
|
3410
|
-
fetchImpl: options?.fetch,
|
3411
|
-
clientName,
|
3412
|
-
xataAgentExtra
|
3413
|
-
});
|
3414
4631
|
if (!apiKey) {
|
3415
4632
|
throw new Error("Option apiKey is required");
|
3416
4633
|
}
|
3417
4634
|
if (!databaseURL) {
|
3418
4635
|
throw new Error("Option databaseURL is required");
|
3419
4636
|
}
|
4637
|
+
const envBranch = getBranch();
|
4638
|
+
const previewBranch = getPreviewBranch();
|
4639
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4640
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4641
|
+
console.warn(
|
4642
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4643
|
+
);
|
4644
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4645
|
+
console.warn(
|
4646
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4647
|
+
);
|
4648
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4649
|
+
console.warn(
|
4650
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4651
|
+
);
|
4652
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4653
|
+
console.warn(
|
4654
|
+
`No branch was passed to the client constructor. Using default branch ${branch}. You can set the branch with the environment variable XATA_BRANCH or by passing the branch option to the client constructor.`
|
4655
|
+
);
|
4656
|
+
}
|
3420
4657
|
return {
|
3421
4658
|
fetch,
|
3422
4659
|
databaseURL,
|
@@ -3424,12 +4661,13 @@ const buildClient = (plugins) => {
|
|
3424
4661
|
branch,
|
3425
4662
|
cache,
|
3426
4663
|
trace,
|
4664
|
+
host,
|
3427
4665
|
clientID: generateUUID(),
|
3428
4666
|
enableBrowser,
|
3429
4667
|
clientName,
|
3430
4668
|
xataAgentExtra
|
3431
4669
|
};
|
3432
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn =
|
4670
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3433
4671
|
fetch,
|
3434
4672
|
apiKey,
|
3435
4673
|
databaseURL,
|
@@ -3439,16 +4677,14 @@ const buildClient = (plugins) => {
|
|
3439
4677
|
clientName,
|
3440
4678
|
xataAgentExtra
|
3441
4679
|
}) {
|
3442
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3443
|
-
if (!branchValue)
|
3444
|
-
throw new Error("Unable to resolve branch value");
|
3445
4680
|
return {
|
3446
|
-
|
4681
|
+
fetch,
|
3447
4682
|
apiKey,
|
3448
4683
|
apiUrl: "",
|
4684
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3449
4685
|
workspacesApiUrl: (path, params) => {
|
3450
4686
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3451
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4687
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3452
4688
|
return databaseURL + newPath;
|
3453
4689
|
},
|
3454
4690
|
trace,
|
@@ -3456,22 +4692,6 @@ const buildClient = (plugins) => {
|
|
3456
4692
|
clientName,
|
3457
4693
|
xataAgentExtra
|
3458
4694
|
};
|
3459
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3460
|
-
if (__privateGet(this, _branch))
|
3461
|
-
return __privateGet(this, _branch);
|
3462
|
-
if (param === void 0)
|
3463
|
-
return void 0;
|
3464
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3465
|
-
const evaluateBranch = async (strategy) => {
|
3466
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3467
|
-
};
|
3468
|
-
for await (const strategy of strategies) {
|
3469
|
-
const branch = await evaluateBranch(strategy);
|
3470
|
-
if (branch) {
|
3471
|
-
__privateSet(this, _branch, branch);
|
3472
|
-
return branch;
|
3473
|
-
}
|
3474
|
-
}
|
3475
4695
|
}, _a;
|
3476
4696
|
};
|
3477
4697
|
class BaseClient extends buildClient() {
|
@@ -3544,21 +4764,6 @@ const deserialize = (json) => {
|
|
3544
4764
|
return defaultSerializer.fromJSON(json);
|
3545
4765
|
};
|
3546
4766
|
|
3547
|
-
function buildWorkerRunner(config) {
|
3548
|
-
return function xataWorker(name, worker) {
|
3549
|
-
return async (...args) => {
|
3550
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3551
|
-
const result = await fetch(url, {
|
3552
|
-
method: "POST",
|
3553
|
-
headers: { "Content-Type": "application/json" },
|
3554
|
-
body: serialize({ args })
|
3555
|
-
});
|
3556
|
-
const text = await result.text();
|
3557
|
-
return deserialize(text);
|
3558
|
-
};
|
3559
|
-
};
|
3560
|
-
}
|
3561
|
-
|
3562
4767
|
class XataError extends Error {
|
3563
4768
|
constructor(message, status) {
|
3564
4769
|
super(message);
|
@@ -3568,6 +4773,7 @@ class XataError extends Error {
|
|
3568
4773
|
|
3569
4774
|
exports.BaseClient = BaseClient;
|
3570
4775
|
exports.FetcherError = FetcherError;
|
4776
|
+
exports.FilesPlugin = FilesPlugin;
|
3571
4777
|
exports.Operations = operationsByTag;
|
3572
4778
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
3573
4779
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -3576,31 +4782,41 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
|
3576
4782
|
exports.Page = Page;
|
3577
4783
|
exports.Query = Query;
|
3578
4784
|
exports.RecordArray = RecordArray;
|
4785
|
+
exports.RecordColumnTypes = RecordColumnTypes;
|
3579
4786
|
exports.Repository = Repository;
|
3580
4787
|
exports.RestRepository = RestRepository;
|
4788
|
+
exports.SQLPlugin = SQLPlugin;
|
3581
4789
|
exports.SchemaPlugin = SchemaPlugin;
|
3582
4790
|
exports.SearchPlugin = SearchPlugin;
|
3583
4791
|
exports.Serializer = Serializer;
|
3584
4792
|
exports.SimpleCache = SimpleCache;
|
4793
|
+
exports.TransactionPlugin = TransactionPlugin;
|
3585
4794
|
exports.XataApiClient = XataApiClient;
|
3586
4795
|
exports.XataApiPlugin = XataApiPlugin;
|
3587
4796
|
exports.XataError = XataError;
|
4797
|
+
exports.XataFile = XataFile;
|
3588
4798
|
exports.XataPlugin = XataPlugin;
|
3589
4799
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
3590
4800
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
3591
4801
|
exports.addTableColumn = addTableColumn;
|
3592
4802
|
exports.aggregateTable = aggregateTable;
|
3593
4803
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4804
|
+
exports.applyMigration = applyMigration;
|
4805
|
+
exports.askTable = askTable;
|
4806
|
+
exports.askTableSession = askTableSession;
|
3594
4807
|
exports.branchTransaction = branchTransaction;
|
3595
4808
|
exports.buildClient = buildClient;
|
3596
|
-
exports.
|
4809
|
+
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4810
|
+
exports.buildProviderString = buildProviderString;
|
3597
4811
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
3598
4812
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
3599
4813
|
exports.compareBranchSchemas = compareBranchSchemas;
|
3600
4814
|
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3601
4815
|
exports.compareMigrationRequest = compareMigrationRequest;
|
3602
4816
|
exports.contains = contains;
|
4817
|
+
exports.copyBranch = copyBranch;
|
3603
4818
|
exports.createBranch = createBranch;
|
4819
|
+
exports.createCluster = createCluster;
|
3604
4820
|
exports.createDatabase = createDatabase;
|
3605
4821
|
exports.createMigrationRequest = createMigrationRequest;
|
3606
4822
|
exports.createTable = createTable;
|
@@ -3610,18 +4826,25 @@ exports.deleteBranch = deleteBranch;
|
|
3610
4826
|
exports.deleteColumn = deleteColumn;
|
3611
4827
|
exports.deleteDatabase = deleteDatabase;
|
3612
4828
|
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
4829
|
+
exports.deleteFile = deleteFile;
|
4830
|
+
exports.deleteFileItem = deleteFileItem;
|
4831
|
+
exports.deleteOAuthAccessToken = deleteOAuthAccessToken;
|
3613
4832
|
exports.deleteRecord = deleteRecord;
|
3614
4833
|
exports.deleteTable = deleteTable;
|
3615
4834
|
exports.deleteUser = deleteUser;
|
3616
4835
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
4836
|
+
exports.deleteUserOAuthClient = deleteUserOAuthClient;
|
3617
4837
|
exports.deleteWorkspace = deleteWorkspace;
|
3618
4838
|
exports.deserialize = deserialize;
|
3619
4839
|
exports.endsWith = endsWith;
|
3620
4840
|
exports.equals = equals;
|
3621
4841
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
3622
4842
|
exports.exists = exists;
|
4843
|
+
exports.fileAccess = fileAccess;
|
3623
4844
|
exports.ge = ge;
|
3624
4845
|
exports.getAPIKey = getAPIKey;
|
4846
|
+
exports.getAuthorizationCode = getAuthorizationCode;
|
4847
|
+
exports.getBranch = getBranch;
|
3625
4848
|
exports.getBranchDetails = getBranchDetails;
|
3626
4849
|
exports.getBranchList = getBranchList;
|
3627
4850
|
exports.getBranchMetadata = getBranchMetadata;
|
@@ -3629,30 +4852,38 @@ exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
|
3629
4852
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
3630
4853
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
3631
4854
|
exports.getBranchStats = getBranchStats;
|
4855
|
+
exports.getCluster = getCluster;
|
3632
4856
|
exports.getColumn = getColumn;
|
3633
|
-
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
3634
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
3635
4857
|
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
3636
4858
|
exports.getDatabaseList = getDatabaseList;
|
3637
4859
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
3638
4860
|
exports.getDatabaseURL = getDatabaseURL;
|
4861
|
+
exports.getFile = getFile;
|
4862
|
+
exports.getFileItem = getFileItem;
|
3639
4863
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3640
4864
|
exports.getHostUrl = getHostUrl;
|
3641
4865
|
exports.getMigrationRequest = getMigrationRequest;
|
3642
4866
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4867
|
+
exports.getPreviewBranch = getPreviewBranch;
|
3643
4868
|
exports.getRecord = getRecord;
|
4869
|
+
exports.getSchema = getSchema;
|
3644
4870
|
exports.getTableColumns = getTableColumns;
|
3645
4871
|
exports.getTableSchema = getTableSchema;
|
3646
4872
|
exports.getUser = getUser;
|
3647
4873
|
exports.getUserAPIKeys = getUserAPIKeys;
|
4874
|
+
exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
|
4875
|
+
exports.getUserOAuthClients = getUserOAuthClients;
|
3648
4876
|
exports.getWorkspace = getWorkspace;
|
3649
4877
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
3650
4878
|
exports.getWorkspacesList = getWorkspacesList;
|
4879
|
+
exports.grantAuthorizationCode = grantAuthorizationCode;
|
3651
4880
|
exports.greaterEquals = greaterEquals;
|
3652
4881
|
exports.greaterThan = greaterThan;
|
3653
4882
|
exports.greaterThanEquals = greaterThanEquals;
|
3654
4883
|
exports.gt = gt;
|
3655
4884
|
exports.gte = gte;
|
4885
|
+
exports.iContains = iContains;
|
4886
|
+
exports.iPattern = iPattern;
|
3656
4887
|
exports.includes = includes;
|
3657
4888
|
exports.includesAll = includesAll;
|
3658
4889
|
exports.includesAny = includesAny;
|
@@ -3666,11 +4897,14 @@ exports.isHostProviderAlias = isHostProviderAlias;
|
|
3666
4897
|
exports.isHostProviderBuilder = isHostProviderBuilder;
|
3667
4898
|
exports.isIdentifiable = isIdentifiable;
|
3668
4899
|
exports.isNot = isNot;
|
4900
|
+
exports.isValidExpandedColumn = isValidExpandedColumn;
|
4901
|
+
exports.isValidSelectableColumns = isValidSelectableColumns;
|
3669
4902
|
exports.isXataRecord = isXataRecord;
|
3670
4903
|
exports.le = le;
|
3671
4904
|
exports.lessEquals = lessEquals;
|
3672
4905
|
exports.lessThan = lessThan;
|
3673
4906
|
exports.lessThanEquals = lessThanEquals;
|
4907
|
+
exports.listClusters = listClusters;
|
3674
4908
|
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
3675
4909
|
exports.listRegions = listRegions;
|
3676
4910
|
exports.lt = lt;
|
@@ -3681,25 +4915,34 @@ exports.operationsByTag = operationsByTag;
|
|
3681
4915
|
exports.parseProviderString = parseProviderString;
|
3682
4916
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
3683
4917
|
exports.pattern = pattern;
|
4918
|
+
exports.pgRollStatus = pgRollStatus;
|
3684
4919
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4920
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
4921
|
+
exports.putFile = putFile;
|
4922
|
+
exports.putFileItem = putFileItem;
|
3685
4923
|
exports.queryMigrationRequests = queryMigrationRequests;
|
3686
4924
|
exports.queryTable = queryTable;
|
3687
4925
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
3688
4926
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
4927
|
+
exports.renameDatabase = renameDatabase;
|
3689
4928
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
3690
4929
|
exports.resolveBranch = resolveBranch;
|
3691
4930
|
exports.searchBranch = searchBranch;
|
3692
4931
|
exports.searchTable = searchTable;
|
3693
4932
|
exports.serialize = serialize;
|
3694
4933
|
exports.setTableSchema = setTableSchema;
|
4934
|
+
exports.sqlQuery = sqlQuery;
|
3695
4935
|
exports.startsWith = startsWith;
|
3696
4936
|
exports.summarizeTable = summarizeTable;
|
4937
|
+
exports.transformImage = transformImage;
|
3697
4938
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3698
4939
|
exports.updateBranchSchema = updateBranchSchema;
|
4940
|
+
exports.updateCluster = updateCluster;
|
3699
4941
|
exports.updateColumn = updateColumn;
|
3700
4942
|
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3701
4943
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3702
4944
|
exports.updateMigrationRequest = updateMigrationRequest;
|
4945
|
+
exports.updateOAuthAccessToken = updateOAuthAccessToken;
|
3703
4946
|
exports.updateRecordWithID = updateRecordWithID;
|
3704
4947
|
exports.updateTable = updateTable;
|
3705
4948
|
exports.updateUser = updateUser;
|
@@ -3707,4 +4950,5 @@ exports.updateWorkspace = updateWorkspace;
|
|
3707
4950
|
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
3708
4951
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
3709
4952
|
exports.upsertRecordWithID = upsertRecordWithID;
|
4953
|
+
exports.vectorSearchTable = vectorSearchTable;
|
3710
4954
|
//# sourceMappingURL=index.cjs.map
|