@xata.io/client 0.0.0-alpha.vf59e81b → 0.0.0-alpha.vf5a2120
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 +201 -3
- package/README.md +1 -274
- package/dist/index.cjs +1679 -195
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2154 -337
- package/dist/index.mjs +1645 -196
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/.eslintrc.cjs +0 -13
- package/Usage.md +0 -451
- package/rollup.config.mjs +0 -44
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -18,7 +18,8 @@ const TraceAttributes = {
|
|
18
18
|
HTTP_METHOD: "http.method",
|
19
19
|
HTTP_URL: "http.url",
|
20
20
|
HTTP_ROUTE: "http.route",
|
21
|
-
HTTP_TARGET: "http.target"
|
21
|
+
HTTP_TARGET: "http.target",
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
22
23
|
};
|
23
24
|
|
24
25
|
function notEmpty(value) {
|
@@ -27,8 +28,18 @@ function notEmpty(value) {
|
|
27
28
|
function compact(arr) {
|
28
29
|
return arr.filter(notEmpty);
|
29
30
|
}
|
31
|
+
function compactObject(obj) {
|
32
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
33
|
+
}
|
34
|
+
function isBlob(value) {
|
35
|
+
try {
|
36
|
+
return value instanceof Blob;
|
37
|
+
} catch (error) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
}
|
30
41
|
function isObject(value) {
|
31
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
32
43
|
}
|
33
44
|
function isDefined(value) {
|
34
45
|
return value !== null && value !== void 0;
|
@@ -83,6 +94,27 @@ function chunk(array, chunkSize) {
|
|
83
94
|
async function timeout(ms) {
|
84
95
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
85
96
|
}
|
97
|
+
function timeoutWithCancel(ms) {
|
98
|
+
let timeoutId;
|
99
|
+
const promise = new Promise((resolve) => {
|
100
|
+
timeoutId = setTimeout(() => {
|
101
|
+
resolve();
|
102
|
+
}, ms);
|
103
|
+
});
|
104
|
+
return {
|
105
|
+
cancel: () => clearTimeout(timeoutId),
|
106
|
+
promise
|
107
|
+
};
|
108
|
+
}
|
109
|
+
function promiseMap(inputValues, mapper) {
|
110
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
111
|
+
(acc) => mapper(inputValue).then((result) => {
|
112
|
+
acc.push(result);
|
113
|
+
return acc;
|
114
|
+
})
|
115
|
+
);
|
116
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
117
|
+
}
|
86
118
|
|
87
119
|
function getEnvironment() {
|
88
120
|
try {
|
@@ -91,8 +123,10 @@ function getEnvironment() {
|
|
91
123
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
92
124
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
93
125
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
94
|
-
|
95
|
-
|
126
|
+
deployPreview: process.env.XATA_PREVIEW,
|
127
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
128
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
129
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
96
130
|
};
|
97
131
|
}
|
98
132
|
} catch (err) {
|
@@ -103,8 +137,10 @@ function getEnvironment() {
|
|
103
137
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
104
138
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
105
139
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
106
|
-
|
107
|
-
|
140
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
141
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
142
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
143
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
108
144
|
};
|
109
145
|
}
|
110
146
|
} catch (err) {
|
@@ -113,8 +149,10 @@ function getEnvironment() {
|
|
113
149
|
apiKey: getGlobalApiKey(),
|
114
150
|
databaseURL: getGlobalDatabaseURL(),
|
115
151
|
branch: getGlobalBranch(),
|
116
|
-
|
117
|
-
|
152
|
+
deployPreview: void 0,
|
153
|
+
deployPreviewBranch: void 0,
|
154
|
+
vercelGitCommitRef: void 0,
|
155
|
+
vercelGitRepoOwner: void 0
|
118
156
|
};
|
119
157
|
}
|
120
158
|
function getEnableBrowserVariable() {
|
@@ -157,13 +195,6 @@ function getGlobalBranch() {
|
|
157
195
|
return void 0;
|
158
196
|
}
|
159
197
|
}
|
160
|
-
function getGlobalFallbackBranch() {
|
161
|
-
try {
|
162
|
-
return XATA_FALLBACK_BRANCH;
|
163
|
-
} catch (err) {
|
164
|
-
return void 0;
|
165
|
-
}
|
166
|
-
}
|
167
198
|
function getDatabaseURL() {
|
168
199
|
try {
|
169
200
|
const { databaseURL } = getEnvironment();
|
@@ -180,7 +211,43 @@ function getAPIKey() {
|
|
180
211
|
return void 0;
|
181
212
|
}
|
182
213
|
}
|
214
|
+
function getBranch() {
|
215
|
+
try {
|
216
|
+
const { branch } = getEnvironment();
|
217
|
+
return branch;
|
218
|
+
} catch (err) {
|
219
|
+
return void 0;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
function buildPreviewBranchName({ org, branch }) {
|
223
|
+
return `preview-${org}-${branch}`;
|
224
|
+
}
|
225
|
+
function getPreviewBranch() {
|
226
|
+
try {
|
227
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
228
|
+
if (deployPreviewBranch)
|
229
|
+
return deployPreviewBranch;
|
230
|
+
switch (deployPreview) {
|
231
|
+
case "vercel": {
|
232
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
233
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
234
|
+
return void 0;
|
235
|
+
}
|
236
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
237
|
+
}
|
238
|
+
}
|
239
|
+
return void 0;
|
240
|
+
} catch (err) {
|
241
|
+
return void 0;
|
242
|
+
}
|
243
|
+
}
|
183
244
|
|
245
|
+
var __defProp$8 = Object.defineProperty;
|
246
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
247
|
+
var __publicField$8 = (obj, key, value) => {
|
248
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
249
|
+
return value;
|
250
|
+
};
|
184
251
|
var __accessCheck$8 = (obj, member, msg) => {
|
185
252
|
if (!member.has(obj))
|
186
253
|
throw TypeError("Cannot " + msg);
|
@@ -204,13 +271,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
204
271
|
return method;
|
205
272
|
};
|
206
273
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
274
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
207
275
|
function getFetchImplementation(userFetch) {
|
208
276
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
209
|
-
const
|
277
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
278
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
210
279
|
if (!fetchImpl) {
|
211
|
-
throw new Error(
|
212
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
213
|
-
);
|
280
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
214
281
|
}
|
215
282
|
return fetchImpl;
|
216
283
|
}
|
@@ -220,6 +287,8 @@ class ApiRequestPool {
|
|
220
287
|
__privateAdd$8(this, _fetch, void 0);
|
221
288
|
__privateAdd$8(this, _queue, void 0);
|
222
289
|
__privateAdd$8(this, _concurrency, void 0);
|
290
|
+
__publicField$8(this, "running");
|
291
|
+
__publicField$8(this, "started");
|
223
292
|
__privateSet$8(this, _queue, []);
|
224
293
|
__privateSet$8(this, _concurrency, concurrency);
|
225
294
|
this.running = 0;
|
@@ -235,18 +304,22 @@ class ApiRequestPool {
|
|
235
304
|
return __privateGet$8(this, _fetch);
|
236
305
|
}
|
237
306
|
request(url, options) {
|
238
|
-
const start = new Date();
|
239
|
-
const
|
307
|
+
const start = /* @__PURE__ */ new Date();
|
308
|
+
const fetchImpl = this.getFetch();
|
240
309
|
const runRequest = async (stalled = false) => {
|
241
|
-
const
|
310
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
311
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
312
|
+
if (!response) {
|
313
|
+
throw new Error("Request timed out");
|
314
|
+
}
|
242
315
|
if (response.status === 429) {
|
243
316
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
244
317
|
await timeout(rateLimitReset * 1e3);
|
245
318
|
return await runRequest(true);
|
246
319
|
}
|
247
320
|
if (stalled) {
|
248
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
249
|
-
console.warn(`A request to Xata hit
|
321
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
322
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
250
323
|
}
|
251
324
|
return response;
|
252
325
|
};
|
@@ -288,16 +361,199 @@ function generateUUID() {
|
|
288
361
|
});
|
289
362
|
}
|
290
363
|
|
291
|
-
|
364
|
+
async function getBytes(stream, onChunk) {
|
365
|
+
const reader = stream.getReader();
|
366
|
+
let result;
|
367
|
+
while (!(result = await reader.read()).done) {
|
368
|
+
onChunk(result.value);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
function getLines(onLine) {
|
372
|
+
let buffer;
|
373
|
+
let position;
|
374
|
+
let fieldLength;
|
375
|
+
let discardTrailingNewline = false;
|
376
|
+
return function onChunk(arr) {
|
377
|
+
if (buffer === void 0) {
|
378
|
+
buffer = arr;
|
379
|
+
position = 0;
|
380
|
+
fieldLength = -1;
|
381
|
+
} else {
|
382
|
+
buffer = concat(buffer, arr);
|
383
|
+
}
|
384
|
+
const bufLength = buffer.length;
|
385
|
+
let lineStart = 0;
|
386
|
+
while (position < bufLength) {
|
387
|
+
if (discardTrailingNewline) {
|
388
|
+
if (buffer[position] === 10 /* NewLine */) {
|
389
|
+
lineStart = ++position;
|
390
|
+
}
|
391
|
+
discardTrailingNewline = false;
|
392
|
+
}
|
393
|
+
let lineEnd = -1;
|
394
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
395
|
+
switch (buffer[position]) {
|
396
|
+
case 58 /* Colon */:
|
397
|
+
if (fieldLength === -1) {
|
398
|
+
fieldLength = position - lineStart;
|
399
|
+
}
|
400
|
+
break;
|
401
|
+
case 13 /* CarriageReturn */:
|
402
|
+
discardTrailingNewline = true;
|
403
|
+
case 10 /* NewLine */:
|
404
|
+
lineEnd = position;
|
405
|
+
break;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
if (lineEnd === -1) {
|
409
|
+
break;
|
410
|
+
}
|
411
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
412
|
+
lineStart = position;
|
413
|
+
fieldLength = -1;
|
414
|
+
}
|
415
|
+
if (lineStart === bufLength) {
|
416
|
+
buffer = void 0;
|
417
|
+
} else if (lineStart !== 0) {
|
418
|
+
buffer = buffer.subarray(lineStart);
|
419
|
+
position -= lineStart;
|
420
|
+
}
|
421
|
+
};
|
422
|
+
}
|
423
|
+
function getMessages(onId, onRetry, onMessage) {
|
424
|
+
let message = newMessage();
|
425
|
+
const decoder = new TextDecoder();
|
426
|
+
return function onLine(line, fieldLength) {
|
427
|
+
if (line.length === 0) {
|
428
|
+
onMessage?.(message);
|
429
|
+
message = newMessage();
|
430
|
+
} else if (fieldLength > 0) {
|
431
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
432
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
433
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
434
|
+
switch (field) {
|
435
|
+
case "data":
|
436
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
437
|
+
break;
|
438
|
+
case "event":
|
439
|
+
message.event = value;
|
440
|
+
break;
|
441
|
+
case "id":
|
442
|
+
onId(message.id = value);
|
443
|
+
break;
|
444
|
+
case "retry":
|
445
|
+
const retry = parseInt(value, 10);
|
446
|
+
if (!isNaN(retry)) {
|
447
|
+
onRetry(message.retry = retry);
|
448
|
+
}
|
449
|
+
break;
|
450
|
+
}
|
451
|
+
}
|
452
|
+
};
|
453
|
+
}
|
454
|
+
function concat(a, b) {
|
455
|
+
const res = new Uint8Array(a.length + b.length);
|
456
|
+
res.set(a);
|
457
|
+
res.set(b, a.length);
|
458
|
+
return res;
|
459
|
+
}
|
460
|
+
function newMessage() {
|
461
|
+
return {
|
462
|
+
data: "",
|
463
|
+
event: "",
|
464
|
+
id: "",
|
465
|
+
retry: void 0
|
466
|
+
};
|
467
|
+
}
|
468
|
+
const EventStreamContentType = "text/event-stream";
|
469
|
+
const LastEventId = "last-event-id";
|
470
|
+
function fetchEventSource(input, {
|
471
|
+
signal: inputSignal,
|
472
|
+
headers: inputHeaders,
|
473
|
+
onopen: inputOnOpen,
|
474
|
+
onmessage,
|
475
|
+
onclose,
|
476
|
+
onerror,
|
477
|
+
fetch: inputFetch,
|
478
|
+
...rest
|
479
|
+
}) {
|
480
|
+
return new Promise((resolve, reject) => {
|
481
|
+
const headers = { ...inputHeaders };
|
482
|
+
if (!headers.accept) {
|
483
|
+
headers.accept = EventStreamContentType;
|
484
|
+
}
|
485
|
+
let curRequestController;
|
486
|
+
function dispose() {
|
487
|
+
curRequestController.abort();
|
488
|
+
}
|
489
|
+
inputSignal?.addEventListener("abort", () => {
|
490
|
+
dispose();
|
491
|
+
resolve();
|
492
|
+
});
|
493
|
+
const fetchImpl = inputFetch ?? fetch;
|
494
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
495
|
+
async function create() {
|
496
|
+
curRequestController = new AbortController();
|
497
|
+
try {
|
498
|
+
const response = await fetchImpl(input, {
|
499
|
+
...rest,
|
500
|
+
headers,
|
501
|
+
signal: curRequestController.signal
|
502
|
+
});
|
503
|
+
await onopen(response);
|
504
|
+
await getBytes(
|
505
|
+
response.body,
|
506
|
+
getLines(
|
507
|
+
getMessages(
|
508
|
+
(id) => {
|
509
|
+
if (id) {
|
510
|
+
headers[LastEventId] = id;
|
511
|
+
} else {
|
512
|
+
delete headers[LastEventId];
|
513
|
+
}
|
514
|
+
},
|
515
|
+
(_retry) => {
|
516
|
+
},
|
517
|
+
onmessage
|
518
|
+
)
|
519
|
+
)
|
520
|
+
);
|
521
|
+
onclose?.();
|
522
|
+
dispose();
|
523
|
+
resolve();
|
524
|
+
} catch (err) {
|
525
|
+
}
|
526
|
+
}
|
527
|
+
create();
|
528
|
+
});
|
529
|
+
}
|
530
|
+
function defaultOnOpen(response) {
|
531
|
+
const contentType = response.headers?.get("content-type");
|
532
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
533
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
534
|
+
}
|
535
|
+
}
|
536
|
+
|
537
|
+
const VERSION = "0.26.5";
|
292
538
|
|
539
|
+
var __defProp$7 = Object.defineProperty;
|
540
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
541
|
+
var __publicField$7 = (obj, key, value) => {
|
542
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
543
|
+
return value;
|
544
|
+
};
|
293
545
|
class ErrorWithCause extends Error {
|
294
546
|
constructor(message, options) {
|
295
547
|
super(message, options);
|
548
|
+
__publicField$7(this, "cause");
|
296
549
|
}
|
297
550
|
}
|
298
551
|
class FetcherError extends ErrorWithCause {
|
299
552
|
constructor(status, data, requestId) {
|
300
553
|
super(getMessage(data));
|
554
|
+
__publicField$7(this, "status");
|
555
|
+
__publicField$7(this, "requestId");
|
556
|
+
__publicField$7(this, "errors");
|
301
557
|
this.status = status;
|
302
558
|
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
303
559
|
this.requestId = requestId;
|
@@ -364,6 +620,18 @@ function hostHeader(url) {
|
|
364
620
|
const { groups } = pattern.exec(url) ?? {};
|
365
621
|
return groups?.host ? { Host: groups.host } : {};
|
366
622
|
}
|
623
|
+
async function parseBody(body, headers) {
|
624
|
+
if (!isDefined(body))
|
625
|
+
return void 0;
|
626
|
+
if (isBlob(body) || typeof body.text === "function") {
|
627
|
+
return body;
|
628
|
+
}
|
629
|
+
const { "Content-Type": contentType } = headers ?? {};
|
630
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
631
|
+
return JSON.stringify(body);
|
632
|
+
}
|
633
|
+
return body;
|
634
|
+
}
|
367
635
|
const defaultClientID = generateUUID();
|
368
636
|
async function fetch$1({
|
369
637
|
url: path,
|
@@ -372,7 +640,7 @@ async function fetch$1({
|
|
372
640
|
headers: customHeaders,
|
373
641
|
pathParams,
|
374
642
|
queryParams,
|
375
|
-
|
643
|
+
fetch: fetch2,
|
376
644
|
apiKey,
|
377
645
|
endpoint,
|
378
646
|
apiUrl,
|
@@ -382,9 +650,11 @@ async function fetch$1({
|
|
382
650
|
clientID,
|
383
651
|
sessionID,
|
384
652
|
clientName,
|
385
|
-
|
653
|
+
xataAgentExtra,
|
654
|
+
fetchOptions = {},
|
655
|
+
rawResponse = false
|
386
656
|
}) {
|
387
|
-
pool.setFetch(
|
657
|
+
pool.setFetch(fetch2);
|
388
658
|
return await trace(
|
389
659
|
`${method.toUpperCase()} ${path}`,
|
390
660
|
async ({ setAttributes }) => {
|
@@ -398,9 +668,10 @@ async function fetch$1({
|
|
398
668
|
const xataAgent = compact([
|
399
669
|
["client", "TS_SDK"],
|
400
670
|
["version", VERSION],
|
401
|
-
isDefined(clientName) ? ["service", clientName] : void 0
|
671
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
672
|
+
...Object.entries(xataAgentExtra ?? {})
|
402
673
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
403
|
-
const headers = {
|
674
|
+
const headers = compactObject({
|
404
675
|
"Accept-Encoding": "identity",
|
405
676
|
"Content-Type": "application/json",
|
406
677
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
@@ -409,11 +680,11 @@ async function fetch$1({
|
|
409
680
|
...customHeaders,
|
410
681
|
...hostHeader(fullUrl),
|
411
682
|
Authorization: `Bearer ${apiKey}`
|
412
|
-
};
|
683
|
+
});
|
413
684
|
const response = await pool.request(url, {
|
414
685
|
...fetchOptions,
|
415
686
|
method: method.toUpperCase(),
|
416
|
-
body:
|
687
|
+
body: await parseBody(body, headers),
|
417
688
|
headers,
|
418
689
|
signal
|
419
690
|
});
|
@@ -424,8 +695,12 @@ async function fetch$1({
|
|
424
695
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
425
696
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
426
697
|
[TraceAttributes.HTTP_HOST]: host,
|
427
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
698
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
699
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
428
700
|
});
|
701
|
+
const message = response.headers?.get("x-xata-message");
|
702
|
+
if (message)
|
703
|
+
console.warn(message);
|
429
704
|
if (response.status === 204) {
|
430
705
|
return {};
|
431
706
|
}
|
@@ -433,7 +708,7 @@ async function fetch$1({
|
|
433
708
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
434
709
|
}
|
435
710
|
try {
|
436
|
-
const jsonResponse = await response.json();
|
711
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
437
712
|
if (response.ok) {
|
438
713
|
return jsonResponse;
|
439
714
|
}
|
@@ -445,6 +720,59 @@ async function fetch$1({
|
|
445
720
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
446
721
|
);
|
447
722
|
}
|
723
|
+
function fetchSSERequest({
|
724
|
+
url: path,
|
725
|
+
method,
|
726
|
+
body,
|
727
|
+
headers: customHeaders,
|
728
|
+
pathParams,
|
729
|
+
queryParams,
|
730
|
+
fetch: fetch2,
|
731
|
+
apiKey,
|
732
|
+
endpoint,
|
733
|
+
apiUrl,
|
734
|
+
workspacesApiUrl,
|
735
|
+
onMessage,
|
736
|
+
onError,
|
737
|
+
onClose,
|
738
|
+
signal,
|
739
|
+
clientID,
|
740
|
+
sessionID,
|
741
|
+
clientName,
|
742
|
+
xataAgentExtra
|
743
|
+
}) {
|
744
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
745
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
746
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
747
|
+
void fetchEventSource(url, {
|
748
|
+
method,
|
749
|
+
body: JSON.stringify(body),
|
750
|
+
fetch: fetch2,
|
751
|
+
signal,
|
752
|
+
headers: {
|
753
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
754
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
755
|
+
"X-Xata-Agent": compact([
|
756
|
+
["client", "TS_SDK"],
|
757
|
+
["version", VERSION],
|
758
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
759
|
+
...Object.entries(xataAgentExtra ?? {})
|
760
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
761
|
+
...customHeaders,
|
762
|
+
Authorization: `Bearer ${apiKey}`,
|
763
|
+
"Content-Type": "application/json"
|
764
|
+
},
|
765
|
+
onmessage(ev) {
|
766
|
+
onMessage?.(JSON.parse(ev.data));
|
767
|
+
},
|
768
|
+
onerror(ev) {
|
769
|
+
onError?.(JSON.parse(ev.data));
|
770
|
+
},
|
771
|
+
onclose() {
|
772
|
+
onClose?.();
|
773
|
+
}
|
774
|
+
});
|
775
|
+
}
|
448
776
|
function parseUrl(url) {
|
449
777
|
try {
|
450
778
|
const { host, protocol } = new URL(url);
|
@@ -475,6 +803,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
475
803
|
...variables,
|
476
804
|
signal
|
477
805
|
});
|
806
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
807
|
+
url: "/db/{dbBranchName}/copy",
|
808
|
+
method: "post",
|
809
|
+
...variables,
|
810
|
+
signal
|
811
|
+
});
|
478
812
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
479
813
|
url: "/db/{dbBranchName}/metadata",
|
480
814
|
method: "put",
|
@@ -524,6 +858,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
524
858
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
525
859
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
526
860
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
861
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
527
862
|
const createTable = (variables, signal) => dataPlaneFetch({
|
528
863
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
529
864
|
method: "put",
|
@@ -568,6 +903,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
568
903
|
});
|
569
904
|
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
570
905
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
906
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
907
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
908
|
+
method: "get",
|
909
|
+
...variables,
|
910
|
+
signal
|
911
|
+
});
|
912
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
913
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
914
|
+
method: "put",
|
915
|
+
...variables,
|
916
|
+
signal
|
917
|
+
});
|
918
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
919
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
920
|
+
method: "delete",
|
921
|
+
...variables,
|
922
|
+
signal
|
923
|
+
});
|
924
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
925
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
926
|
+
method: "get",
|
927
|
+
...variables,
|
928
|
+
signal
|
929
|
+
});
|
930
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
931
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
932
|
+
method: "put",
|
933
|
+
...variables,
|
934
|
+
signal
|
935
|
+
});
|
936
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
937
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
938
|
+
method: "delete",
|
939
|
+
...variables,
|
940
|
+
signal
|
941
|
+
});
|
571
942
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
572
943
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
573
944
|
method: "get",
|
@@ -597,14 +968,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
597
968
|
...variables,
|
598
969
|
signal
|
599
970
|
});
|
971
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
972
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
973
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
974
|
+
method: "post",
|
975
|
+
...variables,
|
976
|
+
signal
|
977
|
+
});
|
978
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
600
979
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
601
980
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
981
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
982
|
+
url: "/file/{fileId}",
|
983
|
+
method: "get",
|
984
|
+
...variables,
|
985
|
+
signal
|
986
|
+
});
|
987
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
988
|
+
url: "/db/{dbBranchName}/sql",
|
989
|
+
method: "post",
|
990
|
+
...variables,
|
991
|
+
signal
|
992
|
+
});
|
602
993
|
const operationsByTag$2 = {
|
603
994
|
branch: {
|
604
995
|
getBranchList,
|
605
996
|
getBranchDetails,
|
606
997
|
createBranch,
|
607
998
|
deleteBranch,
|
999
|
+
copyBranch,
|
608
1000
|
updateBranchMetadata,
|
609
1001
|
getBranchMetadata,
|
610
1002
|
getBranchStats,
|
@@ -622,7 +1014,8 @@ const operationsByTag$2 = {
|
|
622
1014
|
compareBranchSchemas,
|
623
1015
|
updateBranchSchema,
|
624
1016
|
previewBranchSchemaEdit,
|
625
|
-
applyBranchSchemaEdit
|
1017
|
+
applyBranchSchemaEdit,
|
1018
|
+
pushBranchMigrations
|
626
1019
|
},
|
627
1020
|
migrationRequests: {
|
628
1021
|
queryMigrationRequests,
|
@@ -656,11 +1049,24 @@ const operationsByTag$2 = {
|
|
656
1049
|
deleteRecord,
|
657
1050
|
bulkInsertTableRecords
|
658
1051
|
},
|
659
|
-
|
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 }
|
660
1064
|
};
|
661
1065
|
|
662
1066
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
663
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 });
|
664
1070
|
const getUser = (variables, signal) => controlPlaneFetch({
|
665
1071
|
url: "/user",
|
666
1072
|
method: "get",
|
@@ -697,6 +1103,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
697
1103
|
...variables,
|
698
1104
|
signal
|
699
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 });
|
700
1131
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
701
1132
|
url: "/workspaces",
|
702
1133
|
method: "get",
|
@@ -755,6 +1186,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
755
1186
|
});
|
756
1187
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
757
1188
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1189
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1190
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1191
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1192
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
758
1193
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
759
1194
|
url: "/workspaces/{workspaceId}/regions",
|
760
1195
|
method: "get",
|
@@ -762,6 +1197,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
762
1197
|
signal
|
763
1198
|
});
|
764
1199
|
const operationsByTag$1 = {
|
1200
|
+
oAuth: {
|
1201
|
+
getAuthorizationCode,
|
1202
|
+
grantAuthorizationCode,
|
1203
|
+
getUserOAuthClients,
|
1204
|
+
deleteUserOAuthClient,
|
1205
|
+
getUserOAuthAccessTokens,
|
1206
|
+
deleteOAuthAccessToken,
|
1207
|
+
updateOAuthAccessToken
|
1208
|
+
},
|
765
1209
|
users: { getUser, updateUser, deleteUser },
|
766
1210
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
767
1211
|
workspaces: {
|
@@ -787,6 +1231,10 @@ const operationsByTag$1 = {
|
|
787
1231
|
deleteDatabase,
|
788
1232
|
getDatabaseMetadata,
|
789
1233
|
updateDatabaseMetadata,
|
1234
|
+
renameDatabase,
|
1235
|
+
getDatabaseGithubSettings,
|
1236
|
+
updateDatabaseGithubSettings,
|
1237
|
+
deleteDatabaseGithubSettings,
|
790
1238
|
listRegions
|
791
1239
|
}
|
792
1240
|
};
|
@@ -807,8 +1255,12 @@ const providers = {
|
|
807
1255
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
808
1256
|
},
|
809
1257
|
staging: {
|
810
|
-
main: "https://staging.
|
811
|
-
workspaces: "https://{workspaceId}.
|
1258
|
+
main: "https://api.staging-xata.dev",
|
1259
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1260
|
+
},
|
1261
|
+
dev: {
|
1262
|
+
main: "https://api.dev-xata.dev",
|
1263
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
812
1264
|
}
|
813
1265
|
};
|
814
1266
|
function isHostProviderAlias(alias) {
|
@@ -826,12 +1278,19 @@ function parseProviderString(provider = "production") {
|
|
826
1278
|
return null;
|
827
1279
|
return { main, workspaces };
|
828
1280
|
}
|
1281
|
+
function buildProviderString(provider) {
|
1282
|
+
if (isHostProviderAlias(provider))
|
1283
|
+
return provider;
|
1284
|
+
return `${provider.main},${provider.workspaces}`;
|
1285
|
+
}
|
829
1286
|
function parseWorkspacesUrlParts(url) {
|
830
1287
|
if (!isString(url))
|
831
1288
|
return null;
|
832
1289
|
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
833
|
-
const
|
834
|
-
const
|
1290
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1291
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1292
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1293
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
835
1294
|
if (!match)
|
836
1295
|
return null;
|
837
1296
|
return { workspace: match[1], region: match[2] };
|
@@ -870,10 +1329,11 @@ class XataApiClient {
|
|
870
1329
|
__privateSet$7(this, _extraProps, {
|
871
1330
|
apiUrl: getHostUrl(provider, "main"),
|
872
1331
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
873
|
-
|
1332
|
+
fetch: getFetchImplementation(options.fetch),
|
874
1333
|
apiKey,
|
875
1334
|
trace,
|
876
1335
|
clientName: options.clientName,
|
1336
|
+
xataAgentExtra: options.xataAgentExtra,
|
877
1337
|
clientID
|
878
1338
|
});
|
879
1339
|
}
|
@@ -927,6 +1387,11 @@ class XataApiClient {
|
|
927
1387
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
928
1388
|
return __privateGet$7(this, _namespaces).records;
|
929
1389
|
}
|
1390
|
+
get files() {
|
1391
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1392
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1393
|
+
return __privateGet$7(this, _namespaces).files;
|
1394
|
+
}
|
930
1395
|
get searchAndFilter() {
|
931
1396
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
932
1397
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1135,6 +1600,20 @@ class BranchApi {
|
|
1135
1600
|
...this.extraProps
|
1136
1601
|
});
|
1137
1602
|
}
|
1603
|
+
copyBranch({
|
1604
|
+
workspace,
|
1605
|
+
region,
|
1606
|
+
database,
|
1607
|
+
branch,
|
1608
|
+
destinationBranch,
|
1609
|
+
limit
|
1610
|
+
}) {
|
1611
|
+
return operationsByTag.branch.copyBranch({
|
1612
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1613
|
+
body: { destinationBranch, limit },
|
1614
|
+
...this.extraProps
|
1615
|
+
});
|
1616
|
+
}
|
1138
1617
|
updateBranchMetadata({
|
1139
1618
|
workspace,
|
1140
1619
|
region,
|
@@ -1490,6 +1969,164 @@ class RecordsApi {
|
|
1490
1969
|
});
|
1491
1970
|
}
|
1492
1971
|
}
|
1972
|
+
class FilesApi {
|
1973
|
+
constructor(extraProps) {
|
1974
|
+
this.extraProps = extraProps;
|
1975
|
+
}
|
1976
|
+
getFileItem({
|
1977
|
+
workspace,
|
1978
|
+
region,
|
1979
|
+
database,
|
1980
|
+
branch,
|
1981
|
+
table,
|
1982
|
+
record,
|
1983
|
+
column,
|
1984
|
+
fileId
|
1985
|
+
}) {
|
1986
|
+
return operationsByTag.files.getFileItem({
|
1987
|
+
pathParams: {
|
1988
|
+
workspace,
|
1989
|
+
region,
|
1990
|
+
dbBranchName: `${database}:${branch}`,
|
1991
|
+
tableName: table,
|
1992
|
+
recordId: record,
|
1993
|
+
columnName: column,
|
1994
|
+
fileId
|
1995
|
+
},
|
1996
|
+
...this.extraProps
|
1997
|
+
});
|
1998
|
+
}
|
1999
|
+
putFileItem({
|
2000
|
+
workspace,
|
2001
|
+
region,
|
2002
|
+
database,
|
2003
|
+
branch,
|
2004
|
+
table,
|
2005
|
+
record,
|
2006
|
+
column,
|
2007
|
+
fileId,
|
2008
|
+
file
|
2009
|
+
}) {
|
2010
|
+
return operationsByTag.files.putFileItem({
|
2011
|
+
pathParams: {
|
2012
|
+
workspace,
|
2013
|
+
region,
|
2014
|
+
dbBranchName: `${database}:${branch}`,
|
2015
|
+
tableName: table,
|
2016
|
+
recordId: record,
|
2017
|
+
columnName: column,
|
2018
|
+
fileId
|
2019
|
+
},
|
2020
|
+
// @ts-ignore
|
2021
|
+
body: file,
|
2022
|
+
...this.extraProps
|
2023
|
+
});
|
2024
|
+
}
|
2025
|
+
deleteFileItem({
|
2026
|
+
workspace,
|
2027
|
+
region,
|
2028
|
+
database,
|
2029
|
+
branch,
|
2030
|
+
table,
|
2031
|
+
record,
|
2032
|
+
column,
|
2033
|
+
fileId
|
2034
|
+
}) {
|
2035
|
+
return operationsByTag.files.deleteFileItem({
|
2036
|
+
pathParams: {
|
2037
|
+
workspace,
|
2038
|
+
region,
|
2039
|
+
dbBranchName: `${database}:${branch}`,
|
2040
|
+
tableName: table,
|
2041
|
+
recordId: record,
|
2042
|
+
columnName: column,
|
2043
|
+
fileId
|
2044
|
+
},
|
2045
|
+
...this.extraProps
|
2046
|
+
});
|
2047
|
+
}
|
2048
|
+
getFile({
|
2049
|
+
workspace,
|
2050
|
+
region,
|
2051
|
+
database,
|
2052
|
+
branch,
|
2053
|
+
table,
|
2054
|
+
record,
|
2055
|
+
column
|
2056
|
+
}) {
|
2057
|
+
return operationsByTag.files.getFile({
|
2058
|
+
pathParams: {
|
2059
|
+
workspace,
|
2060
|
+
region,
|
2061
|
+
dbBranchName: `${database}:${branch}`,
|
2062
|
+
tableName: table,
|
2063
|
+
recordId: record,
|
2064
|
+
columnName: column
|
2065
|
+
},
|
2066
|
+
...this.extraProps
|
2067
|
+
});
|
2068
|
+
}
|
2069
|
+
putFile({
|
2070
|
+
workspace,
|
2071
|
+
region,
|
2072
|
+
database,
|
2073
|
+
branch,
|
2074
|
+
table,
|
2075
|
+
record,
|
2076
|
+
column,
|
2077
|
+
file
|
2078
|
+
}) {
|
2079
|
+
return operationsByTag.files.putFile({
|
2080
|
+
pathParams: {
|
2081
|
+
workspace,
|
2082
|
+
region,
|
2083
|
+
dbBranchName: `${database}:${branch}`,
|
2084
|
+
tableName: table,
|
2085
|
+
recordId: record,
|
2086
|
+
columnName: column
|
2087
|
+
},
|
2088
|
+
body: file,
|
2089
|
+
...this.extraProps
|
2090
|
+
});
|
2091
|
+
}
|
2092
|
+
deleteFile({
|
2093
|
+
workspace,
|
2094
|
+
region,
|
2095
|
+
database,
|
2096
|
+
branch,
|
2097
|
+
table,
|
2098
|
+
record,
|
2099
|
+
column
|
2100
|
+
}) {
|
2101
|
+
return operationsByTag.files.deleteFile({
|
2102
|
+
pathParams: {
|
2103
|
+
workspace,
|
2104
|
+
region,
|
2105
|
+
dbBranchName: `${database}:${branch}`,
|
2106
|
+
tableName: table,
|
2107
|
+
recordId: record,
|
2108
|
+
columnName: column
|
2109
|
+
},
|
2110
|
+
...this.extraProps
|
2111
|
+
});
|
2112
|
+
}
|
2113
|
+
fileAccess({
|
2114
|
+
workspace,
|
2115
|
+
region,
|
2116
|
+
fileId,
|
2117
|
+
verify
|
2118
|
+
}) {
|
2119
|
+
return operationsByTag.files.fileAccess({
|
2120
|
+
pathParams: {
|
2121
|
+
workspace,
|
2122
|
+
region,
|
2123
|
+
fileId
|
2124
|
+
},
|
2125
|
+
queryParams: { verify },
|
2126
|
+
...this.extraProps
|
2127
|
+
});
|
2128
|
+
}
|
2129
|
+
}
|
1493
2130
|
class SearchAndFilterApi {
|
1494
2131
|
constructor(extraProps) {
|
1495
2132
|
this.extraProps = extraProps;
|
@@ -1549,6 +2186,53 @@ class SearchAndFilterApi {
|
|
1549
2186
|
...this.extraProps
|
1550
2187
|
});
|
1551
2188
|
}
|
2189
|
+
vectorSearchTable({
|
2190
|
+
workspace,
|
2191
|
+
region,
|
2192
|
+
database,
|
2193
|
+
branch,
|
2194
|
+
table,
|
2195
|
+
queryVector,
|
2196
|
+
column,
|
2197
|
+
similarityFunction,
|
2198
|
+
size,
|
2199
|
+
filter
|
2200
|
+
}) {
|
2201
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2202
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2203
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2204
|
+
...this.extraProps
|
2205
|
+
});
|
2206
|
+
}
|
2207
|
+
askTable({
|
2208
|
+
workspace,
|
2209
|
+
region,
|
2210
|
+
database,
|
2211
|
+
branch,
|
2212
|
+
table,
|
2213
|
+
options
|
2214
|
+
}) {
|
2215
|
+
return operationsByTag.searchAndFilter.askTable({
|
2216
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2217
|
+
body: { ...options },
|
2218
|
+
...this.extraProps
|
2219
|
+
});
|
2220
|
+
}
|
2221
|
+
askTableSession({
|
2222
|
+
workspace,
|
2223
|
+
region,
|
2224
|
+
database,
|
2225
|
+
branch,
|
2226
|
+
table,
|
2227
|
+
sessionId,
|
2228
|
+
message
|
2229
|
+
}) {
|
2230
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2231
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2232
|
+
body: { message },
|
2233
|
+
...this.extraProps
|
2234
|
+
});
|
2235
|
+
}
|
1552
2236
|
summarizeTable({
|
1553
2237
|
workspace,
|
1554
2238
|
region,
|
@@ -1749,11 +2433,13 @@ class MigrationsApi {
|
|
1749
2433
|
region,
|
1750
2434
|
database,
|
1751
2435
|
branch,
|
1752
|
-
schema
|
2436
|
+
schema,
|
2437
|
+
schemaOperations,
|
2438
|
+
branchOperations
|
1753
2439
|
}) {
|
1754
2440
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1755
2441
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1756
|
-
body: { schema },
|
2442
|
+
body: { schema, schemaOperations, branchOperations },
|
1757
2443
|
...this.extraProps
|
1758
2444
|
});
|
1759
2445
|
}
|
@@ -1763,11 +2449,12 @@ class MigrationsApi {
|
|
1763
2449
|
database,
|
1764
2450
|
branch,
|
1765
2451
|
compare,
|
1766
|
-
|
2452
|
+
sourceBranchOperations,
|
2453
|
+
targetBranchOperations
|
1767
2454
|
}) {
|
1768
2455
|
return operationsByTag.migrations.compareBranchSchemas({
|
1769
2456
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1770
|
-
body: {
|
2457
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1771
2458
|
...this.extraProps
|
1772
2459
|
});
|
1773
2460
|
}
|
@@ -1810,6 +2497,19 @@ class MigrationsApi {
|
|
1810
2497
|
...this.extraProps
|
1811
2498
|
});
|
1812
2499
|
}
|
2500
|
+
pushBranchMigrations({
|
2501
|
+
workspace,
|
2502
|
+
region,
|
2503
|
+
database,
|
2504
|
+
branch,
|
2505
|
+
migrations
|
2506
|
+
}) {
|
2507
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2508
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2509
|
+
body: { migrations },
|
2510
|
+
...this.extraProps
|
2511
|
+
});
|
2512
|
+
}
|
1813
2513
|
}
|
1814
2514
|
class DatabaseApi {
|
1815
2515
|
constructor(extraProps) {
|
@@ -1824,11 +2524,13 @@ class DatabaseApi {
|
|
1824
2524
|
createDatabase({
|
1825
2525
|
workspace,
|
1826
2526
|
database,
|
1827
|
-
data
|
2527
|
+
data,
|
2528
|
+
headers
|
1828
2529
|
}) {
|
1829
2530
|
return operationsByTag.databases.createDatabase({
|
1830
2531
|
pathParams: { workspaceId: workspace, dbName: database },
|
1831
2532
|
body: data,
|
2533
|
+
headers,
|
1832
2534
|
...this.extraProps
|
1833
2535
|
});
|
1834
2536
|
}
|
@@ -1861,6 +2563,46 @@ class DatabaseApi {
|
|
1861
2563
|
...this.extraProps
|
1862
2564
|
});
|
1863
2565
|
}
|
2566
|
+
renameDatabase({
|
2567
|
+
workspace,
|
2568
|
+
database,
|
2569
|
+
newName
|
2570
|
+
}) {
|
2571
|
+
return operationsByTag.databases.renameDatabase({
|
2572
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2573
|
+
body: { newName },
|
2574
|
+
...this.extraProps
|
2575
|
+
});
|
2576
|
+
}
|
2577
|
+
getDatabaseGithubSettings({
|
2578
|
+
workspace,
|
2579
|
+
database
|
2580
|
+
}) {
|
2581
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2582
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2583
|
+
...this.extraProps
|
2584
|
+
});
|
2585
|
+
}
|
2586
|
+
updateDatabaseGithubSettings({
|
2587
|
+
workspace,
|
2588
|
+
database,
|
2589
|
+
settings
|
2590
|
+
}) {
|
2591
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2592
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2593
|
+
body: settings,
|
2594
|
+
...this.extraProps
|
2595
|
+
});
|
2596
|
+
}
|
2597
|
+
deleteDatabaseGithubSettings({
|
2598
|
+
workspace,
|
2599
|
+
database
|
2600
|
+
}) {
|
2601
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2602
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2603
|
+
...this.extraProps
|
2604
|
+
});
|
2605
|
+
}
|
1864
2606
|
listRegions({ workspace }) {
|
1865
2607
|
return operationsByTag.databases.listRegions({
|
1866
2608
|
pathParams: { workspaceId: workspace },
|
@@ -1871,21 +2613,326 @@ class DatabaseApi {
|
|
1871
2613
|
|
1872
2614
|
class XataApiPlugin {
|
1873
2615
|
build(options) {
|
1874
|
-
|
1875
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2616
|
+
return new XataApiClient(options);
|
1876
2617
|
}
|
1877
2618
|
}
|
1878
2619
|
|
1879
2620
|
class XataPlugin {
|
1880
2621
|
}
|
1881
2622
|
|
2623
|
+
class FilesPlugin extends XataPlugin {
|
2624
|
+
build(pluginOptions) {
|
2625
|
+
return {
|
2626
|
+
download: async (location) => {
|
2627
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2628
|
+
return await getFileItem({
|
2629
|
+
pathParams: {
|
2630
|
+
workspace: "{workspaceId}",
|
2631
|
+
dbBranchName: "{dbBranch}",
|
2632
|
+
region: "{region}",
|
2633
|
+
tableName: table ?? "",
|
2634
|
+
recordId: record ?? "",
|
2635
|
+
columnName: column ?? "",
|
2636
|
+
fileId
|
2637
|
+
},
|
2638
|
+
...pluginOptions,
|
2639
|
+
rawResponse: true
|
2640
|
+
});
|
2641
|
+
},
|
2642
|
+
upload: async (location, file) => {
|
2643
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2644
|
+
const contentType = getContentType(file);
|
2645
|
+
return await putFileItem({
|
2646
|
+
...pluginOptions,
|
2647
|
+
pathParams: {
|
2648
|
+
workspace: "{workspaceId}",
|
2649
|
+
dbBranchName: "{dbBranch}",
|
2650
|
+
region: "{region}",
|
2651
|
+
tableName: table ?? "",
|
2652
|
+
recordId: record ?? "",
|
2653
|
+
columnName: column ?? "",
|
2654
|
+
fileId
|
2655
|
+
},
|
2656
|
+
body: file,
|
2657
|
+
headers: { "Content-Type": contentType }
|
2658
|
+
});
|
2659
|
+
},
|
2660
|
+
delete: async (location) => {
|
2661
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2662
|
+
return await deleteFileItem({
|
2663
|
+
pathParams: {
|
2664
|
+
workspace: "{workspaceId}",
|
2665
|
+
dbBranchName: "{dbBranch}",
|
2666
|
+
region: "{region}",
|
2667
|
+
tableName: table ?? "",
|
2668
|
+
recordId: record ?? "",
|
2669
|
+
columnName: column ?? "",
|
2670
|
+
fileId
|
2671
|
+
},
|
2672
|
+
...pluginOptions
|
2673
|
+
});
|
2674
|
+
}
|
2675
|
+
};
|
2676
|
+
}
|
2677
|
+
}
|
2678
|
+
function getContentType(file) {
|
2679
|
+
if (typeof file === "string") {
|
2680
|
+
return "text/plain";
|
2681
|
+
}
|
2682
|
+
if (isBlob(file)) {
|
2683
|
+
return file.type;
|
2684
|
+
}
|
2685
|
+
try {
|
2686
|
+
return file.type;
|
2687
|
+
} catch (e) {
|
2688
|
+
}
|
2689
|
+
return "application/octet-stream";
|
2690
|
+
}
|
2691
|
+
|
2692
|
+
function buildTransformString(transformations) {
|
2693
|
+
return transformations.flatMap(
|
2694
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2695
|
+
if (key === "trim") {
|
2696
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2697
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2698
|
+
}
|
2699
|
+
if (key === "gravity" && typeof value === "object") {
|
2700
|
+
const { x = 0.5, y = 0.5 } = value;
|
2701
|
+
return `${key}=${[x, y].join("x")}`;
|
2702
|
+
}
|
2703
|
+
return `${key}=${value}`;
|
2704
|
+
})
|
2705
|
+
).join(",");
|
2706
|
+
}
|
2707
|
+
function transformImage(url, ...transformations) {
|
2708
|
+
if (!isDefined(url))
|
2709
|
+
return void 0;
|
2710
|
+
const newTransformations = buildTransformString(transformations);
|
2711
|
+
const { hostname, pathname, search } = new URL(url);
|
2712
|
+
const pathParts = pathname.split("/");
|
2713
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2714
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2715
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2716
|
+
const path = pathParts.join("/");
|
2717
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2718
|
+
}
|
2719
|
+
|
2720
|
+
var __defProp$6 = Object.defineProperty;
|
2721
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2722
|
+
var __publicField$6 = (obj, key, value) => {
|
2723
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2724
|
+
return value;
|
2725
|
+
};
|
2726
|
+
class XataFile {
|
2727
|
+
constructor(file) {
|
2728
|
+
/**
|
2729
|
+
* Identifier of the file.
|
2730
|
+
*/
|
2731
|
+
__publicField$6(this, "id");
|
2732
|
+
/**
|
2733
|
+
* Name of the file.
|
2734
|
+
*/
|
2735
|
+
__publicField$6(this, "name");
|
2736
|
+
/**
|
2737
|
+
* Media type of the file.
|
2738
|
+
*/
|
2739
|
+
__publicField$6(this, "mediaType");
|
2740
|
+
/**
|
2741
|
+
* Base64 encoded content of the file.
|
2742
|
+
*/
|
2743
|
+
__publicField$6(this, "base64Content");
|
2744
|
+
/**
|
2745
|
+
* Whether to enable public url for the file.
|
2746
|
+
*/
|
2747
|
+
__publicField$6(this, "enablePublicUrl");
|
2748
|
+
/**
|
2749
|
+
* Timeout for the signed url.
|
2750
|
+
*/
|
2751
|
+
__publicField$6(this, "signedUrlTimeout");
|
2752
|
+
/**
|
2753
|
+
* Size of the file.
|
2754
|
+
*/
|
2755
|
+
__publicField$6(this, "size");
|
2756
|
+
/**
|
2757
|
+
* Version of the file.
|
2758
|
+
*/
|
2759
|
+
__publicField$6(this, "version");
|
2760
|
+
/**
|
2761
|
+
* Url of the file.
|
2762
|
+
*/
|
2763
|
+
__publicField$6(this, "url");
|
2764
|
+
/**
|
2765
|
+
* Signed url of the file.
|
2766
|
+
*/
|
2767
|
+
__publicField$6(this, "signedUrl");
|
2768
|
+
/**
|
2769
|
+
* Attributes of the file.
|
2770
|
+
*/
|
2771
|
+
__publicField$6(this, "attributes");
|
2772
|
+
this.id = file.id;
|
2773
|
+
this.name = file.name || "";
|
2774
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2775
|
+
this.base64Content = file.base64Content;
|
2776
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2777
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2778
|
+
this.size = file.size ?? 0;
|
2779
|
+
this.version = file.version ?? 1;
|
2780
|
+
this.url = file.url || "";
|
2781
|
+
this.signedUrl = file.signedUrl;
|
2782
|
+
this.attributes = file.attributes || {};
|
2783
|
+
}
|
2784
|
+
static fromBuffer(buffer, options = {}) {
|
2785
|
+
const base64Content = buffer.toString("base64");
|
2786
|
+
return new XataFile({ ...options, base64Content });
|
2787
|
+
}
|
2788
|
+
toBuffer() {
|
2789
|
+
if (!this.base64Content) {
|
2790
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2791
|
+
}
|
2792
|
+
return Buffer.from(this.base64Content, "base64");
|
2793
|
+
}
|
2794
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2795
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2796
|
+
return this.fromUint8Array(uint8Array, options);
|
2797
|
+
}
|
2798
|
+
toArrayBuffer() {
|
2799
|
+
if (!this.base64Content) {
|
2800
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2801
|
+
}
|
2802
|
+
const binary = atob(this.base64Content);
|
2803
|
+
return new ArrayBuffer(binary.length);
|
2804
|
+
}
|
2805
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2806
|
+
let binary = "";
|
2807
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2808
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2809
|
+
}
|
2810
|
+
const base64Content = btoa(binary);
|
2811
|
+
return new XataFile({ ...options, base64Content });
|
2812
|
+
}
|
2813
|
+
toUint8Array() {
|
2814
|
+
if (!this.base64Content) {
|
2815
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2816
|
+
}
|
2817
|
+
const binary = atob(this.base64Content);
|
2818
|
+
const uint8Array = new Uint8Array(binary.length);
|
2819
|
+
for (let i = 0; i < binary.length; i++) {
|
2820
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2821
|
+
}
|
2822
|
+
return uint8Array;
|
2823
|
+
}
|
2824
|
+
static async fromBlob(file, options = {}) {
|
2825
|
+
const name = options.name ?? file.name;
|
2826
|
+
const mediaType = file.type;
|
2827
|
+
const arrayBuffer = await file.arrayBuffer();
|
2828
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2829
|
+
}
|
2830
|
+
toBlob() {
|
2831
|
+
if (!this.base64Content) {
|
2832
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2833
|
+
}
|
2834
|
+
const binary = atob(this.base64Content);
|
2835
|
+
const uint8Array = new Uint8Array(binary.length);
|
2836
|
+
for (let i = 0; i < binary.length; i++) {
|
2837
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2838
|
+
}
|
2839
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2840
|
+
}
|
2841
|
+
static fromString(string, options = {}) {
|
2842
|
+
const base64Content = btoa(string);
|
2843
|
+
return new XataFile({ ...options, base64Content });
|
2844
|
+
}
|
2845
|
+
toString() {
|
2846
|
+
if (!this.base64Content) {
|
2847
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2848
|
+
}
|
2849
|
+
return atob(this.base64Content);
|
2850
|
+
}
|
2851
|
+
static fromBase64(base64Content, options = {}) {
|
2852
|
+
return new XataFile({ ...options, base64Content });
|
2853
|
+
}
|
2854
|
+
toBase64() {
|
2855
|
+
if (!this.base64Content) {
|
2856
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2857
|
+
}
|
2858
|
+
return this.base64Content;
|
2859
|
+
}
|
2860
|
+
transform(...options) {
|
2861
|
+
return {
|
2862
|
+
url: transformImage(this.url, ...options),
|
2863
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2864
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2865
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2866
|
+
};
|
2867
|
+
}
|
2868
|
+
}
|
2869
|
+
const parseInputFileEntry = async (entry) => {
|
2870
|
+
if (!isDefined(entry))
|
2871
|
+
return null;
|
2872
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2873
|
+
return compactObject({
|
2874
|
+
id,
|
2875
|
+
// Name cannot be an empty string in our API
|
2876
|
+
name: name ? name : void 0,
|
2877
|
+
mediaType,
|
2878
|
+
base64Content,
|
2879
|
+
enablePublicUrl,
|
2880
|
+
signedUrlTimeout
|
2881
|
+
});
|
2882
|
+
};
|
2883
|
+
|
1882
2884
|
function cleanFilter(filter) {
|
1883
|
-
if (!filter)
|
2885
|
+
if (!isDefined(filter))
|
1884
2886
|
return void 0;
|
1885
|
-
|
1886
|
-
|
2887
|
+
if (!isObject(filter))
|
2888
|
+
return filter;
|
2889
|
+
const values = Object.fromEntries(
|
2890
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2891
|
+
if (!isDefined(value))
|
2892
|
+
return acc;
|
2893
|
+
if (Array.isArray(value)) {
|
2894
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2895
|
+
if (clean.length === 0)
|
2896
|
+
return acc;
|
2897
|
+
return [...acc, [key, clean]];
|
2898
|
+
}
|
2899
|
+
if (isObject(value)) {
|
2900
|
+
const clean = cleanFilter(value);
|
2901
|
+
if (!isDefined(clean))
|
2902
|
+
return acc;
|
2903
|
+
return [...acc, [key, clean]];
|
2904
|
+
}
|
2905
|
+
return [...acc, [key, value]];
|
2906
|
+
}, [])
|
2907
|
+
);
|
2908
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
2909
|
+
}
|
2910
|
+
|
2911
|
+
function stringifyJson(value) {
|
2912
|
+
if (!isDefined(value))
|
2913
|
+
return value;
|
2914
|
+
if (isString(value))
|
2915
|
+
return value;
|
2916
|
+
try {
|
2917
|
+
return JSON.stringify(value);
|
2918
|
+
} catch (e) {
|
2919
|
+
return value;
|
2920
|
+
}
|
2921
|
+
}
|
2922
|
+
function parseJson(value) {
|
2923
|
+
try {
|
2924
|
+
return JSON.parse(value);
|
2925
|
+
} catch (e) {
|
2926
|
+
return value;
|
2927
|
+
}
|
1887
2928
|
}
|
1888
2929
|
|
2930
|
+
var __defProp$5 = Object.defineProperty;
|
2931
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2932
|
+
var __publicField$5 = (obj, key, value) => {
|
2933
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2934
|
+
return value;
|
2935
|
+
};
|
1889
2936
|
var __accessCheck$6 = (obj, member, msg) => {
|
1890
2937
|
if (!member.has(obj))
|
1891
2938
|
throw TypeError("Cannot " + msg);
|
@@ -1908,22 +2955,58 @@ var _query, _page;
|
|
1908
2955
|
class Page {
|
1909
2956
|
constructor(query, meta, records = []) {
|
1910
2957
|
__privateAdd$6(this, _query, void 0);
|
2958
|
+
/**
|
2959
|
+
* Page metadata, required to retrieve additional records.
|
2960
|
+
*/
|
2961
|
+
__publicField$5(this, "meta");
|
2962
|
+
/**
|
2963
|
+
* The set of results for this page.
|
2964
|
+
*/
|
2965
|
+
__publicField$5(this, "records");
|
1911
2966
|
__privateSet$6(this, _query, query);
|
1912
2967
|
this.meta = meta;
|
1913
2968
|
this.records = new RecordArray(this, records);
|
1914
2969
|
}
|
2970
|
+
/**
|
2971
|
+
* Retrieves the next page of results.
|
2972
|
+
* @param size Maximum number of results to be retrieved.
|
2973
|
+
* @param offset Number of results to skip when retrieving the results.
|
2974
|
+
* @returns The next page or results.
|
2975
|
+
*/
|
1915
2976
|
async nextPage(size, offset) {
|
1916
2977
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1917
2978
|
}
|
2979
|
+
/**
|
2980
|
+
* Retrieves the previous page of results.
|
2981
|
+
* @param size Maximum number of results to be retrieved.
|
2982
|
+
* @param offset Number of results to skip when retrieving the results.
|
2983
|
+
* @returns The previous page or results.
|
2984
|
+
*/
|
1918
2985
|
async previousPage(size, offset) {
|
1919
2986
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1920
2987
|
}
|
2988
|
+
/**
|
2989
|
+
* Retrieves the start page of results.
|
2990
|
+
* @param size Maximum number of results to be retrieved.
|
2991
|
+
* @param offset Number of results to skip when retrieving the results.
|
2992
|
+
* @returns The start page or results.
|
2993
|
+
*/
|
1921
2994
|
async startPage(size, offset) {
|
1922
2995
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1923
2996
|
}
|
2997
|
+
/**
|
2998
|
+
* Retrieves the end page of results.
|
2999
|
+
* @param size Maximum number of results to be retrieved.
|
3000
|
+
* @param offset Number of results to skip when retrieving the results.
|
3001
|
+
* @returns The end page or results.
|
3002
|
+
*/
|
1924
3003
|
async endPage(size, offset) {
|
1925
3004
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1926
3005
|
}
|
3006
|
+
/**
|
3007
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
3008
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
3009
|
+
*/
|
1927
3010
|
hasNextPage() {
|
1928
3011
|
return this.meta.page.more;
|
1929
3012
|
}
|
@@ -1936,7 +3019,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1936
3019
|
function isCursorPaginationOptions(options) {
|
1937
3020
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1938
3021
|
}
|
1939
|
-
const _RecordArray = class extends Array {
|
3022
|
+
const _RecordArray = class _RecordArray extends Array {
|
1940
3023
|
constructor(...args) {
|
1941
3024
|
super(..._RecordArray.parseConstructorParams(...args));
|
1942
3025
|
__privateAdd$6(this, _page, void 0);
|
@@ -1964,29 +3047,58 @@ const _RecordArray = class extends Array {
|
|
1964
3047
|
map(callbackfn, thisArg) {
|
1965
3048
|
return this.toArray().map(callbackfn, thisArg);
|
1966
3049
|
}
|
3050
|
+
/**
|
3051
|
+
* Retrieve next page of records
|
3052
|
+
*
|
3053
|
+
* @returns A new array of objects
|
3054
|
+
*/
|
1967
3055
|
async nextPage(size, offset) {
|
1968
3056
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1969
3057
|
return new _RecordArray(newPage);
|
1970
3058
|
}
|
3059
|
+
/**
|
3060
|
+
* Retrieve previous page of records
|
3061
|
+
*
|
3062
|
+
* @returns A new array of objects
|
3063
|
+
*/
|
1971
3064
|
async previousPage(size, offset) {
|
1972
3065
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1973
3066
|
return new _RecordArray(newPage);
|
1974
3067
|
}
|
3068
|
+
/**
|
3069
|
+
* Retrieve start page of records
|
3070
|
+
*
|
3071
|
+
* @returns A new array of objects
|
3072
|
+
*/
|
1975
3073
|
async startPage(size, offset) {
|
1976
3074
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1977
3075
|
return new _RecordArray(newPage);
|
1978
3076
|
}
|
3077
|
+
/**
|
3078
|
+
* Retrieve end page of records
|
3079
|
+
*
|
3080
|
+
* @returns A new array of objects
|
3081
|
+
*/
|
1979
3082
|
async endPage(size, offset) {
|
1980
3083
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1981
3084
|
return new _RecordArray(newPage);
|
1982
3085
|
}
|
3086
|
+
/**
|
3087
|
+
* @returns Boolean indicating if there is a next page
|
3088
|
+
*/
|
1983
3089
|
hasNextPage() {
|
1984
3090
|
return __privateGet$6(this, _page).meta.page.more;
|
1985
3091
|
}
|
1986
3092
|
};
|
1987
|
-
let RecordArray = _RecordArray;
|
1988
3093
|
_page = new WeakMap();
|
3094
|
+
let RecordArray = _RecordArray;
|
1989
3095
|
|
3096
|
+
var __defProp$4 = Object.defineProperty;
|
3097
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3098
|
+
var __publicField$4 = (obj, key, value) => {
|
3099
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3100
|
+
return value;
|
3101
|
+
};
|
1990
3102
|
var __accessCheck$5 = (obj, member, msg) => {
|
1991
3103
|
if (!member.has(obj))
|
1992
3104
|
throw TypeError("Cannot " + msg);
|
@@ -2010,14 +3122,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2010
3122
|
return method;
|
2011
3123
|
};
|
2012
3124
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2013
|
-
const _Query = class {
|
3125
|
+
const _Query = class _Query {
|
2014
3126
|
constructor(repository, table, data, rawParent) {
|
2015
3127
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2016
3128
|
__privateAdd$5(this, _table$1, void 0);
|
2017
3129
|
__privateAdd$5(this, _repository, void 0);
|
2018
3130
|
__privateAdd$5(this, _data, { filter: {} });
|
2019
|
-
|
2020
|
-
this
|
3131
|
+
// Implements pagination
|
3132
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
3133
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
2021
3134
|
__privateSet$5(this, _table$1, table);
|
2022
3135
|
if (repository) {
|
2023
3136
|
__privateSet$5(this, _repository, repository);
|
@@ -2053,18 +3166,38 @@ const _Query = class {
|
|
2053
3166
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2054
3167
|
return toBase64(key);
|
2055
3168
|
}
|
3169
|
+
/**
|
3170
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3171
|
+
* @param queries An array of subqueries.
|
3172
|
+
* @returns A new Query object.
|
3173
|
+
*/
|
2056
3174
|
any(...queries) {
|
2057
3175
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2058
3176
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2059
3177
|
}
|
3178
|
+
/**
|
3179
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3180
|
+
* @param queries An array of subqueries.
|
3181
|
+
* @returns A new Query object.
|
3182
|
+
*/
|
2060
3183
|
all(...queries) {
|
2061
3184
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2062
3185
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2063
3186
|
}
|
3187
|
+
/**
|
3188
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3189
|
+
* @param queries An array of subqueries.
|
3190
|
+
* @returns A new Query object.
|
3191
|
+
*/
|
2064
3192
|
not(...queries) {
|
2065
3193
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2066
3194
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2067
3195
|
}
|
3196
|
+
/**
|
3197
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3198
|
+
* @param queries An array of subqueries.
|
3199
|
+
* @returns A new Query object.
|
3200
|
+
*/
|
2068
3201
|
none(...queries) {
|
2069
3202
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2070
3203
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2087,6 +3220,11 @@ const _Query = class {
|
|
2087
3220
|
const sort = [...originalSort, { column, direction }];
|
2088
3221
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2089
3222
|
}
|
3223
|
+
/**
|
3224
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3225
|
+
* @param columns Array of column names to be returned by the query.
|
3226
|
+
* @returns A new Query object.
|
3227
|
+
*/
|
2090
3228
|
select(columns) {
|
2091
3229
|
return new _Query(
|
2092
3230
|
__privateGet$5(this, _repository),
|
@@ -2099,6 +3237,12 @@ const _Query = class {
|
|
2099
3237
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2100
3238
|
return __privateGet$5(this, _repository).query(query);
|
2101
3239
|
}
|
3240
|
+
/**
|
3241
|
+
* Get results in an iterator
|
3242
|
+
*
|
3243
|
+
* @async
|
3244
|
+
* @returns Async interable of results
|
3245
|
+
*/
|
2102
3246
|
async *[Symbol.asyncIterator]() {
|
2103
3247
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2104
3248
|
yield record;
|
@@ -2159,26 +3303,53 @@ const _Query = class {
|
|
2159
3303
|
);
|
2160
3304
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2161
3305
|
}
|
3306
|
+
/**
|
3307
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3308
|
+
* @param ttl The cache TTL in milliseconds.
|
3309
|
+
* @returns A new Query object.
|
3310
|
+
*/
|
2162
3311
|
cache(ttl) {
|
2163
3312
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2164
3313
|
}
|
3314
|
+
/**
|
3315
|
+
* Retrieve next page of records
|
3316
|
+
*
|
3317
|
+
* @returns A new page object.
|
3318
|
+
*/
|
2165
3319
|
nextPage(size, offset) {
|
2166
3320
|
return this.startPage(size, offset);
|
2167
3321
|
}
|
3322
|
+
/**
|
3323
|
+
* Retrieve previous page of records
|
3324
|
+
*
|
3325
|
+
* @returns A new page object
|
3326
|
+
*/
|
2168
3327
|
previousPage(size, offset) {
|
2169
3328
|
return this.startPage(size, offset);
|
2170
3329
|
}
|
3330
|
+
/**
|
3331
|
+
* Retrieve start page of records
|
3332
|
+
*
|
3333
|
+
* @returns A new page object
|
3334
|
+
*/
|
2171
3335
|
startPage(size, offset) {
|
2172
3336
|
return this.getPaginated({ pagination: { size, offset } });
|
2173
3337
|
}
|
3338
|
+
/**
|
3339
|
+
* Retrieve last page of records
|
3340
|
+
*
|
3341
|
+
* @returns A new page object
|
3342
|
+
*/
|
2174
3343
|
endPage(size, offset) {
|
2175
3344
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2176
3345
|
}
|
3346
|
+
/**
|
3347
|
+
* @returns Boolean indicating if there is a next page
|
3348
|
+
*/
|
2177
3349
|
hasNextPage() {
|
2178
3350
|
return this.meta.page.more;
|
2179
3351
|
}
|
2180
3352
|
};
|
2181
|
-
let Query = _Query;
|
2182
3353
|
_table$1 = new WeakMap();
|
2183
3354
|
_repository = new WeakMap();
|
2184
3355
|
_data = new WeakMap();
|
@@ -2193,6 +3364,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2193
3364
|
}
|
2194
3365
|
return value;
|
2195
3366
|
};
|
3367
|
+
let Query = _Query;
|
2196
3368
|
function cleanParent(data, parent) {
|
2197
3369
|
if (isCursorPaginationOptions(data.pagination)) {
|
2198
3370
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2200,6 +3372,22 @@ function cleanParent(data, parent) {
|
|
2200
3372
|
return parent;
|
2201
3373
|
}
|
2202
3374
|
|
3375
|
+
const RecordColumnTypes = [
|
3376
|
+
"bool",
|
3377
|
+
"int",
|
3378
|
+
"float",
|
3379
|
+
"string",
|
3380
|
+
"text",
|
3381
|
+
"email",
|
3382
|
+
"multiple",
|
3383
|
+
"link",
|
3384
|
+
"object",
|
3385
|
+
"datetime",
|
3386
|
+
"vector",
|
3387
|
+
"file[]",
|
3388
|
+
"file",
|
3389
|
+
"json"
|
3390
|
+
];
|
2203
3391
|
function isIdentifiable(x) {
|
2204
3392
|
return isObject(x) && isString(x?.id);
|
2205
3393
|
}
|
@@ -2209,11 +3397,33 @@ function isXataRecord(x) {
|
|
2209
3397
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2210
3398
|
}
|
2211
3399
|
|
3400
|
+
function isValidExpandedColumn(column) {
|
3401
|
+
return isObject(column) && isString(column.name);
|
3402
|
+
}
|
3403
|
+
function isValidSelectableColumns(columns) {
|
3404
|
+
if (!Array.isArray(columns)) {
|
3405
|
+
return false;
|
3406
|
+
}
|
3407
|
+
return columns.every((column) => {
|
3408
|
+
if (typeof column === "string") {
|
3409
|
+
return true;
|
3410
|
+
}
|
3411
|
+
if (typeof column === "object") {
|
3412
|
+
return isValidExpandedColumn(column);
|
3413
|
+
}
|
3414
|
+
return false;
|
3415
|
+
});
|
3416
|
+
}
|
3417
|
+
|
2212
3418
|
function isSortFilterString(value) {
|
2213
3419
|
return isString(value);
|
2214
3420
|
}
|
2215
3421
|
function isSortFilterBase(filter) {
|
2216
|
-
return isObject(filter) && Object.
|
3422
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3423
|
+
if (key === "*")
|
3424
|
+
return value === "random";
|
3425
|
+
return value === "asc" || value === "desc";
|
3426
|
+
});
|
2217
3427
|
}
|
2218
3428
|
function isSortFilterObject(filter) {
|
2219
3429
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2254,7 +3464,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2254
3464
|
__accessCheck$4(obj, member, "access private method");
|
2255
3465
|
return method;
|
2256
3466
|
};
|
2257
|
-
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;
|
3467
|
+
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;
|
2258
3468
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2259
3469
|
class Repository extends Query {
|
2260
3470
|
}
|
@@ -2276,6 +3486,7 @@ class RestRepository extends Query {
|
|
2276
3486
|
__privateAdd$4(this, _setCacheQuery);
|
2277
3487
|
__privateAdd$4(this, _getCacheQuery);
|
2278
3488
|
__privateAdd$4(this, _getSchemaTables$1);
|
3489
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2279
3490
|
__privateAdd$4(this, _table, void 0);
|
2280
3491
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2281
3492
|
__privateAdd$4(this, _db, void 0);
|
@@ -2286,10 +3497,7 @@ class RestRepository extends Query {
|
|
2286
3497
|
__privateSet$4(this, _db, options.db);
|
2287
3498
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2288
3499
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2289
|
-
__privateSet$4(this, _getFetchProps,
|
2290
|
-
const props = await options.pluginOptions.getFetchProps();
|
2291
|
-
return { ...props, sessionID: generateUUID() };
|
2292
|
-
});
|
3500
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2293
3501
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2294
3502
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2295
3503
|
return trace(name, fn, {
|
@@ -2307,24 +3515,24 @@ class RestRepository extends Query {
|
|
2307
3515
|
if (a.length === 0)
|
2308
3516
|
return [];
|
2309
3517
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2310
|
-
const columns =
|
3518
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2311
3519
|
const result = await this.read(ids, columns);
|
2312
3520
|
return result;
|
2313
3521
|
}
|
2314
3522
|
if (isString(a) && isObject(b)) {
|
2315
3523
|
if (a === "")
|
2316
3524
|
throw new Error("The id can't be empty");
|
2317
|
-
const columns =
|
3525
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2318
3526
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2319
3527
|
}
|
2320
3528
|
if (isObject(a) && isString(a.id)) {
|
2321
3529
|
if (a.id === "")
|
2322
3530
|
throw new Error("The id can't be empty");
|
2323
|
-
const columns =
|
3531
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2324
3532
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2325
3533
|
}
|
2326
3534
|
if (isObject(a)) {
|
2327
|
-
const columns =
|
3535
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2328
3536
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2329
3537
|
}
|
2330
3538
|
throw new Error("Invalid arguments for create method");
|
@@ -2332,7 +3540,7 @@ class RestRepository extends Query {
|
|
2332
3540
|
}
|
2333
3541
|
async read(a, b) {
|
2334
3542
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2335
|
-
const columns =
|
3543
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2336
3544
|
if (Array.isArray(a)) {
|
2337
3545
|
if (a.length === 0)
|
2338
3546
|
return [];
|
@@ -2346,7 +3554,6 @@ class RestRepository extends Query {
|
|
2346
3554
|
}
|
2347
3555
|
const id = extractId(a);
|
2348
3556
|
if (id) {
|
2349
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2350
3557
|
try {
|
2351
3558
|
const response = await getRecord({
|
2352
3559
|
pathParams: {
|
@@ -2357,10 +3564,16 @@ class RestRepository extends Query {
|
|
2357
3564
|
recordId: id
|
2358
3565
|
},
|
2359
3566
|
queryParams: { columns },
|
2360
|
-
...
|
3567
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2361
3568
|
});
|
2362
3569
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2363
|
-
return initObject(
|
3570
|
+
return initObject(
|
3571
|
+
__privateGet$4(this, _db),
|
3572
|
+
schemaTables,
|
3573
|
+
__privateGet$4(this, _table),
|
3574
|
+
response,
|
3575
|
+
columns
|
3576
|
+
);
|
2364
3577
|
} catch (e) {
|
2365
3578
|
if (isObject(e) && e.status === 404) {
|
2366
3579
|
return null;
|
@@ -2402,17 +3615,17 @@ class RestRepository extends Query {
|
|
2402
3615
|
ifVersion,
|
2403
3616
|
upsert: false
|
2404
3617
|
});
|
2405
|
-
const columns =
|
3618
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2406
3619
|
const result = await this.read(a, columns);
|
2407
3620
|
return result;
|
2408
3621
|
}
|
2409
3622
|
try {
|
2410
3623
|
if (isString(a) && isObject(b)) {
|
2411
|
-
const columns =
|
3624
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2412
3625
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2413
3626
|
}
|
2414
3627
|
if (isObject(a) && isString(a.id)) {
|
2415
|
-
const columns =
|
3628
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2416
3629
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2417
3630
|
}
|
2418
3631
|
} catch (error) {
|
@@ -2452,17 +3665,27 @@ class RestRepository extends Query {
|
|
2452
3665
|
ifVersion,
|
2453
3666
|
upsert: true
|
2454
3667
|
});
|
2455
|
-
const columns =
|
3668
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2456
3669
|
const result = await this.read(a, columns);
|
2457
3670
|
return result;
|
2458
3671
|
}
|
2459
3672
|
if (isString(a) && isObject(b)) {
|
2460
|
-
|
2461
|
-
|
3673
|
+
if (a === "")
|
3674
|
+
throw new Error("The id can't be empty");
|
3675
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3676
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2462
3677
|
}
|
2463
3678
|
if (isObject(a) && isString(a.id)) {
|
2464
|
-
|
2465
|
-
|
3679
|
+
if (a.id === "")
|
3680
|
+
throw new Error("The id can't be empty");
|
3681
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3682
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3683
|
+
}
|
3684
|
+
if (!isDefined(a) && isObject(b)) {
|
3685
|
+
return await this.create(b, c);
|
3686
|
+
}
|
3687
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3688
|
+
return await this.create(a, b);
|
2466
3689
|
}
|
2467
3690
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2468
3691
|
});
|
@@ -2474,17 +3697,27 @@ class RestRepository extends Query {
|
|
2474
3697
|
if (a.length === 0)
|
2475
3698
|
return [];
|
2476
3699
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2477
|
-
const columns =
|
3700
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2478
3701
|
const result = await this.read(ids, columns);
|
2479
3702
|
return result;
|
2480
3703
|
}
|
2481
3704
|
if (isString(a) && isObject(b)) {
|
2482
|
-
|
2483
|
-
|
3705
|
+
if (a === "")
|
3706
|
+
throw new Error("The id can't be empty");
|
3707
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3708
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2484
3709
|
}
|
2485
3710
|
if (isObject(a) && isString(a.id)) {
|
2486
|
-
|
2487
|
-
|
3711
|
+
if (a.id === "")
|
3712
|
+
throw new Error("The id can't be empty");
|
3713
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3714
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3715
|
+
}
|
3716
|
+
if (!isDefined(a) && isObject(b)) {
|
3717
|
+
return await this.create(b, c);
|
3718
|
+
}
|
3719
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3720
|
+
return await this.create(a, b);
|
2488
3721
|
}
|
2489
3722
|
throw new Error("Invalid arguments for createOrReplace method");
|
2490
3723
|
});
|
@@ -2501,7 +3734,7 @@ class RestRepository extends Query {
|
|
2501
3734
|
return o.id;
|
2502
3735
|
throw new Error("Invalid arguments for delete method");
|
2503
3736
|
});
|
2504
|
-
const columns =
|
3737
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2505
3738
|
const result = await this.read(a, columns);
|
2506
3739
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2507
3740
|
return result;
|
@@ -2535,7 +3768,6 @@ class RestRepository extends Query {
|
|
2535
3768
|
}
|
2536
3769
|
async search(query, options = {}) {
|
2537
3770
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2538
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2539
3771
|
const { records } = await searchTable({
|
2540
3772
|
pathParams: {
|
2541
3773
|
workspace: "{workspaceId}",
|
@@ -2553,7 +3785,29 @@ class RestRepository extends Query {
|
|
2553
3785
|
page: options.page,
|
2554
3786
|
target: options.target
|
2555
3787
|
},
|
2556
|
-
...
|
3788
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3789
|
+
});
|
3790
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3791
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3792
|
+
});
|
3793
|
+
}
|
3794
|
+
async vectorSearch(column, query, options) {
|
3795
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3796
|
+
const { records } = await vectorSearchTable({
|
3797
|
+
pathParams: {
|
3798
|
+
workspace: "{workspaceId}",
|
3799
|
+
dbBranchName: "{dbBranch}",
|
3800
|
+
region: "{region}",
|
3801
|
+
tableName: __privateGet$4(this, _table)
|
3802
|
+
},
|
3803
|
+
body: {
|
3804
|
+
column,
|
3805
|
+
queryVector: query,
|
3806
|
+
similarityFunction: options?.similarityFunction,
|
3807
|
+
size: options?.size,
|
3808
|
+
filter: options?.filter
|
3809
|
+
},
|
3810
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2557
3811
|
});
|
2558
3812
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2559
3813
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2561,7 +3815,6 @@ class RestRepository extends Query {
|
|
2561
3815
|
}
|
2562
3816
|
async aggregate(aggs, filter) {
|
2563
3817
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2564
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2565
3818
|
const result = await aggregateTable({
|
2566
3819
|
pathParams: {
|
2567
3820
|
workspace: "{workspaceId}",
|
@@ -2570,7 +3823,7 @@ class RestRepository extends Query {
|
|
2570
3823
|
tableName: __privateGet$4(this, _table)
|
2571
3824
|
},
|
2572
3825
|
body: { aggs, filter },
|
2573
|
-
...
|
3826
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2574
3827
|
});
|
2575
3828
|
return result;
|
2576
3829
|
});
|
@@ -2581,7 +3834,6 @@ class RestRepository extends Query {
|
|
2581
3834
|
if (cacheQuery)
|
2582
3835
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2583
3836
|
const data = query.getQueryOptions();
|
2584
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2585
3837
|
const { meta, records: objects } = await queryTable({
|
2586
3838
|
pathParams: {
|
2587
3839
|
workspace: "{workspaceId}",
|
@@ -2597,11 +3849,17 @@ class RestRepository extends Query {
|
|
2597
3849
|
consistency: data.consistency
|
2598
3850
|
},
|
2599
3851
|
fetchOptions: data.fetchOptions,
|
2600
|
-
...
|
3852
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2601
3853
|
});
|
2602
3854
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2603
3855
|
const records = objects.map(
|
2604
|
-
(record) => initObject(
|
3856
|
+
(record) => initObject(
|
3857
|
+
__privateGet$4(this, _db),
|
3858
|
+
schemaTables,
|
3859
|
+
__privateGet$4(this, _table),
|
3860
|
+
record,
|
3861
|
+
data.columns ?? ["*"]
|
3862
|
+
)
|
2605
3863
|
);
|
2606
3864
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2607
3865
|
return new Page(query, meta, records);
|
@@ -2610,7 +3868,6 @@ class RestRepository extends Query {
|
|
2610
3868
|
async summarizeTable(query, summaries, summariesFilter) {
|
2611
3869
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2612
3870
|
const data = query.getQueryOptions();
|
2613
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2614
3871
|
const result = await summarizeTable({
|
2615
3872
|
pathParams: {
|
2616
3873
|
workspace: "{workspaceId}",
|
@@ -2627,11 +3884,44 @@ class RestRepository extends Query {
|
|
2627
3884
|
summaries,
|
2628
3885
|
summariesFilter
|
2629
3886
|
},
|
2630
|
-
...
|
3887
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2631
3888
|
});
|
2632
3889
|
return result;
|
2633
3890
|
});
|
2634
3891
|
}
|
3892
|
+
ask(question, options) {
|
3893
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3894
|
+
const params = {
|
3895
|
+
pathParams: {
|
3896
|
+
workspace: "{workspaceId}",
|
3897
|
+
dbBranchName: "{dbBranch}",
|
3898
|
+
region: "{region}",
|
3899
|
+
tableName: __privateGet$4(this, _table),
|
3900
|
+
sessionId: options?.sessionId
|
3901
|
+
},
|
3902
|
+
body: {
|
3903
|
+
...questionParam,
|
3904
|
+
rules: options?.rules,
|
3905
|
+
searchType: options?.searchType,
|
3906
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3907
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3908
|
+
},
|
3909
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3910
|
+
};
|
3911
|
+
if (options?.onMessage) {
|
3912
|
+
fetchSSERequest({
|
3913
|
+
endpoint: "dataPlane",
|
3914
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3915
|
+
method: "POST",
|
3916
|
+
onMessage: (message) => {
|
3917
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3918
|
+
},
|
3919
|
+
...params
|
3920
|
+
});
|
3921
|
+
} else {
|
3922
|
+
return askTableSession(params);
|
3923
|
+
}
|
3924
|
+
}
|
2635
3925
|
}
|
2636
3926
|
_table = new WeakMap();
|
2637
3927
|
_getFetchProps = new WeakMap();
|
@@ -2641,8 +3931,7 @@ _schemaTables$2 = new WeakMap();
|
|
2641
3931
|
_trace = new WeakMap();
|
2642
3932
|
_insertRecordWithoutId = new WeakSet();
|
2643
3933
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2644
|
-
const
|
2645
|
-
const record = transformObjectLinks(object);
|
3934
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2646
3935
|
const response = await insertRecord({
|
2647
3936
|
pathParams: {
|
2648
3937
|
workspace: "{workspaceId}",
|
@@ -2652,15 +3941,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2652
3941
|
},
|
2653
3942
|
queryParams: { columns },
|
2654
3943
|
body: record,
|
2655
|
-
...
|
3944
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2656
3945
|
});
|
2657
3946
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2658
3947
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2659
3948
|
};
|
2660
3949
|
_insertRecordWithId = new WeakSet();
|
2661
3950
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2662
|
-
|
2663
|
-
|
3951
|
+
if (!recordId)
|
3952
|
+
return null;
|
3953
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2664
3954
|
const response = await insertRecordWithID({
|
2665
3955
|
pathParams: {
|
2666
3956
|
workspace: "{workspaceId}",
|
@@ -2671,30 +3961,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2671
3961
|
},
|
2672
3962
|
body: record,
|
2673
3963
|
queryParams: { createOnly, columns, ifVersion },
|
2674
|
-
...
|
3964
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2675
3965
|
});
|
2676
3966
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2677
3967
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2678
3968
|
};
|
2679
3969
|
_insertRecords = new WeakSet();
|
2680
3970
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2681
|
-
const
|
2682
|
-
|
2683
|
-
|
2684
|
-
|
2685
|
-
|
2686
|
-
BULK_OPERATION_MAX_SIZE
|
2687
|
-
);
|
3971
|
+
const operations = await promiseMap(objects, async (object) => {
|
3972
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3973
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3974
|
+
});
|
3975
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2688
3976
|
const ids = [];
|
2689
|
-
for (const
|
3977
|
+
for (const operations2 of chunkedOperations) {
|
2690
3978
|
const { results } = await branchTransaction({
|
2691
3979
|
pathParams: {
|
2692
3980
|
workspace: "{workspaceId}",
|
2693
3981
|
dbBranchName: "{dbBranch}",
|
2694
3982
|
region: "{region}"
|
2695
3983
|
},
|
2696
|
-
body: { operations },
|
2697
|
-
...
|
3984
|
+
body: { operations: operations2 },
|
3985
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2698
3986
|
});
|
2699
3987
|
for (const result of results) {
|
2700
3988
|
if (result.operation === "insert") {
|
@@ -2708,8 +3996,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2708
3996
|
};
|
2709
3997
|
_updateRecordWithID = new WeakSet();
|
2710
3998
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2711
|
-
|
2712
|
-
|
3999
|
+
if (!recordId)
|
4000
|
+
return null;
|
4001
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2713
4002
|
try {
|
2714
4003
|
const response = await updateRecordWithID({
|
2715
4004
|
pathParams: {
|
@@ -2721,7 +4010,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2721
4010
|
},
|
2722
4011
|
queryParams: { columns, ifVersion },
|
2723
4012
|
body: record,
|
2724
|
-
...
|
4013
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2725
4014
|
});
|
2726
4015
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2727
4016
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2734,23 +4023,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2734
4023
|
};
|
2735
4024
|
_updateRecords = new WeakSet();
|
2736
4025
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2737
|
-
const
|
2738
|
-
|
2739
|
-
|
2740
|
-
|
2741
|
-
|
2742
|
-
BULK_OPERATION_MAX_SIZE
|
2743
|
-
);
|
4026
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
4027
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
4028
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
4029
|
+
});
|
4030
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2744
4031
|
const ids = [];
|
2745
|
-
for (const
|
4032
|
+
for (const operations2 of chunkedOperations) {
|
2746
4033
|
const { results } = await branchTransaction({
|
2747
4034
|
pathParams: {
|
2748
4035
|
workspace: "{workspaceId}",
|
2749
4036
|
dbBranchName: "{dbBranch}",
|
2750
4037
|
region: "{region}"
|
2751
4038
|
},
|
2752
|
-
body: { operations },
|
2753
|
-
...
|
4039
|
+
body: { operations: operations2 },
|
4040
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2754
4041
|
});
|
2755
4042
|
for (const result of results) {
|
2756
4043
|
if (result.operation === "update") {
|
@@ -2764,7 +4051,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2764
4051
|
};
|
2765
4052
|
_upsertRecordWithID = new WeakSet();
|
2766
4053
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2767
|
-
|
4054
|
+
if (!recordId)
|
4055
|
+
return null;
|
2768
4056
|
const response = await upsertRecordWithID({
|
2769
4057
|
pathParams: {
|
2770
4058
|
workspace: "{workspaceId}",
|
@@ -2775,14 +4063,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2775
4063
|
},
|
2776
4064
|
queryParams: { columns, ifVersion },
|
2777
4065
|
body: object,
|
2778
|
-
...
|
4066
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2779
4067
|
});
|
2780
4068
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2781
4069
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2782
4070
|
};
|
2783
4071
|
_deleteRecord = new WeakSet();
|
2784
4072
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2785
|
-
|
4073
|
+
if (!recordId)
|
4074
|
+
return null;
|
2786
4075
|
try {
|
2787
4076
|
const response = await deleteRecord({
|
2788
4077
|
pathParams: {
|
@@ -2793,7 +4082,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2793
4082
|
recordId
|
2794
4083
|
},
|
2795
4084
|
queryParams: { columns },
|
2796
|
-
...
|
4085
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2797
4086
|
});
|
2798
4087
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2799
4088
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2806,9 +4095,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2806
4095
|
};
|
2807
4096
|
_deleteRecords = new WeakSet();
|
2808
4097
|
deleteRecords_fn = async function(recordIds) {
|
2809
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2810
4098
|
const chunkedOperations = chunk(
|
2811
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
4099
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2812
4100
|
BULK_OPERATION_MAX_SIZE
|
2813
4101
|
);
|
2814
4102
|
for (const operations of chunkedOperations) {
|
@@ -2819,13 +4107,13 @@ deleteRecords_fn = async function(recordIds) {
|
|
2819
4107
|
region: "{region}"
|
2820
4108
|
},
|
2821
4109
|
body: { operations },
|
2822
|
-
...
|
4110
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2823
4111
|
});
|
2824
4112
|
}
|
2825
4113
|
};
|
2826
4114
|
_setCacheQuery = new WeakSet();
|
2827
4115
|
setCacheQuery_fn = async function(query, meta, records) {
|
2828
|
-
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
4116
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2829
4117
|
};
|
2830
4118
|
_getCacheQuery = new WeakSet();
|
2831
4119
|
getCacheQuery_fn = async function(query) {
|
@@ -2844,15 +4132,49 @@ _getSchemaTables$1 = new WeakSet();
|
|
2844
4132
|
getSchemaTables_fn$1 = async function() {
|
2845
4133
|
if (__privateGet$4(this, _schemaTables$2))
|
2846
4134
|
return __privateGet$4(this, _schemaTables$2);
|
2847
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2848
4135
|
const { schema } = await getBranchDetails({
|
2849
4136
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2850
|
-
...
|
4137
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2851
4138
|
});
|
2852
4139
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2853
4140
|
return schema.tables;
|
2854
4141
|
};
|
2855
|
-
|
4142
|
+
_transformObjectToApi = new WeakSet();
|
4143
|
+
transformObjectToApi_fn = async function(object) {
|
4144
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4145
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4146
|
+
if (!schema)
|
4147
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4148
|
+
const result = {};
|
4149
|
+
for (const [key, value] of Object.entries(object)) {
|
4150
|
+
if (key === "xata")
|
4151
|
+
continue;
|
4152
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4153
|
+
switch (type) {
|
4154
|
+
case "link": {
|
4155
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4156
|
+
break;
|
4157
|
+
}
|
4158
|
+
case "datetime": {
|
4159
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4160
|
+
break;
|
4161
|
+
}
|
4162
|
+
case `file`:
|
4163
|
+
result[key] = await parseInputFileEntry(value);
|
4164
|
+
break;
|
4165
|
+
case "file[]":
|
4166
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4167
|
+
break;
|
4168
|
+
case "json":
|
4169
|
+
result[key] = stringifyJson(value);
|
4170
|
+
break;
|
4171
|
+
default:
|
4172
|
+
result[key] = value;
|
4173
|
+
}
|
4174
|
+
}
|
4175
|
+
return result;
|
4176
|
+
};
|
4177
|
+
const removeLinksFromObject = (object) => {
|
2856
4178
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
2857
4179
|
if (key === "xata")
|
2858
4180
|
return acc;
|
@@ -2889,18 +4211,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2889
4211
|
if (item === column.name) {
|
2890
4212
|
return [...acc, "*"];
|
2891
4213
|
}
|
2892
|
-
if (item.startsWith(`${column.name}.`)) {
|
4214
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2893
4215
|
const [, ...path] = item.split(".");
|
2894
4216
|
return [...acc, path.join(".")];
|
2895
4217
|
}
|
2896
4218
|
return acc;
|
2897
4219
|
}, []);
|
2898
|
-
data[column.name] = initObject(
|
4220
|
+
data[column.name] = initObject(
|
4221
|
+
db,
|
4222
|
+
schemaTables,
|
4223
|
+
linkTable,
|
4224
|
+
value,
|
4225
|
+
selectedLinkColumns
|
4226
|
+
);
|
2899
4227
|
} else {
|
2900
4228
|
data[column.name] = null;
|
2901
4229
|
}
|
2902
4230
|
break;
|
2903
4231
|
}
|
4232
|
+
case "file":
|
4233
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4234
|
+
break;
|
4235
|
+
case "file[]":
|
4236
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4237
|
+
break;
|
4238
|
+
case "json":
|
4239
|
+
data[column.name] = parseJson(value);
|
4240
|
+
break;
|
2904
4241
|
default:
|
2905
4242
|
data[column.name] = value ?? null;
|
2906
4243
|
if (column.notNull === true && value === null) {
|
@@ -2910,30 +4247,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2910
4247
|
}
|
2911
4248
|
}
|
2912
4249
|
const record = { ...data };
|
4250
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
4251
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2913
4252
|
record.read = function(columns2) {
|
2914
4253
|
return db[table].read(record["id"], columns2);
|
2915
4254
|
};
|
2916
4255
|
record.update = function(data2, b, c) {
|
2917
|
-
const columns2 =
|
4256
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2918
4257
|
const ifVersion = parseIfVersion(b, c);
|
2919
4258
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2920
4259
|
};
|
2921
4260
|
record.replace = function(data2, b, c) {
|
2922
|
-
const columns2 =
|
4261
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2923
4262
|
const ifVersion = parseIfVersion(b, c);
|
2924
4263
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
2925
4264
|
};
|
2926
4265
|
record.delete = function() {
|
2927
4266
|
return db[table].delete(record["id"]);
|
2928
4267
|
};
|
4268
|
+
record.xata = Object.freeze(metadata);
|
2929
4269
|
record.getMetadata = function() {
|
2930
|
-
return xata;
|
4270
|
+
return record.xata;
|
2931
4271
|
};
|
2932
4272
|
record.toSerializable = function() {
|
2933
|
-
return JSON.parse(JSON.stringify(
|
4273
|
+
return JSON.parse(JSON.stringify(serializable));
|
2934
4274
|
};
|
2935
4275
|
record.toString = function() {
|
2936
|
-
return JSON.stringify(
|
4276
|
+
return JSON.stringify(serializable);
|
2937
4277
|
};
|
2938
4278
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2939
4279
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -2951,11 +4291,7 @@ function extractId(value) {
|
|
2951
4291
|
function isValidColumn(columns, column) {
|
2952
4292
|
if (columns.includes("*"))
|
2953
4293
|
return true;
|
2954
|
-
|
2955
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2956
|
-
return linkColumns.length > 0;
|
2957
|
-
}
|
2958
|
-
return columns.includes(column.name);
|
4294
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
2959
4295
|
}
|
2960
4296
|
function parseIfVersion(...args) {
|
2961
4297
|
for (const arg of args) {
|
@@ -2966,6 +4302,12 @@ function parseIfVersion(...args) {
|
|
2966
4302
|
return void 0;
|
2967
4303
|
}
|
2968
4304
|
|
4305
|
+
var __defProp$3 = Object.defineProperty;
|
4306
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4307
|
+
var __publicField$3 = (obj, key, value) => {
|
4308
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4309
|
+
return value;
|
4310
|
+
};
|
2969
4311
|
var __accessCheck$3 = (obj, member, msg) => {
|
2970
4312
|
if (!member.has(obj))
|
2971
4313
|
throw TypeError("Cannot " + msg);
|
@@ -2988,6 +4330,8 @@ var _map;
|
|
2988
4330
|
class SimpleCache {
|
2989
4331
|
constructor(options = {}) {
|
2990
4332
|
__privateAdd$3(this, _map, void 0);
|
4333
|
+
__publicField$3(this, "capacity");
|
4334
|
+
__publicField$3(this, "defaultQueryTTL");
|
2991
4335
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
2992
4336
|
this.capacity = options.max ?? 500;
|
2993
4337
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3123,19 +4467,19 @@ class SearchPlugin extends XataPlugin {
|
|
3123
4467
|
__privateAdd$1(this, _schemaTables, void 0);
|
3124
4468
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3125
4469
|
}
|
3126
|
-
build(
|
4470
|
+
build(pluginOptions) {
|
3127
4471
|
return {
|
3128
4472
|
all: async (query, options = {}) => {
|
3129
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3130
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4473
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4474
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3131
4475
|
return records.map((record) => {
|
3132
4476
|
const { table = "orphan" } = record.xata;
|
3133
4477
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3134
4478
|
});
|
3135
4479
|
},
|
3136
4480
|
byTable: async (query, options = {}) => {
|
3137
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3138
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4481
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4482
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3139
4483
|
return records.reduce((acc, record) => {
|
3140
4484
|
const { table = "orphan" } = record.xata;
|
3141
4485
|
const items = acc[table] ?? [];
|
@@ -3148,38 +4492,108 @@ class SearchPlugin extends XataPlugin {
|
|
3148
4492
|
}
|
3149
4493
|
_schemaTables = new WeakMap();
|
3150
4494
|
_search = new WeakSet();
|
3151
|
-
search_fn = async function(query, options,
|
3152
|
-
const fetchProps = await getFetchProps();
|
4495
|
+
search_fn = async function(query, options, pluginOptions) {
|
3153
4496
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3154
4497
|
const { records } = await searchBranch({
|
3155
4498
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4499
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3156
4500
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3157
|
-
...
|
4501
|
+
...pluginOptions
|
3158
4502
|
});
|
3159
4503
|
return records;
|
3160
4504
|
};
|
3161
4505
|
_getSchemaTables = new WeakSet();
|
3162
|
-
getSchemaTables_fn = async function(
|
4506
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3163
4507
|
if (__privateGet$1(this, _schemaTables))
|
3164
4508
|
return __privateGet$1(this, _schemaTables);
|
3165
|
-
const fetchProps = await getFetchProps();
|
3166
4509
|
const { schema } = await getBranchDetails({
|
3167
4510
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3168
|
-
...
|
4511
|
+
...pluginOptions
|
3169
4512
|
});
|
3170
4513
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3171
4514
|
return schema.tables;
|
3172
4515
|
};
|
3173
4516
|
|
4517
|
+
function escapeElement(elementRepresentation) {
|
4518
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4519
|
+
return '"' + escaped + '"';
|
4520
|
+
}
|
4521
|
+
function arrayString(val) {
|
4522
|
+
let result = "{";
|
4523
|
+
for (let i = 0; i < val.length; i++) {
|
4524
|
+
if (i > 0) {
|
4525
|
+
result = result + ",";
|
4526
|
+
}
|
4527
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4528
|
+
result = result + "NULL";
|
4529
|
+
} else if (Array.isArray(val[i])) {
|
4530
|
+
result = result + arrayString(val[i]);
|
4531
|
+
} else if (val[i] instanceof Buffer) {
|
4532
|
+
result += "\\\\x" + val[i].toString("hex");
|
4533
|
+
} else {
|
4534
|
+
result += escapeElement(prepareValue(val[i]));
|
4535
|
+
}
|
4536
|
+
}
|
4537
|
+
result = result + "}";
|
4538
|
+
return result;
|
4539
|
+
}
|
4540
|
+
function prepareValue(value) {
|
4541
|
+
if (!isDefined(value))
|
4542
|
+
return null;
|
4543
|
+
if (value instanceof Date) {
|
4544
|
+
return value.toISOString();
|
4545
|
+
}
|
4546
|
+
if (Array.isArray(value)) {
|
4547
|
+
return arrayString(value);
|
4548
|
+
}
|
4549
|
+
if (isObject(value)) {
|
4550
|
+
return JSON.stringify(value);
|
4551
|
+
}
|
4552
|
+
try {
|
4553
|
+
return value.toString();
|
4554
|
+
} catch (e) {
|
4555
|
+
return value;
|
4556
|
+
}
|
4557
|
+
}
|
4558
|
+
function prepareParams(param1, param2) {
|
4559
|
+
if (isString(param1)) {
|
4560
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4561
|
+
}
|
4562
|
+
if (isStringArray(param1)) {
|
4563
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4564
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4565
|
+
}, "");
|
4566
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4567
|
+
}
|
4568
|
+
if (isObject(param1)) {
|
4569
|
+
const { statement, params, consistency } = param1;
|
4570
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4571
|
+
}
|
4572
|
+
throw new Error("Invalid query");
|
4573
|
+
}
|
4574
|
+
|
4575
|
+
class SQLPlugin extends XataPlugin {
|
4576
|
+
build(pluginOptions) {
|
4577
|
+
return async (param1, ...param2) => {
|
4578
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4579
|
+
const { records, warning } = await sqlQuery({
|
4580
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4581
|
+
body: { statement, params, consistency },
|
4582
|
+
...pluginOptions
|
4583
|
+
});
|
4584
|
+
return { records, warning };
|
4585
|
+
};
|
4586
|
+
}
|
4587
|
+
}
|
4588
|
+
|
3174
4589
|
class TransactionPlugin extends XataPlugin {
|
3175
|
-
build(
|
4590
|
+
build(pluginOptions) {
|
3176
4591
|
return {
|
3177
4592
|
run: async (operations) => {
|
3178
|
-
const fetchProps = await getFetchProps();
|
3179
4593
|
const response = await branchTransaction({
|
3180
4594
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3181
4595
|
body: { operations },
|
3182
|
-
...
|
4596
|
+
...pluginOptions
|
3183
4597
|
});
|
3184
4598
|
return response;
|
3185
4599
|
}
|
@@ -3187,10 +4601,12 @@ class TransactionPlugin extends XataPlugin {
|
|
3187
4601
|
}
|
3188
4602
|
}
|
3189
4603
|
|
3190
|
-
|
3191
|
-
|
4604
|
+
var __defProp$2 = Object.defineProperty;
|
4605
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4606
|
+
var __publicField$2 = (obj, key, value) => {
|
4607
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4608
|
+
return value;
|
3192
4609
|
};
|
3193
|
-
|
3194
4610
|
var __accessCheck = (obj, member, msg) => {
|
3195
4611
|
if (!member.has(obj))
|
3196
4612
|
throw TypeError("Cannot " + msg);
|
@@ -3214,27 +4630,34 @@ var __privateMethod = (obj, member, method) => {
|
|
3214
4630
|
return method;
|
3215
4631
|
};
|
3216
4632
|
const buildClient = (plugins) => {
|
3217
|
-
var
|
4633
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3218
4634
|
return _a = class {
|
3219
4635
|
constructor(options = {}, schemaTables) {
|
3220
4636
|
__privateAdd(this, _parseOptions);
|
3221
4637
|
__privateAdd(this, _getFetchProps);
|
3222
|
-
__privateAdd(this, _evaluateBranch);
|
3223
|
-
__privateAdd(this, _branch, void 0);
|
3224
4638
|
__privateAdd(this, _options, void 0);
|
4639
|
+
__publicField$2(this, "db");
|
4640
|
+
__publicField$2(this, "search");
|
4641
|
+
__publicField$2(this, "transactions");
|
4642
|
+
__publicField$2(this, "sql");
|
4643
|
+
__publicField$2(this, "files");
|
3225
4644
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3226
4645
|
__privateSet(this, _options, safeOptions);
|
3227
4646
|
const pluginOptions = {
|
3228
|
-
|
4647
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3229
4648
|
cache: safeOptions.cache,
|
3230
|
-
|
4649
|
+
host: safeOptions.host
|
3231
4650
|
};
|
3232
4651
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3233
4652
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3234
4653
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4654
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4655
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3235
4656
|
this.db = db;
|
3236
4657
|
this.search = search;
|
3237
4658
|
this.transactions = transactions;
|
4659
|
+
this.sql = sql;
|
4660
|
+
this.files = files;
|
3238
4661
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3239
4662
|
if (namespace === void 0)
|
3240
4663
|
continue;
|
@@ -3246,7 +4669,7 @@ const buildClient = (plugins) => {
|
|
3246
4669
|
const branch = __privateGet(this, _options).branch;
|
3247
4670
|
return { databaseURL, branch };
|
3248
4671
|
}
|
3249
|
-
},
|
4672
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3250
4673
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3251
4674
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3252
4675
|
if (isBrowser && !enableBrowser) {
|
@@ -3261,13 +4684,33 @@ const buildClient = (plugins) => {
|
|
3261
4684
|
const trace = options?.trace ?? defaultTrace;
|
3262
4685
|
const clientName = options?.clientName;
|
3263
4686
|
const host = options?.host ?? "production";
|
3264
|
-
const
|
4687
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3265
4688
|
if (!apiKey) {
|
3266
4689
|
throw new Error("Option apiKey is required");
|
3267
4690
|
}
|
3268
4691
|
if (!databaseURL) {
|
3269
4692
|
throw new Error("Option databaseURL is required");
|
3270
4693
|
}
|
4694
|
+
const envBranch = getBranch();
|
4695
|
+
const previewBranch = getPreviewBranch();
|
4696
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4697
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4698
|
+
console.warn(
|
4699
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4700
|
+
);
|
4701
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4702
|
+
console.warn(
|
4703
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4704
|
+
);
|
4705
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4706
|
+
console.warn(
|
4707
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4708
|
+
);
|
4709
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4710
|
+
console.warn(
|
4711
|
+
`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.`
|
4712
|
+
);
|
4713
|
+
}
|
3271
4714
|
return {
|
3272
4715
|
fetch,
|
3273
4716
|
databaseURL,
|
@@ -3278,51 +4721,50 @@ const buildClient = (plugins) => {
|
|
3278
4721
|
host,
|
3279
4722
|
clientID: generateUUID(),
|
3280
4723
|
enableBrowser,
|
3281
|
-
clientName
|
4724
|
+
clientName,
|
4725
|
+
xataAgentExtra
|
3282
4726
|
};
|
3283
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3284
|
-
|
3285
|
-
|
3286
|
-
|
4727
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4728
|
+
fetch,
|
4729
|
+
apiKey,
|
4730
|
+
databaseURL,
|
4731
|
+
branch,
|
4732
|
+
trace,
|
4733
|
+
clientID,
|
4734
|
+
clientName,
|
4735
|
+
xataAgentExtra
|
4736
|
+
}) {
|
3287
4737
|
return {
|
3288
|
-
|
4738
|
+
fetch,
|
3289
4739
|
apiKey,
|
3290
4740
|
apiUrl: "",
|
4741
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3291
4742
|
workspacesApiUrl: (path, params) => {
|
3292
4743
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3293
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4744
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3294
4745
|
return databaseURL + newPath;
|
3295
4746
|
},
|
3296
4747
|
trace,
|
3297
4748
|
clientID,
|
3298
|
-
clientName
|
3299
|
-
|
3300
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = function(param) {
|
3301
|
-
if (__privateGet(this, _branch))
|
3302
|
-
return __privateGet(this, _branch);
|
3303
|
-
if (param === void 0)
|
3304
|
-
return void 0;
|
3305
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3306
|
-
const evaluateBranch = (strategy) => {
|
3307
|
-
return isBranchStrategyBuilder(strategy) ? strategy() : strategy;
|
4749
|
+
clientName,
|
4750
|
+
xataAgentExtra
|
3308
4751
|
};
|
3309
|
-
for (const strategy of strategies) {
|
3310
|
-
const branch = evaluateBranch(strategy);
|
3311
|
-
if (branch) {
|
3312
|
-
__privateSet(this, _branch, branch);
|
3313
|
-
return branch;
|
3314
|
-
}
|
3315
|
-
}
|
3316
4752
|
}, _a;
|
3317
4753
|
};
|
3318
4754
|
class BaseClient extends buildClient() {
|
3319
4755
|
}
|
3320
4756
|
|
4757
|
+
var __defProp$1 = Object.defineProperty;
|
4758
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4759
|
+
var __publicField$1 = (obj, key, value) => {
|
4760
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4761
|
+
return value;
|
4762
|
+
};
|
3321
4763
|
const META = "__";
|
3322
4764
|
const VALUE = "___";
|
3323
4765
|
class Serializer {
|
3324
4766
|
constructor() {
|
3325
|
-
this
|
4767
|
+
__publicField$1(this, "classes", {});
|
3326
4768
|
}
|
3327
4769
|
add(clazz) {
|
3328
4770
|
this.classes[clazz.name] = clazz;
|
@@ -3400,12 +4842,19 @@ function buildWorkerRunner(config) {
|
|
3400
4842
|
};
|
3401
4843
|
}
|
3402
4844
|
|
4845
|
+
var __defProp = Object.defineProperty;
|
4846
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4847
|
+
var __publicField = (obj, key, value) => {
|
4848
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4849
|
+
return value;
|
4850
|
+
};
|
3403
4851
|
class XataError extends Error {
|
3404
4852
|
constructor(message, status) {
|
3405
4853
|
super(message);
|
4854
|
+
__publicField(this, "status");
|
3406
4855
|
this.status = status;
|
3407
4856
|
}
|
3408
4857
|
}
|
3409
4858
|
|
3410
|
-
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
4859
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3411
4860
|
//# sourceMappingURL=index.mjs.map
|