@xata.io/client 0.0.0-alpha.vf4e6746 → 0.0.0-alpha.vf54e954
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +240 -0
- package/README.md +3 -269
- package/dist/index.cjs +1697 -396
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3483 -1708
- package/dist/index.mjs +1664 -390
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -10
- package/.eslintrc.cjs +0 -12
- package/Usage.md +0 -451
- package/rollup.config.mjs +0 -29
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
const defaultTrace = async (
|
1
|
+
const defaultTrace = async (name, fn, _options) => {
|
2
2
|
return await fn({
|
3
|
+
name,
|
3
4
|
setAttributes: () => {
|
4
5
|
return;
|
5
6
|
}
|
@@ -26,8 +27,11 @@ function notEmpty(value) {
|
|
26
27
|
function compact(arr) {
|
27
28
|
return arr.filter(notEmpty);
|
28
29
|
}
|
30
|
+
function compactObject(obj) {
|
31
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
32
|
+
}
|
29
33
|
function isObject(value) {
|
30
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
34
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
31
35
|
}
|
32
36
|
function isDefined(value) {
|
33
37
|
return value !== null && value !== void 0;
|
@@ -82,6 +86,27 @@ function chunk(array, chunkSize) {
|
|
82
86
|
async function timeout(ms) {
|
83
87
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
84
88
|
}
|
89
|
+
function timeoutWithCancel(ms) {
|
90
|
+
let timeoutId;
|
91
|
+
const promise = new Promise((resolve) => {
|
92
|
+
timeoutId = setTimeout(() => {
|
93
|
+
resolve();
|
94
|
+
}, ms);
|
95
|
+
});
|
96
|
+
return {
|
97
|
+
cancel: () => clearTimeout(timeoutId),
|
98
|
+
promise
|
99
|
+
};
|
100
|
+
}
|
101
|
+
function promiseMap(inputValues, mapper) {
|
102
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
103
|
+
(acc) => mapper(inputValue).then((result) => {
|
104
|
+
acc.push(result);
|
105
|
+
return acc;
|
106
|
+
})
|
107
|
+
);
|
108
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
109
|
+
}
|
85
110
|
|
86
111
|
function getEnvironment() {
|
87
112
|
try {
|
@@ -90,8 +115,10 @@ function getEnvironment() {
|
|
90
115
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
91
116
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
92
117
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
93
|
-
|
94
|
-
|
118
|
+
deployPreview: process.env.XATA_PREVIEW,
|
119
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
120
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
121
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
95
122
|
};
|
96
123
|
}
|
97
124
|
} catch (err) {
|
@@ -102,8 +129,10 @@ function getEnvironment() {
|
|
102
129
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
103
130
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
104
131
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
105
|
-
|
106
|
-
|
132
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
133
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
134
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
135
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
107
136
|
};
|
108
137
|
}
|
109
138
|
} catch (err) {
|
@@ -112,8 +141,10 @@ function getEnvironment() {
|
|
112
141
|
apiKey: getGlobalApiKey(),
|
113
142
|
databaseURL: getGlobalDatabaseURL(),
|
114
143
|
branch: getGlobalBranch(),
|
115
|
-
|
116
|
-
|
144
|
+
deployPreview: void 0,
|
145
|
+
deployPreviewBranch: void 0,
|
146
|
+
vercelGitCommitRef: void 0,
|
147
|
+
vercelGitRepoOwner: void 0
|
117
148
|
};
|
118
149
|
}
|
119
150
|
function getEnableBrowserVariable() {
|
@@ -156,44 +187,59 @@ function getGlobalBranch() {
|
|
156
187
|
return void 0;
|
157
188
|
}
|
158
189
|
}
|
159
|
-
function
|
190
|
+
function getDatabaseURL() {
|
160
191
|
try {
|
161
|
-
|
192
|
+
const { databaseURL } = getEnvironment();
|
193
|
+
return databaseURL;
|
162
194
|
} catch (err) {
|
163
195
|
return void 0;
|
164
196
|
}
|
165
197
|
}
|
166
|
-
|
167
|
-
const cmd = ["git", "branch", "--show-current"];
|
168
|
-
const fullCmd = cmd.join(" ");
|
169
|
-
const nodeModule = ["child", "process"].join("_");
|
170
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
198
|
+
function getAPIKey() {
|
171
199
|
try {
|
172
|
-
|
173
|
-
|
174
|
-
}
|
175
|
-
const { execSync } = await import(nodeModule);
|
176
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
200
|
+
const { apiKey } = getEnvironment();
|
201
|
+
return apiKey;
|
177
202
|
} catch (err) {
|
203
|
+
return void 0;
|
178
204
|
}
|
205
|
+
}
|
206
|
+
function getBranch() {
|
179
207
|
try {
|
180
|
-
|
181
|
-
|
182
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
183
|
-
}
|
208
|
+
const { branch } = getEnvironment();
|
209
|
+
return branch;
|
184
210
|
} catch (err) {
|
211
|
+
return void 0;
|
185
212
|
}
|
186
213
|
}
|
187
|
-
|
188
|
-
|
214
|
+
function buildPreviewBranchName({ org, branch }) {
|
215
|
+
return `preview-${org}-${branch}`;
|
216
|
+
}
|
217
|
+
function getPreviewBranch() {
|
189
218
|
try {
|
190
|
-
const {
|
191
|
-
|
219
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
220
|
+
if (deployPreviewBranch)
|
221
|
+
return deployPreviewBranch;
|
222
|
+
switch (deployPreview) {
|
223
|
+
case "vercel": {
|
224
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
225
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
226
|
+
return void 0;
|
227
|
+
}
|
228
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
229
|
+
}
|
230
|
+
}
|
231
|
+
return void 0;
|
192
232
|
} catch (err) {
|
193
233
|
return void 0;
|
194
234
|
}
|
195
235
|
}
|
196
236
|
|
237
|
+
var __defProp$8 = Object.defineProperty;
|
238
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
239
|
+
var __publicField$8 = (obj, key, value) => {
|
240
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
241
|
+
return value;
|
242
|
+
};
|
197
243
|
var __accessCheck$8 = (obj, member, msg) => {
|
198
244
|
if (!member.has(obj))
|
199
245
|
throw TypeError("Cannot " + msg);
|
@@ -217,6 +263,7 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
217
263
|
return method;
|
218
264
|
};
|
219
265
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
266
|
+
const REQUEST_TIMEOUT = 3e4;
|
220
267
|
function getFetchImplementation(userFetch) {
|
221
268
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
222
269
|
const fetchImpl = userFetch ?? globalFetch;
|
@@ -233,6 +280,8 @@ class ApiRequestPool {
|
|
233
280
|
__privateAdd$8(this, _fetch, void 0);
|
234
281
|
__privateAdd$8(this, _queue, void 0);
|
235
282
|
__privateAdd$8(this, _concurrency, void 0);
|
283
|
+
__publicField$8(this, "running");
|
284
|
+
__publicField$8(this, "started");
|
236
285
|
__privateSet$8(this, _queue, []);
|
237
286
|
__privateSet$8(this, _concurrency, concurrency);
|
238
287
|
this.running = 0;
|
@@ -248,18 +297,22 @@ class ApiRequestPool {
|
|
248
297
|
return __privateGet$8(this, _fetch);
|
249
298
|
}
|
250
299
|
request(url, options) {
|
251
|
-
const start = new Date();
|
252
|
-
const
|
300
|
+
const start = /* @__PURE__ */ new Date();
|
301
|
+
const fetchImpl = this.getFetch();
|
253
302
|
const runRequest = async (stalled = false) => {
|
254
|
-
const
|
303
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
304
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
305
|
+
if (!response) {
|
306
|
+
throw new Error("Request timed out");
|
307
|
+
}
|
255
308
|
if (response.status === 429) {
|
256
309
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
257
310
|
await timeout(rateLimitReset * 1e3);
|
258
311
|
return await runRequest(true);
|
259
312
|
}
|
260
313
|
if (stalled) {
|
261
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
262
|
-
console.warn(`A request to Xata hit
|
314
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
315
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
263
316
|
}
|
264
317
|
return response;
|
265
318
|
};
|
@@ -294,18 +347,208 @@ enqueue_fn = function(task) {
|
|
294
347
|
return promise;
|
295
348
|
};
|
296
349
|
|
297
|
-
|
350
|
+
function generateUUID() {
|
351
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
352
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
353
|
+
return v.toString(16);
|
354
|
+
});
|
355
|
+
}
|
356
|
+
|
357
|
+
async function getBytes(stream, onChunk) {
|
358
|
+
const reader = stream.getReader();
|
359
|
+
let result;
|
360
|
+
while (!(result = await reader.read()).done) {
|
361
|
+
onChunk(result.value);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
function getLines(onLine) {
|
365
|
+
let buffer;
|
366
|
+
let position;
|
367
|
+
let fieldLength;
|
368
|
+
let discardTrailingNewline = false;
|
369
|
+
return function onChunk(arr) {
|
370
|
+
if (buffer === void 0) {
|
371
|
+
buffer = arr;
|
372
|
+
position = 0;
|
373
|
+
fieldLength = -1;
|
374
|
+
} else {
|
375
|
+
buffer = concat(buffer, arr);
|
376
|
+
}
|
377
|
+
const bufLength = buffer.length;
|
378
|
+
let lineStart = 0;
|
379
|
+
while (position < bufLength) {
|
380
|
+
if (discardTrailingNewline) {
|
381
|
+
if (buffer[position] === 10 /* NewLine */) {
|
382
|
+
lineStart = ++position;
|
383
|
+
}
|
384
|
+
discardTrailingNewline = false;
|
385
|
+
}
|
386
|
+
let lineEnd = -1;
|
387
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
388
|
+
switch (buffer[position]) {
|
389
|
+
case 58 /* Colon */:
|
390
|
+
if (fieldLength === -1) {
|
391
|
+
fieldLength = position - lineStart;
|
392
|
+
}
|
393
|
+
break;
|
394
|
+
case 13 /* CarriageReturn */:
|
395
|
+
discardTrailingNewline = true;
|
396
|
+
case 10 /* NewLine */:
|
397
|
+
lineEnd = position;
|
398
|
+
break;
|
399
|
+
}
|
400
|
+
}
|
401
|
+
if (lineEnd === -1) {
|
402
|
+
break;
|
403
|
+
}
|
404
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
405
|
+
lineStart = position;
|
406
|
+
fieldLength = -1;
|
407
|
+
}
|
408
|
+
if (lineStart === bufLength) {
|
409
|
+
buffer = void 0;
|
410
|
+
} else if (lineStart !== 0) {
|
411
|
+
buffer = buffer.subarray(lineStart);
|
412
|
+
position -= lineStart;
|
413
|
+
}
|
414
|
+
};
|
415
|
+
}
|
416
|
+
function getMessages(onId, onRetry, onMessage) {
|
417
|
+
let message = newMessage();
|
418
|
+
const decoder = new TextDecoder();
|
419
|
+
return function onLine(line, fieldLength) {
|
420
|
+
if (line.length === 0) {
|
421
|
+
onMessage?.(message);
|
422
|
+
message = newMessage();
|
423
|
+
} else if (fieldLength > 0) {
|
424
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
425
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
426
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
427
|
+
switch (field) {
|
428
|
+
case "data":
|
429
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
430
|
+
break;
|
431
|
+
case "event":
|
432
|
+
message.event = value;
|
433
|
+
break;
|
434
|
+
case "id":
|
435
|
+
onId(message.id = value);
|
436
|
+
break;
|
437
|
+
case "retry":
|
438
|
+
const retry = parseInt(value, 10);
|
439
|
+
if (!isNaN(retry)) {
|
440
|
+
onRetry(message.retry = retry);
|
441
|
+
}
|
442
|
+
break;
|
443
|
+
}
|
444
|
+
}
|
445
|
+
};
|
446
|
+
}
|
447
|
+
function concat(a, b) {
|
448
|
+
const res = new Uint8Array(a.length + b.length);
|
449
|
+
res.set(a);
|
450
|
+
res.set(b, a.length);
|
451
|
+
return res;
|
452
|
+
}
|
453
|
+
function newMessage() {
|
454
|
+
return {
|
455
|
+
data: "",
|
456
|
+
event: "",
|
457
|
+
id: "",
|
458
|
+
retry: void 0
|
459
|
+
};
|
460
|
+
}
|
461
|
+
const EventStreamContentType = "text/event-stream";
|
462
|
+
const LastEventId = "last-event-id";
|
463
|
+
function fetchEventSource(input, {
|
464
|
+
signal: inputSignal,
|
465
|
+
headers: inputHeaders,
|
466
|
+
onopen: inputOnOpen,
|
467
|
+
onmessage,
|
468
|
+
onclose,
|
469
|
+
onerror,
|
470
|
+
fetch: inputFetch,
|
471
|
+
...rest
|
472
|
+
}) {
|
473
|
+
return new Promise((resolve, reject) => {
|
474
|
+
const headers = { ...inputHeaders };
|
475
|
+
if (!headers.accept) {
|
476
|
+
headers.accept = EventStreamContentType;
|
477
|
+
}
|
478
|
+
let curRequestController;
|
479
|
+
function dispose() {
|
480
|
+
curRequestController.abort();
|
481
|
+
}
|
482
|
+
inputSignal?.addEventListener("abort", () => {
|
483
|
+
dispose();
|
484
|
+
resolve();
|
485
|
+
});
|
486
|
+
const fetchImpl = inputFetch ?? fetch;
|
487
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
488
|
+
async function create() {
|
489
|
+
curRequestController = new AbortController();
|
490
|
+
try {
|
491
|
+
const response = await fetchImpl(input, {
|
492
|
+
...rest,
|
493
|
+
headers,
|
494
|
+
signal: curRequestController.signal
|
495
|
+
});
|
496
|
+
await onopen(response);
|
497
|
+
await getBytes(
|
498
|
+
response.body,
|
499
|
+
getLines(
|
500
|
+
getMessages(
|
501
|
+
(id) => {
|
502
|
+
if (id) {
|
503
|
+
headers[LastEventId] = id;
|
504
|
+
} else {
|
505
|
+
delete headers[LastEventId];
|
506
|
+
}
|
507
|
+
},
|
508
|
+
(_retry) => {
|
509
|
+
},
|
510
|
+
onmessage
|
511
|
+
)
|
512
|
+
)
|
513
|
+
);
|
514
|
+
onclose?.();
|
515
|
+
dispose();
|
516
|
+
resolve();
|
517
|
+
} catch (err) {
|
518
|
+
}
|
519
|
+
}
|
520
|
+
create();
|
521
|
+
});
|
522
|
+
}
|
523
|
+
function defaultOnOpen(response) {
|
524
|
+
const contentType = response.headers?.get("content-type");
|
525
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
526
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
527
|
+
}
|
528
|
+
}
|
529
|
+
|
530
|
+
const VERSION = "0.26.0";
|
298
531
|
|
532
|
+
var __defProp$7 = Object.defineProperty;
|
533
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
534
|
+
var __publicField$7 = (obj, key, value) => {
|
535
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
536
|
+
return value;
|
537
|
+
};
|
299
538
|
class ErrorWithCause extends Error {
|
300
539
|
constructor(message, options) {
|
301
540
|
super(message, options);
|
541
|
+
__publicField$7(this, "cause");
|
302
542
|
}
|
303
543
|
}
|
304
544
|
class FetcherError extends ErrorWithCause {
|
305
545
|
constructor(status, data, requestId) {
|
306
546
|
super(getMessage(data));
|
547
|
+
__publicField$7(this, "status");
|
548
|
+
__publicField$7(this, "requestId");
|
549
|
+
__publicField$7(this, "errors");
|
307
550
|
this.status = status;
|
308
|
-
this.errors = isBulkError(data) ? data.errors :
|
551
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
309
552
|
this.requestId = requestId;
|
310
553
|
if (data instanceof Error) {
|
311
554
|
this.stack = data.stack;
|
@@ -370,14 +613,24 @@ function hostHeader(url) {
|
|
370
613
|
const { groups } = pattern.exec(url) ?? {};
|
371
614
|
return groups?.host ? { Host: groups.host } : {};
|
372
615
|
}
|
616
|
+
function parseBody(body, headers) {
|
617
|
+
if (!isDefined(body))
|
618
|
+
return void 0;
|
619
|
+
const { "Content-Type": contentType } = headers ?? {};
|
620
|
+
if (String(contentType).toLowerCase() === "application/json") {
|
621
|
+
return JSON.stringify(body);
|
622
|
+
}
|
623
|
+
return body;
|
624
|
+
}
|
625
|
+
const defaultClientID = generateUUID();
|
373
626
|
async function fetch$1({
|
374
627
|
url: path,
|
375
628
|
method,
|
376
629
|
body,
|
377
|
-
headers,
|
630
|
+
headers: customHeaders,
|
378
631
|
pathParams,
|
379
632
|
queryParams,
|
380
|
-
|
633
|
+
fetch: fetch2,
|
381
634
|
apiKey,
|
382
635
|
endpoint,
|
383
636
|
apiUrl,
|
@@ -386,9 +639,12 @@ async function fetch$1({
|
|
386
639
|
signal,
|
387
640
|
clientID,
|
388
641
|
sessionID,
|
389
|
-
|
642
|
+
clientName,
|
643
|
+
xataAgentExtra,
|
644
|
+
fetchOptions = {},
|
645
|
+
rawResponse = false
|
390
646
|
}) {
|
391
|
-
pool.setFetch(
|
647
|
+
pool.setFetch(fetch2);
|
392
648
|
return await trace(
|
393
649
|
`${method.toUpperCase()} ${path}`,
|
394
650
|
async ({ setAttributes }) => {
|
@@ -399,19 +655,27 @@ async function fetch$1({
|
|
399
655
|
[TraceAttributes.HTTP_URL]: url,
|
400
656
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
401
657
|
});
|
658
|
+
const xataAgent = compact([
|
659
|
+
["client", "TS_SDK"],
|
660
|
+
["version", VERSION],
|
661
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
662
|
+
...Object.entries(xataAgentExtra ?? {})
|
663
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
664
|
+
const headers = compactObject({
|
665
|
+
"Accept-Encoding": "identity",
|
666
|
+
"Content-Type": "application/json",
|
667
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
668
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
669
|
+
"X-Xata-Agent": xataAgent,
|
670
|
+
...customHeaders,
|
671
|
+
...hostHeader(fullUrl),
|
672
|
+
Authorization: `Bearer ${apiKey}`
|
673
|
+
});
|
402
674
|
const response = await pool.request(url, {
|
403
675
|
...fetchOptions,
|
404
676
|
method: method.toUpperCase(),
|
405
|
-
body: body
|
406
|
-
headers
|
407
|
-
"Content-Type": "application/json",
|
408
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
409
|
-
"X-Xata-Client-ID": clientID ?? "",
|
410
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
411
|
-
...headers,
|
412
|
-
...hostHeader(fullUrl),
|
413
|
-
Authorization: `Bearer ${apiKey}`
|
414
|
-
},
|
677
|
+
body: parseBody(body, headers),
|
678
|
+
headers,
|
415
679
|
signal
|
416
680
|
});
|
417
681
|
const { host, protocol } = parseUrl(response.url);
|
@@ -423,6 +687,9 @@ async function fetch$1({
|
|
423
687
|
[TraceAttributes.HTTP_HOST]: host,
|
424
688
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
425
689
|
});
|
690
|
+
const message = response.headers?.get("x-xata-message");
|
691
|
+
if (message)
|
692
|
+
console.warn(message);
|
426
693
|
if (response.status === 204) {
|
427
694
|
return {};
|
428
695
|
}
|
@@ -430,7 +697,7 @@ async function fetch$1({
|
|
430
697
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
431
698
|
}
|
432
699
|
try {
|
433
|
-
const jsonResponse = await response.json();
|
700
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
434
701
|
if (response.ok) {
|
435
702
|
return jsonResponse;
|
436
703
|
}
|
@@ -442,6 +709,59 @@ async function fetch$1({
|
|
442
709
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
443
710
|
);
|
444
711
|
}
|
712
|
+
function fetchSSERequest({
|
713
|
+
url: path,
|
714
|
+
method,
|
715
|
+
body,
|
716
|
+
headers: customHeaders,
|
717
|
+
pathParams,
|
718
|
+
queryParams,
|
719
|
+
fetch: fetch2,
|
720
|
+
apiKey,
|
721
|
+
endpoint,
|
722
|
+
apiUrl,
|
723
|
+
workspacesApiUrl,
|
724
|
+
onMessage,
|
725
|
+
onError,
|
726
|
+
onClose,
|
727
|
+
signal,
|
728
|
+
clientID,
|
729
|
+
sessionID,
|
730
|
+
clientName,
|
731
|
+
xataAgentExtra
|
732
|
+
}) {
|
733
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
734
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
735
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
736
|
+
void fetchEventSource(url, {
|
737
|
+
method,
|
738
|
+
body: JSON.stringify(body),
|
739
|
+
fetch: fetch2,
|
740
|
+
signal,
|
741
|
+
headers: {
|
742
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
743
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
744
|
+
"X-Xata-Agent": compact([
|
745
|
+
["client", "TS_SDK"],
|
746
|
+
["version", VERSION],
|
747
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
748
|
+
...Object.entries(xataAgentExtra ?? {})
|
749
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
750
|
+
...customHeaders,
|
751
|
+
Authorization: `Bearer ${apiKey}`,
|
752
|
+
"Content-Type": "application/json"
|
753
|
+
},
|
754
|
+
onmessage(ev) {
|
755
|
+
onMessage?.(JSON.parse(ev.data));
|
756
|
+
},
|
757
|
+
onerror(ev) {
|
758
|
+
onError?.(JSON.parse(ev.data));
|
759
|
+
},
|
760
|
+
onclose() {
|
761
|
+
onClose?.();
|
762
|
+
}
|
763
|
+
});
|
764
|
+
}
|
445
765
|
function parseUrl(url) {
|
446
766
|
try {
|
447
767
|
const { host, protocol } = new URL(url);
|
@@ -453,17 +773,12 @@ function parseUrl(url) {
|
|
453
773
|
|
454
774
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
455
775
|
|
456
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
457
776
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
458
777
|
url: "/dbs/{dbName}",
|
459
778
|
method: "get",
|
460
779
|
...variables,
|
461
780
|
signal
|
462
781
|
});
|
463
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
464
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
465
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
466
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
467
782
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
468
783
|
url: "/db/{dbBranchName}",
|
469
784
|
method: "get",
|
@@ -477,6 +792,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
477
792
|
...variables,
|
478
793
|
signal
|
479
794
|
});
|
795
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
796
|
+
url: "/db/{dbBranchName}/copy",
|
797
|
+
method: "post",
|
798
|
+
...variables,
|
799
|
+
signal
|
800
|
+
});
|
480
801
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
481
802
|
url: "/db/{dbBranchName}/metadata",
|
482
803
|
method: "put",
|
@@ -502,7 +823,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
502
823
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
503
824
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
504
825
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
505
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
506
826
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
507
827
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
508
828
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -527,6 +847,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
527
847
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
528
848
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
529
849
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
850
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
530
851
|
const createTable = (variables, signal) => dataPlaneFetch({
|
531
852
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
532
853
|
method: "put",
|
@@ -569,7 +890,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
569
890
|
...variables,
|
570
891
|
signal
|
571
892
|
});
|
893
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
572
894
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
895
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
896
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
897
|
+
method: "get",
|
898
|
+
...variables,
|
899
|
+
signal
|
900
|
+
});
|
901
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
902
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
903
|
+
method: "put",
|
904
|
+
...variables,
|
905
|
+
signal
|
906
|
+
});
|
907
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
908
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
909
|
+
method: "delete",
|
910
|
+
...variables,
|
911
|
+
signal
|
912
|
+
});
|
913
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
914
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
915
|
+
method: "get",
|
916
|
+
...variables,
|
917
|
+
signal
|
918
|
+
});
|
919
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
920
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
921
|
+
method: "put",
|
922
|
+
...variables,
|
923
|
+
signal
|
924
|
+
});
|
925
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
926
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
927
|
+
method: "delete",
|
928
|
+
...variables,
|
929
|
+
signal
|
930
|
+
});
|
573
931
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
574
932
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
575
933
|
method: "get",
|
@@ -599,21 +957,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
599
957
|
...variables,
|
600
958
|
signal
|
601
959
|
});
|
960
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
961
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
962
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
963
|
+
method: "post",
|
964
|
+
...variables,
|
965
|
+
signal
|
966
|
+
});
|
967
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
602
968
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
603
969
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
970
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
971
|
+
url: "/file/{fileId}",
|
972
|
+
method: "get",
|
973
|
+
...variables,
|
974
|
+
signal
|
975
|
+
});
|
976
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
977
|
+
url: "/db/{dbBranchName}/sql",
|
978
|
+
method: "post",
|
979
|
+
...variables,
|
980
|
+
signal
|
981
|
+
});
|
604
982
|
const operationsByTag$2 = {
|
605
|
-
database: {
|
606
|
-
dEPRECATEDgetDatabaseList,
|
607
|
-
dEPRECATEDcreateDatabase,
|
608
|
-
dEPRECATEDdeleteDatabase,
|
609
|
-
dEPRECATEDgetDatabaseMetadata,
|
610
|
-
dEPRECATEDupdateDatabaseMetadata
|
611
|
-
},
|
612
983
|
branch: {
|
613
984
|
getBranchList,
|
614
985
|
getBranchDetails,
|
615
986
|
createBranch,
|
616
987
|
deleteBranch,
|
988
|
+
copyBranch,
|
617
989
|
updateBranchMetadata,
|
618
990
|
getBranchMetadata,
|
619
991
|
getBranchStats,
|
@@ -631,17 +1003,8 @@ const operationsByTag$2 = {
|
|
631
1003
|
compareBranchSchemas,
|
632
1004
|
updateBranchSchema,
|
633
1005
|
previewBranchSchemaEdit,
|
634
|
-
applyBranchSchemaEdit
|
635
|
-
|
636
|
-
records: {
|
637
|
-
branchTransaction,
|
638
|
-
insertRecord,
|
639
|
-
getRecord,
|
640
|
-
insertRecordWithID,
|
641
|
-
updateRecordWithID,
|
642
|
-
upsertRecordWithID,
|
643
|
-
deleteRecord,
|
644
|
-
bulkInsertTableRecords
|
1006
|
+
applyBranchSchemaEdit,
|
1007
|
+
pushBranchMigrations
|
645
1008
|
},
|
646
1009
|
migrationRequests: {
|
647
1010
|
queryMigrationRequests,
|
@@ -665,11 +1028,34 @@ const operationsByTag$2 = {
|
|
665
1028
|
updateColumn,
|
666
1029
|
deleteColumn
|
667
1030
|
},
|
668
|
-
|
1031
|
+
records: {
|
1032
|
+
branchTransaction,
|
1033
|
+
insertRecord,
|
1034
|
+
getRecord,
|
1035
|
+
insertRecordWithID,
|
1036
|
+
updateRecordWithID,
|
1037
|
+
upsertRecordWithID,
|
1038
|
+
deleteRecord,
|
1039
|
+
bulkInsertTableRecords
|
1040
|
+
},
|
1041
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1042
|
+
searchAndFilter: {
|
1043
|
+
queryTable,
|
1044
|
+
searchBranch,
|
1045
|
+
searchTable,
|
1046
|
+
vectorSearchTable,
|
1047
|
+
askTable,
|
1048
|
+
askTableSession,
|
1049
|
+
summarizeTable,
|
1050
|
+
aggregateTable
|
1051
|
+
},
|
1052
|
+
sql: { sqlQuery }
|
669
1053
|
};
|
670
1054
|
|
671
1055
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
672
1056
|
|
1057
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1058
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
673
1059
|
const getUser = (variables, signal) => controlPlaneFetch({
|
674
1060
|
url: "/user",
|
675
1061
|
method: "get",
|
@@ -706,6 +1092,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
706
1092
|
...variables,
|
707
1093
|
signal
|
708
1094
|
});
|
1095
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1096
|
+
url: "/user/oauth/clients",
|
1097
|
+
method: "get",
|
1098
|
+
...variables,
|
1099
|
+
signal
|
1100
|
+
});
|
1101
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1102
|
+
url: "/user/oauth/clients/{clientId}",
|
1103
|
+
method: "delete",
|
1104
|
+
...variables,
|
1105
|
+
signal
|
1106
|
+
});
|
1107
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1108
|
+
url: "/user/oauth/tokens",
|
1109
|
+
method: "get",
|
1110
|
+
...variables,
|
1111
|
+
signal
|
1112
|
+
});
|
1113
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1114
|
+
url: "/user/oauth/tokens/{token}",
|
1115
|
+
method: "delete",
|
1116
|
+
...variables,
|
1117
|
+
signal
|
1118
|
+
});
|
1119
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
709
1120
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
710
1121
|
url: "/workspaces",
|
711
1122
|
method: "get",
|
@@ -764,6 +1175,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
764
1175
|
});
|
765
1176
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
766
1177
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1178
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1179
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1180
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1181
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
767
1182
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
768
1183
|
url: "/workspaces/{workspaceId}/regions",
|
769
1184
|
method: "get",
|
@@ -771,6 +1186,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
771
1186
|
signal
|
772
1187
|
});
|
773
1188
|
const operationsByTag$1 = {
|
1189
|
+
oAuth: {
|
1190
|
+
getAuthorizationCode,
|
1191
|
+
grantAuthorizationCode,
|
1192
|
+
getUserOAuthClients,
|
1193
|
+
deleteUserOAuthClient,
|
1194
|
+
getUserOAuthAccessTokens,
|
1195
|
+
deleteOAuthAccessToken,
|
1196
|
+
updateOAuthAccessToken
|
1197
|
+
},
|
774
1198
|
users: { getUser, updateUser, deleteUser },
|
775
1199
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
776
1200
|
workspaces: {
|
@@ -796,6 +1220,10 @@ const operationsByTag$1 = {
|
|
796
1220
|
deleteDatabase,
|
797
1221
|
getDatabaseMetadata,
|
798
1222
|
updateDatabaseMetadata,
|
1223
|
+
renameDatabase,
|
1224
|
+
getDatabaseGithubSettings,
|
1225
|
+
updateDatabaseGithubSettings,
|
1226
|
+
deleteDatabaseGithubSettings,
|
799
1227
|
listRegions
|
800
1228
|
}
|
801
1229
|
};
|
@@ -816,8 +1244,12 @@ const providers = {
|
|
816
1244
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
817
1245
|
},
|
818
1246
|
staging: {
|
819
|
-
main: "https://staging.
|
820
|
-
workspaces: "https://{workspaceId}.
|
1247
|
+
main: "https://api.staging-xata.dev",
|
1248
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1249
|
+
},
|
1250
|
+
dev: {
|
1251
|
+
main: "https://api.dev-xata.dev",
|
1252
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
821
1253
|
}
|
822
1254
|
};
|
823
1255
|
function isHostProviderAlias(alias) {
|
@@ -835,15 +1267,22 @@ function parseProviderString(provider = "production") {
|
|
835
1267
|
return null;
|
836
1268
|
return { main, workspaces };
|
837
1269
|
}
|
1270
|
+
function buildProviderString(provider) {
|
1271
|
+
if (isHostProviderAlias(provider))
|
1272
|
+
return provider;
|
1273
|
+
return `${provider.main},${provider.workspaces}`;
|
1274
|
+
}
|
838
1275
|
function parseWorkspacesUrlParts(url) {
|
839
1276
|
if (!isString(url))
|
840
1277
|
return null;
|
841
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
842
|
-
const
|
843
|
-
const
|
1278
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1279
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1280
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1281
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1282
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
844
1283
|
if (!match)
|
845
1284
|
return null;
|
846
|
-
return { workspace: match[1], region: match[2]
|
1285
|
+
return { workspace: match[1], region: match[2] };
|
847
1286
|
}
|
848
1287
|
|
849
1288
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -872,15 +1311,19 @@ class XataApiClient {
|
|
872
1311
|
const provider = options.host ?? "production";
|
873
1312
|
const apiKey = options.apiKey ?? getAPIKey();
|
874
1313
|
const trace = options.trace ?? defaultTrace;
|
1314
|
+
const clientID = generateUUID();
|
875
1315
|
if (!apiKey) {
|
876
1316
|
throw new Error("Could not resolve a valid apiKey");
|
877
1317
|
}
|
878
1318
|
__privateSet$7(this, _extraProps, {
|
879
1319
|
apiUrl: getHostUrl(provider, "main"),
|
880
1320
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
881
|
-
|
1321
|
+
fetch: getFetchImplementation(options.fetch),
|
882
1322
|
apiKey,
|
883
|
-
trace
|
1323
|
+
trace,
|
1324
|
+
clientName: options.clientName,
|
1325
|
+
xataAgentExtra: options.xataAgentExtra,
|
1326
|
+
clientID
|
884
1327
|
});
|
885
1328
|
}
|
886
1329
|
get user() {
|
@@ -933,6 +1376,11 @@ class XataApiClient {
|
|
933
1376
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
934
1377
|
return __privateGet$7(this, _namespaces).records;
|
935
1378
|
}
|
1379
|
+
get files() {
|
1380
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1381
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1382
|
+
return __privateGet$7(this, _namespaces).files;
|
1383
|
+
}
|
936
1384
|
get searchAndFilter() {
|
937
1385
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
938
1386
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1141,6 +1589,20 @@ class BranchApi {
|
|
1141
1589
|
...this.extraProps
|
1142
1590
|
});
|
1143
1591
|
}
|
1592
|
+
copyBranch({
|
1593
|
+
workspace,
|
1594
|
+
region,
|
1595
|
+
database,
|
1596
|
+
branch,
|
1597
|
+
destinationBranch,
|
1598
|
+
limit
|
1599
|
+
}) {
|
1600
|
+
return operationsByTag.branch.copyBranch({
|
1601
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1602
|
+
body: { destinationBranch, limit },
|
1603
|
+
...this.extraProps
|
1604
|
+
});
|
1605
|
+
}
|
1144
1606
|
updateBranchMetadata({
|
1145
1607
|
workspace,
|
1146
1608
|
region,
|
@@ -1496,83 +1958,288 @@ class RecordsApi {
|
|
1496
1958
|
});
|
1497
1959
|
}
|
1498
1960
|
}
|
1499
|
-
class
|
1961
|
+
class FilesApi {
|
1500
1962
|
constructor(extraProps) {
|
1501
1963
|
this.extraProps = extraProps;
|
1502
1964
|
}
|
1503
|
-
|
1965
|
+
getFileItem({
|
1504
1966
|
workspace,
|
1505
1967
|
region,
|
1506
1968
|
database,
|
1507
1969
|
branch,
|
1508
1970
|
table,
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
columns,
|
1513
|
-
consistency
|
1971
|
+
record,
|
1972
|
+
column,
|
1973
|
+
fileId
|
1514
1974
|
}) {
|
1515
|
-
return operationsByTag.
|
1516
|
-
pathParams: {
|
1517
|
-
|
1975
|
+
return operationsByTag.files.getFileItem({
|
1976
|
+
pathParams: {
|
1977
|
+
workspace,
|
1978
|
+
region,
|
1979
|
+
dbBranchName: `${database}:${branch}`,
|
1980
|
+
tableName: table,
|
1981
|
+
recordId: record,
|
1982
|
+
columnName: column,
|
1983
|
+
fileId
|
1984
|
+
},
|
1518
1985
|
...this.extraProps
|
1519
1986
|
});
|
1520
1987
|
}
|
1521
|
-
|
1988
|
+
putFileItem({
|
1522
1989
|
workspace,
|
1523
1990
|
region,
|
1524
1991
|
database,
|
1525
1992
|
branch,
|
1526
1993
|
table,
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
filter,
|
1532
|
-
highlight,
|
1533
|
-
boosters
|
1994
|
+
record,
|
1995
|
+
column,
|
1996
|
+
fileId,
|
1997
|
+
file
|
1534
1998
|
}) {
|
1535
|
-
return operationsByTag.
|
1536
|
-
pathParams: {
|
1537
|
-
|
1999
|
+
return operationsByTag.files.putFileItem({
|
2000
|
+
pathParams: {
|
2001
|
+
workspace,
|
2002
|
+
region,
|
2003
|
+
dbBranchName: `${database}:${branch}`,
|
2004
|
+
tableName: table,
|
2005
|
+
recordId: record,
|
2006
|
+
columnName: column,
|
2007
|
+
fileId
|
2008
|
+
},
|
2009
|
+
// @ts-ignore
|
2010
|
+
body: file,
|
1538
2011
|
...this.extraProps
|
1539
2012
|
});
|
1540
2013
|
}
|
1541
|
-
|
2014
|
+
deleteFileItem({
|
1542
2015
|
workspace,
|
1543
2016
|
region,
|
1544
2017
|
database,
|
1545
2018
|
branch,
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
highlight
|
2019
|
+
table,
|
2020
|
+
record,
|
2021
|
+
column,
|
2022
|
+
fileId
|
1551
2023
|
}) {
|
1552
|
-
return operationsByTag.
|
1553
|
-
pathParams: {
|
1554
|
-
|
2024
|
+
return operationsByTag.files.deleteFileItem({
|
2025
|
+
pathParams: {
|
2026
|
+
workspace,
|
2027
|
+
region,
|
2028
|
+
dbBranchName: `${database}:${branch}`,
|
2029
|
+
tableName: table,
|
2030
|
+
recordId: record,
|
2031
|
+
columnName: column,
|
2032
|
+
fileId
|
2033
|
+
},
|
1555
2034
|
...this.extraProps
|
1556
2035
|
});
|
1557
2036
|
}
|
1558
|
-
|
2037
|
+
getFile({
|
1559
2038
|
workspace,
|
1560
2039
|
region,
|
1561
2040
|
database,
|
1562
2041
|
branch,
|
1563
2042
|
table,
|
1564
|
-
|
1565
|
-
|
1566
|
-
summaries,
|
1567
|
-
sort,
|
1568
|
-
summariesFilter,
|
1569
|
-
page,
|
1570
|
-
consistency
|
2043
|
+
record,
|
2044
|
+
column
|
1571
2045
|
}) {
|
1572
|
-
return operationsByTag.
|
1573
|
-
pathParams: {
|
1574
|
-
|
1575
|
-
|
2046
|
+
return operationsByTag.files.getFile({
|
2047
|
+
pathParams: {
|
2048
|
+
workspace,
|
2049
|
+
region,
|
2050
|
+
dbBranchName: `${database}:${branch}`,
|
2051
|
+
tableName: table,
|
2052
|
+
recordId: record,
|
2053
|
+
columnName: column
|
2054
|
+
},
|
2055
|
+
...this.extraProps
|
2056
|
+
});
|
2057
|
+
}
|
2058
|
+
putFile({
|
2059
|
+
workspace,
|
2060
|
+
region,
|
2061
|
+
database,
|
2062
|
+
branch,
|
2063
|
+
table,
|
2064
|
+
record,
|
2065
|
+
column,
|
2066
|
+
file
|
2067
|
+
}) {
|
2068
|
+
return operationsByTag.files.putFile({
|
2069
|
+
pathParams: {
|
2070
|
+
workspace,
|
2071
|
+
region,
|
2072
|
+
dbBranchName: `${database}:${branch}`,
|
2073
|
+
tableName: table,
|
2074
|
+
recordId: record,
|
2075
|
+
columnName: column
|
2076
|
+
},
|
2077
|
+
body: file,
|
2078
|
+
...this.extraProps
|
2079
|
+
});
|
2080
|
+
}
|
2081
|
+
deleteFile({
|
2082
|
+
workspace,
|
2083
|
+
region,
|
2084
|
+
database,
|
2085
|
+
branch,
|
2086
|
+
table,
|
2087
|
+
record,
|
2088
|
+
column
|
2089
|
+
}) {
|
2090
|
+
return operationsByTag.files.deleteFile({
|
2091
|
+
pathParams: {
|
2092
|
+
workspace,
|
2093
|
+
region,
|
2094
|
+
dbBranchName: `${database}:${branch}`,
|
2095
|
+
tableName: table,
|
2096
|
+
recordId: record,
|
2097
|
+
columnName: column
|
2098
|
+
},
|
2099
|
+
...this.extraProps
|
2100
|
+
});
|
2101
|
+
}
|
2102
|
+
fileAccess({
|
2103
|
+
workspace,
|
2104
|
+
region,
|
2105
|
+
fileId,
|
2106
|
+
verify
|
2107
|
+
}) {
|
2108
|
+
return operationsByTag.files.fileAccess({
|
2109
|
+
pathParams: {
|
2110
|
+
workspace,
|
2111
|
+
region,
|
2112
|
+
fileId
|
2113
|
+
},
|
2114
|
+
queryParams: { verify },
|
2115
|
+
...this.extraProps
|
2116
|
+
});
|
2117
|
+
}
|
2118
|
+
}
|
2119
|
+
class SearchAndFilterApi {
|
2120
|
+
constructor(extraProps) {
|
2121
|
+
this.extraProps = extraProps;
|
2122
|
+
}
|
2123
|
+
queryTable({
|
2124
|
+
workspace,
|
2125
|
+
region,
|
2126
|
+
database,
|
2127
|
+
branch,
|
2128
|
+
table,
|
2129
|
+
filter,
|
2130
|
+
sort,
|
2131
|
+
page,
|
2132
|
+
columns,
|
2133
|
+
consistency
|
2134
|
+
}) {
|
2135
|
+
return operationsByTag.searchAndFilter.queryTable({
|
2136
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2137
|
+
body: { filter, sort, page, columns, consistency },
|
2138
|
+
...this.extraProps
|
2139
|
+
});
|
2140
|
+
}
|
2141
|
+
searchTable({
|
2142
|
+
workspace,
|
2143
|
+
region,
|
2144
|
+
database,
|
2145
|
+
branch,
|
2146
|
+
table,
|
2147
|
+
query,
|
2148
|
+
fuzziness,
|
2149
|
+
target,
|
2150
|
+
prefix,
|
2151
|
+
filter,
|
2152
|
+
highlight,
|
2153
|
+
boosters
|
2154
|
+
}) {
|
2155
|
+
return operationsByTag.searchAndFilter.searchTable({
|
2156
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2157
|
+
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
2158
|
+
...this.extraProps
|
2159
|
+
});
|
2160
|
+
}
|
2161
|
+
searchBranch({
|
2162
|
+
workspace,
|
2163
|
+
region,
|
2164
|
+
database,
|
2165
|
+
branch,
|
2166
|
+
tables,
|
2167
|
+
query,
|
2168
|
+
fuzziness,
|
2169
|
+
prefix,
|
2170
|
+
highlight
|
2171
|
+
}) {
|
2172
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
2173
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2174
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
2175
|
+
...this.extraProps
|
2176
|
+
});
|
2177
|
+
}
|
2178
|
+
vectorSearchTable({
|
2179
|
+
workspace,
|
2180
|
+
region,
|
2181
|
+
database,
|
2182
|
+
branch,
|
2183
|
+
table,
|
2184
|
+
queryVector,
|
2185
|
+
column,
|
2186
|
+
similarityFunction,
|
2187
|
+
size,
|
2188
|
+
filter
|
2189
|
+
}) {
|
2190
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2191
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2192
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2193
|
+
...this.extraProps
|
2194
|
+
});
|
2195
|
+
}
|
2196
|
+
askTable({
|
2197
|
+
workspace,
|
2198
|
+
region,
|
2199
|
+
database,
|
2200
|
+
branch,
|
2201
|
+
table,
|
2202
|
+
options
|
2203
|
+
}) {
|
2204
|
+
return operationsByTag.searchAndFilter.askTable({
|
2205
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2206
|
+
body: { ...options },
|
2207
|
+
...this.extraProps
|
2208
|
+
});
|
2209
|
+
}
|
2210
|
+
askTableSession({
|
2211
|
+
workspace,
|
2212
|
+
region,
|
2213
|
+
database,
|
2214
|
+
branch,
|
2215
|
+
table,
|
2216
|
+
sessionId,
|
2217
|
+
message
|
2218
|
+
}) {
|
2219
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2220
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2221
|
+
body: { message },
|
2222
|
+
...this.extraProps
|
2223
|
+
});
|
2224
|
+
}
|
2225
|
+
summarizeTable({
|
2226
|
+
workspace,
|
2227
|
+
region,
|
2228
|
+
database,
|
2229
|
+
branch,
|
2230
|
+
table,
|
2231
|
+
filter,
|
2232
|
+
columns,
|
2233
|
+
summaries,
|
2234
|
+
sort,
|
2235
|
+
summariesFilter,
|
2236
|
+
page,
|
2237
|
+
consistency
|
2238
|
+
}) {
|
2239
|
+
return operationsByTag.searchAndFilter.summarizeTable({
|
2240
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2241
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
2242
|
+
...this.extraProps
|
1576
2243
|
});
|
1577
2244
|
}
|
1578
2245
|
aggregateTable({
|
@@ -1755,11 +2422,13 @@ class MigrationsApi {
|
|
1755
2422
|
region,
|
1756
2423
|
database,
|
1757
2424
|
branch,
|
1758
|
-
schema
|
2425
|
+
schema,
|
2426
|
+
schemaOperations,
|
2427
|
+
branchOperations
|
1759
2428
|
}) {
|
1760
2429
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1761
2430
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1762
|
-
body: { schema },
|
2431
|
+
body: { schema, schemaOperations, branchOperations },
|
1763
2432
|
...this.extraProps
|
1764
2433
|
});
|
1765
2434
|
}
|
@@ -1769,11 +2438,12 @@ class MigrationsApi {
|
|
1769
2438
|
database,
|
1770
2439
|
branch,
|
1771
2440
|
compare,
|
1772
|
-
|
2441
|
+
sourceBranchOperations,
|
2442
|
+
targetBranchOperations
|
1773
2443
|
}) {
|
1774
2444
|
return operationsByTag.migrations.compareBranchSchemas({
|
1775
2445
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1776
|
-
body: {
|
2446
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1777
2447
|
...this.extraProps
|
1778
2448
|
});
|
1779
2449
|
}
|
@@ -1816,6 +2486,19 @@ class MigrationsApi {
|
|
1816
2486
|
...this.extraProps
|
1817
2487
|
});
|
1818
2488
|
}
|
2489
|
+
pushBranchMigrations({
|
2490
|
+
workspace,
|
2491
|
+
region,
|
2492
|
+
database,
|
2493
|
+
branch,
|
2494
|
+
migrations
|
2495
|
+
}) {
|
2496
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2497
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2498
|
+
body: { migrations },
|
2499
|
+
...this.extraProps
|
2500
|
+
});
|
2501
|
+
}
|
1819
2502
|
}
|
1820
2503
|
class DatabaseApi {
|
1821
2504
|
constructor(extraProps) {
|
@@ -1830,11 +2513,13 @@ class DatabaseApi {
|
|
1830
2513
|
createDatabase({
|
1831
2514
|
workspace,
|
1832
2515
|
database,
|
1833
|
-
data
|
2516
|
+
data,
|
2517
|
+
headers
|
1834
2518
|
}) {
|
1835
2519
|
return operationsByTag.databases.createDatabase({
|
1836
2520
|
pathParams: { workspaceId: workspace, dbName: database },
|
1837
2521
|
body: data,
|
2522
|
+
headers,
|
1838
2523
|
...this.extraProps
|
1839
2524
|
});
|
1840
2525
|
}
|
@@ -1867,6 +2552,46 @@ class DatabaseApi {
|
|
1867
2552
|
...this.extraProps
|
1868
2553
|
});
|
1869
2554
|
}
|
2555
|
+
renameDatabase({
|
2556
|
+
workspace,
|
2557
|
+
database,
|
2558
|
+
newName
|
2559
|
+
}) {
|
2560
|
+
return operationsByTag.databases.renameDatabase({
|
2561
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2562
|
+
body: { newName },
|
2563
|
+
...this.extraProps
|
2564
|
+
});
|
2565
|
+
}
|
2566
|
+
getDatabaseGithubSettings({
|
2567
|
+
workspace,
|
2568
|
+
database
|
2569
|
+
}) {
|
2570
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2571
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2572
|
+
...this.extraProps
|
2573
|
+
});
|
2574
|
+
}
|
2575
|
+
updateDatabaseGithubSettings({
|
2576
|
+
workspace,
|
2577
|
+
database,
|
2578
|
+
settings
|
2579
|
+
}) {
|
2580
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2581
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2582
|
+
body: settings,
|
2583
|
+
...this.extraProps
|
2584
|
+
});
|
2585
|
+
}
|
2586
|
+
deleteDatabaseGithubSettings({
|
2587
|
+
workspace,
|
2588
|
+
database
|
2589
|
+
}) {
|
2590
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2591
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2592
|
+
...this.extraProps
|
2593
|
+
});
|
2594
|
+
}
|
1870
2595
|
listRegions({ workspace }) {
|
1871
2596
|
return operationsByTag.databases.listRegions({
|
1872
2597
|
pathParams: { workspaceId: workspace },
|
@@ -1876,29 +2601,269 @@ class DatabaseApi {
|
|
1876
2601
|
}
|
1877
2602
|
|
1878
2603
|
class XataApiPlugin {
|
1879
|
-
|
1880
|
-
|
1881
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2604
|
+
build(options) {
|
2605
|
+
return new XataApiClient(options);
|
1882
2606
|
}
|
1883
2607
|
}
|
1884
2608
|
|
1885
2609
|
class XataPlugin {
|
1886
2610
|
}
|
1887
2611
|
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
2612
|
+
class FilesPlugin extends XataPlugin {
|
2613
|
+
build(pluginOptions) {
|
2614
|
+
return {
|
2615
|
+
download: async (location) => {
|
2616
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2617
|
+
return await getFileItem({
|
2618
|
+
pathParams: {
|
2619
|
+
workspace: "{workspaceId}",
|
2620
|
+
dbBranchName: "{dbBranch}",
|
2621
|
+
region: "{region}",
|
2622
|
+
tableName: table ?? "",
|
2623
|
+
recordId: record ?? "",
|
2624
|
+
columnName: column ?? "",
|
2625
|
+
fileId
|
2626
|
+
},
|
2627
|
+
...pluginOptions,
|
2628
|
+
rawResponse: true
|
2629
|
+
});
|
2630
|
+
},
|
2631
|
+
upload: async (location, file) => {
|
2632
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2633
|
+
return await putFileItem({
|
2634
|
+
pathParams: {
|
2635
|
+
workspace: "{workspaceId}",
|
2636
|
+
dbBranchName: "{dbBranch}",
|
2637
|
+
region: "{region}",
|
2638
|
+
tableName: table ?? "",
|
2639
|
+
recordId: record ?? "",
|
2640
|
+
columnName: column ?? "",
|
2641
|
+
fileId
|
2642
|
+
},
|
2643
|
+
body: file,
|
2644
|
+
...pluginOptions
|
2645
|
+
});
|
2646
|
+
},
|
2647
|
+
delete: async (location) => {
|
2648
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2649
|
+
return await deleteFileItem({
|
2650
|
+
pathParams: {
|
2651
|
+
workspace: "{workspaceId}",
|
2652
|
+
dbBranchName: "{dbBranch}",
|
2653
|
+
region: "{region}",
|
2654
|
+
tableName: table ?? "",
|
2655
|
+
recordId: record ?? "",
|
2656
|
+
columnName: column ?? "",
|
2657
|
+
fileId
|
2658
|
+
},
|
2659
|
+
...pluginOptions
|
2660
|
+
});
|
2661
|
+
}
|
2662
|
+
};
|
2663
|
+
}
|
2664
|
+
}
|
2665
|
+
|
2666
|
+
function buildTransformString(transformations) {
|
2667
|
+
return transformations.flatMap(
|
2668
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2669
|
+
if (key === "trim") {
|
2670
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2671
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2672
|
+
}
|
2673
|
+
if (key === "gravity" && typeof value === "object") {
|
2674
|
+
const { x = 0.5, y = 0.5 } = value;
|
2675
|
+
return `${key}=${[x, y].join("x")}`;
|
2676
|
+
}
|
2677
|
+
return `${key}=${value}`;
|
2678
|
+
})
|
2679
|
+
).join(",");
|
2680
|
+
}
|
2681
|
+
function transformImage(url, ...transformations) {
|
2682
|
+
if (!isDefined(url))
|
2683
|
+
return void 0;
|
2684
|
+
const transformationsString = buildTransformString(transformations);
|
2685
|
+
const { hostname, pathname, search } = new URL(url);
|
2686
|
+
return `https://${hostname}/transform/${transformationsString}${pathname}${search}`;
|
1893
2687
|
}
|
1894
2688
|
|
2689
|
+
var __defProp$6 = Object.defineProperty;
|
2690
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2691
|
+
var __publicField$6 = (obj, key, value) => {
|
2692
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2693
|
+
return value;
|
2694
|
+
};
|
2695
|
+
class XataFile {
|
2696
|
+
constructor(file) {
|
2697
|
+
/**
|
2698
|
+
* Name of this file.
|
2699
|
+
*/
|
2700
|
+
__publicField$6(this, "name");
|
2701
|
+
/**
|
2702
|
+
* Media type of this file.
|
2703
|
+
*/
|
2704
|
+
__publicField$6(this, "mediaType");
|
2705
|
+
/**
|
2706
|
+
* Base64 encoded content of this file.
|
2707
|
+
*/
|
2708
|
+
__publicField$6(this, "base64Content");
|
2709
|
+
/**
|
2710
|
+
* Whether to enable public url for this file.
|
2711
|
+
*/
|
2712
|
+
__publicField$6(this, "enablePublicUrl");
|
2713
|
+
/**
|
2714
|
+
* Timeout for the signed url.
|
2715
|
+
*/
|
2716
|
+
__publicField$6(this, "signedUrlTimeout");
|
2717
|
+
/**
|
2718
|
+
* Size of this file.
|
2719
|
+
*/
|
2720
|
+
__publicField$6(this, "size");
|
2721
|
+
/**
|
2722
|
+
* Version of this file.
|
2723
|
+
*/
|
2724
|
+
__publicField$6(this, "version");
|
2725
|
+
/**
|
2726
|
+
* Url of this file.
|
2727
|
+
*/
|
2728
|
+
__publicField$6(this, "url");
|
2729
|
+
/**
|
2730
|
+
* Signed url of this file.
|
2731
|
+
*/
|
2732
|
+
__publicField$6(this, "signedUrl");
|
2733
|
+
/**
|
2734
|
+
* Attributes of this file.
|
2735
|
+
*/
|
2736
|
+
__publicField$6(this, "attributes");
|
2737
|
+
this.name = file.name || "";
|
2738
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2739
|
+
this.base64Content = file.base64Content;
|
2740
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2741
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2742
|
+
this.size = file.size ?? 0;
|
2743
|
+
this.version = file.version ?? 1;
|
2744
|
+
this.url = file.url || "";
|
2745
|
+
this.signedUrl = file.signedUrl;
|
2746
|
+
this.attributes = file.attributes || {};
|
2747
|
+
}
|
2748
|
+
static fromBuffer(buffer, options = {}) {
|
2749
|
+
const base64Content = buffer.toString("base64");
|
2750
|
+
return new XataFile({ ...options, base64Content });
|
2751
|
+
}
|
2752
|
+
toBuffer() {
|
2753
|
+
if (!this.base64Content) {
|
2754
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2755
|
+
}
|
2756
|
+
return Buffer.from(this.base64Content, "base64");
|
2757
|
+
}
|
2758
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2759
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2760
|
+
return this.fromUint8Array(uint8Array, options);
|
2761
|
+
}
|
2762
|
+
toArrayBuffer() {
|
2763
|
+
if (!this.base64Content) {
|
2764
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2765
|
+
}
|
2766
|
+
const binary = atob(this.base64Content);
|
2767
|
+
return new ArrayBuffer(binary.length);
|
2768
|
+
}
|
2769
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2770
|
+
let binary = "";
|
2771
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2772
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2773
|
+
}
|
2774
|
+
const base64Content = btoa(binary);
|
2775
|
+
return new XataFile({ ...options, base64Content });
|
2776
|
+
}
|
2777
|
+
toUint8Array() {
|
2778
|
+
if (!this.base64Content) {
|
2779
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2780
|
+
}
|
2781
|
+
const binary = atob(this.base64Content);
|
2782
|
+
const uint8Array = new Uint8Array(binary.length);
|
2783
|
+
for (let i = 0; i < binary.length; i++) {
|
2784
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2785
|
+
}
|
2786
|
+
return uint8Array;
|
2787
|
+
}
|
2788
|
+
static async fromBlob(file, options = {}) {
|
2789
|
+
const name = options.name ?? file.name;
|
2790
|
+
const mediaType = file.type;
|
2791
|
+
const arrayBuffer = await file.arrayBuffer();
|
2792
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2793
|
+
}
|
2794
|
+
toBlob() {
|
2795
|
+
if (!this.base64Content) {
|
2796
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2797
|
+
}
|
2798
|
+
const arrayBuffer = this.toArrayBuffer();
|
2799
|
+
return new Blob([arrayBuffer], { type: this.mediaType });
|
2800
|
+
}
|
2801
|
+
static fromString(string, options = {}) {
|
2802
|
+
const base64Content = btoa(string);
|
2803
|
+
return new XataFile({ ...options, base64Content });
|
2804
|
+
}
|
2805
|
+
toString() {
|
2806
|
+
if (!this.base64Content) {
|
2807
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2808
|
+
}
|
2809
|
+
return atob(this.base64Content);
|
2810
|
+
}
|
2811
|
+
static fromBase64(base64Content, options = {}) {
|
2812
|
+
return new XataFile({ ...options, base64Content });
|
2813
|
+
}
|
2814
|
+
toBase64() {
|
2815
|
+
if (!this.base64Content) {
|
2816
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2817
|
+
}
|
2818
|
+
return this.base64Content;
|
2819
|
+
}
|
2820
|
+
transform(...options) {
|
2821
|
+
return {
|
2822
|
+
url: transformImage(this.url, ...options),
|
2823
|
+
signedUrl: transformImage(this.signedUrl, ...options)
|
2824
|
+
};
|
2825
|
+
}
|
2826
|
+
}
|
2827
|
+
const parseInputFileEntry = async (entry) => {
|
2828
|
+
if (!isDefined(entry))
|
2829
|
+
return null;
|
2830
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2831
|
+
return compactObject({ id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout });
|
2832
|
+
};
|
2833
|
+
|
1895
2834
|
function cleanFilter(filter) {
|
1896
|
-
if (!filter)
|
2835
|
+
if (!isDefined(filter))
|
1897
2836
|
return void 0;
|
1898
|
-
|
1899
|
-
|
2837
|
+
if (!isObject(filter))
|
2838
|
+
return filter;
|
2839
|
+
const values = Object.fromEntries(
|
2840
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2841
|
+
if (!isDefined(value))
|
2842
|
+
return acc;
|
2843
|
+
if (Array.isArray(value)) {
|
2844
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2845
|
+
if (clean.length === 0)
|
2846
|
+
return acc;
|
2847
|
+
return [...acc, [key, clean]];
|
2848
|
+
}
|
2849
|
+
if (isObject(value)) {
|
2850
|
+
const clean = cleanFilter(value);
|
2851
|
+
if (!isDefined(clean))
|
2852
|
+
return acc;
|
2853
|
+
return [...acc, [key, clean]];
|
2854
|
+
}
|
2855
|
+
return [...acc, [key, value]];
|
2856
|
+
}, [])
|
2857
|
+
);
|
2858
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
1900
2859
|
}
|
1901
2860
|
|
2861
|
+
var __defProp$5 = Object.defineProperty;
|
2862
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2863
|
+
var __publicField$5 = (obj, key, value) => {
|
2864
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2865
|
+
return value;
|
2866
|
+
};
|
1902
2867
|
var __accessCheck$6 = (obj, member, msg) => {
|
1903
2868
|
if (!member.has(obj))
|
1904
2869
|
throw TypeError("Cannot " + msg);
|
@@ -1921,22 +2886,58 @@ var _query, _page;
|
|
1921
2886
|
class Page {
|
1922
2887
|
constructor(query, meta, records = []) {
|
1923
2888
|
__privateAdd$6(this, _query, void 0);
|
2889
|
+
/**
|
2890
|
+
* Page metadata, required to retrieve additional records.
|
2891
|
+
*/
|
2892
|
+
__publicField$5(this, "meta");
|
2893
|
+
/**
|
2894
|
+
* The set of results for this page.
|
2895
|
+
*/
|
2896
|
+
__publicField$5(this, "records");
|
1924
2897
|
__privateSet$6(this, _query, query);
|
1925
2898
|
this.meta = meta;
|
1926
2899
|
this.records = new RecordArray(this, records);
|
1927
2900
|
}
|
2901
|
+
/**
|
2902
|
+
* Retrieves the next page of results.
|
2903
|
+
* @param size Maximum number of results to be retrieved.
|
2904
|
+
* @param offset Number of results to skip when retrieving the results.
|
2905
|
+
* @returns The next page or results.
|
2906
|
+
*/
|
1928
2907
|
async nextPage(size, offset) {
|
1929
2908
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1930
2909
|
}
|
2910
|
+
/**
|
2911
|
+
* Retrieves the previous page of results.
|
2912
|
+
* @param size Maximum number of results to be retrieved.
|
2913
|
+
* @param offset Number of results to skip when retrieving the results.
|
2914
|
+
* @returns The previous page or results.
|
2915
|
+
*/
|
1931
2916
|
async previousPage(size, offset) {
|
1932
2917
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1933
2918
|
}
|
2919
|
+
/**
|
2920
|
+
* Retrieves the start page of results.
|
2921
|
+
* @param size Maximum number of results to be retrieved.
|
2922
|
+
* @param offset Number of results to skip when retrieving the results.
|
2923
|
+
* @returns The start page or results.
|
2924
|
+
*/
|
1934
2925
|
async startPage(size, offset) {
|
1935
2926
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1936
2927
|
}
|
2928
|
+
/**
|
2929
|
+
* Retrieves the end page of results.
|
2930
|
+
* @param size Maximum number of results to be retrieved.
|
2931
|
+
* @param offset Number of results to skip when retrieving the results.
|
2932
|
+
* @returns The end page or results.
|
2933
|
+
*/
|
1937
2934
|
async endPage(size, offset) {
|
1938
2935
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1939
2936
|
}
|
2937
|
+
/**
|
2938
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2939
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2940
|
+
*/
|
1940
2941
|
hasNextPage() {
|
1941
2942
|
return this.meta.page.more;
|
1942
2943
|
}
|
@@ -1949,7 +2950,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1949
2950
|
function isCursorPaginationOptions(options) {
|
1950
2951
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1951
2952
|
}
|
1952
|
-
const _RecordArray = class extends Array {
|
2953
|
+
const _RecordArray = class _RecordArray extends Array {
|
1953
2954
|
constructor(...args) {
|
1954
2955
|
super(..._RecordArray.parseConstructorParams(...args));
|
1955
2956
|
__privateAdd$6(this, _page, void 0);
|
@@ -1968,32 +2969,67 @@ const _RecordArray = class extends Array {
|
|
1968
2969
|
toArray() {
|
1969
2970
|
return new Array(...this);
|
1970
2971
|
}
|
2972
|
+
toSerializable() {
|
2973
|
+
return JSON.parse(this.toString());
|
2974
|
+
}
|
2975
|
+
toString() {
|
2976
|
+
return JSON.stringify(this.toArray());
|
2977
|
+
}
|
1971
2978
|
map(callbackfn, thisArg) {
|
1972
2979
|
return this.toArray().map(callbackfn, thisArg);
|
1973
2980
|
}
|
2981
|
+
/**
|
2982
|
+
* Retrieve next page of records
|
2983
|
+
*
|
2984
|
+
* @returns A new array of objects
|
2985
|
+
*/
|
1974
2986
|
async nextPage(size, offset) {
|
1975
2987
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1976
2988
|
return new _RecordArray(newPage);
|
1977
2989
|
}
|
2990
|
+
/**
|
2991
|
+
* Retrieve previous page of records
|
2992
|
+
*
|
2993
|
+
* @returns A new array of objects
|
2994
|
+
*/
|
1978
2995
|
async previousPage(size, offset) {
|
1979
2996
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1980
2997
|
return new _RecordArray(newPage);
|
1981
2998
|
}
|
2999
|
+
/**
|
3000
|
+
* Retrieve start page of records
|
3001
|
+
*
|
3002
|
+
* @returns A new array of objects
|
3003
|
+
*/
|
1982
3004
|
async startPage(size, offset) {
|
1983
3005
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1984
3006
|
return new _RecordArray(newPage);
|
1985
3007
|
}
|
3008
|
+
/**
|
3009
|
+
* Retrieve end page of records
|
3010
|
+
*
|
3011
|
+
* @returns A new array of objects
|
3012
|
+
*/
|
1986
3013
|
async endPage(size, offset) {
|
1987
3014
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1988
3015
|
return new _RecordArray(newPage);
|
1989
3016
|
}
|
3017
|
+
/**
|
3018
|
+
* @returns Boolean indicating if there is a next page
|
3019
|
+
*/
|
1990
3020
|
hasNextPage() {
|
1991
3021
|
return __privateGet$6(this, _page).meta.page.more;
|
1992
3022
|
}
|
1993
3023
|
};
|
1994
|
-
let RecordArray = _RecordArray;
|
1995
3024
|
_page = new WeakMap();
|
3025
|
+
let RecordArray = _RecordArray;
|
1996
3026
|
|
3027
|
+
var __defProp$4 = Object.defineProperty;
|
3028
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3029
|
+
var __publicField$4 = (obj, key, value) => {
|
3030
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3031
|
+
return value;
|
3032
|
+
};
|
1997
3033
|
var __accessCheck$5 = (obj, member, msg) => {
|
1998
3034
|
if (!member.has(obj))
|
1999
3035
|
throw TypeError("Cannot " + msg);
|
@@ -2017,14 +3053,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2017
3053
|
return method;
|
2018
3054
|
};
|
2019
3055
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2020
|
-
const _Query = class {
|
3056
|
+
const _Query = class _Query {
|
2021
3057
|
constructor(repository, table, data, rawParent) {
|
2022
3058
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2023
3059
|
__privateAdd$5(this, _table$1, void 0);
|
2024
3060
|
__privateAdd$5(this, _repository, void 0);
|
2025
3061
|
__privateAdd$5(this, _data, { filter: {} });
|
2026
|
-
|
2027
|
-
this
|
3062
|
+
// Implements pagination
|
3063
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
3064
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
2028
3065
|
__privateSet$5(this, _table$1, table);
|
2029
3066
|
if (repository) {
|
2030
3067
|
__privateSet$5(this, _repository, repository);
|
@@ -2039,6 +3076,7 @@ const _Query = class {
|
|
2039
3076
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
2040
3077
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
2041
3078
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
3079
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
2042
3080
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
2043
3081
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2044
3082
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -2059,18 +3097,38 @@ const _Query = class {
|
|
2059
3097
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2060
3098
|
return toBase64(key);
|
2061
3099
|
}
|
3100
|
+
/**
|
3101
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3102
|
+
* @param queries An array of subqueries.
|
3103
|
+
* @returns A new Query object.
|
3104
|
+
*/
|
2062
3105
|
any(...queries) {
|
2063
3106
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2064
3107
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2065
3108
|
}
|
3109
|
+
/**
|
3110
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3111
|
+
* @param queries An array of subqueries.
|
3112
|
+
* @returns A new Query object.
|
3113
|
+
*/
|
2066
3114
|
all(...queries) {
|
2067
3115
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2068
3116
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2069
3117
|
}
|
3118
|
+
/**
|
3119
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3120
|
+
* @param queries An array of subqueries.
|
3121
|
+
* @returns A new Query object.
|
3122
|
+
*/
|
2070
3123
|
not(...queries) {
|
2071
3124
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2072
3125
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2073
3126
|
}
|
3127
|
+
/**
|
3128
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3129
|
+
* @param queries An array of subqueries.
|
3130
|
+
* @returns A new Query object.
|
3131
|
+
*/
|
2074
3132
|
none(...queries) {
|
2075
3133
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2076
3134
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2093,6 +3151,11 @@ const _Query = class {
|
|
2093
3151
|
const sort = [...originalSort, { column, direction }];
|
2094
3152
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2095
3153
|
}
|
3154
|
+
/**
|
3155
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3156
|
+
* @param columns Array of column names to be returned by the query.
|
3157
|
+
* @returns A new Query object.
|
3158
|
+
*/
|
2096
3159
|
select(columns) {
|
2097
3160
|
return new _Query(
|
2098
3161
|
__privateGet$5(this, _repository),
|
@@ -2105,6 +3168,12 @@ const _Query = class {
|
|
2105
3168
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2106
3169
|
return __privateGet$5(this, _repository).query(query);
|
2107
3170
|
}
|
3171
|
+
/**
|
3172
|
+
* Get results in an iterator
|
3173
|
+
*
|
3174
|
+
* @async
|
3175
|
+
* @returns Async interable of results
|
3176
|
+
*/
|
2108
3177
|
async *[Symbol.asyncIterator]() {
|
2109
3178
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2110
3179
|
yield record;
|
@@ -2165,26 +3234,53 @@ const _Query = class {
|
|
2165
3234
|
);
|
2166
3235
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2167
3236
|
}
|
3237
|
+
/**
|
3238
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3239
|
+
* @param ttl The cache TTL in milliseconds.
|
3240
|
+
* @returns A new Query object.
|
3241
|
+
*/
|
2168
3242
|
cache(ttl) {
|
2169
3243
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2170
3244
|
}
|
3245
|
+
/**
|
3246
|
+
* Retrieve next page of records
|
3247
|
+
*
|
3248
|
+
* @returns A new page object.
|
3249
|
+
*/
|
2171
3250
|
nextPage(size, offset) {
|
2172
3251
|
return this.startPage(size, offset);
|
2173
3252
|
}
|
3253
|
+
/**
|
3254
|
+
* Retrieve previous page of records
|
3255
|
+
*
|
3256
|
+
* @returns A new page object
|
3257
|
+
*/
|
2174
3258
|
previousPage(size, offset) {
|
2175
3259
|
return this.startPage(size, offset);
|
2176
3260
|
}
|
3261
|
+
/**
|
3262
|
+
* Retrieve start page of records
|
3263
|
+
*
|
3264
|
+
* @returns A new page object
|
3265
|
+
*/
|
2177
3266
|
startPage(size, offset) {
|
2178
3267
|
return this.getPaginated({ pagination: { size, offset } });
|
2179
3268
|
}
|
3269
|
+
/**
|
3270
|
+
* Retrieve last page of records
|
3271
|
+
*
|
3272
|
+
* @returns A new page object
|
3273
|
+
*/
|
2180
3274
|
endPage(size, offset) {
|
2181
3275
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2182
3276
|
}
|
3277
|
+
/**
|
3278
|
+
* @returns Boolean indicating if there is a next page
|
3279
|
+
*/
|
2183
3280
|
hasNextPage() {
|
2184
3281
|
return this.meta.page.more;
|
2185
3282
|
}
|
2186
3283
|
};
|
2187
|
-
let Query = _Query;
|
2188
3284
|
_table$1 = new WeakMap();
|
2189
3285
|
_repository = new WeakMap();
|
2190
3286
|
_data = new WeakMap();
|
@@ -2199,6 +3295,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2199
3295
|
}
|
2200
3296
|
return value;
|
2201
3297
|
};
|
3298
|
+
let Query = _Query;
|
2202
3299
|
function cleanParent(data, parent) {
|
2203
3300
|
if (isCursorPaginationOptions(data.pagination)) {
|
2204
3301
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2206,6 +3303,22 @@ function cleanParent(data, parent) {
|
|
2206
3303
|
return parent;
|
2207
3304
|
}
|
2208
3305
|
|
3306
|
+
const RecordColumnTypes = [
|
3307
|
+
"bool",
|
3308
|
+
"int",
|
3309
|
+
"float",
|
3310
|
+
"string",
|
3311
|
+
"text",
|
3312
|
+
"email",
|
3313
|
+
"multiple",
|
3314
|
+
"link",
|
3315
|
+
"object",
|
3316
|
+
"datetime",
|
3317
|
+
"vector",
|
3318
|
+
"file[]",
|
3319
|
+
"file",
|
3320
|
+
"json"
|
3321
|
+
];
|
2209
3322
|
function isIdentifiable(x) {
|
2210
3323
|
return isObject(x) && isString(x?.id);
|
2211
3324
|
}
|
@@ -2219,7 +3332,11 @@ function isSortFilterString(value) {
|
|
2219
3332
|
return isString(value);
|
2220
3333
|
}
|
2221
3334
|
function isSortFilterBase(filter) {
|
2222
|
-
return isObject(filter) && Object.
|
3335
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3336
|
+
if (key === "*")
|
3337
|
+
return value === "random";
|
3338
|
+
return value === "asc" || value === "desc";
|
3339
|
+
});
|
2223
3340
|
}
|
2224
3341
|
function isSortFilterObject(filter) {
|
2225
3342
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2260,7 +3377,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2260
3377
|
__accessCheck$4(obj, member, "access private method");
|
2261
3378
|
return method;
|
2262
3379
|
};
|
2263
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
3380
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1, _transformObjectToApi, transformObjectToApi_fn;
|
2264
3381
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2265
3382
|
class Repository extends Query {
|
2266
3383
|
}
|
@@ -2282,6 +3399,7 @@ class RestRepository extends Query {
|
|
2282
3399
|
__privateAdd$4(this, _setCacheQuery);
|
2283
3400
|
__privateAdd$4(this, _getCacheQuery);
|
2284
3401
|
__privateAdd$4(this, _getSchemaTables$1);
|
3402
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2285
3403
|
__privateAdd$4(this, _table, void 0);
|
2286
3404
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2287
3405
|
__privateAdd$4(this, _db, void 0);
|
@@ -2292,10 +3410,7 @@ class RestRepository extends Query {
|
|
2292
3410
|
__privateSet$4(this, _db, options.db);
|
2293
3411
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2294
3412
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2295
|
-
__privateSet$4(this, _getFetchProps,
|
2296
|
-
const props = await options.pluginOptions.getFetchProps();
|
2297
|
-
return { ...props, sessionID: generateUUID() };
|
2298
|
-
});
|
3413
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2299
3414
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2300
3415
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2301
3416
|
return trace(name, fn, {
|
@@ -2352,7 +3467,6 @@ class RestRepository extends Query {
|
|
2352
3467
|
}
|
2353
3468
|
const id = extractId(a);
|
2354
3469
|
if (id) {
|
2355
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2356
3470
|
try {
|
2357
3471
|
const response = await getRecord({
|
2358
3472
|
pathParams: {
|
@@ -2363,7 +3477,7 @@ class RestRepository extends Query {
|
|
2363
3477
|
recordId: id
|
2364
3478
|
},
|
2365
3479
|
queryParams: { columns },
|
2366
|
-
...
|
3480
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2367
3481
|
});
|
2368
3482
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2369
3483
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2412,13 +3526,19 @@ class RestRepository extends Query {
|
|
2412
3526
|
const result = await this.read(a, columns);
|
2413
3527
|
return result;
|
2414
3528
|
}
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
3529
|
+
try {
|
3530
|
+
if (isString(a) && isObject(b)) {
|
3531
|
+
const columns = isStringArray(c) ? c : void 0;
|
3532
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3533
|
+
}
|
3534
|
+
if (isObject(a) && isString(a.id)) {
|
3535
|
+
const columns = isStringArray(b) ? b : void 0;
|
3536
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3537
|
+
}
|
3538
|
+
} catch (error) {
|
3539
|
+
if (error.status === 422)
|
3540
|
+
return null;
|
3541
|
+
throw error;
|
2422
3542
|
}
|
2423
3543
|
throw new Error("Invalid arguments for update method");
|
2424
3544
|
});
|
@@ -2457,12 +3577,22 @@ class RestRepository extends Query {
|
|
2457
3577
|
return result;
|
2458
3578
|
}
|
2459
3579
|
if (isString(a) && isObject(b)) {
|
3580
|
+
if (a === "")
|
3581
|
+
throw new Error("The id can't be empty");
|
2460
3582
|
const columns = isStringArray(c) ? c : void 0;
|
2461
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3583
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2462
3584
|
}
|
2463
3585
|
if (isObject(a) && isString(a.id)) {
|
3586
|
+
if (a.id === "")
|
3587
|
+
throw new Error("The id can't be empty");
|
2464
3588
|
const columns = isStringArray(c) ? c : void 0;
|
2465
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3589
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3590
|
+
}
|
3591
|
+
if (!isDefined(a) && isObject(b)) {
|
3592
|
+
return await this.create(b, c);
|
3593
|
+
}
|
3594
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3595
|
+
return await this.create(a, b);
|
2466
3596
|
}
|
2467
3597
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2468
3598
|
});
|
@@ -2479,12 +3609,22 @@ class RestRepository extends Query {
|
|
2479
3609
|
return result;
|
2480
3610
|
}
|
2481
3611
|
if (isString(a) && isObject(b)) {
|
3612
|
+
if (a === "")
|
3613
|
+
throw new Error("The id can't be empty");
|
2482
3614
|
const columns = isStringArray(c) ? c : void 0;
|
2483
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3615
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2484
3616
|
}
|
2485
3617
|
if (isObject(a) && isString(a.id)) {
|
3618
|
+
if (a.id === "")
|
3619
|
+
throw new Error("The id can't be empty");
|
2486
3620
|
const columns = isStringArray(c) ? c : void 0;
|
2487
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3621
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3622
|
+
}
|
3623
|
+
if (!isDefined(a) && isObject(b)) {
|
3624
|
+
return await this.create(b, c);
|
3625
|
+
}
|
3626
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3627
|
+
return await this.create(a, b);
|
2488
3628
|
}
|
2489
3629
|
throw new Error("Invalid arguments for createOrReplace method");
|
2490
3630
|
});
|
@@ -2535,7 +3675,6 @@ class RestRepository extends Query {
|
|
2535
3675
|
}
|
2536
3676
|
async search(query, options = {}) {
|
2537
3677
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2538
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2539
3678
|
const { records } = await searchTable({
|
2540
3679
|
pathParams: {
|
2541
3680
|
workspace: "{workspaceId}",
|
@@ -2549,9 +3688,33 @@ class RestRepository extends Query {
|
|
2549
3688
|
prefix: options.prefix,
|
2550
3689
|
highlight: options.highlight,
|
2551
3690
|
filter: options.filter,
|
2552
|
-
boosters: options.boosters
|
3691
|
+
boosters: options.boosters,
|
3692
|
+
page: options.page,
|
3693
|
+
target: options.target
|
2553
3694
|
},
|
2554
|
-
...
|
3695
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3696
|
+
});
|
3697
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3698
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3699
|
+
});
|
3700
|
+
}
|
3701
|
+
async vectorSearch(column, query, options) {
|
3702
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3703
|
+
const { records } = await vectorSearchTable({
|
3704
|
+
pathParams: {
|
3705
|
+
workspace: "{workspaceId}",
|
3706
|
+
dbBranchName: "{dbBranch}",
|
3707
|
+
region: "{region}",
|
3708
|
+
tableName: __privateGet$4(this, _table)
|
3709
|
+
},
|
3710
|
+
body: {
|
3711
|
+
column,
|
3712
|
+
queryVector: query,
|
3713
|
+
similarityFunction: options?.similarityFunction,
|
3714
|
+
size: options?.size,
|
3715
|
+
filter: options?.filter
|
3716
|
+
},
|
3717
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2555
3718
|
});
|
2556
3719
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2557
3720
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2559,7 +3722,6 @@ class RestRepository extends Query {
|
|
2559
3722
|
}
|
2560
3723
|
async aggregate(aggs, filter) {
|
2561
3724
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2562
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2563
3725
|
const result = await aggregateTable({
|
2564
3726
|
pathParams: {
|
2565
3727
|
workspace: "{workspaceId}",
|
@@ -2568,7 +3730,7 @@ class RestRepository extends Query {
|
|
2568
3730
|
tableName: __privateGet$4(this, _table)
|
2569
3731
|
},
|
2570
3732
|
body: { aggs, filter },
|
2571
|
-
...
|
3733
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2572
3734
|
});
|
2573
3735
|
return result;
|
2574
3736
|
});
|
@@ -2579,7 +3741,6 @@ class RestRepository extends Query {
|
|
2579
3741
|
if (cacheQuery)
|
2580
3742
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2581
3743
|
const data = query.getQueryOptions();
|
2582
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2583
3744
|
const { meta, records: objects } = await queryTable({
|
2584
3745
|
pathParams: {
|
2585
3746
|
workspace: "{workspaceId}",
|
@@ -2591,10 +3752,11 @@ class RestRepository extends Query {
|
|
2591
3752
|
filter: cleanFilter(data.filter),
|
2592
3753
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2593
3754
|
page: data.pagination,
|
2594
|
-
columns: data.columns ?? ["*"]
|
3755
|
+
columns: data.columns ?? ["*"],
|
3756
|
+
consistency: data.consistency
|
2595
3757
|
},
|
2596
3758
|
fetchOptions: data.fetchOptions,
|
2597
|
-
...
|
3759
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2598
3760
|
});
|
2599
3761
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2600
3762
|
const records = objects.map(
|
@@ -2607,7 +3769,6 @@ class RestRepository extends Query {
|
|
2607
3769
|
async summarizeTable(query, summaries, summariesFilter) {
|
2608
3770
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2609
3771
|
const data = query.getQueryOptions();
|
2610
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2611
3772
|
const result = await summarizeTable({
|
2612
3773
|
pathParams: {
|
2613
3774
|
workspace: "{workspaceId}",
|
@@ -2619,15 +3780,49 @@ class RestRepository extends Query {
|
|
2619
3780
|
filter: cleanFilter(data.filter),
|
2620
3781
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2621
3782
|
columns: data.columns,
|
3783
|
+
consistency: data.consistency,
|
2622
3784
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2623
3785
|
summaries,
|
2624
3786
|
summariesFilter
|
2625
3787
|
},
|
2626
|
-
...
|
3788
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2627
3789
|
});
|
2628
3790
|
return result;
|
2629
3791
|
});
|
2630
3792
|
}
|
3793
|
+
ask(question, options) {
|
3794
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3795
|
+
const params = {
|
3796
|
+
pathParams: {
|
3797
|
+
workspace: "{workspaceId}",
|
3798
|
+
dbBranchName: "{dbBranch}",
|
3799
|
+
region: "{region}",
|
3800
|
+
tableName: __privateGet$4(this, _table),
|
3801
|
+
sessionId: options?.sessionId
|
3802
|
+
},
|
3803
|
+
body: {
|
3804
|
+
...questionParam,
|
3805
|
+
rules: options?.rules,
|
3806
|
+
searchType: options?.searchType,
|
3807
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3808
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3809
|
+
},
|
3810
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3811
|
+
};
|
3812
|
+
if (options?.onMessage) {
|
3813
|
+
fetchSSERequest({
|
3814
|
+
endpoint: "dataPlane",
|
3815
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3816
|
+
method: "POST",
|
3817
|
+
onMessage: (message) => {
|
3818
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3819
|
+
},
|
3820
|
+
...params
|
3821
|
+
});
|
3822
|
+
} else {
|
3823
|
+
return askTableSession(params);
|
3824
|
+
}
|
3825
|
+
}
|
2631
3826
|
}
|
2632
3827
|
_table = new WeakMap();
|
2633
3828
|
_getFetchProps = new WeakMap();
|
@@ -2637,8 +3832,7 @@ _schemaTables$2 = new WeakMap();
|
|
2637
3832
|
_trace = new WeakMap();
|
2638
3833
|
_insertRecordWithoutId = new WeakSet();
|
2639
3834
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2640
|
-
const
|
2641
|
-
const record = transformObjectLinks(object);
|
3835
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2642
3836
|
const response = await insertRecord({
|
2643
3837
|
pathParams: {
|
2644
3838
|
workspace: "{workspaceId}",
|
@@ -2648,15 +3842,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2648
3842
|
},
|
2649
3843
|
queryParams: { columns },
|
2650
3844
|
body: record,
|
2651
|
-
...
|
3845
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2652
3846
|
});
|
2653
3847
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2654
3848
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2655
3849
|
};
|
2656
3850
|
_insertRecordWithId = new WeakSet();
|
2657
3851
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2658
|
-
|
2659
|
-
|
3852
|
+
if (!recordId)
|
3853
|
+
return null;
|
3854
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2660
3855
|
const response = await insertRecordWithID({
|
2661
3856
|
pathParams: {
|
2662
3857
|
workspace: "{workspaceId}",
|
@@ -2667,30 +3862,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2667
3862
|
},
|
2668
3863
|
body: record,
|
2669
3864
|
queryParams: { createOnly, columns, ifVersion },
|
2670
|
-
...
|
3865
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2671
3866
|
});
|
2672
3867
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2673
3868
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2674
3869
|
};
|
2675
3870
|
_insertRecords = new WeakSet();
|
2676
3871
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2677
|
-
const
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
|
2682
|
-
BULK_OPERATION_MAX_SIZE
|
2683
|
-
);
|
3872
|
+
const operations = await promiseMap(objects, async (object) => {
|
3873
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3874
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3875
|
+
});
|
3876
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2684
3877
|
const ids = [];
|
2685
|
-
for (const
|
3878
|
+
for (const operations2 of chunkedOperations) {
|
2686
3879
|
const { results } = await branchTransaction({
|
2687
3880
|
pathParams: {
|
2688
3881
|
workspace: "{workspaceId}",
|
2689
3882
|
dbBranchName: "{dbBranch}",
|
2690
3883
|
region: "{region}"
|
2691
3884
|
},
|
2692
|
-
body: { operations },
|
2693
|
-
...
|
3885
|
+
body: { operations: operations2 },
|
3886
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2694
3887
|
});
|
2695
3888
|
for (const result of results) {
|
2696
3889
|
if (result.operation === "insert") {
|
@@ -2704,8 +3897,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2704
3897
|
};
|
2705
3898
|
_updateRecordWithID = new WeakSet();
|
2706
3899
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2707
|
-
|
2708
|
-
|
3900
|
+
if (!recordId)
|
3901
|
+
return null;
|
3902
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2709
3903
|
try {
|
2710
3904
|
const response = await updateRecordWithID({
|
2711
3905
|
pathParams: {
|
@@ -2717,7 +3911,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2717
3911
|
},
|
2718
3912
|
queryParams: { columns, ifVersion },
|
2719
3913
|
body: record,
|
2720
|
-
...
|
3914
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2721
3915
|
});
|
2722
3916
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2723
3917
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2730,23 +3924,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2730
3924
|
};
|
2731
3925
|
_updateRecords = new WeakSet();
|
2732
3926
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2733
|
-
const
|
2734
|
-
|
2735
|
-
|
2736
|
-
|
2737
|
-
|
2738
|
-
BULK_OPERATION_MAX_SIZE
|
2739
|
-
);
|
3927
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3928
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3929
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3930
|
+
});
|
3931
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2740
3932
|
const ids = [];
|
2741
|
-
for (const
|
3933
|
+
for (const operations2 of chunkedOperations) {
|
2742
3934
|
const { results } = await branchTransaction({
|
2743
3935
|
pathParams: {
|
2744
3936
|
workspace: "{workspaceId}",
|
2745
3937
|
dbBranchName: "{dbBranch}",
|
2746
3938
|
region: "{region}"
|
2747
3939
|
},
|
2748
|
-
body: { operations },
|
2749
|
-
...
|
3940
|
+
body: { operations: operations2 },
|
3941
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2750
3942
|
});
|
2751
3943
|
for (const result of results) {
|
2752
3944
|
if (result.operation === "update") {
|
@@ -2760,7 +3952,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2760
3952
|
};
|
2761
3953
|
_upsertRecordWithID = new WeakSet();
|
2762
3954
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2763
|
-
|
3955
|
+
if (!recordId)
|
3956
|
+
return null;
|
2764
3957
|
const response = await upsertRecordWithID({
|
2765
3958
|
pathParams: {
|
2766
3959
|
workspace: "{workspaceId}",
|
@@ -2771,14 +3964,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2771
3964
|
},
|
2772
3965
|
queryParams: { columns, ifVersion },
|
2773
3966
|
body: object,
|
2774
|
-
...
|
3967
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2775
3968
|
});
|
2776
3969
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2777
3970
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2778
3971
|
};
|
2779
3972
|
_deleteRecord = new WeakSet();
|
2780
3973
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2781
|
-
|
3974
|
+
if (!recordId)
|
3975
|
+
return null;
|
2782
3976
|
try {
|
2783
3977
|
const response = await deleteRecord({
|
2784
3978
|
pathParams: {
|
@@ -2789,7 +3983,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2789
3983
|
recordId
|
2790
3984
|
},
|
2791
3985
|
queryParams: { columns },
|
2792
|
-
...
|
3986
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2793
3987
|
});
|
2794
3988
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2795
3989
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2802,9 +3996,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2802
3996
|
};
|
2803
3997
|
_deleteRecords = new WeakSet();
|
2804
3998
|
deleteRecords_fn = async function(recordIds) {
|
2805
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2806
3999
|
const chunkedOperations = chunk(
|
2807
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
4000
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2808
4001
|
BULK_OPERATION_MAX_SIZE
|
2809
4002
|
);
|
2810
4003
|
for (const operations of chunkedOperations) {
|
@@ -2815,21 +4008,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2815
4008
|
region: "{region}"
|
2816
4009
|
},
|
2817
4010
|
body: { operations },
|
2818
|
-
...
|
4011
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2819
4012
|
});
|
2820
4013
|
}
|
2821
4014
|
};
|
2822
4015
|
_setCacheQuery = new WeakSet();
|
2823
4016
|
setCacheQuery_fn = async function(query, meta, records) {
|
2824
|
-
await __privateGet$4(this, _cache)
|
4017
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2825
4018
|
};
|
2826
4019
|
_getCacheQuery = new WeakSet();
|
2827
4020
|
getCacheQuery_fn = async function(query) {
|
2828
4021
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2829
|
-
const result = await __privateGet$4(this, _cache)
|
4022
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2830
4023
|
if (!result)
|
2831
4024
|
return null;
|
2832
|
-
const
|
4025
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4026
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2833
4027
|
if (ttl < 0)
|
2834
4028
|
return null;
|
2835
4029
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2839,15 +4033,46 @@ _getSchemaTables$1 = new WeakSet();
|
|
2839
4033
|
getSchemaTables_fn$1 = async function() {
|
2840
4034
|
if (__privateGet$4(this, _schemaTables$2))
|
2841
4035
|
return __privateGet$4(this, _schemaTables$2);
|
2842
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2843
4036
|
const { schema } = await getBranchDetails({
|
2844
4037
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2845
|
-
...
|
4038
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2846
4039
|
});
|
2847
4040
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2848
4041
|
return schema.tables;
|
2849
4042
|
};
|
2850
|
-
|
4043
|
+
_transformObjectToApi = new WeakSet();
|
4044
|
+
transformObjectToApi_fn = async function(object) {
|
4045
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4046
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4047
|
+
if (!schema)
|
4048
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4049
|
+
const result = {};
|
4050
|
+
for (const [key, value] of Object.entries(object)) {
|
4051
|
+
if (key === "xata")
|
4052
|
+
continue;
|
4053
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4054
|
+
switch (type) {
|
4055
|
+
case "link": {
|
4056
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4057
|
+
break;
|
4058
|
+
}
|
4059
|
+
case "datetime": {
|
4060
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4061
|
+
break;
|
4062
|
+
}
|
4063
|
+
case `file`:
|
4064
|
+
result[key] = await parseInputFileEntry(value);
|
4065
|
+
break;
|
4066
|
+
case "file[]":
|
4067
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4068
|
+
break;
|
4069
|
+
default:
|
4070
|
+
result[key] = value;
|
4071
|
+
}
|
4072
|
+
}
|
4073
|
+
return result;
|
4074
|
+
};
|
4075
|
+
const removeLinksFromObject = (object) => {
|
2851
4076
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
2852
4077
|
if (key === "xata")
|
2853
4078
|
return acc;
|
@@ -2855,23 +4080,23 @@ const transformObjectLinks = (object) => {
|
|
2855
4080
|
}, {});
|
2856
4081
|
};
|
2857
4082
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2858
|
-
const
|
4083
|
+
const data = {};
|
2859
4084
|
const { xata, ...rest } = object ?? {};
|
2860
|
-
Object.assign(
|
4085
|
+
Object.assign(data, rest);
|
2861
4086
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2862
4087
|
if (!columns)
|
2863
4088
|
console.error(`Table ${table} not found in schema`);
|
2864
4089
|
for (const column of columns ?? []) {
|
2865
4090
|
if (!isValidColumn(selectedColumns, column))
|
2866
4091
|
continue;
|
2867
|
-
const value =
|
4092
|
+
const value = data[column.name];
|
2868
4093
|
switch (column.type) {
|
2869
4094
|
case "datetime": {
|
2870
4095
|
const date = value !== void 0 ? new Date(value) : null;
|
2871
4096
|
if (date !== null && isNaN(date.getTime())) {
|
2872
4097
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2873
4098
|
} else {
|
2874
|
-
|
4099
|
+
data[column.name] = date;
|
2875
4100
|
}
|
2876
4101
|
break;
|
2877
4102
|
}
|
@@ -2890,44 +4115,60 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2890
4115
|
}
|
2891
4116
|
return acc;
|
2892
4117
|
}, []);
|
2893
|
-
|
4118
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2894
4119
|
} else {
|
2895
|
-
|
4120
|
+
data[column.name] = null;
|
2896
4121
|
}
|
2897
4122
|
break;
|
2898
4123
|
}
|
4124
|
+
case "file":
|
4125
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4126
|
+
break;
|
4127
|
+
case "file[]":
|
4128
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4129
|
+
break;
|
2899
4130
|
default:
|
2900
|
-
|
4131
|
+
data[column.name] = value ?? null;
|
2901
4132
|
if (column.notNull === true && value === null) {
|
2902
4133
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2903
4134
|
}
|
2904
4135
|
break;
|
2905
4136
|
}
|
2906
4137
|
}
|
2907
|
-
|
2908
|
-
|
4138
|
+
const record = { ...data };
|
4139
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
4140
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4141
|
+
record.read = function(columns2) {
|
4142
|
+
return db[table].read(record["id"], columns2);
|
2909
4143
|
};
|
2910
|
-
|
4144
|
+
record.update = function(data2, b, c) {
|
2911
4145
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2912
4146
|
const ifVersion = parseIfVersion(b, c);
|
2913
|
-
return db[table].update(
|
4147
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2914
4148
|
};
|
2915
|
-
|
4149
|
+
record.replace = function(data2, b, c) {
|
2916
4150
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2917
4151
|
const ifVersion = parseIfVersion(b, c);
|
2918
|
-
return db[table].createOrReplace(
|
4152
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4153
|
+
};
|
4154
|
+
record.delete = function() {
|
4155
|
+
return db[table].delete(record["id"]);
|
4156
|
+
};
|
4157
|
+
record.xata = Object.freeze(metadata);
|
4158
|
+
record.getMetadata = function() {
|
4159
|
+
return record.xata;
|
2919
4160
|
};
|
2920
|
-
|
2921
|
-
return
|
4161
|
+
record.toSerializable = function() {
|
4162
|
+
return JSON.parse(JSON.stringify(serializable));
|
2922
4163
|
};
|
2923
|
-
|
2924
|
-
return
|
4164
|
+
record.toString = function() {
|
4165
|
+
return JSON.stringify(serializable);
|
2925
4166
|
};
|
2926
|
-
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
2927
|
-
Object.defineProperty(
|
4167
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4168
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2928
4169
|
}
|
2929
|
-
Object.freeze(
|
2930
|
-
return
|
4170
|
+
Object.freeze(record);
|
4171
|
+
return record;
|
2931
4172
|
};
|
2932
4173
|
function extractId(value) {
|
2933
4174
|
if (isString(value))
|
@@ -2939,11 +4180,7 @@ function extractId(value) {
|
|
2939
4180
|
function isValidColumn(columns, column) {
|
2940
4181
|
if (columns.includes("*"))
|
2941
4182
|
return true;
|
2942
|
-
|
2943
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2944
|
-
return linkColumns.length > 0;
|
2945
|
-
}
|
2946
|
-
return columns.includes(column.name);
|
4183
|
+
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
2947
4184
|
}
|
2948
4185
|
function parseIfVersion(...args) {
|
2949
4186
|
for (const arg of args) {
|
@@ -2954,6 +4191,12 @@ function parseIfVersion(...args) {
|
|
2954
4191
|
return void 0;
|
2955
4192
|
}
|
2956
4193
|
|
4194
|
+
var __defProp$3 = Object.defineProperty;
|
4195
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4196
|
+
var __publicField$3 = (obj, key, value) => {
|
4197
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4198
|
+
return value;
|
4199
|
+
};
|
2957
4200
|
var __accessCheck$3 = (obj, member, msg) => {
|
2958
4201
|
if (!member.has(obj))
|
2959
4202
|
throw TypeError("Cannot " + msg);
|
@@ -2976,6 +4219,8 @@ var _map;
|
|
2976
4219
|
class SimpleCache {
|
2977
4220
|
constructor(options = {}) {
|
2978
4221
|
__privateAdd$3(this, _map, void 0);
|
4222
|
+
__publicField$3(this, "capacity");
|
4223
|
+
__publicField$3(this, "defaultQueryTTL");
|
2979
4224
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
2980
4225
|
this.capacity = options.max ?? 500;
|
2981
4226
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3111,19 +4356,19 @@ class SearchPlugin extends XataPlugin {
|
|
3111
4356
|
__privateAdd$1(this, _schemaTables, void 0);
|
3112
4357
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3113
4358
|
}
|
3114
|
-
build(
|
4359
|
+
build(pluginOptions) {
|
3115
4360
|
return {
|
3116
4361
|
all: async (query, options = {}) => {
|
3117
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3118
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4362
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4363
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3119
4364
|
return records.map((record) => {
|
3120
4365
|
const { table = "orphan" } = record.xata;
|
3121
4366
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3122
4367
|
});
|
3123
4368
|
},
|
3124
4369
|
byTable: async (query, options = {}) => {
|
3125
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3126
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4370
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4371
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3127
4372
|
return records.reduce((acc, record) => {
|
3128
4373
|
const { table = "orphan" } = record.xata;
|
3129
4374
|
const items = acc[table] ?? [];
|
@@ -3136,38 +4381,108 @@ class SearchPlugin extends XataPlugin {
|
|
3136
4381
|
}
|
3137
4382
|
_schemaTables = new WeakMap();
|
3138
4383
|
_search = new WeakSet();
|
3139
|
-
search_fn = async function(query, options,
|
3140
|
-
const
|
3141
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
4384
|
+
search_fn = async function(query, options, pluginOptions) {
|
4385
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3142
4386
|
const { records } = await searchBranch({
|
3143
4387
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3144
|
-
|
3145
|
-
|
4388
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4389
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
4390
|
+
...pluginOptions
|
3146
4391
|
});
|
3147
4392
|
return records;
|
3148
4393
|
};
|
3149
4394
|
_getSchemaTables = new WeakSet();
|
3150
|
-
getSchemaTables_fn = async function(
|
4395
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3151
4396
|
if (__privateGet$1(this, _schemaTables))
|
3152
4397
|
return __privateGet$1(this, _schemaTables);
|
3153
|
-
const fetchProps = await getFetchProps();
|
3154
4398
|
const { schema } = await getBranchDetails({
|
3155
4399
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3156
|
-
...
|
4400
|
+
...pluginOptions
|
3157
4401
|
});
|
3158
4402
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3159
4403
|
return schema.tables;
|
3160
4404
|
};
|
3161
4405
|
|
4406
|
+
function escapeElement(elementRepresentation) {
|
4407
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4408
|
+
return '"' + escaped + '"';
|
4409
|
+
}
|
4410
|
+
function arrayString(val) {
|
4411
|
+
let result = "{";
|
4412
|
+
for (let i = 0; i < val.length; i++) {
|
4413
|
+
if (i > 0) {
|
4414
|
+
result = result + ",";
|
4415
|
+
}
|
4416
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4417
|
+
result = result + "NULL";
|
4418
|
+
} else if (Array.isArray(val[i])) {
|
4419
|
+
result = result + arrayString(val[i]);
|
4420
|
+
} else if (val[i] instanceof Buffer) {
|
4421
|
+
result += "\\\\x" + val[i].toString("hex");
|
4422
|
+
} else {
|
4423
|
+
result += escapeElement(prepareValue(val[i]));
|
4424
|
+
}
|
4425
|
+
}
|
4426
|
+
result = result + "}";
|
4427
|
+
return result;
|
4428
|
+
}
|
4429
|
+
function prepareValue(value) {
|
4430
|
+
if (!isDefined(value))
|
4431
|
+
return null;
|
4432
|
+
if (value instanceof Date) {
|
4433
|
+
return value.toISOString();
|
4434
|
+
}
|
4435
|
+
if (Array.isArray(value)) {
|
4436
|
+
return arrayString(value);
|
4437
|
+
}
|
4438
|
+
if (isObject(value)) {
|
4439
|
+
return JSON.stringify(value);
|
4440
|
+
}
|
4441
|
+
try {
|
4442
|
+
return value.toString();
|
4443
|
+
} catch (e) {
|
4444
|
+
return value;
|
4445
|
+
}
|
4446
|
+
}
|
4447
|
+
function prepareParams(param1, param2) {
|
4448
|
+
if (isString(param1)) {
|
4449
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4450
|
+
}
|
4451
|
+
if (isStringArray(param1)) {
|
4452
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4453
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4454
|
+
}, "");
|
4455
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4456
|
+
}
|
4457
|
+
if (isObject(param1)) {
|
4458
|
+
const { statement, params, consistency } = param1;
|
4459
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4460
|
+
}
|
4461
|
+
throw new Error("Invalid query");
|
4462
|
+
}
|
4463
|
+
|
4464
|
+
class SQLPlugin extends XataPlugin {
|
4465
|
+
build(pluginOptions) {
|
4466
|
+
return async (param1, ...param2) => {
|
4467
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4468
|
+
const { records, warning } = await sqlQuery({
|
4469
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4470
|
+
body: { statement, params, consistency },
|
4471
|
+
...pluginOptions
|
4472
|
+
});
|
4473
|
+
return { records, warning };
|
4474
|
+
};
|
4475
|
+
}
|
4476
|
+
}
|
4477
|
+
|
3162
4478
|
class TransactionPlugin extends XataPlugin {
|
3163
|
-
build(
|
4479
|
+
build(pluginOptions) {
|
3164
4480
|
return {
|
3165
4481
|
run: async (operations) => {
|
3166
|
-
const fetchProps = await getFetchProps();
|
3167
4482
|
const response = await branchTransaction({
|
3168
4483
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3169
4484
|
body: { operations },
|
3170
|
-
...
|
4485
|
+
...pluginOptions
|
3171
4486
|
});
|
3172
4487
|
return response;
|
3173
4488
|
}
|
@@ -3175,93 +4490,12 @@ class TransactionPlugin extends XataPlugin {
|
|
3175
4490
|
}
|
3176
4491
|
}
|
3177
4492
|
|
3178
|
-
|
3179
|
-
|
4493
|
+
var __defProp$2 = Object.defineProperty;
|
4494
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4495
|
+
var __publicField$2 = (obj, key, value) => {
|
4496
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4497
|
+
return value;
|
3180
4498
|
};
|
3181
|
-
|
3182
|
-
async function getCurrentBranchName(options) {
|
3183
|
-
const { branch, envBranch } = getEnvironment();
|
3184
|
-
if (branch) {
|
3185
|
-
const details = await getDatabaseBranch(branch, options);
|
3186
|
-
if (details)
|
3187
|
-
return branch;
|
3188
|
-
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
3189
|
-
}
|
3190
|
-
const gitBranch = envBranch || await getGitBranch();
|
3191
|
-
return resolveXataBranch(gitBranch, options);
|
3192
|
-
}
|
3193
|
-
async function getCurrentBranchDetails(options) {
|
3194
|
-
const branch = await getCurrentBranchName(options);
|
3195
|
-
return getDatabaseBranch(branch, options);
|
3196
|
-
}
|
3197
|
-
async function resolveXataBranch(gitBranch, options) {
|
3198
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3199
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3200
|
-
if (!databaseURL)
|
3201
|
-
throw new Error(
|
3202
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3203
|
-
);
|
3204
|
-
if (!apiKey)
|
3205
|
-
throw new Error(
|
3206
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3207
|
-
);
|
3208
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3209
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3210
|
-
if (!urlParts)
|
3211
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3212
|
-
const { workspace, region } = urlParts;
|
3213
|
-
const { fallbackBranch } = getEnvironment();
|
3214
|
-
const { branch } = await resolveBranch({
|
3215
|
-
apiKey,
|
3216
|
-
apiUrl: databaseURL,
|
3217
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3218
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3219
|
-
pathParams: { dbName, workspace, region },
|
3220
|
-
queryParams: { gitBranch, fallbackBranch },
|
3221
|
-
trace: defaultTrace
|
3222
|
-
});
|
3223
|
-
return branch;
|
3224
|
-
}
|
3225
|
-
async function getDatabaseBranch(branch, options) {
|
3226
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3227
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3228
|
-
if (!databaseURL)
|
3229
|
-
throw new Error(
|
3230
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3231
|
-
);
|
3232
|
-
if (!apiKey)
|
3233
|
-
throw new Error(
|
3234
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3235
|
-
);
|
3236
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3237
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3238
|
-
if (!urlParts)
|
3239
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3240
|
-
const { workspace, region } = urlParts;
|
3241
|
-
try {
|
3242
|
-
return await getBranchDetails({
|
3243
|
-
apiKey,
|
3244
|
-
apiUrl: databaseURL,
|
3245
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3246
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3247
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3248
|
-
trace: defaultTrace
|
3249
|
-
});
|
3250
|
-
} catch (err) {
|
3251
|
-
if (isObject(err) && err.status === 404)
|
3252
|
-
return null;
|
3253
|
-
throw err;
|
3254
|
-
}
|
3255
|
-
}
|
3256
|
-
function getDatabaseURL() {
|
3257
|
-
try {
|
3258
|
-
const { databaseURL } = getEnvironment();
|
3259
|
-
return databaseURL;
|
3260
|
-
} catch (err) {
|
3261
|
-
return void 0;
|
3262
|
-
}
|
3263
|
-
}
|
3264
|
-
|
3265
4499
|
var __accessCheck = (obj, member, msg) => {
|
3266
4500
|
if (!member.has(obj))
|
3267
4501
|
throw TypeError("Cannot " + msg);
|
@@ -3285,48 +4519,48 @@ var __privateMethod = (obj, member, method) => {
|
|
3285
4519
|
return method;
|
3286
4520
|
};
|
3287
4521
|
const buildClient = (plugins) => {
|
3288
|
-
var
|
4522
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3289
4523
|
return _a = class {
|
3290
4524
|
constructor(options = {}, schemaTables) {
|
3291
4525
|
__privateAdd(this, _parseOptions);
|
3292
4526
|
__privateAdd(this, _getFetchProps);
|
3293
|
-
__privateAdd(this, _evaluateBranch);
|
3294
|
-
__privateAdd(this, _branch, void 0);
|
3295
4527
|
__privateAdd(this, _options, void 0);
|
4528
|
+
__publicField$2(this, "db");
|
4529
|
+
__publicField$2(this, "search");
|
4530
|
+
__publicField$2(this, "transactions");
|
4531
|
+
__publicField$2(this, "sql");
|
4532
|
+
__publicField$2(this, "files");
|
3296
4533
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3297
4534
|
__privateSet(this, _options, safeOptions);
|
3298
4535
|
const pluginOptions = {
|
3299
|
-
|
4536
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3300
4537
|
cache: safeOptions.cache,
|
3301
|
-
|
4538
|
+
host: safeOptions.host
|
3302
4539
|
};
|
3303
4540
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3304
4541
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3305
4542
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4543
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4544
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3306
4545
|
this.db = db;
|
3307
4546
|
this.search = search;
|
3308
4547
|
this.transactions = transactions;
|
4548
|
+
this.sql = sql;
|
4549
|
+
this.files = files;
|
3309
4550
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3310
4551
|
if (namespace === void 0)
|
3311
4552
|
continue;
|
3312
|
-
|
3313
|
-
if (result instanceof Promise) {
|
3314
|
-
void result.then((namespace2) => {
|
3315
|
-
this[key] = namespace2;
|
3316
|
-
});
|
3317
|
-
} else {
|
3318
|
-
this[key] = result;
|
3319
|
-
}
|
4553
|
+
this[key] = namespace.build(pluginOptions);
|
3320
4554
|
}
|
3321
4555
|
}
|
3322
4556
|
async getConfig() {
|
3323
4557
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3324
|
-
const branch =
|
4558
|
+
const branch = __privateGet(this, _options).branch;
|
3325
4559
|
return { databaseURL, branch };
|
3326
4560
|
}
|
3327
|
-
},
|
4561
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3328
4562
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3329
|
-
const isBrowser = typeof window !== "undefined";
|
4563
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3330
4564
|
if (isBrowser && !enableBrowser) {
|
3331
4565
|
throw new Error(
|
3332
4566
|
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
@@ -3337,56 +4571,89 @@ const buildClient = (plugins) => {
|
|
3337
4571
|
const apiKey = options?.apiKey || getAPIKey();
|
3338
4572
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3339
4573
|
const trace = options?.trace ?? defaultTrace;
|
3340
|
-
const
|
4574
|
+
const clientName = options?.clientName;
|
4575
|
+
const host = options?.host ?? "production";
|
4576
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3341
4577
|
if (!apiKey) {
|
3342
4578
|
throw new Error("Option apiKey is required");
|
3343
4579
|
}
|
3344
4580
|
if (!databaseURL) {
|
3345
4581
|
throw new Error("Option databaseURL is required");
|
3346
4582
|
}
|
3347
|
-
|
3348
|
-
|
3349
|
-
const
|
3350
|
-
if (
|
3351
|
-
|
4583
|
+
const envBranch = getBranch();
|
4584
|
+
const previewBranch = getPreviewBranch();
|
4585
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4586
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4587
|
+
console.warn(
|
4588
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4589
|
+
);
|
4590
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4591
|
+
console.warn(
|
4592
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4593
|
+
);
|
4594
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4595
|
+
console.warn(
|
4596
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4597
|
+
);
|
4598
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4599
|
+
console.warn(
|
4600
|
+
`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.`
|
4601
|
+
);
|
4602
|
+
}
|
4603
|
+
return {
|
4604
|
+
fetch,
|
4605
|
+
databaseURL,
|
4606
|
+
apiKey,
|
4607
|
+
branch,
|
4608
|
+
cache,
|
4609
|
+
trace,
|
4610
|
+
host,
|
4611
|
+
clientID: generateUUID(),
|
4612
|
+
enableBrowser,
|
4613
|
+
clientName,
|
4614
|
+
xataAgentExtra
|
4615
|
+
};
|
4616
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4617
|
+
fetch,
|
4618
|
+
apiKey,
|
4619
|
+
databaseURL,
|
4620
|
+
branch,
|
4621
|
+
trace,
|
4622
|
+
clientID,
|
4623
|
+
clientName,
|
4624
|
+
xataAgentExtra
|
4625
|
+
}) {
|
3352
4626
|
return {
|
3353
|
-
|
4627
|
+
fetch,
|
3354
4628
|
apiKey,
|
3355
4629
|
apiUrl: "",
|
4630
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3356
4631
|
workspacesApiUrl: (path, params) => {
|
3357
4632
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3358
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4633
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3359
4634
|
return databaseURL + newPath;
|
3360
4635
|
},
|
3361
4636
|
trace,
|
3362
|
-
clientID
|
3363
|
-
|
3364
|
-
|
3365
|
-
if (__privateGet(this, _branch))
|
3366
|
-
return __privateGet(this, _branch);
|
3367
|
-
if (param === void 0)
|
3368
|
-
return void 0;
|
3369
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3370
|
-
const evaluateBranch = async (strategy) => {
|
3371
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
4637
|
+
clientID,
|
4638
|
+
clientName,
|
4639
|
+
xataAgentExtra
|
3372
4640
|
};
|
3373
|
-
for await (const strategy of strategies) {
|
3374
|
-
const branch = await evaluateBranch(strategy);
|
3375
|
-
if (branch) {
|
3376
|
-
__privateSet(this, _branch, branch);
|
3377
|
-
return branch;
|
3378
|
-
}
|
3379
|
-
}
|
3380
4641
|
}, _a;
|
3381
4642
|
};
|
3382
4643
|
class BaseClient extends buildClient() {
|
3383
4644
|
}
|
3384
4645
|
|
4646
|
+
var __defProp$1 = Object.defineProperty;
|
4647
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4648
|
+
var __publicField$1 = (obj, key, value) => {
|
4649
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4650
|
+
return value;
|
4651
|
+
};
|
3385
4652
|
const META = "__";
|
3386
4653
|
const VALUE = "___";
|
3387
4654
|
class Serializer {
|
3388
4655
|
constructor() {
|
3389
|
-
this
|
4656
|
+
__publicField$1(this, "classes", {});
|
3390
4657
|
}
|
3391
4658
|
add(clazz) {
|
3392
4659
|
this.classes[clazz.name] = clazz;
|
@@ -3450,7 +4717,7 @@ const deserialize = (json) => {
|
|
3450
4717
|
};
|
3451
4718
|
|
3452
4719
|
function buildWorkerRunner(config) {
|
3453
|
-
return function xataWorker(name,
|
4720
|
+
return function xataWorker(name, worker) {
|
3454
4721
|
return async (...args) => {
|
3455
4722
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3456
4723
|
const result = await fetch(url, {
|
@@ -3464,12 +4731,19 @@ function buildWorkerRunner(config) {
|
|
3464
4731
|
};
|
3465
4732
|
}
|
3466
4733
|
|
4734
|
+
var __defProp = Object.defineProperty;
|
4735
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4736
|
+
var __publicField = (obj, key, value) => {
|
4737
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4738
|
+
return value;
|
4739
|
+
};
|
3467
4740
|
class XataError extends Error {
|
3468
4741
|
constructor(message, status) {
|
3469
4742
|
super(message);
|
4743
|
+
__publicField(this, "status");
|
3470
4744
|
this.status = status;
|
3471
4745
|
}
|
3472
4746
|
}
|
3473
4747
|
|
3474
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace,
|
4748
|
+
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, 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 };
|
3475
4749
|
//# sourceMappingURL=index.mjs.map
|