@xata.io/client 0.0.0-alpha.vf9f8d99 → 0.0.0-alpha.vfa1407e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +3 -3
- package/CHANGELOG.md +171 -1
- package/dist/index.cjs +1505 -125
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1769 -356
- package/dist/index.mjs +1477 -126
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/.eslintrc.cjs +0 -13
- package/rollup.config.mjs +0 -44
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -18,7 +18,8 @@ const TraceAttributes = {
|
|
18
18
|
HTTP_METHOD: "http.method",
|
19
19
|
HTTP_URL: "http.url",
|
20
20
|
HTTP_ROUTE: "http.route",
|
21
|
-
HTTP_TARGET: "http.target"
|
21
|
+
HTTP_TARGET: "http.target",
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
22
23
|
};
|
23
24
|
|
24
25
|
function notEmpty(value) {
|
@@ -27,8 +28,18 @@ function notEmpty(value) {
|
|
27
28
|
function compact(arr) {
|
28
29
|
return arr.filter(notEmpty);
|
29
30
|
}
|
31
|
+
function compactObject(obj) {
|
32
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
33
|
+
}
|
34
|
+
function isBlob(value) {
|
35
|
+
try {
|
36
|
+
return value instanceof Blob;
|
37
|
+
} catch (error) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
}
|
30
41
|
function isObject(value) {
|
31
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
32
43
|
}
|
33
44
|
function isDefined(value) {
|
34
45
|
return value !== null && value !== void 0;
|
@@ -83,6 +94,27 @@ function chunk(array, chunkSize) {
|
|
83
94
|
async function timeout(ms) {
|
84
95
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
85
96
|
}
|
97
|
+
function timeoutWithCancel(ms) {
|
98
|
+
let timeoutId;
|
99
|
+
const promise = new Promise((resolve) => {
|
100
|
+
timeoutId = setTimeout(() => {
|
101
|
+
resolve();
|
102
|
+
}, ms);
|
103
|
+
});
|
104
|
+
return {
|
105
|
+
cancel: () => clearTimeout(timeoutId),
|
106
|
+
promise
|
107
|
+
};
|
108
|
+
}
|
109
|
+
function promiseMap(inputValues, mapper) {
|
110
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
111
|
+
(acc) => mapper(inputValue).then((result) => {
|
112
|
+
acc.push(result);
|
113
|
+
return acc;
|
114
|
+
})
|
115
|
+
);
|
116
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
117
|
+
}
|
86
118
|
|
87
119
|
function getEnvironment() {
|
88
120
|
try {
|
@@ -91,8 +123,10 @@ function getEnvironment() {
|
|
91
123
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
92
124
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
93
125
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
94
|
-
|
95
|
-
|
126
|
+
deployPreview: process.env.XATA_PREVIEW,
|
127
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
128
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
129
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
96
130
|
};
|
97
131
|
}
|
98
132
|
} catch (err) {
|
@@ -103,8 +137,10 @@ function getEnvironment() {
|
|
103
137
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
104
138
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
105
139
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
106
|
-
|
107
|
-
|
140
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
141
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
142
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
143
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
108
144
|
};
|
109
145
|
}
|
110
146
|
} catch (err) {
|
@@ -113,8 +149,10 @@ function getEnvironment() {
|
|
113
149
|
apiKey: getGlobalApiKey(),
|
114
150
|
databaseURL: getGlobalDatabaseURL(),
|
115
151
|
branch: getGlobalBranch(),
|
116
|
-
|
117
|
-
|
152
|
+
deployPreview: void 0,
|
153
|
+
deployPreviewBranch: void 0,
|
154
|
+
vercelGitCommitRef: void 0,
|
155
|
+
vercelGitRepoOwner: void 0
|
118
156
|
};
|
119
157
|
}
|
120
158
|
function getEnableBrowserVariable() {
|
@@ -157,39 +195,59 @@ function getGlobalBranch() {
|
|
157
195
|
return void 0;
|
158
196
|
}
|
159
197
|
}
|
160
|
-
function
|
198
|
+
function getDatabaseURL() {
|
161
199
|
try {
|
162
|
-
|
200
|
+
const { databaseURL } = getEnvironment();
|
201
|
+
return databaseURL;
|
163
202
|
} catch (err) {
|
164
203
|
return void 0;
|
165
204
|
}
|
166
205
|
}
|
167
|
-
function
|
206
|
+
function getAPIKey() {
|
168
207
|
try {
|
169
|
-
const {
|
170
|
-
return
|
208
|
+
const { apiKey } = getEnvironment();
|
209
|
+
return apiKey;
|
171
210
|
} catch (err) {
|
172
211
|
return void 0;
|
173
212
|
}
|
174
213
|
}
|
175
214
|
function getBranch() {
|
176
215
|
try {
|
177
|
-
const { branch
|
178
|
-
return branch
|
216
|
+
const { branch } = getEnvironment();
|
217
|
+
return branch;
|
179
218
|
} catch (err) {
|
180
219
|
return void 0;
|
181
220
|
}
|
182
221
|
}
|
183
|
-
|
184
|
-
|
222
|
+
function buildPreviewBranchName({ org, branch }) {
|
223
|
+
return `preview-${org}-${branch}`;
|
224
|
+
}
|
225
|
+
function getPreviewBranch() {
|
185
226
|
try {
|
186
|
-
const {
|
187
|
-
|
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;
|
188
240
|
} catch (err) {
|
189
241
|
return void 0;
|
190
242
|
}
|
191
243
|
}
|
192
244
|
|
245
|
+
var __defProp$8 = Object.defineProperty;
|
246
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
247
|
+
var __publicField$8 = (obj, key, value) => {
|
248
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
249
|
+
return value;
|
250
|
+
};
|
193
251
|
var __accessCheck$8 = (obj, member, msg) => {
|
194
252
|
if (!member.has(obj))
|
195
253
|
throw TypeError("Cannot " + msg);
|
@@ -213,13 +271,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
213
271
|
return method;
|
214
272
|
};
|
215
273
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
274
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
216
275
|
function getFetchImplementation(userFetch) {
|
217
276
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
218
|
-
const
|
277
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
278
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
219
279
|
if (!fetchImpl) {
|
220
|
-
throw new Error(
|
221
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
222
|
-
);
|
280
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
223
281
|
}
|
224
282
|
return fetchImpl;
|
225
283
|
}
|
@@ -229,6 +287,8 @@ class ApiRequestPool {
|
|
229
287
|
__privateAdd$8(this, _fetch, void 0);
|
230
288
|
__privateAdd$8(this, _queue, void 0);
|
231
289
|
__privateAdd$8(this, _concurrency, void 0);
|
290
|
+
__publicField$8(this, "running");
|
291
|
+
__publicField$8(this, "started");
|
232
292
|
__privateSet$8(this, _queue, []);
|
233
293
|
__privateSet$8(this, _concurrency, concurrency);
|
234
294
|
this.running = 0;
|
@@ -244,18 +304,22 @@ class ApiRequestPool {
|
|
244
304
|
return __privateGet$8(this, _fetch);
|
245
305
|
}
|
246
306
|
request(url, options) {
|
247
|
-
const start = new Date();
|
248
|
-
const
|
307
|
+
const start = /* @__PURE__ */ new Date();
|
308
|
+
const fetchImpl = this.getFetch();
|
249
309
|
const runRequest = async (stalled = false) => {
|
250
|
-
const
|
310
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
311
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
312
|
+
if (!response) {
|
313
|
+
throw new Error("Request timed out");
|
314
|
+
}
|
251
315
|
if (response.status === 429) {
|
252
316
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
253
317
|
await timeout(rateLimitReset * 1e3);
|
254
318
|
return await runRequest(true);
|
255
319
|
}
|
256
320
|
if (stalled) {
|
257
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
258
|
-
console.warn(`A request to Xata hit
|
321
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
322
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
259
323
|
}
|
260
324
|
return response;
|
261
325
|
};
|
@@ -297,16 +361,199 @@ function generateUUID() {
|
|
297
361
|
});
|
298
362
|
}
|
299
363
|
|
300
|
-
|
364
|
+
async function getBytes(stream, onChunk) {
|
365
|
+
const reader = stream.getReader();
|
366
|
+
let result;
|
367
|
+
while (!(result = await reader.read()).done) {
|
368
|
+
onChunk(result.value);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
function getLines(onLine) {
|
372
|
+
let buffer;
|
373
|
+
let position;
|
374
|
+
let fieldLength;
|
375
|
+
let discardTrailingNewline = false;
|
376
|
+
return function onChunk(arr) {
|
377
|
+
if (buffer === void 0) {
|
378
|
+
buffer = arr;
|
379
|
+
position = 0;
|
380
|
+
fieldLength = -1;
|
381
|
+
} else {
|
382
|
+
buffer = concat(buffer, arr);
|
383
|
+
}
|
384
|
+
const bufLength = buffer.length;
|
385
|
+
let lineStart = 0;
|
386
|
+
while (position < bufLength) {
|
387
|
+
if (discardTrailingNewline) {
|
388
|
+
if (buffer[position] === 10 /* NewLine */) {
|
389
|
+
lineStart = ++position;
|
390
|
+
}
|
391
|
+
discardTrailingNewline = false;
|
392
|
+
}
|
393
|
+
let lineEnd = -1;
|
394
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
395
|
+
switch (buffer[position]) {
|
396
|
+
case 58 /* Colon */:
|
397
|
+
if (fieldLength === -1) {
|
398
|
+
fieldLength = position - lineStart;
|
399
|
+
}
|
400
|
+
break;
|
401
|
+
case 13 /* CarriageReturn */:
|
402
|
+
discardTrailingNewline = true;
|
403
|
+
case 10 /* NewLine */:
|
404
|
+
lineEnd = position;
|
405
|
+
break;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
if (lineEnd === -1) {
|
409
|
+
break;
|
410
|
+
}
|
411
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
412
|
+
lineStart = position;
|
413
|
+
fieldLength = -1;
|
414
|
+
}
|
415
|
+
if (lineStart === bufLength) {
|
416
|
+
buffer = void 0;
|
417
|
+
} else if (lineStart !== 0) {
|
418
|
+
buffer = buffer.subarray(lineStart);
|
419
|
+
position -= lineStart;
|
420
|
+
}
|
421
|
+
};
|
422
|
+
}
|
423
|
+
function getMessages(onId, onRetry, onMessage) {
|
424
|
+
let message = newMessage();
|
425
|
+
const decoder = new TextDecoder();
|
426
|
+
return function onLine(line, fieldLength) {
|
427
|
+
if (line.length === 0) {
|
428
|
+
onMessage?.(message);
|
429
|
+
message = newMessage();
|
430
|
+
} else if (fieldLength > 0) {
|
431
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
432
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
433
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
434
|
+
switch (field) {
|
435
|
+
case "data":
|
436
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
437
|
+
break;
|
438
|
+
case "event":
|
439
|
+
message.event = value;
|
440
|
+
break;
|
441
|
+
case "id":
|
442
|
+
onId(message.id = value);
|
443
|
+
break;
|
444
|
+
case "retry":
|
445
|
+
const retry = parseInt(value, 10);
|
446
|
+
if (!isNaN(retry)) {
|
447
|
+
onRetry(message.retry = retry);
|
448
|
+
}
|
449
|
+
break;
|
450
|
+
}
|
451
|
+
}
|
452
|
+
};
|
453
|
+
}
|
454
|
+
function concat(a, b) {
|
455
|
+
const res = new Uint8Array(a.length + b.length);
|
456
|
+
res.set(a);
|
457
|
+
res.set(b, a.length);
|
458
|
+
return res;
|
459
|
+
}
|
460
|
+
function newMessage() {
|
461
|
+
return {
|
462
|
+
data: "",
|
463
|
+
event: "",
|
464
|
+
id: "",
|
465
|
+
retry: void 0
|
466
|
+
};
|
467
|
+
}
|
468
|
+
const EventStreamContentType = "text/event-stream";
|
469
|
+
const LastEventId = "last-event-id";
|
470
|
+
function fetchEventSource(input, {
|
471
|
+
signal: inputSignal,
|
472
|
+
headers: inputHeaders,
|
473
|
+
onopen: inputOnOpen,
|
474
|
+
onmessage,
|
475
|
+
onclose,
|
476
|
+
onerror,
|
477
|
+
fetch: inputFetch,
|
478
|
+
...rest
|
479
|
+
}) {
|
480
|
+
return new Promise((resolve, reject) => {
|
481
|
+
const headers = { ...inputHeaders };
|
482
|
+
if (!headers.accept) {
|
483
|
+
headers.accept = EventStreamContentType;
|
484
|
+
}
|
485
|
+
let curRequestController;
|
486
|
+
function dispose() {
|
487
|
+
curRequestController.abort();
|
488
|
+
}
|
489
|
+
inputSignal?.addEventListener("abort", () => {
|
490
|
+
dispose();
|
491
|
+
resolve();
|
492
|
+
});
|
493
|
+
const fetchImpl = inputFetch ?? fetch;
|
494
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
495
|
+
async function create() {
|
496
|
+
curRequestController = new AbortController();
|
497
|
+
try {
|
498
|
+
const response = await fetchImpl(input, {
|
499
|
+
...rest,
|
500
|
+
headers,
|
501
|
+
signal: curRequestController.signal
|
502
|
+
});
|
503
|
+
await onopen(response);
|
504
|
+
await getBytes(
|
505
|
+
response.body,
|
506
|
+
getLines(
|
507
|
+
getMessages(
|
508
|
+
(id) => {
|
509
|
+
if (id) {
|
510
|
+
headers[LastEventId] = id;
|
511
|
+
} else {
|
512
|
+
delete headers[LastEventId];
|
513
|
+
}
|
514
|
+
},
|
515
|
+
(_retry) => {
|
516
|
+
},
|
517
|
+
onmessage
|
518
|
+
)
|
519
|
+
)
|
520
|
+
);
|
521
|
+
onclose?.();
|
522
|
+
dispose();
|
523
|
+
resolve();
|
524
|
+
} catch (err) {
|
525
|
+
}
|
526
|
+
}
|
527
|
+
create();
|
528
|
+
});
|
529
|
+
}
|
530
|
+
function defaultOnOpen(response) {
|
531
|
+
const contentType = response.headers?.get("content-type");
|
532
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
533
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
534
|
+
}
|
535
|
+
}
|
536
|
+
|
537
|
+
const VERSION = "0.26.5";
|
301
538
|
|
539
|
+
var __defProp$7 = Object.defineProperty;
|
540
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
541
|
+
var __publicField$7 = (obj, key, value) => {
|
542
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
543
|
+
return value;
|
544
|
+
};
|
302
545
|
class ErrorWithCause extends Error {
|
303
546
|
constructor(message, options) {
|
304
547
|
super(message, options);
|
548
|
+
__publicField$7(this, "cause");
|
305
549
|
}
|
306
550
|
}
|
307
551
|
class FetcherError extends ErrorWithCause {
|
308
552
|
constructor(status, data, requestId) {
|
309
553
|
super(getMessage(data));
|
554
|
+
__publicField$7(this, "status");
|
555
|
+
__publicField$7(this, "requestId");
|
556
|
+
__publicField$7(this, "errors");
|
310
557
|
this.status = status;
|
311
558
|
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
312
559
|
this.requestId = requestId;
|
@@ -373,6 +620,18 @@ function hostHeader(url) {
|
|
373
620
|
const { groups } = pattern.exec(url) ?? {};
|
374
621
|
return groups?.host ? { Host: groups.host } : {};
|
375
622
|
}
|
623
|
+
async function parseBody(body, headers) {
|
624
|
+
if (!isDefined(body))
|
625
|
+
return void 0;
|
626
|
+
if (isBlob(body) || typeof body.text === "function") {
|
627
|
+
return body;
|
628
|
+
}
|
629
|
+
const { "Content-Type": contentType } = headers ?? {};
|
630
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
631
|
+
return JSON.stringify(body);
|
632
|
+
}
|
633
|
+
return body;
|
634
|
+
}
|
376
635
|
const defaultClientID = generateUUID();
|
377
636
|
async function fetch$1({
|
378
637
|
url: path,
|
@@ -392,7 +651,8 @@ async function fetch$1({
|
|
392
651
|
sessionID,
|
393
652
|
clientName,
|
394
653
|
xataAgentExtra,
|
395
|
-
fetchOptions = {}
|
654
|
+
fetchOptions = {},
|
655
|
+
rawResponse = false
|
396
656
|
}) {
|
397
657
|
pool.setFetch(fetch2);
|
398
658
|
return await trace(
|
@@ -411,7 +671,7 @@ async function fetch$1({
|
|
411
671
|
isDefined(clientName) ? ["service", clientName] : void 0,
|
412
672
|
...Object.entries(xataAgentExtra ?? {})
|
413
673
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
414
|
-
const headers = {
|
674
|
+
const headers = compactObject({
|
415
675
|
"Accept-Encoding": "identity",
|
416
676
|
"Content-Type": "application/json",
|
417
677
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
@@ -420,11 +680,11 @@ async function fetch$1({
|
|
420
680
|
...customHeaders,
|
421
681
|
...hostHeader(fullUrl),
|
422
682
|
Authorization: `Bearer ${apiKey}`
|
423
|
-
};
|
683
|
+
});
|
424
684
|
const response = await pool.request(url, {
|
425
685
|
...fetchOptions,
|
426
686
|
method: method.toUpperCase(),
|
427
|
-
body:
|
687
|
+
body: await parseBody(body, headers),
|
428
688
|
headers,
|
429
689
|
signal
|
430
690
|
});
|
@@ -435,8 +695,12 @@ async function fetch$1({
|
|
435
695
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
436
696
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
437
697
|
[TraceAttributes.HTTP_HOST]: host,
|
438
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
698
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
699
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
439
700
|
});
|
701
|
+
const message = response.headers?.get("x-xata-message");
|
702
|
+
if (message)
|
703
|
+
console.warn(message);
|
440
704
|
if (response.status === 204) {
|
441
705
|
return {};
|
442
706
|
}
|
@@ -444,7 +708,7 @@ async function fetch$1({
|
|
444
708
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
445
709
|
}
|
446
710
|
try {
|
447
|
-
const jsonResponse = await response.json();
|
711
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
448
712
|
if (response.ok) {
|
449
713
|
return jsonResponse;
|
450
714
|
}
|
@@ -456,6 +720,59 @@ async function fetch$1({
|
|
456
720
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
457
721
|
);
|
458
722
|
}
|
723
|
+
function fetchSSERequest({
|
724
|
+
url: path,
|
725
|
+
method,
|
726
|
+
body,
|
727
|
+
headers: customHeaders,
|
728
|
+
pathParams,
|
729
|
+
queryParams,
|
730
|
+
fetch: fetch2,
|
731
|
+
apiKey,
|
732
|
+
endpoint,
|
733
|
+
apiUrl,
|
734
|
+
workspacesApiUrl,
|
735
|
+
onMessage,
|
736
|
+
onError,
|
737
|
+
onClose,
|
738
|
+
signal,
|
739
|
+
clientID,
|
740
|
+
sessionID,
|
741
|
+
clientName,
|
742
|
+
xataAgentExtra
|
743
|
+
}) {
|
744
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
745
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
746
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
747
|
+
void fetchEventSource(url, {
|
748
|
+
method,
|
749
|
+
body: JSON.stringify(body),
|
750
|
+
fetch: fetch2,
|
751
|
+
signal,
|
752
|
+
headers: {
|
753
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
754
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
755
|
+
"X-Xata-Agent": compact([
|
756
|
+
["client", "TS_SDK"],
|
757
|
+
["version", VERSION],
|
758
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
759
|
+
...Object.entries(xataAgentExtra ?? {})
|
760
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
761
|
+
...customHeaders,
|
762
|
+
Authorization: `Bearer ${apiKey}`,
|
763
|
+
"Content-Type": "application/json"
|
764
|
+
},
|
765
|
+
onmessage(ev) {
|
766
|
+
onMessage?.(JSON.parse(ev.data));
|
767
|
+
},
|
768
|
+
onerror(ev) {
|
769
|
+
onError?.(JSON.parse(ev.data));
|
770
|
+
},
|
771
|
+
onclose() {
|
772
|
+
onClose?.();
|
773
|
+
}
|
774
|
+
});
|
775
|
+
}
|
459
776
|
function parseUrl(url) {
|
460
777
|
try {
|
461
778
|
const { host, protocol } = new URL(url);
|
@@ -486,6 +803,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
486
803
|
...variables,
|
487
804
|
signal
|
488
805
|
});
|
806
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
807
|
+
url: "/db/{dbBranchName}/copy",
|
808
|
+
method: "post",
|
809
|
+
...variables,
|
810
|
+
signal
|
811
|
+
});
|
489
812
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
490
813
|
url: "/db/{dbBranchName}/metadata",
|
491
814
|
method: "put",
|
@@ -535,6 +858,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
535
858
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
536
859
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
537
860
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
861
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
538
862
|
const createTable = (variables, signal) => dataPlaneFetch({
|
539
863
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
540
864
|
method: "put",
|
@@ -579,6 +903,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
579
903
|
});
|
580
904
|
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
581
905
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
906
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
907
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
908
|
+
method: "get",
|
909
|
+
...variables,
|
910
|
+
signal
|
911
|
+
});
|
912
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
913
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
914
|
+
method: "put",
|
915
|
+
...variables,
|
916
|
+
signal
|
917
|
+
});
|
918
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
919
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
920
|
+
method: "delete",
|
921
|
+
...variables,
|
922
|
+
signal
|
923
|
+
});
|
924
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
925
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
926
|
+
method: "get",
|
927
|
+
...variables,
|
928
|
+
signal
|
929
|
+
});
|
930
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
931
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
932
|
+
method: "put",
|
933
|
+
...variables,
|
934
|
+
signal
|
935
|
+
});
|
936
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
937
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
938
|
+
method: "delete",
|
939
|
+
...variables,
|
940
|
+
signal
|
941
|
+
});
|
582
942
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
583
943
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
584
944
|
method: "get",
|
@@ -615,14 +975,28 @@ const askTable = (variables, signal) => dataPlaneFetch({
|
|
615
975
|
...variables,
|
616
976
|
signal
|
617
977
|
});
|
978
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
618
979
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
619
980
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
981
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
982
|
+
url: "/file/{fileId}",
|
983
|
+
method: "get",
|
984
|
+
...variables,
|
985
|
+
signal
|
986
|
+
});
|
987
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
988
|
+
url: "/db/{dbBranchName}/sql",
|
989
|
+
method: "post",
|
990
|
+
...variables,
|
991
|
+
signal
|
992
|
+
});
|
620
993
|
const operationsByTag$2 = {
|
621
994
|
branch: {
|
622
995
|
getBranchList,
|
623
996
|
getBranchDetails,
|
624
997
|
createBranch,
|
625
998
|
deleteBranch,
|
999
|
+
copyBranch,
|
626
1000
|
updateBranchMetadata,
|
627
1001
|
getBranchMetadata,
|
628
1002
|
getBranchStats,
|
@@ -640,7 +1014,8 @@ const operationsByTag$2 = {
|
|
640
1014
|
compareBranchSchemas,
|
641
1015
|
updateBranchSchema,
|
642
1016
|
previewBranchSchemaEdit,
|
643
|
-
applyBranchSchemaEdit
|
1017
|
+
applyBranchSchemaEdit,
|
1018
|
+
pushBranchMigrations
|
644
1019
|
},
|
645
1020
|
migrationRequests: {
|
646
1021
|
queryMigrationRequests,
|
@@ -674,19 +1049,24 @@ const operationsByTag$2 = {
|
|
674
1049
|
deleteRecord,
|
675
1050
|
bulkInsertTableRecords
|
676
1051
|
},
|
1052
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
677
1053
|
searchAndFilter: {
|
678
1054
|
queryTable,
|
679
1055
|
searchBranch,
|
680
1056
|
searchTable,
|
681
1057
|
vectorSearchTable,
|
682
1058
|
askTable,
|
1059
|
+
askTableSession,
|
683
1060
|
summarizeTable,
|
684
1061
|
aggregateTable
|
685
|
-
}
|
1062
|
+
},
|
1063
|
+
sql: { sqlQuery }
|
686
1064
|
};
|
687
1065
|
|
688
1066
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
689
1067
|
|
1068
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1069
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
690
1070
|
const getUser = (variables, signal) => controlPlaneFetch({
|
691
1071
|
url: "/user",
|
692
1072
|
method: "get",
|
@@ -723,6 +1103,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
723
1103
|
...variables,
|
724
1104
|
signal
|
725
1105
|
});
|
1106
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1107
|
+
url: "/user/oauth/clients",
|
1108
|
+
method: "get",
|
1109
|
+
...variables,
|
1110
|
+
signal
|
1111
|
+
});
|
1112
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1113
|
+
url: "/user/oauth/clients/{clientId}",
|
1114
|
+
method: "delete",
|
1115
|
+
...variables,
|
1116
|
+
signal
|
1117
|
+
});
|
1118
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1119
|
+
url: "/user/oauth/tokens",
|
1120
|
+
method: "get",
|
1121
|
+
...variables,
|
1122
|
+
signal
|
1123
|
+
});
|
1124
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1125
|
+
url: "/user/oauth/tokens/{token}",
|
1126
|
+
method: "delete",
|
1127
|
+
...variables,
|
1128
|
+
signal
|
1129
|
+
});
|
1130
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
726
1131
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
727
1132
|
url: "/workspaces",
|
728
1133
|
method: "get",
|
@@ -781,6 +1186,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
781
1186
|
});
|
782
1187
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
783
1188
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1189
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
784
1190
|
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
785
1191
|
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
786
1192
|
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
@@ -791,6 +1197,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
791
1197
|
signal
|
792
1198
|
});
|
793
1199
|
const operationsByTag$1 = {
|
1200
|
+
oAuth: {
|
1201
|
+
getAuthorizationCode,
|
1202
|
+
grantAuthorizationCode,
|
1203
|
+
getUserOAuthClients,
|
1204
|
+
deleteUserOAuthClient,
|
1205
|
+
getUserOAuthAccessTokens,
|
1206
|
+
deleteOAuthAccessToken,
|
1207
|
+
updateOAuthAccessToken
|
1208
|
+
},
|
794
1209
|
users: { getUser, updateUser, deleteUser },
|
795
1210
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
796
1211
|
workspaces: {
|
@@ -816,6 +1231,7 @@ const operationsByTag$1 = {
|
|
816
1231
|
deleteDatabase,
|
817
1232
|
getDatabaseMetadata,
|
818
1233
|
updateDatabaseMetadata,
|
1234
|
+
renameDatabase,
|
819
1235
|
getDatabaseGithubSettings,
|
820
1236
|
updateDatabaseGithubSettings,
|
821
1237
|
deleteDatabaseGithubSettings,
|
@@ -841,6 +1257,10 @@ const providers = {
|
|
841
1257
|
staging: {
|
842
1258
|
main: "https://api.staging-xata.dev",
|
843
1259
|
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1260
|
+
},
|
1261
|
+
dev: {
|
1262
|
+
main: "https://api.dev-xata.dev",
|
1263
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
844
1264
|
}
|
845
1265
|
};
|
846
1266
|
function isHostProviderAlias(alias) {
|
@@ -858,6 +1278,11 @@ function parseProviderString(provider = "production") {
|
|
858
1278
|
return null;
|
859
1279
|
return { main, workspaces };
|
860
1280
|
}
|
1281
|
+
function buildProviderString(provider) {
|
1282
|
+
if (isHostProviderAlias(provider))
|
1283
|
+
return provider;
|
1284
|
+
return `${provider.main},${provider.workspaces}`;
|
1285
|
+
}
|
861
1286
|
function parseWorkspacesUrlParts(url) {
|
862
1287
|
if (!isString(url))
|
863
1288
|
return null;
|
@@ -962,6 +1387,11 @@ class XataApiClient {
|
|
962
1387
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
963
1388
|
return __privateGet$7(this, _namespaces).records;
|
964
1389
|
}
|
1390
|
+
get files() {
|
1391
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1392
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1393
|
+
return __privateGet$7(this, _namespaces).files;
|
1394
|
+
}
|
965
1395
|
get searchAndFilter() {
|
966
1396
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
967
1397
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1170,6 +1600,20 @@ class BranchApi {
|
|
1170
1600
|
...this.extraProps
|
1171
1601
|
});
|
1172
1602
|
}
|
1603
|
+
copyBranch({
|
1604
|
+
workspace,
|
1605
|
+
region,
|
1606
|
+
database,
|
1607
|
+
branch,
|
1608
|
+
destinationBranch,
|
1609
|
+
limit
|
1610
|
+
}) {
|
1611
|
+
return operationsByTag.branch.copyBranch({
|
1612
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1613
|
+
body: { destinationBranch, limit },
|
1614
|
+
...this.extraProps
|
1615
|
+
});
|
1616
|
+
}
|
1173
1617
|
updateBranchMetadata({
|
1174
1618
|
workspace,
|
1175
1619
|
region,
|
@@ -1525,6 +1969,164 @@ class RecordsApi {
|
|
1525
1969
|
});
|
1526
1970
|
}
|
1527
1971
|
}
|
1972
|
+
class FilesApi {
|
1973
|
+
constructor(extraProps) {
|
1974
|
+
this.extraProps = extraProps;
|
1975
|
+
}
|
1976
|
+
getFileItem({
|
1977
|
+
workspace,
|
1978
|
+
region,
|
1979
|
+
database,
|
1980
|
+
branch,
|
1981
|
+
table,
|
1982
|
+
record,
|
1983
|
+
column,
|
1984
|
+
fileId
|
1985
|
+
}) {
|
1986
|
+
return operationsByTag.files.getFileItem({
|
1987
|
+
pathParams: {
|
1988
|
+
workspace,
|
1989
|
+
region,
|
1990
|
+
dbBranchName: `${database}:${branch}`,
|
1991
|
+
tableName: table,
|
1992
|
+
recordId: record,
|
1993
|
+
columnName: column,
|
1994
|
+
fileId
|
1995
|
+
},
|
1996
|
+
...this.extraProps
|
1997
|
+
});
|
1998
|
+
}
|
1999
|
+
putFileItem({
|
2000
|
+
workspace,
|
2001
|
+
region,
|
2002
|
+
database,
|
2003
|
+
branch,
|
2004
|
+
table,
|
2005
|
+
record,
|
2006
|
+
column,
|
2007
|
+
fileId,
|
2008
|
+
file
|
2009
|
+
}) {
|
2010
|
+
return operationsByTag.files.putFileItem({
|
2011
|
+
pathParams: {
|
2012
|
+
workspace,
|
2013
|
+
region,
|
2014
|
+
dbBranchName: `${database}:${branch}`,
|
2015
|
+
tableName: table,
|
2016
|
+
recordId: record,
|
2017
|
+
columnName: column,
|
2018
|
+
fileId
|
2019
|
+
},
|
2020
|
+
// @ts-ignore
|
2021
|
+
body: file,
|
2022
|
+
...this.extraProps
|
2023
|
+
});
|
2024
|
+
}
|
2025
|
+
deleteFileItem({
|
2026
|
+
workspace,
|
2027
|
+
region,
|
2028
|
+
database,
|
2029
|
+
branch,
|
2030
|
+
table,
|
2031
|
+
record,
|
2032
|
+
column,
|
2033
|
+
fileId
|
2034
|
+
}) {
|
2035
|
+
return operationsByTag.files.deleteFileItem({
|
2036
|
+
pathParams: {
|
2037
|
+
workspace,
|
2038
|
+
region,
|
2039
|
+
dbBranchName: `${database}:${branch}`,
|
2040
|
+
tableName: table,
|
2041
|
+
recordId: record,
|
2042
|
+
columnName: column,
|
2043
|
+
fileId
|
2044
|
+
},
|
2045
|
+
...this.extraProps
|
2046
|
+
});
|
2047
|
+
}
|
2048
|
+
getFile({
|
2049
|
+
workspace,
|
2050
|
+
region,
|
2051
|
+
database,
|
2052
|
+
branch,
|
2053
|
+
table,
|
2054
|
+
record,
|
2055
|
+
column
|
2056
|
+
}) {
|
2057
|
+
return operationsByTag.files.getFile({
|
2058
|
+
pathParams: {
|
2059
|
+
workspace,
|
2060
|
+
region,
|
2061
|
+
dbBranchName: `${database}:${branch}`,
|
2062
|
+
tableName: table,
|
2063
|
+
recordId: record,
|
2064
|
+
columnName: column
|
2065
|
+
},
|
2066
|
+
...this.extraProps
|
2067
|
+
});
|
2068
|
+
}
|
2069
|
+
putFile({
|
2070
|
+
workspace,
|
2071
|
+
region,
|
2072
|
+
database,
|
2073
|
+
branch,
|
2074
|
+
table,
|
2075
|
+
record,
|
2076
|
+
column,
|
2077
|
+
file
|
2078
|
+
}) {
|
2079
|
+
return operationsByTag.files.putFile({
|
2080
|
+
pathParams: {
|
2081
|
+
workspace,
|
2082
|
+
region,
|
2083
|
+
dbBranchName: `${database}:${branch}`,
|
2084
|
+
tableName: table,
|
2085
|
+
recordId: record,
|
2086
|
+
columnName: column
|
2087
|
+
},
|
2088
|
+
body: file,
|
2089
|
+
...this.extraProps
|
2090
|
+
});
|
2091
|
+
}
|
2092
|
+
deleteFile({
|
2093
|
+
workspace,
|
2094
|
+
region,
|
2095
|
+
database,
|
2096
|
+
branch,
|
2097
|
+
table,
|
2098
|
+
record,
|
2099
|
+
column
|
2100
|
+
}) {
|
2101
|
+
return operationsByTag.files.deleteFile({
|
2102
|
+
pathParams: {
|
2103
|
+
workspace,
|
2104
|
+
region,
|
2105
|
+
dbBranchName: `${database}:${branch}`,
|
2106
|
+
tableName: table,
|
2107
|
+
recordId: record,
|
2108
|
+
columnName: column
|
2109
|
+
},
|
2110
|
+
...this.extraProps
|
2111
|
+
});
|
2112
|
+
}
|
2113
|
+
fileAccess({
|
2114
|
+
workspace,
|
2115
|
+
region,
|
2116
|
+
fileId,
|
2117
|
+
verify
|
2118
|
+
}) {
|
2119
|
+
return operationsByTag.files.fileAccess({
|
2120
|
+
pathParams: {
|
2121
|
+
workspace,
|
2122
|
+
region,
|
2123
|
+
fileId
|
2124
|
+
},
|
2125
|
+
queryParams: { verify },
|
2126
|
+
...this.extraProps
|
2127
|
+
});
|
2128
|
+
}
|
2129
|
+
}
|
1528
2130
|
class SearchAndFilterApi {
|
1529
2131
|
constructor(extraProps) {
|
1530
2132
|
this.extraProps = extraProps;
|
@@ -1608,17 +2210,26 @@ class SearchAndFilterApi {
|
|
1608
2210
|
database,
|
1609
2211
|
branch,
|
1610
2212
|
table,
|
1611
|
-
|
1612
|
-
fuzziness,
|
1613
|
-
target,
|
1614
|
-
prefix,
|
1615
|
-
filter,
|
1616
|
-
boosters,
|
1617
|
-
rules
|
2213
|
+
options
|
1618
2214
|
}) {
|
1619
2215
|
return operationsByTag.searchAndFilter.askTable({
|
1620
2216
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1621
|
-
body: {
|
2217
|
+
body: { ...options },
|
2218
|
+
...this.extraProps
|
2219
|
+
});
|
2220
|
+
}
|
2221
|
+
askTableSession({
|
2222
|
+
workspace,
|
2223
|
+
region,
|
2224
|
+
database,
|
2225
|
+
branch,
|
2226
|
+
table,
|
2227
|
+
sessionId,
|
2228
|
+
message
|
2229
|
+
}) {
|
2230
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2231
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2232
|
+
body: { message },
|
1622
2233
|
...this.extraProps
|
1623
2234
|
});
|
1624
2235
|
}
|
@@ -1886,6 +2497,19 @@ class MigrationsApi {
|
|
1886
2497
|
...this.extraProps
|
1887
2498
|
});
|
1888
2499
|
}
|
2500
|
+
pushBranchMigrations({
|
2501
|
+
workspace,
|
2502
|
+
region,
|
2503
|
+
database,
|
2504
|
+
branch,
|
2505
|
+
migrations
|
2506
|
+
}) {
|
2507
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2508
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2509
|
+
body: { migrations },
|
2510
|
+
...this.extraProps
|
2511
|
+
});
|
2512
|
+
}
|
1889
2513
|
}
|
1890
2514
|
class DatabaseApi {
|
1891
2515
|
constructor(extraProps) {
|
@@ -1900,11 +2524,13 @@ class DatabaseApi {
|
|
1900
2524
|
createDatabase({
|
1901
2525
|
workspace,
|
1902
2526
|
database,
|
1903
|
-
data
|
2527
|
+
data,
|
2528
|
+
headers
|
1904
2529
|
}) {
|
1905
2530
|
return operationsByTag.databases.createDatabase({
|
1906
2531
|
pathParams: { workspaceId: workspace, dbName: database },
|
1907
2532
|
body: data,
|
2533
|
+
headers,
|
1908
2534
|
...this.extraProps
|
1909
2535
|
});
|
1910
2536
|
}
|
@@ -1937,6 +2563,17 @@ class DatabaseApi {
|
|
1937
2563
|
...this.extraProps
|
1938
2564
|
});
|
1939
2565
|
}
|
2566
|
+
renameDatabase({
|
2567
|
+
workspace,
|
2568
|
+
database,
|
2569
|
+
newName
|
2570
|
+
}) {
|
2571
|
+
return operationsByTag.databases.renameDatabase({
|
2572
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2573
|
+
body: { newName },
|
2574
|
+
...this.extraProps
|
2575
|
+
});
|
2576
|
+
}
|
1940
2577
|
getDatabaseGithubSettings({
|
1941
2578
|
workspace,
|
1942
2579
|
database
|
@@ -1983,13 +2620,319 @@ class XataApiPlugin {
|
|
1983
2620
|
class XataPlugin {
|
1984
2621
|
}
|
1985
2622
|
|
2623
|
+
class FilesPlugin extends XataPlugin {
|
2624
|
+
build(pluginOptions) {
|
2625
|
+
return {
|
2626
|
+
download: async (location) => {
|
2627
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2628
|
+
return await getFileItem({
|
2629
|
+
pathParams: {
|
2630
|
+
workspace: "{workspaceId}",
|
2631
|
+
dbBranchName: "{dbBranch}",
|
2632
|
+
region: "{region}",
|
2633
|
+
tableName: table ?? "",
|
2634
|
+
recordId: record ?? "",
|
2635
|
+
columnName: column ?? "",
|
2636
|
+
fileId
|
2637
|
+
},
|
2638
|
+
...pluginOptions,
|
2639
|
+
rawResponse: true
|
2640
|
+
});
|
2641
|
+
},
|
2642
|
+
upload: async (location, file) => {
|
2643
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2644
|
+
const contentType = getContentType(file);
|
2645
|
+
return await putFileItem({
|
2646
|
+
...pluginOptions,
|
2647
|
+
pathParams: {
|
2648
|
+
workspace: "{workspaceId}",
|
2649
|
+
dbBranchName: "{dbBranch}",
|
2650
|
+
region: "{region}",
|
2651
|
+
tableName: table ?? "",
|
2652
|
+
recordId: record ?? "",
|
2653
|
+
columnName: column ?? "",
|
2654
|
+
fileId
|
2655
|
+
},
|
2656
|
+
body: file,
|
2657
|
+
headers: { "Content-Type": contentType }
|
2658
|
+
});
|
2659
|
+
},
|
2660
|
+
delete: async (location) => {
|
2661
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2662
|
+
return await deleteFileItem({
|
2663
|
+
pathParams: {
|
2664
|
+
workspace: "{workspaceId}",
|
2665
|
+
dbBranchName: "{dbBranch}",
|
2666
|
+
region: "{region}",
|
2667
|
+
tableName: table ?? "",
|
2668
|
+
recordId: record ?? "",
|
2669
|
+
columnName: column ?? "",
|
2670
|
+
fileId
|
2671
|
+
},
|
2672
|
+
...pluginOptions
|
2673
|
+
});
|
2674
|
+
}
|
2675
|
+
};
|
2676
|
+
}
|
2677
|
+
}
|
2678
|
+
function getContentType(file) {
|
2679
|
+
if (typeof file === "string") {
|
2680
|
+
return "text/plain";
|
2681
|
+
}
|
2682
|
+
if (isBlob(file)) {
|
2683
|
+
return file.type;
|
2684
|
+
}
|
2685
|
+
try {
|
2686
|
+
return file.type;
|
2687
|
+
} catch (e) {
|
2688
|
+
}
|
2689
|
+
return "application/octet-stream";
|
2690
|
+
}
|
2691
|
+
|
2692
|
+
function buildTransformString(transformations) {
|
2693
|
+
return transformations.flatMap(
|
2694
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2695
|
+
if (key === "trim") {
|
2696
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2697
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2698
|
+
}
|
2699
|
+
if (key === "gravity" && typeof value === "object") {
|
2700
|
+
const { x = 0.5, y = 0.5 } = value;
|
2701
|
+
return `${key}=${[x, y].join("x")}`;
|
2702
|
+
}
|
2703
|
+
return `${key}=${value}`;
|
2704
|
+
})
|
2705
|
+
).join(",");
|
2706
|
+
}
|
2707
|
+
function transformImage(url, ...transformations) {
|
2708
|
+
if (!isDefined(url))
|
2709
|
+
return void 0;
|
2710
|
+
const newTransformations = buildTransformString(transformations);
|
2711
|
+
const { hostname, pathname, search } = new URL(url);
|
2712
|
+
const pathParts = pathname.split("/");
|
2713
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2714
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2715
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2716
|
+
const path = pathParts.join("/");
|
2717
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2718
|
+
}
|
2719
|
+
|
2720
|
+
var __defProp$6 = Object.defineProperty;
|
2721
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2722
|
+
var __publicField$6 = (obj, key, value) => {
|
2723
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2724
|
+
return value;
|
2725
|
+
};
|
2726
|
+
class XataFile {
|
2727
|
+
constructor(file) {
|
2728
|
+
/**
|
2729
|
+
* Identifier of the file.
|
2730
|
+
*/
|
2731
|
+
__publicField$6(this, "id");
|
2732
|
+
/**
|
2733
|
+
* Name of the file.
|
2734
|
+
*/
|
2735
|
+
__publicField$6(this, "name");
|
2736
|
+
/**
|
2737
|
+
* Media type of the file.
|
2738
|
+
*/
|
2739
|
+
__publicField$6(this, "mediaType");
|
2740
|
+
/**
|
2741
|
+
* Base64 encoded content of the file.
|
2742
|
+
*/
|
2743
|
+
__publicField$6(this, "base64Content");
|
2744
|
+
/**
|
2745
|
+
* Whether to enable public url for the file.
|
2746
|
+
*/
|
2747
|
+
__publicField$6(this, "enablePublicUrl");
|
2748
|
+
/**
|
2749
|
+
* Timeout for the signed url.
|
2750
|
+
*/
|
2751
|
+
__publicField$6(this, "signedUrlTimeout");
|
2752
|
+
/**
|
2753
|
+
* Size of the file.
|
2754
|
+
*/
|
2755
|
+
__publicField$6(this, "size");
|
2756
|
+
/**
|
2757
|
+
* Version of the file.
|
2758
|
+
*/
|
2759
|
+
__publicField$6(this, "version");
|
2760
|
+
/**
|
2761
|
+
* Url of the file.
|
2762
|
+
*/
|
2763
|
+
__publicField$6(this, "url");
|
2764
|
+
/**
|
2765
|
+
* Signed url of the file.
|
2766
|
+
*/
|
2767
|
+
__publicField$6(this, "signedUrl");
|
2768
|
+
/**
|
2769
|
+
* Attributes of the file.
|
2770
|
+
*/
|
2771
|
+
__publicField$6(this, "attributes");
|
2772
|
+
this.id = file.id;
|
2773
|
+
this.name = file.name || "";
|
2774
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2775
|
+
this.base64Content = file.base64Content;
|
2776
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2777
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2778
|
+
this.size = file.size ?? 0;
|
2779
|
+
this.version = file.version ?? 1;
|
2780
|
+
this.url = file.url || "";
|
2781
|
+
this.signedUrl = file.signedUrl;
|
2782
|
+
this.attributes = file.attributes || {};
|
2783
|
+
}
|
2784
|
+
static fromBuffer(buffer, options = {}) {
|
2785
|
+
const base64Content = buffer.toString("base64");
|
2786
|
+
return new XataFile({ ...options, base64Content });
|
2787
|
+
}
|
2788
|
+
toBuffer() {
|
2789
|
+
if (!this.base64Content) {
|
2790
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2791
|
+
}
|
2792
|
+
return Buffer.from(this.base64Content, "base64");
|
2793
|
+
}
|
2794
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2795
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2796
|
+
return this.fromUint8Array(uint8Array, options);
|
2797
|
+
}
|
2798
|
+
toArrayBuffer() {
|
2799
|
+
if (!this.base64Content) {
|
2800
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2801
|
+
}
|
2802
|
+
const binary = atob(this.base64Content);
|
2803
|
+
return new ArrayBuffer(binary.length);
|
2804
|
+
}
|
2805
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2806
|
+
let binary = "";
|
2807
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2808
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2809
|
+
}
|
2810
|
+
const base64Content = btoa(binary);
|
2811
|
+
return new XataFile({ ...options, base64Content });
|
2812
|
+
}
|
2813
|
+
toUint8Array() {
|
2814
|
+
if (!this.base64Content) {
|
2815
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2816
|
+
}
|
2817
|
+
const binary = atob(this.base64Content);
|
2818
|
+
const uint8Array = new Uint8Array(binary.length);
|
2819
|
+
for (let i = 0; i < binary.length; i++) {
|
2820
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2821
|
+
}
|
2822
|
+
return uint8Array;
|
2823
|
+
}
|
2824
|
+
static async fromBlob(file, options = {}) {
|
2825
|
+
const name = options.name ?? file.name;
|
2826
|
+
const mediaType = file.type;
|
2827
|
+
const arrayBuffer = await file.arrayBuffer();
|
2828
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2829
|
+
}
|
2830
|
+
toBlob() {
|
2831
|
+
if (!this.base64Content) {
|
2832
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2833
|
+
}
|
2834
|
+
const binary = atob(this.base64Content);
|
2835
|
+
const uint8Array = new Uint8Array(binary.length);
|
2836
|
+
for (let i = 0; i < binary.length; i++) {
|
2837
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2838
|
+
}
|
2839
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2840
|
+
}
|
2841
|
+
static fromString(string, options = {}) {
|
2842
|
+
const base64Content = btoa(string);
|
2843
|
+
return new XataFile({ ...options, base64Content });
|
2844
|
+
}
|
2845
|
+
toString() {
|
2846
|
+
if (!this.base64Content) {
|
2847
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2848
|
+
}
|
2849
|
+
return atob(this.base64Content);
|
2850
|
+
}
|
2851
|
+
static fromBase64(base64Content, options = {}) {
|
2852
|
+
return new XataFile({ ...options, base64Content });
|
2853
|
+
}
|
2854
|
+
toBase64() {
|
2855
|
+
if (!this.base64Content) {
|
2856
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2857
|
+
}
|
2858
|
+
return this.base64Content;
|
2859
|
+
}
|
2860
|
+
transform(...options) {
|
2861
|
+
return {
|
2862
|
+
url: transformImage(this.url, ...options),
|
2863
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2864
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2865
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2866
|
+
};
|
2867
|
+
}
|
2868
|
+
}
|
2869
|
+
const parseInputFileEntry = async (entry) => {
|
2870
|
+
if (!isDefined(entry))
|
2871
|
+
return null;
|
2872
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2873
|
+
return compactObject({
|
2874
|
+
id,
|
2875
|
+
// Name cannot be an empty string in our API
|
2876
|
+
name: name ? name : void 0,
|
2877
|
+
mediaType,
|
2878
|
+
base64Content,
|
2879
|
+
enablePublicUrl,
|
2880
|
+
signedUrlTimeout
|
2881
|
+
});
|
2882
|
+
};
|
2883
|
+
|
1986
2884
|
function cleanFilter(filter) {
|
1987
|
-
if (!filter)
|
2885
|
+
if (!isDefined(filter))
|
1988
2886
|
return void 0;
|
1989
|
-
|
1990
|
-
|
2887
|
+
if (!isObject(filter))
|
2888
|
+
return filter;
|
2889
|
+
const values = Object.fromEntries(
|
2890
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2891
|
+
if (!isDefined(value))
|
2892
|
+
return acc;
|
2893
|
+
if (Array.isArray(value)) {
|
2894
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2895
|
+
if (clean.length === 0)
|
2896
|
+
return acc;
|
2897
|
+
return [...acc, [key, clean]];
|
2898
|
+
}
|
2899
|
+
if (isObject(value)) {
|
2900
|
+
const clean = cleanFilter(value);
|
2901
|
+
if (!isDefined(clean))
|
2902
|
+
return acc;
|
2903
|
+
return [...acc, [key, clean]];
|
2904
|
+
}
|
2905
|
+
return [...acc, [key, value]];
|
2906
|
+
}, [])
|
2907
|
+
);
|
2908
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
2909
|
+
}
|
2910
|
+
|
2911
|
+
function stringifyJson(value) {
|
2912
|
+
if (!isDefined(value))
|
2913
|
+
return value;
|
2914
|
+
if (isString(value))
|
2915
|
+
return value;
|
2916
|
+
try {
|
2917
|
+
return JSON.stringify(value);
|
2918
|
+
} catch (e) {
|
2919
|
+
return value;
|
2920
|
+
}
|
2921
|
+
}
|
2922
|
+
function parseJson(value) {
|
2923
|
+
try {
|
2924
|
+
return JSON.parse(value);
|
2925
|
+
} catch (e) {
|
2926
|
+
return value;
|
2927
|
+
}
|
1991
2928
|
}
|
1992
2929
|
|
2930
|
+
var __defProp$5 = Object.defineProperty;
|
2931
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2932
|
+
var __publicField$5 = (obj, key, value) => {
|
2933
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2934
|
+
return value;
|
2935
|
+
};
|
1993
2936
|
var __accessCheck$6 = (obj, member, msg) => {
|
1994
2937
|
if (!member.has(obj))
|
1995
2938
|
throw TypeError("Cannot " + msg);
|
@@ -2012,22 +2955,58 @@ var _query, _page;
|
|
2012
2955
|
class Page {
|
2013
2956
|
constructor(query, meta, records = []) {
|
2014
2957
|
__privateAdd$6(this, _query, void 0);
|
2958
|
+
/**
|
2959
|
+
* Page metadata, required to retrieve additional records.
|
2960
|
+
*/
|
2961
|
+
__publicField$5(this, "meta");
|
2962
|
+
/**
|
2963
|
+
* The set of results for this page.
|
2964
|
+
*/
|
2965
|
+
__publicField$5(this, "records");
|
2015
2966
|
__privateSet$6(this, _query, query);
|
2016
2967
|
this.meta = meta;
|
2017
2968
|
this.records = new RecordArray(this, records);
|
2018
2969
|
}
|
2970
|
+
/**
|
2971
|
+
* Retrieves the next page of results.
|
2972
|
+
* @param size Maximum number of results to be retrieved.
|
2973
|
+
* @param offset Number of results to skip when retrieving the results.
|
2974
|
+
* @returns The next page or results.
|
2975
|
+
*/
|
2019
2976
|
async nextPage(size, offset) {
|
2020
2977
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
2021
2978
|
}
|
2979
|
+
/**
|
2980
|
+
* Retrieves the previous page of results.
|
2981
|
+
* @param size Maximum number of results to be retrieved.
|
2982
|
+
* @param offset Number of results to skip when retrieving the results.
|
2983
|
+
* @returns The previous page or results.
|
2984
|
+
*/
|
2022
2985
|
async previousPage(size, offset) {
|
2023
2986
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
2024
2987
|
}
|
2988
|
+
/**
|
2989
|
+
* Retrieves the start page of results.
|
2990
|
+
* @param size Maximum number of results to be retrieved.
|
2991
|
+
* @param offset Number of results to skip when retrieving the results.
|
2992
|
+
* @returns The start page or results.
|
2993
|
+
*/
|
2025
2994
|
async startPage(size, offset) {
|
2026
2995
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
2027
2996
|
}
|
2997
|
+
/**
|
2998
|
+
* Retrieves the end page of results.
|
2999
|
+
* @param size Maximum number of results to be retrieved.
|
3000
|
+
* @param offset Number of results to skip when retrieving the results.
|
3001
|
+
* @returns The end page or results.
|
3002
|
+
*/
|
2028
3003
|
async endPage(size, offset) {
|
2029
3004
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
2030
3005
|
}
|
3006
|
+
/**
|
3007
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
3008
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
3009
|
+
*/
|
2031
3010
|
hasNextPage() {
|
2032
3011
|
return this.meta.page.more;
|
2033
3012
|
}
|
@@ -2040,7 +3019,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
2040
3019
|
function isCursorPaginationOptions(options) {
|
2041
3020
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
2042
3021
|
}
|
2043
|
-
const _RecordArray = class extends Array {
|
3022
|
+
const _RecordArray = class _RecordArray extends Array {
|
2044
3023
|
constructor(...args) {
|
2045
3024
|
super(..._RecordArray.parseConstructorParams(...args));
|
2046
3025
|
__privateAdd$6(this, _page, void 0);
|
@@ -2068,29 +3047,58 @@ const _RecordArray = class extends Array {
|
|
2068
3047
|
map(callbackfn, thisArg) {
|
2069
3048
|
return this.toArray().map(callbackfn, thisArg);
|
2070
3049
|
}
|
3050
|
+
/**
|
3051
|
+
* Retrieve next page of records
|
3052
|
+
*
|
3053
|
+
* @returns A new array of objects
|
3054
|
+
*/
|
2071
3055
|
async nextPage(size, offset) {
|
2072
3056
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
2073
3057
|
return new _RecordArray(newPage);
|
2074
3058
|
}
|
3059
|
+
/**
|
3060
|
+
* Retrieve previous page of records
|
3061
|
+
*
|
3062
|
+
* @returns A new array of objects
|
3063
|
+
*/
|
2075
3064
|
async previousPage(size, offset) {
|
2076
3065
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
2077
3066
|
return new _RecordArray(newPage);
|
2078
3067
|
}
|
3068
|
+
/**
|
3069
|
+
* Retrieve start page of records
|
3070
|
+
*
|
3071
|
+
* @returns A new array of objects
|
3072
|
+
*/
|
2079
3073
|
async startPage(size, offset) {
|
2080
3074
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
2081
3075
|
return new _RecordArray(newPage);
|
2082
3076
|
}
|
3077
|
+
/**
|
3078
|
+
* Retrieve end page of records
|
3079
|
+
*
|
3080
|
+
* @returns A new array of objects
|
3081
|
+
*/
|
2083
3082
|
async endPage(size, offset) {
|
2084
3083
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
2085
3084
|
return new _RecordArray(newPage);
|
2086
3085
|
}
|
3086
|
+
/**
|
3087
|
+
* @returns Boolean indicating if there is a next page
|
3088
|
+
*/
|
2087
3089
|
hasNextPage() {
|
2088
3090
|
return __privateGet$6(this, _page).meta.page.more;
|
2089
3091
|
}
|
2090
3092
|
};
|
2091
|
-
let RecordArray = _RecordArray;
|
2092
3093
|
_page = new WeakMap();
|
3094
|
+
let RecordArray = _RecordArray;
|
2093
3095
|
|
3096
|
+
var __defProp$4 = Object.defineProperty;
|
3097
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3098
|
+
var __publicField$4 = (obj, key, value) => {
|
3099
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3100
|
+
return value;
|
3101
|
+
};
|
2094
3102
|
var __accessCheck$5 = (obj, member, msg) => {
|
2095
3103
|
if (!member.has(obj))
|
2096
3104
|
throw TypeError("Cannot " + msg);
|
@@ -2114,14 +3122,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2114
3122
|
return method;
|
2115
3123
|
};
|
2116
3124
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2117
|
-
const _Query = class {
|
3125
|
+
const _Query = class _Query {
|
2118
3126
|
constructor(repository, table, data, rawParent) {
|
2119
3127
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2120
3128
|
__privateAdd$5(this, _table$1, void 0);
|
2121
3129
|
__privateAdd$5(this, _repository, void 0);
|
2122
3130
|
__privateAdd$5(this, _data, { filter: {} });
|
2123
|
-
|
2124
|
-
this
|
3131
|
+
// Implements pagination
|
3132
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
3133
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
2125
3134
|
__privateSet$5(this, _table$1, table);
|
2126
3135
|
if (repository) {
|
2127
3136
|
__privateSet$5(this, _repository, repository);
|
@@ -2157,18 +3166,38 @@ const _Query = class {
|
|
2157
3166
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2158
3167
|
return toBase64(key);
|
2159
3168
|
}
|
3169
|
+
/**
|
3170
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3171
|
+
* @param queries An array of subqueries.
|
3172
|
+
* @returns A new Query object.
|
3173
|
+
*/
|
2160
3174
|
any(...queries) {
|
2161
3175
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2162
3176
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2163
3177
|
}
|
3178
|
+
/**
|
3179
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3180
|
+
* @param queries An array of subqueries.
|
3181
|
+
* @returns A new Query object.
|
3182
|
+
*/
|
2164
3183
|
all(...queries) {
|
2165
3184
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2166
3185
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2167
3186
|
}
|
3187
|
+
/**
|
3188
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3189
|
+
* @param queries An array of subqueries.
|
3190
|
+
* @returns A new Query object.
|
3191
|
+
*/
|
2168
3192
|
not(...queries) {
|
2169
3193
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2170
3194
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2171
3195
|
}
|
3196
|
+
/**
|
3197
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3198
|
+
* @param queries An array of subqueries.
|
3199
|
+
* @returns A new Query object.
|
3200
|
+
*/
|
2172
3201
|
none(...queries) {
|
2173
3202
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2174
3203
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2191,6 +3220,11 @@ const _Query = class {
|
|
2191
3220
|
const sort = [...originalSort, { column, direction }];
|
2192
3221
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2193
3222
|
}
|
3223
|
+
/**
|
3224
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3225
|
+
* @param columns Array of column names to be returned by the query.
|
3226
|
+
* @returns A new Query object.
|
3227
|
+
*/
|
2194
3228
|
select(columns) {
|
2195
3229
|
return new _Query(
|
2196
3230
|
__privateGet$5(this, _repository),
|
@@ -2203,6 +3237,12 @@ const _Query = class {
|
|
2203
3237
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2204
3238
|
return __privateGet$5(this, _repository).query(query);
|
2205
3239
|
}
|
3240
|
+
/**
|
3241
|
+
* Get results in an iterator
|
3242
|
+
*
|
3243
|
+
* @async
|
3244
|
+
* @returns Async interable of results
|
3245
|
+
*/
|
2206
3246
|
async *[Symbol.asyncIterator]() {
|
2207
3247
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2208
3248
|
yield record;
|
@@ -2263,26 +3303,53 @@ const _Query = class {
|
|
2263
3303
|
);
|
2264
3304
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2265
3305
|
}
|
3306
|
+
/**
|
3307
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3308
|
+
* @param ttl The cache TTL in milliseconds.
|
3309
|
+
* @returns A new Query object.
|
3310
|
+
*/
|
2266
3311
|
cache(ttl) {
|
2267
3312
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2268
3313
|
}
|
3314
|
+
/**
|
3315
|
+
* Retrieve next page of records
|
3316
|
+
*
|
3317
|
+
* @returns A new page object.
|
3318
|
+
*/
|
2269
3319
|
nextPage(size, offset) {
|
2270
3320
|
return this.startPage(size, offset);
|
2271
3321
|
}
|
3322
|
+
/**
|
3323
|
+
* Retrieve previous page of records
|
3324
|
+
*
|
3325
|
+
* @returns A new page object
|
3326
|
+
*/
|
2272
3327
|
previousPage(size, offset) {
|
2273
3328
|
return this.startPage(size, offset);
|
2274
3329
|
}
|
3330
|
+
/**
|
3331
|
+
* Retrieve start page of records
|
3332
|
+
*
|
3333
|
+
* @returns A new page object
|
3334
|
+
*/
|
2275
3335
|
startPage(size, offset) {
|
2276
3336
|
return this.getPaginated({ pagination: { size, offset } });
|
2277
3337
|
}
|
3338
|
+
/**
|
3339
|
+
* Retrieve last page of records
|
3340
|
+
*
|
3341
|
+
* @returns A new page object
|
3342
|
+
*/
|
2278
3343
|
endPage(size, offset) {
|
2279
3344
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2280
3345
|
}
|
3346
|
+
/**
|
3347
|
+
* @returns Boolean indicating if there is a next page
|
3348
|
+
*/
|
2281
3349
|
hasNextPage() {
|
2282
3350
|
return this.meta.page.more;
|
2283
3351
|
}
|
2284
3352
|
};
|
2285
|
-
let Query = _Query;
|
2286
3353
|
_table$1 = new WeakMap();
|
2287
3354
|
_repository = new WeakMap();
|
2288
3355
|
_data = new WeakMap();
|
@@ -2297,6 +3364,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2297
3364
|
}
|
2298
3365
|
return value;
|
2299
3366
|
};
|
3367
|
+
let Query = _Query;
|
2300
3368
|
function cleanParent(data, parent) {
|
2301
3369
|
if (isCursorPaginationOptions(data.pagination)) {
|
2302
3370
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2304,6 +3372,22 @@ function cleanParent(data, parent) {
|
|
2304
3372
|
return parent;
|
2305
3373
|
}
|
2306
3374
|
|
3375
|
+
const RecordColumnTypes = [
|
3376
|
+
"bool",
|
3377
|
+
"int",
|
3378
|
+
"float",
|
3379
|
+
"string",
|
3380
|
+
"text",
|
3381
|
+
"email",
|
3382
|
+
"multiple",
|
3383
|
+
"link",
|
3384
|
+
"object",
|
3385
|
+
"datetime",
|
3386
|
+
"vector",
|
3387
|
+
"file[]",
|
3388
|
+
"file",
|
3389
|
+
"json"
|
3390
|
+
];
|
2307
3391
|
function isIdentifiable(x) {
|
2308
3392
|
return isObject(x) && isString(x?.id);
|
2309
3393
|
}
|
@@ -2313,11 +3397,33 @@ function isXataRecord(x) {
|
|
2313
3397
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2314
3398
|
}
|
2315
3399
|
|
3400
|
+
function isValidExpandedColumn(column) {
|
3401
|
+
return isObject(column) && isString(column.name);
|
3402
|
+
}
|
3403
|
+
function isValidSelectableColumns(columns) {
|
3404
|
+
if (!Array.isArray(columns)) {
|
3405
|
+
return false;
|
3406
|
+
}
|
3407
|
+
return columns.every((column) => {
|
3408
|
+
if (typeof column === "string") {
|
3409
|
+
return true;
|
3410
|
+
}
|
3411
|
+
if (typeof column === "object") {
|
3412
|
+
return isValidExpandedColumn(column);
|
3413
|
+
}
|
3414
|
+
return false;
|
3415
|
+
});
|
3416
|
+
}
|
3417
|
+
|
2316
3418
|
function isSortFilterString(value) {
|
2317
3419
|
return isString(value);
|
2318
3420
|
}
|
2319
3421
|
function isSortFilterBase(filter) {
|
2320
|
-
return isObject(filter) && Object.
|
3422
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3423
|
+
if (key === "*")
|
3424
|
+
return value === "random";
|
3425
|
+
return value === "asc" || value === "desc";
|
3426
|
+
});
|
2321
3427
|
}
|
2322
3428
|
function isSortFilterObject(filter) {
|
2323
3429
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2358,7 +3464,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2358
3464
|
__accessCheck$4(obj, member, "access private method");
|
2359
3465
|
return method;
|
2360
3466
|
};
|
2361
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
3467
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1, _transformObjectToApi, transformObjectToApi_fn;
|
2362
3468
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2363
3469
|
class Repository extends Query {
|
2364
3470
|
}
|
@@ -2380,6 +3486,7 @@ class RestRepository extends Query {
|
|
2380
3486
|
__privateAdd$4(this, _setCacheQuery);
|
2381
3487
|
__privateAdd$4(this, _getCacheQuery);
|
2382
3488
|
__privateAdd$4(this, _getSchemaTables$1);
|
3489
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2383
3490
|
__privateAdd$4(this, _table, void 0);
|
2384
3491
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2385
3492
|
__privateAdd$4(this, _db, void 0);
|
@@ -2408,24 +3515,24 @@ class RestRepository extends Query {
|
|
2408
3515
|
if (a.length === 0)
|
2409
3516
|
return [];
|
2410
3517
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2411
|
-
const columns =
|
3518
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2412
3519
|
const result = await this.read(ids, columns);
|
2413
3520
|
return result;
|
2414
3521
|
}
|
2415
3522
|
if (isString(a) && isObject(b)) {
|
2416
3523
|
if (a === "")
|
2417
3524
|
throw new Error("The id can't be empty");
|
2418
|
-
const columns =
|
3525
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2419
3526
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2420
3527
|
}
|
2421
3528
|
if (isObject(a) && isString(a.id)) {
|
2422
3529
|
if (a.id === "")
|
2423
3530
|
throw new Error("The id can't be empty");
|
2424
|
-
const columns =
|
3531
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2425
3532
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2426
3533
|
}
|
2427
3534
|
if (isObject(a)) {
|
2428
|
-
const columns =
|
3535
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2429
3536
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2430
3537
|
}
|
2431
3538
|
throw new Error("Invalid arguments for create method");
|
@@ -2433,7 +3540,7 @@ class RestRepository extends Query {
|
|
2433
3540
|
}
|
2434
3541
|
async read(a, b) {
|
2435
3542
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2436
|
-
const columns =
|
3543
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2437
3544
|
if (Array.isArray(a)) {
|
2438
3545
|
if (a.length === 0)
|
2439
3546
|
return [];
|
@@ -2460,7 +3567,13 @@ class RestRepository extends Query {
|
|
2460
3567
|
...__privateGet$4(this, _getFetchProps).call(this)
|
2461
3568
|
});
|
2462
3569
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2463
|
-
return initObject(
|
3570
|
+
return initObject(
|
3571
|
+
__privateGet$4(this, _db),
|
3572
|
+
schemaTables,
|
3573
|
+
__privateGet$4(this, _table),
|
3574
|
+
response,
|
3575
|
+
columns
|
3576
|
+
);
|
2464
3577
|
} catch (e) {
|
2465
3578
|
if (isObject(e) && e.status === 404) {
|
2466
3579
|
return null;
|
@@ -2502,17 +3615,17 @@ class RestRepository extends Query {
|
|
2502
3615
|
ifVersion,
|
2503
3616
|
upsert: false
|
2504
3617
|
});
|
2505
|
-
const columns =
|
3618
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2506
3619
|
const result = await this.read(a, columns);
|
2507
3620
|
return result;
|
2508
3621
|
}
|
2509
3622
|
try {
|
2510
3623
|
if (isString(a) && isObject(b)) {
|
2511
|
-
const columns =
|
3624
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2512
3625
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2513
3626
|
}
|
2514
3627
|
if (isObject(a) && isString(a.id)) {
|
2515
|
-
const columns =
|
3628
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2516
3629
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2517
3630
|
}
|
2518
3631
|
} catch (error) {
|
@@ -2552,17 +3665,27 @@ class RestRepository extends Query {
|
|
2552
3665
|
ifVersion,
|
2553
3666
|
upsert: true
|
2554
3667
|
});
|
2555
|
-
const columns =
|
3668
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2556
3669
|
const result = await this.read(a, columns);
|
2557
3670
|
return result;
|
2558
3671
|
}
|
2559
3672
|
if (isString(a) && isObject(b)) {
|
2560
|
-
|
2561
|
-
|
3673
|
+
if (a === "")
|
3674
|
+
throw new Error("The id can't be empty");
|
3675
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3676
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2562
3677
|
}
|
2563
3678
|
if (isObject(a) && isString(a.id)) {
|
2564
|
-
|
2565
|
-
|
3679
|
+
if (a.id === "")
|
3680
|
+
throw new Error("The id can't be empty");
|
3681
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3682
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3683
|
+
}
|
3684
|
+
if (!isDefined(a) && isObject(b)) {
|
3685
|
+
return await this.create(b, c);
|
3686
|
+
}
|
3687
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3688
|
+
return await this.create(a, b);
|
2566
3689
|
}
|
2567
3690
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2568
3691
|
});
|
@@ -2574,17 +3697,27 @@ class RestRepository extends Query {
|
|
2574
3697
|
if (a.length === 0)
|
2575
3698
|
return [];
|
2576
3699
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2577
|
-
const columns =
|
3700
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2578
3701
|
const result = await this.read(ids, columns);
|
2579
3702
|
return result;
|
2580
3703
|
}
|
2581
3704
|
if (isString(a) && isObject(b)) {
|
2582
|
-
|
2583
|
-
|
3705
|
+
if (a === "")
|
3706
|
+
throw new Error("The id can't be empty");
|
3707
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3708
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2584
3709
|
}
|
2585
3710
|
if (isObject(a) && isString(a.id)) {
|
2586
|
-
|
2587
|
-
|
3711
|
+
if (a.id === "")
|
3712
|
+
throw new Error("The id can't be empty");
|
3713
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3714
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3715
|
+
}
|
3716
|
+
if (!isDefined(a) && isObject(b)) {
|
3717
|
+
return await this.create(b, c);
|
3718
|
+
}
|
3719
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3720
|
+
return await this.create(a, b);
|
2588
3721
|
}
|
2589
3722
|
throw new Error("Invalid arguments for createOrReplace method");
|
2590
3723
|
});
|
@@ -2601,7 +3734,7 @@ class RestRepository extends Query {
|
|
2601
3734
|
return o.id;
|
2602
3735
|
throw new Error("Invalid arguments for delete method");
|
2603
3736
|
});
|
2604
|
-
const columns =
|
3737
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2605
3738
|
const result = await this.read(a, columns);
|
2606
3739
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2607
3740
|
return result;
|
@@ -2720,7 +3853,13 @@ class RestRepository extends Query {
|
|
2720
3853
|
});
|
2721
3854
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2722
3855
|
const records = objects.map(
|
2723
|
-
(record) => initObject(
|
3856
|
+
(record) => initObject(
|
3857
|
+
__privateGet$4(this, _db),
|
3858
|
+
schemaTables,
|
3859
|
+
__privateGet$4(this, _table),
|
3860
|
+
record,
|
3861
|
+
data.columns ?? ["*"]
|
3862
|
+
)
|
2724
3863
|
);
|
2725
3864
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2726
3865
|
return new Page(query, meta, records);
|
@@ -2750,6 +3889,39 @@ class RestRepository extends Query {
|
|
2750
3889
|
return result;
|
2751
3890
|
});
|
2752
3891
|
}
|
3892
|
+
ask(question, options) {
|
3893
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3894
|
+
const params = {
|
3895
|
+
pathParams: {
|
3896
|
+
workspace: "{workspaceId}",
|
3897
|
+
dbBranchName: "{dbBranch}",
|
3898
|
+
region: "{region}",
|
3899
|
+
tableName: __privateGet$4(this, _table),
|
3900
|
+
sessionId: options?.sessionId
|
3901
|
+
},
|
3902
|
+
body: {
|
3903
|
+
...questionParam,
|
3904
|
+
rules: options?.rules,
|
3905
|
+
searchType: options?.searchType,
|
3906
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3907
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3908
|
+
},
|
3909
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3910
|
+
};
|
3911
|
+
if (options?.onMessage) {
|
3912
|
+
fetchSSERequest({
|
3913
|
+
endpoint: "dataPlane",
|
3914
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3915
|
+
method: "POST",
|
3916
|
+
onMessage: (message) => {
|
3917
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3918
|
+
},
|
3919
|
+
...params
|
3920
|
+
});
|
3921
|
+
} else {
|
3922
|
+
return askTableSession(params);
|
3923
|
+
}
|
3924
|
+
}
|
2753
3925
|
}
|
2754
3926
|
_table = new WeakMap();
|
2755
3927
|
_getFetchProps = new WeakMap();
|
@@ -2759,7 +3931,7 @@ _schemaTables$2 = new WeakMap();
|
|
2759
3931
|
_trace = new WeakMap();
|
2760
3932
|
_insertRecordWithoutId = new WeakSet();
|
2761
3933
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2762
|
-
const record =
|
3934
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2763
3935
|
const response = await insertRecord({
|
2764
3936
|
pathParams: {
|
2765
3937
|
workspace: "{workspaceId}",
|
@@ -2776,7 +3948,9 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2776
3948
|
};
|
2777
3949
|
_insertRecordWithId = new WeakSet();
|
2778
3950
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2779
|
-
|
3951
|
+
if (!recordId)
|
3952
|
+
return null;
|
3953
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2780
3954
|
const response = await insertRecordWithID({
|
2781
3955
|
pathParams: {
|
2782
3956
|
workspace: "{workspaceId}",
|
@@ -2794,21 +3968,20 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2794
3968
|
};
|
2795
3969
|
_insertRecords = new WeakSet();
|
2796
3970
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2797
|
-
const
|
2798
|
-
|
2799
|
-
|
2800
|
-
|
2801
|
-
|
2802
|
-
);
|
3971
|
+
const operations = await promiseMap(objects, async (object) => {
|
3972
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3973
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3974
|
+
});
|
3975
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2803
3976
|
const ids = [];
|
2804
|
-
for (const
|
3977
|
+
for (const operations2 of chunkedOperations) {
|
2805
3978
|
const { results } = await branchTransaction({
|
2806
3979
|
pathParams: {
|
2807
3980
|
workspace: "{workspaceId}",
|
2808
3981
|
dbBranchName: "{dbBranch}",
|
2809
3982
|
region: "{region}"
|
2810
3983
|
},
|
2811
|
-
body: { operations },
|
3984
|
+
body: { operations: operations2 },
|
2812
3985
|
...__privateGet$4(this, _getFetchProps).call(this)
|
2813
3986
|
});
|
2814
3987
|
for (const result of results) {
|
@@ -2823,7 +3996,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2823
3996
|
};
|
2824
3997
|
_updateRecordWithID = new WeakSet();
|
2825
3998
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2826
|
-
|
3999
|
+
if (!recordId)
|
4000
|
+
return null;
|
4001
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2827
4002
|
try {
|
2828
4003
|
const response = await updateRecordWithID({
|
2829
4004
|
pathParams: {
|
@@ -2848,21 +4023,20 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2848
4023
|
};
|
2849
4024
|
_updateRecords = new WeakSet();
|
2850
4025
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2851
|
-
const
|
2852
|
-
|
2853
|
-
|
2854
|
-
|
2855
|
-
|
2856
|
-
);
|
4026
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
4027
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
4028
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
4029
|
+
});
|
4030
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2857
4031
|
const ids = [];
|
2858
|
-
for (const
|
4032
|
+
for (const operations2 of chunkedOperations) {
|
2859
4033
|
const { results } = await branchTransaction({
|
2860
4034
|
pathParams: {
|
2861
4035
|
workspace: "{workspaceId}",
|
2862
4036
|
dbBranchName: "{dbBranch}",
|
2863
4037
|
region: "{region}"
|
2864
4038
|
},
|
2865
|
-
body: { operations },
|
4039
|
+
body: { operations: operations2 },
|
2866
4040
|
...__privateGet$4(this, _getFetchProps).call(this)
|
2867
4041
|
});
|
2868
4042
|
for (const result of results) {
|
@@ -2877,6 +4051,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2877
4051
|
};
|
2878
4052
|
_upsertRecordWithID = new WeakSet();
|
2879
4053
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
4054
|
+
if (!recordId)
|
4055
|
+
return null;
|
2880
4056
|
const response = await upsertRecordWithID({
|
2881
4057
|
pathParams: {
|
2882
4058
|
workspace: "{workspaceId}",
|
@@ -2894,6 +4070,8 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2894
4070
|
};
|
2895
4071
|
_deleteRecord = new WeakSet();
|
2896
4072
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
4073
|
+
if (!recordId)
|
4074
|
+
return null;
|
2897
4075
|
try {
|
2898
4076
|
const response = await deleteRecord({
|
2899
4077
|
pathParams: {
|
@@ -2918,7 +4096,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2918
4096
|
_deleteRecords = new WeakSet();
|
2919
4097
|
deleteRecords_fn = async function(recordIds) {
|
2920
4098
|
const chunkedOperations = chunk(
|
2921
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
4099
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2922
4100
|
BULK_OPERATION_MAX_SIZE
|
2923
4101
|
);
|
2924
4102
|
for (const operations of chunkedOperations) {
|
@@ -2935,15 +4113,16 @@ deleteRecords_fn = async function(recordIds) {
|
|
2935
4113
|
};
|
2936
4114
|
_setCacheQuery = new WeakSet();
|
2937
4115
|
setCacheQuery_fn = async function(query, meta, records) {
|
2938
|
-
await __privateGet$4(this, _cache)
|
4116
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2939
4117
|
};
|
2940
4118
|
_getCacheQuery = new WeakSet();
|
2941
4119
|
getCacheQuery_fn = async function(query) {
|
2942
4120
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2943
|
-
const result = await __privateGet$4(this, _cache)
|
4121
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2944
4122
|
if (!result)
|
2945
4123
|
return null;
|
2946
|
-
const
|
4124
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4125
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2947
4126
|
if (ttl < 0)
|
2948
4127
|
return null;
|
2949
4128
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2960,7 +4139,42 @@ getSchemaTables_fn$1 = async function() {
|
|
2960
4139
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2961
4140
|
return schema.tables;
|
2962
4141
|
};
|
2963
|
-
|
4142
|
+
_transformObjectToApi = new WeakSet();
|
4143
|
+
transformObjectToApi_fn = async function(object) {
|
4144
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4145
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4146
|
+
if (!schema)
|
4147
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4148
|
+
const result = {};
|
4149
|
+
for (const [key, value] of Object.entries(object)) {
|
4150
|
+
if (key === "xata")
|
4151
|
+
continue;
|
4152
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4153
|
+
switch (type) {
|
4154
|
+
case "link": {
|
4155
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4156
|
+
break;
|
4157
|
+
}
|
4158
|
+
case "datetime": {
|
4159
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4160
|
+
break;
|
4161
|
+
}
|
4162
|
+
case `file`:
|
4163
|
+
result[key] = await parseInputFileEntry(value);
|
4164
|
+
break;
|
4165
|
+
case "file[]":
|
4166
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4167
|
+
break;
|
4168
|
+
case "json":
|
4169
|
+
result[key] = stringifyJson(value);
|
4170
|
+
break;
|
4171
|
+
default:
|
4172
|
+
result[key] = value;
|
4173
|
+
}
|
4174
|
+
}
|
4175
|
+
return result;
|
4176
|
+
};
|
4177
|
+
const removeLinksFromObject = (object) => {
|
2964
4178
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
2965
4179
|
if (key === "xata")
|
2966
4180
|
return acc;
|
@@ -2997,18 +4211,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2997
4211
|
if (item === column.name) {
|
2998
4212
|
return [...acc, "*"];
|
2999
4213
|
}
|
3000
|
-
if (item.startsWith(`${column.name}.`)) {
|
4214
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
3001
4215
|
const [, ...path] = item.split(".");
|
3002
4216
|
return [...acc, path.join(".")];
|
3003
4217
|
}
|
3004
4218
|
return acc;
|
3005
4219
|
}, []);
|
3006
|
-
data[column.name] = initObject(
|
4220
|
+
data[column.name] = initObject(
|
4221
|
+
db,
|
4222
|
+
schemaTables,
|
4223
|
+
linkTable,
|
4224
|
+
value,
|
4225
|
+
selectedLinkColumns
|
4226
|
+
);
|
3007
4227
|
} else {
|
3008
4228
|
data[column.name] = null;
|
3009
4229
|
}
|
3010
4230
|
break;
|
3011
4231
|
}
|
4232
|
+
case "file":
|
4233
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4234
|
+
break;
|
4235
|
+
case "file[]":
|
4236
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4237
|
+
break;
|
4238
|
+
case "json":
|
4239
|
+
data[column.name] = parseJson(value);
|
4240
|
+
break;
|
3012
4241
|
default:
|
3013
4242
|
data[column.name] = value ?? null;
|
3014
4243
|
if (column.notNull === true && value === null) {
|
@@ -3018,30 +4247,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
3018
4247
|
}
|
3019
4248
|
}
|
3020
4249
|
const record = { ...data };
|
4250
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
4251
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
3021
4252
|
record.read = function(columns2) {
|
3022
4253
|
return db[table].read(record["id"], columns2);
|
3023
4254
|
};
|
3024
4255
|
record.update = function(data2, b, c) {
|
3025
|
-
const columns2 =
|
4256
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
3026
4257
|
const ifVersion = parseIfVersion(b, c);
|
3027
4258
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
3028
4259
|
};
|
3029
4260
|
record.replace = function(data2, b, c) {
|
3030
|
-
const columns2 =
|
4261
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
3031
4262
|
const ifVersion = parseIfVersion(b, c);
|
3032
4263
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
3033
4264
|
};
|
3034
4265
|
record.delete = function() {
|
3035
4266
|
return db[table].delete(record["id"]);
|
3036
4267
|
};
|
4268
|
+
record.xata = Object.freeze(metadata);
|
3037
4269
|
record.getMetadata = function() {
|
3038
|
-
return xata;
|
4270
|
+
return record.xata;
|
3039
4271
|
};
|
3040
4272
|
record.toSerializable = function() {
|
3041
|
-
return JSON.parse(JSON.stringify(
|
4273
|
+
return JSON.parse(JSON.stringify(serializable));
|
3042
4274
|
};
|
3043
4275
|
record.toString = function() {
|
3044
|
-
return JSON.stringify(
|
4276
|
+
return JSON.stringify(serializable);
|
3045
4277
|
};
|
3046
4278
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3047
4279
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -3059,11 +4291,7 @@ function extractId(value) {
|
|
3059
4291
|
function isValidColumn(columns, column) {
|
3060
4292
|
if (columns.includes("*"))
|
3061
4293
|
return true;
|
3062
|
-
|
3063
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
3064
|
-
return linkColumns.length > 0;
|
3065
|
-
}
|
3066
|
-
return columns.includes(column.name);
|
4294
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
3067
4295
|
}
|
3068
4296
|
function parseIfVersion(...args) {
|
3069
4297
|
for (const arg of args) {
|
@@ -3074,6 +4302,12 @@ function parseIfVersion(...args) {
|
|
3074
4302
|
return void 0;
|
3075
4303
|
}
|
3076
4304
|
|
4305
|
+
var __defProp$3 = Object.defineProperty;
|
4306
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4307
|
+
var __publicField$3 = (obj, key, value) => {
|
4308
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4309
|
+
return value;
|
4310
|
+
};
|
3077
4311
|
var __accessCheck$3 = (obj, member, msg) => {
|
3078
4312
|
if (!member.has(obj))
|
3079
4313
|
throw TypeError("Cannot " + msg);
|
@@ -3096,6 +4330,8 @@ var _map;
|
|
3096
4330
|
class SimpleCache {
|
3097
4331
|
constructor(options = {}) {
|
3098
4332
|
__privateAdd$3(this, _map, void 0);
|
4333
|
+
__publicField$3(this, "capacity");
|
4334
|
+
__publicField$3(this, "defaultQueryTTL");
|
3099
4335
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
3100
4336
|
this.capacity = options.max ?? 500;
|
3101
4337
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3260,6 +4496,7 @@ search_fn = async function(query, options, pluginOptions) {
|
|
3260
4496
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3261
4497
|
const { records } = await searchBranch({
|
3262
4498
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4499
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3263
4500
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3264
4501
|
...pluginOptions
|
3265
4502
|
});
|
@@ -3277,6 +4514,78 @@ getSchemaTables_fn = async function(pluginOptions) {
|
|
3277
4514
|
return schema.tables;
|
3278
4515
|
};
|
3279
4516
|
|
4517
|
+
function escapeElement(elementRepresentation) {
|
4518
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4519
|
+
return '"' + escaped + '"';
|
4520
|
+
}
|
4521
|
+
function arrayString(val) {
|
4522
|
+
let result = "{";
|
4523
|
+
for (let i = 0; i < val.length; i++) {
|
4524
|
+
if (i > 0) {
|
4525
|
+
result = result + ",";
|
4526
|
+
}
|
4527
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4528
|
+
result = result + "NULL";
|
4529
|
+
} else if (Array.isArray(val[i])) {
|
4530
|
+
result = result + arrayString(val[i]);
|
4531
|
+
} else if (val[i] instanceof Buffer) {
|
4532
|
+
result += "\\\\x" + val[i].toString("hex");
|
4533
|
+
} else {
|
4534
|
+
result += escapeElement(prepareValue(val[i]));
|
4535
|
+
}
|
4536
|
+
}
|
4537
|
+
result = result + "}";
|
4538
|
+
return result;
|
4539
|
+
}
|
4540
|
+
function prepareValue(value) {
|
4541
|
+
if (!isDefined(value))
|
4542
|
+
return null;
|
4543
|
+
if (value instanceof Date) {
|
4544
|
+
return value.toISOString();
|
4545
|
+
}
|
4546
|
+
if (Array.isArray(value)) {
|
4547
|
+
return arrayString(value);
|
4548
|
+
}
|
4549
|
+
if (isObject(value)) {
|
4550
|
+
return JSON.stringify(value);
|
4551
|
+
}
|
4552
|
+
try {
|
4553
|
+
return value.toString();
|
4554
|
+
} catch (e) {
|
4555
|
+
return value;
|
4556
|
+
}
|
4557
|
+
}
|
4558
|
+
function prepareParams(param1, param2) {
|
4559
|
+
if (isString(param1)) {
|
4560
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4561
|
+
}
|
4562
|
+
if (isStringArray(param1)) {
|
4563
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4564
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4565
|
+
}, "");
|
4566
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4567
|
+
}
|
4568
|
+
if (isObject(param1)) {
|
4569
|
+
const { statement, params, consistency } = param1;
|
4570
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4571
|
+
}
|
4572
|
+
throw new Error("Invalid query");
|
4573
|
+
}
|
4574
|
+
|
4575
|
+
class SQLPlugin extends XataPlugin {
|
4576
|
+
build(pluginOptions) {
|
4577
|
+
return async (param1, ...param2) => {
|
4578
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4579
|
+
const { records, warning } = await sqlQuery({
|
4580
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4581
|
+
body: { statement, params, consistency },
|
4582
|
+
...pluginOptions
|
4583
|
+
});
|
4584
|
+
return { records, warning };
|
4585
|
+
};
|
4586
|
+
}
|
4587
|
+
}
|
4588
|
+
|
3280
4589
|
class TransactionPlugin extends XataPlugin {
|
3281
4590
|
build(pluginOptions) {
|
3282
4591
|
return {
|
@@ -3292,6 +4601,12 @@ class TransactionPlugin extends XataPlugin {
|
|
3292
4601
|
}
|
3293
4602
|
}
|
3294
4603
|
|
4604
|
+
var __defProp$2 = Object.defineProperty;
|
4605
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4606
|
+
var __publicField$2 = (obj, key, value) => {
|
4607
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4608
|
+
return value;
|
4609
|
+
};
|
3295
4610
|
var __accessCheck = (obj, member, msg) => {
|
3296
4611
|
if (!member.has(obj))
|
3297
4612
|
throw TypeError("Cannot " + msg);
|
@@ -3321,29 +4636,32 @@ const buildClient = (plugins) => {
|
|
3321
4636
|
__privateAdd(this, _parseOptions);
|
3322
4637
|
__privateAdd(this, _getFetchProps);
|
3323
4638
|
__privateAdd(this, _options, void 0);
|
4639
|
+
__publicField$2(this, "db");
|
4640
|
+
__publicField$2(this, "search");
|
4641
|
+
__publicField$2(this, "transactions");
|
4642
|
+
__publicField$2(this, "sql");
|
4643
|
+
__publicField$2(this, "files");
|
3324
4644
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3325
4645
|
__privateSet(this, _options, safeOptions);
|
3326
4646
|
const pluginOptions = {
|
3327
4647
|
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3328
|
-
cache: safeOptions.cache
|
4648
|
+
cache: safeOptions.cache,
|
4649
|
+
host: safeOptions.host
|
3329
4650
|
};
|
3330
4651
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3331
4652
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3332
4653
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4654
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4655
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3333
4656
|
this.db = db;
|
3334
4657
|
this.search = search;
|
3335
4658
|
this.transactions = transactions;
|
4659
|
+
this.sql = sql;
|
4660
|
+
this.files = files;
|
3336
4661
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3337
4662
|
if (namespace === void 0)
|
3338
4663
|
continue;
|
3339
|
-
|
3340
|
-
if (result instanceof Promise) {
|
3341
|
-
void result.then((namespace2) => {
|
3342
|
-
this[key] = namespace2;
|
3343
|
-
});
|
3344
|
-
} else {
|
3345
|
-
this[key] = result;
|
3346
|
-
}
|
4664
|
+
this[key] = namespace.build(pluginOptions);
|
3347
4665
|
}
|
3348
4666
|
}
|
3349
4667
|
async getConfig() {
|
@@ -3361,7 +4679,6 @@ const buildClient = (plugins) => {
|
|
3361
4679
|
}
|
3362
4680
|
const fetch = getFetchImplementation(options?.fetch);
|
3363
4681
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3364
|
-
const branch = options?.branch || getBranch() || "main";
|
3365
4682
|
const apiKey = options?.apiKey || getAPIKey();
|
3366
4683
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3367
4684
|
const trace = options?.trace ?? defaultTrace;
|
@@ -3374,6 +4691,26 @@ const buildClient = (plugins) => {
|
|
3374
4691
|
if (!databaseURL) {
|
3375
4692
|
throw new Error("Option databaseURL is required");
|
3376
4693
|
}
|
4694
|
+
const envBranch = getBranch();
|
4695
|
+
const previewBranch = getPreviewBranch();
|
4696
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4697
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4698
|
+
console.warn(
|
4699
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4700
|
+
);
|
4701
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4702
|
+
console.warn(
|
4703
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4704
|
+
);
|
4705
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4706
|
+
console.warn(
|
4707
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4708
|
+
);
|
4709
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4710
|
+
console.warn(
|
4711
|
+
`No branch was passed to the client constructor. Using default branch ${branch}. You can set the branch with the environment variable XATA_BRANCH or by passing the branch option to the client constructor.`
|
4712
|
+
);
|
4713
|
+
}
|
3377
4714
|
return {
|
3378
4715
|
fetch,
|
3379
4716
|
databaseURL,
|
@@ -3401,6 +4738,7 @@ const buildClient = (plugins) => {
|
|
3401
4738
|
fetch,
|
3402
4739
|
apiKey,
|
3403
4740
|
apiUrl: "",
|
4741
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3404
4742
|
workspacesApiUrl: (path, params) => {
|
3405
4743
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3406
4744
|
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
@@ -3416,11 +4754,17 @@ const buildClient = (plugins) => {
|
|
3416
4754
|
class BaseClient extends buildClient() {
|
3417
4755
|
}
|
3418
4756
|
|
4757
|
+
var __defProp$1 = Object.defineProperty;
|
4758
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4759
|
+
var __publicField$1 = (obj, key, value) => {
|
4760
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4761
|
+
return value;
|
4762
|
+
};
|
3419
4763
|
const META = "__";
|
3420
4764
|
const VALUE = "___";
|
3421
4765
|
class Serializer {
|
3422
4766
|
constructor() {
|
3423
|
-
this
|
4767
|
+
__publicField$1(this, "classes", {});
|
3424
4768
|
}
|
3425
4769
|
add(clazz) {
|
3426
4770
|
this.classes[clazz.name] = clazz;
|
@@ -3498,12 +4842,19 @@ function buildWorkerRunner(config) {
|
|
3498
4842
|
};
|
3499
4843
|
}
|
3500
4844
|
|
4845
|
+
var __defProp = Object.defineProperty;
|
4846
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4847
|
+
var __publicField = (obj, key, value) => {
|
4848
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4849
|
+
return value;
|
4850
|
+
};
|
3501
4851
|
class XataError extends Error {
|
3502
4852
|
constructor(message, status) {
|
3503
4853
|
super(message);
|
4854
|
+
__publicField(this, "status");
|
3504
4855
|
this.status = status;
|
3505
4856
|
}
|
3506
4857
|
}
|
3507
4858
|
|
3508
|
-
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
4859
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3509
4860
|
//# sourceMappingURL=index.mjs.map
|