@xata.io/client 0.0.0-alpha.vfa22996 → 0.0.0-alpha.vfa36696
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +18 -0
- package/CHANGELOG.md +202 -0
- package/README.md +3 -269
- package/dist/index.cjs +1526 -355
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3366 -1599
- package/dist/index.mjs +1501 -349
- 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,15 @@ function chunk(array, chunkSize) {
|
|
82
86
|
async function timeout(ms) {
|
83
87
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
84
88
|
}
|
89
|
+
function promiseMap(inputValues, mapper) {
|
90
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
91
|
+
(acc) => mapper(inputValue).then((result) => {
|
92
|
+
acc.push(result);
|
93
|
+
return acc;
|
94
|
+
})
|
95
|
+
);
|
96
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
97
|
+
}
|
85
98
|
|
86
99
|
function getEnvironment() {
|
87
100
|
try {
|
@@ -90,8 +103,10 @@ function getEnvironment() {
|
|
90
103
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
91
104
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
92
105
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
93
|
-
|
94
|
-
|
106
|
+
deployPreview: process.env.XATA_PREVIEW,
|
107
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
108
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
109
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
95
110
|
};
|
96
111
|
}
|
97
112
|
} catch (err) {
|
@@ -102,8 +117,10 @@ function getEnvironment() {
|
|
102
117
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
103
118
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
104
119
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
105
|
-
|
106
|
-
|
120
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
121
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
122
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
123
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
107
124
|
};
|
108
125
|
}
|
109
126
|
} catch (err) {
|
@@ -112,8 +129,10 @@ function getEnvironment() {
|
|
112
129
|
apiKey: getGlobalApiKey(),
|
113
130
|
databaseURL: getGlobalDatabaseURL(),
|
114
131
|
branch: getGlobalBranch(),
|
115
|
-
|
116
|
-
|
132
|
+
deployPreview: void 0,
|
133
|
+
deployPreviewBranch: void 0,
|
134
|
+
vercelGitCommitRef: void 0,
|
135
|
+
vercelGitRepoOwner: void 0
|
117
136
|
};
|
118
137
|
}
|
119
138
|
function getEnableBrowserVariable() {
|
@@ -156,44 +175,59 @@ function getGlobalBranch() {
|
|
156
175
|
return void 0;
|
157
176
|
}
|
158
177
|
}
|
159
|
-
function
|
178
|
+
function getDatabaseURL() {
|
160
179
|
try {
|
161
|
-
|
180
|
+
const { databaseURL } = getEnvironment();
|
181
|
+
return databaseURL;
|
162
182
|
} catch (err) {
|
163
183
|
return void 0;
|
164
184
|
}
|
165
185
|
}
|
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"] };
|
186
|
+
function getAPIKey() {
|
171
187
|
try {
|
172
|
-
|
173
|
-
|
174
|
-
}
|
175
|
-
const { execSync } = await import(nodeModule);
|
176
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
188
|
+
const { apiKey } = getEnvironment();
|
189
|
+
return apiKey;
|
177
190
|
} catch (err) {
|
191
|
+
return void 0;
|
178
192
|
}
|
193
|
+
}
|
194
|
+
function getBranch() {
|
179
195
|
try {
|
180
|
-
|
181
|
-
|
182
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
183
|
-
}
|
196
|
+
const { branch } = getEnvironment();
|
197
|
+
return branch ?? "main";
|
184
198
|
} catch (err) {
|
199
|
+
return void 0;
|
185
200
|
}
|
186
201
|
}
|
187
|
-
|
188
|
-
|
202
|
+
function buildPreviewBranchName({ org, branch }) {
|
203
|
+
return `preview-${org}-${branch}`;
|
204
|
+
}
|
205
|
+
function getPreviewBranch() {
|
189
206
|
try {
|
190
|
-
const {
|
191
|
-
|
207
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
208
|
+
if (deployPreviewBranch)
|
209
|
+
return deployPreviewBranch;
|
210
|
+
switch (deployPreview) {
|
211
|
+
case "vercel": {
|
212
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
213
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
214
|
+
return void 0;
|
215
|
+
}
|
216
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
217
|
+
}
|
218
|
+
}
|
219
|
+
return void 0;
|
192
220
|
} catch (err) {
|
193
221
|
return void 0;
|
194
222
|
}
|
195
223
|
}
|
196
224
|
|
225
|
+
var __defProp$8 = Object.defineProperty;
|
226
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
227
|
+
var __publicField$8 = (obj, key, value) => {
|
228
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
229
|
+
return value;
|
230
|
+
};
|
197
231
|
var __accessCheck$8 = (obj, member, msg) => {
|
198
232
|
if (!member.has(obj))
|
199
233
|
throw TypeError("Cannot " + msg);
|
@@ -217,6 +251,7 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
217
251
|
return method;
|
218
252
|
};
|
219
253
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
254
|
+
const REQUEST_TIMEOUT = 3e4;
|
220
255
|
function getFetchImplementation(userFetch) {
|
221
256
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
222
257
|
const fetchImpl = userFetch ?? globalFetch;
|
@@ -233,6 +268,8 @@ class ApiRequestPool {
|
|
233
268
|
__privateAdd$8(this, _fetch, void 0);
|
234
269
|
__privateAdd$8(this, _queue, void 0);
|
235
270
|
__privateAdd$8(this, _concurrency, void 0);
|
271
|
+
__publicField$8(this, "running");
|
272
|
+
__publicField$8(this, "started");
|
236
273
|
__privateSet$8(this, _queue, []);
|
237
274
|
__privateSet$8(this, _concurrency, concurrency);
|
238
275
|
this.running = 0;
|
@@ -248,17 +285,20 @@ class ApiRequestPool {
|
|
248
285
|
return __privateGet$8(this, _fetch);
|
249
286
|
}
|
250
287
|
request(url, options) {
|
251
|
-
const start = new Date();
|
288
|
+
const start = /* @__PURE__ */ new Date();
|
252
289
|
const fetch2 = this.getFetch();
|
253
290
|
const runRequest = async (stalled = false) => {
|
254
|
-
const response = await fetch2(url, options);
|
291
|
+
const response = await Promise.race([fetch2(url, options), timeout(REQUEST_TIMEOUT).then(() => null)]);
|
292
|
+
if (!response) {
|
293
|
+
throw new Error("Request timed out");
|
294
|
+
}
|
255
295
|
if (response.status === 429) {
|
256
296
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
257
297
|
await timeout(rateLimitReset * 1e3);
|
258
298
|
return await runRequest(true);
|
259
299
|
}
|
260
300
|
if (stalled) {
|
261
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
301
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
262
302
|
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
263
303
|
}
|
264
304
|
return response;
|
@@ -294,18 +334,208 @@ enqueue_fn = function(task) {
|
|
294
334
|
return promise;
|
295
335
|
};
|
296
336
|
|
297
|
-
|
337
|
+
function generateUUID() {
|
338
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
339
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
340
|
+
return v.toString(16);
|
341
|
+
});
|
342
|
+
}
|
343
|
+
|
344
|
+
async function getBytes(stream, onChunk) {
|
345
|
+
const reader = stream.getReader();
|
346
|
+
let result;
|
347
|
+
while (!(result = await reader.read()).done) {
|
348
|
+
onChunk(result.value);
|
349
|
+
}
|
350
|
+
}
|
351
|
+
function getLines(onLine) {
|
352
|
+
let buffer;
|
353
|
+
let position;
|
354
|
+
let fieldLength;
|
355
|
+
let discardTrailingNewline = false;
|
356
|
+
return function onChunk(arr) {
|
357
|
+
if (buffer === void 0) {
|
358
|
+
buffer = arr;
|
359
|
+
position = 0;
|
360
|
+
fieldLength = -1;
|
361
|
+
} else {
|
362
|
+
buffer = concat(buffer, arr);
|
363
|
+
}
|
364
|
+
const bufLength = buffer.length;
|
365
|
+
let lineStart = 0;
|
366
|
+
while (position < bufLength) {
|
367
|
+
if (discardTrailingNewline) {
|
368
|
+
if (buffer[position] === 10 /* NewLine */) {
|
369
|
+
lineStart = ++position;
|
370
|
+
}
|
371
|
+
discardTrailingNewline = false;
|
372
|
+
}
|
373
|
+
let lineEnd = -1;
|
374
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
375
|
+
switch (buffer[position]) {
|
376
|
+
case 58 /* Colon */:
|
377
|
+
if (fieldLength === -1) {
|
378
|
+
fieldLength = position - lineStart;
|
379
|
+
}
|
380
|
+
break;
|
381
|
+
case 13 /* CarriageReturn */:
|
382
|
+
discardTrailingNewline = true;
|
383
|
+
case 10 /* NewLine */:
|
384
|
+
lineEnd = position;
|
385
|
+
break;
|
386
|
+
}
|
387
|
+
}
|
388
|
+
if (lineEnd === -1) {
|
389
|
+
break;
|
390
|
+
}
|
391
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
392
|
+
lineStart = position;
|
393
|
+
fieldLength = -1;
|
394
|
+
}
|
395
|
+
if (lineStart === bufLength) {
|
396
|
+
buffer = void 0;
|
397
|
+
} else if (lineStart !== 0) {
|
398
|
+
buffer = buffer.subarray(lineStart);
|
399
|
+
position -= lineStart;
|
400
|
+
}
|
401
|
+
};
|
402
|
+
}
|
403
|
+
function getMessages(onId, onRetry, onMessage) {
|
404
|
+
let message = newMessage();
|
405
|
+
const decoder = new TextDecoder();
|
406
|
+
return function onLine(line, fieldLength) {
|
407
|
+
if (line.length === 0) {
|
408
|
+
onMessage?.(message);
|
409
|
+
message = newMessage();
|
410
|
+
} else if (fieldLength > 0) {
|
411
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
412
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
413
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
414
|
+
switch (field) {
|
415
|
+
case "data":
|
416
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
417
|
+
break;
|
418
|
+
case "event":
|
419
|
+
message.event = value;
|
420
|
+
break;
|
421
|
+
case "id":
|
422
|
+
onId(message.id = value);
|
423
|
+
break;
|
424
|
+
case "retry":
|
425
|
+
const retry = parseInt(value, 10);
|
426
|
+
if (!isNaN(retry)) {
|
427
|
+
onRetry(message.retry = retry);
|
428
|
+
}
|
429
|
+
break;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
};
|
433
|
+
}
|
434
|
+
function concat(a, b) {
|
435
|
+
const res = new Uint8Array(a.length + b.length);
|
436
|
+
res.set(a);
|
437
|
+
res.set(b, a.length);
|
438
|
+
return res;
|
439
|
+
}
|
440
|
+
function newMessage() {
|
441
|
+
return {
|
442
|
+
data: "",
|
443
|
+
event: "",
|
444
|
+
id: "",
|
445
|
+
retry: void 0
|
446
|
+
};
|
447
|
+
}
|
448
|
+
const EventStreamContentType = "text/event-stream";
|
449
|
+
const LastEventId = "last-event-id";
|
450
|
+
function fetchEventSource(input, {
|
451
|
+
signal: inputSignal,
|
452
|
+
headers: inputHeaders,
|
453
|
+
onopen: inputOnOpen,
|
454
|
+
onmessage,
|
455
|
+
onclose,
|
456
|
+
onerror,
|
457
|
+
fetch: inputFetch,
|
458
|
+
...rest
|
459
|
+
}) {
|
460
|
+
return new Promise((resolve, reject) => {
|
461
|
+
const headers = { ...inputHeaders };
|
462
|
+
if (!headers.accept) {
|
463
|
+
headers.accept = EventStreamContentType;
|
464
|
+
}
|
465
|
+
let curRequestController;
|
466
|
+
function dispose() {
|
467
|
+
curRequestController.abort();
|
468
|
+
}
|
469
|
+
inputSignal?.addEventListener("abort", () => {
|
470
|
+
dispose();
|
471
|
+
resolve();
|
472
|
+
});
|
473
|
+
const fetchImpl = inputFetch ?? fetch;
|
474
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
475
|
+
async function create() {
|
476
|
+
curRequestController = new AbortController();
|
477
|
+
try {
|
478
|
+
const response = await fetchImpl(input, {
|
479
|
+
...rest,
|
480
|
+
headers,
|
481
|
+
signal: curRequestController.signal
|
482
|
+
});
|
483
|
+
await onopen(response);
|
484
|
+
await getBytes(
|
485
|
+
response.body,
|
486
|
+
getLines(
|
487
|
+
getMessages(
|
488
|
+
(id) => {
|
489
|
+
if (id) {
|
490
|
+
headers[LastEventId] = id;
|
491
|
+
} else {
|
492
|
+
delete headers[LastEventId];
|
493
|
+
}
|
494
|
+
},
|
495
|
+
(_retry) => {
|
496
|
+
},
|
497
|
+
onmessage
|
498
|
+
)
|
499
|
+
)
|
500
|
+
);
|
501
|
+
onclose?.();
|
502
|
+
dispose();
|
503
|
+
resolve();
|
504
|
+
} catch (err) {
|
505
|
+
}
|
506
|
+
}
|
507
|
+
create();
|
508
|
+
});
|
509
|
+
}
|
510
|
+
function defaultOnOpen(response) {
|
511
|
+
const contentType = response.headers?.get("content-type");
|
512
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
513
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
514
|
+
}
|
515
|
+
}
|
516
|
+
|
517
|
+
const VERSION = "0.24.3";
|
298
518
|
|
519
|
+
var __defProp$7 = Object.defineProperty;
|
520
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
521
|
+
var __publicField$7 = (obj, key, value) => {
|
522
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
523
|
+
return value;
|
524
|
+
};
|
299
525
|
class ErrorWithCause extends Error {
|
300
526
|
constructor(message, options) {
|
301
527
|
super(message, options);
|
528
|
+
__publicField$7(this, "cause");
|
302
529
|
}
|
303
530
|
}
|
304
531
|
class FetcherError extends ErrorWithCause {
|
305
532
|
constructor(status, data, requestId) {
|
306
533
|
super(getMessage(data));
|
534
|
+
__publicField$7(this, "status");
|
535
|
+
__publicField$7(this, "requestId");
|
536
|
+
__publicField$7(this, "errors");
|
307
537
|
this.status = status;
|
308
|
-
this.errors = isBulkError(data) ? data.errors :
|
538
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
309
539
|
this.requestId = requestId;
|
310
540
|
if (data instanceof Error) {
|
311
541
|
this.stack = data.stack;
|
@@ -370,14 +600,24 @@ function hostHeader(url) {
|
|
370
600
|
const { groups } = pattern.exec(url) ?? {};
|
371
601
|
return groups?.host ? { Host: groups.host } : {};
|
372
602
|
}
|
603
|
+
function parseBody(body, headers) {
|
604
|
+
if (!isDefined(body))
|
605
|
+
return void 0;
|
606
|
+
const { "Content-Type": contentType } = headers ?? {};
|
607
|
+
if (String(contentType).toLowerCase() === "application/json") {
|
608
|
+
return JSON.stringify(body);
|
609
|
+
}
|
610
|
+
return body;
|
611
|
+
}
|
612
|
+
const defaultClientID = generateUUID();
|
373
613
|
async function fetch$1({
|
374
614
|
url: path,
|
375
615
|
method,
|
376
616
|
body,
|
377
|
-
headers,
|
617
|
+
headers: customHeaders,
|
378
618
|
pathParams,
|
379
619
|
queryParams,
|
380
|
-
|
620
|
+
fetch: fetch2,
|
381
621
|
apiKey,
|
382
622
|
endpoint,
|
383
623
|
apiUrl,
|
@@ -386,9 +626,12 @@ async function fetch$1({
|
|
386
626
|
signal,
|
387
627
|
clientID,
|
388
628
|
sessionID,
|
389
|
-
|
629
|
+
clientName,
|
630
|
+
xataAgentExtra,
|
631
|
+
fetchOptions = {},
|
632
|
+
rawResponse = false
|
390
633
|
}) {
|
391
|
-
pool.setFetch(
|
634
|
+
pool.setFetch(fetch2);
|
392
635
|
return await trace(
|
393
636
|
`${method.toUpperCase()} ${path}`,
|
394
637
|
async ({ setAttributes }) => {
|
@@ -399,19 +642,27 @@ async function fetch$1({
|
|
399
642
|
[TraceAttributes.HTTP_URL]: url,
|
400
643
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
401
644
|
});
|
645
|
+
const xataAgent = compact([
|
646
|
+
["client", "TS_SDK"],
|
647
|
+
["version", VERSION],
|
648
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
649
|
+
...Object.entries(xataAgentExtra ?? {})
|
650
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
651
|
+
const headers = compactObject({
|
652
|
+
"Accept-Encoding": "identity",
|
653
|
+
"Content-Type": "application/json",
|
654
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
655
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
656
|
+
"X-Xata-Agent": xataAgent,
|
657
|
+
...customHeaders,
|
658
|
+
...hostHeader(fullUrl),
|
659
|
+
Authorization: `Bearer ${apiKey}`
|
660
|
+
});
|
402
661
|
const response = await pool.request(url, {
|
403
662
|
...fetchOptions,
|
404
663
|
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
|
-
},
|
664
|
+
body: parseBody(body, headers),
|
665
|
+
headers,
|
415
666
|
signal
|
416
667
|
});
|
417
668
|
const { host, protocol } = parseUrl(response.url);
|
@@ -423,6 +674,9 @@ async function fetch$1({
|
|
423
674
|
[TraceAttributes.HTTP_HOST]: host,
|
424
675
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
425
676
|
});
|
677
|
+
const message = response.headers?.get("x-xata-message");
|
678
|
+
if (message)
|
679
|
+
console.warn(message);
|
426
680
|
if (response.status === 204) {
|
427
681
|
return {};
|
428
682
|
}
|
@@ -430,7 +684,7 @@ async function fetch$1({
|
|
430
684
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
431
685
|
}
|
432
686
|
try {
|
433
|
-
const jsonResponse = await response.json();
|
687
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
434
688
|
if (response.ok) {
|
435
689
|
return jsonResponse;
|
436
690
|
}
|
@@ -442,6 +696,59 @@ async function fetch$1({
|
|
442
696
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
443
697
|
);
|
444
698
|
}
|
699
|
+
function fetchSSERequest({
|
700
|
+
url: path,
|
701
|
+
method,
|
702
|
+
body,
|
703
|
+
headers: customHeaders,
|
704
|
+
pathParams,
|
705
|
+
queryParams,
|
706
|
+
fetch: fetch2,
|
707
|
+
apiKey,
|
708
|
+
endpoint,
|
709
|
+
apiUrl,
|
710
|
+
workspacesApiUrl,
|
711
|
+
onMessage,
|
712
|
+
onError,
|
713
|
+
onClose,
|
714
|
+
signal,
|
715
|
+
clientID,
|
716
|
+
sessionID,
|
717
|
+
clientName,
|
718
|
+
xataAgentExtra
|
719
|
+
}) {
|
720
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
721
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
722
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
723
|
+
void fetchEventSource(url, {
|
724
|
+
method,
|
725
|
+
body: JSON.stringify(body),
|
726
|
+
fetch: fetch2,
|
727
|
+
signal,
|
728
|
+
headers: {
|
729
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
730
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
731
|
+
"X-Xata-Agent": compact([
|
732
|
+
["client", "TS_SDK"],
|
733
|
+
["version", VERSION],
|
734
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
735
|
+
...Object.entries(xataAgentExtra ?? {})
|
736
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
737
|
+
...customHeaders,
|
738
|
+
Authorization: `Bearer ${apiKey}`,
|
739
|
+
"Content-Type": "application/json"
|
740
|
+
},
|
741
|
+
onmessage(ev) {
|
742
|
+
onMessage?.(JSON.parse(ev.data));
|
743
|
+
},
|
744
|
+
onerror(ev) {
|
745
|
+
onError?.(JSON.parse(ev.data));
|
746
|
+
},
|
747
|
+
onclose() {
|
748
|
+
onClose?.();
|
749
|
+
}
|
750
|
+
});
|
751
|
+
}
|
445
752
|
function parseUrl(url) {
|
446
753
|
try {
|
447
754
|
const { host, protocol } = new URL(url);
|
@@ -453,17 +760,12 @@ function parseUrl(url) {
|
|
453
760
|
|
454
761
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
455
762
|
|
456
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
457
763
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
458
764
|
url: "/dbs/{dbName}",
|
459
765
|
method: "get",
|
460
766
|
...variables,
|
461
767
|
signal
|
462
768
|
});
|
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
769
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
468
770
|
url: "/db/{dbBranchName}",
|
469
771
|
method: "get",
|
@@ -477,6 +779,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
477
779
|
...variables,
|
478
780
|
signal
|
479
781
|
});
|
782
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
783
|
+
url: "/db/{dbBranchName}/copy",
|
784
|
+
method: "post",
|
785
|
+
...variables,
|
786
|
+
signal
|
787
|
+
});
|
480
788
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
481
789
|
url: "/db/{dbBranchName}/metadata",
|
482
790
|
method: "put",
|
@@ -502,7 +810,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
502
810
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
503
811
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
504
812
|
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
813
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
507
814
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
508
815
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -527,6 +834,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
527
834
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
528
835
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
529
836
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
837
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
530
838
|
const createTable = (variables, signal) => dataPlaneFetch({
|
531
839
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
532
840
|
method: "put",
|
@@ -569,7 +877,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
569
877
|
...variables,
|
570
878
|
signal
|
571
879
|
});
|
880
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
572
881
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
882
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
883
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
884
|
+
method: "get",
|
885
|
+
...variables,
|
886
|
+
signal
|
887
|
+
});
|
888
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
889
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
890
|
+
method: "put",
|
891
|
+
...variables,
|
892
|
+
signal
|
893
|
+
});
|
894
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
895
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
896
|
+
method: "delete",
|
897
|
+
...variables,
|
898
|
+
signal
|
899
|
+
});
|
900
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
901
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
902
|
+
method: "get",
|
903
|
+
...variables,
|
904
|
+
signal
|
905
|
+
});
|
906
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
907
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
908
|
+
method: "put",
|
909
|
+
...variables,
|
910
|
+
signal
|
911
|
+
});
|
912
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
913
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
914
|
+
method: "delete",
|
915
|
+
...variables,
|
916
|
+
signal
|
917
|
+
});
|
573
918
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
574
919
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
575
920
|
method: "get",
|
@@ -599,21 +944,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
599
944
|
...variables,
|
600
945
|
signal
|
601
946
|
});
|
947
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
948
|
+
url: "/db/{dbBranchName}/sql",
|
949
|
+
method: "post",
|
950
|
+
...variables,
|
951
|
+
signal
|
952
|
+
});
|
953
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
954
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
955
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
956
|
+
method: "post",
|
957
|
+
...variables,
|
958
|
+
signal
|
959
|
+
});
|
960
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
602
961
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
603
962
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
963
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
964
|
+
url: "/file/{fileId}",
|
965
|
+
method: "get",
|
966
|
+
...variables,
|
967
|
+
signal
|
968
|
+
});
|
604
969
|
const operationsByTag$2 = {
|
605
|
-
database: {
|
606
|
-
dEPRECATEDgetDatabaseList,
|
607
|
-
dEPRECATEDcreateDatabase,
|
608
|
-
dEPRECATEDdeleteDatabase,
|
609
|
-
dEPRECATEDgetDatabaseMetadata,
|
610
|
-
dEPRECATEDupdateDatabaseMetadata
|
611
|
-
},
|
612
970
|
branch: {
|
613
971
|
getBranchList,
|
614
972
|
getBranchDetails,
|
615
973
|
createBranch,
|
616
974
|
deleteBranch,
|
975
|
+
copyBranch,
|
617
976
|
updateBranchMetadata,
|
618
977
|
getBranchMetadata,
|
619
978
|
getBranchStats,
|
@@ -631,17 +990,8 @@ const operationsByTag$2 = {
|
|
631
990
|
compareBranchSchemas,
|
632
991
|
updateBranchSchema,
|
633
992
|
previewBranchSchemaEdit,
|
634
|
-
applyBranchSchemaEdit
|
635
|
-
|
636
|
-
records: {
|
637
|
-
branchTransaction,
|
638
|
-
insertRecord,
|
639
|
-
getRecord,
|
640
|
-
insertRecordWithID,
|
641
|
-
updateRecordWithID,
|
642
|
-
upsertRecordWithID,
|
643
|
-
deleteRecord,
|
644
|
-
bulkInsertTableRecords
|
993
|
+
applyBranchSchemaEdit,
|
994
|
+
pushBranchMigrations
|
645
995
|
},
|
646
996
|
migrationRequests: {
|
647
997
|
queryMigrationRequests,
|
@@ -665,11 +1015,39 @@ const operationsByTag$2 = {
|
|
665
1015
|
updateColumn,
|
666
1016
|
deleteColumn
|
667
1017
|
},
|
668
|
-
|
1018
|
+
records: {
|
1019
|
+
branchTransaction,
|
1020
|
+
insertRecord,
|
1021
|
+
getRecord,
|
1022
|
+
insertRecordWithID,
|
1023
|
+
updateRecordWithID,
|
1024
|
+
upsertRecordWithID,
|
1025
|
+
deleteRecord,
|
1026
|
+
bulkInsertTableRecords
|
1027
|
+
},
|
1028
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1029
|
+
searchAndFilter: {
|
1030
|
+
queryTable,
|
1031
|
+
searchBranch,
|
1032
|
+
searchTable,
|
1033
|
+
sqlQuery,
|
1034
|
+
vectorSearchTable,
|
1035
|
+
askTable,
|
1036
|
+
askTableSession,
|
1037
|
+
summarizeTable,
|
1038
|
+
aggregateTable
|
1039
|
+
}
|
669
1040
|
};
|
670
1041
|
|
671
1042
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
672
1043
|
|
1044
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
1045
|
+
const generateAccessToken = (variables, signal) => controlPlaneFetch({
|
1046
|
+
url: "/oauth/token",
|
1047
|
+
method: "post",
|
1048
|
+
...variables,
|
1049
|
+
signal
|
1050
|
+
});
|
673
1051
|
const getUser = (variables, signal) => controlPlaneFetch({
|
674
1052
|
url: "/user",
|
675
1053
|
method: "get",
|
@@ -764,6 +1142,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
764
1142
|
});
|
765
1143
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
766
1144
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1145
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1146
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1147
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1148
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
767
1149
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
768
1150
|
url: "/workspaces/{workspaceId}/regions",
|
769
1151
|
method: "get",
|
@@ -771,6 +1153,7 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
771
1153
|
signal
|
772
1154
|
});
|
773
1155
|
const operationsByTag$1 = {
|
1156
|
+
authOther: { grantAuthorizationCode, generateAccessToken },
|
774
1157
|
users: { getUser, updateUser, deleteUser },
|
775
1158
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
776
1159
|
workspaces: {
|
@@ -796,6 +1179,10 @@ const operationsByTag$1 = {
|
|
796
1179
|
deleteDatabase,
|
797
1180
|
getDatabaseMetadata,
|
798
1181
|
updateDatabaseMetadata,
|
1182
|
+
renameDatabase,
|
1183
|
+
getDatabaseGithubSettings,
|
1184
|
+
updateDatabaseGithubSettings,
|
1185
|
+
deleteDatabaseGithubSettings,
|
799
1186
|
listRegions
|
800
1187
|
}
|
801
1188
|
};
|
@@ -816,8 +1203,12 @@ const providers = {
|
|
816
1203
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
817
1204
|
},
|
818
1205
|
staging: {
|
819
|
-
main: "https://staging.
|
820
|
-
workspaces: "https://{workspaceId}.
|
1206
|
+
main: "https://api.staging-xata.dev",
|
1207
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1208
|
+
},
|
1209
|
+
dev: {
|
1210
|
+
main: "https://api.dev-xata.dev",
|
1211
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
821
1212
|
}
|
822
1213
|
};
|
823
1214
|
function isHostProviderAlias(alias) {
|
@@ -835,15 +1226,22 @@ function parseProviderString(provider = "production") {
|
|
835
1226
|
return null;
|
836
1227
|
return { main, workspaces };
|
837
1228
|
}
|
1229
|
+
function buildProviderString(provider) {
|
1230
|
+
if (isHostProviderAlias(provider))
|
1231
|
+
return provider;
|
1232
|
+
return `${provider.main},${provider.workspaces}`;
|
1233
|
+
}
|
838
1234
|
function parseWorkspacesUrlParts(url) {
|
839
1235
|
if (!isString(url))
|
840
1236
|
return null;
|
841
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
842
|
-
const
|
843
|
-
const
|
1237
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1238
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1239
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1240
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1241
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
844
1242
|
if (!match)
|
845
1243
|
return null;
|
846
|
-
return { workspace: match[1], region: match[2]
|
1244
|
+
return { workspace: match[1], region: match[2] };
|
847
1245
|
}
|
848
1246
|
|
849
1247
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -872,15 +1270,19 @@ class XataApiClient {
|
|
872
1270
|
const provider = options.host ?? "production";
|
873
1271
|
const apiKey = options.apiKey ?? getAPIKey();
|
874
1272
|
const trace = options.trace ?? defaultTrace;
|
1273
|
+
const clientID = generateUUID();
|
875
1274
|
if (!apiKey) {
|
876
1275
|
throw new Error("Could not resolve a valid apiKey");
|
877
1276
|
}
|
878
1277
|
__privateSet$7(this, _extraProps, {
|
879
1278
|
apiUrl: getHostUrl(provider, "main"),
|
880
1279
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
881
|
-
|
1280
|
+
fetch: getFetchImplementation(options.fetch),
|
882
1281
|
apiKey,
|
883
|
-
trace
|
1282
|
+
trace,
|
1283
|
+
clientName: options.clientName,
|
1284
|
+
xataAgentExtra: options.xataAgentExtra,
|
1285
|
+
clientID
|
884
1286
|
});
|
885
1287
|
}
|
886
1288
|
get user() {
|
@@ -933,6 +1335,11 @@ class XataApiClient {
|
|
933
1335
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
934
1336
|
return __privateGet$7(this, _namespaces).records;
|
935
1337
|
}
|
1338
|
+
get files() {
|
1339
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1340
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1341
|
+
return __privateGet$7(this, _namespaces).files;
|
1342
|
+
}
|
936
1343
|
get searchAndFilter() {
|
937
1344
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
938
1345
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1141,6 +1548,20 @@ class BranchApi {
|
|
1141
1548
|
...this.extraProps
|
1142
1549
|
});
|
1143
1550
|
}
|
1551
|
+
copyBranch({
|
1552
|
+
workspace,
|
1553
|
+
region,
|
1554
|
+
database,
|
1555
|
+
branch,
|
1556
|
+
destinationBranch,
|
1557
|
+
limit
|
1558
|
+
}) {
|
1559
|
+
return operationsByTag.branch.copyBranch({
|
1560
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1561
|
+
body: { destinationBranch, limit },
|
1562
|
+
...this.extraProps
|
1563
|
+
});
|
1564
|
+
}
|
1144
1565
|
updateBranchMetadata({
|
1145
1566
|
workspace,
|
1146
1567
|
region,
|
@@ -1496,6 +1917,164 @@ class RecordsApi {
|
|
1496
1917
|
});
|
1497
1918
|
}
|
1498
1919
|
}
|
1920
|
+
class FilesApi {
|
1921
|
+
constructor(extraProps) {
|
1922
|
+
this.extraProps = extraProps;
|
1923
|
+
}
|
1924
|
+
getFileItem({
|
1925
|
+
workspace,
|
1926
|
+
region,
|
1927
|
+
database,
|
1928
|
+
branch,
|
1929
|
+
table,
|
1930
|
+
record,
|
1931
|
+
column,
|
1932
|
+
fileId
|
1933
|
+
}) {
|
1934
|
+
return operationsByTag.files.getFileItem({
|
1935
|
+
pathParams: {
|
1936
|
+
workspace,
|
1937
|
+
region,
|
1938
|
+
dbBranchName: `${database}:${branch}`,
|
1939
|
+
tableName: table,
|
1940
|
+
recordId: record,
|
1941
|
+
columnName: column,
|
1942
|
+
fileId
|
1943
|
+
},
|
1944
|
+
...this.extraProps
|
1945
|
+
});
|
1946
|
+
}
|
1947
|
+
putFileItem({
|
1948
|
+
workspace,
|
1949
|
+
region,
|
1950
|
+
database,
|
1951
|
+
branch,
|
1952
|
+
table,
|
1953
|
+
record,
|
1954
|
+
column,
|
1955
|
+
fileId,
|
1956
|
+
file
|
1957
|
+
}) {
|
1958
|
+
return operationsByTag.files.putFileItem({
|
1959
|
+
pathParams: {
|
1960
|
+
workspace,
|
1961
|
+
region,
|
1962
|
+
dbBranchName: `${database}:${branch}`,
|
1963
|
+
tableName: table,
|
1964
|
+
recordId: record,
|
1965
|
+
columnName: column,
|
1966
|
+
fileId
|
1967
|
+
},
|
1968
|
+
// @ts-ignore
|
1969
|
+
body: file,
|
1970
|
+
...this.extraProps
|
1971
|
+
});
|
1972
|
+
}
|
1973
|
+
deleteFileItem({
|
1974
|
+
workspace,
|
1975
|
+
region,
|
1976
|
+
database,
|
1977
|
+
branch,
|
1978
|
+
table,
|
1979
|
+
record,
|
1980
|
+
column,
|
1981
|
+
fileId
|
1982
|
+
}) {
|
1983
|
+
return operationsByTag.files.deleteFileItem({
|
1984
|
+
pathParams: {
|
1985
|
+
workspace,
|
1986
|
+
region,
|
1987
|
+
dbBranchName: `${database}:${branch}`,
|
1988
|
+
tableName: table,
|
1989
|
+
recordId: record,
|
1990
|
+
columnName: column,
|
1991
|
+
fileId
|
1992
|
+
},
|
1993
|
+
...this.extraProps
|
1994
|
+
});
|
1995
|
+
}
|
1996
|
+
getFile({
|
1997
|
+
workspace,
|
1998
|
+
region,
|
1999
|
+
database,
|
2000
|
+
branch,
|
2001
|
+
table,
|
2002
|
+
record,
|
2003
|
+
column
|
2004
|
+
}) {
|
2005
|
+
return operationsByTag.files.getFile({
|
2006
|
+
pathParams: {
|
2007
|
+
workspace,
|
2008
|
+
region,
|
2009
|
+
dbBranchName: `${database}:${branch}`,
|
2010
|
+
tableName: table,
|
2011
|
+
recordId: record,
|
2012
|
+
columnName: column
|
2013
|
+
},
|
2014
|
+
...this.extraProps
|
2015
|
+
});
|
2016
|
+
}
|
2017
|
+
putFile({
|
2018
|
+
workspace,
|
2019
|
+
region,
|
2020
|
+
database,
|
2021
|
+
branch,
|
2022
|
+
table,
|
2023
|
+
record,
|
2024
|
+
column,
|
2025
|
+
file
|
2026
|
+
}) {
|
2027
|
+
return operationsByTag.files.putFile({
|
2028
|
+
pathParams: {
|
2029
|
+
workspace,
|
2030
|
+
region,
|
2031
|
+
dbBranchName: `${database}:${branch}`,
|
2032
|
+
tableName: table,
|
2033
|
+
recordId: record,
|
2034
|
+
columnName: column
|
2035
|
+
},
|
2036
|
+
body: file,
|
2037
|
+
...this.extraProps
|
2038
|
+
});
|
2039
|
+
}
|
2040
|
+
deleteFile({
|
2041
|
+
workspace,
|
2042
|
+
region,
|
2043
|
+
database,
|
2044
|
+
branch,
|
2045
|
+
table,
|
2046
|
+
record,
|
2047
|
+
column
|
2048
|
+
}) {
|
2049
|
+
return operationsByTag.files.deleteFile({
|
2050
|
+
pathParams: {
|
2051
|
+
workspace,
|
2052
|
+
region,
|
2053
|
+
dbBranchName: `${database}:${branch}`,
|
2054
|
+
tableName: table,
|
2055
|
+
recordId: record,
|
2056
|
+
columnName: column
|
2057
|
+
},
|
2058
|
+
...this.extraProps
|
2059
|
+
});
|
2060
|
+
}
|
2061
|
+
fileAccess({
|
2062
|
+
workspace,
|
2063
|
+
region,
|
2064
|
+
fileId,
|
2065
|
+
verify
|
2066
|
+
}) {
|
2067
|
+
return operationsByTag.files.fileAccess({
|
2068
|
+
pathParams: {
|
2069
|
+
workspace,
|
2070
|
+
region,
|
2071
|
+
fileId
|
2072
|
+
},
|
2073
|
+
queryParams: { verify },
|
2074
|
+
...this.extraProps
|
2075
|
+
});
|
2076
|
+
}
|
2077
|
+
}
|
1499
2078
|
class SearchAndFilterApi {
|
1500
2079
|
constructor(extraProps) {
|
1501
2080
|
this.extraProps = extraProps;
|
@@ -1549,9 +2128,56 @@ class SearchAndFilterApi {
|
|
1549
2128
|
prefix,
|
1550
2129
|
highlight
|
1551
2130
|
}) {
|
1552
|
-
return operationsByTag.searchAndFilter.searchBranch({
|
1553
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1554
|
-
body: { tables, query, fuzziness, prefix, highlight },
|
2131
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
2132
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2133
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
2134
|
+
...this.extraProps
|
2135
|
+
});
|
2136
|
+
}
|
2137
|
+
vectorSearchTable({
|
2138
|
+
workspace,
|
2139
|
+
region,
|
2140
|
+
database,
|
2141
|
+
branch,
|
2142
|
+
table,
|
2143
|
+
queryVector,
|
2144
|
+
column,
|
2145
|
+
similarityFunction,
|
2146
|
+
size,
|
2147
|
+
filter
|
2148
|
+
}) {
|
2149
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2150
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2151
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2152
|
+
...this.extraProps
|
2153
|
+
});
|
2154
|
+
}
|
2155
|
+
askTable({
|
2156
|
+
workspace,
|
2157
|
+
region,
|
2158
|
+
database,
|
2159
|
+
branch,
|
2160
|
+
table,
|
2161
|
+
options
|
2162
|
+
}) {
|
2163
|
+
return operationsByTag.searchAndFilter.askTable({
|
2164
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2165
|
+
body: { ...options },
|
2166
|
+
...this.extraProps
|
2167
|
+
});
|
2168
|
+
}
|
2169
|
+
askTableSession({
|
2170
|
+
workspace,
|
2171
|
+
region,
|
2172
|
+
database,
|
2173
|
+
branch,
|
2174
|
+
table,
|
2175
|
+
sessionId,
|
2176
|
+
message
|
2177
|
+
}) {
|
2178
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2179
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2180
|
+
body: { message },
|
1555
2181
|
...this.extraProps
|
1556
2182
|
});
|
1557
2183
|
}
|
@@ -1755,11 +2381,13 @@ class MigrationsApi {
|
|
1755
2381
|
region,
|
1756
2382
|
database,
|
1757
2383
|
branch,
|
1758
|
-
schema
|
2384
|
+
schema,
|
2385
|
+
schemaOperations,
|
2386
|
+
branchOperations
|
1759
2387
|
}) {
|
1760
2388
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1761
2389
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1762
|
-
body: { schema },
|
2390
|
+
body: { schema, schemaOperations, branchOperations },
|
1763
2391
|
...this.extraProps
|
1764
2392
|
});
|
1765
2393
|
}
|
@@ -1769,11 +2397,12 @@ class MigrationsApi {
|
|
1769
2397
|
database,
|
1770
2398
|
branch,
|
1771
2399
|
compare,
|
1772
|
-
|
2400
|
+
sourceBranchOperations,
|
2401
|
+
targetBranchOperations
|
1773
2402
|
}) {
|
1774
2403
|
return operationsByTag.migrations.compareBranchSchemas({
|
1775
2404
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1776
|
-
body: {
|
2405
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1777
2406
|
...this.extraProps
|
1778
2407
|
});
|
1779
2408
|
}
|
@@ -1816,6 +2445,19 @@ class MigrationsApi {
|
|
1816
2445
|
...this.extraProps
|
1817
2446
|
});
|
1818
2447
|
}
|
2448
|
+
pushBranchMigrations({
|
2449
|
+
workspace,
|
2450
|
+
region,
|
2451
|
+
database,
|
2452
|
+
branch,
|
2453
|
+
migrations
|
2454
|
+
}) {
|
2455
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2456
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2457
|
+
body: { migrations },
|
2458
|
+
...this.extraProps
|
2459
|
+
});
|
2460
|
+
}
|
1819
2461
|
}
|
1820
2462
|
class DatabaseApi {
|
1821
2463
|
constructor(extraProps) {
|
@@ -1830,11 +2472,13 @@ class DatabaseApi {
|
|
1830
2472
|
createDatabase({
|
1831
2473
|
workspace,
|
1832
2474
|
database,
|
1833
|
-
data
|
2475
|
+
data,
|
2476
|
+
headers
|
1834
2477
|
}) {
|
1835
2478
|
return operationsByTag.databases.createDatabase({
|
1836
2479
|
pathParams: { workspaceId: workspace, dbName: database },
|
1837
2480
|
body: data,
|
2481
|
+
headers,
|
1838
2482
|
...this.extraProps
|
1839
2483
|
});
|
1840
2484
|
}
|
@@ -1867,6 +2511,46 @@ class DatabaseApi {
|
|
1867
2511
|
...this.extraProps
|
1868
2512
|
});
|
1869
2513
|
}
|
2514
|
+
renameDatabase({
|
2515
|
+
workspace,
|
2516
|
+
database,
|
2517
|
+
newName
|
2518
|
+
}) {
|
2519
|
+
return operationsByTag.databases.renameDatabase({
|
2520
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2521
|
+
body: { newName },
|
2522
|
+
...this.extraProps
|
2523
|
+
});
|
2524
|
+
}
|
2525
|
+
getDatabaseGithubSettings({
|
2526
|
+
workspace,
|
2527
|
+
database
|
2528
|
+
}) {
|
2529
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2530
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2531
|
+
...this.extraProps
|
2532
|
+
});
|
2533
|
+
}
|
2534
|
+
updateDatabaseGithubSettings({
|
2535
|
+
workspace,
|
2536
|
+
database,
|
2537
|
+
settings
|
2538
|
+
}) {
|
2539
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2540
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2541
|
+
body: settings,
|
2542
|
+
...this.extraProps
|
2543
|
+
});
|
2544
|
+
}
|
2545
|
+
deleteDatabaseGithubSettings({
|
2546
|
+
workspace,
|
2547
|
+
database
|
2548
|
+
}) {
|
2549
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2550
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2551
|
+
...this.extraProps
|
2552
|
+
});
|
2553
|
+
}
|
1870
2554
|
listRegions({ workspace }) {
|
1871
2555
|
return operationsByTag.databases.listRegions({
|
1872
2556
|
pathParams: { workspaceId: workspace },
|
@@ -1876,29 +2560,269 @@ class DatabaseApi {
|
|
1876
2560
|
}
|
1877
2561
|
|
1878
2562
|
class XataApiPlugin {
|
1879
|
-
|
1880
|
-
|
1881
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2563
|
+
build(options) {
|
2564
|
+
return new XataApiClient(options);
|
1882
2565
|
}
|
1883
2566
|
}
|
1884
2567
|
|
1885
2568
|
class XataPlugin {
|
1886
2569
|
}
|
1887
2570
|
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
2571
|
+
class FilesPlugin extends XataPlugin {
|
2572
|
+
build(pluginOptions) {
|
2573
|
+
return {
|
2574
|
+
download: async (location) => {
|
2575
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2576
|
+
return await getFileItem({
|
2577
|
+
pathParams: {
|
2578
|
+
workspace: "{workspaceId}",
|
2579
|
+
dbBranchName: "{dbBranch}",
|
2580
|
+
region: "{region}",
|
2581
|
+
tableName: table ?? "",
|
2582
|
+
recordId: record ?? "",
|
2583
|
+
columnName: column ?? "",
|
2584
|
+
fileId
|
2585
|
+
},
|
2586
|
+
...pluginOptions,
|
2587
|
+
rawResponse: true
|
2588
|
+
});
|
2589
|
+
},
|
2590
|
+
upload: async (location, file) => {
|
2591
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2592
|
+
return await putFileItem({
|
2593
|
+
pathParams: {
|
2594
|
+
workspace: "{workspaceId}",
|
2595
|
+
dbBranchName: "{dbBranch}",
|
2596
|
+
region: "{region}",
|
2597
|
+
tableName: table ?? "",
|
2598
|
+
recordId: record ?? "",
|
2599
|
+
columnName: column ?? "",
|
2600
|
+
fileId
|
2601
|
+
},
|
2602
|
+
body: file,
|
2603
|
+
...pluginOptions
|
2604
|
+
});
|
2605
|
+
},
|
2606
|
+
delete: async (location) => {
|
2607
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2608
|
+
return await deleteFileItem({
|
2609
|
+
pathParams: {
|
2610
|
+
workspace: "{workspaceId}",
|
2611
|
+
dbBranchName: "{dbBranch}",
|
2612
|
+
region: "{region}",
|
2613
|
+
tableName: table ?? "",
|
2614
|
+
recordId: record ?? "",
|
2615
|
+
columnName: column ?? "",
|
2616
|
+
fileId
|
2617
|
+
},
|
2618
|
+
...pluginOptions
|
2619
|
+
});
|
2620
|
+
}
|
2621
|
+
};
|
2622
|
+
}
|
2623
|
+
}
|
2624
|
+
|
2625
|
+
function buildTransformString(transformations) {
|
2626
|
+
return transformations.flatMap(
|
2627
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2628
|
+
if (key === "trim") {
|
2629
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2630
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2631
|
+
}
|
2632
|
+
if (key === "gravity" && typeof value === "object") {
|
2633
|
+
const { x = 0.5, y = 0.5 } = value;
|
2634
|
+
return `${key}=${[x, y].join("x")}`;
|
2635
|
+
}
|
2636
|
+
return `${key}=${value}`;
|
2637
|
+
})
|
2638
|
+
).join(",");
|
2639
|
+
}
|
2640
|
+
function transformImage(url, transformations) {
|
2641
|
+
if (!isDefined(url))
|
2642
|
+
return void 0;
|
2643
|
+
const transformationsString = buildTransformString(transformations);
|
2644
|
+
const { hostname, pathname, search } = new URL(url);
|
2645
|
+
return `https://${hostname}/transform/${transformationsString}${pathname}${search}`;
|
2646
|
+
}
|
2647
|
+
|
2648
|
+
var __defProp$6 = Object.defineProperty;
|
2649
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2650
|
+
var __publicField$6 = (obj, key, value) => {
|
2651
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2652
|
+
return value;
|
2653
|
+
};
|
2654
|
+
class XataFile {
|
2655
|
+
constructor(file) {
|
2656
|
+
/**
|
2657
|
+
* Name of this file.
|
2658
|
+
*/
|
2659
|
+
__publicField$6(this, "name");
|
2660
|
+
/**
|
2661
|
+
* Media type of this file.
|
2662
|
+
*/
|
2663
|
+
__publicField$6(this, "mediaType");
|
2664
|
+
/**
|
2665
|
+
* Base64 encoded content of this file.
|
2666
|
+
*/
|
2667
|
+
__publicField$6(this, "base64Content");
|
2668
|
+
/**
|
2669
|
+
* Whether to enable public url for this file.
|
2670
|
+
*/
|
2671
|
+
__publicField$6(this, "enablePublicUrl");
|
2672
|
+
/**
|
2673
|
+
* Timeout for the signed url.
|
2674
|
+
*/
|
2675
|
+
__publicField$6(this, "signedUrlTimeout");
|
2676
|
+
/**
|
2677
|
+
* Size of this file.
|
2678
|
+
*/
|
2679
|
+
__publicField$6(this, "size");
|
2680
|
+
/**
|
2681
|
+
* Version of this file.
|
2682
|
+
*/
|
2683
|
+
__publicField$6(this, "version");
|
2684
|
+
/**
|
2685
|
+
* Url of this file.
|
2686
|
+
*/
|
2687
|
+
__publicField$6(this, "url");
|
2688
|
+
/**
|
2689
|
+
* Signed url of this file.
|
2690
|
+
*/
|
2691
|
+
__publicField$6(this, "signedUrl");
|
2692
|
+
/**
|
2693
|
+
* Attributes of this file.
|
2694
|
+
*/
|
2695
|
+
__publicField$6(this, "attributes");
|
2696
|
+
this.name = file.name;
|
2697
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2698
|
+
this.base64Content = file.base64Content;
|
2699
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2700
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2701
|
+
this.size = file.size;
|
2702
|
+
this.version = file.version;
|
2703
|
+
this.url = file.url;
|
2704
|
+
this.signedUrl = file.signedUrl;
|
2705
|
+
this.attributes = file.attributes;
|
2706
|
+
}
|
2707
|
+
static fromBuffer(buffer, options = {}) {
|
2708
|
+
const base64Content = buffer.toString("base64");
|
2709
|
+
return new XataFile({ ...options, base64Content });
|
2710
|
+
}
|
2711
|
+
toBuffer() {
|
2712
|
+
if (!this.base64Content) {
|
2713
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2714
|
+
}
|
2715
|
+
return Buffer.from(this.base64Content, "base64");
|
2716
|
+
}
|
2717
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2718
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2719
|
+
return this.fromUint8Array(uint8Array, options);
|
2720
|
+
}
|
2721
|
+
toArrayBuffer() {
|
2722
|
+
if (!this.base64Content) {
|
2723
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2724
|
+
}
|
2725
|
+
const binary = atob(this.base64Content);
|
2726
|
+
return new ArrayBuffer(binary.length);
|
2727
|
+
}
|
2728
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2729
|
+
let binary = "";
|
2730
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2731
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2732
|
+
}
|
2733
|
+
const base64Content = btoa(binary);
|
2734
|
+
return new XataFile({ ...options, base64Content });
|
2735
|
+
}
|
2736
|
+
toUint8Array() {
|
2737
|
+
if (!this.base64Content) {
|
2738
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2739
|
+
}
|
2740
|
+
const binary = atob(this.base64Content);
|
2741
|
+
const uint8Array = new Uint8Array(binary.length);
|
2742
|
+
for (let i = 0; i < binary.length; i++) {
|
2743
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2744
|
+
}
|
2745
|
+
return uint8Array;
|
2746
|
+
}
|
2747
|
+
static async fromBlob(file, options = {}) {
|
2748
|
+
const name = options.name ?? file.name;
|
2749
|
+
const mediaType = file.type;
|
2750
|
+
const arrayBuffer = await file.arrayBuffer();
|
2751
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2752
|
+
}
|
2753
|
+
toBlob() {
|
2754
|
+
if (!this.base64Content) {
|
2755
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2756
|
+
}
|
2757
|
+
const arrayBuffer = this.toArrayBuffer();
|
2758
|
+
return new Blob([arrayBuffer], { type: this.mediaType });
|
2759
|
+
}
|
2760
|
+
static fromString(string, options = {}) {
|
2761
|
+
const base64Content = btoa(string);
|
2762
|
+
return new XataFile({ ...options, base64Content });
|
2763
|
+
}
|
2764
|
+
toString() {
|
2765
|
+
if (!this.base64Content) {
|
2766
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2767
|
+
}
|
2768
|
+
return atob(this.base64Content);
|
2769
|
+
}
|
2770
|
+
static fromBase64(base64Content, options = {}) {
|
2771
|
+
return new XataFile({ ...options, base64Content });
|
2772
|
+
}
|
2773
|
+
toBase64() {
|
2774
|
+
if (!this.base64Content) {
|
2775
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2776
|
+
}
|
2777
|
+
return this.base64Content;
|
2778
|
+
}
|
2779
|
+
transform(...options) {
|
2780
|
+
return {
|
2781
|
+
url: transformImage(this.url, options),
|
2782
|
+
signedUrl: transformImage(this.signedUrl, options)
|
2783
|
+
};
|
2784
|
+
}
|
1893
2785
|
}
|
2786
|
+
const parseInputFileEntry = async (entry) => {
|
2787
|
+
if (!isDefined(entry))
|
2788
|
+
return null;
|
2789
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2790
|
+
return compactObject({ id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout });
|
2791
|
+
};
|
1894
2792
|
|
1895
2793
|
function cleanFilter(filter) {
|
1896
|
-
if (!filter)
|
2794
|
+
if (!isDefined(filter))
|
1897
2795
|
return void 0;
|
1898
|
-
|
1899
|
-
|
2796
|
+
if (!isObject(filter))
|
2797
|
+
return filter;
|
2798
|
+
const values = Object.fromEntries(
|
2799
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2800
|
+
if (!isDefined(value))
|
2801
|
+
return acc;
|
2802
|
+
if (Array.isArray(value)) {
|
2803
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2804
|
+
if (clean.length === 0)
|
2805
|
+
return acc;
|
2806
|
+
return [...acc, [key, clean]];
|
2807
|
+
}
|
2808
|
+
if (isObject(value)) {
|
2809
|
+
const clean = cleanFilter(value);
|
2810
|
+
if (!isDefined(clean))
|
2811
|
+
return acc;
|
2812
|
+
return [...acc, [key, clean]];
|
2813
|
+
}
|
2814
|
+
return [...acc, [key, value]];
|
2815
|
+
}, [])
|
2816
|
+
);
|
2817
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
1900
2818
|
}
|
1901
2819
|
|
2820
|
+
var __defProp$5 = Object.defineProperty;
|
2821
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2822
|
+
var __publicField$5 = (obj, key, value) => {
|
2823
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2824
|
+
return value;
|
2825
|
+
};
|
1902
2826
|
var __accessCheck$6 = (obj, member, msg) => {
|
1903
2827
|
if (!member.has(obj))
|
1904
2828
|
throw TypeError("Cannot " + msg);
|
@@ -1921,22 +2845,58 @@ var _query, _page;
|
|
1921
2845
|
class Page {
|
1922
2846
|
constructor(query, meta, records = []) {
|
1923
2847
|
__privateAdd$6(this, _query, void 0);
|
2848
|
+
/**
|
2849
|
+
* Page metadata, required to retrieve additional records.
|
2850
|
+
*/
|
2851
|
+
__publicField$5(this, "meta");
|
2852
|
+
/**
|
2853
|
+
* The set of results for this page.
|
2854
|
+
*/
|
2855
|
+
__publicField$5(this, "records");
|
1924
2856
|
__privateSet$6(this, _query, query);
|
1925
2857
|
this.meta = meta;
|
1926
2858
|
this.records = new RecordArray(this, records);
|
1927
2859
|
}
|
2860
|
+
/**
|
2861
|
+
* Retrieves the next page of results.
|
2862
|
+
* @param size Maximum number of results to be retrieved.
|
2863
|
+
* @param offset Number of results to skip when retrieving the results.
|
2864
|
+
* @returns The next page or results.
|
2865
|
+
*/
|
1928
2866
|
async nextPage(size, offset) {
|
1929
2867
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1930
2868
|
}
|
2869
|
+
/**
|
2870
|
+
* Retrieves the previous page of results.
|
2871
|
+
* @param size Maximum number of results to be retrieved.
|
2872
|
+
* @param offset Number of results to skip when retrieving the results.
|
2873
|
+
* @returns The previous page or results.
|
2874
|
+
*/
|
1931
2875
|
async previousPage(size, offset) {
|
1932
2876
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1933
2877
|
}
|
2878
|
+
/**
|
2879
|
+
* Retrieves the start page of results.
|
2880
|
+
* @param size Maximum number of results to be retrieved.
|
2881
|
+
* @param offset Number of results to skip when retrieving the results.
|
2882
|
+
* @returns The start page or results.
|
2883
|
+
*/
|
1934
2884
|
async startPage(size, offset) {
|
1935
2885
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1936
2886
|
}
|
2887
|
+
/**
|
2888
|
+
* Retrieves the end page of results.
|
2889
|
+
* @param size Maximum number of results to be retrieved.
|
2890
|
+
* @param offset Number of results to skip when retrieving the results.
|
2891
|
+
* @returns The end page or results.
|
2892
|
+
*/
|
1937
2893
|
async endPage(size, offset) {
|
1938
2894
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1939
2895
|
}
|
2896
|
+
/**
|
2897
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2898
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2899
|
+
*/
|
1940
2900
|
hasNextPage() {
|
1941
2901
|
return this.meta.page.more;
|
1942
2902
|
}
|
@@ -1949,7 +2909,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1949
2909
|
function isCursorPaginationOptions(options) {
|
1950
2910
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1951
2911
|
}
|
1952
|
-
const _RecordArray = class extends Array {
|
2912
|
+
const _RecordArray = class _RecordArray extends Array {
|
1953
2913
|
constructor(...args) {
|
1954
2914
|
super(..._RecordArray.parseConstructorParams(...args));
|
1955
2915
|
__privateAdd$6(this, _page, void 0);
|
@@ -1968,32 +2928,67 @@ const _RecordArray = class extends Array {
|
|
1968
2928
|
toArray() {
|
1969
2929
|
return new Array(...this);
|
1970
2930
|
}
|
2931
|
+
toSerializable() {
|
2932
|
+
return JSON.parse(this.toString());
|
2933
|
+
}
|
2934
|
+
toString() {
|
2935
|
+
return JSON.stringify(this.toArray());
|
2936
|
+
}
|
1971
2937
|
map(callbackfn, thisArg) {
|
1972
2938
|
return this.toArray().map(callbackfn, thisArg);
|
1973
2939
|
}
|
2940
|
+
/**
|
2941
|
+
* Retrieve next page of records
|
2942
|
+
*
|
2943
|
+
* @returns A new array of objects
|
2944
|
+
*/
|
1974
2945
|
async nextPage(size, offset) {
|
1975
2946
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1976
2947
|
return new _RecordArray(newPage);
|
1977
2948
|
}
|
2949
|
+
/**
|
2950
|
+
* Retrieve previous page of records
|
2951
|
+
*
|
2952
|
+
* @returns A new array of objects
|
2953
|
+
*/
|
1978
2954
|
async previousPage(size, offset) {
|
1979
2955
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1980
2956
|
return new _RecordArray(newPage);
|
1981
2957
|
}
|
2958
|
+
/**
|
2959
|
+
* Retrieve start page of records
|
2960
|
+
*
|
2961
|
+
* @returns A new array of objects
|
2962
|
+
*/
|
1982
2963
|
async startPage(size, offset) {
|
1983
2964
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1984
2965
|
return new _RecordArray(newPage);
|
1985
2966
|
}
|
2967
|
+
/**
|
2968
|
+
* Retrieve end page of records
|
2969
|
+
*
|
2970
|
+
* @returns A new array of objects
|
2971
|
+
*/
|
1986
2972
|
async endPage(size, offset) {
|
1987
2973
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1988
2974
|
return new _RecordArray(newPage);
|
1989
2975
|
}
|
2976
|
+
/**
|
2977
|
+
* @returns Boolean indicating if there is a next page
|
2978
|
+
*/
|
1990
2979
|
hasNextPage() {
|
1991
2980
|
return __privateGet$6(this, _page).meta.page.more;
|
1992
2981
|
}
|
1993
2982
|
};
|
1994
|
-
let RecordArray = _RecordArray;
|
1995
2983
|
_page = new WeakMap();
|
2984
|
+
let RecordArray = _RecordArray;
|
1996
2985
|
|
2986
|
+
var __defProp$4 = Object.defineProperty;
|
2987
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2988
|
+
var __publicField$4 = (obj, key, value) => {
|
2989
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2990
|
+
return value;
|
2991
|
+
};
|
1997
2992
|
var __accessCheck$5 = (obj, member, msg) => {
|
1998
2993
|
if (!member.has(obj))
|
1999
2994
|
throw TypeError("Cannot " + msg);
|
@@ -2017,14 +3012,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2017
3012
|
return method;
|
2018
3013
|
};
|
2019
3014
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2020
|
-
const _Query = class {
|
3015
|
+
const _Query = class _Query {
|
2021
3016
|
constructor(repository, table, data, rawParent) {
|
2022
3017
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2023
3018
|
__privateAdd$5(this, _table$1, void 0);
|
2024
3019
|
__privateAdd$5(this, _repository, void 0);
|
2025
3020
|
__privateAdd$5(this, _data, { filter: {} });
|
2026
|
-
|
2027
|
-
this
|
3021
|
+
// Implements pagination
|
3022
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
3023
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
2028
3024
|
__privateSet$5(this, _table$1, table);
|
2029
3025
|
if (repository) {
|
2030
3026
|
__privateSet$5(this, _repository, repository);
|
@@ -2039,6 +3035,7 @@ const _Query = class {
|
|
2039
3035
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
2040
3036
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
2041
3037
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
3038
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
2042
3039
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
2043
3040
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2044
3041
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -2059,18 +3056,38 @@ const _Query = class {
|
|
2059
3056
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2060
3057
|
return toBase64(key);
|
2061
3058
|
}
|
3059
|
+
/**
|
3060
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3061
|
+
* @param queries An array of subqueries.
|
3062
|
+
* @returns A new Query object.
|
3063
|
+
*/
|
2062
3064
|
any(...queries) {
|
2063
3065
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2064
3066
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2065
3067
|
}
|
3068
|
+
/**
|
3069
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3070
|
+
* @param queries An array of subqueries.
|
3071
|
+
* @returns A new Query object.
|
3072
|
+
*/
|
2066
3073
|
all(...queries) {
|
2067
3074
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2068
3075
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2069
3076
|
}
|
3077
|
+
/**
|
3078
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3079
|
+
* @param queries An array of subqueries.
|
3080
|
+
* @returns A new Query object.
|
3081
|
+
*/
|
2070
3082
|
not(...queries) {
|
2071
3083
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2072
3084
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2073
3085
|
}
|
3086
|
+
/**
|
3087
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3088
|
+
* @param queries An array of subqueries.
|
3089
|
+
* @returns A new Query object.
|
3090
|
+
*/
|
2074
3091
|
none(...queries) {
|
2075
3092
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2076
3093
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2093,6 +3110,11 @@ const _Query = class {
|
|
2093
3110
|
const sort = [...originalSort, { column, direction }];
|
2094
3111
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2095
3112
|
}
|
3113
|
+
/**
|
3114
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3115
|
+
* @param columns Array of column names to be returned by the query.
|
3116
|
+
* @returns A new Query object.
|
3117
|
+
*/
|
2096
3118
|
select(columns) {
|
2097
3119
|
return new _Query(
|
2098
3120
|
__privateGet$5(this, _repository),
|
@@ -2105,6 +3127,12 @@ const _Query = class {
|
|
2105
3127
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2106
3128
|
return __privateGet$5(this, _repository).query(query);
|
2107
3129
|
}
|
3130
|
+
/**
|
3131
|
+
* Get results in an iterator
|
3132
|
+
*
|
3133
|
+
* @async
|
3134
|
+
* @returns Async interable of results
|
3135
|
+
*/
|
2108
3136
|
async *[Symbol.asyncIterator]() {
|
2109
3137
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2110
3138
|
yield record;
|
@@ -2165,26 +3193,53 @@ const _Query = class {
|
|
2165
3193
|
);
|
2166
3194
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2167
3195
|
}
|
3196
|
+
/**
|
3197
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3198
|
+
* @param ttl The cache TTL in milliseconds.
|
3199
|
+
* @returns A new Query object.
|
3200
|
+
*/
|
2168
3201
|
cache(ttl) {
|
2169
3202
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2170
3203
|
}
|
3204
|
+
/**
|
3205
|
+
* Retrieve next page of records
|
3206
|
+
*
|
3207
|
+
* @returns A new page object.
|
3208
|
+
*/
|
2171
3209
|
nextPage(size, offset) {
|
2172
3210
|
return this.startPage(size, offset);
|
2173
3211
|
}
|
3212
|
+
/**
|
3213
|
+
* Retrieve previous page of records
|
3214
|
+
*
|
3215
|
+
* @returns A new page object
|
3216
|
+
*/
|
2174
3217
|
previousPage(size, offset) {
|
2175
3218
|
return this.startPage(size, offset);
|
2176
3219
|
}
|
3220
|
+
/**
|
3221
|
+
* Retrieve start page of records
|
3222
|
+
*
|
3223
|
+
* @returns A new page object
|
3224
|
+
*/
|
2177
3225
|
startPage(size, offset) {
|
2178
3226
|
return this.getPaginated({ pagination: { size, offset } });
|
2179
3227
|
}
|
3228
|
+
/**
|
3229
|
+
* Retrieve last page of records
|
3230
|
+
*
|
3231
|
+
* @returns A new page object
|
3232
|
+
*/
|
2180
3233
|
endPage(size, offset) {
|
2181
3234
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2182
3235
|
}
|
3236
|
+
/**
|
3237
|
+
* @returns Boolean indicating if there is a next page
|
3238
|
+
*/
|
2183
3239
|
hasNextPage() {
|
2184
3240
|
return this.meta.page.more;
|
2185
3241
|
}
|
2186
3242
|
};
|
2187
|
-
let Query = _Query;
|
2188
3243
|
_table$1 = new WeakMap();
|
2189
3244
|
_repository = new WeakMap();
|
2190
3245
|
_data = new WeakMap();
|
@@ -2199,6 +3254,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2199
3254
|
}
|
2200
3255
|
return value;
|
2201
3256
|
};
|
3257
|
+
let Query = _Query;
|
2202
3258
|
function cleanParent(data, parent) {
|
2203
3259
|
if (isCursorPaginationOptions(data.pagination)) {
|
2204
3260
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2206,6 +3262,21 @@ function cleanParent(data, parent) {
|
|
2206
3262
|
return parent;
|
2207
3263
|
}
|
2208
3264
|
|
3265
|
+
const RecordColumnTypes = [
|
3266
|
+
"bool",
|
3267
|
+
"int",
|
3268
|
+
"float",
|
3269
|
+
"string",
|
3270
|
+
"text",
|
3271
|
+
"email",
|
3272
|
+
"multiple",
|
3273
|
+
"link",
|
3274
|
+
"object",
|
3275
|
+
"datetime",
|
3276
|
+
"vector",
|
3277
|
+
"file[]",
|
3278
|
+
"file"
|
3279
|
+
];
|
2209
3280
|
function isIdentifiable(x) {
|
2210
3281
|
return isObject(x) && isString(x?.id);
|
2211
3282
|
}
|
@@ -2219,7 +3290,11 @@ function isSortFilterString(value) {
|
|
2219
3290
|
return isString(value);
|
2220
3291
|
}
|
2221
3292
|
function isSortFilterBase(filter) {
|
2222
|
-
return isObject(filter) && Object.
|
3293
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3294
|
+
if (key === "*")
|
3295
|
+
return value === "random";
|
3296
|
+
return value === "asc" || value === "desc";
|
3297
|
+
});
|
2223
3298
|
}
|
2224
3299
|
function isSortFilterObject(filter) {
|
2225
3300
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2260,7 +3335,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2260
3335
|
__accessCheck$4(obj, member, "access private method");
|
2261
3336
|
return method;
|
2262
3337
|
};
|
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;
|
3338
|
+
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
3339
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2265
3340
|
class Repository extends Query {
|
2266
3341
|
}
|
@@ -2282,6 +3357,7 @@ class RestRepository extends Query {
|
|
2282
3357
|
__privateAdd$4(this, _setCacheQuery);
|
2283
3358
|
__privateAdd$4(this, _getCacheQuery);
|
2284
3359
|
__privateAdd$4(this, _getSchemaTables$1);
|
3360
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2285
3361
|
__privateAdd$4(this, _table, void 0);
|
2286
3362
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2287
3363
|
__privateAdd$4(this, _db, void 0);
|
@@ -2292,10 +3368,7 @@ class RestRepository extends Query {
|
|
2292
3368
|
__privateSet$4(this, _db, options.db);
|
2293
3369
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2294
3370
|
__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
|
-
});
|
3371
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2299
3372
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2300
3373
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2301
3374
|
return trace(name, fn, {
|
@@ -2352,7 +3425,6 @@ class RestRepository extends Query {
|
|
2352
3425
|
}
|
2353
3426
|
const id = extractId(a);
|
2354
3427
|
if (id) {
|
2355
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2356
3428
|
try {
|
2357
3429
|
const response = await getRecord({
|
2358
3430
|
pathParams: {
|
@@ -2363,7 +3435,7 @@ class RestRepository extends Query {
|
|
2363
3435
|
recordId: id
|
2364
3436
|
},
|
2365
3437
|
queryParams: { columns },
|
2366
|
-
...
|
3438
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2367
3439
|
});
|
2368
3440
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2369
3441
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2412,13 +3484,19 @@ class RestRepository extends Query {
|
|
2412
3484
|
const result = await this.read(a, columns);
|
2413
3485
|
return result;
|
2414
3486
|
}
|
2415
|
-
|
2416
|
-
|
2417
|
-
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
3487
|
+
try {
|
3488
|
+
if (isString(a) && isObject(b)) {
|
3489
|
+
const columns = isStringArray(c) ? c : void 0;
|
3490
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3491
|
+
}
|
3492
|
+
if (isObject(a) && isString(a.id)) {
|
3493
|
+
const columns = isStringArray(b) ? b : void 0;
|
3494
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3495
|
+
}
|
3496
|
+
} catch (error) {
|
3497
|
+
if (error.status === 422)
|
3498
|
+
return null;
|
3499
|
+
throw error;
|
2422
3500
|
}
|
2423
3501
|
throw new Error("Invalid arguments for update method");
|
2424
3502
|
});
|
@@ -2457,12 +3535,22 @@ class RestRepository extends Query {
|
|
2457
3535
|
return result;
|
2458
3536
|
}
|
2459
3537
|
if (isString(a) && isObject(b)) {
|
3538
|
+
if (a === "")
|
3539
|
+
throw new Error("The id can't be empty");
|
2460
3540
|
const columns = isStringArray(c) ? c : void 0;
|
2461
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3541
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2462
3542
|
}
|
2463
3543
|
if (isObject(a) && isString(a.id)) {
|
3544
|
+
if (a.id === "")
|
3545
|
+
throw new Error("The id can't be empty");
|
2464
3546
|
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 });
|
3547
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3548
|
+
}
|
3549
|
+
if (!isDefined(a) && isObject(b)) {
|
3550
|
+
return await this.create(b, c);
|
3551
|
+
}
|
3552
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3553
|
+
return await this.create(a, b);
|
2466
3554
|
}
|
2467
3555
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2468
3556
|
});
|
@@ -2479,12 +3567,22 @@ class RestRepository extends Query {
|
|
2479
3567
|
return result;
|
2480
3568
|
}
|
2481
3569
|
if (isString(a) && isObject(b)) {
|
3570
|
+
if (a === "")
|
3571
|
+
throw new Error("The id can't be empty");
|
2482
3572
|
const columns = isStringArray(c) ? c : void 0;
|
2483
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3573
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2484
3574
|
}
|
2485
3575
|
if (isObject(a) && isString(a.id)) {
|
3576
|
+
if (a.id === "")
|
3577
|
+
throw new Error("The id can't be empty");
|
2486
3578
|
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 });
|
3579
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3580
|
+
}
|
3581
|
+
if (!isDefined(a) && isObject(b)) {
|
3582
|
+
return await this.create(b, c);
|
3583
|
+
}
|
3584
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3585
|
+
return await this.create(a, b);
|
2488
3586
|
}
|
2489
3587
|
throw new Error("Invalid arguments for createOrReplace method");
|
2490
3588
|
});
|
@@ -2535,7 +3633,6 @@ class RestRepository extends Query {
|
|
2535
3633
|
}
|
2536
3634
|
async search(query, options = {}) {
|
2537
3635
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2538
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2539
3636
|
const { records } = await searchTable({
|
2540
3637
|
pathParams: {
|
2541
3638
|
workspace: "{workspaceId}",
|
@@ -2549,9 +3646,33 @@ class RestRepository extends Query {
|
|
2549
3646
|
prefix: options.prefix,
|
2550
3647
|
highlight: options.highlight,
|
2551
3648
|
filter: options.filter,
|
2552
|
-
boosters: options.boosters
|
3649
|
+
boosters: options.boosters,
|
3650
|
+
page: options.page,
|
3651
|
+
target: options.target
|
3652
|
+
},
|
3653
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3654
|
+
});
|
3655
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3656
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3657
|
+
});
|
3658
|
+
}
|
3659
|
+
async vectorSearch(column, query, options) {
|
3660
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3661
|
+
const { records } = await vectorSearchTable({
|
3662
|
+
pathParams: {
|
3663
|
+
workspace: "{workspaceId}",
|
3664
|
+
dbBranchName: "{dbBranch}",
|
3665
|
+
region: "{region}",
|
3666
|
+
tableName: __privateGet$4(this, _table)
|
3667
|
+
},
|
3668
|
+
body: {
|
3669
|
+
column,
|
3670
|
+
queryVector: query,
|
3671
|
+
similarityFunction: options?.similarityFunction,
|
3672
|
+
size: options?.size,
|
3673
|
+
filter: options?.filter
|
2553
3674
|
},
|
2554
|
-
...
|
3675
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2555
3676
|
});
|
2556
3677
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2557
3678
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2559,7 +3680,6 @@ class RestRepository extends Query {
|
|
2559
3680
|
}
|
2560
3681
|
async aggregate(aggs, filter) {
|
2561
3682
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2562
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2563
3683
|
const result = await aggregateTable({
|
2564
3684
|
pathParams: {
|
2565
3685
|
workspace: "{workspaceId}",
|
@@ -2568,7 +3688,7 @@ class RestRepository extends Query {
|
|
2568
3688
|
tableName: __privateGet$4(this, _table)
|
2569
3689
|
},
|
2570
3690
|
body: { aggs, filter },
|
2571
|
-
...
|
3691
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2572
3692
|
});
|
2573
3693
|
return result;
|
2574
3694
|
});
|
@@ -2579,7 +3699,6 @@ class RestRepository extends Query {
|
|
2579
3699
|
if (cacheQuery)
|
2580
3700
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2581
3701
|
const data = query.getQueryOptions();
|
2582
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2583
3702
|
const { meta, records: objects } = await queryTable({
|
2584
3703
|
pathParams: {
|
2585
3704
|
workspace: "{workspaceId}",
|
@@ -2591,10 +3710,11 @@ class RestRepository extends Query {
|
|
2591
3710
|
filter: cleanFilter(data.filter),
|
2592
3711
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2593
3712
|
page: data.pagination,
|
2594
|
-
columns: data.columns ?? ["*"]
|
3713
|
+
columns: data.columns ?? ["*"],
|
3714
|
+
consistency: data.consistency
|
2595
3715
|
},
|
2596
3716
|
fetchOptions: data.fetchOptions,
|
2597
|
-
...
|
3717
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2598
3718
|
});
|
2599
3719
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2600
3720
|
const records = objects.map(
|
@@ -2607,7 +3727,6 @@ class RestRepository extends Query {
|
|
2607
3727
|
async summarizeTable(query, summaries, summariesFilter) {
|
2608
3728
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2609
3729
|
const data = query.getQueryOptions();
|
2610
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2611
3730
|
const result = await summarizeTable({
|
2612
3731
|
pathParams: {
|
2613
3732
|
workspace: "{workspaceId}",
|
@@ -2619,15 +3738,44 @@ class RestRepository extends Query {
|
|
2619
3738
|
filter: cleanFilter(data.filter),
|
2620
3739
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2621
3740
|
columns: data.columns,
|
3741
|
+
consistency: data.consistency,
|
2622
3742
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2623
3743
|
summaries,
|
2624
3744
|
summariesFilter
|
2625
3745
|
},
|
2626
|
-
...
|
3746
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2627
3747
|
});
|
2628
3748
|
return result;
|
2629
3749
|
});
|
2630
3750
|
}
|
3751
|
+
ask(question, options) {
|
3752
|
+
const params = {
|
3753
|
+
pathParams: {
|
3754
|
+
workspace: "{workspaceId}",
|
3755
|
+
dbBranchName: "{dbBranch}",
|
3756
|
+
region: "{region}",
|
3757
|
+
tableName: __privateGet$4(this, _table)
|
3758
|
+
},
|
3759
|
+
body: {
|
3760
|
+
question,
|
3761
|
+
...options
|
3762
|
+
},
|
3763
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3764
|
+
};
|
3765
|
+
if (options?.onMessage) {
|
3766
|
+
fetchSSERequest({
|
3767
|
+
endpoint: "dataPlane",
|
3768
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3769
|
+
method: "POST",
|
3770
|
+
onMessage: (message) => {
|
3771
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3772
|
+
},
|
3773
|
+
...params
|
3774
|
+
});
|
3775
|
+
} else {
|
3776
|
+
return askTable(params);
|
3777
|
+
}
|
3778
|
+
}
|
2631
3779
|
}
|
2632
3780
|
_table = new WeakMap();
|
2633
3781
|
_getFetchProps = new WeakMap();
|
@@ -2637,8 +3785,7 @@ _schemaTables$2 = new WeakMap();
|
|
2637
3785
|
_trace = new WeakMap();
|
2638
3786
|
_insertRecordWithoutId = new WeakSet();
|
2639
3787
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2640
|
-
const
|
2641
|
-
const record = transformObjectLinks(object);
|
3788
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2642
3789
|
const response = await insertRecord({
|
2643
3790
|
pathParams: {
|
2644
3791
|
workspace: "{workspaceId}",
|
@@ -2648,15 +3795,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2648
3795
|
},
|
2649
3796
|
queryParams: { columns },
|
2650
3797
|
body: record,
|
2651
|
-
...
|
3798
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2652
3799
|
});
|
2653
3800
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2654
3801
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2655
3802
|
};
|
2656
3803
|
_insertRecordWithId = new WeakSet();
|
2657
3804
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2658
|
-
|
2659
|
-
|
3805
|
+
if (!recordId)
|
3806
|
+
return null;
|
3807
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2660
3808
|
const response = await insertRecordWithID({
|
2661
3809
|
pathParams: {
|
2662
3810
|
workspace: "{workspaceId}",
|
@@ -2667,30 +3815,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2667
3815
|
},
|
2668
3816
|
body: record,
|
2669
3817
|
queryParams: { createOnly, columns, ifVersion },
|
2670
|
-
...
|
3818
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2671
3819
|
});
|
2672
3820
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2673
3821
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2674
3822
|
};
|
2675
3823
|
_insertRecords = new WeakSet();
|
2676
3824
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2677
|
-
const
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
|
2682
|
-
BULK_OPERATION_MAX_SIZE
|
2683
|
-
);
|
3825
|
+
const operations = await promiseMap(objects, async (object) => {
|
3826
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3827
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3828
|
+
});
|
3829
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2684
3830
|
const ids = [];
|
2685
|
-
for (const
|
3831
|
+
for (const operations2 of chunkedOperations) {
|
2686
3832
|
const { results } = await branchTransaction({
|
2687
3833
|
pathParams: {
|
2688
3834
|
workspace: "{workspaceId}",
|
2689
3835
|
dbBranchName: "{dbBranch}",
|
2690
3836
|
region: "{region}"
|
2691
3837
|
},
|
2692
|
-
body: { operations },
|
2693
|
-
...
|
3838
|
+
body: { operations: operations2 },
|
3839
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2694
3840
|
});
|
2695
3841
|
for (const result of results) {
|
2696
3842
|
if (result.operation === "insert") {
|
@@ -2704,8 +3850,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2704
3850
|
};
|
2705
3851
|
_updateRecordWithID = new WeakSet();
|
2706
3852
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2707
|
-
|
2708
|
-
|
3853
|
+
if (!recordId)
|
3854
|
+
return null;
|
3855
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2709
3856
|
try {
|
2710
3857
|
const response = await updateRecordWithID({
|
2711
3858
|
pathParams: {
|
@@ -2717,7 +3864,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2717
3864
|
},
|
2718
3865
|
queryParams: { columns, ifVersion },
|
2719
3866
|
body: record,
|
2720
|
-
...
|
3867
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2721
3868
|
});
|
2722
3869
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2723
3870
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2730,23 +3877,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2730
3877
|
};
|
2731
3878
|
_updateRecords = new WeakSet();
|
2732
3879
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2733
|
-
const
|
2734
|
-
|
2735
|
-
|
2736
|
-
|
2737
|
-
|
2738
|
-
BULK_OPERATION_MAX_SIZE
|
2739
|
-
);
|
3880
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3881
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3882
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3883
|
+
});
|
3884
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2740
3885
|
const ids = [];
|
2741
|
-
for (const
|
3886
|
+
for (const operations2 of chunkedOperations) {
|
2742
3887
|
const { results } = await branchTransaction({
|
2743
3888
|
pathParams: {
|
2744
3889
|
workspace: "{workspaceId}",
|
2745
3890
|
dbBranchName: "{dbBranch}",
|
2746
3891
|
region: "{region}"
|
2747
3892
|
},
|
2748
|
-
body: { operations },
|
2749
|
-
...
|
3893
|
+
body: { operations: operations2 },
|
3894
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2750
3895
|
});
|
2751
3896
|
for (const result of results) {
|
2752
3897
|
if (result.operation === "update") {
|
@@ -2760,7 +3905,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2760
3905
|
};
|
2761
3906
|
_upsertRecordWithID = new WeakSet();
|
2762
3907
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2763
|
-
|
3908
|
+
if (!recordId)
|
3909
|
+
return null;
|
2764
3910
|
const response = await upsertRecordWithID({
|
2765
3911
|
pathParams: {
|
2766
3912
|
workspace: "{workspaceId}",
|
@@ -2771,14 +3917,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2771
3917
|
},
|
2772
3918
|
queryParams: { columns, ifVersion },
|
2773
3919
|
body: object,
|
2774
|
-
...
|
3920
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2775
3921
|
});
|
2776
3922
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2777
3923
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2778
3924
|
};
|
2779
3925
|
_deleteRecord = new WeakSet();
|
2780
3926
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2781
|
-
|
3927
|
+
if (!recordId)
|
3928
|
+
return null;
|
2782
3929
|
try {
|
2783
3930
|
const response = await deleteRecord({
|
2784
3931
|
pathParams: {
|
@@ -2789,7 +3936,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2789
3936
|
recordId
|
2790
3937
|
},
|
2791
3938
|
queryParams: { columns },
|
2792
|
-
...
|
3939
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2793
3940
|
});
|
2794
3941
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2795
3942
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2802,9 +3949,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2802
3949
|
};
|
2803
3950
|
_deleteRecords = new WeakSet();
|
2804
3951
|
deleteRecords_fn = async function(recordIds) {
|
2805
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2806
3952
|
const chunkedOperations = chunk(
|
2807
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3953
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2808
3954
|
BULK_OPERATION_MAX_SIZE
|
2809
3955
|
);
|
2810
3956
|
for (const operations of chunkedOperations) {
|
@@ -2815,21 +3961,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2815
3961
|
region: "{region}"
|
2816
3962
|
},
|
2817
3963
|
body: { operations },
|
2818
|
-
...
|
3964
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2819
3965
|
});
|
2820
3966
|
}
|
2821
3967
|
};
|
2822
3968
|
_setCacheQuery = new WeakSet();
|
2823
3969
|
setCacheQuery_fn = async function(query, meta, records) {
|
2824
|
-
await __privateGet$4(this, _cache)
|
3970
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2825
3971
|
};
|
2826
3972
|
_getCacheQuery = new WeakSet();
|
2827
3973
|
getCacheQuery_fn = async function(query) {
|
2828
3974
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2829
|
-
const result = await __privateGet$4(this, _cache)
|
3975
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2830
3976
|
if (!result)
|
2831
3977
|
return null;
|
2832
|
-
const
|
3978
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3979
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2833
3980
|
if (ttl < 0)
|
2834
3981
|
return null;
|
2835
3982
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2839,15 +3986,46 @@ _getSchemaTables$1 = new WeakSet();
|
|
2839
3986
|
getSchemaTables_fn$1 = async function() {
|
2840
3987
|
if (__privateGet$4(this, _schemaTables$2))
|
2841
3988
|
return __privateGet$4(this, _schemaTables$2);
|
2842
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2843
3989
|
const { schema } = await getBranchDetails({
|
2844
3990
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2845
|
-
...
|
3991
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2846
3992
|
});
|
2847
3993
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2848
3994
|
return schema.tables;
|
2849
3995
|
};
|
2850
|
-
|
3996
|
+
_transformObjectToApi = new WeakSet();
|
3997
|
+
transformObjectToApi_fn = async function(object) {
|
3998
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3999
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4000
|
+
if (!schema)
|
4001
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4002
|
+
const result = {};
|
4003
|
+
for (const [key, value] of Object.entries(object)) {
|
4004
|
+
if (key === "xata")
|
4005
|
+
continue;
|
4006
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4007
|
+
switch (type) {
|
4008
|
+
case "link": {
|
4009
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4010
|
+
break;
|
4011
|
+
}
|
4012
|
+
case "datetime": {
|
4013
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4014
|
+
break;
|
4015
|
+
}
|
4016
|
+
case `file`:
|
4017
|
+
result[key] = await parseInputFileEntry(value);
|
4018
|
+
break;
|
4019
|
+
case "file[]":
|
4020
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4021
|
+
break;
|
4022
|
+
default:
|
4023
|
+
result[key] = value;
|
4024
|
+
}
|
4025
|
+
}
|
4026
|
+
return result;
|
4027
|
+
};
|
4028
|
+
const removeLinksFromObject = (object) => {
|
2851
4029
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
2852
4030
|
if (key === "xata")
|
2853
4031
|
return acc;
|
@@ -2855,23 +4033,23 @@ const transformObjectLinks = (object) => {
|
|
2855
4033
|
}, {});
|
2856
4034
|
};
|
2857
4035
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2858
|
-
const
|
4036
|
+
const data = {};
|
2859
4037
|
const { xata, ...rest } = object ?? {};
|
2860
|
-
Object.assign(
|
4038
|
+
Object.assign(data, rest);
|
2861
4039
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2862
4040
|
if (!columns)
|
2863
4041
|
console.error(`Table ${table} not found in schema`);
|
2864
4042
|
for (const column of columns ?? []) {
|
2865
4043
|
if (!isValidColumn(selectedColumns, column))
|
2866
4044
|
continue;
|
2867
|
-
const value =
|
4045
|
+
const value = data[column.name];
|
2868
4046
|
switch (column.type) {
|
2869
4047
|
case "datetime": {
|
2870
4048
|
const date = value !== void 0 ? new Date(value) : null;
|
2871
4049
|
if (date !== null && isNaN(date.getTime())) {
|
2872
4050
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2873
4051
|
} else {
|
2874
|
-
|
4052
|
+
data[column.name] = date;
|
2875
4053
|
}
|
2876
4054
|
break;
|
2877
4055
|
}
|
@@ -2890,44 +4068,60 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2890
4068
|
}
|
2891
4069
|
return acc;
|
2892
4070
|
}, []);
|
2893
|
-
|
4071
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2894
4072
|
} else {
|
2895
|
-
|
4073
|
+
data[column.name] = null;
|
2896
4074
|
}
|
2897
4075
|
break;
|
2898
4076
|
}
|
4077
|
+
case "file":
|
4078
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4079
|
+
break;
|
4080
|
+
case "file[]":
|
4081
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4082
|
+
break;
|
2899
4083
|
default:
|
2900
|
-
|
4084
|
+
data[column.name] = value ?? null;
|
2901
4085
|
if (column.notNull === true && value === null) {
|
2902
4086
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2903
4087
|
}
|
2904
4088
|
break;
|
2905
4089
|
}
|
2906
4090
|
}
|
2907
|
-
|
2908
|
-
|
4091
|
+
const record = { ...data };
|
4092
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
4093
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4094
|
+
record.read = function(columns2) {
|
4095
|
+
return db[table].read(record["id"], columns2);
|
2909
4096
|
};
|
2910
|
-
|
4097
|
+
record.update = function(data2, b, c) {
|
2911
4098
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2912
4099
|
const ifVersion = parseIfVersion(b, c);
|
2913
|
-
return db[table].update(
|
4100
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2914
4101
|
};
|
2915
|
-
|
4102
|
+
record.replace = function(data2, b, c) {
|
2916
4103
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2917
4104
|
const ifVersion = parseIfVersion(b, c);
|
2918
|
-
return db[table].createOrReplace(
|
4105
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
2919
4106
|
};
|
2920
|
-
|
2921
|
-
return db[table].delete(
|
4107
|
+
record.delete = function() {
|
4108
|
+
return db[table].delete(record["id"]);
|
2922
4109
|
};
|
2923
|
-
|
2924
|
-
|
4110
|
+
record.xata = Object.freeze(metadata);
|
4111
|
+
record.getMetadata = function() {
|
4112
|
+
return record.xata;
|
2925
4113
|
};
|
2926
|
-
|
2927
|
-
|
4114
|
+
record.toSerializable = function() {
|
4115
|
+
return JSON.parse(JSON.stringify(serializable));
|
4116
|
+
};
|
4117
|
+
record.toString = function() {
|
4118
|
+
return JSON.stringify(serializable);
|
4119
|
+
};
|
4120
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4121
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2928
4122
|
}
|
2929
|
-
Object.freeze(
|
2930
|
-
return
|
4123
|
+
Object.freeze(record);
|
4124
|
+
return record;
|
2931
4125
|
};
|
2932
4126
|
function extractId(value) {
|
2933
4127
|
if (isString(value))
|
@@ -2939,11 +4133,7 @@ function extractId(value) {
|
|
2939
4133
|
function isValidColumn(columns, column) {
|
2940
4134
|
if (columns.includes("*"))
|
2941
4135
|
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);
|
4136
|
+
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
2947
4137
|
}
|
2948
4138
|
function parseIfVersion(...args) {
|
2949
4139
|
for (const arg of args) {
|
@@ -2954,6 +4144,12 @@ function parseIfVersion(...args) {
|
|
2954
4144
|
return void 0;
|
2955
4145
|
}
|
2956
4146
|
|
4147
|
+
var __defProp$3 = Object.defineProperty;
|
4148
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4149
|
+
var __publicField$3 = (obj, key, value) => {
|
4150
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4151
|
+
return value;
|
4152
|
+
};
|
2957
4153
|
var __accessCheck$3 = (obj, member, msg) => {
|
2958
4154
|
if (!member.has(obj))
|
2959
4155
|
throw TypeError("Cannot " + msg);
|
@@ -2976,6 +4172,8 @@ var _map;
|
|
2976
4172
|
class SimpleCache {
|
2977
4173
|
constructor(options = {}) {
|
2978
4174
|
__privateAdd$3(this, _map, void 0);
|
4175
|
+
__publicField$3(this, "capacity");
|
4176
|
+
__publicField$3(this, "defaultQueryTTL");
|
2979
4177
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
2980
4178
|
this.capacity = options.max ?? 500;
|
2981
4179
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3111,19 +4309,19 @@ class SearchPlugin extends XataPlugin {
|
|
3111
4309
|
__privateAdd$1(this, _schemaTables, void 0);
|
3112
4310
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3113
4311
|
}
|
3114
|
-
build(
|
4312
|
+
build(pluginOptions) {
|
3115
4313
|
return {
|
3116
4314
|
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,
|
4315
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4316
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3119
4317
|
return records.map((record) => {
|
3120
4318
|
const { table = "orphan" } = record.xata;
|
3121
4319
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3122
4320
|
});
|
3123
4321
|
},
|
3124
4322
|
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,
|
4323
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4324
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3127
4325
|
return records.reduce((acc, record) => {
|
3128
4326
|
const { table = "orphan" } = record.xata;
|
3129
4327
|
const items = acc[table] ?? [];
|
@@ -3136,38 +4334,36 @@ class SearchPlugin extends XataPlugin {
|
|
3136
4334
|
}
|
3137
4335
|
_schemaTables = new WeakMap();
|
3138
4336
|
_search = new WeakSet();
|
3139
|
-
search_fn = async function(query, options,
|
3140
|
-
const
|
3141
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
4337
|
+
search_fn = async function(query, options, pluginOptions) {
|
4338
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3142
4339
|
const { records } = await searchBranch({
|
3143
4340
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3144
|
-
|
3145
|
-
|
4341
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4342
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
4343
|
+
...pluginOptions
|
3146
4344
|
});
|
3147
4345
|
return records;
|
3148
4346
|
};
|
3149
4347
|
_getSchemaTables = new WeakSet();
|
3150
|
-
getSchemaTables_fn = async function(
|
4348
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3151
4349
|
if (__privateGet$1(this, _schemaTables))
|
3152
4350
|
return __privateGet$1(this, _schemaTables);
|
3153
|
-
const fetchProps = await getFetchProps();
|
3154
4351
|
const { schema } = await getBranchDetails({
|
3155
4352
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3156
|
-
...
|
4353
|
+
...pluginOptions
|
3157
4354
|
});
|
3158
4355
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3159
4356
|
return schema.tables;
|
3160
4357
|
};
|
3161
4358
|
|
3162
4359
|
class TransactionPlugin extends XataPlugin {
|
3163
|
-
build(
|
4360
|
+
build(pluginOptions) {
|
3164
4361
|
return {
|
3165
4362
|
run: async (operations) => {
|
3166
|
-
const fetchProps = await getFetchProps();
|
3167
4363
|
const response = await branchTransaction({
|
3168
4364
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3169
4365
|
body: { operations },
|
3170
|
-
...
|
4366
|
+
...pluginOptions
|
3171
4367
|
});
|
3172
4368
|
return response;
|
3173
4369
|
}
|
@@ -3175,93 +4371,12 @@ class TransactionPlugin extends XataPlugin {
|
|
3175
4371
|
}
|
3176
4372
|
}
|
3177
4373
|
|
3178
|
-
|
3179
|
-
|
4374
|
+
var __defProp$2 = Object.defineProperty;
|
4375
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4376
|
+
var __publicField$2 = (obj, key, value) => {
|
4377
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4378
|
+
return value;
|
3180
4379
|
};
|
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
4380
|
var __accessCheck = (obj, member, msg) => {
|
3266
4381
|
if (!member.has(obj))
|
3267
4382
|
throw TypeError("Cannot " + msg);
|
@@ -3285,48 +4400,45 @@ var __privateMethod = (obj, member, method) => {
|
|
3285
4400
|
return method;
|
3286
4401
|
};
|
3287
4402
|
const buildClient = (plugins) => {
|
3288
|
-
var
|
4403
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3289
4404
|
return _a = class {
|
3290
4405
|
constructor(options = {}, schemaTables) {
|
3291
4406
|
__privateAdd(this, _parseOptions);
|
3292
4407
|
__privateAdd(this, _getFetchProps);
|
3293
|
-
__privateAdd(this, _evaluateBranch);
|
3294
|
-
__privateAdd(this, _branch, void 0);
|
3295
4408
|
__privateAdd(this, _options, void 0);
|
4409
|
+
__publicField$2(this, "db");
|
4410
|
+
__publicField$2(this, "search");
|
4411
|
+
__publicField$2(this, "transactions");
|
4412
|
+
__publicField$2(this, "files");
|
3296
4413
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3297
4414
|
__privateSet(this, _options, safeOptions);
|
3298
4415
|
const pluginOptions = {
|
3299
|
-
|
4416
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3300
4417
|
cache: safeOptions.cache,
|
3301
|
-
|
4418
|
+
host: safeOptions.host
|
3302
4419
|
};
|
3303
4420
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3304
4421
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3305
4422
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4423
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3306
4424
|
this.db = db;
|
3307
4425
|
this.search = search;
|
3308
4426
|
this.transactions = transactions;
|
4427
|
+
this.files = files;
|
3309
4428
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3310
4429
|
if (namespace === void 0)
|
3311
4430
|
continue;
|
3312
|
-
|
3313
|
-
if (result instanceof Promise) {
|
3314
|
-
void result.then((namespace2) => {
|
3315
|
-
this[key] = namespace2;
|
3316
|
-
});
|
3317
|
-
} else {
|
3318
|
-
this[key] = result;
|
3319
|
-
}
|
4431
|
+
this[key] = namespace.build(pluginOptions);
|
3320
4432
|
}
|
3321
4433
|
}
|
3322
4434
|
async getConfig() {
|
3323
4435
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3324
|
-
const branch =
|
4436
|
+
const branch = __privateGet(this, _options).branch;
|
3325
4437
|
return { databaseURL, branch };
|
3326
4438
|
}
|
3327
|
-
},
|
4439
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3328
4440
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3329
|
-
const isBrowser = typeof window !== "undefined";
|
4441
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3330
4442
|
if (isBrowser && !enableBrowser) {
|
3331
4443
|
throw new Error(
|
3332
4444
|
"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 +4449,89 @@ const buildClient = (plugins) => {
|
|
3337
4449
|
const apiKey = options?.apiKey || getAPIKey();
|
3338
4450
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3339
4451
|
const trace = options?.trace ?? defaultTrace;
|
3340
|
-
const
|
4452
|
+
const clientName = options?.clientName;
|
4453
|
+
const host = options?.host ?? "production";
|
4454
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3341
4455
|
if (!apiKey) {
|
3342
4456
|
throw new Error("Option apiKey is required");
|
3343
4457
|
}
|
3344
4458
|
if (!databaseURL) {
|
3345
4459
|
throw new Error("Option databaseURL is required");
|
3346
4460
|
}
|
3347
|
-
|
3348
|
-
|
3349
|
-
const
|
3350
|
-
if (
|
3351
|
-
|
4461
|
+
const envBranch = getBranch();
|
4462
|
+
const previewBranch = getPreviewBranch();
|
4463
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4464
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4465
|
+
console.warn(
|
4466
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4467
|
+
);
|
4468
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4469
|
+
console.warn(
|
4470
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4471
|
+
);
|
4472
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4473
|
+
console.warn(
|
4474
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4475
|
+
);
|
4476
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4477
|
+
console.warn(
|
4478
|
+
`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.`
|
4479
|
+
);
|
4480
|
+
}
|
4481
|
+
return {
|
4482
|
+
fetch,
|
4483
|
+
databaseURL,
|
4484
|
+
apiKey,
|
4485
|
+
branch,
|
4486
|
+
cache,
|
4487
|
+
trace,
|
4488
|
+
host,
|
4489
|
+
clientID: generateUUID(),
|
4490
|
+
enableBrowser,
|
4491
|
+
clientName,
|
4492
|
+
xataAgentExtra
|
4493
|
+
};
|
4494
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4495
|
+
fetch,
|
4496
|
+
apiKey,
|
4497
|
+
databaseURL,
|
4498
|
+
branch,
|
4499
|
+
trace,
|
4500
|
+
clientID,
|
4501
|
+
clientName,
|
4502
|
+
xataAgentExtra
|
4503
|
+
}) {
|
3352
4504
|
return {
|
3353
|
-
|
4505
|
+
fetch,
|
3354
4506
|
apiKey,
|
3355
4507
|
apiUrl: "",
|
4508
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3356
4509
|
workspacesApiUrl: (path, params) => {
|
3357
4510
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3358
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4511
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3359
4512
|
return databaseURL + newPath;
|
3360
4513
|
},
|
3361
4514
|
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;
|
4515
|
+
clientID,
|
4516
|
+
clientName,
|
4517
|
+
xataAgentExtra
|
3372
4518
|
};
|
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
4519
|
}, _a;
|
3381
4520
|
};
|
3382
4521
|
class BaseClient extends buildClient() {
|
3383
4522
|
}
|
3384
4523
|
|
4524
|
+
var __defProp$1 = Object.defineProperty;
|
4525
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4526
|
+
var __publicField$1 = (obj, key, value) => {
|
4527
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4528
|
+
return value;
|
4529
|
+
};
|
3385
4530
|
const META = "__";
|
3386
4531
|
const VALUE = "___";
|
3387
4532
|
class Serializer {
|
3388
4533
|
constructor() {
|
3389
|
-
this
|
4534
|
+
__publicField$1(this, "classes", {});
|
3390
4535
|
}
|
3391
4536
|
add(clazz) {
|
3392
4537
|
this.classes[clazz.name] = clazz;
|
@@ -3450,7 +4595,7 @@ const deserialize = (json) => {
|
|
3450
4595
|
};
|
3451
4596
|
|
3452
4597
|
function buildWorkerRunner(config) {
|
3453
|
-
return function xataWorker(name,
|
4598
|
+
return function xataWorker(name, worker) {
|
3454
4599
|
return async (...args) => {
|
3455
4600
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3456
4601
|
const result = await fetch(url, {
|
@@ -3464,12 +4609,19 @@ function buildWorkerRunner(config) {
|
|
3464
4609
|
};
|
3465
4610
|
}
|
3466
4611
|
|
4612
|
+
var __defProp = Object.defineProperty;
|
4613
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4614
|
+
var __publicField = (obj, key, value) => {
|
4615
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4616
|
+
return value;
|
4617
|
+
};
|
3467
4618
|
class XataError extends Error {
|
3468
4619
|
constructor(message, status) {
|
3469
4620
|
super(message);
|
4621
|
+
__publicField(this, "status");
|
3470
4622
|
this.status = status;
|
3471
4623
|
}
|
3472
4624
|
}
|
3473
4625
|
|
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,
|
4626
|
+
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, 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, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, generateAccessToken, getAPIKey, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, 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, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3475
4627
|
//# sourceMappingURL=index.mjs.map
|