@xata.io/client 0.0.0-alpha.vf4e6746 → 0.0.0-alpha.vf501d195ec7907e696637eff52ae02941341dca1
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 +13 -0
- package/CHANGELOG.md +356 -0
- package/README.md +3 -269
- package/dist/index.cjs +1836 -461
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5106 -2686
- package/dist/index.mjs +1788 -454
- 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
|
}
|
@@ -17,7 +18,8 @@ const TraceAttributes = {
|
|
17
18
|
HTTP_METHOD: "http.method",
|
18
19
|
HTTP_URL: "http.url",
|
19
20
|
HTTP_ROUTE: "http.route",
|
20
|
-
HTTP_TARGET: "http.target"
|
21
|
+
HTTP_TARGET: "http.target",
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
21
23
|
};
|
22
24
|
|
23
25
|
function notEmpty(value) {
|
@@ -26,8 +28,18 @@ function notEmpty(value) {
|
|
26
28
|
function compact(arr) {
|
27
29
|
return arr.filter(notEmpty);
|
28
30
|
}
|
31
|
+
function compactObject(obj) {
|
32
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
33
|
+
}
|
34
|
+
function isBlob(value) {
|
35
|
+
try {
|
36
|
+
return value instanceof Blob;
|
37
|
+
} catch (error) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
}
|
29
41
|
function isObject(value) {
|
30
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
31
43
|
}
|
32
44
|
function isDefined(value) {
|
33
45
|
return value !== null && value !== void 0;
|
@@ -82,6 +94,27 @@ function chunk(array, chunkSize) {
|
|
82
94
|
async function timeout(ms) {
|
83
95
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
84
96
|
}
|
97
|
+
function timeoutWithCancel(ms) {
|
98
|
+
let timeoutId;
|
99
|
+
const promise = new Promise((resolve) => {
|
100
|
+
timeoutId = setTimeout(() => {
|
101
|
+
resolve();
|
102
|
+
}, ms);
|
103
|
+
});
|
104
|
+
return {
|
105
|
+
cancel: () => clearTimeout(timeoutId),
|
106
|
+
promise
|
107
|
+
};
|
108
|
+
}
|
109
|
+
function promiseMap(inputValues, mapper) {
|
110
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
111
|
+
(acc) => mapper(inputValue).then((result) => {
|
112
|
+
acc.push(result);
|
113
|
+
return acc;
|
114
|
+
})
|
115
|
+
);
|
116
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
117
|
+
}
|
85
118
|
|
86
119
|
function getEnvironment() {
|
87
120
|
try {
|
@@ -90,8 +123,10 @@ function getEnvironment() {
|
|
90
123
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
91
124
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
92
125
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
93
|
-
|
94
|
-
|
126
|
+
deployPreview: process.env.XATA_PREVIEW,
|
127
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
128
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
129
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
95
130
|
};
|
96
131
|
}
|
97
132
|
} catch (err) {
|
@@ -102,8 +137,10 @@ function getEnvironment() {
|
|
102
137
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
103
138
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
104
139
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
105
|
-
|
106
|
-
|
140
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
141
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
142
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
143
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
107
144
|
};
|
108
145
|
}
|
109
146
|
} catch (err) {
|
@@ -112,8 +149,10 @@ function getEnvironment() {
|
|
112
149
|
apiKey: getGlobalApiKey(),
|
113
150
|
databaseURL: getGlobalDatabaseURL(),
|
114
151
|
branch: getGlobalBranch(),
|
115
|
-
|
116
|
-
|
152
|
+
deployPreview: void 0,
|
153
|
+
deployPreviewBranch: void 0,
|
154
|
+
vercelGitCommitRef: void 0,
|
155
|
+
vercelGitRepoOwner: void 0
|
117
156
|
};
|
118
157
|
}
|
119
158
|
function getEnableBrowserVariable() {
|
@@ -156,39 +195,48 @@ function getGlobalBranch() {
|
|
156
195
|
return void 0;
|
157
196
|
}
|
158
197
|
}
|
159
|
-
function
|
198
|
+
function getDatabaseURL() {
|
160
199
|
try {
|
161
|
-
|
200
|
+
const { databaseURL } = getEnvironment();
|
201
|
+
return databaseURL;
|
162
202
|
} catch (err) {
|
163
203
|
return void 0;
|
164
204
|
}
|
165
205
|
}
|
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"] };
|
206
|
+
function getAPIKey() {
|
171
207
|
try {
|
172
|
-
|
173
|
-
|
174
|
-
}
|
175
|
-
const { execSync } = await import(nodeModule);
|
176
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
208
|
+
const { apiKey } = getEnvironment();
|
209
|
+
return apiKey;
|
177
210
|
} catch (err) {
|
211
|
+
return void 0;
|
178
212
|
}
|
213
|
+
}
|
214
|
+
function getBranch() {
|
179
215
|
try {
|
180
|
-
|
181
|
-
|
182
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
183
|
-
}
|
216
|
+
const { branch } = getEnvironment();
|
217
|
+
return branch;
|
184
218
|
} catch (err) {
|
219
|
+
return void 0;
|
185
220
|
}
|
186
221
|
}
|
187
|
-
|
188
|
-
|
222
|
+
function buildPreviewBranchName({ org, branch }) {
|
223
|
+
return `preview-${org}-${branch}`;
|
224
|
+
}
|
225
|
+
function getPreviewBranch() {
|
189
226
|
try {
|
190
|
-
const {
|
191
|
-
|
227
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
228
|
+
if (deployPreviewBranch)
|
229
|
+
return deployPreviewBranch;
|
230
|
+
switch (deployPreview) {
|
231
|
+
case "vercel": {
|
232
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
233
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
234
|
+
return void 0;
|
235
|
+
}
|
236
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
237
|
+
}
|
238
|
+
}
|
239
|
+
return void 0;
|
192
240
|
} catch (err) {
|
193
241
|
return void 0;
|
194
242
|
}
|
@@ -217,13 +265,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
217
265
|
return method;
|
218
266
|
};
|
219
267
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
220
269
|
function getFetchImplementation(userFetch) {
|
221
270
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
222
|
-
const
|
271
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
272
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
223
273
|
if (!fetchImpl) {
|
224
|
-
throw new Error(
|
225
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
226
|
-
);
|
274
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
227
275
|
}
|
228
276
|
return fetchImpl;
|
229
277
|
}
|
@@ -248,18 +296,22 @@ class ApiRequestPool {
|
|
248
296
|
return __privateGet$8(this, _fetch);
|
249
297
|
}
|
250
298
|
request(url, options) {
|
251
|
-
const start = new Date();
|
252
|
-
const
|
299
|
+
const start = /* @__PURE__ */ new Date();
|
300
|
+
const fetchImpl = this.getFetch();
|
253
301
|
const runRequest = async (stalled = false) => {
|
254
|
-
const
|
302
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
303
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
304
|
+
if (!response) {
|
305
|
+
throw new Error("Request timed out");
|
306
|
+
}
|
255
307
|
if (response.status === 429) {
|
256
308
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
257
309
|
await timeout(rateLimitReset * 1e3);
|
258
310
|
return await runRequest(true);
|
259
311
|
}
|
260
312
|
if (stalled) {
|
261
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
262
|
-
console.warn(`A request to Xata hit
|
313
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
314
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
263
315
|
}
|
264
316
|
return response;
|
265
317
|
};
|
@@ -294,7 +346,187 @@ enqueue_fn = function(task) {
|
|
294
346
|
return promise;
|
295
347
|
};
|
296
348
|
|
297
|
-
|
349
|
+
function generateUUID() {
|
350
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
351
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
352
|
+
return v.toString(16);
|
353
|
+
});
|
354
|
+
}
|
355
|
+
|
356
|
+
async function getBytes(stream, onChunk) {
|
357
|
+
const reader = stream.getReader();
|
358
|
+
let result;
|
359
|
+
while (!(result = await reader.read()).done) {
|
360
|
+
onChunk(result.value);
|
361
|
+
}
|
362
|
+
}
|
363
|
+
function getLines(onLine) {
|
364
|
+
let buffer;
|
365
|
+
let position;
|
366
|
+
let fieldLength;
|
367
|
+
let discardTrailingNewline = false;
|
368
|
+
return function onChunk(arr) {
|
369
|
+
if (buffer === void 0) {
|
370
|
+
buffer = arr;
|
371
|
+
position = 0;
|
372
|
+
fieldLength = -1;
|
373
|
+
} else {
|
374
|
+
buffer = concat(buffer, arr);
|
375
|
+
}
|
376
|
+
const bufLength = buffer.length;
|
377
|
+
let lineStart = 0;
|
378
|
+
while (position < bufLength) {
|
379
|
+
if (discardTrailingNewline) {
|
380
|
+
if (buffer[position] === 10 /* NewLine */) {
|
381
|
+
lineStart = ++position;
|
382
|
+
}
|
383
|
+
discardTrailingNewline = false;
|
384
|
+
}
|
385
|
+
let lineEnd = -1;
|
386
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
387
|
+
switch (buffer[position]) {
|
388
|
+
case 58 /* Colon */:
|
389
|
+
if (fieldLength === -1) {
|
390
|
+
fieldLength = position - lineStart;
|
391
|
+
}
|
392
|
+
break;
|
393
|
+
case 13 /* CarriageReturn */:
|
394
|
+
discardTrailingNewline = true;
|
395
|
+
case 10 /* NewLine */:
|
396
|
+
lineEnd = position;
|
397
|
+
break;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
if (lineEnd === -1) {
|
401
|
+
break;
|
402
|
+
}
|
403
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
404
|
+
lineStart = position;
|
405
|
+
fieldLength = -1;
|
406
|
+
}
|
407
|
+
if (lineStart === bufLength) {
|
408
|
+
buffer = void 0;
|
409
|
+
} else if (lineStart !== 0) {
|
410
|
+
buffer = buffer.subarray(lineStart);
|
411
|
+
position -= lineStart;
|
412
|
+
}
|
413
|
+
};
|
414
|
+
}
|
415
|
+
function getMessages(onId, onRetry, onMessage) {
|
416
|
+
let message = newMessage();
|
417
|
+
const decoder = new TextDecoder();
|
418
|
+
return function onLine(line, fieldLength) {
|
419
|
+
if (line.length === 0) {
|
420
|
+
onMessage?.(message);
|
421
|
+
message = newMessage();
|
422
|
+
} else if (fieldLength > 0) {
|
423
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
424
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
425
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
426
|
+
switch (field) {
|
427
|
+
case "data":
|
428
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
429
|
+
break;
|
430
|
+
case "event":
|
431
|
+
message.event = value;
|
432
|
+
break;
|
433
|
+
case "id":
|
434
|
+
onId(message.id = value);
|
435
|
+
break;
|
436
|
+
case "retry":
|
437
|
+
const retry = parseInt(value, 10);
|
438
|
+
if (!isNaN(retry)) {
|
439
|
+
onRetry(message.retry = retry);
|
440
|
+
}
|
441
|
+
break;
|
442
|
+
}
|
443
|
+
}
|
444
|
+
};
|
445
|
+
}
|
446
|
+
function concat(a, b) {
|
447
|
+
const res = new Uint8Array(a.length + b.length);
|
448
|
+
res.set(a);
|
449
|
+
res.set(b, a.length);
|
450
|
+
return res;
|
451
|
+
}
|
452
|
+
function newMessage() {
|
453
|
+
return {
|
454
|
+
data: "",
|
455
|
+
event: "",
|
456
|
+
id: "",
|
457
|
+
retry: void 0
|
458
|
+
};
|
459
|
+
}
|
460
|
+
const EventStreamContentType = "text/event-stream";
|
461
|
+
const LastEventId = "last-event-id";
|
462
|
+
function fetchEventSource(input, {
|
463
|
+
signal: inputSignal,
|
464
|
+
headers: inputHeaders,
|
465
|
+
onopen: inputOnOpen,
|
466
|
+
onmessage,
|
467
|
+
onclose,
|
468
|
+
onerror,
|
469
|
+
fetch: inputFetch,
|
470
|
+
...rest
|
471
|
+
}) {
|
472
|
+
return new Promise((resolve, reject) => {
|
473
|
+
const headers = { ...inputHeaders };
|
474
|
+
if (!headers.accept) {
|
475
|
+
headers.accept = EventStreamContentType;
|
476
|
+
}
|
477
|
+
let curRequestController;
|
478
|
+
function dispose() {
|
479
|
+
curRequestController.abort();
|
480
|
+
}
|
481
|
+
inputSignal?.addEventListener("abort", () => {
|
482
|
+
dispose();
|
483
|
+
resolve();
|
484
|
+
});
|
485
|
+
const fetchImpl = inputFetch ?? fetch;
|
486
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
487
|
+
async function create() {
|
488
|
+
curRequestController = new AbortController();
|
489
|
+
try {
|
490
|
+
const response = await fetchImpl(input, {
|
491
|
+
...rest,
|
492
|
+
headers,
|
493
|
+
signal: curRequestController.signal
|
494
|
+
});
|
495
|
+
await onopen(response);
|
496
|
+
await getBytes(
|
497
|
+
response.body,
|
498
|
+
getLines(
|
499
|
+
getMessages(
|
500
|
+
(id) => {
|
501
|
+
if (id) {
|
502
|
+
headers[LastEventId] = id;
|
503
|
+
} else {
|
504
|
+
delete headers[LastEventId];
|
505
|
+
}
|
506
|
+
},
|
507
|
+
(_retry) => {
|
508
|
+
},
|
509
|
+
onmessage
|
510
|
+
)
|
511
|
+
)
|
512
|
+
);
|
513
|
+
onclose?.();
|
514
|
+
dispose();
|
515
|
+
resolve();
|
516
|
+
} catch (err) {
|
517
|
+
}
|
518
|
+
}
|
519
|
+
create();
|
520
|
+
});
|
521
|
+
}
|
522
|
+
function defaultOnOpen(response) {
|
523
|
+
const contentType = response.headers?.get("content-type");
|
524
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
525
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
526
|
+
}
|
527
|
+
}
|
528
|
+
|
529
|
+
const VERSION = "0.28.4";
|
298
530
|
|
299
531
|
class ErrorWithCause extends Error {
|
300
532
|
constructor(message, options) {
|
@@ -305,7 +537,7 @@ class FetcherError extends ErrorWithCause {
|
|
305
537
|
constructor(status, data, requestId) {
|
306
538
|
super(getMessage(data));
|
307
539
|
this.status = status;
|
308
|
-
this.errors = isBulkError(data) ? data.errors :
|
540
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
309
541
|
this.requestId = requestId;
|
310
542
|
if (data instanceof Error) {
|
311
543
|
this.stack = data.stack;
|
@@ -337,6 +569,67 @@ function getMessage(data) {
|
|
337
569
|
}
|
338
570
|
}
|
339
571
|
|
572
|
+
function getHostUrl(provider, type) {
|
573
|
+
if (isHostProviderAlias(provider)) {
|
574
|
+
return providers[provider][type];
|
575
|
+
} else if (isHostProviderBuilder(provider)) {
|
576
|
+
return provider[type];
|
577
|
+
}
|
578
|
+
throw new Error("Invalid API provider");
|
579
|
+
}
|
580
|
+
const providers = {
|
581
|
+
production: {
|
582
|
+
main: "https://api.xata.io",
|
583
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
584
|
+
},
|
585
|
+
staging: {
|
586
|
+
main: "https://api.staging-xata.dev",
|
587
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
588
|
+
},
|
589
|
+
dev: {
|
590
|
+
main: "https://api.dev-xata.dev",
|
591
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
592
|
+
},
|
593
|
+
local: {
|
594
|
+
main: "http://localhost:6001",
|
595
|
+
workspaces: "http://{workspaceId}.{region}.localhost:6001"
|
596
|
+
}
|
597
|
+
};
|
598
|
+
function isHostProviderAlias(alias) {
|
599
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
600
|
+
}
|
601
|
+
function isHostProviderBuilder(builder) {
|
602
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
603
|
+
}
|
604
|
+
function parseProviderString(provider = "production") {
|
605
|
+
if (isHostProviderAlias(provider)) {
|
606
|
+
return provider;
|
607
|
+
}
|
608
|
+
const [main, workspaces] = provider.split(",");
|
609
|
+
if (!main || !workspaces)
|
610
|
+
return null;
|
611
|
+
return { main, workspaces };
|
612
|
+
}
|
613
|
+
function buildProviderString(provider) {
|
614
|
+
if (isHostProviderAlias(provider))
|
615
|
+
return provider;
|
616
|
+
return `${provider.main},${provider.workspaces}`;
|
617
|
+
}
|
618
|
+
function parseWorkspacesUrlParts(url) {
|
619
|
+
if (!isString(url))
|
620
|
+
return null;
|
621
|
+
const matches = {
|
622
|
+
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
|
623
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
624
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
625
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
626
|
+
};
|
627
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
628
|
+
if (!isHostProviderAlias(host) || !match)
|
629
|
+
return null;
|
630
|
+
return { workspace: match[1], region: match[2], host };
|
631
|
+
}
|
632
|
+
|
340
633
|
const pool = new ApiRequestPool();
|
341
634
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
342
635
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
@@ -352,6 +645,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
352
645
|
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
353
646
|
};
|
354
647
|
function buildBaseUrl({
|
648
|
+
method,
|
355
649
|
endpoint,
|
356
650
|
path,
|
357
651
|
workspacesApiUrl,
|
@@ -359,7 +653,24 @@ function buildBaseUrl({
|
|
359
653
|
pathParams = {}
|
360
654
|
}) {
|
361
655
|
if (endpoint === "dataPlane") {
|
362
|
-
|
656
|
+
let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
657
|
+
if (method.toUpperCase() === "PUT" && [
|
658
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
659
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
|
660
|
+
].includes(path)) {
|
661
|
+
const { host } = parseWorkspacesUrlParts(url) ?? {};
|
662
|
+
switch (host) {
|
663
|
+
case "production":
|
664
|
+
url = url.replace("xata.sh", "upload.xata.sh");
|
665
|
+
break;
|
666
|
+
case "staging":
|
667
|
+
url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
|
668
|
+
break;
|
669
|
+
case "dev":
|
670
|
+
url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
|
671
|
+
break;
|
672
|
+
}
|
673
|
+
}
|
363
674
|
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
364
675
|
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
365
676
|
}
|
@@ -370,14 +681,27 @@ function hostHeader(url) {
|
|
370
681
|
const { groups } = pattern.exec(url) ?? {};
|
371
682
|
return groups?.host ? { Host: groups.host } : {};
|
372
683
|
}
|
684
|
+
async function parseBody(body, headers) {
|
685
|
+
if (!isDefined(body))
|
686
|
+
return void 0;
|
687
|
+
if (isBlob(body) || typeof body.text === "function") {
|
688
|
+
return body;
|
689
|
+
}
|
690
|
+
const { "Content-Type": contentType } = headers ?? {};
|
691
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
692
|
+
return JSON.stringify(body);
|
693
|
+
}
|
694
|
+
return body;
|
695
|
+
}
|
696
|
+
const defaultClientID = generateUUID();
|
373
697
|
async function fetch$1({
|
374
698
|
url: path,
|
375
699
|
method,
|
376
700
|
body,
|
377
|
-
headers,
|
701
|
+
headers: customHeaders,
|
378
702
|
pathParams,
|
379
703
|
queryParams,
|
380
|
-
|
704
|
+
fetch: fetch2,
|
381
705
|
apiKey,
|
382
706
|
endpoint,
|
383
707
|
apiUrl,
|
@@ -386,32 +710,43 @@ async function fetch$1({
|
|
386
710
|
signal,
|
387
711
|
clientID,
|
388
712
|
sessionID,
|
389
|
-
|
713
|
+
clientName,
|
714
|
+
xataAgentExtra,
|
715
|
+
fetchOptions = {},
|
716
|
+
rawResponse = false
|
390
717
|
}) {
|
391
|
-
pool.setFetch(
|
718
|
+
pool.setFetch(fetch2);
|
392
719
|
return await trace(
|
393
720
|
`${method.toUpperCase()} ${path}`,
|
394
721
|
async ({ setAttributes }) => {
|
395
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
722
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
396
723
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
397
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
724
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
398
725
|
setAttributes({
|
399
726
|
[TraceAttributes.HTTP_URL]: url,
|
400
727
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
401
728
|
});
|
729
|
+
const xataAgent = compact([
|
730
|
+
["client", "TS_SDK"],
|
731
|
+
["version", VERSION],
|
732
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
733
|
+
...Object.entries(xataAgentExtra ?? {})
|
734
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
735
|
+
const headers = compactObject({
|
736
|
+
"Accept-Encoding": "identity",
|
737
|
+
"Content-Type": "application/json",
|
738
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
739
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
740
|
+
"X-Xata-Agent": xataAgent,
|
741
|
+
...customHeaders,
|
742
|
+
...hostHeader(fullUrl),
|
743
|
+
Authorization: `Bearer ${apiKey}`
|
744
|
+
});
|
402
745
|
const response = await pool.request(url, {
|
403
746
|
...fetchOptions,
|
404
747
|
method: method.toUpperCase(),
|
405
|
-
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
|
-
},
|
748
|
+
body: await parseBody(body, headers),
|
749
|
+
headers,
|
415
750
|
signal
|
416
751
|
});
|
417
752
|
const { host, protocol } = parseUrl(response.url);
|
@@ -421,8 +756,12 @@ async function fetch$1({
|
|
421
756
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
422
757
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
423
758
|
[TraceAttributes.HTTP_HOST]: host,
|
424
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
759
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
760
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
425
761
|
});
|
762
|
+
const message = response.headers?.get("x-xata-message");
|
763
|
+
if (message)
|
764
|
+
console.warn(message);
|
426
765
|
if (response.status === 204) {
|
427
766
|
return {};
|
428
767
|
}
|
@@ -430,7 +769,7 @@ async function fetch$1({
|
|
430
769
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
431
770
|
}
|
432
771
|
try {
|
433
|
-
const jsonResponse = await response.json();
|
772
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
434
773
|
if (response.ok) {
|
435
774
|
return jsonResponse;
|
436
775
|
}
|
@@ -442,6 +781,59 @@ async function fetch$1({
|
|
442
781
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
443
782
|
);
|
444
783
|
}
|
784
|
+
function fetchSSERequest({
|
785
|
+
url: path,
|
786
|
+
method,
|
787
|
+
body,
|
788
|
+
headers: customHeaders,
|
789
|
+
pathParams,
|
790
|
+
queryParams,
|
791
|
+
fetch: fetch2,
|
792
|
+
apiKey,
|
793
|
+
endpoint,
|
794
|
+
apiUrl,
|
795
|
+
workspacesApiUrl,
|
796
|
+
onMessage,
|
797
|
+
onError,
|
798
|
+
onClose,
|
799
|
+
signal,
|
800
|
+
clientID,
|
801
|
+
sessionID,
|
802
|
+
clientName,
|
803
|
+
xataAgentExtra
|
804
|
+
}) {
|
805
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
806
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
807
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
808
|
+
void fetchEventSource(url, {
|
809
|
+
method,
|
810
|
+
body: JSON.stringify(body),
|
811
|
+
fetch: fetch2,
|
812
|
+
signal,
|
813
|
+
headers: {
|
814
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
815
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
816
|
+
"X-Xata-Agent": compact([
|
817
|
+
["client", "TS_SDK"],
|
818
|
+
["version", VERSION],
|
819
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
820
|
+
...Object.entries(xataAgentExtra ?? {})
|
821
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
822
|
+
...customHeaders,
|
823
|
+
Authorization: `Bearer ${apiKey}`,
|
824
|
+
"Content-Type": "application/json"
|
825
|
+
},
|
826
|
+
onmessage(ev) {
|
827
|
+
onMessage?.(JSON.parse(ev.data));
|
828
|
+
},
|
829
|
+
onerror(ev) {
|
830
|
+
onError?.(JSON.parse(ev.data));
|
831
|
+
},
|
832
|
+
onclose() {
|
833
|
+
onClose?.();
|
834
|
+
}
|
835
|
+
});
|
836
|
+
}
|
445
837
|
function parseUrl(url) {
|
446
838
|
try {
|
447
839
|
const { host, protocol } = new URL(url);
|
@@ -453,17 +845,26 @@ function parseUrl(url) {
|
|
453
845
|
|
454
846
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
455
847
|
|
456
|
-
const
|
848
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
849
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
850
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
851
|
+
method: "get",
|
852
|
+
...variables,
|
853
|
+
signal
|
854
|
+
});
|
855
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
856
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
857
|
+
method: "get",
|
858
|
+
...variables,
|
859
|
+
signal
|
860
|
+
});
|
861
|
+
const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
|
457
862
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
458
863
|
url: "/dbs/{dbName}",
|
459
864
|
method: "get",
|
460
865
|
...variables,
|
461
866
|
signal
|
462
867
|
});
|
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
868
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
468
869
|
url: "/db/{dbBranchName}",
|
469
870
|
method: "get",
|
@@ -477,6 +878,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
477
878
|
...variables,
|
478
879
|
signal
|
479
880
|
});
|
881
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
882
|
+
url: "/db/{dbBranchName}/schema",
|
883
|
+
method: "get",
|
884
|
+
...variables,
|
885
|
+
signal
|
886
|
+
});
|
887
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
888
|
+
url: "/db/{dbBranchName}/copy",
|
889
|
+
method: "post",
|
890
|
+
...variables,
|
891
|
+
signal
|
892
|
+
});
|
480
893
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
481
894
|
url: "/db/{dbBranchName}/metadata",
|
482
895
|
method: "put",
|
@@ -502,7 +915,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
502
915
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
503
916
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
504
917
|
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
918
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
507
919
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
508
920
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -527,6 +939,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
527
939
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
528
940
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
529
941
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
942
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
530
943
|
const createTable = (variables, signal) => dataPlaneFetch({
|
531
944
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
532
945
|
method: "put",
|
@@ -569,7 +982,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
569
982
|
...variables,
|
570
983
|
signal
|
571
984
|
});
|
985
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
572
986
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
987
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
988
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
989
|
+
method: "get",
|
990
|
+
...variables,
|
991
|
+
signal
|
992
|
+
});
|
993
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
994
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
995
|
+
method: "put",
|
996
|
+
...variables,
|
997
|
+
signal
|
998
|
+
});
|
999
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
1000
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
1001
|
+
method: "delete",
|
1002
|
+
...variables,
|
1003
|
+
signal
|
1004
|
+
});
|
1005
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
1006
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1007
|
+
method: "get",
|
1008
|
+
...variables,
|
1009
|
+
signal
|
1010
|
+
});
|
1011
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
1012
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1013
|
+
method: "put",
|
1014
|
+
...variables,
|
1015
|
+
signal
|
1016
|
+
});
|
1017
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
1018
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1019
|
+
method: "delete",
|
1020
|
+
...variables,
|
1021
|
+
signal
|
1022
|
+
});
|
573
1023
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
574
1024
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
575
1025
|
method: "get",
|
@@ -599,21 +1049,45 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
599
1049
|
...variables,
|
600
1050
|
signal
|
601
1051
|
});
|
1052
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
1053
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
1054
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
1055
|
+
method: "post",
|
1056
|
+
...variables,
|
1057
|
+
signal
|
1058
|
+
});
|
1059
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
602
1060
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
603
1061
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
1062
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
1063
|
+
url: "/file/{fileId}",
|
1064
|
+
method: "get",
|
1065
|
+
...variables,
|
1066
|
+
signal
|
1067
|
+
});
|
1068
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1069
|
+
url: "/file/{fileId}",
|
1070
|
+
method: "put",
|
1071
|
+
...variables,
|
1072
|
+
signal
|
1073
|
+
});
|
1074
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
1075
|
+
url: "/db/{dbBranchName}/sql",
|
1076
|
+
method: "post",
|
1077
|
+
...variables,
|
1078
|
+
signal
|
1079
|
+
});
|
604
1080
|
const operationsByTag$2 = {
|
605
|
-
database: {
|
606
|
-
dEPRECATEDgetDatabaseList,
|
607
|
-
dEPRECATEDcreateDatabase,
|
608
|
-
dEPRECATEDdeleteDatabase,
|
609
|
-
dEPRECATEDgetDatabaseMetadata,
|
610
|
-
dEPRECATEDupdateDatabaseMetadata
|
611
|
-
},
|
612
1081
|
branch: {
|
1082
|
+
applyMigration,
|
1083
|
+
pgRollStatus,
|
1084
|
+
pgRollJobStatus,
|
1085
|
+
pgRollMigrationHistory,
|
613
1086
|
getBranchList,
|
614
1087
|
getBranchDetails,
|
615
1088
|
createBranch,
|
616
1089
|
deleteBranch,
|
1090
|
+
copyBranch,
|
617
1091
|
updateBranchMetadata,
|
618
1092
|
getBranchMetadata,
|
619
1093
|
getBranchStats,
|
@@ -623,6 +1097,7 @@ const operationsByTag$2 = {
|
|
623
1097
|
resolveBranch
|
624
1098
|
},
|
625
1099
|
migrations: {
|
1100
|
+
getSchema,
|
626
1101
|
getBranchMigrationHistory,
|
627
1102
|
getBranchMigrationPlan,
|
628
1103
|
executeBranchMigrationPlan,
|
@@ -631,17 +1106,8 @@ const operationsByTag$2 = {
|
|
631
1106
|
compareBranchSchemas,
|
632
1107
|
updateBranchSchema,
|
633
1108
|
previewBranchSchemaEdit,
|
634
|
-
applyBranchSchemaEdit
|
635
|
-
|
636
|
-
records: {
|
637
|
-
branchTransaction,
|
638
|
-
insertRecord,
|
639
|
-
getRecord,
|
640
|
-
insertRecordWithID,
|
641
|
-
updateRecordWithID,
|
642
|
-
upsertRecordWithID,
|
643
|
-
deleteRecord,
|
644
|
-
bulkInsertTableRecords
|
1109
|
+
applyBranchSchemaEdit,
|
1110
|
+
pushBranchMigrations
|
645
1111
|
},
|
646
1112
|
migrationRequests: {
|
647
1113
|
queryMigrationRequests,
|
@@ -665,11 +1131,34 @@ const operationsByTag$2 = {
|
|
665
1131
|
updateColumn,
|
666
1132
|
deleteColumn
|
667
1133
|
},
|
668
|
-
|
1134
|
+
records: {
|
1135
|
+
branchTransaction,
|
1136
|
+
insertRecord,
|
1137
|
+
getRecord,
|
1138
|
+
insertRecordWithID,
|
1139
|
+
updateRecordWithID,
|
1140
|
+
upsertRecordWithID,
|
1141
|
+
deleteRecord,
|
1142
|
+
bulkInsertTableRecords
|
1143
|
+
},
|
1144
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1145
|
+
searchAndFilter: {
|
1146
|
+
queryTable,
|
1147
|
+
searchBranch,
|
1148
|
+
searchTable,
|
1149
|
+
vectorSearchTable,
|
1150
|
+
askTable,
|
1151
|
+
askTableSession,
|
1152
|
+
summarizeTable,
|
1153
|
+
aggregateTable
|
1154
|
+
},
|
1155
|
+
sql: { sqlQuery }
|
669
1156
|
};
|
670
1157
|
|
671
1158
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
672
1159
|
|
1160
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1161
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
673
1162
|
const getUser = (variables, signal) => controlPlaneFetch({
|
674
1163
|
url: "/user",
|
675
1164
|
method: "get",
|
@@ -706,6 +1195,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
706
1195
|
...variables,
|
707
1196
|
signal
|
708
1197
|
});
|
1198
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1199
|
+
url: "/user/oauth/clients",
|
1200
|
+
method: "get",
|
1201
|
+
...variables,
|
1202
|
+
signal
|
1203
|
+
});
|
1204
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1205
|
+
url: "/user/oauth/clients/{clientId}",
|
1206
|
+
method: "delete",
|
1207
|
+
...variables,
|
1208
|
+
signal
|
1209
|
+
});
|
1210
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1211
|
+
url: "/user/oauth/tokens",
|
1212
|
+
method: "get",
|
1213
|
+
...variables,
|
1214
|
+
signal
|
1215
|
+
});
|
1216
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1217
|
+
url: "/user/oauth/tokens/{token}",
|
1218
|
+
method: "delete",
|
1219
|
+
...variables,
|
1220
|
+
signal
|
1221
|
+
});
|
1222
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
709
1223
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
710
1224
|
url: "/workspaces",
|
711
1225
|
method: "get",
|
@@ -749,6 +1263,15 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
749
1263
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
750
1264
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
751
1265
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1266
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1267
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1268
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1269
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1270
|
+
method: "get",
|
1271
|
+
...variables,
|
1272
|
+
signal
|
1273
|
+
});
|
1274
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
752
1275
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
753
1276
|
url: "/workspaces/{workspaceId}/dbs",
|
754
1277
|
method: "get",
|
@@ -764,6 +1287,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
764
1287
|
});
|
765
1288
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
766
1289
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1290
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1291
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1292
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1293
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
767
1294
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
768
1295
|
url: "/workspaces/{workspaceId}/regions",
|
769
1296
|
method: "get",
|
@@ -771,6 +1298,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
771
1298
|
signal
|
772
1299
|
});
|
773
1300
|
const operationsByTag$1 = {
|
1301
|
+
oAuth: {
|
1302
|
+
getAuthorizationCode,
|
1303
|
+
grantAuthorizationCode,
|
1304
|
+
getUserOAuthClients,
|
1305
|
+
deleteUserOAuthClient,
|
1306
|
+
getUserOAuthAccessTokens,
|
1307
|
+
deleteOAuthAccessToken,
|
1308
|
+
updateOAuthAccessToken
|
1309
|
+
},
|
774
1310
|
users: { getUser, updateUser, deleteUser },
|
775
1311
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
776
1312
|
workspaces: {
|
@@ -790,62 +1326,23 @@ const operationsByTag$1 = {
|
|
790
1326
|
acceptWorkspaceMemberInvite,
|
791
1327
|
resendWorkspaceMemberInvite
|
792
1328
|
},
|
1329
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
793
1330
|
databases: {
|
794
1331
|
getDatabaseList,
|
795
1332
|
createDatabase,
|
796
1333
|
deleteDatabase,
|
797
1334
|
getDatabaseMetadata,
|
798
1335
|
updateDatabaseMetadata,
|
1336
|
+
renameDatabase,
|
1337
|
+
getDatabaseGithubSettings,
|
1338
|
+
updateDatabaseGithubSettings,
|
1339
|
+
deleteDatabaseGithubSettings,
|
799
1340
|
listRegions
|
800
1341
|
}
|
801
1342
|
};
|
802
1343
|
|
803
1344
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
804
1345
|
|
805
|
-
function getHostUrl(provider, type) {
|
806
|
-
if (isHostProviderAlias(provider)) {
|
807
|
-
return providers[provider][type];
|
808
|
-
} else if (isHostProviderBuilder(provider)) {
|
809
|
-
return provider[type];
|
810
|
-
}
|
811
|
-
throw new Error("Invalid API provider");
|
812
|
-
}
|
813
|
-
const providers = {
|
814
|
-
production: {
|
815
|
-
main: "https://api.xata.io",
|
816
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
817
|
-
},
|
818
|
-
staging: {
|
819
|
-
main: "https://staging.xatabase.co",
|
820
|
-
workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
|
821
|
-
}
|
822
|
-
};
|
823
|
-
function isHostProviderAlias(alias) {
|
824
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
825
|
-
}
|
826
|
-
function isHostProviderBuilder(builder) {
|
827
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
828
|
-
}
|
829
|
-
function parseProviderString(provider = "production") {
|
830
|
-
if (isHostProviderAlias(provider)) {
|
831
|
-
return provider;
|
832
|
-
}
|
833
|
-
const [main, workspaces] = provider.split(",");
|
834
|
-
if (!main || !workspaces)
|
835
|
-
return null;
|
836
|
-
return { main, workspaces };
|
837
|
-
}
|
838
|
-
function parseWorkspacesUrlParts(url) {
|
839
|
-
if (!isString(url))
|
840
|
-
return null;
|
841
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
|
842
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
|
843
|
-
const match = url.match(regex) || url.match(regexStaging);
|
844
|
-
if (!match)
|
845
|
-
return null;
|
846
|
-
return { workspace: match[1], region: match[2] ?? "eu-west-1" };
|
847
|
-
}
|
848
|
-
|
849
1346
|
var __accessCheck$7 = (obj, member, msg) => {
|
850
1347
|
if (!member.has(obj))
|
851
1348
|
throw TypeError("Cannot " + msg);
|
@@ -872,15 +1369,19 @@ class XataApiClient {
|
|
872
1369
|
const provider = options.host ?? "production";
|
873
1370
|
const apiKey = options.apiKey ?? getAPIKey();
|
874
1371
|
const trace = options.trace ?? defaultTrace;
|
1372
|
+
const clientID = generateUUID();
|
875
1373
|
if (!apiKey) {
|
876
1374
|
throw new Error("Could not resolve a valid apiKey");
|
877
1375
|
}
|
878
1376
|
__privateSet$7(this, _extraProps, {
|
879
1377
|
apiUrl: getHostUrl(provider, "main"),
|
880
1378
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
881
|
-
|
1379
|
+
fetch: getFetchImplementation(options.fetch),
|
882
1380
|
apiKey,
|
883
|
-
trace
|
1381
|
+
trace,
|
1382
|
+
clientName: options.clientName,
|
1383
|
+
xataAgentExtra: options.xataAgentExtra,
|
1384
|
+
clientID
|
884
1385
|
});
|
885
1386
|
}
|
886
1387
|
get user() {
|
@@ -933,6 +1434,11 @@ class XataApiClient {
|
|
933
1434
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
934
1435
|
return __privateGet$7(this, _namespaces).records;
|
935
1436
|
}
|
1437
|
+
get files() {
|
1438
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1439
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1440
|
+
return __privateGet$7(this, _namespaces).files;
|
1441
|
+
}
|
936
1442
|
get searchAndFilter() {
|
937
1443
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
938
1444
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1141,6 +1647,20 @@ class BranchApi {
|
|
1141
1647
|
...this.extraProps
|
1142
1648
|
});
|
1143
1649
|
}
|
1650
|
+
copyBranch({
|
1651
|
+
workspace,
|
1652
|
+
region,
|
1653
|
+
database,
|
1654
|
+
branch,
|
1655
|
+
destinationBranch,
|
1656
|
+
limit
|
1657
|
+
}) {
|
1658
|
+
return operationsByTag.branch.copyBranch({
|
1659
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1660
|
+
body: { destinationBranch, limit },
|
1661
|
+
...this.extraProps
|
1662
|
+
});
|
1663
|
+
}
|
1144
1664
|
updateBranchMetadata({
|
1145
1665
|
workspace,
|
1146
1666
|
region,
|
@@ -1496,6 +2016,164 @@ class RecordsApi {
|
|
1496
2016
|
});
|
1497
2017
|
}
|
1498
2018
|
}
|
2019
|
+
class FilesApi {
|
2020
|
+
constructor(extraProps) {
|
2021
|
+
this.extraProps = extraProps;
|
2022
|
+
}
|
2023
|
+
getFileItem({
|
2024
|
+
workspace,
|
2025
|
+
region,
|
2026
|
+
database,
|
2027
|
+
branch,
|
2028
|
+
table,
|
2029
|
+
record,
|
2030
|
+
column,
|
2031
|
+
fileId
|
2032
|
+
}) {
|
2033
|
+
return operationsByTag.files.getFileItem({
|
2034
|
+
pathParams: {
|
2035
|
+
workspace,
|
2036
|
+
region,
|
2037
|
+
dbBranchName: `${database}:${branch}`,
|
2038
|
+
tableName: table,
|
2039
|
+
recordId: record,
|
2040
|
+
columnName: column,
|
2041
|
+
fileId
|
2042
|
+
},
|
2043
|
+
...this.extraProps
|
2044
|
+
});
|
2045
|
+
}
|
2046
|
+
putFileItem({
|
2047
|
+
workspace,
|
2048
|
+
region,
|
2049
|
+
database,
|
2050
|
+
branch,
|
2051
|
+
table,
|
2052
|
+
record,
|
2053
|
+
column,
|
2054
|
+
fileId,
|
2055
|
+
file
|
2056
|
+
}) {
|
2057
|
+
return operationsByTag.files.putFileItem({
|
2058
|
+
pathParams: {
|
2059
|
+
workspace,
|
2060
|
+
region,
|
2061
|
+
dbBranchName: `${database}:${branch}`,
|
2062
|
+
tableName: table,
|
2063
|
+
recordId: record,
|
2064
|
+
columnName: column,
|
2065
|
+
fileId
|
2066
|
+
},
|
2067
|
+
// @ts-ignore
|
2068
|
+
body: file,
|
2069
|
+
...this.extraProps
|
2070
|
+
});
|
2071
|
+
}
|
2072
|
+
deleteFileItem({
|
2073
|
+
workspace,
|
2074
|
+
region,
|
2075
|
+
database,
|
2076
|
+
branch,
|
2077
|
+
table,
|
2078
|
+
record,
|
2079
|
+
column,
|
2080
|
+
fileId
|
2081
|
+
}) {
|
2082
|
+
return operationsByTag.files.deleteFileItem({
|
2083
|
+
pathParams: {
|
2084
|
+
workspace,
|
2085
|
+
region,
|
2086
|
+
dbBranchName: `${database}:${branch}`,
|
2087
|
+
tableName: table,
|
2088
|
+
recordId: record,
|
2089
|
+
columnName: column,
|
2090
|
+
fileId
|
2091
|
+
},
|
2092
|
+
...this.extraProps
|
2093
|
+
});
|
2094
|
+
}
|
2095
|
+
getFile({
|
2096
|
+
workspace,
|
2097
|
+
region,
|
2098
|
+
database,
|
2099
|
+
branch,
|
2100
|
+
table,
|
2101
|
+
record,
|
2102
|
+
column
|
2103
|
+
}) {
|
2104
|
+
return operationsByTag.files.getFile({
|
2105
|
+
pathParams: {
|
2106
|
+
workspace,
|
2107
|
+
region,
|
2108
|
+
dbBranchName: `${database}:${branch}`,
|
2109
|
+
tableName: table,
|
2110
|
+
recordId: record,
|
2111
|
+
columnName: column
|
2112
|
+
},
|
2113
|
+
...this.extraProps
|
2114
|
+
});
|
2115
|
+
}
|
2116
|
+
putFile({
|
2117
|
+
workspace,
|
2118
|
+
region,
|
2119
|
+
database,
|
2120
|
+
branch,
|
2121
|
+
table,
|
2122
|
+
record,
|
2123
|
+
column,
|
2124
|
+
file
|
2125
|
+
}) {
|
2126
|
+
return operationsByTag.files.putFile({
|
2127
|
+
pathParams: {
|
2128
|
+
workspace,
|
2129
|
+
region,
|
2130
|
+
dbBranchName: `${database}:${branch}`,
|
2131
|
+
tableName: table,
|
2132
|
+
recordId: record,
|
2133
|
+
columnName: column
|
2134
|
+
},
|
2135
|
+
body: file,
|
2136
|
+
...this.extraProps
|
2137
|
+
});
|
2138
|
+
}
|
2139
|
+
deleteFile({
|
2140
|
+
workspace,
|
2141
|
+
region,
|
2142
|
+
database,
|
2143
|
+
branch,
|
2144
|
+
table,
|
2145
|
+
record,
|
2146
|
+
column
|
2147
|
+
}) {
|
2148
|
+
return operationsByTag.files.deleteFile({
|
2149
|
+
pathParams: {
|
2150
|
+
workspace,
|
2151
|
+
region,
|
2152
|
+
dbBranchName: `${database}:${branch}`,
|
2153
|
+
tableName: table,
|
2154
|
+
recordId: record,
|
2155
|
+
columnName: column
|
2156
|
+
},
|
2157
|
+
...this.extraProps
|
2158
|
+
});
|
2159
|
+
}
|
2160
|
+
fileAccess({
|
2161
|
+
workspace,
|
2162
|
+
region,
|
2163
|
+
fileId,
|
2164
|
+
verify
|
2165
|
+
}) {
|
2166
|
+
return operationsByTag.files.fileAccess({
|
2167
|
+
pathParams: {
|
2168
|
+
workspace,
|
2169
|
+
region,
|
2170
|
+
fileId
|
2171
|
+
},
|
2172
|
+
queryParams: { verify },
|
2173
|
+
...this.extraProps
|
2174
|
+
});
|
2175
|
+
}
|
2176
|
+
}
|
1499
2177
|
class SearchAndFilterApi {
|
1500
2178
|
constructor(extraProps) {
|
1501
2179
|
this.extraProps = extraProps;
|
@@ -1555,6 +2233,53 @@ class SearchAndFilterApi {
|
|
1555
2233
|
...this.extraProps
|
1556
2234
|
});
|
1557
2235
|
}
|
2236
|
+
vectorSearchTable({
|
2237
|
+
workspace,
|
2238
|
+
region,
|
2239
|
+
database,
|
2240
|
+
branch,
|
2241
|
+
table,
|
2242
|
+
queryVector,
|
2243
|
+
column,
|
2244
|
+
similarityFunction,
|
2245
|
+
size,
|
2246
|
+
filter
|
2247
|
+
}) {
|
2248
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2249
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2250
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2251
|
+
...this.extraProps
|
2252
|
+
});
|
2253
|
+
}
|
2254
|
+
askTable({
|
2255
|
+
workspace,
|
2256
|
+
region,
|
2257
|
+
database,
|
2258
|
+
branch,
|
2259
|
+
table,
|
2260
|
+
options
|
2261
|
+
}) {
|
2262
|
+
return operationsByTag.searchAndFilter.askTable({
|
2263
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2264
|
+
body: { ...options },
|
2265
|
+
...this.extraProps
|
2266
|
+
});
|
2267
|
+
}
|
2268
|
+
askTableSession({
|
2269
|
+
workspace,
|
2270
|
+
region,
|
2271
|
+
database,
|
2272
|
+
branch,
|
2273
|
+
table,
|
2274
|
+
sessionId,
|
2275
|
+
message
|
2276
|
+
}) {
|
2277
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2278
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2279
|
+
body: { message },
|
2280
|
+
...this.extraProps
|
2281
|
+
});
|
2282
|
+
}
|
1558
2283
|
summarizeTable({
|
1559
2284
|
workspace,
|
1560
2285
|
region,
|
@@ -1755,11 +2480,13 @@ class MigrationsApi {
|
|
1755
2480
|
region,
|
1756
2481
|
database,
|
1757
2482
|
branch,
|
1758
|
-
schema
|
2483
|
+
schema,
|
2484
|
+
schemaOperations,
|
2485
|
+
branchOperations
|
1759
2486
|
}) {
|
1760
2487
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1761
2488
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1762
|
-
body: { schema },
|
2489
|
+
body: { schema, schemaOperations, branchOperations },
|
1763
2490
|
...this.extraProps
|
1764
2491
|
});
|
1765
2492
|
}
|
@@ -1769,11 +2496,12 @@ class MigrationsApi {
|
|
1769
2496
|
database,
|
1770
2497
|
branch,
|
1771
2498
|
compare,
|
1772
|
-
|
2499
|
+
sourceBranchOperations,
|
2500
|
+
targetBranchOperations
|
1773
2501
|
}) {
|
1774
2502
|
return operationsByTag.migrations.compareBranchSchemas({
|
1775
2503
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1776
|
-
body: {
|
2504
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1777
2505
|
...this.extraProps
|
1778
2506
|
});
|
1779
2507
|
}
|
@@ -1816,6 +2544,19 @@ class MigrationsApi {
|
|
1816
2544
|
...this.extraProps
|
1817
2545
|
});
|
1818
2546
|
}
|
2547
|
+
pushBranchMigrations({
|
2548
|
+
workspace,
|
2549
|
+
region,
|
2550
|
+
database,
|
2551
|
+
branch,
|
2552
|
+
migrations
|
2553
|
+
}) {
|
2554
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2555
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2556
|
+
body: { migrations },
|
2557
|
+
...this.extraProps
|
2558
|
+
});
|
2559
|
+
}
|
1819
2560
|
}
|
1820
2561
|
class DatabaseApi {
|
1821
2562
|
constructor(extraProps) {
|
@@ -1830,11 +2571,13 @@ class DatabaseApi {
|
|
1830
2571
|
createDatabase({
|
1831
2572
|
workspace,
|
1832
2573
|
database,
|
1833
|
-
data
|
2574
|
+
data,
|
2575
|
+
headers
|
1834
2576
|
}) {
|
1835
2577
|
return operationsByTag.databases.createDatabase({
|
1836
2578
|
pathParams: { workspaceId: workspace, dbName: database },
|
1837
2579
|
body: data,
|
2580
|
+
headers,
|
1838
2581
|
...this.extraProps
|
1839
2582
|
});
|
1840
2583
|
}
|
@@ -1867,36 +2610,252 @@ class DatabaseApi {
|
|
1867
2610
|
...this.extraProps
|
1868
2611
|
});
|
1869
2612
|
}
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
2613
|
+
renameDatabase({
|
2614
|
+
workspace,
|
2615
|
+
database,
|
2616
|
+
newName
|
2617
|
+
}) {
|
2618
|
+
return operationsByTag.databases.renameDatabase({
|
2619
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2620
|
+
body: { newName },
|
2621
|
+
...this.extraProps
|
2622
|
+
});
|
2623
|
+
}
|
2624
|
+
getDatabaseGithubSettings({
|
2625
|
+
workspace,
|
2626
|
+
database
|
2627
|
+
}) {
|
2628
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2629
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2630
|
+
...this.extraProps
|
2631
|
+
});
|
2632
|
+
}
|
2633
|
+
updateDatabaseGithubSettings({
|
2634
|
+
workspace,
|
2635
|
+
database,
|
2636
|
+
settings
|
2637
|
+
}) {
|
2638
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2639
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2640
|
+
body: settings,
|
2641
|
+
...this.extraProps
|
2642
|
+
});
|
2643
|
+
}
|
2644
|
+
deleteDatabaseGithubSettings({
|
2645
|
+
workspace,
|
2646
|
+
database
|
2647
|
+
}) {
|
2648
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2649
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2650
|
+
...this.extraProps
|
2651
|
+
});
|
2652
|
+
}
|
2653
|
+
listRegions({ workspace }) {
|
2654
|
+
return operationsByTag.databases.listRegions({
|
2655
|
+
pathParams: { workspaceId: workspace },
|
2656
|
+
...this.extraProps
|
2657
|
+
});
|
2658
|
+
}
|
2659
|
+
}
|
2660
|
+
|
2661
|
+
class XataApiPlugin {
|
2662
|
+
build(options) {
|
2663
|
+
return new XataApiClient(options);
|
2664
|
+
}
|
2665
|
+
}
|
2666
|
+
|
2667
|
+
class XataPlugin {
|
2668
|
+
}
|
2669
|
+
|
2670
|
+
function buildTransformString(transformations) {
|
2671
|
+
return transformations.flatMap(
|
2672
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2673
|
+
if (key === "trim") {
|
2674
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2675
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2676
|
+
}
|
2677
|
+
if (key === "gravity" && typeof value === "object") {
|
2678
|
+
const { x = 0.5, y = 0.5 } = value;
|
2679
|
+
return `${key}=${[x, y].join("x")}`;
|
2680
|
+
}
|
2681
|
+
return `${key}=${value}`;
|
2682
|
+
})
|
2683
|
+
).join(",");
|
2684
|
+
}
|
2685
|
+
function transformImage(url, ...transformations) {
|
2686
|
+
if (!isDefined(url))
|
2687
|
+
return void 0;
|
2688
|
+
const newTransformations = buildTransformString(transformations);
|
2689
|
+
const { hostname, pathname, search } = new URL(url);
|
2690
|
+
const pathParts = pathname.split("/");
|
2691
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2692
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2693
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2694
|
+
const path = pathParts.join("/");
|
2695
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2696
|
+
}
|
2697
|
+
|
2698
|
+
class XataFile {
|
2699
|
+
constructor(file) {
|
2700
|
+
this.id = file.id;
|
2701
|
+
this.name = file.name;
|
2702
|
+
this.mediaType = file.mediaType;
|
2703
|
+
this.base64Content = file.base64Content;
|
2704
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2705
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2706
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2707
|
+
this.size = file.size;
|
2708
|
+
this.version = file.version;
|
2709
|
+
this.url = file.url;
|
2710
|
+
this.signedUrl = file.signedUrl;
|
2711
|
+
this.uploadUrl = file.uploadUrl;
|
2712
|
+
this.attributes = file.attributes;
|
2713
|
+
}
|
2714
|
+
static fromBuffer(buffer, options = {}) {
|
2715
|
+
const base64Content = buffer.toString("base64");
|
2716
|
+
return new XataFile({ ...options, base64Content });
|
2717
|
+
}
|
2718
|
+
toBuffer() {
|
2719
|
+
if (!this.base64Content) {
|
2720
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2721
|
+
}
|
2722
|
+
return Buffer.from(this.base64Content, "base64");
|
2723
|
+
}
|
2724
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2725
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2726
|
+
return this.fromUint8Array(uint8Array, options);
|
2727
|
+
}
|
2728
|
+
toArrayBuffer() {
|
2729
|
+
if (!this.base64Content) {
|
2730
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2731
|
+
}
|
2732
|
+
const binary = atob(this.base64Content);
|
2733
|
+
return new ArrayBuffer(binary.length);
|
2734
|
+
}
|
2735
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2736
|
+
let binary = "";
|
2737
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2738
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2739
|
+
}
|
2740
|
+
const base64Content = btoa(binary);
|
2741
|
+
return new XataFile({ ...options, base64Content });
|
2742
|
+
}
|
2743
|
+
toUint8Array() {
|
2744
|
+
if (!this.base64Content) {
|
2745
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2746
|
+
}
|
2747
|
+
const binary = atob(this.base64Content);
|
2748
|
+
const uint8Array = new Uint8Array(binary.length);
|
2749
|
+
for (let i = 0; i < binary.length; i++) {
|
2750
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2751
|
+
}
|
2752
|
+
return uint8Array;
|
2753
|
+
}
|
2754
|
+
static async fromBlob(file, options = {}) {
|
2755
|
+
const name = options.name ?? file.name;
|
2756
|
+
const mediaType = file.type;
|
2757
|
+
const arrayBuffer = await file.arrayBuffer();
|
2758
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2759
|
+
}
|
2760
|
+
toBlob() {
|
2761
|
+
if (!this.base64Content) {
|
2762
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2763
|
+
}
|
2764
|
+
const binary = atob(this.base64Content);
|
2765
|
+
const uint8Array = new Uint8Array(binary.length);
|
2766
|
+
for (let i = 0; i < binary.length; i++) {
|
2767
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2768
|
+
}
|
2769
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2770
|
+
}
|
2771
|
+
static fromString(string, options = {}) {
|
2772
|
+
const base64Content = btoa(string);
|
2773
|
+
return new XataFile({ ...options, base64Content });
|
2774
|
+
}
|
2775
|
+
toString() {
|
2776
|
+
if (!this.base64Content) {
|
2777
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2778
|
+
}
|
2779
|
+
return atob(this.base64Content);
|
2780
|
+
}
|
2781
|
+
static fromBase64(base64Content, options = {}) {
|
2782
|
+
return new XataFile({ ...options, base64Content });
|
1875
2783
|
}
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
2784
|
+
toBase64() {
|
2785
|
+
if (!this.base64Content) {
|
2786
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2787
|
+
}
|
2788
|
+
return this.base64Content;
|
2789
|
+
}
|
2790
|
+
transform(...options) {
|
2791
|
+
return {
|
2792
|
+
url: transformImage(this.url, ...options),
|
2793
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2794
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2795
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2796
|
+
};
|
1882
2797
|
}
|
1883
2798
|
}
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
2799
|
+
const parseInputFileEntry = async (entry) => {
|
2800
|
+
if (!isDefined(entry))
|
2801
|
+
return null;
|
2802
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
2803
|
+
return compactObject({
|
2804
|
+
id,
|
2805
|
+
// Name cannot be an empty string in our API
|
2806
|
+
name: name ? name : void 0,
|
2807
|
+
mediaType,
|
2808
|
+
base64Content,
|
2809
|
+
enablePublicUrl,
|
2810
|
+
signedUrlTimeout,
|
2811
|
+
uploadUrlTimeout
|
1892
2812
|
});
|
1893
|
-
}
|
2813
|
+
};
|
1894
2814
|
|
1895
2815
|
function cleanFilter(filter) {
|
1896
|
-
if (!filter)
|
2816
|
+
if (!isDefined(filter))
|
1897
2817
|
return void 0;
|
1898
|
-
|
1899
|
-
|
2818
|
+
if (!isObject(filter))
|
2819
|
+
return filter;
|
2820
|
+
const values = Object.fromEntries(
|
2821
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2822
|
+
if (!isDefined(value))
|
2823
|
+
return acc;
|
2824
|
+
if (Array.isArray(value)) {
|
2825
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2826
|
+
if (clean.length === 0)
|
2827
|
+
return acc;
|
2828
|
+
return [...acc, [key, clean]];
|
2829
|
+
}
|
2830
|
+
if (isObject(value)) {
|
2831
|
+
const clean = cleanFilter(value);
|
2832
|
+
if (!isDefined(clean))
|
2833
|
+
return acc;
|
2834
|
+
return [...acc, [key, clean]];
|
2835
|
+
}
|
2836
|
+
return [...acc, [key, value]];
|
2837
|
+
}, [])
|
2838
|
+
);
|
2839
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
2840
|
+
}
|
2841
|
+
|
2842
|
+
function stringifyJson(value) {
|
2843
|
+
if (!isDefined(value))
|
2844
|
+
return value;
|
2845
|
+
if (isString(value))
|
2846
|
+
return value;
|
2847
|
+
try {
|
2848
|
+
return JSON.stringify(value);
|
2849
|
+
} catch (e) {
|
2850
|
+
return value;
|
2851
|
+
}
|
2852
|
+
}
|
2853
|
+
function parseJson(value) {
|
2854
|
+
try {
|
2855
|
+
return JSON.parse(value);
|
2856
|
+
} catch (e) {
|
2857
|
+
return value;
|
2858
|
+
}
|
1900
2859
|
}
|
1901
2860
|
|
1902
2861
|
var __accessCheck$6 = (obj, member, msg) => {
|
@@ -1925,31 +2884,59 @@ class Page {
|
|
1925
2884
|
this.meta = meta;
|
1926
2885
|
this.records = new RecordArray(this, records);
|
1927
2886
|
}
|
2887
|
+
/**
|
2888
|
+
* Retrieves the next page of results.
|
2889
|
+
* @param size Maximum number of results to be retrieved.
|
2890
|
+
* @param offset Number of results to skip when retrieving the results.
|
2891
|
+
* @returns The next page or results.
|
2892
|
+
*/
|
1928
2893
|
async nextPage(size, offset) {
|
1929
2894
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1930
2895
|
}
|
2896
|
+
/**
|
2897
|
+
* Retrieves the previous page of results.
|
2898
|
+
* @param size Maximum number of results to be retrieved.
|
2899
|
+
* @param offset Number of results to skip when retrieving the results.
|
2900
|
+
* @returns The previous page or results.
|
2901
|
+
*/
|
1931
2902
|
async previousPage(size, offset) {
|
1932
2903
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1933
2904
|
}
|
2905
|
+
/**
|
2906
|
+
* Retrieves the start page of results.
|
2907
|
+
* @param size Maximum number of results to be retrieved.
|
2908
|
+
* @param offset Number of results to skip when retrieving the results.
|
2909
|
+
* @returns The start page or results.
|
2910
|
+
*/
|
1934
2911
|
async startPage(size, offset) {
|
1935
2912
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1936
2913
|
}
|
2914
|
+
/**
|
2915
|
+
* Retrieves the end page of results.
|
2916
|
+
* @param size Maximum number of results to be retrieved.
|
2917
|
+
* @param offset Number of results to skip when retrieving the results.
|
2918
|
+
* @returns The end page or results.
|
2919
|
+
*/
|
1937
2920
|
async endPage(size, offset) {
|
1938
2921
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1939
2922
|
}
|
2923
|
+
/**
|
2924
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2925
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2926
|
+
*/
|
1940
2927
|
hasNextPage() {
|
1941
2928
|
return this.meta.page.more;
|
1942
2929
|
}
|
1943
2930
|
}
|
1944
2931
|
_query = new WeakMap();
|
1945
|
-
const PAGINATION_MAX_SIZE =
|
2932
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
1946
2933
|
const PAGINATION_DEFAULT_SIZE = 20;
|
1947
|
-
const PAGINATION_MAX_OFFSET =
|
2934
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
1948
2935
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1949
2936
|
function isCursorPaginationOptions(options) {
|
1950
2937
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1951
2938
|
}
|
1952
|
-
const _RecordArray = class extends Array {
|
2939
|
+
const _RecordArray = class _RecordArray extends Array {
|
1953
2940
|
constructor(...args) {
|
1954
2941
|
super(..._RecordArray.parseConstructorParams(...args));
|
1955
2942
|
__privateAdd$6(this, _page, void 0);
|
@@ -1968,31 +2955,60 @@ const _RecordArray = class extends Array {
|
|
1968
2955
|
toArray() {
|
1969
2956
|
return new Array(...this);
|
1970
2957
|
}
|
2958
|
+
toSerializable() {
|
2959
|
+
return JSON.parse(this.toString());
|
2960
|
+
}
|
2961
|
+
toString() {
|
2962
|
+
return JSON.stringify(this.toArray());
|
2963
|
+
}
|
1971
2964
|
map(callbackfn, thisArg) {
|
1972
2965
|
return this.toArray().map(callbackfn, thisArg);
|
1973
2966
|
}
|
2967
|
+
/**
|
2968
|
+
* Retrieve next page of records
|
2969
|
+
*
|
2970
|
+
* @returns A new array of objects
|
2971
|
+
*/
|
1974
2972
|
async nextPage(size, offset) {
|
1975
2973
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1976
2974
|
return new _RecordArray(newPage);
|
1977
2975
|
}
|
2976
|
+
/**
|
2977
|
+
* Retrieve previous page of records
|
2978
|
+
*
|
2979
|
+
* @returns A new array of objects
|
2980
|
+
*/
|
1978
2981
|
async previousPage(size, offset) {
|
1979
2982
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1980
2983
|
return new _RecordArray(newPage);
|
1981
2984
|
}
|
2985
|
+
/**
|
2986
|
+
* Retrieve start page of records
|
2987
|
+
*
|
2988
|
+
* @returns A new array of objects
|
2989
|
+
*/
|
1982
2990
|
async startPage(size, offset) {
|
1983
2991
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1984
2992
|
return new _RecordArray(newPage);
|
1985
2993
|
}
|
2994
|
+
/**
|
2995
|
+
* Retrieve end page of records
|
2996
|
+
*
|
2997
|
+
* @returns A new array of objects
|
2998
|
+
*/
|
1986
2999
|
async endPage(size, offset) {
|
1987
3000
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1988
3001
|
return new _RecordArray(newPage);
|
1989
3002
|
}
|
3003
|
+
/**
|
3004
|
+
* @returns Boolean indicating if there is a next page
|
3005
|
+
*/
|
1990
3006
|
hasNextPage() {
|
1991
3007
|
return __privateGet$6(this, _page).meta.page.more;
|
1992
3008
|
}
|
1993
3009
|
};
|
1994
|
-
let RecordArray = _RecordArray;
|
1995
3010
|
_page = new WeakMap();
|
3011
|
+
let RecordArray = _RecordArray;
|
1996
3012
|
|
1997
3013
|
var __accessCheck$5 = (obj, member, msg) => {
|
1998
3014
|
if (!member.has(obj))
|
@@ -2017,13 +3033,14 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2017
3033
|
return method;
|
2018
3034
|
};
|
2019
3035
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2020
|
-
const _Query = class {
|
3036
|
+
const _Query = class _Query {
|
2021
3037
|
constructor(repository, table, data, rawParent) {
|
2022
3038
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2023
3039
|
__privateAdd$5(this, _table$1, void 0);
|
2024
3040
|
__privateAdd$5(this, _repository, void 0);
|
2025
3041
|
__privateAdd$5(this, _data, { filter: {} });
|
2026
|
-
|
3042
|
+
// Implements pagination
|
3043
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
2027
3044
|
this.records = new RecordArray(this, []);
|
2028
3045
|
__privateSet$5(this, _table$1, table);
|
2029
3046
|
if (repository) {
|
@@ -2039,6 +3056,7 @@ const _Query = class {
|
|
2039
3056
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
2040
3057
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
2041
3058
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
3059
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
2042
3060
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
2043
3061
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2044
3062
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -2059,18 +3077,38 @@ const _Query = class {
|
|
2059
3077
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2060
3078
|
return toBase64(key);
|
2061
3079
|
}
|
3080
|
+
/**
|
3081
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3082
|
+
* @param queries An array of subqueries.
|
3083
|
+
* @returns A new Query object.
|
3084
|
+
*/
|
2062
3085
|
any(...queries) {
|
2063
3086
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2064
3087
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2065
3088
|
}
|
3089
|
+
/**
|
3090
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3091
|
+
* @param queries An array of subqueries.
|
3092
|
+
* @returns A new Query object.
|
3093
|
+
*/
|
2066
3094
|
all(...queries) {
|
2067
3095
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2068
3096
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2069
3097
|
}
|
3098
|
+
/**
|
3099
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3100
|
+
* @param queries An array of subqueries.
|
3101
|
+
* @returns A new Query object.
|
3102
|
+
*/
|
2070
3103
|
not(...queries) {
|
2071
3104
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2072
3105
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2073
3106
|
}
|
3107
|
+
/**
|
3108
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3109
|
+
* @param queries An array of subqueries.
|
3110
|
+
* @returns A new Query object.
|
3111
|
+
*/
|
2074
3112
|
none(...queries) {
|
2075
3113
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2076
3114
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2093,6 +3131,11 @@ const _Query = class {
|
|
2093
3131
|
const sort = [...originalSort, { column, direction }];
|
2094
3132
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2095
3133
|
}
|
3134
|
+
/**
|
3135
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3136
|
+
* @param columns Array of column names to be returned by the query.
|
3137
|
+
* @returns A new Query object.
|
3138
|
+
*/
|
2096
3139
|
select(columns) {
|
2097
3140
|
return new _Query(
|
2098
3141
|
__privateGet$5(this, _repository),
|
@@ -2105,6 +3148,12 @@ const _Query = class {
|
|
2105
3148
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2106
3149
|
return __privateGet$5(this, _repository).query(query);
|
2107
3150
|
}
|
3151
|
+
/**
|
3152
|
+
* Get results in an iterator
|
3153
|
+
*
|
3154
|
+
* @async
|
3155
|
+
* @returns Async interable of results
|
3156
|
+
*/
|
2108
3157
|
async *[Symbol.asyncIterator]() {
|
2109
3158
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2110
3159
|
yield record;
|
@@ -2165,26 +3214,53 @@ const _Query = class {
|
|
2165
3214
|
);
|
2166
3215
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2167
3216
|
}
|
3217
|
+
/**
|
3218
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3219
|
+
* @param ttl The cache TTL in milliseconds.
|
3220
|
+
* @returns A new Query object.
|
3221
|
+
*/
|
2168
3222
|
cache(ttl) {
|
2169
3223
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2170
3224
|
}
|
3225
|
+
/**
|
3226
|
+
* Retrieve next page of records
|
3227
|
+
*
|
3228
|
+
* @returns A new page object.
|
3229
|
+
*/
|
2171
3230
|
nextPage(size, offset) {
|
2172
3231
|
return this.startPage(size, offset);
|
2173
3232
|
}
|
3233
|
+
/**
|
3234
|
+
* Retrieve previous page of records
|
3235
|
+
*
|
3236
|
+
* @returns A new page object
|
3237
|
+
*/
|
2174
3238
|
previousPage(size, offset) {
|
2175
3239
|
return this.startPage(size, offset);
|
2176
3240
|
}
|
3241
|
+
/**
|
3242
|
+
* Retrieve start page of records
|
3243
|
+
*
|
3244
|
+
* @returns A new page object
|
3245
|
+
*/
|
2177
3246
|
startPage(size, offset) {
|
2178
3247
|
return this.getPaginated({ pagination: { size, offset } });
|
2179
3248
|
}
|
3249
|
+
/**
|
3250
|
+
* Retrieve last page of records
|
3251
|
+
*
|
3252
|
+
* @returns A new page object
|
3253
|
+
*/
|
2180
3254
|
endPage(size, offset) {
|
2181
3255
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2182
3256
|
}
|
3257
|
+
/**
|
3258
|
+
* @returns Boolean indicating if there is a next page
|
3259
|
+
*/
|
2183
3260
|
hasNextPage() {
|
2184
3261
|
return this.meta.page.more;
|
2185
3262
|
}
|
2186
3263
|
};
|
2187
|
-
let Query = _Query;
|
2188
3264
|
_table$1 = new WeakMap();
|
2189
3265
|
_repository = new WeakMap();
|
2190
3266
|
_data = new WeakMap();
|
@@ -2199,6 +3275,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2199
3275
|
}
|
2200
3276
|
return value;
|
2201
3277
|
};
|
3278
|
+
let Query = _Query;
|
2202
3279
|
function cleanParent(data, parent) {
|
2203
3280
|
if (isCursorPaginationOptions(data.pagination)) {
|
2204
3281
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2206,6 +3283,21 @@ function cleanParent(data, parent) {
|
|
2206
3283
|
return parent;
|
2207
3284
|
}
|
2208
3285
|
|
3286
|
+
const RecordColumnTypes = [
|
3287
|
+
"bool",
|
3288
|
+
"int",
|
3289
|
+
"float",
|
3290
|
+
"string",
|
3291
|
+
"text",
|
3292
|
+
"email",
|
3293
|
+
"multiple",
|
3294
|
+
"link",
|
3295
|
+
"datetime",
|
3296
|
+
"vector",
|
3297
|
+
"file[]",
|
3298
|
+
"file",
|
3299
|
+
"json"
|
3300
|
+
];
|
2209
3301
|
function isIdentifiable(x) {
|
2210
3302
|
return isObject(x) && isString(x?.id);
|
2211
3303
|
}
|
@@ -2215,11 +3307,33 @@ function isXataRecord(x) {
|
|
2215
3307
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2216
3308
|
}
|
2217
3309
|
|
3310
|
+
function isValidExpandedColumn(column) {
|
3311
|
+
return isObject(column) && isString(column.name);
|
3312
|
+
}
|
3313
|
+
function isValidSelectableColumns(columns) {
|
3314
|
+
if (!Array.isArray(columns)) {
|
3315
|
+
return false;
|
3316
|
+
}
|
3317
|
+
return columns.every((column) => {
|
3318
|
+
if (typeof column === "string") {
|
3319
|
+
return true;
|
3320
|
+
}
|
3321
|
+
if (typeof column === "object") {
|
3322
|
+
return isValidExpandedColumn(column);
|
3323
|
+
}
|
3324
|
+
return false;
|
3325
|
+
});
|
3326
|
+
}
|
3327
|
+
|
2218
3328
|
function isSortFilterString(value) {
|
2219
3329
|
return isString(value);
|
2220
3330
|
}
|
2221
3331
|
function isSortFilterBase(filter) {
|
2222
|
-
return isObject(filter) && Object.
|
3332
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3333
|
+
if (key === "*")
|
3334
|
+
return value === "random";
|
3335
|
+
return value === "asc" || value === "desc";
|
3336
|
+
});
|
2223
3337
|
}
|
2224
3338
|
function isSortFilterObject(filter) {
|
2225
3339
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2260,7 +3374,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2260
3374
|
__accessCheck$4(obj, member, "access private method");
|
2261
3375
|
return method;
|
2262
3376
|
};
|
2263
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
3377
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1, _transformObjectToApi, transformObjectToApi_fn;
|
2264
3378
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2265
3379
|
class Repository extends Query {
|
2266
3380
|
}
|
@@ -2282,6 +3396,7 @@ class RestRepository extends Query {
|
|
2282
3396
|
__privateAdd$4(this, _setCacheQuery);
|
2283
3397
|
__privateAdd$4(this, _getCacheQuery);
|
2284
3398
|
__privateAdd$4(this, _getSchemaTables$1);
|
3399
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2285
3400
|
__privateAdd$4(this, _table, void 0);
|
2286
3401
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2287
3402
|
__privateAdd$4(this, _db, void 0);
|
@@ -2292,10 +3407,7 @@ class RestRepository extends Query {
|
|
2292
3407
|
__privateSet$4(this, _db, options.db);
|
2293
3408
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2294
3409
|
__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
|
-
});
|
3410
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2299
3411
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2300
3412
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2301
3413
|
return trace(name, fn, {
|
@@ -2313,24 +3425,24 @@ class RestRepository extends Query {
|
|
2313
3425
|
if (a.length === 0)
|
2314
3426
|
return [];
|
2315
3427
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2316
|
-
const columns =
|
3428
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2317
3429
|
const result = await this.read(ids, columns);
|
2318
3430
|
return result;
|
2319
3431
|
}
|
2320
3432
|
if (isString(a) && isObject(b)) {
|
2321
3433
|
if (a === "")
|
2322
3434
|
throw new Error("The id can't be empty");
|
2323
|
-
const columns =
|
3435
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2324
3436
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2325
3437
|
}
|
2326
3438
|
if (isObject(a) && isString(a.id)) {
|
2327
3439
|
if (a.id === "")
|
2328
3440
|
throw new Error("The id can't be empty");
|
2329
|
-
const columns =
|
3441
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2330
3442
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2331
3443
|
}
|
2332
3444
|
if (isObject(a)) {
|
2333
|
-
const columns =
|
3445
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2334
3446
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2335
3447
|
}
|
2336
3448
|
throw new Error("Invalid arguments for create method");
|
@@ -2338,7 +3450,7 @@ class RestRepository extends Query {
|
|
2338
3450
|
}
|
2339
3451
|
async read(a, b) {
|
2340
3452
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2341
|
-
const columns =
|
3453
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2342
3454
|
if (Array.isArray(a)) {
|
2343
3455
|
if (a.length === 0)
|
2344
3456
|
return [];
|
@@ -2352,7 +3464,6 @@ class RestRepository extends Query {
|
|
2352
3464
|
}
|
2353
3465
|
const id = extractId(a);
|
2354
3466
|
if (id) {
|
2355
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2356
3467
|
try {
|
2357
3468
|
const response = await getRecord({
|
2358
3469
|
pathParams: {
|
@@ -2363,10 +3474,16 @@ class RestRepository extends Query {
|
|
2363
3474
|
recordId: id
|
2364
3475
|
},
|
2365
3476
|
queryParams: { columns },
|
2366
|
-
...
|
3477
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2367
3478
|
});
|
2368
3479
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2369
|
-
return initObject(
|
3480
|
+
return initObject(
|
3481
|
+
__privateGet$4(this, _db),
|
3482
|
+
schemaTables,
|
3483
|
+
__privateGet$4(this, _table),
|
3484
|
+
response,
|
3485
|
+
columns
|
3486
|
+
);
|
2370
3487
|
} catch (e) {
|
2371
3488
|
if (isObject(e) && e.status === 404) {
|
2372
3489
|
return null;
|
@@ -2408,17 +3525,23 @@ class RestRepository extends Query {
|
|
2408
3525
|
ifVersion,
|
2409
3526
|
upsert: false
|
2410
3527
|
});
|
2411
|
-
const columns =
|
3528
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2412
3529
|
const result = await this.read(a, columns);
|
2413
3530
|
return result;
|
2414
3531
|
}
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
3532
|
+
try {
|
3533
|
+
if (isString(a) && isObject(b)) {
|
3534
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3535
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3536
|
+
}
|
3537
|
+
if (isObject(a) && isString(a.id)) {
|
3538
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3539
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3540
|
+
}
|
3541
|
+
} catch (error) {
|
3542
|
+
if (error.status === 422)
|
3543
|
+
return null;
|
3544
|
+
throw error;
|
2422
3545
|
}
|
2423
3546
|
throw new Error("Invalid arguments for update method");
|
2424
3547
|
});
|
@@ -2452,17 +3575,27 @@ class RestRepository extends Query {
|
|
2452
3575
|
ifVersion,
|
2453
3576
|
upsert: true
|
2454
3577
|
});
|
2455
|
-
const columns =
|
3578
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2456
3579
|
const result = await this.read(a, columns);
|
2457
3580
|
return result;
|
2458
3581
|
}
|
2459
3582
|
if (isString(a) && isObject(b)) {
|
2460
|
-
|
2461
|
-
|
3583
|
+
if (a === "")
|
3584
|
+
throw new Error("The id can't be empty");
|
3585
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3586
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2462
3587
|
}
|
2463
3588
|
if (isObject(a) && isString(a.id)) {
|
2464
|
-
|
2465
|
-
|
3589
|
+
if (a.id === "")
|
3590
|
+
throw new Error("The id can't be empty");
|
3591
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3592
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3593
|
+
}
|
3594
|
+
if (!isDefined(a) && isObject(b)) {
|
3595
|
+
return await this.create(b, c);
|
3596
|
+
}
|
3597
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3598
|
+
return await this.create(a, b);
|
2466
3599
|
}
|
2467
3600
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2468
3601
|
});
|
@@ -2474,17 +3607,27 @@ class RestRepository extends Query {
|
|
2474
3607
|
if (a.length === 0)
|
2475
3608
|
return [];
|
2476
3609
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2477
|
-
const columns =
|
3610
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2478
3611
|
const result = await this.read(ids, columns);
|
2479
3612
|
return result;
|
2480
3613
|
}
|
2481
3614
|
if (isString(a) && isObject(b)) {
|
2482
|
-
|
2483
|
-
|
3615
|
+
if (a === "")
|
3616
|
+
throw new Error("The id can't be empty");
|
3617
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3618
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2484
3619
|
}
|
2485
3620
|
if (isObject(a) && isString(a.id)) {
|
2486
|
-
|
2487
|
-
|
3621
|
+
if (a.id === "")
|
3622
|
+
throw new Error("The id can't be empty");
|
3623
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3624
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3625
|
+
}
|
3626
|
+
if (!isDefined(a) && isObject(b)) {
|
3627
|
+
return await this.create(b, c);
|
3628
|
+
}
|
3629
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3630
|
+
return await this.create(a, b);
|
2488
3631
|
}
|
2489
3632
|
throw new Error("Invalid arguments for createOrReplace method");
|
2490
3633
|
});
|
@@ -2501,7 +3644,7 @@ class RestRepository extends Query {
|
|
2501
3644
|
return o.id;
|
2502
3645
|
throw new Error("Invalid arguments for delete method");
|
2503
3646
|
});
|
2504
|
-
const columns =
|
3647
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2505
3648
|
const result = await this.read(a, columns);
|
2506
3649
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2507
3650
|
return result;
|
@@ -2535,8 +3678,7 @@ class RestRepository extends Query {
|
|
2535
3678
|
}
|
2536
3679
|
async search(query, options = {}) {
|
2537
3680
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2538
|
-
const
|
2539
|
-
const { records } = await searchTable({
|
3681
|
+
const { records, totalCount } = await searchTable({
|
2540
3682
|
pathParams: {
|
2541
3683
|
workspace: "{workspaceId}",
|
2542
3684
|
dbBranchName: "{dbBranch}",
|
@@ -2549,17 +3691,46 @@ class RestRepository extends Query {
|
|
2549
3691
|
prefix: options.prefix,
|
2550
3692
|
highlight: options.highlight,
|
2551
3693
|
filter: options.filter,
|
2552
|
-
boosters: options.boosters
|
3694
|
+
boosters: options.boosters,
|
3695
|
+
page: options.page,
|
3696
|
+
target: options.target
|
2553
3697
|
},
|
2554
|
-
...
|
3698
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2555
3699
|
});
|
2556
3700
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2557
|
-
return
|
3701
|
+
return {
|
3702
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3703
|
+
totalCount
|
3704
|
+
};
|
3705
|
+
});
|
3706
|
+
}
|
3707
|
+
async vectorSearch(column, query, options) {
|
3708
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3709
|
+
const { records, totalCount } = await vectorSearchTable({
|
3710
|
+
pathParams: {
|
3711
|
+
workspace: "{workspaceId}",
|
3712
|
+
dbBranchName: "{dbBranch}",
|
3713
|
+
region: "{region}",
|
3714
|
+
tableName: __privateGet$4(this, _table)
|
3715
|
+
},
|
3716
|
+
body: {
|
3717
|
+
column,
|
3718
|
+
queryVector: query,
|
3719
|
+
similarityFunction: options?.similarityFunction,
|
3720
|
+
size: options?.size,
|
3721
|
+
filter: options?.filter
|
3722
|
+
},
|
3723
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3724
|
+
});
|
3725
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3726
|
+
return {
|
3727
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3728
|
+
totalCount
|
3729
|
+
};
|
2558
3730
|
});
|
2559
3731
|
}
|
2560
3732
|
async aggregate(aggs, filter) {
|
2561
3733
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2562
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2563
3734
|
const result = await aggregateTable({
|
2564
3735
|
pathParams: {
|
2565
3736
|
workspace: "{workspaceId}",
|
@@ -2568,7 +3739,7 @@ class RestRepository extends Query {
|
|
2568
3739
|
tableName: __privateGet$4(this, _table)
|
2569
3740
|
},
|
2570
3741
|
body: { aggs, filter },
|
2571
|
-
...
|
3742
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2572
3743
|
});
|
2573
3744
|
return result;
|
2574
3745
|
});
|
@@ -2579,7 +3750,6 @@ class RestRepository extends Query {
|
|
2579
3750
|
if (cacheQuery)
|
2580
3751
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2581
3752
|
const data = query.getQueryOptions();
|
2582
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2583
3753
|
const { meta, records: objects } = await queryTable({
|
2584
3754
|
pathParams: {
|
2585
3755
|
workspace: "{workspaceId}",
|
@@ -2591,14 +3761,21 @@ class RestRepository extends Query {
|
|
2591
3761
|
filter: cleanFilter(data.filter),
|
2592
3762
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2593
3763
|
page: data.pagination,
|
2594
|
-
columns: data.columns ?? ["*"]
|
3764
|
+
columns: data.columns ?? ["*"],
|
3765
|
+
consistency: data.consistency
|
2595
3766
|
},
|
2596
3767
|
fetchOptions: data.fetchOptions,
|
2597
|
-
...
|
3768
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2598
3769
|
});
|
2599
3770
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2600
3771
|
const records = objects.map(
|
2601
|
-
(record) => initObject(
|
3772
|
+
(record) => initObject(
|
3773
|
+
__privateGet$4(this, _db),
|
3774
|
+
schemaTables,
|
3775
|
+
__privateGet$4(this, _table),
|
3776
|
+
record,
|
3777
|
+
data.columns ?? ["*"]
|
3778
|
+
)
|
2602
3779
|
);
|
2603
3780
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2604
3781
|
return new Page(query, meta, records);
|
@@ -2607,7 +3784,6 @@ class RestRepository extends Query {
|
|
2607
3784
|
async summarizeTable(query, summaries, summariesFilter) {
|
2608
3785
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2609
3786
|
const data = query.getQueryOptions();
|
2610
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2611
3787
|
const result = await summarizeTable({
|
2612
3788
|
pathParams: {
|
2613
3789
|
workspace: "{workspaceId}",
|
@@ -2619,15 +3795,55 @@ class RestRepository extends Query {
|
|
2619
3795
|
filter: cleanFilter(data.filter),
|
2620
3796
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2621
3797
|
columns: data.columns,
|
3798
|
+
consistency: data.consistency,
|
2622
3799
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2623
3800
|
summaries,
|
2624
3801
|
summariesFilter
|
2625
3802
|
},
|
2626
|
-
...
|
3803
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2627
3804
|
});
|
2628
|
-
|
3805
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3806
|
+
return {
|
3807
|
+
...result,
|
3808
|
+
summaries: result.summaries.map(
|
3809
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3810
|
+
)
|
3811
|
+
};
|
2629
3812
|
});
|
2630
3813
|
}
|
3814
|
+
ask(question, options) {
|
3815
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3816
|
+
const params = {
|
3817
|
+
pathParams: {
|
3818
|
+
workspace: "{workspaceId}",
|
3819
|
+
dbBranchName: "{dbBranch}",
|
3820
|
+
region: "{region}",
|
3821
|
+
tableName: __privateGet$4(this, _table),
|
3822
|
+
sessionId: options?.sessionId
|
3823
|
+
},
|
3824
|
+
body: {
|
3825
|
+
...questionParam,
|
3826
|
+
rules: options?.rules,
|
3827
|
+
searchType: options?.searchType,
|
3828
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3829
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3830
|
+
},
|
3831
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3832
|
+
};
|
3833
|
+
if (options?.onMessage) {
|
3834
|
+
fetchSSERequest({
|
3835
|
+
endpoint: "dataPlane",
|
3836
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3837
|
+
method: "POST",
|
3838
|
+
onMessage: (message) => {
|
3839
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3840
|
+
},
|
3841
|
+
...params
|
3842
|
+
});
|
3843
|
+
} else {
|
3844
|
+
return askTableSession(params);
|
3845
|
+
}
|
3846
|
+
}
|
2631
3847
|
}
|
2632
3848
|
_table = new WeakMap();
|
2633
3849
|
_getFetchProps = new WeakMap();
|
@@ -2637,8 +3853,7 @@ _schemaTables$2 = new WeakMap();
|
|
2637
3853
|
_trace = new WeakMap();
|
2638
3854
|
_insertRecordWithoutId = new WeakSet();
|
2639
3855
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2640
|
-
const
|
2641
|
-
const record = transformObjectLinks(object);
|
3856
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2642
3857
|
const response = await insertRecord({
|
2643
3858
|
pathParams: {
|
2644
3859
|
workspace: "{workspaceId}",
|
@@ -2648,15 +3863,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2648
3863
|
},
|
2649
3864
|
queryParams: { columns },
|
2650
3865
|
body: record,
|
2651
|
-
...
|
3866
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2652
3867
|
});
|
2653
3868
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2654
3869
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2655
3870
|
};
|
2656
3871
|
_insertRecordWithId = new WeakSet();
|
2657
3872
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2658
|
-
|
2659
|
-
|
3873
|
+
if (!recordId)
|
3874
|
+
return null;
|
3875
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2660
3876
|
const response = await insertRecordWithID({
|
2661
3877
|
pathParams: {
|
2662
3878
|
workspace: "{workspaceId}",
|
@@ -2667,30 +3883,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2667
3883
|
},
|
2668
3884
|
body: record,
|
2669
3885
|
queryParams: { createOnly, columns, ifVersion },
|
2670
|
-
...
|
3886
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2671
3887
|
});
|
2672
3888
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2673
3889
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2674
3890
|
};
|
2675
3891
|
_insertRecords = new WeakSet();
|
2676
3892
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2677
|
-
const
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
|
2682
|
-
BULK_OPERATION_MAX_SIZE
|
2683
|
-
);
|
3893
|
+
const operations = await promiseMap(objects, async (object) => {
|
3894
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3895
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3896
|
+
});
|
3897
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2684
3898
|
const ids = [];
|
2685
|
-
for (const
|
3899
|
+
for (const operations2 of chunkedOperations) {
|
2686
3900
|
const { results } = await branchTransaction({
|
2687
3901
|
pathParams: {
|
2688
3902
|
workspace: "{workspaceId}",
|
2689
3903
|
dbBranchName: "{dbBranch}",
|
2690
3904
|
region: "{region}"
|
2691
3905
|
},
|
2692
|
-
body: { operations },
|
2693
|
-
...
|
3906
|
+
body: { operations: operations2 },
|
3907
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2694
3908
|
});
|
2695
3909
|
for (const result of results) {
|
2696
3910
|
if (result.operation === "insert") {
|
@@ -2704,8 +3918,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2704
3918
|
};
|
2705
3919
|
_updateRecordWithID = new WeakSet();
|
2706
3920
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2707
|
-
|
2708
|
-
|
3921
|
+
if (!recordId)
|
3922
|
+
return null;
|
3923
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2709
3924
|
try {
|
2710
3925
|
const response = await updateRecordWithID({
|
2711
3926
|
pathParams: {
|
@@ -2717,7 +3932,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2717
3932
|
},
|
2718
3933
|
queryParams: { columns, ifVersion },
|
2719
3934
|
body: record,
|
2720
|
-
...
|
3935
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2721
3936
|
});
|
2722
3937
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2723
3938
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2730,23 +3945,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2730
3945
|
};
|
2731
3946
|
_updateRecords = new WeakSet();
|
2732
3947
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2733
|
-
const
|
2734
|
-
|
2735
|
-
|
2736
|
-
|
2737
|
-
|
2738
|
-
BULK_OPERATION_MAX_SIZE
|
2739
|
-
);
|
3948
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3949
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3950
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3951
|
+
});
|
3952
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2740
3953
|
const ids = [];
|
2741
|
-
for (const
|
3954
|
+
for (const operations2 of chunkedOperations) {
|
2742
3955
|
const { results } = await branchTransaction({
|
2743
3956
|
pathParams: {
|
2744
3957
|
workspace: "{workspaceId}",
|
2745
3958
|
dbBranchName: "{dbBranch}",
|
2746
3959
|
region: "{region}"
|
2747
3960
|
},
|
2748
|
-
body: { operations },
|
2749
|
-
...
|
3961
|
+
body: { operations: operations2 },
|
3962
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2750
3963
|
});
|
2751
3964
|
for (const result of results) {
|
2752
3965
|
if (result.operation === "update") {
|
@@ -2760,7 +3973,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2760
3973
|
};
|
2761
3974
|
_upsertRecordWithID = new WeakSet();
|
2762
3975
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2763
|
-
|
3976
|
+
if (!recordId)
|
3977
|
+
return null;
|
2764
3978
|
const response = await upsertRecordWithID({
|
2765
3979
|
pathParams: {
|
2766
3980
|
workspace: "{workspaceId}",
|
@@ -2771,14 +3985,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2771
3985
|
},
|
2772
3986
|
queryParams: { columns, ifVersion },
|
2773
3987
|
body: object,
|
2774
|
-
...
|
3988
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2775
3989
|
});
|
2776
3990
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2777
3991
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2778
3992
|
};
|
2779
3993
|
_deleteRecord = new WeakSet();
|
2780
3994
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2781
|
-
|
3995
|
+
if (!recordId)
|
3996
|
+
return null;
|
2782
3997
|
try {
|
2783
3998
|
const response = await deleteRecord({
|
2784
3999
|
pathParams: {
|
@@ -2789,7 +4004,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2789
4004
|
recordId
|
2790
4005
|
},
|
2791
4006
|
queryParams: { columns },
|
2792
|
-
...
|
4007
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2793
4008
|
});
|
2794
4009
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2795
4010
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2802,9 +4017,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2802
4017
|
};
|
2803
4018
|
_deleteRecords = new WeakSet();
|
2804
4019
|
deleteRecords_fn = async function(recordIds) {
|
2805
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2806
4020
|
const chunkedOperations = chunk(
|
2807
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
4021
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2808
4022
|
BULK_OPERATION_MAX_SIZE
|
2809
4023
|
);
|
2810
4024
|
for (const operations of chunkedOperations) {
|
@@ -2815,21 +4029,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2815
4029
|
region: "{region}"
|
2816
4030
|
},
|
2817
4031
|
body: { operations },
|
2818
|
-
...
|
4032
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2819
4033
|
});
|
2820
4034
|
}
|
2821
4035
|
};
|
2822
4036
|
_setCacheQuery = new WeakSet();
|
2823
4037
|
setCacheQuery_fn = async function(query, meta, records) {
|
2824
|
-
await __privateGet$4(this, _cache)
|
4038
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2825
4039
|
};
|
2826
4040
|
_getCacheQuery = new WeakSet();
|
2827
4041
|
getCacheQuery_fn = async function(query) {
|
2828
4042
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2829
|
-
const result = await __privateGet$4(this, _cache)
|
4043
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2830
4044
|
if (!result)
|
2831
4045
|
return null;
|
2832
|
-
const
|
4046
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4047
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2833
4048
|
if (ttl < 0)
|
2834
4049
|
return null;
|
2835
4050
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2839,39 +4054,66 @@ _getSchemaTables$1 = new WeakSet();
|
|
2839
4054
|
getSchemaTables_fn$1 = async function() {
|
2840
4055
|
if (__privateGet$4(this, _schemaTables$2))
|
2841
4056
|
return __privateGet$4(this, _schemaTables$2);
|
2842
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2843
4057
|
const { schema } = await getBranchDetails({
|
2844
4058
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2845
|
-
...
|
4059
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2846
4060
|
});
|
2847
4061
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2848
4062
|
return schema.tables;
|
2849
4063
|
};
|
2850
|
-
|
2851
|
-
|
4064
|
+
_transformObjectToApi = new WeakSet();
|
4065
|
+
transformObjectToApi_fn = async function(object) {
|
4066
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4067
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4068
|
+
if (!schema)
|
4069
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4070
|
+
const result = {};
|
4071
|
+
for (const [key, value] of Object.entries(object)) {
|
2852
4072
|
if (key === "xata")
|
2853
|
-
|
2854
|
-
|
2855
|
-
|
4073
|
+
continue;
|
4074
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4075
|
+
switch (type) {
|
4076
|
+
case "link": {
|
4077
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4078
|
+
break;
|
4079
|
+
}
|
4080
|
+
case "datetime": {
|
4081
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4082
|
+
break;
|
4083
|
+
}
|
4084
|
+
case `file`:
|
4085
|
+
result[key] = await parseInputFileEntry(value);
|
4086
|
+
break;
|
4087
|
+
case "file[]":
|
4088
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4089
|
+
break;
|
4090
|
+
case "json":
|
4091
|
+
result[key] = stringifyJson(value);
|
4092
|
+
break;
|
4093
|
+
default:
|
4094
|
+
result[key] = value;
|
4095
|
+
}
|
4096
|
+
}
|
4097
|
+
return result;
|
2856
4098
|
};
|
2857
4099
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2858
|
-
const
|
4100
|
+
const data = {};
|
2859
4101
|
const { xata, ...rest } = object ?? {};
|
2860
|
-
Object.assign(
|
4102
|
+
Object.assign(data, rest);
|
2861
4103
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2862
4104
|
if (!columns)
|
2863
4105
|
console.error(`Table ${table} not found in schema`);
|
2864
4106
|
for (const column of columns ?? []) {
|
2865
4107
|
if (!isValidColumn(selectedColumns, column))
|
2866
4108
|
continue;
|
2867
|
-
const value =
|
4109
|
+
const value = data[column.name];
|
2868
4110
|
switch (column.type) {
|
2869
4111
|
case "datetime": {
|
2870
4112
|
const date = value !== void 0 ? new Date(value) : null;
|
2871
4113
|
if (date !== null && isNaN(date.getTime())) {
|
2872
4114
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2873
4115
|
} else {
|
2874
|
-
|
4116
|
+
data[column.name] = date;
|
2875
4117
|
}
|
2876
4118
|
break;
|
2877
4119
|
}
|
@@ -2884,50 +4126,76 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2884
4126
|
if (item === column.name) {
|
2885
4127
|
return [...acc, "*"];
|
2886
4128
|
}
|
2887
|
-
if (item.startsWith(`${column.name}.`)) {
|
4129
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2888
4130
|
const [, ...path] = item.split(".");
|
2889
4131
|
return [...acc, path.join(".")];
|
2890
4132
|
}
|
2891
4133
|
return acc;
|
2892
4134
|
}, []);
|
2893
|
-
|
4135
|
+
data[column.name] = initObject(
|
4136
|
+
db,
|
4137
|
+
schemaTables,
|
4138
|
+
linkTable,
|
4139
|
+
value,
|
4140
|
+
selectedLinkColumns
|
4141
|
+
);
|
2894
4142
|
} else {
|
2895
|
-
|
4143
|
+
data[column.name] = null;
|
2896
4144
|
}
|
2897
4145
|
break;
|
2898
4146
|
}
|
4147
|
+
case "file":
|
4148
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4149
|
+
break;
|
4150
|
+
case "file[]":
|
4151
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4152
|
+
break;
|
4153
|
+
case "json":
|
4154
|
+
data[column.name] = parseJson(value);
|
4155
|
+
break;
|
2899
4156
|
default:
|
2900
|
-
|
4157
|
+
data[column.name] = value ?? null;
|
2901
4158
|
if (column.notNull === true && value === null) {
|
2902
4159
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2903
4160
|
}
|
2904
4161
|
break;
|
2905
4162
|
}
|
2906
4163
|
}
|
2907
|
-
|
2908
|
-
|
4164
|
+
const record = { ...data };
|
4165
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4166
|
+
record.read = function(columns2) {
|
4167
|
+
return db[table].read(record["id"], columns2);
|
2909
4168
|
};
|
2910
|
-
|
2911
|
-
const columns2 =
|
4169
|
+
record.update = function(data2, b, c) {
|
4170
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2912
4171
|
const ifVersion = parseIfVersion(b, c);
|
2913
|
-
return db[table].update(
|
4172
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2914
4173
|
};
|
2915
|
-
|
2916
|
-
const columns2 =
|
4174
|
+
record.replace = function(data2, b, c) {
|
4175
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2917
4176
|
const ifVersion = parseIfVersion(b, c);
|
2918
|
-
return db[table].createOrReplace(
|
4177
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
2919
4178
|
};
|
2920
|
-
|
2921
|
-
return db[table].delete(
|
4179
|
+
record.delete = function() {
|
4180
|
+
return db[table].delete(record["id"]);
|
2922
4181
|
};
|
2923
|
-
|
2924
|
-
|
4182
|
+
if (metadata !== void 0) {
|
4183
|
+
record.xata = Object.freeze(metadata);
|
4184
|
+
}
|
4185
|
+
record.getMetadata = function() {
|
4186
|
+
return record.xata;
|
4187
|
+
};
|
4188
|
+
record.toSerializable = function() {
|
4189
|
+
return JSON.parse(JSON.stringify(record));
|
2925
4190
|
};
|
2926
|
-
|
2927
|
-
|
4191
|
+
record.toString = function() {
|
4192
|
+
return JSON.stringify(record);
|
4193
|
+
};
|
4194
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4195
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2928
4196
|
}
|
2929
|
-
Object.freeze(
|
2930
|
-
return
|
4197
|
+
Object.freeze(record);
|
4198
|
+
return record;
|
2931
4199
|
};
|
2932
4200
|
function extractId(value) {
|
2933
4201
|
if (isString(value))
|
@@ -2939,11 +4207,7 @@ function extractId(value) {
|
|
2939
4207
|
function isValidColumn(columns, column) {
|
2940
4208
|
if (columns.includes("*"))
|
2941
4209
|
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);
|
4210
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
2947
4211
|
}
|
2948
4212
|
function parseIfVersion(...args) {
|
2949
4213
|
for (const arg of args) {
|
@@ -3020,10 +4284,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
3020
4284
|
const startsWith = (value) => ({ $startsWith: value });
|
3021
4285
|
const endsWith = (value) => ({ $endsWith: value });
|
3022
4286
|
const pattern = (value) => ({ $pattern: value });
|
4287
|
+
const iPattern = (value) => ({ $iPattern: value });
|
3023
4288
|
const is = (value) => ({ $is: value });
|
3024
4289
|
const equals = is;
|
3025
4290
|
const isNot = (value) => ({ $isNot: value });
|
3026
4291
|
const contains = (value) => ({ $contains: value });
|
4292
|
+
const iContains = (value) => ({ $iContains: value });
|
3027
4293
|
const includes = (value) => ({ $includes: value });
|
3028
4294
|
const includesAll = (value) => ({ $includesAll: value });
|
3029
4295
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -3079,6 +4345,80 @@ class SchemaPlugin extends XataPlugin {
|
|
3079
4345
|
_tables = new WeakMap();
|
3080
4346
|
_schemaTables$1 = new WeakMap();
|
3081
4347
|
|
4348
|
+
class FilesPlugin extends XataPlugin {
|
4349
|
+
build(pluginOptions) {
|
4350
|
+
return {
|
4351
|
+
download: async (location) => {
|
4352
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4353
|
+
return await getFileItem({
|
4354
|
+
pathParams: {
|
4355
|
+
workspace: "{workspaceId}",
|
4356
|
+
dbBranchName: "{dbBranch}",
|
4357
|
+
region: "{region}",
|
4358
|
+
tableName: table ?? "",
|
4359
|
+
recordId: record ?? "",
|
4360
|
+
columnName: column ?? "",
|
4361
|
+
fileId
|
4362
|
+
},
|
4363
|
+
...pluginOptions,
|
4364
|
+
rawResponse: true
|
4365
|
+
});
|
4366
|
+
},
|
4367
|
+
upload: async (location, file, options) => {
|
4368
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4369
|
+
const resolvedFile = await file;
|
4370
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4371
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4372
|
+
return await putFileItem({
|
4373
|
+
...pluginOptions,
|
4374
|
+
pathParams: {
|
4375
|
+
workspace: "{workspaceId}",
|
4376
|
+
dbBranchName: "{dbBranch}",
|
4377
|
+
region: "{region}",
|
4378
|
+
tableName: table ?? "",
|
4379
|
+
recordId: record ?? "",
|
4380
|
+
columnName: column ?? "",
|
4381
|
+
fileId
|
4382
|
+
},
|
4383
|
+
body,
|
4384
|
+
headers: { "Content-Type": contentType }
|
4385
|
+
});
|
4386
|
+
},
|
4387
|
+
delete: async (location) => {
|
4388
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4389
|
+
return await deleteFileItem({
|
4390
|
+
pathParams: {
|
4391
|
+
workspace: "{workspaceId}",
|
4392
|
+
dbBranchName: "{dbBranch}",
|
4393
|
+
region: "{region}",
|
4394
|
+
tableName: table ?? "",
|
4395
|
+
recordId: record ?? "",
|
4396
|
+
columnName: column ?? "",
|
4397
|
+
fileId
|
4398
|
+
},
|
4399
|
+
...pluginOptions
|
4400
|
+
});
|
4401
|
+
}
|
4402
|
+
};
|
4403
|
+
}
|
4404
|
+
}
|
4405
|
+
function getContentType(file) {
|
4406
|
+
if (typeof file === "string") {
|
4407
|
+
return "text/plain";
|
4408
|
+
}
|
4409
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
4410
|
+
return file.mediaType;
|
4411
|
+
}
|
4412
|
+
if (isBlob(file)) {
|
4413
|
+
return file.type;
|
4414
|
+
}
|
4415
|
+
try {
|
4416
|
+
return file.type;
|
4417
|
+
} catch (e) {
|
4418
|
+
}
|
4419
|
+
return "application/octet-stream";
|
4420
|
+
}
|
4421
|
+
|
3082
4422
|
var __accessCheck$1 = (obj, member, msg) => {
|
3083
4423
|
if (!member.has(obj))
|
3084
4424
|
throw TypeError("Cannot " + msg);
|
@@ -3111,63 +4451,137 @@ class SearchPlugin extends XataPlugin {
|
|
3111
4451
|
__privateAdd$1(this, _schemaTables, void 0);
|
3112
4452
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3113
4453
|
}
|
3114
|
-
build(
|
4454
|
+
build(pluginOptions) {
|
3115
4455
|
return {
|
3116
4456
|
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,
|
3119
|
-
return
|
3120
|
-
|
3121
|
-
|
3122
|
-
|
4457
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4458
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4459
|
+
return {
|
4460
|
+
totalCount,
|
4461
|
+
records: records.map((record) => {
|
4462
|
+
const { table = "orphan" } = record.xata;
|
4463
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4464
|
+
})
|
4465
|
+
};
|
3123
4466
|
},
|
3124
4467
|
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,
|
3127
|
-
|
4468
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4469
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4470
|
+
const records = rawRecords.reduce((acc, record) => {
|
3128
4471
|
const { table = "orphan" } = record.xata;
|
3129
4472
|
const items = acc[table] ?? [];
|
3130
4473
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
3131
4474
|
return { ...acc, [table]: [...items, item] };
|
3132
4475
|
}, {});
|
4476
|
+
return { totalCount, records };
|
3133
4477
|
}
|
3134
4478
|
};
|
3135
4479
|
}
|
3136
4480
|
}
|
3137
4481
|
_schemaTables = new WeakMap();
|
3138
4482
|
_search = new WeakSet();
|
3139
|
-
search_fn = async function(query, options,
|
3140
|
-
const
|
3141
|
-
const {
|
3142
|
-
const { records } = await searchBranch({
|
4483
|
+
search_fn = async function(query, options, pluginOptions) {
|
4484
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4485
|
+
const { records, totalCount } = await searchBranch({
|
3143
4486
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3144
|
-
|
3145
|
-
|
4487
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4488
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
4489
|
+
...pluginOptions
|
3146
4490
|
});
|
3147
|
-
return records;
|
4491
|
+
return { records, totalCount };
|
3148
4492
|
};
|
3149
4493
|
_getSchemaTables = new WeakSet();
|
3150
|
-
getSchemaTables_fn = async function(
|
4494
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3151
4495
|
if (__privateGet$1(this, _schemaTables))
|
3152
4496
|
return __privateGet$1(this, _schemaTables);
|
3153
|
-
const fetchProps = await getFetchProps();
|
3154
4497
|
const { schema } = await getBranchDetails({
|
3155
4498
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3156
|
-
...
|
4499
|
+
...pluginOptions
|
3157
4500
|
});
|
3158
4501
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3159
4502
|
return schema.tables;
|
3160
4503
|
};
|
3161
4504
|
|
4505
|
+
function escapeElement(elementRepresentation) {
|
4506
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4507
|
+
return '"' + escaped + '"';
|
4508
|
+
}
|
4509
|
+
function arrayString(val) {
|
4510
|
+
let result = "{";
|
4511
|
+
for (let i = 0; i < val.length; i++) {
|
4512
|
+
if (i > 0) {
|
4513
|
+
result = result + ",";
|
4514
|
+
}
|
4515
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4516
|
+
result = result + "NULL";
|
4517
|
+
} else if (Array.isArray(val[i])) {
|
4518
|
+
result = result + arrayString(val[i]);
|
4519
|
+
} else if (val[i] instanceof Buffer) {
|
4520
|
+
result += "\\\\x" + val[i].toString("hex");
|
4521
|
+
} else {
|
4522
|
+
result += escapeElement(prepareValue(val[i]));
|
4523
|
+
}
|
4524
|
+
}
|
4525
|
+
result = result + "}";
|
4526
|
+
return result;
|
4527
|
+
}
|
4528
|
+
function prepareValue(value) {
|
4529
|
+
if (!isDefined(value))
|
4530
|
+
return null;
|
4531
|
+
if (value instanceof Date) {
|
4532
|
+
return value.toISOString();
|
4533
|
+
}
|
4534
|
+
if (Array.isArray(value)) {
|
4535
|
+
return arrayString(value);
|
4536
|
+
}
|
4537
|
+
if (isObject(value)) {
|
4538
|
+
return JSON.stringify(value);
|
4539
|
+
}
|
4540
|
+
try {
|
4541
|
+
return value.toString();
|
4542
|
+
} catch (e) {
|
4543
|
+
return value;
|
4544
|
+
}
|
4545
|
+
}
|
4546
|
+
function prepareParams(param1, param2) {
|
4547
|
+
if (isString(param1)) {
|
4548
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4549
|
+
}
|
4550
|
+
if (isStringArray(param1)) {
|
4551
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4552
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4553
|
+
}, "");
|
4554
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4555
|
+
}
|
4556
|
+
if (isObject(param1)) {
|
4557
|
+
const { statement, params, consistency } = param1;
|
4558
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4559
|
+
}
|
4560
|
+
throw new Error("Invalid query");
|
4561
|
+
}
|
4562
|
+
|
4563
|
+
class SQLPlugin extends XataPlugin {
|
4564
|
+
build(pluginOptions) {
|
4565
|
+
return async (param1, ...param2) => {
|
4566
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4567
|
+
const { records, warning, columns } = await sqlQuery({
|
4568
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4569
|
+
body: { statement, params, consistency },
|
4570
|
+
...pluginOptions
|
4571
|
+
});
|
4572
|
+
return { records, warning, columns };
|
4573
|
+
};
|
4574
|
+
}
|
4575
|
+
}
|
4576
|
+
|
3162
4577
|
class TransactionPlugin extends XataPlugin {
|
3163
|
-
build(
|
4578
|
+
build(pluginOptions) {
|
3164
4579
|
return {
|
3165
4580
|
run: async (operations) => {
|
3166
|
-
const fetchProps = await getFetchProps();
|
3167
4581
|
const response = await branchTransaction({
|
3168
4582
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3169
4583
|
body: { operations },
|
3170
|
-
...
|
4584
|
+
...pluginOptions
|
3171
4585
|
});
|
3172
4586
|
return response;
|
3173
4587
|
}
|
@@ -3175,93 +4589,6 @@ class TransactionPlugin extends XataPlugin {
|
|
3175
4589
|
}
|
3176
4590
|
}
|
3177
4591
|
|
3178
|
-
const isBranchStrategyBuilder = (strategy) => {
|
3179
|
-
return typeof strategy === "function";
|
3180
|
-
};
|
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
4592
|
var __accessCheck = (obj, member, msg) => {
|
3266
4593
|
if (!member.has(obj))
|
3267
4594
|
throw TypeError("Cannot " + msg);
|
@@ -3285,48 +4612,43 @@ var __privateMethod = (obj, member, method) => {
|
|
3285
4612
|
return method;
|
3286
4613
|
};
|
3287
4614
|
const buildClient = (plugins) => {
|
3288
|
-
var
|
4615
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3289
4616
|
return _a = class {
|
3290
4617
|
constructor(options = {}, schemaTables) {
|
3291
4618
|
__privateAdd(this, _parseOptions);
|
3292
4619
|
__privateAdd(this, _getFetchProps);
|
3293
|
-
__privateAdd(this, _evaluateBranch);
|
3294
|
-
__privateAdd(this, _branch, void 0);
|
3295
4620
|
__privateAdd(this, _options, void 0);
|
3296
4621
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3297
4622
|
__privateSet(this, _options, safeOptions);
|
3298
4623
|
const pluginOptions = {
|
3299
|
-
|
4624
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3300
4625
|
cache: safeOptions.cache,
|
3301
|
-
|
4626
|
+
host: safeOptions.host
|
3302
4627
|
};
|
3303
4628
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3304
4629
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3305
4630
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4631
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4632
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3306
4633
|
this.db = db;
|
3307
4634
|
this.search = search;
|
3308
4635
|
this.transactions = transactions;
|
4636
|
+
this.sql = sql;
|
4637
|
+
this.files = files;
|
3309
4638
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3310
4639
|
if (namespace === void 0)
|
3311
4640
|
continue;
|
3312
|
-
|
3313
|
-
if (result instanceof Promise) {
|
3314
|
-
void result.then((namespace2) => {
|
3315
|
-
this[key] = namespace2;
|
3316
|
-
});
|
3317
|
-
} else {
|
3318
|
-
this[key] = result;
|
3319
|
-
}
|
4641
|
+
this[key] = namespace.build(pluginOptions);
|
3320
4642
|
}
|
3321
4643
|
}
|
3322
4644
|
async getConfig() {
|
3323
4645
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3324
|
-
const branch =
|
4646
|
+
const branch = __privateGet(this, _options).branch;
|
3325
4647
|
return { databaseURL, branch };
|
3326
4648
|
}
|
3327
|
-
},
|
4649
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3328
4650
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3329
|
-
const isBrowser = typeof window !== "undefined";
|
4651
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3330
4652
|
if (isBrowser && !enableBrowser) {
|
3331
4653
|
throw new Error(
|
3332
4654
|
"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,46 +4659,73 @@ const buildClient = (plugins) => {
|
|
3337
4659
|
const apiKey = options?.apiKey || getAPIKey();
|
3338
4660
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3339
4661
|
const trace = options?.trace ?? defaultTrace;
|
3340
|
-
const
|
4662
|
+
const clientName = options?.clientName;
|
4663
|
+
const host = options?.host ?? "production";
|
4664
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3341
4665
|
if (!apiKey) {
|
3342
4666
|
throw new Error("Option apiKey is required");
|
3343
4667
|
}
|
3344
4668
|
if (!databaseURL) {
|
3345
4669
|
throw new Error("Option databaseURL is required");
|
3346
4670
|
}
|
3347
|
-
|
3348
|
-
|
3349
|
-
const
|
3350
|
-
if (
|
3351
|
-
|
4671
|
+
const envBranch = getBranch();
|
4672
|
+
const previewBranch = getPreviewBranch();
|
4673
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4674
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4675
|
+
console.warn(
|
4676
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4677
|
+
);
|
4678
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4679
|
+
console.warn(
|
4680
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4681
|
+
);
|
4682
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4683
|
+
console.warn(
|
4684
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4685
|
+
);
|
4686
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4687
|
+
console.warn(
|
4688
|
+
`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.`
|
4689
|
+
);
|
4690
|
+
}
|
4691
|
+
return {
|
4692
|
+
fetch,
|
4693
|
+
databaseURL,
|
4694
|
+
apiKey,
|
4695
|
+
branch,
|
4696
|
+
cache,
|
4697
|
+
trace,
|
4698
|
+
host,
|
4699
|
+
clientID: generateUUID(),
|
4700
|
+
enableBrowser,
|
4701
|
+
clientName,
|
4702
|
+
xataAgentExtra
|
4703
|
+
};
|
4704
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4705
|
+
fetch,
|
4706
|
+
apiKey,
|
4707
|
+
databaseURL,
|
4708
|
+
branch,
|
4709
|
+
trace,
|
4710
|
+
clientID,
|
4711
|
+
clientName,
|
4712
|
+
xataAgentExtra
|
4713
|
+
}) {
|
3352
4714
|
return {
|
3353
|
-
|
4715
|
+
fetch,
|
3354
4716
|
apiKey,
|
3355
4717
|
apiUrl: "",
|
4718
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3356
4719
|
workspacesApiUrl: (path, params) => {
|
3357
4720
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3358
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4721
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3359
4722
|
return databaseURL + newPath;
|
3360
4723
|
},
|
3361
4724
|
trace,
|
3362
|
-
clientID
|
3363
|
-
|
3364
|
-
|
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;
|
4725
|
+
clientID,
|
4726
|
+
clientName,
|
4727
|
+
xataAgentExtra
|
3372
4728
|
};
|
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
4729
|
}, _a;
|
3381
4730
|
};
|
3382
4731
|
class BaseClient extends buildClient() {
|
@@ -3449,21 +4798,6 @@ const deserialize = (json) => {
|
|
3449
4798
|
return defaultSerializer.fromJSON(json);
|
3450
4799
|
};
|
3451
4800
|
|
3452
|
-
function buildWorkerRunner(config) {
|
3453
|
-
return function xataWorker(name, _worker) {
|
3454
|
-
return async (...args) => {
|
3455
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3456
|
-
const result = await fetch(url, {
|
3457
|
-
method: "POST",
|
3458
|
-
headers: { "Content-Type": "application/json" },
|
3459
|
-
body: serialize({ args })
|
3460
|
-
});
|
3461
|
-
const text = await result.text();
|
3462
|
-
return deserialize(text);
|
3463
|
-
};
|
3464
|
-
};
|
3465
|
-
}
|
3466
|
-
|
3467
4801
|
class XataError extends Error {
|
3468
4802
|
constructor(message, status) {
|
3469
4803
|
super(message);
|
@@ -3471,5 +4805,5 @@ class XataError extends Error {
|
|
3471
4805
|
}
|
3472
4806
|
}
|
3473
4807
|
|
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,
|
4808
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, pgRollMigrationHistory, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3475
4809
|
//# sourceMappingURL=index.mjs.map
|