@xata.io/client 0.0.0-alpha.vfa22996 → 0.0.0-alpha.vfaba5d6
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 +4 -0
- package/.turbo/turbo-build.log +18 -0
- package/CHANGELOG.md +196 -0
- package/README.md +3 -269
- package/dist/index.cjs +1220 -337
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3034 -1622
- package/dist/index.mjs +1198 -331
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -10
- package/.eslintrc.cjs +0 -12
- package/Usage.md +0 -451
- package/rollup.config.mjs +0 -29
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
const defaultTrace = async (
|
1
|
+
const defaultTrace = async (name, fn, _options) => {
|
2
2
|
return await fn({
|
3
|
+
name,
|
3
4
|
setAttributes: () => {
|
4
5
|
return;
|
5
6
|
}
|
@@ -26,8 +27,11 @@ function notEmpty(value) {
|
|
26
27
|
function compact(arr) {
|
27
28
|
return arr.filter(notEmpty);
|
28
29
|
}
|
30
|
+
function compactObject(obj) {
|
31
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
32
|
+
}
|
29
33
|
function isObject(value) {
|
30
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
34
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
31
35
|
}
|
32
36
|
function isDefined(value) {
|
33
37
|
return value !== null && value !== void 0;
|
@@ -90,8 +94,10 @@ function getEnvironment() {
|
|
90
94
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
91
95
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
92
96
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
93
|
-
|
94
|
-
|
97
|
+
deployPreview: process.env.XATA_PREVIEW,
|
98
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
99
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
100
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
95
101
|
};
|
96
102
|
}
|
97
103
|
} catch (err) {
|
@@ -102,8 +108,10 @@ function getEnvironment() {
|
|
102
108
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
103
109
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
104
110
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
105
|
-
|
106
|
-
|
111
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
112
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
113
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
114
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
107
115
|
};
|
108
116
|
}
|
109
117
|
} catch (err) {
|
@@ -112,8 +120,10 @@ function getEnvironment() {
|
|
112
120
|
apiKey: getGlobalApiKey(),
|
113
121
|
databaseURL: getGlobalDatabaseURL(),
|
114
122
|
branch: getGlobalBranch(),
|
115
|
-
|
116
|
-
|
123
|
+
deployPreview: void 0,
|
124
|
+
deployPreviewBranch: void 0,
|
125
|
+
vercelGitCommitRef: void 0,
|
126
|
+
vercelGitRepoOwner: void 0
|
117
127
|
};
|
118
128
|
}
|
119
129
|
function getEnableBrowserVariable() {
|
@@ -156,44 +166,59 @@ function getGlobalBranch() {
|
|
156
166
|
return void 0;
|
157
167
|
}
|
158
168
|
}
|
159
|
-
function
|
169
|
+
function getDatabaseURL() {
|
160
170
|
try {
|
161
|
-
|
171
|
+
const { databaseURL } = getEnvironment();
|
172
|
+
return databaseURL;
|
162
173
|
} catch (err) {
|
163
174
|
return void 0;
|
164
175
|
}
|
165
176
|
}
|
166
|
-
|
167
|
-
const cmd = ["git", "branch", "--show-current"];
|
168
|
-
const fullCmd = cmd.join(" ");
|
169
|
-
const nodeModule = ["child", "process"].join("_");
|
170
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
177
|
+
function getAPIKey() {
|
171
178
|
try {
|
172
|
-
|
173
|
-
|
174
|
-
}
|
175
|
-
const { execSync } = await import(nodeModule);
|
176
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
179
|
+
const { apiKey } = getEnvironment();
|
180
|
+
return apiKey;
|
177
181
|
} catch (err) {
|
182
|
+
return void 0;
|
178
183
|
}
|
184
|
+
}
|
185
|
+
function getBranch() {
|
179
186
|
try {
|
180
|
-
|
181
|
-
|
182
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
183
|
-
}
|
187
|
+
const { branch } = getEnvironment();
|
188
|
+
return branch ?? "main";
|
184
189
|
} catch (err) {
|
190
|
+
return void 0;
|
185
191
|
}
|
186
192
|
}
|
187
|
-
|
188
|
-
|
193
|
+
function buildPreviewBranchName({ org, branch }) {
|
194
|
+
return `preview-${org}-${branch}`;
|
195
|
+
}
|
196
|
+
function getPreviewBranch() {
|
189
197
|
try {
|
190
|
-
const {
|
191
|
-
|
198
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
199
|
+
if (deployPreviewBranch)
|
200
|
+
return deployPreviewBranch;
|
201
|
+
switch (deployPreview) {
|
202
|
+
case "vercel": {
|
203
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
204
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
205
|
+
return void 0;
|
206
|
+
}
|
207
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
208
|
+
}
|
209
|
+
}
|
210
|
+
return void 0;
|
192
211
|
} catch (err) {
|
193
212
|
return void 0;
|
194
213
|
}
|
195
214
|
}
|
196
215
|
|
216
|
+
var __defProp$7 = Object.defineProperty;
|
217
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
218
|
+
var __publicField$7 = (obj, key, value) => {
|
219
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
220
|
+
return value;
|
221
|
+
};
|
197
222
|
var __accessCheck$8 = (obj, member, msg) => {
|
198
223
|
if (!member.has(obj))
|
199
224
|
throw TypeError("Cannot " + msg);
|
@@ -233,6 +258,8 @@ class ApiRequestPool {
|
|
233
258
|
__privateAdd$8(this, _fetch, void 0);
|
234
259
|
__privateAdd$8(this, _queue, void 0);
|
235
260
|
__privateAdd$8(this, _concurrency, void 0);
|
261
|
+
__publicField$7(this, "running");
|
262
|
+
__publicField$7(this, "started");
|
236
263
|
__privateSet$8(this, _queue, []);
|
237
264
|
__privateSet$8(this, _concurrency, concurrency);
|
238
265
|
this.running = 0;
|
@@ -248,7 +275,7 @@ class ApiRequestPool {
|
|
248
275
|
return __privateGet$8(this, _fetch);
|
249
276
|
}
|
250
277
|
request(url, options) {
|
251
|
-
const start = new Date();
|
278
|
+
const start = /* @__PURE__ */ new Date();
|
252
279
|
const fetch2 = this.getFetch();
|
253
280
|
const runRequest = async (stalled = false) => {
|
254
281
|
const response = await fetch2(url, options);
|
@@ -258,7 +285,7 @@ class ApiRequestPool {
|
|
258
285
|
return await runRequest(true);
|
259
286
|
}
|
260
287
|
if (stalled) {
|
261
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
288
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
262
289
|
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
263
290
|
}
|
264
291
|
return response;
|
@@ -294,18 +321,208 @@ enqueue_fn = function(task) {
|
|
294
321
|
return promise;
|
295
322
|
};
|
296
323
|
|
297
|
-
|
324
|
+
function generateUUID() {
|
325
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
326
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
327
|
+
return v.toString(16);
|
328
|
+
});
|
329
|
+
}
|
330
|
+
|
331
|
+
async function getBytes(stream, onChunk) {
|
332
|
+
const reader = stream.getReader();
|
333
|
+
let result;
|
334
|
+
while (!(result = await reader.read()).done) {
|
335
|
+
onChunk(result.value);
|
336
|
+
}
|
337
|
+
}
|
338
|
+
function getLines(onLine) {
|
339
|
+
let buffer;
|
340
|
+
let position;
|
341
|
+
let fieldLength;
|
342
|
+
let discardTrailingNewline = false;
|
343
|
+
return function onChunk(arr) {
|
344
|
+
if (buffer === void 0) {
|
345
|
+
buffer = arr;
|
346
|
+
position = 0;
|
347
|
+
fieldLength = -1;
|
348
|
+
} else {
|
349
|
+
buffer = concat(buffer, arr);
|
350
|
+
}
|
351
|
+
const bufLength = buffer.length;
|
352
|
+
let lineStart = 0;
|
353
|
+
while (position < bufLength) {
|
354
|
+
if (discardTrailingNewline) {
|
355
|
+
if (buffer[position] === 10 /* NewLine */) {
|
356
|
+
lineStart = ++position;
|
357
|
+
}
|
358
|
+
discardTrailingNewline = false;
|
359
|
+
}
|
360
|
+
let lineEnd = -1;
|
361
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
362
|
+
switch (buffer[position]) {
|
363
|
+
case 58 /* Colon */:
|
364
|
+
if (fieldLength === -1) {
|
365
|
+
fieldLength = position - lineStart;
|
366
|
+
}
|
367
|
+
break;
|
368
|
+
case 13 /* CarriageReturn */:
|
369
|
+
discardTrailingNewline = true;
|
370
|
+
case 10 /* NewLine */:
|
371
|
+
lineEnd = position;
|
372
|
+
break;
|
373
|
+
}
|
374
|
+
}
|
375
|
+
if (lineEnd === -1) {
|
376
|
+
break;
|
377
|
+
}
|
378
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
379
|
+
lineStart = position;
|
380
|
+
fieldLength = -1;
|
381
|
+
}
|
382
|
+
if (lineStart === bufLength) {
|
383
|
+
buffer = void 0;
|
384
|
+
} else if (lineStart !== 0) {
|
385
|
+
buffer = buffer.subarray(lineStart);
|
386
|
+
position -= lineStart;
|
387
|
+
}
|
388
|
+
};
|
389
|
+
}
|
390
|
+
function getMessages(onId, onRetry, onMessage) {
|
391
|
+
let message = newMessage();
|
392
|
+
const decoder = new TextDecoder();
|
393
|
+
return function onLine(line, fieldLength) {
|
394
|
+
if (line.length === 0) {
|
395
|
+
onMessage?.(message);
|
396
|
+
message = newMessage();
|
397
|
+
} else if (fieldLength > 0) {
|
398
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
399
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
400
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
401
|
+
switch (field) {
|
402
|
+
case "data":
|
403
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
404
|
+
break;
|
405
|
+
case "event":
|
406
|
+
message.event = value;
|
407
|
+
break;
|
408
|
+
case "id":
|
409
|
+
onId(message.id = value);
|
410
|
+
break;
|
411
|
+
case "retry":
|
412
|
+
const retry = parseInt(value, 10);
|
413
|
+
if (!isNaN(retry)) {
|
414
|
+
onRetry(message.retry = retry);
|
415
|
+
}
|
416
|
+
break;
|
417
|
+
}
|
418
|
+
}
|
419
|
+
};
|
420
|
+
}
|
421
|
+
function concat(a, b) {
|
422
|
+
const res = new Uint8Array(a.length + b.length);
|
423
|
+
res.set(a);
|
424
|
+
res.set(b, a.length);
|
425
|
+
return res;
|
426
|
+
}
|
427
|
+
function newMessage() {
|
428
|
+
return {
|
429
|
+
data: "",
|
430
|
+
event: "",
|
431
|
+
id: "",
|
432
|
+
retry: void 0
|
433
|
+
};
|
434
|
+
}
|
435
|
+
const EventStreamContentType = "text/event-stream";
|
436
|
+
const LastEventId = "last-event-id";
|
437
|
+
function fetchEventSource(input, {
|
438
|
+
signal: inputSignal,
|
439
|
+
headers: inputHeaders,
|
440
|
+
onopen: inputOnOpen,
|
441
|
+
onmessage,
|
442
|
+
onclose,
|
443
|
+
onerror,
|
444
|
+
fetch: inputFetch,
|
445
|
+
...rest
|
446
|
+
}) {
|
447
|
+
return new Promise((resolve, reject) => {
|
448
|
+
const headers = { ...inputHeaders };
|
449
|
+
if (!headers.accept) {
|
450
|
+
headers.accept = EventStreamContentType;
|
451
|
+
}
|
452
|
+
let curRequestController;
|
453
|
+
function dispose() {
|
454
|
+
curRequestController.abort();
|
455
|
+
}
|
456
|
+
inputSignal?.addEventListener("abort", () => {
|
457
|
+
dispose();
|
458
|
+
resolve();
|
459
|
+
});
|
460
|
+
const fetchImpl = inputFetch ?? fetch;
|
461
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
462
|
+
async function create() {
|
463
|
+
curRequestController = new AbortController();
|
464
|
+
try {
|
465
|
+
const response = await fetchImpl(input, {
|
466
|
+
...rest,
|
467
|
+
headers,
|
468
|
+
signal: curRequestController.signal
|
469
|
+
});
|
470
|
+
await onopen(response);
|
471
|
+
await getBytes(
|
472
|
+
response.body,
|
473
|
+
getLines(
|
474
|
+
getMessages(
|
475
|
+
(id) => {
|
476
|
+
if (id) {
|
477
|
+
headers[LastEventId] = id;
|
478
|
+
} else {
|
479
|
+
delete headers[LastEventId];
|
480
|
+
}
|
481
|
+
},
|
482
|
+
(_retry) => {
|
483
|
+
},
|
484
|
+
onmessage
|
485
|
+
)
|
486
|
+
)
|
487
|
+
);
|
488
|
+
onclose?.();
|
489
|
+
dispose();
|
490
|
+
resolve();
|
491
|
+
} catch (err) {
|
492
|
+
}
|
493
|
+
}
|
494
|
+
create();
|
495
|
+
});
|
496
|
+
}
|
497
|
+
function defaultOnOpen(response) {
|
498
|
+
const contentType = response.headers?.get("content-type");
|
499
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
500
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
501
|
+
}
|
502
|
+
}
|
503
|
+
|
504
|
+
const VERSION = "0.24.3";
|
298
505
|
|
506
|
+
var __defProp$6 = Object.defineProperty;
|
507
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
508
|
+
var __publicField$6 = (obj, key, value) => {
|
509
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
510
|
+
return value;
|
511
|
+
};
|
299
512
|
class ErrorWithCause extends Error {
|
300
513
|
constructor(message, options) {
|
301
514
|
super(message, options);
|
515
|
+
__publicField$6(this, "cause");
|
302
516
|
}
|
303
517
|
}
|
304
518
|
class FetcherError extends ErrorWithCause {
|
305
519
|
constructor(status, data, requestId) {
|
306
520
|
super(getMessage(data));
|
521
|
+
__publicField$6(this, "status");
|
522
|
+
__publicField$6(this, "requestId");
|
523
|
+
__publicField$6(this, "errors");
|
307
524
|
this.status = status;
|
308
|
-
this.errors = isBulkError(data) ? data.errors :
|
525
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
309
526
|
this.requestId = requestId;
|
310
527
|
if (data instanceof Error) {
|
311
528
|
this.stack = data.stack;
|
@@ -370,14 +587,24 @@ function hostHeader(url) {
|
|
370
587
|
const { groups } = pattern.exec(url) ?? {};
|
371
588
|
return groups?.host ? { Host: groups.host } : {};
|
372
589
|
}
|
590
|
+
function parseBody(body, headers) {
|
591
|
+
if (!isDefined(body))
|
592
|
+
return void 0;
|
593
|
+
const { "Content-Type": contentType } = headers ?? {};
|
594
|
+
if (String(contentType).toLowerCase() === "application/json") {
|
595
|
+
return JSON.stringify(body);
|
596
|
+
}
|
597
|
+
return body;
|
598
|
+
}
|
599
|
+
const defaultClientID = generateUUID();
|
373
600
|
async function fetch$1({
|
374
601
|
url: path,
|
375
602
|
method,
|
376
603
|
body,
|
377
|
-
headers,
|
604
|
+
headers: customHeaders,
|
378
605
|
pathParams,
|
379
606
|
queryParams,
|
380
|
-
|
607
|
+
fetch: fetch2,
|
381
608
|
apiKey,
|
382
609
|
endpoint,
|
383
610
|
apiUrl,
|
@@ -386,9 +613,12 @@ async function fetch$1({
|
|
386
613
|
signal,
|
387
614
|
clientID,
|
388
615
|
sessionID,
|
389
|
-
|
616
|
+
clientName,
|
617
|
+
xataAgentExtra,
|
618
|
+
fetchOptions = {},
|
619
|
+
rawResponse = false
|
390
620
|
}) {
|
391
|
-
pool.setFetch(
|
621
|
+
pool.setFetch(fetch2);
|
392
622
|
return await trace(
|
393
623
|
`${method.toUpperCase()} ${path}`,
|
394
624
|
async ({ setAttributes }) => {
|
@@ -399,19 +629,27 @@ async function fetch$1({
|
|
399
629
|
[TraceAttributes.HTTP_URL]: url,
|
400
630
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
401
631
|
});
|
632
|
+
const xataAgent = compact([
|
633
|
+
["client", "TS_SDK"],
|
634
|
+
["version", VERSION],
|
635
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
636
|
+
...Object.entries(xataAgentExtra ?? {})
|
637
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
638
|
+
const headers = compactObject({
|
639
|
+
"Accept-Encoding": "identity",
|
640
|
+
"Content-Type": "application/json",
|
641
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
642
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
643
|
+
"X-Xata-Agent": xataAgent,
|
644
|
+
...customHeaders,
|
645
|
+
...hostHeader(fullUrl),
|
646
|
+
Authorization: `Bearer ${apiKey}`
|
647
|
+
});
|
402
648
|
const response = await pool.request(url, {
|
403
649
|
...fetchOptions,
|
404
650
|
method: method.toUpperCase(),
|
405
|
-
body: body
|
406
|
-
headers
|
407
|
-
"Content-Type": "application/json",
|
408
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
409
|
-
"X-Xata-Client-ID": clientID ?? "",
|
410
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
411
|
-
...headers,
|
412
|
-
...hostHeader(fullUrl),
|
413
|
-
Authorization: `Bearer ${apiKey}`
|
414
|
-
},
|
651
|
+
body: parseBody(body, headers),
|
652
|
+
headers,
|
415
653
|
signal
|
416
654
|
});
|
417
655
|
const { host, protocol } = parseUrl(response.url);
|
@@ -423,6 +661,9 @@ async function fetch$1({
|
|
423
661
|
[TraceAttributes.HTTP_HOST]: host,
|
424
662
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
425
663
|
});
|
664
|
+
const message = response.headers?.get("x-xata-message");
|
665
|
+
if (message)
|
666
|
+
console.warn(message);
|
426
667
|
if (response.status === 204) {
|
427
668
|
return {};
|
428
669
|
}
|
@@ -430,7 +671,7 @@ async function fetch$1({
|
|
430
671
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
431
672
|
}
|
432
673
|
try {
|
433
|
-
const jsonResponse = await response.json();
|
674
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
434
675
|
if (response.ok) {
|
435
676
|
return jsonResponse;
|
436
677
|
}
|
@@ -442,6 +683,59 @@ async function fetch$1({
|
|
442
683
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
443
684
|
);
|
444
685
|
}
|
686
|
+
function fetchSSERequest({
|
687
|
+
url: path,
|
688
|
+
method,
|
689
|
+
body,
|
690
|
+
headers: customHeaders,
|
691
|
+
pathParams,
|
692
|
+
queryParams,
|
693
|
+
fetch: fetch2,
|
694
|
+
apiKey,
|
695
|
+
endpoint,
|
696
|
+
apiUrl,
|
697
|
+
workspacesApiUrl,
|
698
|
+
onMessage,
|
699
|
+
onError,
|
700
|
+
onClose,
|
701
|
+
signal,
|
702
|
+
clientID,
|
703
|
+
sessionID,
|
704
|
+
clientName,
|
705
|
+
xataAgentExtra
|
706
|
+
}) {
|
707
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
708
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
709
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
710
|
+
void fetchEventSource(url, {
|
711
|
+
method,
|
712
|
+
body: JSON.stringify(body),
|
713
|
+
fetch: fetch2,
|
714
|
+
signal,
|
715
|
+
headers: {
|
716
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
717
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
718
|
+
"X-Xata-Agent": compact([
|
719
|
+
["client", "TS_SDK"],
|
720
|
+
["version", VERSION],
|
721
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
722
|
+
...Object.entries(xataAgentExtra ?? {})
|
723
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
724
|
+
...customHeaders,
|
725
|
+
Authorization: `Bearer ${apiKey}`,
|
726
|
+
"Content-Type": "application/json"
|
727
|
+
},
|
728
|
+
onmessage(ev) {
|
729
|
+
onMessage?.(JSON.parse(ev.data));
|
730
|
+
},
|
731
|
+
onerror(ev) {
|
732
|
+
onError?.(JSON.parse(ev.data));
|
733
|
+
},
|
734
|
+
onclose() {
|
735
|
+
onClose?.();
|
736
|
+
}
|
737
|
+
});
|
738
|
+
}
|
445
739
|
function parseUrl(url) {
|
446
740
|
try {
|
447
741
|
const { host, protocol } = new URL(url);
|
@@ -453,17 +747,12 @@ function parseUrl(url) {
|
|
453
747
|
|
454
748
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
455
749
|
|
456
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
457
750
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
458
751
|
url: "/dbs/{dbName}",
|
459
752
|
method: "get",
|
460
753
|
...variables,
|
461
754
|
signal
|
462
755
|
});
|
463
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
464
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
465
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
466
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
467
756
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
468
757
|
url: "/db/{dbBranchName}",
|
469
758
|
method: "get",
|
@@ -477,6 +766,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
477
766
|
...variables,
|
478
767
|
signal
|
479
768
|
});
|
769
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
770
|
+
url: "/db/{dbBranchName}/copy",
|
771
|
+
method: "post",
|
772
|
+
...variables,
|
773
|
+
signal
|
774
|
+
});
|
480
775
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
481
776
|
url: "/db/{dbBranchName}/metadata",
|
482
777
|
method: "put",
|
@@ -502,7 +797,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
502
797
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
503
798
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
504
799
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
505
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
506
800
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
507
801
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
508
802
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -527,6 +821,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
527
821
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
528
822
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
529
823
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
824
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
530
825
|
const createTable = (variables, signal) => dataPlaneFetch({
|
531
826
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
532
827
|
method: "put",
|
@@ -569,7 +864,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
569
864
|
...variables,
|
570
865
|
signal
|
571
866
|
});
|
867
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
572
868
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
869
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
870
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
871
|
+
method: "get",
|
872
|
+
...variables,
|
873
|
+
signal
|
874
|
+
});
|
875
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
876
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
877
|
+
method: "put",
|
878
|
+
...variables,
|
879
|
+
signal
|
880
|
+
});
|
881
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
882
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
883
|
+
method: "delete",
|
884
|
+
...variables,
|
885
|
+
signal
|
886
|
+
});
|
887
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
888
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
889
|
+
method: "get",
|
890
|
+
...variables,
|
891
|
+
signal
|
892
|
+
});
|
893
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
894
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
895
|
+
method: "put",
|
896
|
+
...variables,
|
897
|
+
signal
|
898
|
+
});
|
899
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
900
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
901
|
+
method: "delete",
|
902
|
+
...variables,
|
903
|
+
signal
|
904
|
+
});
|
573
905
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
574
906
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
575
907
|
method: "get",
|
@@ -599,21 +931,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
599
931
|
...variables,
|
600
932
|
signal
|
601
933
|
});
|
934
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
935
|
+
url: "/db/{dbBranchName}/sql",
|
936
|
+
method: "post",
|
937
|
+
...variables,
|
938
|
+
signal
|
939
|
+
});
|
940
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
941
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
942
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
943
|
+
method: "post",
|
944
|
+
...variables,
|
945
|
+
signal
|
946
|
+
});
|
947
|
+
const chatSessionMessage = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
602
948
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
603
949
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
950
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
951
|
+
url: "/file/{fileId}",
|
952
|
+
method: "get",
|
953
|
+
...variables,
|
954
|
+
signal
|
955
|
+
});
|
604
956
|
const operationsByTag$2 = {
|
605
|
-
database: {
|
606
|
-
dEPRECATEDgetDatabaseList,
|
607
|
-
dEPRECATEDcreateDatabase,
|
608
|
-
dEPRECATEDdeleteDatabase,
|
609
|
-
dEPRECATEDgetDatabaseMetadata,
|
610
|
-
dEPRECATEDupdateDatabaseMetadata
|
611
|
-
},
|
612
957
|
branch: {
|
613
958
|
getBranchList,
|
614
959
|
getBranchDetails,
|
615
960
|
createBranch,
|
616
961
|
deleteBranch,
|
962
|
+
copyBranch,
|
617
963
|
updateBranchMetadata,
|
618
964
|
getBranchMetadata,
|
619
965
|
getBranchStats,
|
@@ -631,17 +977,8 @@ const operationsByTag$2 = {
|
|
631
977
|
compareBranchSchemas,
|
632
978
|
updateBranchSchema,
|
633
979
|
previewBranchSchemaEdit,
|
634
|
-
applyBranchSchemaEdit
|
635
|
-
|
636
|
-
records: {
|
637
|
-
branchTransaction,
|
638
|
-
insertRecord,
|
639
|
-
getRecord,
|
640
|
-
insertRecordWithID,
|
641
|
-
updateRecordWithID,
|
642
|
-
upsertRecordWithID,
|
643
|
-
deleteRecord,
|
644
|
-
bulkInsertTableRecords
|
980
|
+
applyBranchSchemaEdit,
|
981
|
+
pushBranchMigrations
|
645
982
|
},
|
646
983
|
migrationRequests: {
|
647
984
|
queryMigrationRequests,
|
@@ -665,7 +1002,28 @@ const operationsByTag$2 = {
|
|
665
1002
|
updateColumn,
|
666
1003
|
deleteColumn
|
667
1004
|
},
|
668
|
-
|
1005
|
+
records: {
|
1006
|
+
branchTransaction,
|
1007
|
+
insertRecord,
|
1008
|
+
getRecord,
|
1009
|
+
insertRecordWithID,
|
1010
|
+
updateRecordWithID,
|
1011
|
+
upsertRecordWithID,
|
1012
|
+
deleteRecord,
|
1013
|
+
bulkInsertTableRecords
|
1014
|
+
},
|
1015
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1016
|
+
searchAndFilter: {
|
1017
|
+
queryTable,
|
1018
|
+
searchBranch,
|
1019
|
+
searchTable,
|
1020
|
+
sqlQuery,
|
1021
|
+
vectorSearchTable,
|
1022
|
+
askTable,
|
1023
|
+
chatSessionMessage,
|
1024
|
+
summarizeTable,
|
1025
|
+
aggregateTable
|
1026
|
+
}
|
669
1027
|
};
|
670
1028
|
|
671
1029
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -764,6 +1122,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
764
1122
|
});
|
765
1123
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
766
1124
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1125
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1126
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1127
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1128
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
767
1129
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
768
1130
|
url: "/workspaces/{workspaceId}/regions",
|
769
1131
|
method: "get",
|
@@ -796,6 +1158,10 @@ const operationsByTag$1 = {
|
|
796
1158
|
deleteDatabase,
|
797
1159
|
getDatabaseMetadata,
|
798
1160
|
updateDatabaseMetadata,
|
1161
|
+
renameDatabase,
|
1162
|
+
getDatabaseGithubSettings,
|
1163
|
+
updateDatabaseGithubSettings,
|
1164
|
+
deleteDatabaseGithubSettings,
|
799
1165
|
listRegions
|
800
1166
|
}
|
801
1167
|
};
|
@@ -816,8 +1182,12 @@ const providers = {
|
|
816
1182
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
817
1183
|
},
|
818
1184
|
staging: {
|
819
|
-
main: "https://staging.
|
820
|
-
workspaces: "https://{workspaceId}.
|
1185
|
+
main: "https://api.staging-xata.dev",
|
1186
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1187
|
+
},
|
1188
|
+
dev: {
|
1189
|
+
main: "https://api.dev-xata.dev",
|
1190
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
821
1191
|
}
|
822
1192
|
};
|
823
1193
|
function isHostProviderAlias(alias) {
|
@@ -835,15 +1205,22 @@ function parseProviderString(provider = "production") {
|
|
835
1205
|
return null;
|
836
1206
|
return { main, workspaces };
|
837
1207
|
}
|
1208
|
+
function buildProviderString(provider) {
|
1209
|
+
if (isHostProviderAlias(provider))
|
1210
|
+
return provider;
|
1211
|
+
return `${provider.main},${provider.workspaces}`;
|
1212
|
+
}
|
838
1213
|
function parseWorkspacesUrlParts(url) {
|
839
1214
|
if (!isString(url))
|
840
1215
|
return null;
|
841
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
842
|
-
const
|
843
|
-
const
|
1216
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1217
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1218
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1219
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1220
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
844
1221
|
if (!match)
|
845
1222
|
return null;
|
846
|
-
return { workspace: match[1], region: match[2]
|
1223
|
+
return { workspace: match[1], region: match[2] };
|
847
1224
|
}
|
848
1225
|
|
849
1226
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -872,15 +1249,19 @@ class XataApiClient {
|
|
872
1249
|
const provider = options.host ?? "production";
|
873
1250
|
const apiKey = options.apiKey ?? getAPIKey();
|
874
1251
|
const trace = options.trace ?? defaultTrace;
|
1252
|
+
const clientID = generateUUID();
|
875
1253
|
if (!apiKey) {
|
876
1254
|
throw new Error("Could not resolve a valid apiKey");
|
877
1255
|
}
|
878
1256
|
__privateSet$7(this, _extraProps, {
|
879
1257
|
apiUrl: getHostUrl(provider, "main"),
|
880
1258
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
881
|
-
|
1259
|
+
fetch: getFetchImplementation(options.fetch),
|
882
1260
|
apiKey,
|
883
|
-
trace
|
1261
|
+
trace,
|
1262
|
+
clientName: options.clientName,
|
1263
|
+
xataAgentExtra: options.xataAgentExtra,
|
1264
|
+
clientID
|
884
1265
|
});
|
885
1266
|
}
|
886
1267
|
get user() {
|
@@ -933,6 +1314,11 @@ class XataApiClient {
|
|
933
1314
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
934
1315
|
return __privateGet$7(this, _namespaces).records;
|
935
1316
|
}
|
1317
|
+
get files() {
|
1318
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1319
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1320
|
+
return __privateGet$7(this, _namespaces).files;
|
1321
|
+
}
|
936
1322
|
get searchAndFilter() {
|
937
1323
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
938
1324
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1141,6 +1527,20 @@ class BranchApi {
|
|
1141
1527
|
...this.extraProps
|
1142
1528
|
});
|
1143
1529
|
}
|
1530
|
+
copyBranch({
|
1531
|
+
workspace,
|
1532
|
+
region,
|
1533
|
+
database,
|
1534
|
+
branch,
|
1535
|
+
destinationBranch,
|
1536
|
+
limit
|
1537
|
+
}) {
|
1538
|
+
return operationsByTag.branch.copyBranch({
|
1539
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1540
|
+
body: { destinationBranch, limit },
|
1541
|
+
...this.extraProps
|
1542
|
+
});
|
1543
|
+
}
|
1144
1544
|
updateBranchMetadata({
|
1145
1545
|
workspace,
|
1146
1546
|
region,
|
@@ -1496,6 +1896,164 @@ class RecordsApi {
|
|
1496
1896
|
});
|
1497
1897
|
}
|
1498
1898
|
}
|
1899
|
+
class FilesApi {
|
1900
|
+
constructor(extraProps) {
|
1901
|
+
this.extraProps = extraProps;
|
1902
|
+
}
|
1903
|
+
getFileItem({
|
1904
|
+
workspace,
|
1905
|
+
region,
|
1906
|
+
database,
|
1907
|
+
branch,
|
1908
|
+
table,
|
1909
|
+
record,
|
1910
|
+
column,
|
1911
|
+
fileId
|
1912
|
+
}) {
|
1913
|
+
return operationsByTag.files.getFileItem({
|
1914
|
+
pathParams: {
|
1915
|
+
workspace,
|
1916
|
+
region,
|
1917
|
+
dbBranchName: `${database}:${branch}`,
|
1918
|
+
tableName: table,
|
1919
|
+
recordId: record,
|
1920
|
+
columnName: column,
|
1921
|
+
fileId
|
1922
|
+
},
|
1923
|
+
...this.extraProps
|
1924
|
+
});
|
1925
|
+
}
|
1926
|
+
putFileItem({
|
1927
|
+
workspace,
|
1928
|
+
region,
|
1929
|
+
database,
|
1930
|
+
branch,
|
1931
|
+
table,
|
1932
|
+
record,
|
1933
|
+
column,
|
1934
|
+
fileId,
|
1935
|
+
file
|
1936
|
+
}) {
|
1937
|
+
return operationsByTag.files.putFileItem({
|
1938
|
+
pathParams: {
|
1939
|
+
workspace,
|
1940
|
+
region,
|
1941
|
+
dbBranchName: `${database}:${branch}`,
|
1942
|
+
tableName: table,
|
1943
|
+
recordId: record,
|
1944
|
+
columnName: column,
|
1945
|
+
fileId
|
1946
|
+
},
|
1947
|
+
// @ts-ignore
|
1948
|
+
body: file,
|
1949
|
+
...this.extraProps
|
1950
|
+
});
|
1951
|
+
}
|
1952
|
+
deleteFileItem({
|
1953
|
+
workspace,
|
1954
|
+
region,
|
1955
|
+
database,
|
1956
|
+
branch,
|
1957
|
+
table,
|
1958
|
+
record,
|
1959
|
+
column,
|
1960
|
+
fileId
|
1961
|
+
}) {
|
1962
|
+
return operationsByTag.files.deleteFileItem({
|
1963
|
+
pathParams: {
|
1964
|
+
workspace,
|
1965
|
+
region,
|
1966
|
+
dbBranchName: `${database}:${branch}`,
|
1967
|
+
tableName: table,
|
1968
|
+
recordId: record,
|
1969
|
+
columnName: column,
|
1970
|
+
fileId
|
1971
|
+
},
|
1972
|
+
...this.extraProps
|
1973
|
+
});
|
1974
|
+
}
|
1975
|
+
getFile({
|
1976
|
+
workspace,
|
1977
|
+
region,
|
1978
|
+
database,
|
1979
|
+
branch,
|
1980
|
+
table,
|
1981
|
+
record,
|
1982
|
+
column
|
1983
|
+
}) {
|
1984
|
+
return operationsByTag.files.getFile({
|
1985
|
+
pathParams: {
|
1986
|
+
workspace,
|
1987
|
+
region,
|
1988
|
+
dbBranchName: `${database}:${branch}`,
|
1989
|
+
tableName: table,
|
1990
|
+
recordId: record,
|
1991
|
+
columnName: column
|
1992
|
+
},
|
1993
|
+
...this.extraProps
|
1994
|
+
});
|
1995
|
+
}
|
1996
|
+
putFile({
|
1997
|
+
workspace,
|
1998
|
+
region,
|
1999
|
+
database,
|
2000
|
+
branch,
|
2001
|
+
table,
|
2002
|
+
record,
|
2003
|
+
column,
|
2004
|
+
file
|
2005
|
+
}) {
|
2006
|
+
return operationsByTag.files.putFile({
|
2007
|
+
pathParams: {
|
2008
|
+
workspace,
|
2009
|
+
region,
|
2010
|
+
dbBranchName: `${database}:${branch}`,
|
2011
|
+
tableName: table,
|
2012
|
+
recordId: record,
|
2013
|
+
columnName: column
|
2014
|
+
},
|
2015
|
+
body: file,
|
2016
|
+
...this.extraProps
|
2017
|
+
});
|
2018
|
+
}
|
2019
|
+
deleteFile({
|
2020
|
+
workspace,
|
2021
|
+
region,
|
2022
|
+
database,
|
2023
|
+
branch,
|
2024
|
+
table,
|
2025
|
+
record,
|
2026
|
+
column
|
2027
|
+
}) {
|
2028
|
+
return operationsByTag.files.deleteFile({
|
2029
|
+
pathParams: {
|
2030
|
+
workspace,
|
2031
|
+
region,
|
2032
|
+
dbBranchName: `${database}:${branch}`,
|
2033
|
+
tableName: table,
|
2034
|
+
recordId: record,
|
2035
|
+
columnName: column
|
2036
|
+
},
|
2037
|
+
...this.extraProps
|
2038
|
+
});
|
2039
|
+
}
|
2040
|
+
fileAccess({
|
2041
|
+
workspace,
|
2042
|
+
region,
|
2043
|
+
fileId,
|
2044
|
+
verify
|
2045
|
+
}) {
|
2046
|
+
return operationsByTag.files.fileAccess({
|
2047
|
+
pathParams: {
|
2048
|
+
workspace,
|
2049
|
+
region,
|
2050
|
+
fileId
|
2051
|
+
},
|
2052
|
+
queryParams: { verify },
|
2053
|
+
...this.extraProps
|
2054
|
+
});
|
2055
|
+
}
|
2056
|
+
}
|
1499
2057
|
class SearchAndFilterApi {
|
1500
2058
|
constructor(extraProps) {
|
1501
2059
|
this.extraProps = extraProps;
|
@@ -1555,6 +2113,53 @@ class SearchAndFilterApi {
|
|
1555
2113
|
...this.extraProps
|
1556
2114
|
});
|
1557
2115
|
}
|
2116
|
+
vectorSearchTable({
|
2117
|
+
workspace,
|
2118
|
+
region,
|
2119
|
+
database,
|
2120
|
+
branch,
|
2121
|
+
table,
|
2122
|
+
queryVector,
|
2123
|
+
column,
|
2124
|
+
similarityFunction,
|
2125
|
+
size,
|
2126
|
+
filter
|
2127
|
+
}) {
|
2128
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2129
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2130
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2131
|
+
...this.extraProps
|
2132
|
+
});
|
2133
|
+
}
|
2134
|
+
askTable({
|
2135
|
+
workspace,
|
2136
|
+
region,
|
2137
|
+
database,
|
2138
|
+
branch,
|
2139
|
+
table,
|
2140
|
+
options
|
2141
|
+
}) {
|
2142
|
+
return operationsByTag.searchAndFilter.askTable({
|
2143
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2144
|
+
body: { ...options },
|
2145
|
+
...this.extraProps
|
2146
|
+
});
|
2147
|
+
}
|
2148
|
+
chatSessionMessage({
|
2149
|
+
workspace,
|
2150
|
+
region,
|
2151
|
+
database,
|
2152
|
+
branch,
|
2153
|
+
table,
|
2154
|
+
sessionId,
|
2155
|
+
message
|
2156
|
+
}) {
|
2157
|
+
return operationsByTag.searchAndFilter.chatSessionMessage({
|
2158
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2159
|
+
body: { message },
|
2160
|
+
...this.extraProps
|
2161
|
+
});
|
2162
|
+
}
|
1558
2163
|
summarizeTable({
|
1559
2164
|
workspace,
|
1560
2165
|
region,
|
@@ -1755,11 +2360,13 @@ class MigrationsApi {
|
|
1755
2360
|
region,
|
1756
2361
|
database,
|
1757
2362
|
branch,
|
1758
|
-
schema
|
2363
|
+
schema,
|
2364
|
+
schemaOperations,
|
2365
|
+
branchOperations
|
1759
2366
|
}) {
|
1760
2367
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1761
2368
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1762
|
-
body: { schema },
|
2369
|
+
body: { schema, schemaOperations, branchOperations },
|
1763
2370
|
...this.extraProps
|
1764
2371
|
});
|
1765
2372
|
}
|
@@ -1769,11 +2376,12 @@ class MigrationsApi {
|
|
1769
2376
|
database,
|
1770
2377
|
branch,
|
1771
2378
|
compare,
|
1772
|
-
|
2379
|
+
sourceBranchOperations,
|
2380
|
+
targetBranchOperations
|
1773
2381
|
}) {
|
1774
2382
|
return operationsByTag.migrations.compareBranchSchemas({
|
1775
2383
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1776
|
-
body: {
|
2384
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1777
2385
|
...this.extraProps
|
1778
2386
|
});
|
1779
2387
|
}
|
@@ -1816,6 +2424,19 @@ class MigrationsApi {
|
|
1816
2424
|
...this.extraProps
|
1817
2425
|
});
|
1818
2426
|
}
|
2427
|
+
pushBranchMigrations({
|
2428
|
+
workspace,
|
2429
|
+
region,
|
2430
|
+
database,
|
2431
|
+
branch,
|
2432
|
+
migrations
|
2433
|
+
}) {
|
2434
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2435
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2436
|
+
body: { migrations },
|
2437
|
+
...this.extraProps
|
2438
|
+
});
|
2439
|
+
}
|
1819
2440
|
}
|
1820
2441
|
class DatabaseApi {
|
1821
2442
|
constructor(extraProps) {
|
@@ -1867,6 +2488,46 @@ class DatabaseApi {
|
|
1867
2488
|
...this.extraProps
|
1868
2489
|
});
|
1869
2490
|
}
|
2491
|
+
renameDatabase({
|
2492
|
+
workspace,
|
2493
|
+
database,
|
2494
|
+
newName
|
2495
|
+
}) {
|
2496
|
+
return operationsByTag.databases.renameDatabase({
|
2497
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2498
|
+
body: { newName },
|
2499
|
+
...this.extraProps
|
2500
|
+
});
|
2501
|
+
}
|
2502
|
+
getDatabaseGithubSettings({
|
2503
|
+
workspace,
|
2504
|
+
database
|
2505
|
+
}) {
|
2506
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2507
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2508
|
+
...this.extraProps
|
2509
|
+
});
|
2510
|
+
}
|
2511
|
+
updateDatabaseGithubSettings({
|
2512
|
+
workspace,
|
2513
|
+
database,
|
2514
|
+
settings
|
2515
|
+
}) {
|
2516
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2517
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2518
|
+
body: settings,
|
2519
|
+
...this.extraProps
|
2520
|
+
});
|
2521
|
+
}
|
2522
|
+
deleteDatabaseGithubSettings({
|
2523
|
+
workspace,
|
2524
|
+
database
|
2525
|
+
}) {
|
2526
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2527
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2528
|
+
...this.extraProps
|
2529
|
+
});
|
2530
|
+
}
|
1870
2531
|
listRegions({ workspace }) {
|
1871
2532
|
return operationsByTag.databases.listRegions({
|
1872
2533
|
pathParams: { workspaceId: workspace },
|
@@ -1876,29 +2537,47 @@ class DatabaseApi {
|
|
1876
2537
|
}
|
1877
2538
|
|
1878
2539
|
class XataApiPlugin {
|
1879
|
-
|
1880
|
-
|
1881
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2540
|
+
build(options) {
|
2541
|
+
return new XataApiClient(options);
|
1882
2542
|
}
|
1883
2543
|
}
|
1884
2544
|
|
1885
2545
|
class XataPlugin {
|
1886
2546
|
}
|
1887
2547
|
|
1888
|
-
function generateUUID() {
|
1889
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1890
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1891
|
-
return v.toString(16);
|
1892
|
-
});
|
1893
|
-
}
|
1894
|
-
|
1895
2548
|
function cleanFilter(filter) {
|
1896
|
-
if (!filter)
|
2549
|
+
if (!isDefined(filter))
|
1897
2550
|
return void 0;
|
1898
|
-
|
1899
|
-
|
2551
|
+
if (!isObject(filter))
|
2552
|
+
return filter;
|
2553
|
+
const values = Object.fromEntries(
|
2554
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2555
|
+
if (!isDefined(value))
|
2556
|
+
return acc;
|
2557
|
+
if (Array.isArray(value)) {
|
2558
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2559
|
+
if (clean.length === 0)
|
2560
|
+
return acc;
|
2561
|
+
return [...acc, [key, clean]];
|
2562
|
+
}
|
2563
|
+
if (isObject(value)) {
|
2564
|
+
const clean = cleanFilter(value);
|
2565
|
+
if (!isDefined(clean))
|
2566
|
+
return acc;
|
2567
|
+
return [...acc, [key, clean]];
|
2568
|
+
}
|
2569
|
+
return [...acc, [key, value]];
|
2570
|
+
}, [])
|
2571
|
+
);
|
2572
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
1900
2573
|
}
|
1901
2574
|
|
2575
|
+
var __defProp$5 = Object.defineProperty;
|
2576
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2577
|
+
var __publicField$5 = (obj, key, value) => {
|
2578
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2579
|
+
return value;
|
2580
|
+
};
|
1902
2581
|
var __accessCheck$6 = (obj, member, msg) => {
|
1903
2582
|
if (!member.has(obj))
|
1904
2583
|
throw TypeError("Cannot " + msg);
|
@@ -1921,22 +2600,58 @@ var _query, _page;
|
|
1921
2600
|
class Page {
|
1922
2601
|
constructor(query, meta, records = []) {
|
1923
2602
|
__privateAdd$6(this, _query, void 0);
|
2603
|
+
/**
|
2604
|
+
* Page metadata, required to retrieve additional records.
|
2605
|
+
*/
|
2606
|
+
__publicField$5(this, "meta");
|
2607
|
+
/**
|
2608
|
+
* The set of results for this page.
|
2609
|
+
*/
|
2610
|
+
__publicField$5(this, "records");
|
1924
2611
|
__privateSet$6(this, _query, query);
|
1925
2612
|
this.meta = meta;
|
1926
2613
|
this.records = new RecordArray(this, records);
|
1927
2614
|
}
|
2615
|
+
/**
|
2616
|
+
* Retrieves the next page of results.
|
2617
|
+
* @param size Maximum number of results to be retrieved.
|
2618
|
+
* @param offset Number of results to skip when retrieving the results.
|
2619
|
+
* @returns The next page or results.
|
2620
|
+
*/
|
1928
2621
|
async nextPage(size, offset) {
|
1929
2622
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1930
2623
|
}
|
2624
|
+
/**
|
2625
|
+
* Retrieves the previous page of results.
|
2626
|
+
* @param size Maximum number of results to be retrieved.
|
2627
|
+
* @param offset Number of results to skip when retrieving the results.
|
2628
|
+
* @returns The previous page or results.
|
2629
|
+
*/
|
1931
2630
|
async previousPage(size, offset) {
|
1932
2631
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1933
2632
|
}
|
2633
|
+
/**
|
2634
|
+
* Retrieves the start page of results.
|
2635
|
+
* @param size Maximum number of results to be retrieved.
|
2636
|
+
* @param offset Number of results to skip when retrieving the results.
|
2637
|
+
* @returns The start page or results.
|
2638
|
+
*/
|
1934
2639
|
async startPage(size, offset) {
|
1935
2640
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1936
2641
|
}
|
2642
|
+
/**
|
2643
|
+
* Retrieves the end page of results.
|
2644
|
+
* @param size Maximum number of results to be retrieved.
|
2645
|
+
* @param offset Number of results to skip when retrieving the results.
|
2646
|
+
* @returns The end page or results.
|
2647
|
+
*/
|
1937
2648
|
async endPage(size, offset) {
|
1938
2649
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1939
2650
|
}
|
2651
|
+
/**
|
2652
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2653
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2654
|
+
*/
|
1940
2655
|
hasNextPage() {
|
1941
2656
|
return this.meta.page.more;
|
1942
2657
|
}
|
@@ -1949,7 +2664,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1949
2664
|
function isCursorPaginationOptions(options) {
|
1950
2665
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1951
2666
|
}
|
1952
|
-
const _RecordArray = class extends Array {
|
2667
|
+
const _RecordArray = class _RecordArray extends Array {
|
1953
2668
|
constructor(...args) {
|
1954
2669
|
super(..._RecordArray.parseConstructorParams(...args));
|
1955
2670
|
__privateAdd$6(this, _page, void 0);
|
@@ -1968,32 +2683,67 @@ const _RecordArray = class extends Array {
|
|
1968
2683
|
toArray() {
|
1969
2684
|
return new Array(...this);
|
1970
2685
|
}
|
2686
|
+
toSerializable() {
|
2687
|
+
return JSON.parse(this.toString());
|
2688
|
+
}
|
2689
|
+
toString() {
|
2690
|
+
return JSON.stringify(this.toArray());
|
2691
|
+
}
|
1971
2692
|
map(callbackfn, thisArg) {
|
1972
2693
|
return this.toArray().map(callbackfn, thisArg);
|
1973
2694
|
}
|
2695
|
+
/**
|
2696
|
+
* Retrieve next page of records
|
2697
|
+
*
|
2698
|
+
* @returns A new array of objects
|
2699
|
+
*/
|
1974
2700
|
async nextPage(size, offset) {
|
1975
2701
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1976
2702
|
return new _RecordArray(newPage);
|
1977
2703
|
}
|
2704
|
+
/**
|
2705
|
+
* Retrieve previous page of records
|
2706
|
+
*
|
2707
|
+
* @returns A new array of objects
|
2708
|
+
*/
|
1978
2709
|
async previousPage(size, offset) {
|
1979
2710
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1980
2711
|
return new _RecordArray(newPage);
|
1981
2712
|
}
|
2713
|
+
/**
|
2714
|
+
* Retrieve start page of records
|
2715
|
+
*
|
2716
|
+
* @returns A new array of objects
|
2717
|
+
*/
|
1982
2718
|
async startPage(size, offset) {
|
1983
2719
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1984
2720
|
return new _RecordArray(newPage);
|
1985
2721
|
}
|
2722
|
+
/**
|
2723
|
+
* Retrieve end page of records
|
2724
|
+
*
|
2725
|
+
* @returns A new array of objects
|
2726
|
+
*/
|
1986
2727
|
async endPage(size, offset) {
|
1987
2728
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1988
2729
|
return new _RecordArray(newPage);
|
1989
2730
|
}
|
2731
|
+
/**
|
2732
|
+
* @returns Boolean indicating if there is a next page
|
2733
|
+
*/
|
1990
2734
|
hasNextPage() {
|
1991
2735
|
return __privateGet$6(this, _page).meta.page.more;
|
1992
2736
|
}
|
1993
2737
|
};
|
1994
|
-
let RecordArray = _RecordArray;
|
1995
2738
|
_page = new WeakMap();
|
2739
|
+
let RecordArray = _RecordArray;
|
1996
2740
|
|
2741
|
+
var __defProp$4 = Object.defineProperty;
|
2742
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2743
|
+
var __publicField$4 = (obj, key, value) => {
|
2744
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2745
|
+
return value;
|
2746
|
+
};
|
1997
2747
|
var __accessCheck$5 = (obj, member, msg) => {
|
1998
2748
|
if (!member.has(obj))
|
1999
2749
|
throw TypeError("Cannot " + msg);
|
@@ -2017,14 +2767,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2017
2767
|
return method;
|
2018
2768
|
};
|
2019
2769
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2020
|
-
const _Query = class {
|
2770
|
+
const _Query = class _Query {
|
2021
2771
|
constructor(repository, table, data, rawParent) {
|
2022
2772
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2023
2773
|
__privateAdd$5(this, _table$1, void 0);
|
2024
2774
|
__privateAdd$5(this, _repository, void 0);
|
2025
2775
|
__privateAdd$5(this, _data, { filter: {} });
|
2026
|
-
|
2027
|
-
this
|
2776
|
+
// Implements pagination
|
2777
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
2778
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
2028
2779
|
__privateSet$5(this, _table$1, table);
|
2029
2780
|
if (repository) {
|
2030
2781
|
__privateSet$5(this, _repository, repository);
|
@@ -2039,6 +2790,7 @@ const _Query = class {
|
|
2039
2790
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
2040
2791
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
2041
2792
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
2793
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
2042
2794
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
2043
2795
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2044
2796
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -2059,18 +2811,38 @@ const _Query = class {
|
|
2059
2811
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2060
2812
|
return toBase64(key);
|
2061
2813
|
}
|
2814
|
+
/**
|
2815
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
2816
|
+
* @param queries An array of subqueries.
|
2817
|
+
* @returns A new Query object.
|
2818
|
+
*/
|
2062
2819
|
any(...queries) {
|
2063
2820
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2064
2821
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2065
2822
|
}
|
2823
|
+
/**
|
2824
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
2825
|
+
* @param queries An array of subqueries.
|
2826
|
+
* @returns A new Query object.
|
2827
|
+
*/
|
2066
2828
|
all(...queries) {
|
2067
2829
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2068
2830
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2069
2831
|
}
|
2832
|
+
/**
|
2833
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
2834
|
+
* @param queries An array of subqueries.
|
2835
|
+
* @returns A new Query object.
|
2836
|
+
*/
|
2070
2837
|
not(...queries) {
|
2071
2838
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2072
2839
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2073
2840
|
}
|
2841
|
+
/**
|
2842
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
2843
|
+
* @param queries An array of subqueries.
|
2844
|
+
* @returns A new Query object.
|
2845
|
+
*/
|
2074
2846
|
none(...queries) {
|
2075
2847
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2076
2848
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2093,6 +2865,11 @@ const _Query = class {
|
|
2093
2865
|
const sort = [...originalSort, { column, direction }];
|
2094
2866
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2095
2867
|
}
|
2868
|
+
/**
|
2869
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
2870
|
+
* @param columns Array of column names to be returned by the query.
|
2871
|
+
* @returns A new Query object.
|
2872
|
+
*/
|
2096
2873
|
select(columns) {
|
2097
2874
|
return new _Query(
|
2098
2875
|
__privateGet$5(this, _repository),
|
@@ -2105,6 +2882,12 @@ const _Query = class {
|
|
2105
2882
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2106
2883
|
return __privateGet$5(this, _repository).query(query);
|
2107
2884
|
}
|
2885
|
+
/**
|
2886
|
+
* Get results in an iterator
|
2887
|
+
*
|
2888
|
+
* @async
|
2889
|
+
* @returns Async interable of results
|
2890
|
+
*/
|
2108
2891
|
async *[Symbol.asyncIterator]() {
|
2109
2892
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2110
2893
|
yield record;
|
@@ -2165,26 +2948,53 @@ const _Query = class {
|
|
2165
2948
|
);
|
2166
2949
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2167
2950
|
}
|
2951
|
+
/**
|
2952
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
2953
|
+
* @param ttl The cache TTL in milliseconds.
|
2954
|
+
* @returns A new Query object.
|
2955
|
+
*/
|
2168
2956
|
cache(ttl) {
|
2169
2957
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2170
2958
|
}
|
2959
|
+
/**
|
2960
|
+
* Retrieve next page of records
|
2961
|
+
*
|
2962
|
+
* @returns A new page object.
|
2963
|
+
*/
|
2171
2964
|
nextPage(size, offset) {
|
2172
2965
|
return this.startPage(size, offset);
|
2173
2966
|
}
|
2967
|
+
/**
|
2968
|
+
* Retrieve previous page of records
|
2969
|
+
*
|
2970
|
+
* @returns A new page object
|
2971
|
+
*/
|
2174
2972
|
previousPage(size, offset) {
|
2175
2973
|
return this.startPage(size, offset);
|
2176
2974
|
}
|
2975
|
+
/**
|
2976
|
+
* Retrieve start page of records
|
2977
|
+
*
|
2978
|
+
* @returns A new page object
|
2979
|
+
*/
|
2177
2980
|
startPage(size, offset) {
|
2178
2981
|
return this.getPaginated({ pagination: { size, offset } });
|
2179
2982
|
}
|
2983
|
+
/**
|
2984
|
+
* Retrieve last page of records
|
2985
|
+
*
|
2986
|
+
* @returns A new page object
|
2987
|
+
*/
|
2180
2988
|
endPage(size, offset) {
|
2181
2989
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2182
2990
|
}
|
2991
|
+
/**
|
2992
|
+
* @returns Boolean indicating if there is a next page
|
2993
|
+
*/
|
2183
2994
|
hasNextPage() {
|
2184
2995
|
return this.meta.page.more;
|
2185
2996
|
}
|
2186
2997
|
};
|
2187
|
-
let Query = _Query;
|
2188
2998
|
_table$1 = new WeakMap();
|
2189
2999
|
_repository = new WeakMap();
|
2190
3000
|
_data = new WeakMap();
|
@@ -2199,6 +3009,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2199
3009
|
}
|
2200
3010
|
return value;
|
2201
3011
|
};
|
3012
|
+
let Query = _Query;
|
2202
3013
|
function cleanParent(data, parent) {
|
2203
3014
|
if (isCursorPaginationOptions(data.pagination)) {
|
2204
3015
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2206,6 +3017,21 @@ function cleanParent(data, parent) {
|
|
2206
3017
|
return parent;
|
2207
3018
|
}
|
2208
3019
|
|
3020
|
+
const RecordColumnTypes = [
|
3021
|
+
"bool",
|
3022
|
+
"int",
|
3023
|
+
"float",
|
3024
|
+
"string",
|
3025
|
+
"text",
|
3026
|
+
"email",
|
3027
|
+
"multiple",
|
3028
|
+
"link",
|
3029
|
+
"object",
|
3030
|
+
"datetime",
|
3031
|
+
"vector",
|
3032
|
+
"file[]",
|
3033
|
+
"file"
|
3034
|
+
];
|
2209
3035
|
function isIdentifiable(x) {
|
2210
3036
|
return isObject(x) && isString(x?.id);
|
2211
3037
|
}
|
@@ -2219,7 +3045,11 @@ function isSortFilterString(value) {
|
|
2219
3045
|
return isString(value);
|
2220
3046
|
}
|
2221
3047
|
function isSortFilterBase(filter) {
|
2222
|
-
return isObject(filter) && Object.
|
3048
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3049
|
+
if (key === "*")
|
3050
|
+
return value === "random";
|
3051
|
+
return value === "asc" || value === "desc";
|
3052
|
+
});
|
2223
3053
|
}
|
2224
3054
|
function isSortFilterObject(filter) {
|
2225
3055
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2292,10 +3122,7 @@ class RestRepository extends Query {
|
|
2292
3122
|
__privateSet$4(this, _db, options.db);
|
2293
3123
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2294
3124
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2295
|
-
__privateSet$4(this, _getFetchProps,
|
2296
|
-
const props = await options.pluginOptions.getFetchProps();
|
2297
|
-
return { ...props, sessionID: generateUUID() };
|
2298
|
-
});
|
3125
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2299
3126
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2300
3127
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2301
3128
|
return trace(name, fn, {
|
@@ -2352,7 +3179,6 @@ class RestRepository extends Query {
|
|
2352
3179
|
}
|
2353
3180
|
const id = extractId(a);
|
2354
3181
|
if (id) {
|
2355
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2356
3182
|
try {
|
2357
3183
|
const response = await getRecord({
|
2358
3184
|
pathParams: {
|
@@ -2363,7 +3189,7 @@ class RestRepository extends Query {
|
|
2363
3189
|
recordId: id
|
2364
3190
|
},
|
2365
3191
|
queryParams: { columns },
|
2366
|
-
...
|
3192
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2367
3193
|
});
|
2368
3194
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2369
3195
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2412,13 +3238,19 @@ class RestRepository extends Query {
|
|
2412
3238
|
const result = await this.read(a, columns);
|
2413
3239
|
return result;
|
2414
3240
|
}
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
3241
|
+
try {
|
3242
|
+
if (isString(a) && isObject(b)) {
|
3243
|
+
const columns = isStringArray(c) ? c : void 0;
|
3244
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3245
|
+
}
|
3246
|
+
if (isObject(a) && isString(a.id)) {
|
3247
|
+
const columns = isStringArray(b) ? b : void 0;
|
3248
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3249
|
+
}
|
3250
|
+
} catch (error) {
|
3251
|
+
if (error.status === 422)
|
3252
|
+
return null;
|
3253
|
+
throw error;
|
2422
3254
|
}
|
2423
3255
|
throw new Error("Invalid arguments for update method");
|
2424
3256
|
});
|
@@ -2457,12 +3289,22 @@ class RestRepository extends Query {
|
|
2457
3289
|
return result;
|
2458
3290
|
}
|
2459
3291
|
if (isString(a) && isObject(b)) {
|
3292
|
+
if (a === "")
|
3293
|
+
throw new Error("The id can't be empty");
|
2460
3294
|
const columns = isStringArray(c) ? c : void 0;
|
2461
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3295
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2462
3296
|
}
|
2463
3297
|
if (isObject(a) && isString(a.id)) {
|
3298
|
+
if (a.id === "")
|
3299
|
+
throw new Error("The id can't be empty");
|
2464
3300
|
const columns = isStringArray(c) ? c : void 0;
|
2465
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3301
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3302
|
+
}
|
3303
|
+
if (!isDefined(a) && isObject(b)) {
|
3304
|
+
return await this.create(b, c);
|
3305
|
+
}
|
3306
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3307
|
+
return await this.create(a, b);
|
2466
3308
|
}
|
2467
3309
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2468
3310
|
});
|
@@ -2479,12 +3321,22 @@ class RestRepository extends Query {
|
|
2479
3321
|
return result;
|
2480
3322
|
}
|
2481
3323
|
if (isString(a) && isObject(b)) {
|
3324
|
+
if (a === "")
|
3325
|
+
throw new Error("The id can't be empty");
|
2482
3326
|
const columns = isStringArray(c) ? c : void 0;
|
2483
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3327
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2484
3328
|
}
|
2485
3329
|
if (isObject(a) && isString(a.id)) {
|
3330
|
+
if (a.id === "")
|
3331
|
+
throw new Error("The id can't be empty");
|
2486
3332
|
const columns = isStringArray(c) ? c : void 0;
|
2487
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3333
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3334
|
+
}
|
3335
|
+
if (!isDefined(a) && isObject(b)) {
|
3336
|
+
return await this.create(b, c);
|
3337
|
+
}
|
3338
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3339
|
+
return await this.create(a, b);
|
2488
3340
|
}
|
2489
3341
|
throw new Error("Invalid arguments for createOrReplace method");
|
2490
3342
|
});
|
@@ -2535,7 +3387,6 @@ class RestRepository extends Query {
|
|
2535
3387
|
}
|
2536
3388
|
async search(query, options = {}) {
|
2537
3389
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2538
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2539
3390
|
const { records } = await searchTable({
|
2540
3391
|
pathParams: {
|
2541
3392
|
workspace: "{workspaceId}",
|
@@ -2549,9 +3400,33 @@ class RestRepository extends Query {
|
|
2549
3400
|
prefix: options.prefix,
|
2550
3401
|
highlight: options.highlight,
|
2551
3402
|
filter: options.filter,
|
2552
|
-
boosters: options.boosters
|
3403
|
+
boosters: options.boosters,
|
3404
|
+
page: options.page,
|
3405
|
+
target: options.target
|
2553
3406
|
},
|
2554
|
-
...
|
3407
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3408
|
+
});
|
3409
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3410
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3411
|
+
});
|
3412
|
+
}
|
3413
|
+
async vectorSearch(column, query, options) {
|
3414
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3415
|
+
const { records } = await vectorSearchTable({
|
3416
|
+
pathParams: {
|
3417
|
+
workspace: "{workspaceId}",
|
3418
|
+
dbBranchName: "{dbBranch}",
|
3419
|
+
region: "{region}",
|
3420
|
+
tableName: __privateGet$4(this, _table)
|
3421
|
+
},
|
3422
|
+
body: {
|
3423
|
+
column,
|
3424
|
+
queryVector: query,
|
3425
|
+
similarityFunction: options?.similarityFunction,
|
3426
|
+
size: options?.size,
|
3427
|
+
filter: options?.filter
|
3428
|
+
},
|
3429
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2555
3430
|
});
|
2556
3431
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2557
3432
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2559,7 +3434,6 @@ class RestRepository extends Query {
|
|
2559
3434
|
}
|
2560
3435
|
async aggregate(aggs, filter) {
|
2561
3436
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2562
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2563
3437
|
const result = await aggregateTable({
|
2564
3438
|
pathParams: {
|
2565
3439
|
workspace: "{workspaceId}",
|
@@ -2568,7 +3442,7 @@ class RestRepository extends Query {
|
|
2568
3442
|
tableName: __privateGet$4(this, _table)
|
2569
3443
|
},
|
2570
3444
|
body: { aggs, filter },
|
2571
|
-
...
|
3445
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2572
3446
|
});
|
2573
3447
|
return result;
|
2574
3448
|
});
|
@@ -2579,7 +3453,6 @@ class RestRepository extends Query {
|
|
2579
3453
|
if (cacheQuery)
|
2580
3454
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2581
3455
|
const data = query.getQueryOptions();
|
2582
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2583
3456
|
const { meta, records: objects } = await queryTable({
|
2584
3457
|
pathParams: {
|
2585
3458
|
workspace: "{workspaceId}",
|
@@ -2591,10 +3464,11 @@ class RestRepository extends Query {
|
|
2591
3464
|
filter: cleanFilter(data.filter),
|
2592
3465
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2593
3466
|
page: data.pagination,
|
2594
|
-
columns: data.columns ?? ["*"]
|
3467
|
+
columns: data.columns ?? ["*"],
|
3468
|
+
consistency: data.consistency
|
2595
3469
|
},
|
2596
3470
|
fetchOptions: data.fetchOptions,
|
2597
|
-
...
|
3471
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2598
3472
|
});
|
2599
3473
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2600
3474
|
const records = objects.map(
|
@@ -2607,7 +3481,6 @@ class RestRepository extends Query {
|
|
2607
3481
|
async summarizeTable(query, summaries, summariesFilter) {
|
2608
3482
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2609
3483
|
const data = query.getQueryOptions();
|
2610
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2611
3484
|
const result = await summarizeTable({
|
2612
3485
|
pathParams: {
|
2613
3486
|
workspace: "{workspaceId}",
|
@@ -2619,15 +3492,44 @@ class RestRepository extends Query {
|
|
2619
3492
|
filter: cleanFilter(data.filter),
|
2620
3493
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2621
3494
|
columns: data.columns,
|
3495
|
+
consistency: data.consistency,
|
2622
3496
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2623
3497
|
summaries,
|
2624
3498
|
summariesFilter
|
2625
3499
|
},
|
2626
|
-
...
|
3500
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2627
3501
|
});
|
2628
3502
|
return result;
|
2629
3503
|
});
|
2630
3504
|
}
|
3505
|
+
ask(question, options) {
|
3506
|
+
const params = {
|
3507
|
+
pathParams: {
|
3508
|
+
workspace: "{workspaceId}",
|
3509
|
+
dbBranchName: "{dbBranch}",
|
3510
|
+
region: "{region}",
|
3511
|
+
tableName: __privateGet$4(this, _table)
|
3512
|
+
},
|
3513
|
+
body: {
|
3514
|
+
question,
|
3515
|
+
...options
|
3516
|
+
},
|
3517
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3518
|
+
};
|
3519
|
+
if (options?.onMessage) {
|
3520
|
+
fetchSSERequest({
|
3521
|
+
endpoint: "dataPlane",
|
3522
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3523
|
+
method: "POST",
|
3524
|
+
onMessage: (message) => {
|
3525
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3526
|
+
},
|
3527
|
+
...params
|
3528
|
+
});
|
3529
|
+
} else {
|
3530
|
+
return askTable(params);
|
3531
|
+
}
|
3532
|
+
}
|
2631
3533
|
}
|
2632
3534
|
_table = new WeakMap();
|
2633
3535
|
_getFetchProps = new WeakMap();
|
@@ -2637,8 +3539,7 @@ _schemaTables$2 = new WeakMap();
|
|
2637
3539
|
_trace = new WeakMap();
|
2638
3540
|
_insertRecordWithoutId = new WeakSet();
|
2639
3541
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2640
|
-
const
|
2641
|
-
const record = transformObjectLinks(object);
|
3542
|
+
const record = removeLinksFromObject(object);
|
2642
3543
|
const response = await insertRecord({
|
2643
3544
|
pathParams: {
|
2644
3545
|
workspace: "{workspaceId}",
|
@@ -2648,15 +3549,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2648
3549
|
},
|
2649
3550
|
queryParams: { columns },
|
2650
3551
|
body: record,
|
2651
|
-
...
|
3552
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2652
3553
|
});
|
2653
3554
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2654
3555
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2655
3556
|
};
|
2656
3557
|
_insertRecordWithId = new WeakSet();
|
2657
3558
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2658
|
-
|
2659
|
-
|
3559
|
+
if (!recordId)
|
3560
|
+
return null;
|
3561
|
+
const record = removeLinksFromObject(object);
|
2660
3562
|
const response = await insertRecordWithID({
|
2661
3563
|
pathParams: {
|
2662
3564
|
workspace: "{workspaceId}",
|
@@ -2667,17 +3569,16 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2667
3569
|
},
|
2668
3570
|
body: record,
|
2669
3571
|
queryParams: { createOnly, columns, ifVersion },
|
2670
|
-
...
|
3572
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2671
3573
|
});
|
2672
3574
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2673
3575
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2674
3576
|
};
|
2675
3577
|
_insertRecords = new WeakSet();
|
2676
3578
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2677
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2678
3579
|
const chunkedOperations = chunk(
|
2679
3580
|
objects.map((object) => ({
|
2680
|
-
insert: { table: __privateGet$4(this, _table), record:
|
3581
|
+
insert: { table: __privateGet$4(this, _table), record: removeLinksFromObject(object), createOnly, ifVersion }
|
2681
3582
|
})),
|
2682
3583
|
BULK_OPERATION_MAX_SIZE
|
2683
3584
|
);
|
@@ -2690,7 +3591,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2690
3591
|
region: "{region}"
|
2691
3592
|
},
|
2692
3593
|
body: { operations },
|
2693
|
-
...
|
3594
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2694
3595
|
});
|
2695
3596
|
for (const result of results) {
|
2696
3597
|
if (result.operation === "insert") {
|
@@ -2704,8 +3605,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2704
3605
|
};
|
2705
3606
|
_updateRecordWithID = new WeakSet();
|
2706
3607
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2707
|
-
|
2708
|
-
|
3608
|
+
if (!recordId)
|
3609
|
+
return null;
|
3610
|
+
const { id: _id, ...record } = removeLinksFromObject(object);
|
2709
3611
|
try {
|
2710
3612
|
const response = await updateRecordWithID({
|
2711
3613
|
pathParams: {
|
@@ -2717,7 +3619,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2717
3619
|
},
|
2718
3620
|
queryParams: { columns, ifVersion },
|
2719
3621
|
body: record,
|
2720
|
-
...
|
3622
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2721
3623
|
});
|
2722
3624
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2723
3625
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2730,10 +3632,9 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2730
3632
|
};
|
2731
3633
|
_updateRecords = new WeakSet();
|
2732
3634
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2733
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2734
3635
|
const chunkedOperations = chunk(
|
2735
3636
|
objects.map(({ id, ...object }) => ({
|
2736
|
-
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields:
|
3637
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: removeLinksFromObject(object) }
|
2737
3638
|
})),
|
2738
3639
|
BULK_OPERATION_MAX_SIZE
|
2739
3640
|
);
|
@@ -2746,7 +3647,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2746
3647
|
region: "{region}"
|
2747
3648
|
},
|
2748
3649
|
body: { operations },
|
2749
|
-
...
|
3650
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2750
3651
|
});
|
2751
3652
|
for (const result of results) {
|
2752
3653
|
if (result.operation === "update") {
|
@@ -2760,7 +3661,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2760
3661
|
};
|
2761
3662
|
_upsertRecordWithID = new WeakSet();
|
2762
3663
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2763
|
-
|
3664
|
+
if (!recordId)
|
3665
|
+
return null;
|
2764
3666
|
const response = await upsertRecordWithID({
|
2765
3667
|
pathParams: {
|
2766
3668
|
workspace: "{workspaceId}",
|
@@ -2771,14 +3673,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2771
3673
|
},
|
2772
3674
|
queryParams: { columns, ifVersion },
|
2773
3675
|
body: object,
|
2774
|
-
...
|
3676
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2775
3677
|
});
|
2776
3678
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2777
3679
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2778
3680
|
};
|
2779
3681
|
_deleteRecord = new WeakSet();
|
2780
3682
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2781
|
-
|
3683
|
+
if (!recordId)
|
3684
|
+
return null;
|
2782
3685
|
try {
|
2783
3686
|
const response = await deleteRecord({
|
2784
3687
|
pathParams: {
|
@@ -2789,7 +3692,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2789
3692
|
recordId
|
2790
3693
|
},
|
2791
3694
|
queryParams: { columns },
|
2792
|
-
...
|
3695
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2793
3696
|
});
|
2794
3697
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2795
3698
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2802,9 +3705,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2802
3705
|
};
|
2803
3706
|
_deleteRecords = new WeakSet();
|
2804
3707
|
deleteRecords_fn = async function(recordIds) {
|
2805
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2806
3708
|
const chunkedOperations = chunk(
|
2807
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3709
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2808
3710
|
BULK_OPERATION_MAX_SIZE
|
2809
3711
|
);
|
2810
3712
|
for (const operations of chunkedOperations) {
|
@@ -2815,21 +3717,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2815
3717
|
region: "{region}"
|
2816
3718
|
},
|
2817
3719
|
body: { operations },
|
2818
|
-
...
|
3720
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2819
3721
|
});
|
2820
3722
|
}
|
2821
3723
|
};
|
2822
3724
|
_setCacheQuery = new WeakSet();
|
2823
3725
|
setCacheQuery_fn = async function(query, meta, records) {
|
2824
|
-
await __privateGet$4(this, _cache)
|
3726
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2825
3727
|
};
|
2826
3728
|
_getCacheQuery = new WeakSet();
|
2827
3729
|
getCacheQuery_fn = async function(query) {
|
2828
3730
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2829
|
-
const result = await __privateGet$4(this, _cache)
|
3731
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2830
3732
|
if (!result)
|
2831
3733
|
return null;
|
2832
|
-
const
|
3734
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3735
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2833
3736
|
if (ttl < 0)
|
2834
3737
|
return null;
|
2835
3738
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2839,15 +3742,14 @@ _getSchemaTables$1 = new WeakSet();
|
|
2839
3742
|
getSchemaTables_fn$1 = async function() {
|
2840
3743
|
if (__privateGet$4(this, _schemaTables$2))
|
2841
3744
|
return __privateGet$4(this, _schemaTables$2);
|
2842
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2843
3745
|
const { schema } = await getBranchDetails({
|
2844
3746
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2845
|
-
...
|
3747
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2846
3748
|
});
|
2847
3749
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2848
3750
|
return schema.tables;
|
2849
3751
|
};
|
2850
|
-
const
|
3752
|
+
const removeLinksFromObject = (object) => {
|
2851
3753
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
2852
3754
|
if (key === "xata")
|
2853
3755
|
return acc;
|
@@ -2855,23 +3757,23 @@ const transformObjectLinks = (object) => {
|
|
2855
3757
|
}, {});
|
2856
3758
|
};
|
2857
3759
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2858
|
-
const
|
3760
|
+
const data = {};
|
2859
3761
|
const { xata, ...rest } = object ?? {};
|
2860
|
-
Object.assign(
|
3762
|
+
Object.assign(data, rest);
|
2861
3763
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2862
3764
|
if (!columns)
|
2863
3765
|
console.error(`Table ${table} not found in schema`);
|
2864
3766
|
for (const column of columns ?? []) {
|
2865
3767
|
if (!isValidColumn(selectedColumns, column))
|
2866
3768
|
continue;
|
2867
|
-
const value =
|
3769
|
+
const value = data[column.name];
|
2868
3770
|
switch (column.type) {
|
2869
3771
|
case "datetime": {
|
2870
3772
|
const date = value !== void 0 ? new Date(value) : null;
|
2871
3773
|
if (date !== null && isNaN(date.getTime())) {
|
2872
3774
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2873
3775
|
} else {
|
2874
|
-
|
3776
|
+
data[column.name] = date;
|
2875
3777
|
}
|
2876
3778
|
break;
|
2877
3779
|
}
|
@@ -2890,44 +3792,54 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2890
3792
|
}
|
2891
3793
|
return acc;
|
2892
3794
|
}, []);
|
2893
|
-
|
3795
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2894
3796
|
} else {
|
2895
|
-
|
3797
|
+
data[column.name] = null;
|
2896
3798
|
}
|
2897
3799
|
break;
|
2898
3800
|
}
|
2899
3801
|
default:
|
2900
|
-
|
3802
|
+
data[column.name] = value ?? null;
|
2901
3803
|
if (column.notNull === true && value === null) {
|
2902
3804
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2903
3805
|
}
|
2904
3806
|
break;
|
2905
3807
|
}
|
2906
3808
|
}
|
2907
|
-
|
2908
|
-
|
3809
|
+
const record = { ...data };
|
3810
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
3811
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
3812
|
+
record.read = function(columns2) {
|
3813
|
+
return db[table].read(record["id"], columns2);
|
2909
3814
|
};
|
2910
|
-
|
3815
|
+
record.update = function(data2, b, c) {
|
2911
3816
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2912
3817
|
const ifVersion = parseIfVersion(b, c);
|
2913
|
-
return db[table].update(
|
3818
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2914
3819
|
};
|
2915
|
-
|
3820
|
+
record.replace = function(data2, b, c) {
|
2916
3821
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2917
3822
|
const ifVersion = parseIfVersion(b, c);
|
2918
|
-
return db[table].createOrReplace(
|
3823
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
3824
|
+
};
|
3825
|
+
record.delete = function() {
|
3826
|
+
return db[table].delete(record["id"]);
|
3827
|
+
};
|
3828
|
+
record.xata = Object.freeze(metadata);
|
3829
|
+
record.getMetadata = function() {
|
3830
|
+
return record.xata;
|
2919
3831
|
};
|
2920
|
-
|
2921
|
-
return
|
3832
|
+
record.toSerializable = function() {
|
3833
|
+
return JSON.parse(JSON.stringify(serializable));
|
2922
3834
|
};
|
2923
|
-
|
2924
|
-
return
|
3835
|
+
record.toString = function() {
|
3836
|
+
return JSON.stringify(serializable);
|
2925
3837
|
};
|
2926
|
-
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
2927
|
-
Object.defineProperty(
|
3838
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3839
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2928
3840
|
}
|
2929
|
-
Object.freeze(
|
2930
|
-
return
|
3841
|
+
Object.freeze(record);
|
3842
|
+
return record;
|
2931
3843
|
};
|
2932
3844
|
function extractId(value) {
|
2933
3845
|
if (isString(value))
|
@@ -2939,11 +3851,7 @@ function extractId(value) {
|
|
2939
3851
|
function isValidColumn(columns, column) {
|
2940
3852
|
if (columns.includes("*"))
|
2941
3853
|
return true;
|
2942
|
-
|
2943
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2944
|
-
return linkColumns.length > 0;
|
2945
|
-
}
|
2946
|
-
return columns.includes(column.name);
|
3854
|
+
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
2947
3855
|
}
|
2948
3856
|
function parseIfVersion(...args) {
|
2949
3857
|
for (const arg of args) {
|
@@ -2954,6 +3862,12 @@ function parseIfVersion(...args) {
|
|
2954
3862
|
return void 0;
|
2955
3863
|
}
|
2956
3864
|
|
3865
|
+
var __defProp$3 = Object.defineProperty;
|
3866
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3867
|
+
var __publicField$3 = (obj, key, value) => {
|
3868
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3869
|
+
return value;
|
3870
|
+
};
|
2957
3871
|
var __accessCheck$3 = (obj, member, msg) => {
|
2958
3872
|
if (!member.has(obj))
|
2959
3873
|
throw TypeError("Cannot " + msg);
|
@@ -2976,6 +3890,8 @@ var _map;
|
|
2976
3890
|
class SimpleCache {
|
2977
3891
|
constructor(options = {}) {
|
2978
3892
|
__privateAdd$3(this, _map, void 0);
|
3893
|
+
__publicField$3(this, "capacity");
|
3894
|
+
__publicField$3(this, "defaultQueryTTL");
|
2979
3895
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
2980
3896
|
this.capacity = options.max ?? 500;
|
2981
3897
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3111,19 +4027,19 @@ class SearchPlugin extends XataPlugin {
|
|
3111
4027
|
__privateAdd$1(this, _schemaTables, void 0);
|
3112
4028
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3113
4029
|
}
|
3114
|
-
build(
|
4030
|
+
build(pluginOptions) {
|
3115
4031
|
return {
|
3116
4032
|
all: async (query, options = {}) => {
|
3117
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3118
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4033
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4034
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3119
4035
|
return records.map((record) => {
|
3120
4036
|
const { table = "orphan" } = record.xata;
|
3121
4037
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3122
4038
|
});
|
3123
4039
|
},
|
3124
4040
|
byTable: async (query, options = {}) => {
|
3125
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3126
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4041
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4042
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3127
4043
|
return records.reduce((acc, record) => {
|
3128
4044
|
const { table = "orphan" } = record.xata;
|
3129
4045
|
const items = acc[table] ?? [];
|
@@ -3136,38 +4052,36 @@ class SearchPlugin extends XataPlugin {
|
|
3136
4052
|
}
|
3137
4053
|
_schemaTables = new WeakMap();
|
3138
4054
|
_search = new WeakSet();
|
3139
|
-
search_fn = async function(query, options,
|
3140
|
-
const
|
3141
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
4055
|
+
search_fn = async function(query, options, pluginOptions) {
|
4056
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3142
4057
|
const { records } = await searchBranch({
|
3143
4058
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3144
|
-
|
3145
|
-
|
4059
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4060
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
4061
|
+
...pluginOptions
|
3146
4062
|
});
|
3147
4063
|
return records;
|
3148
4064
|
};
|
3149
4065
|
_getSchemaTables = new WeakSet();
|
3150
|
-
getSchemaTables_fn = async function(
|
4066
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3151
4067
|
if (__privateGet$1(this, _schemaTables))
|
3152
4068
|
return __privateGet$1(this, _schemaTables);
|
3153
|
-
const fetchProps = await getFetchProps();
|
3154
4069
|
const { schema } = await getBranchDetails({
|
3155
4070
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3156
|
-
...
|
4071
|
+
...pluginOptions
|
3157
4072
|
});
|
3158
4073
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3159
4074
|
return schema.tables;
|
3160
4075
|
};
|
3161
4076
|
|
3162
4077
|
class TransactionPlugin extends XataPlugin {
|
3163
|
-
build(
|
4078
|
+
build(pluginOptions) {
|
3164
4079
|
return {
|
3165
4080
|
run: async (operations) => {
|
3166
|
-
const fetchProps = await getFetchProps();
|
3167
4081
|
const response = await branchTransaction({
|
3168
4082
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3169
4083
|
body: { operations },
|
3170
|
-
...
|
4084
|
+
...pluginOptions
|
3171
4085
|
});
|
3172
4086
|
return response;
|
3173
4087
|
}
|
@@ -3175,93 +4089,12 @@ class TransactionPlugin extends XataPlugin {
|
|
3175
4089
|
}
|
3176
4090
|
}
|
3177
4091
|
|
3178
|
-
|
3179
|
-
|
4092
|
+
var __defProp$2 = Object.defineProperty;
|
4093
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4094
|
+
var __publicField$2 = (obj, key, value) => {
|
4095
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4096
|
+
return value;
|
3180
4097
|
};
|
3181
|
-
|
3182
|
-
async function getCurrentBranchName(options) {
|
3183
|
-
const { branch, envBranch } = getEnvironment();
|
3184
|
-
if (branch) {
|
3185
|
-
const details = await getDatabaseBranch(branch, options);
|
3186
|
-
if (details)
|
3187
|
-
return branch;
|
3188
|
-
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
3189
|
-
}
|
3190
|
-
const gitBranch = envBranch || await getGitBranch();
|
3191
|
-
return resolveXataBranch(gitBranch, options);
|
3192
|
-
}
|
3193
|
-
async function getCurrentBranchDetails(options) {
|
3194
|
-
const branch = await getCurrentBranchName(options);
|
3195
|
-
return getDatabaseBranch(branch, options);
|
3196
|
-
}
|
3197
|
-
async function resolveXataBranch(gitBranch, options) {
|
3198
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3199
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3200
|
-
if (!databaseURL)
|
3201
|
-
throw new Error(
|
3202
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3203
|
-
);
|
3204
|
-
if (!apiKey)
|
3205
|
-
throw new Error(
|
3206
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3207
|
-
);
|
3208
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3209
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3210
|
-
if (!urlParts)
|
3211
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3212
|
-
const { workspace, region } = urlParts;
|
3213
|
-
const { fallbackBranch } = getEnvironment();
|
3214
|
-
const { branch } = await resolveBranch({
|
3215
|
-
apiKey,
|
3216
|
-
apiUrl: databaseURL,
|
3217
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3218
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3219
|
-
pathParams: { dbName, workspace, region },
|
3220
|
-
queryParams: { gitBranch, fallbackBranch },
|
3221
|
-
trace: defaultTrace
|
3222
|
-
});
|
3223
|
-
return branch;
|
3224
|
-
}
|
3225
|
-
async function getDatabaseBranch(branch, options) {
|
3226
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3227
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3228
|
-
if (!databaseURL)
|
3229
|
-
throw new Error(
|
3230
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3231
|
-
);
|
3232
|
-
if (!apiKey)
|
3233
|
-
throw new Error(
|
3234
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3235
|
-
);
|
3236
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3237
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3238
|
-
if (!urlParts)
|
3239
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3240
|
-
const { workspace, region } = urlParts;
|
3241
|
-
try {
|
3242
|
-
return await getBranchDetails({
|
3243
|
-
apiKey,
|
3244
|
-
apiUrl: databaseURL,
|
3245
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3246
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3247
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3248
|
-
trace: defaultTrace
|
3249
|
-
});
|
3250
|
-
} catch (err) {
|
3251
|
-
if (isObject(err) && err.status === 404)
|
3252
|
-
return null;
|
3253
|
-
throw err;
|
3254
|
-
}
|
3255
|
-
}
|
3256
|
-
function getDatabaseURL() {
|
3257
|
-
try {
|
3258
|
-
const { databaseURL } = getEnvironment();
|
3259
|
-
return databaseURL;
|
3260
|
-
} catch (err) {
|
3261
|
-
return void 0;
|
3262
|
-
}
|
3263
|
-
}
|
3264
|
-
|
3265
4098
|
var __accessCheck = (obj, member, msg) => {
|
3266
4099
|
if (!member.has(obj))
|
3267
4100
|
throw TypeError("Cannot " + msg);
|
@@ -3285,20 +4118,21 @@ var __privateMethod = (obj, member, method) => {
|
|
3285
4118
|
return method;
|
3286
4119
|
};
|
3287
4120
|
const buildClient = (plugins) => {
|
3288
|
-
var
|
4121
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3289
4122
|
return _a = class {
|
3290
4123
|
constructor(options = {}, schemaTables) {
|
3291
4124
|
__privateAdd(this, _parseOptions);
|
3292
4125
|
__privateAdd(this, _getFetchProps);
|
3293
|
-
__privateAdd(this, _evaluateBranch);
|
3294
|
-
__privateAdd(this, _branch, void 0);
|
3295
4126
|
__privateAdd(this, _options, void 0);
|
4127
|
+
__publicField$2(this, "db");
|
4128
|
+
__publicField$2(this, "search");
|
4129
|
+
__publicField$2(this, "transactions");
|
3296
4130
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3297
4131
|
__privateSet(this, _options, safeOptions);
|
3298
4132
|
const pluginOptions = {
|
3299
|
-
|
4133
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3300
4134
|
cache: safeOptions.cache,
|
3301
|
-
|
4135
|
+
host: safeOptions.host
|
3302
4136
|
};
|
3303
4137
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3304
4138
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -3309,24 +4143,17 @@ const buildClient = (plugins) => {
|
|
3309
4143
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3310
4144
|
if (namespace === void 0)
|
3311
4145
|
continue;
|
3312
|
-
|
3313
|
-
if (result instanceof Promise) {
|
3314
|
-
void result.then((namespace2) => {
|
3315
|
-
this[key] = namespace2;
|
3316
|
-
});
|
3317
|
-
} else {
|
3318
|
-
this[key] = result;
|
3319
|
-
}
|
4146
|
+
this[key] = namespace.build(pluginOptions);
|
3320
4147
|
}
|
3321
4148
|
}
|
3322
4149
|
async getConfig() {
|
3323
4150
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3324
|
-
const branch =
|
4151
|
+
const branch = __privateGet(this, _options).branch;
|
3325
4152
|
return { databaseURL, branch };
|
3326
4153
|
}
|
3327
|
-
},
|
4154
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3328
4155
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3329
|
-
const isBrowser = typeof window !== "undefined";
|
4156
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3330
4157
|
if (isBrowser && !enableBrowser) {
|
3331
4158
|
throw new Error(
|
3332
4159
|
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
@@ -3337,56 +4164,89 @@ const buildClient = (plugins) => {
|
|
3337
4164
|
const apiKey = options?.apiKey || getAPIKey();
|
3338
4165
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3339
4166
|
const trace = options?.trace ?? defaultTrace;
|
3340
|
-
const
|
4167
|
+
const clientName = options?.clientName;
|
4168
|
+
const host = options?.host ?? "production";
|
4169
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3341
4170
|
if (!apiKey) {
|
3342
4171
|
throw new Error("Option apiKey is required");
|
3343
4172
|
}
|
3344
4173
|
if (!databaseURL) {
|
3345
4174
|
throw new Error("Option databaseURL is required");
|
3346
4175
|
}
|
3347
|
-
|
3348
|
-
|
3349
|
-
const
|
3350
|
-
if (
|
3351
|
-
|
4176
|
+
const envBranch = getBranch();
|
4177
|
+
const previewBranch = getPreviewBranch();
|
4178
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4179
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4180
|
+
console.warn(
|
4181
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4182
|
+
);
|
4183
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4184
|
+
console.warn(
|
4185
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4186
|
+
);
|
4187
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4188
|
+
console.warn(
|
4189
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4190
|
+
);
|
4191
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4192
|
+
console.warn(
|
4193
|
+
`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.`
|
4194
|
+
);
|
4195
|
+
}
|
3352
4196
|
return {
|
3353
|
-
|
4197
|
+
fetch,
|
4198
|
+
databaseURL,
|
4199
|
+
apiKey,
|
4200
|
+
branch,
|
4201
|
+
cache,
|
4202
|
+
trace,
|
4203
|
+
host,
|
4204
|
+
clientID: generateUUID(),
|
4205
|
+
enableBrowser,
|
4206
|
+
clientName,
|
4207
|
+
xataAgentExtra
|
4208
|
+
};
|
4209
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4210
|
+
fetch,
|
4211
|
+
apiKey,
|
4212
|
+
databaseURL,
|
4213
|
+
branch,
|
4214
|
+
trace,
|
4215
|
+
clientID,
|
4216
|
+
clientName,
|
4217
|
+
xataAgentExtra
|
4218
|
+
}) {
|
4219
|
+
return {
|
4220
|
+
fetch,
|
3354
4221
|
apiKey,
|
3355
4222
|
apiUrl: "",
|
4223
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3356
4224
|
workspacesApiUrl: (path, params) => {
|
3357
4225
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3358
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4226
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3359
4227
|
return databaseURL + newPath;
|
3360
4228
|
},
|
3361
4229
|
trace,
|
3362
|
-
clientID
|
4230
|
+
clientID,
|
4231
|
+
clientName,
|
4232
|
+
xataAgentExtra
|
3363
4233
|
};
|
3364
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3365
|
-
if (__privateGet(this, _branch))
|
3366
|
-
return __privateGet(this, _branch);
|
3367
|
-
if (param === void 0)
|
3368
|
-
return void 0;
|
3369
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3370
|
-
const evaluateBranch = async (strategy) => {
|
3371
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3372
|
-
};
|
3373
|
-
for await (const strategy of strategies) {
|
3374
|
-
const branch = await evaluateBranch(strategy);
|
3375
|
-
if (branch) {
|
3376
|
-
__privateSet(this, _branch, branch);
|
3377
|
-
return branch;
|
3378
|
-
}
|
3379
|
-
}
|
3380
4234
|
}, _a;
|
3381
4235
|
};
|
3382
4236
|
class BaseClient extends buildClient() {
|
3383
4237
|
}
|
3384
4238
|
|
4239
|
+
var __defProp$1 = Object.defineProperty;
|
4240
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4241
|
+
var __publicField$1 = (obj, key, value) => {
|
4242
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4243
|
+
return value;
|
4244
|
+
};
|
3385
4245
|
const META = "__";
|
3386
4246
|
const VALUE = "___";
|
3387
4247
|
class Serializer {
|
3388
4248
|
constructor() {
|
3389
|
-
this
|
4249
|
+
__publicField$1(this, "classes", {});
|
3390
4250
|
}
|
3391
4251
|
add(clazz) {
|
3392
4252
|
this.classes[clazz.name] = clazz;
|
@@ -3450,7 +4310,7 @@ const deserialize = (json) => {
|
|
3450
4310
|
};
|
3451
4311
|
|
3452
4312
|
function buildWorkerRunner(config) {
|
3453
|
-
return function xataWorker(name,
|
4313
|
+
return function xataWorker(name, worker) {
|
3454
4314
|
return async (...args) => {
|
3455
4315
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3456
4316
|
const result = await fetch(url, {
|
@@ -3464,12 +4324,19 @@ function buildWorkerRunner(config) {
|
|
3464
4324
|
};
|
3465
4325
|
}
|
3466
4326
|
|
4327
|
+
var __defProp = Object.defineProperty;
|
4328
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4329
|
+
var __publicField = (obj, key, value) => {
|
4330
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4331
|
+
return value;
|
4332
|
+
};
|
3467
4333
|
class XataError extends Error {
|
3468
4334
|
constructor(message, status) {
|
3469
4335
|
super(message);
|
4336
|
+
__publicField(this, "status");
|
3470
4337
|
this.status = status;
|
3471
4338
|
}
|
3472
4339
|
}
|
3473
4340
|
|
3474
|
-
export { BaseClient, 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,
|
4341
|
+
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, chatSessionMessage, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, 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, 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, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3475
4342
|
//# sourceMappingURL=index.mjs.map
|