@xata.io/client 0.0.0-alpha.vff9649a → 0.0.0-alpha.vffe924c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +119 -1
- package/README.md +3 -269
- package/dist/index.cjs +975 -245
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2365 -1051
- package/dist/index.mjs +956 -243
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/.eslintrc.cjs +0 -13
- package/Usage.md +0 -451
- package/rollup.config.mjs +0 -44
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -91,8 +91,10 @@ function getEnvironment() {
|
|
91
91
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
92
92
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
93
93
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
94
|
-
|
95
|
-
|
94
|
+
deployPreview: process.env.XATA_PREVIEW,
|
95
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
96
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
97
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
96
98
|
};
|
97
99
|
}
|
98
100
|
} catch (err) {
|
@@ -103,8 +105,10 @@ function getEnvironment() {
|
|
103
105
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
104
106
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
105
107
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
106
|
-
|
107
|
-
|
108
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
109
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
110
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
111
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
108
112
|
};
|
109
113
|
}
|
110
114
|
} catch (err) {
|
@@ -113,8 +117,10 @@ function getEnvironment() {
|
|
113
117
|
apiKey: getGlobalApiKey(),
|
114
118
|
databaseURL: getGlobalDatabaseURL(),
|
115
119
|
branch: getGlobalBranch(),
|
116
|
-
|
117
|
-
|
120
|
+
deployPreview: void 0,
|
121
|
+
deployPreviewBranch: void 0,
|
122
|
+
vercelGitCommitRef: void 0,
|
123
|
+
vercelGitRepoOwner: void 0
|
118
124
|
};
|
119
125
|
}
|
120
126
|
function getEnableBrowserVariable() {
|
@@ -157,36 +163,48 @@ function getGlobalBranch() {
|
|
157
163
|
return void 0;
|
158
164
|
}
|
159
165
|
}
|
160
|
-
function
|
166
|
+
function getDatabaseURL() {
|
161
167
|
try {
|
162
|
-
|
168
|
+
const { databaseURL } = getEnvironment();
|
169
|
+
return databaseURL;
|
163
170
|
} catch (err) {
|
164
171
|
return void 0;
|
165
172
|
}
|
166
173
|
}
|
167
|
-
|
168
|
-
const cmd = ["git", "branch", "--show-current"];
|
169
|
-
const fullCmd = cmd.join(" ");
|
170
|
-
const nodeModule = ["child", "process"].join("_");
|
171
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
174
|
+
function getAPIKey() {
|
172
175
|
try {
|
173
|
-
const {
|
174
|
-
return
|
176
|
+
const { apiKey } = getEnvironment();
|
177
|
+
return apiKey;
|
175
178
|
} catch (err) {
|
179
|
+
return void 0;
|
176
180
|
}
|
181
|
+
}
|
182
|
+
function getBranch() {
|
177
183
|
try {
|
178
|
-
|
179
|
-
|
180
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
181
|
-
}
|
184
|
+
const { branch } = getEnvironment();
|
185
|
+
return branch ?? "main";
|
182
186
|
} catch (err) {
|
187
|
+
return void 0;
|
183
188
|
}
|
184
189
|
}
|
185
|
-
|
186
|
-
|
190
|
+
function buildPreviewBranchName({ org, branch }) {
|
191
|
+
return `preview-${org}-${branch}`;
|
192
|
+
}
|
193
|
+
function getPreviewBranch() {
|
187
194
|
try {
|
188
|
-
const {
|
189
|
-
|
195
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
196
|
+
if (deployPreviewBranch)
|
197
|
+
return deployPreviewBranch;
|
198
|
+
switch (deployPreview) {
|
199
|
+
case "vercel": {
|
200
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
201
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
202
|
+
return void 0;
|
203
|
+
}
|
204
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
205
|
+
}
|
206
|
+
}
|
207
|
+
return void 0;
|
190
208
|
} catch (err) {
|
191
209
|
return void 0;
|
192
210
|
}
|
@@ -246,7 +264,7 @@ class ApiRequestPool {
|
|
246
264
|
return __privateGet$8(this, _fetch);
|
247
265
|
}
|
248
266
|
request(url, options) {
|
249
|
-
const start = new Date();
|
267
|
+
const start = /* @__PURE__ */ new Date();
|
250
268
|
const fetch2 = this.getFetch();
|
251
269
|
const runRequest = async (stalled = false) => {
|
252
270
|
const response = await fetch2(url, options);
|
@@ -256,7 +274,7 @@ class ApiRequestPool {
|
|
256
274
|
return await runRequest(true);
|
257
275
|
}
|
258
276
|
if (stalled) {
|
259
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
277
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
260
278
|
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
261
279
|
}
|
262
280
|
return response;
|
@@ -299,7 +317,180 @@ function generateUUID() {
|
|
299
317
|
});
|
300
318
|
}
|
301
319
|
|
302
|
-
|
320
|
+
async function getBytes(stream, onChunk) {
|
321
|
+
const reader = stream.getReader();
|
322
|
+
let result;
|
323
|
+
while (!(result = await reader.read()).done) {
|
324
|
+
onChunk(result.value);
|
325
|
+
}
|
326
|
+
}
|
327
|
+
function getLines(onLine) {
|
328
|
+
let buffer;
|
329
|
+
let position;
|
330
|
+
let fieldLength;
|
331
|
+
let discardTrailingNewline = false;
|
332
|
+
return function onChunk(arr) {
|
333
|
+
if (buffer === void 0) {
|
334
|
+
buffer = arr;
|
335
|
+
position = 0;
|
336
|
+
fieldLength = -1;
|
337
|
+
} else {
|
338
|
+
buffer = concat(buffer, arr);
|
339
|
+
}
|
340
|
+
const bufLength = buffer.length;
|
341
|
+
let lineStart = 0;
|
342
|
+
while (position < bufLength) {
|
343
|
+
if (discardTrailingNewline) {
|
344
|
+
if (buffer[position] === 10 /* NewLine */) {
|
345
|
+
lineStart = ++position;
|
346
|
+
}
|
347
|
+
discardTrailingNewline = false;
|
348
|
+
}
|
349
|
+
let lineEnd = -1;
|
350
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
351
|
+
switch (buffer[position]) {
|
352
|
+
case 58 /* Colon */:
|
353
|
+
if (fieldLength === -1) {
|
354
|
+
fieldLength = position - lineStart;
|
355
|
+
}
|
356
|
+
break;
|
357
|
+
case 13 /* CarriageReturn */:
|
358
|
+
discardTrailingNewline = true;
|
359
|
+
case 10 /* NewLine */:
|
360
|
+
lineEnd = position;
|
361
|
+
break;
|
362
|
+
}
|
363
|
+
}
|
364
|
+
if (lineEnd === -1) {
|
365
|
+
break;
|
366
|
+
}
|
367
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
368
|
+
lineStart = position;
|
369
|
+
fieldLength = -1;
|
370
|
+
}
|
371
|
+
if (lineStart === bufLength) {
|
372
|
+
buffer = void 0;
|
373
|
+
} else if (lineStart !== 0) {
|
374
|
+
buffer = buffer.subarray(lineStart);
|
375
|
+
position -= lineStart;
|
376
|
+
}
|
377
|
+
};
|
378
|
+
}
|
379
|
+
function getMessages(onId, onRetry, onMessage) {
|
380
|
+
let message = newMessage();
|
381
|
+
const decoder = new TextDecoder();
|
382
|
+
return function onLine(line, fieldLength) {
|
383
|
+
if (line.length === 0) {
|
384
|
+
onMessage?.(message);
|
385
|
+
message = newMessage();
|
386
|
+
} else if (fieldLength > 0) {
|
387
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
388
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
389
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
390
|
+
switch (field) {
|
391
|
+
case "data":
|
392
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
393
|
+
break;
|
394
|
+
case "event":
|
395
|
+
message.event = value;
|
396
|
+
break;
|
397
|
+
case "id":
|
398
|
+
onId(message.id = value);
|
399
|
+
break;
|
400
|
+
case "retry":
|
401
|
+
const retry = parseInt(value, 10);
|
402
|
+
if (!isNaN(retry)) {
|
403
|
+
onRetry(message.retry = retry);
|
404
|
+
}
|
405
|
+
break;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
};
|
409
|
+
}
|
410
|
+
function concat(a, b) {
|
411
|
+
const res = new Uint8Array(a.length + b.length);
|
412
|
+
res.set(a);
|
413
|
+
res.set(b, a.length);
|
414
|
+
return res;
|
415
|
+
}
|
416
|
+
function newMessage() {
|
417
|
+
return {
|
418
|
+
data: "",
|
419
|
+
event: "",
|
420
|
+
id: "",
|
421
|
+
retry: void 0
|
422
|
+
};
|
423
|
+
}
|
424
|
+
const EventStreamContentType = "text/event-stream";
|
425
|
+
const LastEventId = "last-event-id";
|
426
|
+
function fetchEventSource(input, {
|
427
|
+
signal: inputSignal,
|
428
|
+
headers: inputHeaders,
|
429
|
+
onopen: inputOnOpen,
|
430
|
+
onmessage,
|
431
|
+
onclose,
|
432
|
+
onerror,
|
433
|
+
fetch: inputFetch,
|
434
|
+
...rest
|
435
|
+
}) {
|
436
|
+
return new Promise((resolve, reject) => {
|
437
|
+
const headers = { ...inputHeaders };
|
438
|
+
if (!headers.accept) {
|
439
|
+
headers.accept = EventStreamContentType;
|
440
|
+
}
|
441
|
+
let curRequestController;
|
442
|
+
function dispose() {
|
443
|
+
curRequestController.abort();
|
444
|
+
}
|
445
|
+
inputSignal?.addEventListener("abort", () => {
|
446
|
+
dispose();
|
447
|
+
resolve();
|
448
|
+
});
|
449
|
+
const fetchImpl = inputFetch ?? fetch;
|
450
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
451
|
+
async function create() {
|
452
|
+
curRequestController = new AbortController();
|
453
|
+
try {
|
454
|
+
const response = await fetchImpl(input, {
|
455
|
+
...rest,
|
456
|
+
headers,
|
457
|
+
signal: curRequestController.signal
|
458
|
+
});
|
459
|
+
await onopen(response);
|
460
|
+
await getBytes(
|
461
|
+
response.body,
|
462
|
+
getLines(
|
463
|
+
getMessages(
|
464
|
+
(id) => {
|
465
|
+
if (id) {
|
466
|
+
headers[LastEventId] = id;
|
467
|
+
} else {
|
468
|
+
delete headers[LastEventId];
|
469
|
+
}
|
470
|
+
},
|
471
|
+
(_retry) => {
|
472
|
+
},
|
473
|
+
onmessage
|
474
|
+
)
|
475
|
+
)
|
476
|
+
);
|
477
|
+
onclose?.();
|
478
|
+
dispose();
|
479
|
+
resolve();
|
480
|
+
} catch (err) {
|
481
|
+
}
|
482
|
+
}
|
483
|
+
create();
|
484
|
+
});
|
485
|
+
}
|
486
|
+
function defaultOnOpen(response) {
|
487
|
+
const contentType = response.headers?.get("content-type");
|
488
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
489
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
const VERSION = "0.24.2";
|
303
494
|
|
304
495
|
class ErrorWithCause extends Error {
|
305
496
|
constructor(message, options) {
|
@@ -383,7 +574,7 @@ async function fetch$1({
|
|
383
574
|
headers: customHeaders,
|
384
575
|
pathParams,
|
385
576
|
queryParams,
|
386
|
-
|
577
|
+
fetch: fetch2,
|
387
578
|
apiKey,
|
388
579
|
endpoint,
|
389
580
|
apiUrl,
|
@@ -393,9 +584,10 @@ async function fetch$1({
|
|
393
584
|
clientID,
|
394
585
|
sessionID,
|
395
586
|
clientName,
|
587
|
+
xataAgentExtra,
|
396
588
|
fetchOptions = {}
|
397
589
|
}) {
|
398
|
-
pool.setFetch(
|
590
|
+
pool.setFetch(fetch2);
|
399
591
|
return await trace(
|
400
592
|
`${method.toUpperCase()} ${path}`,
|
401
593
|
async ({ setAttributes }) => {
|
@@ -409,7 +601,8 @@ async function fetch$1({
|
|
409
601
|
const xataAgent = compact([
|
410
602
|
["client", "TS_SDK"],
|
411
603
|
["version", VERSION],
|
412
|
-
isDefined(clientName) ? ["service", clientName] : void 0
|
604
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
605
|
+
...Object.entries(xataAgentExtra ?? {})
|
413
606
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
414
607
|
const headers = {
|
415
608
|
"Accept-Encoding": "identity",
|
@@ -456,6 +649,59 @@ async function fetch$1({
|
|
456
649
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
457
650
|
);
|
458
651
|
}
|
652
|
+
function fetchSSERequest({
|
653
|
+
url: path,
|
654
|
+
method,
|
655
|
+
body,
|
656
|
+
headers: customHeaders,
|
657
|
+
pathParams,
|
658
|
+
queryParams,
|
659
|
+
fetch: fetch2,
|
660
|
+
apiKey,
|
661
|
+
endpoint,
|
662
|
+
apiUrl,
|
663
|
+
workspacesApiUrl,
|
664
|
+
onMessage,
|
665
|
+
onError,
|
666
|
+
onClose,
|
667
|
+
signal,
|
668
|
+
clientID,
|
669
|
+
sessionID,
|
670
|
+
clientName,
|
671
|
+
xataAgentExtra
|
672
|
+
}) {
|
673
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
674
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
675
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
676
|
+
void fetchEventSource(url, {
|
677
|
+
method,
|
678
|
+
body: JSON.stringify(body),
|
679
|
+
fetch: fetch2,
|
680
|
+
signal,
|
681
|
+
headers: {
|
682
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
683
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
684
|
+
"X-Xata-Agent": compact([
|
685
|
+
["client", "TS_SDK"],
|
686
|
+
["version", VERSION],
|
687
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
688
|
+
...Object.entries(xataAgentExtra ?? {})
|
689
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
690
|
+
...customHeaders,
|
691
|
+
Authorization: `Bearer ${apiKey}`,
|
692
|
+
"Content-Type": "application/json"
|
693
|
+
},
|
694
|
+
onmessage(ev) {
|
695
|
+
onMessage?.(JSON.parse(ev.data));
|
696
|
+
},
|
697
|
+
onerror(ev) {
|
698
|
+
onError?.(JSON.parse(ev.data));
|
699
|
+
},
|
700
|
+
onclose() {
|
701
|
+
onClose?.();
|
702
|
+
}
|
703
|
+
});
|
704
|
+
}
|
459
705
|
function parseUrl(url) {
|
460
706
|
try {
|
461
707
|
const { host, protocol } = new URL(url);
|
@@ -486,6 +732,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
486
732
|
...variables,
|
487
733
|
signal
|
488
734
|
});
|
735
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
736
|
+
url: "/db/{dbBranchName}/copy",
|
737
|
+
method: "post",
|
738
|
+
...variables,
|
739
|
+
signal
|
740
|
+
});
|
489
741
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
490
742
|
url: "/db/{dbBranchName}/metadata",
|
491
743
|
method: "put",
|
@@ -511,7 +763,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
511
763
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
512
764
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
513
765
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
514
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
515
766
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
516
767
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
517
768
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -536,6 +787,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
536
787
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
537
788
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
538
789
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
790
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
539
791
|
const createTable = (variables, signal) => dataPlaneFetch({
|
540
792
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
541
793
|
method: "put",
|
@@ -578,7 +830,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
578
830
|
...variables,
|
579
831
|
signal
|
580
832
|
});
|
833
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
581
834
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
835
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
836
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
837
|
+
method: "get",
|
838
|
+
...variables,
|
839
|
+
signal
|
840
|
+
});
|
841
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
842
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
843
|
+
method: "put",
|
844
|
+
...variables,
|
845
|
+
signal
|
846
|
+
});
|
847
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
848
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
849
|
+
method: "delete",
|
850
|
+
...variables,
|
851
|
+
signal
|
852
|
+
});
|
853
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
854
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
855
|
+
method: "get",
|
856
|
+
...variables,
|
857
|
+
signal
|
858
|
+
});
|
859
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
860
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
861
|
+
method: "put",
|
862
|
+
...variables,
|
863
|
+
signal
|
864
|
+
});
|
865
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
866
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
867
|
+
method: "delete",
|
868
|
+
...variables,
|
869
|
+
signal
|
870
|
+
});
|
582
871
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
583
872
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
584
873
|
method: "get",
|
@@ -608,14 +897,34 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
608
897
|
...variables,
|
609
898
|
signal
|
610
899
|
});
|
900
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
901
|
+
url: "/db/{dbBranchName}/sql",
|
902
|
+
method: "post",
|
903
|
+
...variables,
|
904
|
+
signal
|
905
|
+
});
|
906
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
907
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
908
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
909
|
+
method: "post",
|
910
|
+
...variables,
|
911
|
+
signal
|
912
|
+
});
|
611
913
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
612
914
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
915
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
916
|
+
url: "/file/{fileId}",
|
917
|
+
method: "get",
|
918
|
+
...variables,
|
919
|
+
signal
|
920
|
+
});
|
613
921
|
const operationsByTag$2 = {
|
614
922
|
branch: {
|
615
923
|
getBranchList,
|
616
924
|
getBranchDetails,
|
617
925
|
createBranch,
|
618
926
|
deleteBranch,
|
927
|
+
copyBranch,
|
619
928
|
updateBranchMetadata,
|
620
929
|
getBranchMetadata,
|
621
930
|
getBranchStats,
|
@@ -633,17 +942,8 @@ const operationsByTag$2 = {
|
|
633
942
|
compareBranchSchemas,
|
634
943
|
updateBranchSchema,
|
635
944
|
previewBranchSchemaEdit,
|
636
|
-
applyBranchSchemaEdit
|
637
|
-
|
638
|
-
records: {
|
639
|
-
branchTransaction,
|
640
|
-
insertRecord,
|
641
|
-
getRecord,
|
642
|
-
insertRecordWithID,
|
643
|
-
updateRecordWithID,
|
644
|
-
upsertRecordWithID,
|
645
|
-
deleteRecord,
|
646
|
-
bulkInsertTableRecords
|
945
|
+
applyBranchSchemaEdit,
|
946
|
+
pushBranchMigrations
|
647
947
|
},
|
648
948
|
migrationRequests: {
|
649
949
|
queryMigrationRequests,
|
@@ -667,7 +967,27 @@ const operationsByTag$2 = {
|
|
667
967
|
updateColumn,
|
668
968
|
deleteColumn
|
669
969
|
},
|
670
|
-
|
970
|
+
records: {
|
971
|
+
branchTransaction,
|
972
|
+
insertRecord,
|
973
|
+
getRecord,
|
974
|
+
insertRecordWithID,
|
975
|
+
updateRecordWithID,
|
976
|
+
upsertRecordWithID,
|
977
|
+
deleteRecord,
|
978
|
+
bulkInsertTableRecords
|
979
|
+
},
|
980
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
981
|
+
searchAndFilter: {
|
982
|
+
queryTable,
|
983
|
+
searchBranch,
|
984
|
+
searchTable,
|
985
|
+
sqlQuery,
|
986
|
+
vectorSearchTable,
|
987
|
+
askTable,
|
988
|
+
summarizeTable,
|
989
|
+
aggregateTable
|
990
|
+
}
|
671
991
|
};
|
672
992
|
|
673
993
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -766,6 +1086,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
766
1086
|
});
|
767
1087
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
768
1088
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1089
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1090
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1091
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1092
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
769
1093
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
770
1094
|
url: "/workspaces/{workspaceId}/regions",
|
771
1095
|
method: "get",
|
@@ -798,6 +1122,10 @@ const operationsByTag$1 = {
|
|
798
1122
|
deleteDatabase,
|
799
1123
|
getDatabaseMetadata,
|
800
1124
|
updateDatabaseMetadata,
|
1125
|
+
renameDatabase,
|
1126
|
+
getDatabaseGithubSettings,
|
1127
|
+
updateDatabaseGithubSettings,
|
1128
|
+
deleteDatabaseGithubSettings,
|
801
1129
|
listRegions
|
802
1130
|
}
|
803
1131
|
};
|
@@ -818,8 +1146,12 @@ const providers = {
|
|
818
1146
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
819
1147
|
},
|
820
1148
|
staging: {
|
821
|
-
main: "https://staging.
|
822
|
-
workspaces: "https://{workspaceId}.
|
1149
|
+
main: "https://api.staging-xata.dev",
|
1150
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1151
|
+
},
|
1152
|
+
dev: {
|
1153
|
+
main: "https://api.dev-xata.dev",
|
1154
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
823
1155
|
}
|
824
1156
|
};
|
825
1157
|
function isHostProviderAlias(alias) {
|
@@ -837,12 +1169,19 @@ function parseProviderString(provider = "production") {
|
|
837
1169
|
return null;
|
838
1170
|
return { main, workspaces };
|
839
1171
|
}
|
1172
|
+
function buildProviderString(provider) {
|
1173
|
+
if (isHostProviderAlias(provider))
|
1174
|
+
return provider;
|
1175
|
+
return `${provider.main},${provider.workspaces}`;
|
1176
|
+
}
|
840
1177
|
function parseWorkspacesUrlParts(url) {
|
841
1178
|
if (!isString(url))
|
842
1179
|
return null;
|
843
1180
|
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
844
|
-
const
|
845
|
-
const
|
1181
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1182
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1183
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1184
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
846
1185
|
if (!match)
|
847
1186
|
return null;
|
848
1187
|
return { workspace: match[1], region: match[2] };
|
@@ -881,10 +1220,11 @@ class XataApiClient {
|
|
881
1220
|
__privateSet$7(this, _extraProps, {
|
882
1221
|
apiUrl: getHostUrl(provider, "main"),
|
883
1222
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
884
|
-
|
1223
|
+
fetch: getFetchImplementation(options.fetch),
|
885
1224
|
apiKey,
|
886
1225
|
trace,
|
887
1226
|
clientName: options.clientName,
|
1227
|
+
xataAgentExtra: options.xataAgentExtra,
|
888
1228
|
clientID
|
889
1229
|
});
|
890
1230
|
}
|
@@ -938,6 +1278,11 @@ class XataApiClient {
|
|
938
1278
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
939
1279
|
return __privateGet$7(this, _namespaces).records;
|
940
1280
|
}
|
1281
|
+
get files() {
|
1282
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1283
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1284
|
+
return __privateGet$7(this, _namespaces).files;
|
1285
|
+
}
|
941
1286
|
get searchAndFilter() {
|
942
1287
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
943
1288
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1146,6 +1491,20 @@ class BranchApi {
|
|
1146
1491
|
...this.extraProps
|
1147
1492
|
});
|
1148
1493
|
}
|
1494
|
+
copyBranch({
|
1495
|
+
workspace,
|
1496
|
+
region,
|
1497
|
+
database,
|
1498
|
+
branch,
|
1499
|
+
destinationBranch,
|
1500
|
+
limit
|
1501
|
+
}) {
|
1502
|
+
return operationsByTag.branch.copyBranch({
|
1503
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1504
|
+
body: { destinationBranch, limit },
|
1505
|
+
...this.extraProps
|
1506
|
+
});
|
1507
|
+
}
|
1149
1508
|
updateBranchMetadata({
|
1150
1509
|
workspace,
|
1151
1510
|
region,
|
@@ -1501,6 +1860,164 @@ class RecordsApi {
|
|
1501
1860
|
});
|
1502
1861
|
}
|
1503
1862
|
}
|
1863
|
+
class FilesApi {
|
1864
|
+
constructor(extraProps) {
|
1865
|
+
this.extraProps = extraProps;
|
1866
|
+
}
|
1867
|
+
getFileItem({
|
1868
|
+
workspace,
|
1869
|
+
region,
|
1870
|
+
database,
|
1871
|
+
branch,
|
1872
|
+
table,
|
1873
|
+
record,
|
1874
|
+
column,
|
1875
|
+
fileId
|
1876
|
+
}) {
|
1877
|
+
return operationsByTag.files.getFileItem({
|
1878
|
+
pathParams: {
|
1879
|
+
workspace,
|
1880
|
+
region,
|
1881
|
+
dbBranchName: `${database}:${branch}`,
|
1882
|
+
tableName: table,
|
1883
|
+
recordId: record,
|
1884
|
+
columnName: column,
|
1885
|
+
fileId
|
1886
|
+
},
|
1887
|
+
...this.extraProps
|
1888
|
+
});
|
1889
|
+
}
|
1890
|
+
putFileItem({
|
1891
|
+
workspace,
|
1892
|
+
region,
|
1893
|
+
database,
|
1894
|
+
branch,
|
1895
|
+
table,
|
1896
|
+
record,
|
1897
|
+
column,
|
1898
|
+
fileId,
|
1899
|
+
file
|
1900
|
+
}) {
|
1901
|
+
return operationsByTag.files.putFileItem({
|
1902
|
+
pathParams: {
|
1903
|
+
workspace,
|
1904
|
+
region,
|
1905
|
+
dbBranchName: `${database}:${branch}`,
|
1906
|
+
tableName: table,
|
1907
|
+
recordId: record,
|
1908
|
+
columnName: column,
|
1909
|
+
fileId
|
1910
|
+
},
|
1911
|
+
// @ts-ignore
|
1912
|
+
body: file,
|
1913
|
+
...this.extraProps
|
1914
|
+
});
|
1915
|
+
}
|
1916
|
+
deleteFileItem({
|
1917
|
+
workspace,
|
1918
|
+
region,
|
1919
|
+
database,
|
1920
|
+
branch,
|
1921
|
+
table,
|
1922
|
+
record,
|
1923
|
+
column,
|
1924
|
+
fileId
|
1925
|
+
}) {
|
1926
|
+
return operationsByTag.files.deleteFileItem({
|
1927
|
+
pathParams: {
|
1928
|
+
workspace,
|
1929
|
+
region,
|
1930
|
+
dbBranchName: `${database}:${branch}`,
|
1931
|
+
tableName: table,
|
1932
|
+
recordId: record,
|
1933
|
+
columnName: column,
|
1934
|
+
fileId
|
1935
|
+
},
|
1936
|
+
...this.extraProps
|
1937
|
+
});
|
1938
|
+
}
|
1939
|
+
getFile({
|
1940
|
+
workspace,
|
1941
|
+
region,
|
1942
|
+
database,
|
1943
|
+
branch,
|
1944
|
+
table,
|
1945
|
+
record,
|
1946
|
+
column
|
1947
|
+
}) {
|
1948
|
+
return operationsByTag.files.getFile({
|
1949
|
+
pathParams: {
|
1950
|
+
workspace,
|
1951
|
+
region,
|
1952
|
+
dbBranchName: `${database}:${branch}`,
|
1953
|
+
tableName: table,
|
1954
|
+
recordId: record,
|
1955
|
+
columnName: column
|
1956
|
+
},
|
1957
|
+
...this.extraProps
|
1958
|
+
});
|
1959
|
+
}
|
1960
|
+
putFile({
|
1961
|
+
workspace,
|
1962
|
+
region,
|
1963
|
+
database,
|
1964
|
+
branch,
|
1965
|
+
table,
|
1966
|
+
record,
|
1967
|
+
column,
|
1968
|
+
file
|
1969
|
+
}) {
|
1970
|
+
return operationsByTag.files.putFile({
|
1971
|
+
pathParams: {
|
1972
|
+
workspace,
|
1973
|
+
region,
|
1974
|
+
dbBranchName: `${database}:${branch}`,
|
1975
|
+
tableName: table,
|
1976
|
+
recordId: record,
|
1977
|
+
columnName: column
|
1978
|
+
},
|
1979
|
+
body: file,
|
1980
|
+
...this.extraProps
|
1981
|
+
});
|
1982
|
+
}
|
1983
|
+
deleteFile({
|
1984
|
+
workspace,
|
1985
|
+
region,
|
1986
|
+
database,
|
1987
|
+
branch,
|
1988
|
+
table,
|
1989
|
+
record,
|
1990
|
+
column
|
1991
|
+
}) {
|
1992
|
+
return operationsByTag.files.deleteFile({
|
1993
|
+
pathParams: {
|
1994
|
+
workspace,
|
1995
|
+
region,
|
1996
|
+
dbBranchName: `${database}:${branch}`,
|
1997
|
+
tableName: table,
|
1998
|
+
recordId: record,
|
1999
|
+
columnName: column
|
2000
|
+
},
|
2001
|
+
...this.extraProps
|
2002
|
+
});
|
2003
|
+
}
|
2004
|
+
fileAccess({
|
2005
|
+
workspace,
|
2006
|
+
region,
|
2007
|
+
fileId,
|
2008
|
+
verify
|
2009
|
+
}) {
|
2010
|
+
return operationsByTag.files.fileAccess({
|
2011
|
+
pathParams: {
|
2012
|
+
workspace,
|
2013
|
+
region,
|
2014
|
+
fileId
|
2015
|
+
},
|
2016
|
+
queryParams: { verify },
|
2017
|
+
...this.extraProps
|
2018
|
+
});
|
2019
|
+
}
|
2020
|
+
}
|
1504
2021
|
class SearchAndFilterApi {
|
1505
2022
|
constructor(extraProps) {
|
1506
2023
|
this.extraProps = extraProps;
|
@@ -1560,6 +2077,38 @@ class SearchAndFilterApi {
|
|
1560
2077
|
...this.extraProps
|
1561
2078
|
});
|
1562
2079
|
}
|
2080
|
+
vectorSearchTable({
|
2081
|
+
workspace,
|
2082
|
+
region,
|
2083
|
+
database,
|
2084
|
+
branch,
|
2085
|
+
table,
|
2086
|
+
queryVector,
|
2087
|
+
column,
|
2088
|
+
similarityFunction,
|
2089
|
+
size,
|
2090
|
+
filter
|
2091
|
+
}) {
|
2092
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2093
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2094
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2095
|
+
...this.extraProps
|
2096
|
+
});
|
2097
|
+
}
|
2098
|
+
askTable({
|
2099
|
+
workspace,
|
2100
|
+
region,
|
2101
|
+
database,
|
2102
|
+
branch,
|
2103
|
+
table,
|
2104
|
+
options
|
2105
|
+
}) {
|
2106
|
+
return operationsByTag.searchAndFilter.askTable({
|
2107
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2108
|
+
body: { ...options },
|
2109
|
+
...this.extraProps
|
2110
|
+
});
|
2111
|
+
}
|
1563
2112
|
summarizeTable({
|
1564
2113
|
workspace,
|
1565
2114
|
region,
|
@@ -1760,11 +2309,13 @@ class MigrationsApi {
|
|
1760
2309
|
region,
|
1761
2310
|
database,
|
1762
2311
|
branch,
|
1763
|
-
schema
|
2312
|
+
schema,
|
2313
|
+
schemaOperations,
|
2314
|
+
branchOperations
|
1764
2315
|
}) {
|
1765
2316
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1766
2317
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1767
|
-
body: { schema },
|
2318
|
+
body: { schema, schemaOperations, branchOperations },
|
1768
2319
|
...this.extraProps
|
1769
2320
|
});
|
1770
2321
|
}
|
@@ -1774,11 +2325,12 @@ class MigrationsApi {
|
|
1774
2325
|
database,
|
1775
2326
|
branch,
|
1776
2327
|
compare,
|
1777
|
-
|
2328
|
+
sourceBranchOperations,
|
2329
|
+
targetBranchOperations
|
1778
2330
|
}) {
|
1779
2331
|
return operationsByTag.migrations.compareBranchSchemas({
|
1780
2332
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1781
|
-
body: {
|
2333
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1782
2334
|
...this.extraProps
|
1783
2335
|
});
|
1784
2336
|
}
|
@@ -1821,6 +2373,19 @@ class MigrationsApi {
|
|
1821
2373
|
...this.extraProps
|
1822
2374
|
});
|
1823
2375
|
}
|
2376
|
+
pushBranchMigrations({
|
2377
|
+
workspace,
|
2378
|
+
region,
|
2379
|
+
database,
|
2380
|
+
branch,
|
2381
|
+
migrations
|
2382
|
+
}) {
|
2383
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2384
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2385
|
+
body: { migrations },
|
2386
|
+
...this.extraProps
|
2387
|
+
});
|
2388
|
+
}
|
1824
2389
|
}
|
1825
2390
|
class DatabaseApi {
|
1826
2391
|
constructor(extraProps) {
|
@@ -1872,6 +2437,46 @@ class DatabaseApi {
|
|
1872
2437
|
...this.extraProps
|
1873
2438
|
});
|
1874
2439
|
}
|
2440
|
+
renameDatabase({
|
2441
|
+
workspace,
|
2442
|
+
database,
|
2443
|
+
newName
|
2444
|
+
}) {
|
2445
|
+
return operationsByTag.databases.renameDatabase({
|
2446
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2447
|
+
body: { newName },
|
2448
|
+
...this.extraProps
|
2449
|
+
});
|
2450
|
+
}
|
2451
|
+
getDatabaseGithubSettings({
|
2452
|
+
workspace,
|
2453
|
+
database
|
2454
|
+
}) {
|
2455
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2456
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2457
|
+
...this.extraProps
|
2458
|
+
});
|
2459
|
+
}
|
2460
|
+
updateDatabaseGithubSettings({
|
2461
|
+
workspace,
|
2462
|
+
database,
|
2463
|
+
settings
|
2464
|
+
}) {
|
2465
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2466
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2467
|
+
body: settings,
|
2468
|
+
...this.extraProps
|
2469
|
+
});
|
2470
|
+
}
|
2471
|
+
deleteDatabaseGithubSettings({
|
2472
|
+
workspace,
|
2473
|
+
database
|
2474
|
+
}) {
|
2475
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2476
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2477
|
+
...this.extraProps
|
2478
|
+
});
|
2479
|
+
}
|
1875
2480
|
listRegions({ workspace }) {
|
1876
2481
|
return operationsByTag.databases.listRegions({
|
1877
2482
|
pathParams: { workspaceId: workspace },
|
@@ -1881,9 +2486,8 @@ class DatabaseApi {
|
|
1881
2486
|
}
|
1882
2487
|
|
1883
2488
|
class XataApiPlugin {
|
1884
|
-
|
1885
|
-
|
1886
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2489
|
+
build(options) {
|
2490
|
+
return new XataApiClient(options);
|
1887
2491
|
}
|
1888
2492
|
}
|
1889
2493
|
|
@@ -1923,18 +2527,46 @@ class Page {
|
|
1923
2527
|
this.meta = meta;
|
1924
2528
|
this.records = new RecordArray(this, records);
|
1925
2529
|
}
|
2530
|
+
/**
|
2531
|
+
* Retrieves the next page of results.
|
2532
|
+
* @param size Maximum number of results to be retrieved.
|
2533
|
+
* @param offset Number of results to skip when retrieving the results.
|
2534
|
+
* @returns The next page or results.
|
2535
|
+
*/
|
1926
2536
|
async nextPage(size, offset) {
|
1927
2537
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1928
2538
|
}
|
2539
|
+
/**
|
2540
|
+
* Retrieves the previous page of results.
|
2541
|
+
* @param size Maximum number of results to be retrieved.
|
2542
|
+
* @param offset Number of results to skip when retrieving the results.
|
2543
|
+
* @returns The previous page or results.
|
2544
|
+
*/
|
1929
2545
|
async previousPage(size, offset) {
|
1930
2546
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1931
2547
|
}
|
2548
|
+
/**
|
2549
|
+
* Retrieves the start page of results.
|
2550
|
+
* @param size Maximum number of results to be retrieved.
|
2551
|
+
* @param offset Number of results to skip when retrieving the results.
|
2552
|
+
* @returns The start page or results.
|
2553
|
+
*/
|
1932
2554
|
async startPage(size, offset) {
|
1933
2555
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1934
2556
|
}
|
2557
|
+
/**
|
2558
|
+
* Retrieves the end page of results.
|
2559
|
+
* @param size Maximum number of results to be retrieved.
|
2560
|
+
* @param offset Number of results to skip when retrieving the results.
|
2561
|
+
* @returns The end page or results.
|
2562
|
+
*/
|
1935
2563
|
async endPage(size, offset) {
|
1936
2564
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1937
2565
|
}
|
2566
|
+
/**
|
2567
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2568
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2569
|
+
*/
|
1938
2570
|
hasNextPage() {
|
1939
2571
|
return this.meta.page.more;
|
1940
2572
|
}
|
@@ -1966,25 +2598,54 @@ const _RecordArray = class extends Array {
|
|
1966
2598
|
toArray() {
|
1967
2599
|
return new Array(...this);
|
1968
2600
|
}
|
2601
|
+
toSerializable() {
|
2602
|
+
return JSON.parse(this.toString());
|
2603
|
+
}
|
2604
|
+
toString() {
|
2605
|
+
return JSON.stringify(this.toArray());
|
2606
|
+
}
|
1969
2607
|
map(callbackfn, thisArg) {
|
1970
2608
|
return this.toArray().map(callbackfn, thisArg);
|
1971
2609
|
}
|
2610
|
+
/**
|
2611
|
+
* Retrieve next page of records
|
2612
|
+
*
|
2613
|
+
* @returns A new array of objects
|
2614
|
+
*/
|
1972
2615
|
async nextPage(size, offset) {
|
1973
2616
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1974
2617
|
return new _RecordArray(newPage);
|
1975
2618
|
}
|
2619
|
+
/**
|
2620
|
+
* Retrieve previous page of records
|
2621
|
+
*
|
2622
|
+
* @returns A new array of objects
|
2623
|
+
*/
|
1976
2624
|
async previousPage(size, offset) {
|
1977
2625
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1978
2626
|
return new _RecordArray(newPage);
|
1979
2627
|
}
|
2628
|
+
/**
|
2629
|
+
* Retrieve start page of records
|
2630
|
+
*
|
2631
|
+
* @returns A new array of objects
|
2632
|
+
*/
|
1980
2633
|
async startPage(size, offset) {
|
1981
2634
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1982
2635
|
return new _RecordArray(newPage);
|
1983
2636
|
}
|
2637
|
+
/**
|
2638
|
+
* Retrieve end page of records
|
2639
|
+
*
|
2640
|
+
* @returns A new array of objects
|
2641
|
+
*/
|
1984
2642
|
async endPage(size, offset) {
|
1985
2643
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1986
2644
|
return new _RecordArray(newPage);
|
1987
2645
|
}
|
2646
|
+
/**
|
2647
|
+
* @returns Boolean indicating if there is a next page
|
2648
|
+
*/
|
1988
2649
|
hasNextPage() {
|
1989
2650
|
return __privateGet$6(this, _page).meta.page.more;
|
1990
2651
|
}
|
@@ -2021,7 +2682,8 @@ const _Query = class {
|
|
2021
2682
|
__privateAdd$5(this, _table$1, void 0);
|
2022
2683
|
__privateAdd$5(this, _repository, void 0);
|
2023
2684
|
__privateAdd$5(this, _data, { filter: {} });
|
2024
|
-
|
2685
|
+
// Implements pagination
|
2686
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
2025
2687
|
this.records = new RecordArray(this, []);
|
2026
2688
|
__privateSet$5(this, _table$1, table);
|
2027
2689
|
if (repository) {
|
@@ -2058,18 +2720,38 @@ const _Query = class {
|
|
2058
2720
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2059
2721
|
return toBase64(key);
|
2060
2722
|
}
|
2723
|
+
/**
|
2724
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
2725
|
+
* @param queries An array of subqueries.
|
2726
|
+
* @returns A new Query object.
|
2727
|
+
*/
|
2061
2728
|
any(...queries) {
|
2062
2729
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2063
2730
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2064
2731
|
}
|
2732
|
+
/**
|
2733
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
2734
|
+
* @param queries An array of subqueries.
|
2735
|
+
* @returns A new Query object.
|
2736
|
+
*/
|
2065
2737
|
all(...queries) {
|
2066
2738
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2067
2739
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2068
2740
|
}
|
2741
|
+
/**
|
2742
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
2743
|
+
* @param queries An array of subqueries.
|
2744
|
+
* @returns A new Query object.
|
2745
|
+
*/
|
2069
2746
|
not(...queries) {
|
2070
2747
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2071
2748
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2072
2749
|
}
|
2750
|
+
/**
|
2751
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
2752
|
+
* @param queries An array of subqueries.
|
2753
|
+
* @returns A new Query object.
|
2754
|
+
*/
|
2073
2755
|
none(...queries) {
|
2074
2756
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2075
2757
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2092,6 +2774,11 @@ const _Query = class {
|
|
2092
2774
|
const sort = [...originalSort, { column, direction }];
|
2093
2775
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2094
2776
|
}
|
2777
|
+
/**
|
2778
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
2779
|
+
* @param columns Array of column names to be returned by the query.
|
2780
|
+
* @returns A new Query object.
|
2781
|
+
*/
|
2095
2782
|
select(columns) {
|
2096
2783
|
return new _Query(
|
2097
2784
|
__privateGet$5(this, _repository),
|
@@ -2104,6 +2791,12 @@ const _Query = class {
|
|
2104
2791
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2105
2792
|
return __privateGet$5(this, _repository).query(query);
|
2106
2793
|
}
|
2794
|
+
/**
|
2795
|
+
* Get results in an iterator
|
2796
|
+
*
|
2797
|
+
* @async
|
2798
|
+
* @returns Async interable of results
|
2799
|
+
*/
|
2107
2800
|
async *[Symbol.asyncIterator]() {
|
2108
2801
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2109
2802
|
yield record;
|
@@ -2164,21 +2857,49 @@ const _Query = class {
|
|
2164
2857
|
);
|
2165
2858
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2166
2859
|
}
|
2860
|
+
/**
|
2861
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
2862
|
+
* @param ttl The cache TTL in milliseconds.
|
2863
|
+
* @returns A new Query object.
|
2864
|
+
*/
|
2167
2865
|
cache(ttl) {
|
2168
2866
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2169
2867
|
}
|
2868
|
+
/**
|
2869
|
+
* Retrieve next page of records
|
2870
|
+
*
|
2871
|
+
* @returns A new page object.
|
2872
|
+
*/
|
2170
2873
|
nextPage(size, offset) {
|
2171
2874
|
return this.startPage(size, offset);
|
2172
2875
|
}
|
2876
|
+
/**
|
2877
|
+
* Retrieve previous page of records
|
2878
|
+
*
|
2879
|
+
* @returns A new page object
|
2880
|
+
*/
|
2173
2881
|
previousPage(size, offset) {
|
2174
2882
|
return this.startPage(size, offset);
|
2175
2883
|
}
|
2884
|
+
/**
|
2885
|
+
* Retrieve start page of records
|
2886
|
+
*
|
2887
|
+
* @returns A new page object
|
2888
|
+
*/
|
2176
2889
|
startPage(size, offset) {
|
2177
2890
|
return this.getPaginated({ pagination: { size, offset } });
|
2178
2891
|
}
|
2892
|
+
/**
|
2893
|
+
* Retrieve last page of records
|
2894
|
+
*
|
2895
|
+
* @returns A new page object
|
2896
|
+
*/
|
2179
2897
|
endPage(size, offset) {
|
2180
2898
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2181
2899
|
}
|
2900
|
+
/**
|
2901
|
+
* @returns Boolean indicating if there is a next page
|
2902
|
+
*/
|
2182
2903
|
hasNextPage() {
|
2183
2904
|
return this.meta.page.more;
|
2184
2905
|
}
|
@@ -2218,7 +2939,11 @@ function isSortFilterString(value) {
|
|
2218
2939
|
return isString(value);
|
2219
2940
|
}
|
2220
2941
|
function isSortFilterBase(filter) {
|
2221
|
-
return isObject(filter) && Object.
|
2942
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
2943
|
+
if (key === "*")
|
2944
|
+
return value === "random";
|
2945
|
+
return value === "asc" || value === "desc";
|
2946
|
+
});
|
2222
2947
|
}
|
2223
2948
|
function isSortFilterObject(filter) {
|
2224
2949
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2291,10 +3016,7 @@ class RestRepository extends Query {
|
|
2291
3016
|
__privateSet$4(this, _db, options.db);
|
2292
3017
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2293
3018
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2294
|
-
__privateSet$4(this, _getFetchProps,
|
2295
|
-
const props = await options.pluginOptions.getFetchProps();
|
2296
|
-
return { ...props, sessionID: generateUUID() };
|
2297
|
-
});
|
3019
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2298
3020
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2299
3021
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2300
3022
|
return trace(name, fn, {
|
@@ -2351,7 +3073,6 @@ class RestRepository extends Query {
|
|
2351
3073
|
}
|
2352
3074
|
const id = extractId(a);
|
2353
3075
|
if (id) {
|
2354
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2355
3076
|
try {
|
2356
3077
|
const response = await getRecord({
|
2357
3078
|
pathParams: {
|
@@ -2362,7 +3083,7 @@ class RestRepository extends Query {
|
|
2362
3083
|
recordId: id
|
2363
3084
|
},
|
2364
3085
|
queryParams: { columns },
|
2365
|
-
...
|
3086
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2366
3087
|
});
|
2367
3088
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2368
3089
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2462,12 +3183,22 @@ class RestRepository extends Query {
|
|
2462
3183
|
return result;
|
2463
3184
|
}
|
2464
3185
|
if (isString(a) && isObject(b)) {
|
3186
|
+
if (a === "")
|
3187
|
+
throw new Error("The id can't be empty");
|
2465
3188
|
const columns = isStringArray(c) ? c : void 0;
|
2466
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3189
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2467
3190
|
}
|
2468
3191
|
if (isObject(a) && isString(a.id)) {
|
3192
|
+
if (a.id === "")
|
3193
|
+
throw new Error("The id can't be empty");
|
2469
3194
|
const columns = isStringArray(c) ? c : void 0;
|
2470
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3195
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3196
|
+
}
|
3197
|
+
if (!isDefined(a) && isObject(b)) {
|
3198
|
+
return await this.create(b, c);
|
3199
|
+
}
|
3200
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3201
|
+
return await this.create(a, b);
|
2471
3202
|
}
|
2472
3203
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2473
3204
|
});
|
@@ -2484,12 +3215,22 @@ class RestRepository extends Query {
|
|
2484
3215
|
return result;
|
2485
3216
|
}
|
2486
3217
|
if (isString(a) && isObject(b)) {
|
3218
|
+
if (a === "")
|
3219
|
+
throw new Error("The id can't be empty");
|
2487
3220
|
const columns = isStringArray(c) ? c : void 0;
|
2488
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3221
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2489
3222
|
}
|
2490
3223
|
if (isObject(a) && isString(a.id)) {
|
3224
|
+
if (a.id === "")
|
3225
|
+
throw new Error("The id can't be empty");
|
2491
3226
|
const columns = isStringArray(c) ? c : void 0;
|
2492
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3227
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3228
|
+
}
|
3229
|
+
if (!isDefined(a) && isObject(b)) {
|
3230
|
+
return await this.create(b, c);
|
3231
|
+
}
|
3232
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3233
|
+
return await this.create(a, b);
|
2493
3234
|
}
|
2494
3235
|
throw new Error("Invalid arguments for createOrReplace method");
|
2495
3236
|
});
|
@@ -2540,7 +3281,6 @@ class RestRepository extends Query {
|
|
2540
3281
|
}
|
2541
3282
|
async search(query, options = {}) {
|
2542
3283
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2543
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2544
3284
|
const { records } = await searchTable({
|
2545
3285
|
pathParams: {
|
2546
3286
|
workspace: "{workspaceId}",
|
@@ -2558,7 +3298,29 @@ class RestRepository extends Query {
|
|
2558
3298
|
page: options.page,
|
2559
3299
|
target: options.target
|
2560
3300
|
},
|
2561
|
-
...
|
3301
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3302
|
+
});
|
3303
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3304
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3305
|
+
});
|
3306
|
+
}
|
3307
|
+
async vectorSearch(column, query, options) {
|
3308
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3309
|
+
const { records } = await vectorSearchTable({
|
3310
|
+
pathParams: {
|
3311
|
+
workspace: "{workspaceId}",
|
3312
|
+
dbBranchName: "{dbBranch}",
|
3313
|
+
region: "{region}",
|
3314
|
+
tableName: __privateGet$4(this, _table)
|
3315
|
+
},
|
3316
|
+
body: {
|
3317
|
+
column,
|
3318
|
+
queryVector: query,
|
3319
|
+
similarityFunction: options?.similarityFunction,
|
3320
|
+
size: options?.size,
|
3321
|
+
filter: options?.filter
|
3322
|
+
},
|
3323
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2562
3324
|
});
|
2563
3325
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2564
3326
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2566,7 +3328,6 @@ class RestRepository extends Query {
|
|
2566
3328
|
}
|
2567
3329
|
async aggregate(aggs, filter) {
|
2568
3330
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2569
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2570
3331
|
const result = await aggregateTable({
|
2571
3332
|
pathParams: {
|
2572
3333
|
workspace: "{workspaceId}",
|
@@ -2575,7 +3336,7 @@ class RestRepository extends Query {
|
|
2575
3336
|
tableName: __privateGet$4(this, _table)
|
2576
3337
|
},
|
2577
3338
|
body: { aggs, filter },
|
2578
|
-
...
|
3339
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2579
3340
|
});
|
2580
3341
|
return result;
|
2581
3342
|
});
|
@@ -2586,7 +3347,6 @@ class RestRepository extends Query {
|
|
2586
3347
|
if (cacheQuery)
|
2587
3348
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2588
3349
|
const data = query.getQueryOptions();
|
2589
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2590
3350
|
const { meta, records: objects } = await queryTable({
|
2591
3351
|
pathParams: {
|
2592
3352
|
workspace: "{workspaceId}",
|
@@ -2602,7 +3362,7 @@ class RestRepository extends Query {
|
|
2602
3362
|
consistency: data.consistency
|
2603
3363
|
},
|
2604
3364
|
fetchOptions: data.fetchOptions,
|
2605
|
-
...
|
3365
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2606
3366
|
});
|
2607
3367
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2608
3368
|
const records = objects.map(
|
@@ -2615,7 +3375,6 @@ class RestRepository extends Query {
|
|
2615
3375
|
async summarizeTable(query, summaries, summariesFilter) {
|
2616
3376
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2617
3377
|
const data = query.getQueryOptions();
|
2618
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2619
3378
|
const result = await summarizeTable({
|
2620
3379
|
pathParams: {
|
2621
3380
|
workspace: "{workspaceId}",
|
@@ -2632,11 +3391,39 @@ class RestRepository extends Query {
|
|
2632
3391
|
summaries,
|
2633
3392
|
summariesFilter
|
2634
3393
|
},
|
2635
|
-
...
|
3394
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2636
3395
|
});
|
2637
3396
|
return result;
|
2638
3397
|
});
|
2639
3398
|
}
|
3399
|
+
ask(question, options) {
|
3400
|
+
const params = {
|
3401
|
+
pathParams: {
|
3402
|
+
workspace: "{workspaceId}",
|
3403
|
+
dbBranchName: "{dbBranch}",
|
3404
|
+
region: "{region}",
|
3405
|
+
tableName: __privateGet$4(this, _table)
|
3406
|
+
},
|
3407
|
+
body: {
|
3408
|
+
question,
|
3409
|
+
...options
|
3410
|
+
},
|
3411
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3412
|
+
};
|
3413
|
+
if (options?.onMessage) {
|
3414
|
+
fetchSSERequest({
|
3415
|
+
endpoint: "dataPlane",
|
3416
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3417
|
+
method: "POST",
|
3418
|
+
onMessage: (message) => {
|
3419
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3420
|
+
},
|
3421
|
+
...params
|
3422
|
+
});
|
3423
|
+
} else {
|
3424
|
+
return askTable(params);
|
3425
|
+
}
|
3426
|
+
}
|
2640
3427
|
}
|
2641
3428
|
_table = new WeakMap();
|
2642
3429
|
_getFetchProps = new WeakMap();
|
@@ -2646,7 +3433,6 @@ _schemaTables$2 = new WeakMap();
|
|
2646
3433
|
_trace = new WeakMap();
|
2647
3434
|
_insertRecordWithoutId = new WeakSet();
|
2648
3435
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2649
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2650
3436
|
const record = transformObjectLinks(object);
|
2651
3437
|
const response = await insertRecord({
|
2652
3438
|
pathParams: {
|
@@ -2657,14 +3443,15 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2657
3443
|
},
|
2658
3444
|
queryParams: { columns },
|
2659
3445
|
body: record,
|
2660
|
-
...
|
3446
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2661
3447
|
});
|
2662
3448
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2663
3449
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2664
3450
|
};
|
2665
3451
|
_insertRecordWithId = new WeakSet();
|
2666
3452
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2667
|
-
|
3453
|
+
if (!recordId)
|
3454
|
+
return null;
|
2668
3455
|
const record = transformObjectLinks(object);
|
2669
3456
|
const response = await insertRecordWithID({
|
2670
3457
|
pathParams: {
|
@@ -2676,14 +3463,13 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2676
3463
|
},
|
2677
3464
|
body: record,
|
2678
3465
|
queryParams: { createOnly, columns, ifVersion },
|
2679
|
-
...
|
3466
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2680
3467
|
});
|
2681
3468
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2682
3469
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2683
3470
|
};
|
2684
3471
|
_insertRecords = new WeakSet();
|
2685
3472
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2686
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2687
3473
|
const chunkedOperations = chunk(
|
2688
3474
|
objects.map((object) => ({
|
2689
3475
|
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
@@ -2699,7 +3485,7 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2699
3485
|
region: "{region}"
|
2700
3486
|
},
|
2701
3487
|
body: { operations },
|
2702
|
-
...
|
3488
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2703
3489
|
});
|
2704
3490
|
for (const result of results) {
|
2705
3491
|
if (result.operation === "insert") {
|
@@ -2713,7 +3499,8 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2713
3499
|
};
|
2714
3500
|
_updateRecordWithID = new WeakSet();
|
2715
3501
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2716
|
-
|
3502
|
+
if (!recordId)
|
3503
|
+
return null;
|
2717
3504
|
const { id: _id, ...record } = transformObjectLinks(object);
|
2718
3505
|
try {
|
2719
3506
|
const response = await updateRecordWithID({
|
@@ -2726,7 +3513,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2726
3513
|
},
|
2727
3514
|
queryParams: { columns, ifVersion },
|
2728
3515
|
body: record,
|
2729
|
-
...
|
3516
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2730
3517
|
});
|
2731
3518
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2732
3519
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2739,7 +3526,6 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2739
3526
|
};
|
2740
3527
|
_updateRecords = new WeakSet();
|
2741
3528
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2742
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2743
3529
|
const chunkedOperations = chunk(
|
2744
3530
|
objects.map(({ id, ...object }) => ({
|
2745
3531
|
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
@@ -2755,7 +3541,7 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2755
3541
|
region: "{region}"
|
2756
3542
|
},
|
2757
3543
|
body: { operations },
|
2758
|
-
...
|
3544
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2759
3545
|
});
|
2760
3546
|
for (const result of results) {
|
2761
3547
|
if (result.operation === "update") {
|
@@ -2769,7 +3555,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2769
3555
|
};
|
2770
3556
|
_upsertRecordWithID = new WeakSet();
|
2771
3557
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2772
|
-
|
3558
|
+
if (!recordId)
|
3559
|
+
return null;
|
2773
3560
|
const response = await upsertRecordWithID({
|
2774
3561
|
pathParams: {
|
2775
3562
|
workspace: "{workspaceId}",
|
@@ -2780,14 +3567,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2780
3567
|
},
|
2781
3568
|
queryParams: { columns, ifVersion },
|
2782
3569
|
body: object,
|
2783
|
-
...
|
3570
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2784
3571
|
});
|
2785
3572
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2786
3573
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2787
3574
|
};
|
2788
3575
|
_deleteRecord = new WeakSet();
|
2789
3576
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2790
|
-
|
3577
|
+
if (!recordId)
|
3578
|
+
return null;
|
2791
3579
|
try {
|
2792
3580
|
const response = await deleteRecord({
|
2793
3581
|
pathParams: {
|
@@ -2798,7 +3586,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2798
3586
|
recordId
|
2799
3587
|
},
|
2800
3588
|
queryParams: { columns },
|
2801
|
-
...
|
3589
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2802
3590
|
});
|
2803
3591
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2804
3592
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2811,9 +3599,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2811
3599
|
};
|
2812
3600
|
_deleteRecords = new WeakSet();
|
2813
3601
|
deleteRecords_fn = async function(recordIds) {
|
2814
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2815
3602
|
const chunkedOperations = chunk(
|
2816
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3603
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2817
3604
|
BULK_OPERATION_MAX_SIZE
|
2818
3605
|
);
|
2819
3606
|
for (const operations of chunkedOperations) {
|
@@ -2824,21 +3611,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2824
3611
|
region: "{region}"
|
2825
3612
|
},
|
2826
3613
|
body: { operations },
|
2827
|
-
...
|
3614
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2828
3615
|
});
|
2829
3616
|
}
|
2830
3617
|
};
|
2831
3618
|
_setCacheQuery = new WeakSet();
|
2832
3619
|
setCacheQuery_fn = async function(query, meta, records) {
|
2833
|
-
await __privateGet$4(this, _cache)
|
3620
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2834
3621
|
};
|
2835
3622
|
_getCacheQuery = new WeakSet();
|
2836
3623
|
getCacheQuery_fn = async function(query) {
|
2837
3624
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2838
|
-
const result = await __privateGet$4(this, _cache)
|
3625
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2839
3626
|
if (!result)
|
2840
3627
|
return null;
|
2841
|
-
const
|
3628
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3629
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2842
3630
|
if (ttl < 0)
|
2843
3631
|
return null;
|
2844
3632
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2848,10 +3636,9 @@ _getSchemaTables$1 = new WeakSet();
|
|
2848
3636
|
getSchemaTables_fn$1 = async function() {
|
2849
3637
|
if (__privateGet$4(this, _schemaTables$2))
|
2850
3638
|
return __privateGet$4(this, _schemaTables$2);
|
2851
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2852
3639
|
const { schema } = await getBranchDetails({
|
2853
3640
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2854
|
-
...
|
3641
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2855
3642
|
});
|
2856
3643
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2857
3644
|
return schema.tables;
|
@@ -2914,6 +3701,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2914
3701
|
}
|
2915
3702
|
}
|
2916
3703
|
const record = { ...data };
|
3704
|
+
const serializable = { xata, ...transformObjectLinks(data) };
|
3705
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2917
3706
|
record.read = function(columns2) {
|
2918
3707
|
return db[table].read(record["id"], columns2);
|
2919
3708
|
};
|
@@ -2930,10 +3719,17 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2930
3719
|
record.delete = function() {
|
2931
3720
|
return db[table].delete(record["id"]);
|
2932
3721
|
};
|
3722
|
+
record.xata = Object.freeze(metadata);
|
2933
3723
|
record.getMetadata = function() {
|
2934
|
-
return xata;
|
3724
|
+
return record.xata;
|
3725
|
+
};
|
3726
|
+
record.toSerializable = function() {
|
3727
|
+
return JSON.parse(JSON.stringify(serializable));
|
3728
|
+
};
|
3729
|
+
record.toString = function() {
|
3730
|
+
return JSON.stringify(transformObjectLinks(serializable));
|
2935
3731
|
};
|
2936
|
-
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
3732
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2937
3733
|
Object.defineProperty(record, prop, { enumerable: false });
|
2938
3734
|
}
|
2939
3735
|
Object.freeze(record);
|
@@ -3121,19 +3917,19 @@ class SearchPlugin extends XataPlugin {
|
|
3121
3917
|
__privateAdd$1(this, _schemaTables, void 0);
|
3122
3918
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3123
3919
|
}
|
3124
|
-
build(
|
3920
|
+
build(pluginOptions) {
|
3125
3921
|
return {
|
3126
3922
|
all: async (query, options = {}) => {
|
3127
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3128
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3923
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3924
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3129
3925
|
return records.map((record) => {
|
3130
3926
|
const { table = "orphan" } = record.xata;
|
3131
3927
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3132
3928
|
});
|
3133
3929
|
},
|
3134
3930
|
byTable: async (query, options = {}) => {
|
3135
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3136
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3931
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3932
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3137
3933
|
return records.reduce((acc, record) => {
|
3138
3934
|
const { table = "orphan" } = record.xata;
|
3139
3935
|
const items = acc[table] ?? [];
|
@@ -3146,38 +3942,36 @@ class SearchPlugin extends XataPlugin {
|
|
3146
3942
|
}
|
3147
3943
|
_schemaTables = new WeakMap();
|
3148
3944
|
_search = new WeakSet();
|
3149
|
-
search_fn = async function(query, options,
|
3150
|
-
const fetchProps = await getFetchProps();
|
3945
|
+
search_fn = async function(query, options, pluginOptions) {
|
3151
3946
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3152
3947
|
const { records } = await searchBranch({
|
3153
3948
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3949
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3154
3950
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3155
|
-
...
|
3951
|
+
...pluginOptions
|
3156
3952
|
});
|
3157
3953
|
return records;
|
3158
3954
|
};
|
3159
3955
|
_getSchemaTables = new WeakSet();
|
3160
|
-
getSchemaTables_fn = async function(
|
3956
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3161
3957
|
if (__privateGet$1(this, _schemaTables))
|
3162
3958
|
return __privateGet$1(this, _schemaTables);
|
3163
|
-
const fetchProps = await getFetchProps();
|
3164
3959
|
const { schema } = await getBranchDetails({
|
3165
3960
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3166
|
-
...
|
3961
|
+
...pluginOptions
|
3167
3962
|
});
|
3168
3963
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3169
3964
|
return schema.tables;
|
3170
3965
|
};
|
3171
3966
|
|
3172
3967
|
class TransactionPlugin extends XataPlugin {
|
3173
|
-
build(
|
3968
|
+
build(pluginOptions) {
|
3174
3969
|
return {
|
3175
3970
|
run: async (operations) => {
|
3176
|
-
const fetchProps = await getFetchProps();
|
3177
3971
|
const response = await branchTransaction({
|
3178
3972
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3179
3973
|
body: { operations },
|
3180
|
-
...
|
3974
|
+
...pluginOptions
|
3181
3975
|
});
|
3182
3976
|
return response;
|
3183
3977
|
}
|
@@ -3185,90 +3979,6 @@ class TransactionPlugin extends XataPlugin {
|
|
3185
3979
|
}
|
3186
3980
|
}
|
3187
3981
|
|
3188
|
-
const isBranchStrategyBuilder = (strategy) => {
|
3189
|
-
return typeof strategy === "function";
|
3190
|
-
};
|
3191
|
-
|
3192
|
-
async function getCurrentBranchName(options) {
|
3193
|
-
const { branch, envBranch } = getEnvironment();
|
3194
|
-
if (branch)
|
3195
|
-
return branch;
|
3196
|
-
const gitBranch = envBranch || await getGitBranch();
|
3197
|
-
return resolveXataBranch(gitBranch, options);
|
3198
|
-
}
|
3199
|
-
async function getCurrentBranchDetails(options) {
|
3200
|
-
const branch = await getCurrentBranchName(options);
|
3201
|
-
return getDatabaseBranch(branch, options);
|
3202
|
-
}
|
3203
|
-
async function resolveXataBranch(gitBranch, options) {
|
3204
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3205
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3206
|
-
if (!databaseURL)
|
3207
|
-
throw new Error(
|
3208
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3209
|
-
);
|
3210
|
-
if (!apiKey)
|
3211
|
-
throw new Error(
|
3212
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3213
|
-
);
|
3214
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3215
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3216
|
-
if (!urlParts)
|
3217
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3218
|
-
const { workspace, region } = urlParts;
|
3219
|
-
const { fallbackBranch } = getEnvironment();
|
3220
|
-
const { branch } = await resolveBranch({
|
3221
|
-
apiKey,
|
3222
|
-
apiUrl: databaseURL,
|
3223
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3224
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3225
|
-
pathParams: { dbName, workspace, region },
|
3226
|
-
queryParams: { gitBranch, fallbackBranch },
|
3227
|
-
trace: defaultTrace,
|
3228
|
-
clientName: options?.clientName
|
3229
|
-
});
|
3230
|
-
return branch;
|
3231
|
-
}
|
3232
|
-
async function getDatabaseBranch(branch, options) {
|
3233
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3234
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3235
|
-
if (!databaseURL)
|
3236
|
-
throw new Error(
|
3237
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3238
|
-
);
|
3239
|
-
if (!apiKey)
|
3240
|
-
throw new Error(
|
3241
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3242
|
-
);
|
3243
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3244
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3245
|
-
if (!urlParts)
|
3246
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3247
|
-
const { workspace, region } = urlParts;
|
3248
|
-
try {
|
3249
|
-
return await getBranchDetails({
|
3250
|
-
apiKey,
|
3251
|
-
apiUrl: databaseURL,
|
3252
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3253
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3254
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3255
|
-
trace: defaultTrace
|
3256
|
-
});
|
3257
|
-
} catch (err) {
|
3258
|
-
if (isObject(err) && err.status === 404)
|
3259
|
-
return null;
|
3260
|
-
throw err;
|
3261
|
-
}
|
3262
|
-
}
|
3263
|
-
function getDatabaseURL() {
|
3264
|
-
try {
|
3265
|
-
const { databaseURL } = getEnvironment();
|
3266
|
-
return databaseURL;
|
3267
|
-
} catch (err) {
|
3268
|
-
return void 0;
|
3269
|
-
}
|
3270
|
-
}
|
3271
|
-
|
3272
3982
|
var __accessCheck = (obj, member, msg) => {
|
3273
3983
|
if (!member.has(obj))
|
3274
3984
|
throw TypeError("Cannot " + msg);
|
@@ -3292,20 +4002,18 @@ var __privateMethod = (obj, member, method) => {
|
|
3292
4002
|
return method;
|
3293
4003
|
};
|
3294
4004
|
const buildClient = (plugins) => {
|
3295
|
-
var
|
4005
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3296
4006
|
return _a = class {
|
3297
4007
|
constructor(options = {}, schemaTables) {
|
3298
4008
|
__privateAdd(this, _parseOptions);
|
3299
4009
|
__privateAdd(this, _getFetchProps);
|
3300
|
-
__privateAdd(this, _evaluateBranch);
|
3301
|
-
__privateAdd(this, _branch, void 0);
|
3302
4010
|
__privateAdd(this, _options, void 0);
|
3303
4011
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3304
4012
|
__privateSet(this, _options, safeOptions);
|
3305
4013
|
const pluginOptions = {
|
3306
|
-
|
4014
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3307
4015
|
cache: safeOptions.cache,
|
3308
|
-
|
4016
|
+
host: safeOptions.host
|
3309
4017
|
};
|
3310
4018
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3311
4019
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -3316,22 +4024,15 @@ const buildClient = (plugins) => {
|
|
3316
4024
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3317
4025
|
if (namespace === void 0)
|
3318
4026
|
continue;
|
3319
|
-
|
3320
|
-
if (result instanceof Promise) {
|
3321
|
-
void result.then((namespace2) => {
|
3322
|
-
this[key] = namespace2;
|
3323
|
-
});
|
3324
|
-
} else {
|
3325
|
-
this[key] = result;
|
3326
|
-
}
|
4027
|
+
this[key] = namespace.build(pluginOptions);
|
3327
4028
|
}
|
3328
4029
|
}
|
3329
4030
|
async getConfig() {
|
3330
4031
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3331
|
-
const branch =
|
4032
|
+
const branch = __privateGet(this, _options).branch;
|
3332
4033
|
return { databaseURL, branch };
|
3333
4034
|
}
|
3334
|
-
},
|
4035
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3335
4036
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3336
4037
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3337
4038
|
if (isBrowser && !enableBrowser) {
|
@@ -3345,60 +4046,72 @@ const buildClient = (plugins) => {
|
|
3345
4046
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3346
4047
|
const trace = options?.trace ?? defaultTrace;
|
3347
4048
|
const clientName = options?.clientName;
|
3348
|
-
const
|
3349
|
-
|
3350
|
-
databaseURL,
|
3351
|
-
fetchImpl: options?.fetch,
|
3352
|
-
clientName: options?.clientName
|
3353
|
-
});
|
4049
|
+
const host = options?.host ?? "production";
|
4050
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3354
4051
|
if (!apiKey) {
|
3355
4052
|
throw new Error("Option apiKey is required");
|
3356
4053
|
}
|
3357
4054
|
if (!databaseURL) {
|
3358
4055
|
throw new Error("Option databaseURL is required");
|
3359
4056
|
}
|
3360
|
-
|
3361
|
-
|
4057
|
+
const envBranch = getBranch();
|
4058
|
+
const previewBranch = getPreviewBranch();
|
4059
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4060
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4061
|
+
console.warn(
|
4062
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4063
|
+
);
|
4064
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4065
|
+
console.warn(
|
4066
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4067
|
+
);
|
4068
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4069
|
+
console.warn(
|
4070
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4071
|
+
);
|
4072
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4073
|
+
console.warn(
|
4074
|
+
`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.`
|
4075
|
+
);
|
4076
|
+
}
|
4077
|
+
return {
|
4078
|
+
fetch,
|
4079
|
+
databaseURL,
|
4080
|
+
apiKey,
|
4081
|
+
branch,
|
4082
|
+
cache,
|
4083
|
+
trace,
|
4084
|
+
host,
|
4085
|
+
clientID: generateUUID(),
|
4086
|
+
enableBrowser,
|
4087
|
+
clientName,
|
4088
|
+
xataAgentExtra
|
4089
|
+
};
|
4090
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3362
4091
|
fetch,
|
3363
4092
|
apiKey,
|
3364
4093
|
databaseURL,
|
3365
4094
|
branch,
|
3366
4095
|
trace,
|
3367
4096
|
clientID,
|
3368
|
-
clientName
|
4097
|
+
clientName,
|
4098
|
+
xataAgentExtra
|
3369
4099
|
}) {
|
3370
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3371
|
-
if (!branchValue)
|
3372
|
-
throw new Error("Unable to resolve branch value");
|
3373
4100
|
return {
|
3374
|
-
|
4101
|
+
fetch,
|
3375
4102
|
apiKey,
|
3376
4103
|
apiUrl: "",
|
4104
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3377
4105
|
workspacesApiUrl: (path, params) => {
|
3378
4106
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3379
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4107
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3380
4108
|
return databaseURL + newPath;
|
3381
4109
|
},
|
3382
4110
|
trace,
|
3383
4111
|
clientID,
|
3384
|
-
clientName
|
4112
|
+
clientName,
|
4113
|
+
xataAgentExtra
|
3385
4114
|
};
|
3386
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3387
|
-
if (__privateGet(this, _branch))
|
3388
|
-
return __privateGet(this, _branch);
|
3389
|
-
if (param === void 0)
|
3390
|
-
return void 0;
|
3391
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3392
|
-
const evaluateBranch = async (strategy) => {
|
3393
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3394
|
-
};
|
3395
|
-
for await (const strategy of strategies) {
|
3396
|
-
const branch = await evaluateBranch(strategy);
|
3397
|
-
if (branch) {
|
3398
|
-
__privateSet(this, _branch, branch);
|
3399
|
-
return branch;
|
3400
|
-
}
|
3401
|
-
}
|
3402
4115
|
}, _a;
|
3403
4116
|
};
|
3404
4117
|
class BaseClient extends buildClient() {
|
@@ -3493,5 +4206,5 @@ class XataError extends Error {
|
|
3493
4206
|
}
|
3494
4207
|
}
|
3495
4208
|
|
3496
|
-
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn,
|
4209
|
+
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, 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 };
|
3497
4210
|
//# sourceMappingURL=index.mjs.map
|