@xata.io/client 0.0.0-alpha.vfbde008 → 0.0.0-alpha.vfc446ea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +1 -1
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +136 -2
- package/dist/index.cjs +1439 -272
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1825 -349
- package/dist/index.mjs +1412 -270
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/.eslintrc.cjs +0 -13
- package/rollup.config.mjs +0 -44
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -27,8 +27,11 @@ function notEmpty(value) {
|
|
27
27
|
function compact(arr) {
|
28
28
|
return arr.filter(notEmpty);
|
29
29
|
}
|
30
|
+
function compactObject(obj) {
|
31
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
32
|
+
}
|
30
33
|
function isObject(value) {
|
31
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
34
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
32
35
|
}
|
33
36
|
function isDefined(value) {
|
34
37
|
return value !== null && value !== void 0;
|
@@ -83,6 +86,27 @@ function chunk(array, chunkSize) {
|
|
83
86
|
async function timeout(ms) {
|
84
87
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
85
88
|
}
|
89
|
+
function timeoutWithCancel(ms) {
|
90
|
+
let timeoutId;
|
91
|
+
const promise = new Promise((resolve) => {
|
92
|
+
timeoutId = setTimeout(() => {
|
93
|
+
resolve();
|
94
|
+
}, ms);
|
95
|
+
});
|
96
|
+
return {
|
97
|
+
cancel: () => clearTimeout(timeoutId),
|
98
|
+
promise
|
99
|
+
};
|
100
|
+
}
|
101
|
+
function promiseMap(inputValues, mapper) {
|
102
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
103
|
+
(acc) => mapper(inputValue).then((result) => {
|
104
|
+
acc.push(result);
|
105
|
+
return acc;
|
106
|
+
})
|
107
|
+
);
|
108
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
109
|
+
}
|
86
110
|
|
87
111
|
function getEnvironment() {
|
88
112
|
try {
|
@@ -91,8 +115,10 @@ function getEnvironment() {
|
|
91
115
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
92
116
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
93
117
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
94
|
-
|
95
|
-
|
118
|
+
deployPreview: process.env.XATA_PREVIEW,
|
119
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
120
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
121
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
96
122
|
};
|
97
123
|
}
|
98
124
|
} catch (err) {
|
@@ -103,8 +129,10 @@ function getEnvironment() {
|
|
103
129
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
104
130
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
105
131
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
106
|
-
|
107
|
-
|
132
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
133
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
134
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
135
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
108
136
|
};
|
109
137
|
}
|
110
138
|
} catch (err) {
|
@@ -113,8 +141,10 @@ function getEnvironment() {
|
|
113
141
|
apiKey: getGlobalApiKey(),
|
114
142
|
databaseURL: getGlobalDatabaseURL(),
|
115
143
|
branch: getGlobalBranch(),
|
116
|
-
|
117
|
-
|
144
|
+
deployPreview: void 0,
|
145
|
+
deployPreviewBranch: void 0,
|
146
|
+
vercelGitCommitRef: void 0,
|
147
|
+
vercelGitRepoOwner: void 0
|
118
148
|
};
|
119
149
|
}
|
120
150
|
function getEnableBrowserVariable() {
|
@@ -157,41 +187,59 @@ function getGlobalBranch() {
|
|
157
187
|
return void 0;
|
158
188
|
}
|
159
189
|
}
|
160
|
-
function
|
190
|
+
function getDatabaseURL() {
|
161
191
|
try {
|
162
|
-
|
192
|
+
const { databaseURL } = getEnvironment();
|
193
|
+
return databaseURL;
|
163
194
|
} catch (err) {
|
164
195
|
return void 0;
|
165
196
|
}
|
166
197
|
}
|
167
|
-
|
168
|
-
const cmd = ["git", "branch", "--show-current"];
|
169
|
-
const fullCmd = cmd.join(" ");
|
170
|
-
const nodeModule = ["child", "process"].join("_");
|
171
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
198
|
+
function getAPIKey() {
|
172
199
|
try {
|
173
|
-
const {
|
174
|
-
return
|
200
|
+
const { apiKey } = getEnvironment();
|
201
|
+
return apiKey;
|
175
202
|
} catch (err) {
|
203
|
+
return void 0;
|
176
204
|
}
|
205
|
+
}
|
206
|
+
function getBranch() {
|
177
207
|
try {
|
178
|
-
|
179
|
-
|
180
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
181
|
-
}
|
208
|
+
const { branch } = getEnvironment();
|
209
|
+
return branch;
|
182
210
|
} catch (err) {
|
211
|
+
return void 0;
|
183
212
|
}
|
184
213
|
}
|
185
|
-
|
186
|
-
|
214
|
+
function buildPreviewBranchName({ org, branch }) {
|
215
|
+
return `preview-${org}-${branch}`;
|
216
|
+
}
|
217
|
+
function getPreviewBranch() {
|
187
218
|
try {
|
188
|
-
const {
|
189
|
-
|
219
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
220
|
+
if (deployPreviewBranch)
|
221
|
+
return deployPreviewBranch;
|
222
|
+
switch (deployPreview) {
|
223
|
+
case "vercel": {
|
224
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
225
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
226
|
+
return void 0;
|
227
|
+
}
|
228
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
229
|
+
}
|
230
|
+
}
|
231
|
+
return void 0;
|
190
232
|
} catch (err) {
|
191
233
|
return void 0;
|
192
234
|
}
|
193
235
|
}
|
194
236
|
|
237
|
+
var __defProp$8 = Object.defineProperty;
|
238
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
239
|
+
var __publicField$8 = (obj, key, value) => {
|
240
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
241
|
+
return value;
|
242
|
+
};
|
195
243
|
var __accessCheck$8 = (obj, member, msg) => {
|
196
244
|
if (!member.has(obj))
|
197
245
|
throw TypeError("Cannot " + msg);
|
@@ -215,6 +263,7 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
215
263
|
return method;
|
216
264
|
};
|
217
265
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
266
|
+
const REQUEST_TIMEOUT = 3e4;
|
218
267
|
function getFetchImplementation(userFetch) {
|
219
268
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
220
269
|
const fetchImpl = userFetch ?? globalFetch;
|
@@ -231,6 +280,8 @@ class ApiRequestPool {
|
|
231
280
|
__privateAdd$8(this, _fetch, void 0);
|
232
281
|
__privateAdd$8(this, _queue, void 0);
|
233
282
|
__privateAdd$8(this, _concurrency, void 0);
|
283
|
+
__publicField$8(this, "running");
|
284
|
+
__publicField$8(this, "started");
|
234
285
|
__privateSet$8(this, _queue, []);
|
235
286
|
__privateSet$8(this, _concurrency, concurrency);
|
236
287
|
this.running = 0;
|
@@ -246,18 +297,22 @@ class ApiRequestPool {
|
|
246
297
|
return __privateGet$8(this, _fetch);
|
247
298
|
}
|
248
299
|
request(url, options) {
|
249
|
-
const start = new Date();
|
250
|
-
const
|
300
|
+
const start = /* @__PURE__ */ new Date();
|
301
|
+
const fetchImpl = this.getFetch();
|
251
302
|
const runRequest = async (stalled = false) => {
|
252
|
-
const
|
303
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
304
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
305
|
+
if (!response) {
|
306
|
+
throw new Error("Request timed out");
|
307
|
+
}
|
253
308
|
if (response.status === 429) {
|
254
309
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
255
310
|
await timeout(rateLimitReset * 1e3);
|
256
311
|
return await runRequest(true);
|
257
312
|
}
|
258
313
|
if (stalled) {
|
259
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
260
|
-
console.warn(`A request to Xata hit
|
314
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
315
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
261
316
|
}
|
262
317
|
return response;
|
263
318
|
};
|
@@ -299,16 +354,199 @@ function generateUUID() {
|
|
299
354
|
});
|
300
355
|
}
|
301
356
|
|
302
|
-
|
357
|
+
async function getBytes(stream, onChunk) {
|
358
|
+
const reader = stream.getReader();
|
359
|
+
let result;
|
360
|
+
while (!(result = await reader.read()).done) {
|
361
|
+
onChunk(result.value);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
function getLines(onLine) {
|
365
|
+
let buffer;
|
366
|
+
let position;
|
367
|
+
let fieldLength;
|
368
|
+
let discardTrailingNewline = false;
|
369
|
+
return function onChunk(arr) {
|
370
|
+
if (buffer === void 0) {
|
371
|
+
buffer = arr;
|
372
|
+
position = 0;
|
373
|
+
fieldLength = -1;
|
374
|
+
} else {
|
375
|
+
buffer = concat(buffer, arr);
|
376
|
+
}
|
377
|
+
const bufLength = buffer.length;
|
378
|
+
let lineStart = 0;
|
379
|
+
while (position < bufLength) {
|
380
|
+
if (discardTrailingNewline) {
|
381
|
+
if (buffer[position] === 10 /* NewLine */) {
|
382
|
+
lineStart = ++position;
|
383
|
+
}
|
384
|
+
discardTrailingNewline = false;
|
385
|
+
}
|
386
|
+
let lineEnd = -1;
|
387
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
388
|
+
switch (buffer[position]) {
|
389
|
+
case 58 /* Colon */:
|
390
|
+
if (fieldLength === -1) {
|
391
|
+
fieldLength = position - lineStart;
|
392
|
+
}
|
393
|
+
break;
|
394
|
+
case 13 /* CarriageReturn */:
|
395
|
+
discardTrailingNewline = true;
|
396
|
+
case 10 /* NewLine */:
|
397
|
+
lineEnd = position;
|
398
|
+
break;
|
399
|
+
}
|
400
|
+
}
|
401
|
+
if (lineEnd === -1) {
|
402
|
+
break;
|
403
|
+
}
|
404
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
405
|
+
lineStart = position;
|
406
|
+
fieldLength = -1;
|
407
|
+
}
|
408
|
+
if (lineStart === bufLength) {
|
409
|
+
buffer = void 0;
|
410
|
+
} else if (lineStart !== 0) {
|
411
|
+
buffer = buffer.subarray(lineStart);
|
412
|
+
position -= lineStart;
|
413
|
+
}
|
414
|
+
};
|
415
|
+
}
|
416
|
+
function getMessages(onId, onRetry, onMessage) {
|
417
|
+
let message = newMessage();
|
418
|
+
const decoder = new TextDecoder();
|
419
|
+
return function onLine(line, fieldLength) {
|
420
|
+
if (line.length === 0) {
|
421
|
+
onMessage?.(message);
|
422
|
+
message = newMessage();
|
423
|
+
} else if (fieldLength > 0) {
|
424
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
425
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
426
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
427
|
+
switch (field) {
|
428
|
+
case "data":
|
429
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
430
|
+
break;
|
431
|
+
case "event":
|
432
|
+
message.event = value;
|
433
|
+
break;
|
434
|
+
case "id":
|
435
|
+
onId(message.id = value);
|
436
|
+
break;
|
437
|
+
case "retry":
|
438
|
+
const retry = parseInt(value, 10);
|
439
|
+
if (!isNaN(retry)) {
|
440
|
+
onRetry(message.retry = retry);
|
441
|
+
}
|
442
|
+
break;
|
443
|
+
}
|
444
|
+
}
|
445
|
+
};
|
446
|
+
}
|
447
|
+
function concat(a, b) {
|
448
|
+
const res = new Uint8Array(a.length + b.length);
|
449
|
+
res.set(a);
|
450
|
+
res.set(b, a.length);
|
451
|
+
return res;
|
452
|
+
}
|
453
|
+
function newMessage() {
|
454
|
+
return {
|
455
|
+
data: "",
|
456
|
+
event: "",
|
457
|
+
id: "",
|
458
|
+
retry: void 0
|
459
|
+
};
|
460
|
+
}
|
461
|
+
const EventStreamContentType = "text/event-stream";
|
462
|
+
const LastEventId = "last-event-id";
|
463
|
+
function fetchEventSource(input, {
|
464
|
+
signal: inputSignal,
|
465
|
+
headers: inputHeaders,
|
466
|
+
onopen: inputOnOpen,
|
467
|
+
onmessage,
|
468
|
+
onclose,
|
469
|
+
onerror,
|
470
|
+
fetch: inputFetch,
|
471
|
+
...rest
|
472
|
+
}) {
|
473
|
+
return new Promise((resolve, reject) => {
|
474
|
+
const headers = { ...inputHeaders };
|
475
|
+
if (!headers.accept) {
|
476
|
+
headers.accept = EventStreamContentType;
|
477
|
+
}
|
478
|
+
let curRequestController;
|
479
|
+
function dispose() {
|
480
|
+
curRequestController.abort();
|
481
|
+
}
|
482
|
+
inputSignal?.addEventListener("abort", () => {
|
483
|
+
dispose();
|
484
|
+
resolve();
|
485
|
+
});
|
486
|
+
const fetchImpl = inputFetch ?? fetch;
|
487
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
488
|
+
async function create() {
|
489
|
+
curRequestController = new AbortController();
|
490
|
+
try {
|
491
|
+
const response = await fetchImpl(input, {
|
492
|
+
...rest,
|
493
|
+
headers,
|
494
|
+
signal: curRequestController.signal
|
495
|
+
});
|
496
|
+
await onopen(response);
|
497
|
+
await getBytes(
|
498
|
+
response.body,
|
499
|
+
getLines(
|
500
|
+
getMessages(
|
501
|
+
(id) => {
|
502
|
+
if (id) {
|
503
|
+
headers[LastEventId] = id;
|
504
|
+
} else {
|
505
|
+
delete headers[LastEventId];
|
506
|
+
}
|
507
|
+
},
|
508
|
+
(_retry) => {
|
509
|
+
},
|
510
|
+
onmessage
|
511
|
+
)
|
512
|
+
)
|
513
|
+
);
|
514
|
+
onclose?.();
|
515
|
+
dispose();
|
516
|
+
resolve();
|
517
|
+
} catch (err) {
|
518
|
+
}
|
519
|
+
}
|
520
|
+
create();
|
521
|
+
});
|
522
|
+
}
|
523
|
+
function defaultOnOpen(response) {
|
524
|
+
const contentType = response.headers?.get("content-type");
|
525
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
526
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
527
|
+
}
|
528
|
+
}
|
303
529
|
|
530
|
+
const VERSION = "0.25.2";
|
531
|
+
|
532
|
+
var __defProp$7 = Object.defineProperty;
|
533
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
534
|
+
var __publicField$7 = (obj, key, value) => {
|
535
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
536
|
+
return value;
|
537
|
+
};
|
304
538
|
class ErrorWithCause extends Error {
|
305
539
|
constructor(message, options) {
|
306
540
|
super(message, options);
|
541
|
+
__publicField$7(this, "cause");
|
307
542
|
}
|
308
543
|
}
|
309
544
|
class FetcherError extends ErrorWithCause {
|
310
545
|
constructor(status, data, requestId) {
|
311
546
|
super(getMessage(data));
|
547
|
+
__publicField$7(this, "status");
|
548
|
+
__publicField$7(this, "requestId");
|
549
|
+
__publicField$7(this, "errors");
|
312
550
|
this.status = status;
|
313
551
|
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
314
552
|
this.requestId = requestId;
|
@@ -375,6 +613,15 @@ function hostHeader(url) {
|
|
375
613
|
const { groups } = pattern.exec(url) ?? {};
|
376
614
|
return groups?.host ? { Host: groups.host } : {};
|
377
615
|
}
|
616
|
+
function parseBody(body, headers) {
|
617
|
+
if (!isDefined(body))
|
618
|
+
return void 0;
|
619
|
+
const { "Content-Type": contentType } = headers ?? {};
|
620
|
+
if (String(contentType).toLowerCase() === "application/json") {
|
621
|
+
return JSON.stringify(body);
|
622
|
+
}
|
623
|
+
return body;
|
624
|
+
}
|
378
625
|
const defaultClientID = generateUUID();
|
379
626
|
async function fetch$1({
|
380
627
|
url: path,
|
@@ -383,7 +630,7 @@ async function fetch$1({
|
|
383
630
|
headers: customHeaders,
|
384
631
|
pathParams,
|
385
632
|
queryParams,
|
386
|
-
|
633
|
+
fetch: fetch2,
|
387
634
|
apiKey,
|
388
635
|
endpoint,
|
389
636
|
apiUrl,
|
@@ -394,9 +641,10 @@ async function fetch$1({
|
|
394
641
|
sessionID,
|
395
642
|
clientName,
|
396
643
|
xataAgentExtra,
|
397
|
-
fetchOptions = {}
|
644
|
+
fetchOptions = {},
|
645
|
+
rawResponse = false
|
398
646
|
}) {
|
399
|
-
pool.setFetch(
|
647
|
+
pool.setFetch(fetch2);
|
400
648
|
return await trace(
|
401
649
|
`${method.toUpperCase()} ${path}`,
|
402
650
|
async ({ setAttributes }) => {
|
@@ -413,7 +661,7 @@ async function fetch$1({
|
|
413
661
|
isDefined(clientName) ? ["service", clientName] : void 0,
|
414
662
|
...Object.entries(xataAgentExtra ?? {})
|
415
663
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
416
|
-
const headers = {
|
664
|
+
const headers = compactObject({
|
417
665
|
"Accept-Encoding": "identity",
|
418
666
|
"Content-Type": "application/json",
|
419
667
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
@@ -422,11 +670,11 @@ async function fetch$1({
|
|
422
670
|
...customHeaders,
|
423
671
|
...hostHeader(fullUrl),
|
424
672
|
Authorization: `Bearer ${apiKey}`
|
425
|
-
};
|
673
|
+
});
|
426
674
|
const response = await pool.request(url, {
|
427
675
|
...fetchOptions,
|
428
676
|
method: method.toUpperCase(),
|
429
|
-
body: body
|
677
|
+
body: parseBody(body, headers),
|
430
678
|
headers,
|
431
679
|
signal
|
432
680
|
});
|
@@ -439,6 +687,9 @@ async function fetch$1({
|
|
439
687
|
[TraceAttributes.HTTP_HOST]: host,
|
440
688
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
441
689
|
});
|
690
|
+
const message = response.headers?.get("x-xata-message");
|
691
|
+
if (message)
|
692
|
+
console.warn(message);
|
442
693
|
if (response.status === 204) {
|
443
694
|
return {};
|
444
695
|
}
|
@@ -446,7 +697,7 @@ async function fetch$1({
|
|
446
697
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
447
698
|
}
|
448
699
|
try {
|
449
|
-
const jsonResponse = await response.json();
|
700
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
450
701
|
if (response.ok) {
|
451
702
|
return jsonResponse;
|
452
703
|
}
|
@@ -458,6 +709,59 @@ async function fetch$1({
|
|
458
709
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
459
710
|
);
|
460
711
|
}
|
712
|
+
function fetchSSERequest({
|
713
|
+
url: path,
|
714
|
+
method,
|
715
|
+
body,
|
716
|
+
headers: customHeaders,
|
717
|
+
pathParams,
|
718
|
+
queryParams,
|
719
|
+
fetch: fetch2,
|
720
|
+
apiKey,
|
721
|
+
endpoint,
|
722
|
+
apiUrl,
|
723
|
+
workspacesApiUrl,
|
724
|
+
onMessage,
|
725
|
+
onError,
|
726
|
+
onClose,
|
727
|
+
signal,
|
728
|
+
clientID,
|
729
|
+
sessionID,
|
730
|
+
clientName,
|
731
|
+
xataAgentExtra
|
732
|
+
}) {
|
733
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
734
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
735
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
736
|
+
void fetchEventSource(url, {
|
737
|
+
method,
|
738
|
+
body: JSON.stringify(body),
|
739
|
+
fetch: fetch2,
|
740
|
+
signal,
|
741
|
+
headers: {
|
742
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
743
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
744
|
+
"X-Xata-Agent": compact([
|
745
|
+
["client", "TS_SDK"],
|
746
|
+
["version", VERSION],
|
747
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
748
|
+
...Object.entries(xataAgentExtra ?? {})
|
749
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
750
|
+
...customHeaders,
|
751
|
+
Authorization: `Bearer ${apiKey}`,
|
752
|
+
"Content-Type": "application/json"
|
753
|
+
},
|
754
|
+
onmessage(ev) {
|
755
|
+
onMessage?.(JSON.parse(ev.data));
|
756
|
+
},
|
757
|
+
onerror(ev) {
|
758
|
+
onError?.(JSON.parse(ev.data));
|
759
|
+
},
|
760
|
+
onclose() {
|
761
|
+
onClose?.();
|
762
|
+
}
|
763
|
+
});
|
764
|
+
}
|
461
765
|
function parseUrl(url) {
|
462
766
|
try {
|
463
767
|
const { host, protocol } = new URL(url);
|
@@ -488,6 +792,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
488
792
|
...variables,
|
489
793
|
signal
|
490
794
|
});
|
795
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
796
|
+
url: "/db/{dbBranchName}/copy",
|
797
|
+
method: "post",
|
798
|
+
...variables,
|
799
|
+
signal
|
800
|
+
});
|
491
801
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
492
802
|
url: "/db/{dbBranchName}/metadata",
|
493
803
|
method: "put",
|
@@ -537,6 +847,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
537
847
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
538
848
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
539
849
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
850
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
540
851
|
const createTable = (variables, signal) => dataPlaneFetch({
|
541
852
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
542
853
|
method: "put",
|
@@ -581,6 +892,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
581
892
|
});
|
582
893
|
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
583
894
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
895
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
896
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
897
|
+
method: "get",
|
898
|
+
...variables,
|
899
|
+
signal
|
900
|
+
});
|
901
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
902
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
903
|
+
method: "put",
|
904
|
+
...variables,
|
905
|
+
signal
|
906
|
+
});
|
907
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
908
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
909
|
+
method: "delete",
|
910
|
+
...variables,
|
911
|
+
signal
|
912
|
+
});
|
913
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
914
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
915
|
+
method: "get",
|
916
|
+
...variables,
|
917
|
+
signal
|
918
|
+
});
|
919
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
920
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
921
|
+
method: "put",
|
922
|
+
...variables,
|
923
|
+
signal
|
924
|
+
});
|
925
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
926
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
927
|
+
method: "delete",
|
928
|
+
...variables,
|
929
|
+
signal
|
930
|
+
});
|
584
931
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
585
932
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
586
933
|
method: "get",
|
@@ -611,14 +958,34 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
611
958
|
signal
|
612
959
|
});
|
613
960
|
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
961
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
962
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
963
|
+
method: "post",
|
964
|
+
...variables,
|
965
|
+
signal
|
966
|
+
});
|
967
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
614
968
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
615
969
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
970
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
971
|
+
url: "/file/{fileId}",
|
972
|
+
method: "get",
|
973
|
+
...variables,
|
974
|
+
signal
|
975
|
+
});
|
976
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
977
|
+
url: "/db/{dbBranchName}/sql",
|
978
|
+
method: "post",
|
979
|
+
...variables,
|
980
|
+
signal
|
981
|
+
});
|
616
982
|
const operationsByTag$2 = {
|
617
983
|
branch: {
|
618
984
|
getBranchList,
|
619
985
|
getBranchDetails,
|
620
986
|
createBranch,
|
621
987
|
deleteBranch,
|
988
|
+
copyBranch,
|
622
989
|
updateBranchMetadata,
|
623
990
|
getBranchMetadata,
|
624
991
|
getBranchStats,
|
@@ -636,7 +1003,8 @@ const operationsByTag$2 = {
|
|
636
1003
|
compareBranchSchemas,
|
637
1004
|
updateBranchSchema,
|
638
1005
|
previewBranchSchemaEdit,
|
639
|
-
applyBranchSchemaEdit
|
1006
|
+
applyBranchSchemaEdit,
|
1007
|
+
pushBranchMigrations
|
640
1008
|
},
|
641
1009
|
migrationRequests: {
|
642
1010
|
queryMigrationRequests,
|
@@ -670,11 +1038,24 @@ const operationsByTag$2 = {
|
|
670
1038
|
deleteRecord,
|
671
1039
|
bulkInsertTableRecords
|
672
1040
|
},
|
673
|
-
|
1041
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1042
|
+
searchAndFilter: {
|
1043
|
+
queryTable,
|
1044
|
+
searchBranch,
|
1045
|
+
searchTable,
|
1046
|
+
vectorSearchTable,
|
1047
|
+
askTable,
|
1048
|
+
askTableSession,
|
1049
|
+
summarizeTable,
|
1050
|
+
aggregateTable
|
1051
|
+
},
|
1052
|
+
sql: { sqlQuery }
|
674
1053
|
};
|
675
1054
|
|
676
1055
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
677
1056
|
|
1057
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1058
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
678
1059
|
const getUser = (variables, signal) => controlPlaneFetch({
|
679
1060
|
url: "/user",
|
680
1061
|
method: "get",
|
@@ -711,6 +1092,25 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
711
1092
|
...variables,
|
712
1093
|
signal
|
713
1094
|
});
|
1095
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1096
|
+
url: "/user/oauth/clients",
|
1097
|
+
method: "get",
|
1098
|
+
...variables,
|
1099
|
+
signal
|
1100
|
+
});
|
1101
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1102
|
+
url: "/user/oauth/tokens",
|
1103
|
+
method: "get",
|
1104
|
+
...variables,
|
1105
|
+
signal
|
1106
|
+
});
|
1107
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1108
|
+
url: "/user/oauth/tokens/{token}",
|
1109
|
+
method: "delete",
|
1110
|
+
...variables,
|
1111
|
+
signal
|
1112
|
+
});
|
1113
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
714
1114
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
715
1115
|
url: "/workspaces",
|
716
1116
|
method: "get",
|
@@ -769,6 +1169,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
769
1169
|
});
|
770
1170
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
771
1171
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1172
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
772
1173
|
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
773
1174
|
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
774
1175
|
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
@@ -779,8 +1180,9 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
779
1180
|
signal
|
780
1181
|
});
|
781
1182
|
const operationsByTag$1 = {
|
1183
|
+
authOther: { getAuthorizationCode, grantAuthorizationCode, deleteOAuthAccessToken, updateOAuthAccessToken },
|
782
1184
|
users: { getUser, updateUser, deleteUser },
|
783
|
-
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1185
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey, getUserOAuthClients, getUserOAuthAccessTokens },
|
784
1186
|
workspaces: {
|
785
1187
|
getWorkspacesList,
|
786
1188
|
createWorkspace,
|
@@ -804,6 +1206,7 @@ const operationsByTag$1 = {
|
|
804
1206
|
deleteDatabase,
|
805
1207
|
getDatabaseMetadata,
|
806
1208
|
updateDatabaseMetadata,
|
1209
|
+
renameDatabase,
|
807
1210
|
getDatabaseGithubSettings,
|
808
1211
|
updateDatabaseGithubSettings,
|
809
1212
|
deleteDatabaseGithubSettings,
|
@@ -829,6 +1232,10 @@ const providers = {
|
|
829
1232
|
staging: {
|
830
1233
|
main: "https://api.staging-xata.dev",
|
831
1234
|
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1235
|
+
},
|
1236
|
+
dev: {
|
1237
|
+
main: "https://api.dev-xata.dev",
|
1238
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
832
1239
|
}
|
833
1240
|
};
|
834
1241
|
function isHostProviderAlias(alias) {
|
@@ -846,6 +1253,11 @@ function parseProviderString(provider = "production") {
|
|
846
1253
|
return null;
|
847
1254
|
return { main, workspaces };
|
848
1255
|
}
|
1256
|
+
function buildProviderString(provider) {
|
1257
|
+
if (isHostProviderAlias(provider))
|
1258
|
+
return provider;
|
1259
|
+
return `${provider.main},${provider.workspaces}`;
|
1260
|
+
}
|
849
1261
|
function parseWorkspacesUrlParts(url) {
|
850
1262
|
if (!isString(url))
|
851
1263
|
return null;
|
@@ -892,7 +1304,7 @@ class XataApiClient {
|
|
892
1304
|
__privateSet$7(this, _extraProps, {
|
893
1305
|
apiUrl: getHostUrl(provider, "main"),
|
894
1306
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
895
|
-
|
1307
|
+
fetch: getFetchImplementation(options.fetch),
|
896
1308
|
apiKey,
|
897
1309
|
trace,
|
898
1310
|
clientName: options.clientName,
|
@@ -950,6 +1362,11 @@ class XataApiClient {
|
|
950
1362
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
951
1363
|
return __privateGet$7(this, _namespaces).records;
|
952
1364
|
}
|
1365
|
+
get files() {
|
1366
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1367
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1368
|
+
return __privateGet$7(this, _namespaces).files;
|
1369
|
+
}
|
953
1370
|
get searchAndFilter() {
|
954
1371
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
955
1372
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1158,6 +1575,20 @@ class BranchApi {
|
|
1158
1575
|
...this.extraProps
|
1159
1576
|
});
|
1160
1577
|
}
|
1578
|
+
copyBranch({
|
1579
|
+
workspace,
|
1580
|
+
region,
|
1581
|
+
database,
|
1582
|
+
branch,
|
1583
|
+
destinationBranch,
|
1584
|
+
limit
|
1585
|
+
}) {
|
1586
|
+
return operationsByTag.branch.copyBranch({
|
1587
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1588
|
+
body: { destinationBranch, limit },
|
1589
|
+
...this.extraProps
|
1590
|
+
});
|
1591
|
+
}
|
1161
1592
|
updateBranchMetadata({
|
1162
1593
|
workspace,
|
1163
1594
|
region,
|
@@ -1513,6 +1944,164 @@ class RecordsApi {
|
|
1513
1944
|
});
|
1514
1945
|
}
|
1515
1946
|
}
|
1947
|
+
class FilesApi {
|
1948
|
+
constructor(extraProps) {
|
1949
|
+
this.extraProps = extraProps;
|
1950
|
+
}
|
1951
|
+
getFileItem({
|
1952
|
+
workspace,
|
1953
|
+
region,
|
1954
|
+
database,
|
1955
|
+
branch,
|
1956
|
+
table,
|
1957
|
+
record,
|
1958
|
+
column,
|
1959
|
+
fileId
|
1960
|
+
}) {
|
1961
|
+
return operationsByTag.files.getFileItem({
|
1962
|
+
pathParams: {
|
1963
|
+
workspace,
|
1964
|
+
region,
|
1965
|
+
dbBranchName: `${database}:${branch}`,
|
1966
|
+
tableName: table,
|
1967
|
+
recordId: record,
|
1968
|
+
columnName: column,
|
1969
|
+
fileId
|
1970
|
+
},
|
1971
|
+
...this.extraProps
|
1972
|
+
});
|
1973
|
+
}
|
1974
|
+
putFileItem({
|
1975
|
+
workspace,
|
1976
|
+
region,
|
1977
|
+
database,
|
1978
|
+
branch,
|
1979
|
+
table,
|
1980
|
+
record,
|
1981
|
+
column,
|
1982
|
+
fileId,
|
1983
|
+
file
|
1984
|
+
}) {
|
1985
|
+
return operationsByTag.files.putFileItem({
|
1986
|
+
pathParams: {
|
1987
|
+
workspace,
|
1988
|
+
region,
|
1989
|
+
dbBranchName: `${database}:${branch}`,
|
1990
|
+
tableName: table,
|
1991
|
+
recordId: record,
|
1992
|
+
columnName: column,
|
1993
|
+
fileId
|
1994
|
+
},
|
1995
|
+
// @ts-ignore
|
1996
|
+
body: file,
|
1997
|
+
...this.extraProps
|
1998
|
+
});
|
1999
|
+
}
|
2000
|
+
deleteFileItem({
|
2001
|
+
workspace,
|
2002
|
+
region,
|
2003
|
+
database,
|
2004
|
+
branch,
|
2005
|
+
table,
|
2006
|
+
record,
|
2007
|
+
column,
|
2008
|
+
fileId
|
2009
|
+
}) {
|
2010
|
+
return operationsByTag.files.deleteFileItem({
|
2011
|
+
pathParams: {
|
2012
|
+
workspace,
|
2013
|
+
region,
|
2014
|
+
dbBranchName: `${database}:${branch}`,
|
2015
|
+
tableName: table,
|
2016
|
+
recordId: record,
|
2017
|
+
columnName: column,
|
2018
|
+
fileId
|
2019
|
+
},
|
2020
|
+
...this.extraProps
|
2021
|
+
});
|
2022
|
+
}
|
2023
|
+
getFile({
|
2024
|
+
workspace,
|
2025
|
+
region,
|
2026
|
+
database,
|
2027
|
+
branch,
|
2028
|
+
table,
|
2029
|
+
record,
|
2030
|
+
column
|
2031
|
+
}) {
|
2032
|
+
return operationsByTag.files.getFile({
|
2033
|
+
pathParams: {
|
2034
|
+
workspace,
|
2035
|
+
region,
|
2036
|
+
dbBranchName: `${database}:${branch}`,
|
2037
|
+
tableName: table,
|
2038
|
+
recordId: record,
|
2039
|
+
columnName: column
|
2040
|
+
},
|
2041
|
+
...this.extraProps
|
2042
|
+
});
|
2043
|
+
}
|
2044
|
+
putFile({
|
2045
|
+
workspace,
|
2046
|
+
region,
|
2047
|
+
database,
|
2048
|
+
branch,
|
2049
|
+
table,
|
2050
|
+
record,
|
2051
|
+
column,
|
2052
|
+
file
|
2053
|
+
}) {
|
2054
|
+
return operationsByTag.files.putFile({
|
2055
|
+
pathParams: {
|
2056
|
+
workspace,
|
2057
|
+
region,
|
2058
|
+
dbBranchName: `${database}:${branch}`,
|
2059
|
+
tableName: table,
|
2060
|
+
recordId: record,
|
2061
|
+
columnName: column
|
2062
|
+
},
|
2063
|
+
body: file,
|
2064
|
+
...this.extraProps
|
2065
|
+
});
|
2066
|
+
}
|
2067
|
+
deleteFile({
|
2068
|
+
workspace,
|
2069
|
+
region,
|
2070
|
+
database,
|
2071
|
+
branch,
|
2072
|
+
table,
|
2073
|
+
record,
|
2074
|
+
column
|
2075
|
+
}) {
|
2076
|
+
return operationsByTag.files.deleteFile({
|
2077
|
+
pathParams: {
|
2078
|
+
workspace,
|
2079
|
+
region,
|
2080
|
+
dbBranchName: `${database}:${branch}`,
|
2081
|
+
tableName: table,
|
2082
|
+
recordId: record,
|
2083
|
+
columnName: column
|
2084
|
+
},
|
2085
|
+
...this.extraProps
|
2086
|
+
});
|
2087
|
+
}
|
2088
|
+
fileAccess({
|
2089
|
+
workspace,
|
2090
|
+
region,
|
2091
|
+
fileId,
|
2092
|
+
verify
|
2093
|
+
}) {
|
2094
|
+
return operationsByTag.files.fileAccess({
|
2095
|
+
pathParams: {
|
2096
|
+
workspace,
|
2097
|
+
region,
|
2098
|
+
fileId
|
2099
|
+
},
|
2100
|
+
queryParams: { verify },
|
2101
|
+
...this.extraProps
|
2102
|
+
});
|
2103
|
+
}
|
2104
|
+
}
|
1516
2105
|
class SearchAndFilterApi {
|
1517
2106
|
constructor(extraProps) {
|
1518
2107
|
this.extraProps = extraProps;
|
@@ -1572,6 +2161,53 @@ class SearchAndFilterApi {
|
|
1572
2161
|
...this.extraProps
|
1573
2162
|
});
|
1574
2163
|
}
|
2164
|
+
vectorSearchTable({
|
2165
|
+
workspace,
|
2166
|
+
region,
|
2167
|
+
database,
|
2168
|
+
branch,
|
2169
|
+
table,
|
2170
|
+
queryVector,
|
2171
|
+
column,
|
2172
|
+
similarityFunction,
|
2173
|
+
size,
|
2174
|
+
filter
|
2175
|
+
}) {
|
2176
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2177
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2178
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2179
|
+
...this.extraProps
|
2180
|
+
});
|
2181
|
+
}
|
2182
|
+
askTable({
|
2183
|
+
workspace,
|
2184
|
+
region,
|
2185
|
+
database,
|
2186
|
+
branch,
|
2187
|
+
table,
|
2188
|
+
options
|
2189
|
+
}) {
|
2190
|
+
return operationsByTag.searchAndFilter.askTable({
|
2191
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2192
|
+
body: { ...options },
|
2193
|
+
...this.extraProps
|
2194
|
+
});
|
2195
|
+
}
|
2196
|
+
askTableSession({
|
2197
|
+
workspace,
|
2198
|
+
region,
|
2199
|
+
database,
|
2200
|
+
branch,
|
2201
|
+
table,
|
2202
|
+
sessionId,
|
2203
|
+
message
|
2204
|
+
}) {
|
2205
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2206
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2207
|
+
body: { message },
|
2208
|
+
...this.extraProps
|
2209
|
+
});
|
2210
|
+
}
|
1575
2211
|
summarizeTable({
|
1576
2212
|
workspace,
|
1577
2213
|
region,
|
@@ -1836,6 +2472,19 @@ class MigrationsApi {
|
|
1836
2472
|
...this.extraProps
|
1837
2473
|
});
|
1838
2474
|
}
|
2475
|
+
pushBranchMigrations({
|
2476
|
+
workspace,
|
2477
|
+
region,
|
2478
|
+
database,
|
2479
|
+
branch,
|
2480
|
+
migrations
|
2481
|
+
}) {
|
2482
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2483
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2484
|
+
body: { migrations },
|
2485
|
+
...this.extraProps
|
2486
|
+
});
|
2487
|
+
}
|
1839
2488
|
}
|
1840
2489
|
class DatabaseApi {
|
1841
2490
|
constructor(extraProps) {
|
@@ -1850,11 +2499,13 @@ class DatabaseApi {
|
|
1850
2499
|
createDatabase({
|
1851
2500
|
workspace,
|
1852
2501
|
database,
|
1853
|
-
data
|
2502
|
+
data,
|
2503
|
+
headers
|
1854
2504
|
}) {
|
1855
2505
|
return operationsByTag.databases.createDatabase({
|
1856
2506
|
pathParams: { workspaceId: workspace, dbName: database },
|
1857
2507
|
body: data,
|
2508
|
+
headers,
|
1858
2509
|
...this.extraProps
|
1859
2510
|
});
|
1860
2511
|
}
|
@@ -1887,6 +2538,17 @@ class DatabaseApi {
|
|
1887
2538
|
...this.extraProps
|
1888
2539
|
});
|
1889
2540
|
}
|
2541
|
+
renameDatabase({
|
2542
|
+
workspace,
|
2543
|
+
database,
|
2544
|
+
newName
|
2545
|
+
}) {
|
2546
|
+
return operationsByTag.databases.renameDatabase({
|
2547
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2548
|
+
body: { newName },
|
2549
|
+
...this.extraProps
|
2550
|
+
});
|
2551
|
+
}
|
1890
2552
|
getDatabaseGithubSettings({
|
1891
2553
|
workspace,
|
1892
2554
|
database
|
@@ -1925,22 +2587,269 @@ class DatabaseApi {
|
|
1925
2587
|
}
|
1926
2588
|
|
1927
2589
|
class XataApiPlugin {
|
1928
|
-
|
1929
|
-
|
1930
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2590
|
+
build(options) {
|
2591
|
+
return new XataApiClient(options);
|
1931
2592
|
}
|
1932
2593
|
}
|
1933
2594
|
|
1934
2595
|
class XataPlugin {
|
1935
2596
|
}
|
1936
2597
|
|
2598
|
+
class FilesPlugin extends XataPlugin {
|
2599
|
+
build(pluginOptions) {
|
2600
|
+
return {
|
2601
|
+
download: async (location) => {
|
2602
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2603
|
+
return await getFileItem({
|
2604
|
+
pathParams: {
|
2605
|
+
workspace: "{workspaceId}",
|
2606
|
+
dbBranchName: "{dbBranch}",
|
2607
|
+
region: "{region}",
|
2608
|
+
tableName: table ?? "",
|
2609
|
+
recordId: record ?? "",
|
2610
|
+
columnName: column ?? "",
|
2611
|
+
fileId
|
2612
|
+
},
|
2613
|
+
...pluginOptions,
|
2614
|
+
rawResponse: true
|
2615
|
+
});
|
2616
|
+
},
|
2617
|
+
upload: async (location, file) => {
|
2618
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2619
|
+
return await putFileItem({
|
2620
|
+
pathParams: {
|
2621
|
+
workspace: "{workspaceId}",
|
2622
|
+
dbBranchName: "{dbBranch}",
|
2623
|
+
region: "{region}",
|
2624
|
+
tableName: table ?? "",
|
2625
|
+
recordId: record ?? "",
|
2626
|
+
columnName: column ?? "",
|
2627
|
+
fileId
|
2628
|
+
},
|
2629
|
+
body: file,
|
2630
|
+
...pluginOptions
|
2631
|
+
});
|
2632
|
+
},
|
2633
|
+
delete: async (location) => {
|
2634
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2635
|
+
return await deleteFileItem({
|
2636
|
+
pathParams: {
|
2637
|
+
workspace: "{workspaceId}",
|
2638
|
+
dbBranchName: "{dbBranch}",
|
2639
|
+
region: "{region}",
|
2640
|
+
tableName: table ?? "",
|
2641
|
+
recordId: record ?? "",
|
2642
|
+
columnName: column ?? "",
|
2643
|
+
fileId
|
2644
|
+
},
|
2645
|
+
...pluginOptions
|
2646
|
+
});
|
2647
|
+
}
|
2648
|
+
};
|
2649
|
+
}
|
2650
|
+
}
|
2651
|
+
|
2652
|
+
function buildTransformString(transformations) {
|
2653
|
+
return transformations.flatMap(
|
2654
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2655
|
+
if (key === "trim") {
|
2656
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2657
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2658
|
+
}
|
2659
|
+
if (key === "gravity" && typeof value === "object") {
|
2660
|
+
const { x = 0.5, y = 0.5 } = value;
|
2661
|
+
return `${key}=${[x, y].join("x")}`;
|
2662
|
+
}
|
2663
|
+
return `${key}=${value}`;
|
2664
|
+
})
|
2665
|
+
).join(",");
|
2666
|
+
}
|
2667
|
+
function transformImage(url, transformations) {
|
2668
|
+
if (!isDefined(url))
|
2669
|
+
return void 0;
|
2670
|
+
const transformationsString = buildTransformString(transformations);
|
2671
|
+
const { hostname, pathname, search } = new URL(url);
|
2672
|
+
return `https://${hostname}/transform/${transformationsString}${pathname}${search}`;
|
2673
|
+
}
|
2674
|
+
|
2675
|
+
var __defProp$6 = Object.defineProperty;
|
2676
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2677
|
+
var __publicField$6 = (obj, key, value) => {
|
2678
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2679
|
+
return value;
|
2680
|
+
};
|
2681
|
+
class XataFile {
|
2682
|
+
constructor(file) {
|
2683
|
+
/**
|
2684
|
+
* Name of this file.
|
2685
|
+
*/
|
2686
|
+
__publicField$6(this, "name");
|
2687
|
+
/**
|
2688
|
+
* Media type of this file.
|
2689
|
+
*/
|
2690
|
+
__publicField$6(this, "mediaType");
|
2691
|
+
/**
|
2692
|
+
* Base64 encoded content of this file.
|
2693
|
+
*/
|
2694
|
+
__publicField$6(this, "base64Content");
|
2695
|
+
/**
|
2696
|
+
* Whether to enable public url for this file.
|
2697
|
+
*/
|
2698
|
+
__publicField$6(this, "enablePublicUrl");
|
2699
|
+
/**
|
2700
|
+
* Timeout for the signed url.
|
2701
|
+
*/
|
2702
|
+
__publicField$6(this, "signedUrlTimeout");
|
2703
|
+
/**
|
2704
|
+
* Size of this file.
|
2705
|
+
*/
|
2706
|
+
__publicField$6(this, "size");
|
2707
|
+
/**
|
2708
|
+
* Version of this file.
|
2709
|
+
*/
|
2710
|
+
__publicField$6(this, "version");
|
2711
|
+
/**
|
2712
|
+
* Url of this file.
|
2713
|
+
*/
|
2714
|
+
__publicField$6(this, "url");
|
2715
|
+
/**
|
2716
|
+
* Signed url of this file.
|
2717
|
+
*/
|
2718
|
+
__publicField$6(this, "signedUrl");
|
2719
|
+
/**
|
2720
|
+
* Attributes of this file.
|
2721
|
+
*/
|
2722
|
+
__publicField$6(this, "attributes");
|
2723
|
+
this.name = file.name;
|
2724
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2725
|
+
this.base64Content = file.base64Content;
|
2726
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2727
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2728
|
+
this.size = file.size;
|
2729
|
+
this.version = file.version;
|
2730
|
+
this.url = file.url;
|
2731
|
+
this.signedUrl = file.signedUrl;
|
2732
|
+
this.attributes = file.attributes;
|
2733
|
+
}
|
2734
|
+
static fromBuffer(buffer, options = {}) {
|
2735
|
+
const base64Content = buffer.toString("base64");
|
2736
|
+
return new XataFile({ ...options, base64Content });
|
2737
|
+
}
|
2738
|
+
toBuffer() {
|
2739
|
+
if (!this.base64Content) {
|
2740
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2741
|
+
}
|
2742
|
+
return Buffer.from(this.base64Content, "base64");
|
2743
|
+
}
|
2744
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2745
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2746
|
+
return this.fromUint8Array(uint8Array, options);
|
2747
|
+
}
|
2748
|
+
toArrayBuffer() {
|
2749
|
+
if (!this.base64Content) {
|
2750
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2751
|
+
}
|
2752
|
+
const binary = atob(this.base64Content);
|
2753
|
+
return new ArrayBuffer(binary.length);
|
2754
|
+
}
|
2755
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2756
|
+
let binary = "";
|
2757
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2758
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2759
|
+
}
|
2760
|
+
const base64Content = btoa(binary);
|
2761
|
+
return new XataFile({ ...options, base64Content });
|
2762
|
+
}
|
2763
|
+
toUint8Array() {
|
2764
|
+
if (!this.base64Content) {
|
2765
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2766
|
+
}
|
2767
|
+
const binary = atob(this.base64Content);
|
2768
|
+
const uint8Array = new Uint8Array(binary.length);
|
2769
|
+
for (let i = 0; i < binary.length; i++) {
|
2770
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2771
|
+
}
|
2772
|
+
return uint8Array;
|
2773
|
+
}
|
2774
|
+
static async fromBlob(file, options = {}) {
|
2775
|
+
const name = options.name ?? file.name;
|
2776
|
+
const mediaType = file.type;
|
2777
|
+
const arrayBuffer = await file.arrayBuffer();
|
2778
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2779
|
+
}
|
2780
|
+
toBlob() {
|
2781
|
+
if (!this.base64Content) {
|
2782
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2783
|
+
}
|
2784
|
+
const arrayBuffer = this.toArrayBuffer();
|
2785
|
+
return new Blob([arrayBuffer], { type: this.mediaType });
|
2786
|
+
}
|
2787
|
+
static fromString(string, options = {}) {
|
2788
|
+
const base64Content = btoa(string);
|
2789
|
+
return new XataFile({ ...options, base64Content });
|
2790
|
+
}
|
2791
|
+
toString() {
|
2792
|
+
if (!this.base64Content) {
|
2793
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2794
|
+
}
|
2795
|
+
return atob(this.base64Content);
|
2796
|
+
}
|
2797
|
+
static fromBase64(base64Content, options = {}) {
|
2798
|
+
return new XataFile({ ...options, base64Content });
|
2799
|
+
}
|
2800
|
+
toBase64() {
|
2801
|
+
if (!this.base64Content) {
|
2802
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2803
|
+
}
|
2804
|
+
return this.base64Content;
|
2805
|
+
}
|
2806
|
+
transform(...options) {
|
2807
|
+
return {
|
2808
|
+
url: transformImage(this.url, options),
|
2809
|
+
signedUrl: transformImage(this.signedUrl, options)
|
2810
|
+
};
|
2811
|
+
}
|
2812
|
+
}
|
2813
|
+
const parseInputFileEntry = async (entry) => {
|
2814
|
+
if (!isDefined(entry))
|
2815
|
+
return null;
|
2816
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2817
|
+
return compactObject({ id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout });
|
2818
|
+
};
|
2819
|
+
|
1937
2820
|
function cleanFilter(filter) {
|
1938
|
-
if (!filter)
|
2821
|
+
if (!isDefined(filter))
|
1939
2822
|
return void 0;
|
1940
|
-
|
1941
|
-
|
2823
|
+
if (!isObject(filter))
|
2824
|
+
return filter;
|
2825
|
+
const values = Object.fromEntries(
|
2826
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2827
|
+
if (!isDefined(value))
|
2828
|
+
return acc;
|
2829
|
+
if (Array.isArray(value)) {
|
2830
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2831
|
+
if (clean.length === 0)
|
2832
|
+
return acc;
|
2833
|
+
return [...acc, [key, clean]];
|
2834
|
+
}
|
2835
|
+
if (isObject(value)) {
|
2836
|
+
const clean = cleanFilter(value);
|
2837
|
+
if (!isDefined(clean))
|
2838
|
+
return acc;
|
2839
|
+
return [...acc, [key, clean]];
|
2840
|
+
}
|
2841
|
+
return [...acc, [key, value]];
|
2842
|
+
}, [])
|
2843
|
+
);
|
2844
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
1942
2845
|
}
|
1943
2846
|
|
2847
|
+
var __defProp$5 = Object.defineProperty;
|
2848
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2849
|
+
var __publicField$5 = (obj, key, value) => {
|
2850
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2851
|
+
return value;
|
2852
|
+
};
|
1944
2853
|
var __accessCheck$6 = (obj, member, msg) => {
|
1945
2854
|
if (!member.has(obj))
|
1946
2855
|
throw TypeError("Cannot " + msg);
|
@@ -1963,22 +2872,58 @@ var _query, _page;
|
|
1963
2872
|
class Page {
|
1964
2873
|
constructor(query, meta, records = []) {
|
1965
2874
|
__privateAdd$6(this, _query, void 0);
|
2875
|
+
/**
|
2876
|
+
* Page metadata, required to retrieve additional records.
|
2877
|
+
*/
|
2878
|
+
__publicField$5(this, "meta");
|
2879
|
+
/**
|
2880
|
+
* The set of results for this page.
|
2881
|
+
*/
|
2882
|
+
__publicField$5(this, "records");
|
1966
2883
|
__privateSet$6(this, _query, query);
|
1967
2884
|
this.meta = meta;
|
1968
2885
|
this.records = new RecordArray(this, records);
|
1969
2886
|
}
|
2887
|
+
/**
|
2888
|
+
* Retrieves the next page of results.
|
2889
|
+
* @param size Maximum number of results to be retrieved.
|
2890
|
+
* @param offset Number of results to skip when retrieving the results.
|
2891
|
+
* @returns The next page or results.
|
2892
|
+
*/
|
1970
2893
|
async nextPage(size, offset) {
|
1971
2894
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1972
2895
|
}
|
2896
|
+
/**
|
2897
|
+
* Retrieves the previous page of results.
|
2898
|
+
* @param size Maximum number of results to be retrieved.
|
2899
|
+
* @param offset Number of results to skip when retrieving the results.
|
2900
|
+
* @returns The previous page or results.
|
2901
|
+
*/
|
1973
2902
|
async previousPage(size, offset) {
|
1974
2903
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1975
2904
|
}
|
2905
|
+
/**
|
2906
|
+
* Retrieves the start page of results.
|
2907
|
+
* @param size Maximum number of results to be retrieved.
|
2908
|
+
* @param offset Number of results to skip when retrieving the results.
|
2909
|
+
* @returns The start page or results.
|
2910
|
+
*/
|
1976
2911
|
async startPage(size, offset) {
|
1977
2912
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1978
2913
|
}
|
2914
|
+
/**
|
2915
|
+
* Retrieves the end page of results.
|
2916
|
+
* @param size Maximum number of results to be retrieved.
|
2917
|
+
* @param offset Number of results to skip when retrieving the results.
|
2918
|
+
* @returns The end page or results.
|
2919
|
+
*/
|
1979
2920
|
async endPage(size, offset) {
|
1980
2921
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1981
2922
|
}
|
2923
|
+
/**
|
2924
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2925
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2926
|
+
*/
|
1982
2927
|
hasNextPage() {
|
1983
2928
|
return this.meta.page.more;
|
1984
2929
|
}
|
@@ -1991,7 +2936,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1991
2936
|
function isCursorPaginationOptions(options) {
|
1992
2937
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1993
2938
|
}
|
1994
|
-
const _RecordArray = class extends Array {
|
2939
|
+
const _RecordArray = class _RecordArray extends Array {
|
1995
2940
|
constructor(...args) {
|
1996
2941
|
super(..._RecordArray.parseConstructorParams(...args));
|
1997
2942
|
__privateAdd$6(this, _page, void 0);
|
@@ -2019,29 +2964,58 @@ const _RecordArray = class extends Array {
|
|
2019
2964
|
map(callbackfn, thisArg) {
|
2020
2965
|
return this.toArray().map(callbackfn, thisArg);
|
2021
2966
|
}
|
2967
|
+
/**
|
2968
|
+
* Retrieve next page of records
|
2969
|
+
*
|
2970
|
+
* @returns A new array of objects
|
2971
|
+
*/
|
2022
2972
|
async nextPage(size, offset) {
|
2023
2973
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
2024
2974
|
return new _RecordArray(newPage);
|
2025
2975
|
}
|
2976
|
+
/**
|
2977
|
+
* Retrieve previous page of records
|
2978
|
+
*
|
2979
|
+
* @returns A new array of objects
|
2980
|
+
*/
|
2026
2981
|
async previousPage(size, offset) {
|
2027
2982
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
2028
2983
|
return new _RecordArray(newPage);
|
2029
2984
|
}
|
2985
|
+
/**
|
2986
|
+
* Retrieve start page of records
|
2987
|
+
*
|
2988
|
+
* @returns A new array of objects
|
2989
|
+
*/
|
2030
2990
|
async startPage(size, offset) {
|
2031
2991
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
2032
2992
|
return new _RecordArray(newPage);
|
2033
2993
|
}
|
2994
|
+
/**
|
2995
|
+
* Retrieve end page of records
|
2996
|
+
*
|
2997
|
+
* @returns A new array of objects
|
2998
|
+
*/
|
2034
2999
|
async endPage(size, offset) {
|
2035
3000
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
2036
3001
|
return new _RecordArray(newPage);
|
2037
3002
|
}
|
3003
|
+
/**
|
3004
|
+
* @returns Boolean indicating if there is a next page
|
3005
|
+
*/
|
2038
3006
|
hasNextPage() {
|
2039
3007
|
return __privateGet$6(this, _page).meta.page.more;
|
2040
3008
|
}
|
2041
3009
|
};
|
2042
|
-
let RecordArray = _RecordArray;
|
2043
3010
|
_page = new WeakMap();
|
3011
|
+
let RecordArray = _RecordArray;
|
2044
3012
|
|
3013
|
+
var __defProp$4 = Object.defineProperty;
|
3014
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3015
|
+
var __publicField$4 = (obj, key, value) => {
|
3016
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3017
|
+
return value;
|
3018
|
+
};
|
2045
3019
|
var __accessCheck$5 = (obj, member, msg) => {
|
2046
3020
|
if (!member.has(obj))
|
2047
3021
|
throw TypeError("Cannot " + msg);
|
@@ -2065,14 +3039,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2065
3039
|
return method;
|
2066
3040
|
};
|
2067
3041
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2068
|
-
const _Query = class {
|
3042
|
+
const _Query = class _Query {
|
2069
3043
|
constructor(repository, table, data, rawParent) {
|
2070
3044
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2071
3045
|
__privateAdd$5(this, _table$1, void 0);
|
2072
3046
|
__privateAdd$5(this, _repository, void 0);
|
2073
3047
|
__privateAdd$5(this, _data, { filter: {} });
|
2074
|
-
|
2075
|
-
this
|
3048
|
+
// Implements pagination
|
3049
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
3050
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
2076
3051
|
__privateSet$5(this, _table$1, table);
|
2077
3052
|
if (repository) {
|
2078
3053
|
__privateSet$5(this, _repository, repository);
|
@@ -2108,18 +3083,38 @@ const _Query = class {
|
|
2108
3083
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2109
3084
|
return toBase64(key);
|
2110
3085
|
}
|
3086
|
+
/**
|
3087
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3088
|
+
* @param queries An array of subqueries.
|
3089
|
+
* @returns A new Query object.
|
3090
|
+
*/
|
2111
3091
|
any(...queries) {
|
2112
3092
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2113
3093
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2114
3094
|
}
|
3095
|
+
/**
|
3096
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3097
|
+
* @param queries An array of subqueries.
|
3098
|
+
* @returns A new Query object.
|
3099
|
+
*/
|
2115
3100
|
all(...queries) {
|
2116
3101
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2117
3102
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2118
3103
|
}
|
3104
|
+
/**
|
3105
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3106
|
+
* @param queries An array of subqueries.
|
3107
|
+
* @returns A new Query object.
|
3108
|
+
*/
|
2119
3109
|
not(...queries) {
|
2120
3110
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2121
3111
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2122
3112
|
}
|
3113
|
+
/**
|
3114
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3115
|
+
* @param queries An array of subqueries.
|
3116
|
+
* @returns A new Query object.
|
3117
|
+
*/
|
2123
3118
|
none(...queries) {
|
2124
3119
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2125
3120
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2142,6 +3137,11 @@ const _Query = class {
|
|
2142
3137
|
const sort = [...originalSort, { column, direction }];
|
2143
3138
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2144
3139
|
}
|
3140
|
+
/**
|
3141
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3142
|
+
* @param columns Array of column names to be returned by the query.
|
3143
|
+
* @returns A new Query object.
|
3144
|
+
*/
|
2145
3145
|
select(columns) {
|
2146
3146
|
return new _Query(
|
2147
3147
|
__privateGet$5(this, _repository),
|
@@ -2154,6 +3154,12 @@ const _Query = class {
|
|
2154
3154
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2155
3155
|
return __privateGet$5(this, _repository).query(query);
|
2156
3156
|
}
|
3157
|
+
/**
|
3158
|
+
* Get results in an iterator
|
3159
|
+
*
|
3160
|
+
* @async
|
3161
|
+
* @returns Async interable of results
|
3162
|
+
*/
|
2157
3163
|
async *[Symbol.asyncIterator]() {
|
2158
3164
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2159
3165
|
yield record;
|
@@ -2214,26 +3220,53 @@ const _Query = class {
|
|
2214
3220
|
);
|
2215
3221
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2216
3222
|
}
|
3223
|
+
/**
|
3224
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3225
|
+
* @param ttl The cache TTL in milliseconds.
|
3226
|
+
* @returns A new Query object.
|
3227
|
+
*/
|
2217
3228
|
cache(ttl) {
|
2218
3229
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2219
3230
|
}
|
3231
|
+
/**
|
3232
|
+
* Retrieve next page of records
|
3233
|
+
*
|
3234
|
+
* @returns A new page object.
|
3235
|
+
*/
|
2220
3236
|
nextPage(size, offset) {
|
2221
3237
|
return this.startPage(size, offset);
|
2222
3238
|
}
|
3239
|
+
/**
|
3240
|
+
* Retrieve previous page of records
|
3241
|
+
*
|
3242
|
+
* @returns A new page object
|
3243
|
+
*/
|
2223
3244
|
previousPage(size, offset) {
|
2224
3245
|
return this.startPage(size, offset);
|
2225
3246
|
}
|
3247
|
+
/**
|
3248
|
+
* Retrieve start page of records
|
3249
|
+
*
|
3250
|
+
* @returns A new page object
|
3251
|
+
*/
|
2226
3252
|
startPage(size, offset) {
|
2227
3253
|
return this.getPaginated({ pagination: { size, offset } });
|
2228
3254
|
}
|
3255
|
+
/**
|
3256
|
+
* Retrieve last page of records
|
3257
|
+
*
|
3258
|
+
* @returns A new page object
|
3259
|
+
*/
|
2229
3260
|
endPage(size, offset) {
|
2230
3261
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2231
3262
|
}
|
3263
|
+
/**
|
3264
|
+
* @returns Boolean indicating if there is a next page
|
3265
|
+
*/
|
2232
3266
|
hasNextPage() {
|
2233
3267
|
return this.meta.page.more;
|
2234
3268
|
}
|
2235
3269
|
};
|
2236
|
-
let Query = _Query;
|
2237
3270
|
_table$1 = new WeakMap();
|
2238
3271
|
_repository = new WeakMap();
|
2239
3272
|
_data = new WeakMap();
|
@@ -2248,6 +3281,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2248
3281
|
}
|
2249
3282
|
return value;
|
2250
3283
|
};
|
3284
|
+
let Query = _Query;
|
2251
3285
|
function cleanParent(data, parent) {
|
2252
3286
|
if (isCursorPaginationOptions(data.pagination)) {
|
2253
3287
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2255,6 +3289,21 @@ function cleanParent(data, parent) {
|
|
2255
3289
|
return parent;
|
2256
3290
|
}
|
2257
3291
|
|
3292
|
+
const RecordColumnTypes = [
|
3293
|
+
"bool",
|
3294
|
+
"int",
|
3295
|
+
"float",
|
3296
|
+
"string",
|
3297
|
+
"text",
|
3298
|
+
"email",
|
3299
|
+
"multiple",
|
3300
|
+
"link",
|
3301
|
+
"object",
|
3302
|
+
"datetime",
|
3303
|
+
"vector",
|
3304
|
+
"file[]",
|
3305
|
+
"file"
|
3306
|
+
];
|
2258
3307
|
function isIdentifiable(x) {
|
2259
3308
|
return isObject(x) && isString(x?.id);
|
2260
3309
|
}
|
@@ -2268,7 +3317,11 @@ function isSortFilterString(value) {
|
|
2268
3317
|
return isString(value);
|
2269
3318
|
}
|
2270
3319
|
function isSortFilterBase(filter) {
|
2271
|
-
return isObject(filter) && Object.
|
3320
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3321
|
+
if (key === "*")
|
3322
|
+
return value === "random";
|
3323
|
+
return value === "asc" || value === "desc";
|
3324
|
+
});
|
2272
3325
|
}
|
2273
3326
|
function isSortFilterObject(filter) {
|
2274
3327
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2309,7 +3362,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2309
3362
|
__accessCheck$4(obj, member, "access private method");
|
2310
3363
|
return method;
|
2311
3364
|
};
|
2312
|
-
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;
|
3365
|
+
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;
|
2313
3366
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2314
3367
|
class Repository extends Query {
|
2315
3368
|
}
|
@@ -2331,6 +3384,7 @@ class RestRepository extends Query {
|
|
2331
3384
|
__privateAdd$4(this, _setCacheQuery);
|
2332
3385
|
__privateAdd$4(this, _getCacheQuery);
|
2333
3386
|
__privateAdd$4(this, _getSchemaTables$1);
|
3387
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2334
3388
|
__privateAdd$4(this, _table, void 0);
|
2335
3389
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2336
3390
|
__privateAdd$4(this, _db, void 0);
|
@@ -2341,10 +3395,7 @@ class RestRepository extends Query {
|
|
2341
3395
|
__privateSet$4(this, _db, options.db);
|
2342
3396
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2343
3397
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2344
|
-
__privateSet$4(this, _getFetchProps,
|
2345
|
-
const props = await options.pluginOptions.getFetchProps();
|
2346
|
-
return { ...props, sessionID: generateUUID() };
|
2347
|
-
});
|
3398
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2348
3399
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2349
3400
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2350
3401
|
return trace(name, fn, {
|
@@ -2401,7 +3452,6 @@ class RestRepository extends Query {
|
|
2401
3452
|
}
|
2402
3453
|
const id = extractId(a);
|
2403
3454
|
if (id) {
|
2404
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2405
3455
|
try {
|
2406
3456
|
const response = await getRecord({
|
2407
3457
|
pathParams: {
|
@@ -2412,7 +3462,7 @@ class RestRepository extends Query {
|
|
2412
3462
|
recordId: id
|
2413
3463
|
},
|
2414
3464
|
queryParams: { columns },
|
2415
|
-
...
|
3465
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2416
3466
|
});
|
2417
3467
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2418
3468
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2512,12 +3562,22 @@ class RestRepository extends Query {
|
|
2512
3562
|
return result;
|
2513
3563
|
}
|
2514
3564
|
if (isString(a) && isObject(b)) {
|
3565
|
+
if (a === "")
|
3566
|
+
throw new Error("The id can't be empty");
|
2515
3567
|
const columns = isStringArray(c) ? c : void 0;
|
2516
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3568
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2517
3569
|
}
|
2518
3570
|
if (isObject(a) && isString(a.id)) {
|
3571
|
+
if (a.id === "")
|
3572
|
+
throw new Error("The id can't be empty");
|
2519
3573
|
const columns = isStringArray(c) ? c : void 0;
|
2520
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3574
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3575
|
+
}
|
3576
|
+
if (!isDefined(a) && isObject(b)) {
|
3577
|
+
return await this.create(b, c);
|
3578
|
+
}
|
3579
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3580
|
+
return await this.create(a, b);
|
2521
3581
|
}
|
2522
3582
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2523
3583
|
});
|
@@ -2534,12 +3594,22 @@ class RestRepository extends Query {
|
|
2534
3594
|
return result;
|
2535
3595
|
}
|
2536
3596
|
if (isString(a) && isObject(b)) {
|
3597
|
+
if (a === "")
|
3598
|
+
throw new Error("The id can't be empty");
|
2537
3599
|
const columns = isStringArray(c) ? c : void 0;
|
2538
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3600
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2539
3601
|
}
|
2540
3602
|
if (isObject(a) && isString(a.id)) {
|
3603
|
+
if (a.id === "")
|
3604
|
+
throw new Error("The id can't be empty");
|
2541
3605
|
const columns = isStringArray(c) ? c : void 0;
|
2542
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3606
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3607
|
+
}
|
3608
|
+
if (!isDefined(a) && isObject(b)) {
|
3609
|
+
return await this.create(b, c);
|
3610
|
+
}
|
3611
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3612
|
+
return await this.create(a, b);
|
2543
3613
|
}
|
2544
3614
|
throw new Error("Invalid arguments for createOrReplace method");
|
2545
3615
|
});
|
@@ -2590,7 +3660,6 @@ class RestRepository extends Query {
|
|
2590
3660
|
}
|
2591
3661
|
async search(query, options = {}) {
|
2592
3662
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2593
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2594
3663
|
const { records } = await searchTable({
|
2595
3664
|
pathParams: {
|
2596
3665
|
workspace: "{workspaceId}",
|
@@ -2608,7 +3677,7 @@ class RestRepository extends Query {
|
|
2608
3677
|
page: options.page,
|
2609
3678
|
target: options.target
|
2610
3679
|
},
|
2611
|
-
...
|
3680
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2612
3681
|
});
|
2613
3682
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2614
3683
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2616,7 +3685,6 @@ class RestRepository extends Query {
|
|
2616
3685
|
}
|
2617
3686
|
async vectorSearch(column, query, options) {
|
2618
3687
|
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
2619
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2620
3688
|
const { records } = await vectorSearchTable({
|
2621
3689
|
pathParams: {
|
2622
3690
|
workspace: "{workspaceId}",
|
@@ -2631,7 +3699,7 @@ class RestRepository extends Query {
|
|
2631
3699
|
size: options?.size,
|
2632
3700
|
filter: options?.filter
|
2633
3701
|
},
|
2634
|
-
...
|
3702
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2635
3703
|
});
|
2636
3704
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2637
3705
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2639,7 +3707,6 @@ class RestRepository extends Query {
|
|
2639
3707
|
}
|
2640
3708
|
async aggregate(aggs, filter) {
|
2641
3709
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2642
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2643
3710
|
const result = await aggregateTable({
|
2644
3711
|
pathParams: {
|
2645
3712
|
workspace: "{workspaceId}",
|
@@ -2648,7 +3715,7 @@ class RestRepository extends Query {
|
|
2648
3715
|
tableName: __privateGet$4(this, _table)
|
2649
3716
|
},
|
2650
3717
|
body: { aggs, filter },
|
2651
|
-
...
|
3718
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2652
3719
|
});
|
2653
3720
|
return result;
|
2654
3721
|
});
|
@@ -2659,7 +3726,6 @@ class RestRepository extends Query {
|
|
2659
3726
|
if (cacheQuery)
|
2660
3727
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2661
3728
|
const data = query.getQueryOptions();
|
2662
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2663
3729
|
const { meta, records: objects } = await queryTable({
|
2664
3730
|
pathParams: {
|
2665
3731
|
workspace: "{workspaceId}",
|
@@ -2675,7 +3741,7 @@ class RestRepository extends Query {
|
|
2675
3741
|
consistency: data.consistency
|
2676
3742
|
},
|
2677
3743
|
fetchOptions: data.fetchOptions,
|
2678
|
-
...
|
3744
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2679
3745
|
});
|
2680
3746
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2681
3747
|
const records = objects.map(
|
@@ -2688,7 +3754,6 @@ class RestRepository extends Query {
|
|
2688
3754
|
async summarizeTable(query, summaries, summariesFilter) {
|
2689
3755
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2690
3756
|
const data = query.getQueryOptions();
|
2691
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2692
3757
|
const result = await summarizeTable({
|
2693
3758
|
pathParams: {
|
2694
3759
|
workspace: "{workspaceId}",
|
@@ -2705,11 +3770,44 @@ class RestRepository extends Query {
|
|
2705
3770
|
summaries,
|
2706
3771
|
summariesFilter
|
2707
3772
|
},
|
2708
|
-
...
|
3773
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2709
3774
|
});
|
2710
3775
|
return result;
|
2711
3776
|
});
|
2712
3777
|
}
|
3778
|
+
ask(question, options) {
|
3779
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3780
|
+
const params = {
|
3781
|
+
pathParams: {
|
3782
|
+
workspace: "{workspaceId}",
|
3783
|
+
dbBranchName: "{dbBranch}",
|
3784
|
+
region: "{region}",
|
3785
|
+
tableName: __privateGet$4(this, _table),
|
3786
|
+
sessionId: options?.sessionId
|
3787
|
+
},
|
3788
|
+
body: {
|
3789
|
+
...questionParam,
|
3790
|
+
rules: options?.rules,
|
3791
|
+
searchType: options?.searchType,
|
3792
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3793
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3794
|
+
},
|
3795
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3796
|
+
};
|
3797
|
+
if (options?.onMessage) {
|
3798
|
+
fetchSSERequest({
|
3799
|
+
endpoint: "dataPlane",
|
3800
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3801
|
+
method: "POST",
|
3802
|
+
onMessage: (message) => {
|
3803
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3804
|
+
},
|
3805
|
+
...params
|
3806
|
+
});
|
3807
|
+
} else {
|
3808
|
+
return askTableSession(params);
|
3809
|
+
}
|
3810
|
+
}
|
2713
3811
|
}
|
2714
3812
|
_table = new WeakMap();
|
2715
3813
|
_getFetchProps = new WeakMap();
|
@@ -2719,8 +3817,7 @@ _schemaTables$2 = new WeakMap();
|
|
2719
3817
|
_trace = new WeakMap();
|
2720
3818
|
_insertRecordWithoutId = new WeakSet();
|
2721
3819
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2722
|
-
const
|
2723
|
-
const record = transformObjectLinks(object);
|
3820
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2724
3821
|
const response = await insertRecord({
|
2725
3822
|
pathParams: {
|
2726
3823
|
workspace: "{workspaceId}",
|
@@ -2730,15 +3827,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2730
3827
|
},
|
2731
3828
|
queryParams: { columns },
|
2732
3829
|
body: record,
|
2733
|
-
...
|
3830
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2734
3831
|
});
|
2735
3832
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2736
3833
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2737
3834
|
};
|
2738
3835
|
_insertRecordWithId = new WeakSet();
|
2739
3836
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2740
|
-
|
2741
|
-
|
3837
|
+
if (!recordId)
|
3838
|
+
return null;
|
3839
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2742
3840
|
const response = await insertRecordWithID({
|
2743
3841
|
pathParams: {
|
2744
3842
|
workspace: "{workspaceId}",
|
@@ -2749,30 +3847,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2749
3847
|
},
|
2750
3848
|
body: record,
|
2751
3849
|
queryParams: { createOnly, columns, ifVersion },
|
2752
|
-
...
|
3850
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2753
3851
|
});
|
2754
3852
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2755
3853
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2756
3854
|
};
|
2757
3855
|
_insertRecords = new WeakSet();
|
2758
3856
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2759
|
-
const
|
2760
|
-
|
2761
|
-
|
2762
|
-
|
2763
|
-
|
2764
|
-
BULK_OPERATION_MAX_SIZE
|
2765
|
-
);
|
3857
|
+
const operations = await promiseMap(objects, async (object) => {
|
3858
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3859
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3860
|
+
});
|
3861
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2766
3862
|
const ids = [];
|
2767
|
-
for (const
|
3863
|
+
for (const operations2 of chunkedOperations) {
|
2768
3864
|
const { results } = await branchTransaction({
|
2769
3865
|
pathParams: {
|
2770
3866
|
workspace: "{workspaceId}",
|
2771
3867
|
dbBranchName: "{dbBranch}",
|
2772
3868
|
region: "{region}"
|
2773
3869
|
},
|
2774
|
-
body: { operations },
|
2775
|
-
...
|
3870
|
+
body: { operations: operations2 },
|
3871
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2776
3872
|
});
|
2777
3873
|
for (const result of results) {
|
2778
3874
|
if (result.operation === "insert") {
|
@@ -2786,8 +3882,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2786
3882
|
};
|
2787
3883
|
_updateRecordWithID = new WeakSet();
|
2788
3884
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2789
|
-
|
2790
|
-
|
3885
|
+
if (!recordId)
|
3886
|
+
return null;
|
3887
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2791
3888
|
try {
|
2792
3889
|
const response = await updateRecordWithID({
|
2793
3890
|
pathParams: {
|
@@ -2799,7 +3896,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2799
3896
|
},
|
2800
3897
|
queryParams: { columns, ifVersion },
|
2801
3898
|
body: record,
|
2802
|
-
...
|
3899
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2803
3900
|
});
|
2804
3901
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2805
3902
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2812,23 +3909,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2812
3909
|
};
|
2813
3910
|
_updateRecords = new WeakSet();
|
2814
3911
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2815
|
-
const
|
2816
|
-
|
2817
|
-
|
2818
|
-
|
2819
|
-
|
2820
|
-
BULK_OPERATION_MAX_SIZE
|
2821
|
-
);
|
3912
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3913
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3914
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3915
|
+
});
|
3916
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2822
3917
|
const ids = [];
|
2823
|
-
for (const
|
3918
|
+
for (const operations2 of chunkedOperations) {
|
2824
3919
|
const { results } = await branchTransaction({
|
2825
3920
|
pathParams: {
|
2826
3921
|
workspace: "{workspaceId}",
|
2827
3922
|
dbBranchName: "{dbBranch}",
|
2828
3923
|
region: "{region}"
|
2829
3924
|
},
|
2830
|
-
body: { operations },
|
2831
|
-
...
|
3925
|
+
body: { operations: operations2 },
|
3926
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2832
3927
|
});
|
2833
3928
|
for (const result of results) {
|
2834
3929
|
if (result.operation === "update") {
|
@@ -2842,7 +3937,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2842
3937
|
};
|
2843
3938
|
_upsertRecordWithID = new WeakSet();
|
2844
3939
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2845
|
-
|
3940
|
+
if (!recordId)
|
3941
|
+
return null;
|
2846
3942
|
const response = await upsertRecordWithID({
|
2847
3943
|
pathParams: {
|
2848
3944
|
workspace: "{workspaceId}",
|
@@ -2853,14 +3949,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2853
3949
|
},
|
2854
3950
|
queryParams: { columns, ifVersion },
|
2855
3951
|
body: object,
|
2856
|
-
...
|
3952
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2857
3953
|
});
|
2858
3954
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2859
3955
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2860
3956
|
};
|
2861
3957
|
_deleteRecord = new WeakSet();
|
2862
3958
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2863
|
-
|
3959
|
+
if (!recordId)
|
3960
|
+
return null;
|
2864
3961
|
try {
|
2865
3962
|
const response = await deleteRecord({
|
2866
3963
|
pathParams: {
|
@@ -2871,7 +3968,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2871
3968
|
recordId
|
2872
3969
|
},
|
2873
3970
|
queryParams: { columns },
|
2874
|
-
...
|
3971
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2875
3972
|
});
|
2876
3973
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2877
3974
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2884,9 +3981,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2884
3981
|
};
|
2885
3982
|
_deleteRecords = new WeakSet();
|
2886
3983
|
deleteRecords_fn = async function(recordIds) {
|
2887
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2888
3984
|
const chunkedOperations = chunk(
|
2889
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3985
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2890
3986
|
BULK_OPERATION_MAX_SIZE
|
2891
3987
|
);
|
2892
3988
|
for (const operations of chunkedOperations) {
|
@@ -2897,21 +3993,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2897
3993
|
region: "{region}"
|
2898
3994
|
},
|
2899
3995
|
body: { operations },
|
2900
|
-
...
|
3996
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2901
3997
|
});
|
2902
3998
|
}
|
2903
3999
|
};
|
2904
4000
|
_setCacheQuery = new WeakSet();
|
2905
4001
|
setCacheQuery_fn = async function(query, meta, records) {
|
2906
|
-
await __privateGet$4(this, _cache)
|
4002
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2907
4003
|
};
|
2908
4004
|
_getCacheQuery = new WeakSet();
|
2909
4005
|
getCacheQuery_fn = async function(query) {
|
2910
4006
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2911
|
-
const result = await __privateGet$4(this, _cache)
|
4007
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2912
4008
|
if (!result)
|
2913
4009
|
return null;
|
2914
|
-
const
|
4010
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4011
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2915
4012
|
if (ttl < 0)
|
2916
4013
|
return null;
|
2917
4014
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2921,15 +4018,46 @@ _getSchemaTables$1 = new WeakSet();
|
|
2921
4018
|
getSchemaTables_fn$1 = async function() {
|
2922
4019
|
if (__privateGet$4(this, _schemaTables$2))
|
2923
4020
|
return __privateGet$4(this, _schemaTables$2);
|
2924
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2925
4021
|
const { schema } = await getBranchDetails({
|
2926
4022
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2927
|
-
...
|
4023
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2928
4024
|
});
|
2929
4025
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2930
4026
|
return schema.tables;
|
2931
4027
|
};
|
2932
|
-
|
4028
|
+
_transformObjectToApi = new WeakSet();
|
4029
|
+
transformObjectToApi_fn = async function(object) {
|
4030
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4031
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4032
|
+
if (!schema)
|
4033
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4034
|
+
const result = {};
|
4035
|
+
for (const [key, value] of Object.entries(object)) {
|
4036
|
+
if (key === "xata")
|
4037
|
+
continue;
|
4038
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4039
|
+
switch (type) {
|
4040
|
+
case "link": {
|
4041
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4042
|
+
break;
|
4043
|
+
}
|
4044
|
+
case "datetime": {
|
4045
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4046
|
+
break;
|
4047
|
+
}
|
4048
|
+
case `file`:
|
4049
|
+
result[key] = await parseInputFileEntry(value);
|
4050
|
+
break;
|
4051
|
+
case "file[]":
|
4052
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4053
|
+
break;
|
4054
|
+
default:
|
4055
|
+
result[key] = value;
|
4056
|
+
}
|
4057
|
+
}
|
4058
|
+
return result;
|
4059
|
+
};
|
4060
|
+
const removeLinksFromObject = (object) => {
|
2933
4061
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
2934
4062
|
if (key === "xata")
|
2935
4063
|
return acc;
|
@@ -2978,6 +4106,12 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2978
4106
|
}
|
2979
4107
|
break;
|
2980
4108
|
}
|
4109
|
+
case "file":
|
4110
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4111
|
+
break;
|
4112
|
+
case "file[]":
|
4113
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4114
|
+
break;
|
2981
4115
|
default:
|
2982
4116
|
data[column.name] = value ?? null;
|
2983
4117
|
if (column.notNull === true && value === null) {
|
@@ -2987,6 +4121,8 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2987
4121
|
}
|
2988
4122
|
}
|
2989
4123
|
const record = { ...data };
|
4124
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
4125
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2990
4126
|
record.read = function(columns2) {
|
2991
4127
|
return db[table].read(record["id"], columns2);
|
2992
4128
|
};
|
@@ -3003,14 +4139,15 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
3003
4139
|
record.delete = function() {
|
3004
4140
|
return db[table].delete(record["id"]);
|
3005
4141
|
};
|
4142
|
+
record.xata = Object.freeze(metadata);
|
3006
4143
|
record.getMetadata = function() {
|
3007
|
-
return xata;
|
4144
|
+
return record.xata;
|
3008
4145
|
};
|
3009
4146
|
record.toSerializable = function() {
|
3010
|
-
return JSON.parse(JSON.stringify(
|
4147
|
+
return JSON.parse(JSON.stringify(serializable));
|
3011
4148
|
};
|
3012
4149
|
record.toString = function() {
|
3013
|
-
return JSON.stringify(
|
4150
|
+
return JSON.stringify(serializable);
|
3014
4151
|
};
|
3015
4152
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3016
4153
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -3028,11 +4165,7 @@ function extractId(value) {
|
|
3028
4165
|
function isValidColumn(columns, column) {
|
3029
4166
|
if (columns.includes("*"))
|
3030
4167
|
return true;
|
3031
|
-
|
3032
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
3033
|
-
return linkColumns.length > 0;
|
3034
|
-
}
|
3035
|
-
return columns.includes(column.name);
|
4168
|
+
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
3036
4169
|
}
|
3037
4170
|
function parseIfVersion(...args) {
|
3038
4171
|
for (const arg of args) {
|
@@ -3043,6 +4176,12 @@ function parseIfVersion(...args) {
|
|
3043
4176
|
return void 0;
|
3044
4177
|
}
|
3045
4178
|
|
4179
|
+
var __defProp$3 = Object.defineProperty;
|
4180
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4181
|
+
var __publicField$3 = (obj, key, value) => {
|
4182
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4183
|
+
return value;
|
4184
|
+
};
|
3046
4185
|
var __accessCheck$3 = (obj, member, msg) => {
|
3047
4186
|
if (!member.has(obj))
|
3048
4187
|
throw TypeError("Cannot " + msg);
|
@@ -3065,6 +4204,8 @@ var _map;
|
|
3065
4204
|
class SimpleCache {
|
3066
4205
|
constructor(options = {}) {
|
3067
4206
|
__privateAdd$3(this, _map, void 0);
|
4207
|
+
__publicField$3(this, "capacity");
|
4208
|
+
__publicField$3(this, "defaultQueryTTL");
|
3068
4209
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
3069
4210
|
this.capacity = options.max ?? 500;
|
3070
4211
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3200,19 +4341,19 @@ class SearchPlugin extends XataPlugin {
|
|
3200
4341
|
__privateAdd$1(this, _schemaTables, void 0);
|
3201
4342
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3202
4343
|
}
|
3203
|
-
build(
|
4344
|
+
build(pluginOptions) {
|
3204
4345
|
return {
|
3205
4346
|
all: async (query, options = {}) => {
|
3206
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3207
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4347
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4348
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3208
4349
|
return records.map((record) => {
|
3209
4350
|
const { table = "orphan" } = record.xata;
|
3210
4351
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3211
4352
|
});
|
3212
4353
|
},
|
3213
4354
|
byTable: async (query, options = {}) => {
|
3214
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3215
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4355
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4356
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3216
4357
|
return records.reduce((acc, record) => {
|
3217
4358
|
const { table = "orphan" } = record.xata;
|
3218
4359
|
const items = acc[table] ?? [];
|
@@ -3225,38 +4366,108 @@ class SearchPlugin extends XataPlugin {
|
|
3225
4366
|
}
|
3226
4367
|
_schemaTables = new WeakMap();
|
3227
4368
|
_search = new WeakSet();
|
3228
|
-
search_fn = async function(query, options,
|
3229
|
-
const fetchProps = await getFetchProps();
|
4369
|
+
search_fn = async function(query, options, pluginOptions) {
|
3230
4370
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3231
4371
|
const { records } = await searchBranch({
|
3232
4372
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4373
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3233
4374
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3234
|
-
...
|
4375
|
+
...pluginOptions
|
3235
4376
|
});
|
3236
4377
|
return records;
|
3237
4378
|
};
|
3238
4379
|
_getSchemaTables = new WeakSet();
|
3239
|
-
getSchemaTables_fn = async function(
|
4380
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3240
4381
|
if (__privateGet$1(this, _schemaTables))
|
3241
4382
|
return __privateGet$1(this, _schemaTables);
|
3242
|
-
const fetchProps = await getFetchProps();
|
3243
4383
|
const { schema } = await getBranchDetails({
|
3244
4384
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3245
|
-
...
|
4385
|
+
...pluginOptions
|
3246
4386
|
});
|
3247
4387
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3248
4388
|
return schema.tables;
|
3249
4389
|
};
|
3250
4390
|
|
4391
|
+
function escapeElement(elementRepresentation) {
|
4392
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4393
|
+
return '"' + escaped + '"';
|
4394
|
+
}
|
4395
|
+
function arrayString(val) {
|
4396
|
+
let result = "{";
|
4397
|
+
for (let i = 0; i < val.length; i++) {
|
4398
|
+
if (i > 0) {
|
4399
|
+
result = result + ",";
|
4400
|
+
}
|
4401
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4402
|
+
result = result + "NULL";
|
4403
|
+
} else if (Array.isArray(val[i])) {
|
4404
|
+
result = result + arrayString(val[i]);
|
4405
|
+
} else if (val[i] instanceof Buffer) {
|
4406
|
+
result += "\\\\x" + val[i].toString("hex");
|
4407
|
+
} else {
|
4408
|
+
result += escapeElement(prepareValue(val[i]));
|
4409
|
+
}
|
4410
|
+
}
|
4411
|
+
result = result + "}";
|
4412
|
+
return result;
|
4413
|
+
}
|
4414
|
+
function prepareValue(value) {
|
4415
|
+
if (!isDefined(value))
|
4416
|
+
return null;
|
4417
|
+
if (value instanceof Date) {
|
4418
|
+
return value.toISOString();
|
4419
|
+
}
|
4420
|
+
if (Array.isArray(value)) {
|
4421
|
+
return arrayString(value);
|
4422
|
+
}
|
4423
|
+
if (isObject(value)) {
|
4424
|
+
return JSON.stringify(value);
|
4425
|
+
}
|
4426
|
+
try {
|
4427
|
+
return value.toString();
|
4428
|
+
} catch (e) {
|
4429
|
+
return value;
|
4430
|
+
}
|
4431
|
+
}
|
4432
|
+
function prepareParams(param1, param2) {
|
4433
|
+
if (isString(param1)) {
|
4434
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4435
|
+
}
|
4436
|
+
if (isStringArray(param1)) {
|
4437
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4438
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4439
|
+
}, "");
|
4440
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4441
|
+
}
|
4442
|
+
if (isObject(param1)) {
|
4443
|
+
const { statement, params, consistency } = param1;
|
4444
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4445
|
+
}
|
4446
|
+
throw new Error("Invalid query");
|
4447
|
+
}
|
4448
|
+
|
4449
|
+
class SQLPlugin extends XataPlugin {
|
4450
|
+
build(pluginOptions) {
|
4451
|
+
return async (param1, ...param2) => {
|
4452
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4453
|
+
const { records, warning } = await sqlQuery({
|
4454
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4455
|
+
body: { statement, params, consistency },
|
4456
|
+
...pluginOptions
|
4457
|
+
});
|
4458
|
+
return { records, warning };
|
4459
|
+
};
|
4460
|
+
}
|
4461
|
+
}
|
4462
|
+
|
3251
4463
|
class TransactionPlugin extends XataPlugin {
|
3252
|
-
build(
|
4464
|
+
build(pluginOptions) {
|
3253
4465
|
return {
|
3254
4466
|
run: async (operations) => {
|
3255
|
-
const fetchProps = await getFetchProps();
|
3256
4467
|
const response = await branchTransaction({
|
3257
4468
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3258
4469
|
body: { operations },
|
3259
|
-
...
|
4470
|
+
...pluginOptions
|
3260
4471
|
});
|
3261
4472
|
return response;
|
3262
4473
|
}
|
@@ -3264,91 +4475,12 @@ class TransactionPlugin extends XataPlugin {
|
|
3264
4475
|
}
|
3265
4476
|
}
|
3266
4477
|
|
3267
|
-
|
3268
|
-
|
4478
|
+
var __defProp$2 = Object.defineProperty;
|
4479
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4480
|
+
var __publicField$2 = (obj, key, value) => {
|
4481
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4482
|
+
return value;
|
3269
4483
|
};
|
3270
|
-
|
3271
|
-
async function getCurrentBranchName(options) {
|
3272
|
-
const { branch, envBranch } = getEnvironment();
|
3273
|
-
if (branch)
|
3274
|
-
return branch;
|
3275
|
-
const gitBranch = envBranch || await getGitBranch();
|
3276
|
-
return resolveXataBranch(gitBranch, options);
|
3277
|
-
}
|
3278
|
-
async function getCurrentBranchDetails(options) {
|
3279
|
-
const branch = await getCurrentBranchName(options);
|
3280
|
-
return getDatabaseBranch(branch, options);
|
3281
|
-
}
|
3282
|
-
async function resolveXataBranch(gitBranch, options) {
|
3283
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3284
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3285
|
-
if (!databaseURL)
|
3286
|
-
throw new Error(
|
3287
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3288
|
-
);
|
3289
|
-
if (!apiKey)
|
3290
|
-
throw new Error(
|
3291
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3292
|
-
);
|
3293
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3294
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3295
|
-
if (!urlParts)
|
3296
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3297
|
-
const { workspace, region } = urlParts;
|
3298
|
-
const { fallbackBranch } = getEnvironment();
|
3299
|
-
const { branch } = await resolveBranch({
|
3300
|
-
apiKey,
|
3301
|
-
apiUrl: databaseURL,
|
3302
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3303
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3304
|
-
pathParams: { dbName, workspace, region },
|
3305
|
-
queryParams: { gitBranch, fallbackBranch },
|
3306
|
-
trace: defaultTrace,
|
3307
|
-
clientName: options?.clientName,
|
3308
|
-
xataAgentExtra: options?.xataAgentExtra
|
3309
|
-
});
|
3310
|
-
return branch;
|
3311
|
-
}
|
3312
|
-
async function getDatabaseBranch(branch, options) {
|
3313
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3314
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3315
|
-
if (!databaseURL)
|
3316
|
-
throw new Error(
|
3317
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3318
|
-
);
|
3319
|
-
if (!apiKey)
|
3320
|
-
throw new Error(
|
3321
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3322
|
-
);
|
3323
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3324
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3325
|
-
if (!urlParts)
|
3326
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3327
|
-
const { workspace, region } = urlParts;
|
3328
|
-
try {
|
3329
|
-
return await getBranchDetails({
|
3330
|
-
apiKey,
|
3331
|
-
apiUrl: databaseURL,
|
3332
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3333
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3334
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3335
|
-
trace: defaultTrace
|
3336
|
-
});
|
3337
|
-
} catch (err) {
|
3338
|
-
if (isObject(err) && err.status === 404)
|
3339
|
-
return null;
|
3340
|
-
throw err;
|
3341
|
-
}
|
3342
|
-
}
|
3343
|
-
function getDatabaseURL() {
|
3344
|
-
try {
|
3345
|
-
const { databaseURL } = getEnvironment();
|
3346
|
-
return databaseURL;
|
3347
|
-
} catch (err) {
|
3348
|
-
return void 0;
|
3349
|
-
}
|
3350
|
-
}
|
3351
|
-
|
3352
4484
|
var __accessCheck = (obj, member, msg) => {
|
3353
4485
|
if (!member.has(obj))
|
3354
4486
|
throw TypeError("Cannot " + msg);
|
@@ -3372,46 +4504,46 @@ var __privateMethod = (obj, member, method) => {
|
|
3372
4504
|
return method;
|
3373
4505
|
};
|
3374
4506
|
const buildClient = (plugins) => {
|
3375
|
-
var
|
4507
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3376
4508
|
return _a = class {
|
3377
4509
|
constructor(options = {}, schemaTables) {
|
3378
4510
|
__privateAdd(this, _parseOptions);
|
3379
4511
|
__privateAdd(this, _getFetchProps);
|
3380
|
-
__privateAdd(this, _evaluateBranch);
|
3381
|
-
__privateAdd(this, _branch, void 0);
|
3382
4512
|
__privateAdd(this, _options, void 0);
|
4513
|
+
__publicField$2(this, "db");
|
4514
|
+
__publicField$2(this, "search");
|
4515
|
+
__publicField$2(this, "transactions");
|
4516
|
+
__publicField$2(this, "sql");
|
4517
|
+
__publicField$2(this, "files");
|
3383
4518
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3384
4519
|
__privateSet(this, _options, safeOptions);
|
3385
4520
|
const pluginOptions = {
|
3386
|
-
|
4521
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3387
4522
|
cache: safeOptions.cache,
|
3388
|
-
|
4523
|
+
host: safeOptions.host
|
3389
4524
|
};
|
3390
4525
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3391
4526
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3392
4527
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4528
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4529
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3393
4530
|
this.db = db;
|
3394
4531
|
this.search = search;
|
3395
4532
|
this.transactions = transactions;
|
4533
|
+
this.sql = sql;
|
4534
|
+
this.files = files;
|
3396
4535
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3397
4536
|
if (namespace === void 0)
|
3398
4537
|
continue;
|
3399
|
-
|
3400
|
-
if (result instanceof Promise) {
|
3401
|
-
void result.then((namespace2) => {
|
3402
|
-
this[key] = namespace2;
|
3403
|
-
});
|
3404
|
-
} else {
|
3405
|
-
this[key] = result;
|
3406
|
-
}
|
4538
|
+
this[key] = namespace.build(pluginOptions);
|
3407
4539
|
}
|
3408
4540
|
}
|
3409
4541
|
async getConfig() {
|
3410
4542
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3411
|
-
const branch =
|
4543
|
+
const branch = __privateGet(this, _options).branch;
|
3412
4544
|
return { databaseURL, branch };
|
3413
4545
|
}
|
3414
|
-
},
|
4546
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3415
4547
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3416
4548
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3417
4549
|
if (isBrowser && !enableBrowser) {
|
@@ -3425,20 +4557,34 @@ const buildClient = (plugins) => {
|
|
3425
4557
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3426
4558
|
const trace = options?.trace ?? defaultTrace;
|
3427
4559
|
const clientName = options?.clientName;
|
4560
|
+
const host = options?.host ?? "production";
|
3428
4561
|
const xataAgentExtra = options?.xataAgentExtra;
|
3429
|
-
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
|
3430
|
-
apiKey,
|
3431
|
-
databaseURL,
|
3432
|
-
fetchImpl: options?.fetch,
|
3433
|
-
clientName,
|
3434
|
-
xataAgentExtra
|
3435
|
-
});
|
3436
4562
|
if (!apiKey) {
|
3437
4563
|
throw new Error("Option apiKey is required");
|
3438
4564
|
}
|
3439
4565
|
if (!databaseURL) {
|
3440
4566
|
throw new Error("Option databaseURL is required");
|
3441
4567
|
}
|
4568
|
+
const envBranch = getBranch();
|
4569
|
+
const previewBranch = getPreviewBranch();
|
4570
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4571
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4572
|
+
console.warn(
|
4573
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4574
|
+
);
|
4575
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4576
|
+
console.warn(
|
4577
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4578
|
+
);
|
4579
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4580
|
+
console.warn(
|
4581
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4582
|
+
);
|
4583
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4584
|
+
console.warn(
|
4585
|
+
`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.`
|
4586
|
+
);
|
4587
|
+
}
|
3442
4588
|
return {
|
3443
4589
|
fetch,
|
3444
4590
|
databaseURL,
|
@@ -3446,12 +4592,13 @@ const buildClient = (plugins) => {
|
|
3446
4592
|
branch,
|
3447
4593
|
cache,
|
3448
4594
|
trace,
|
4595
|
+
host,
|
3449
4596
|
clientID: generateUUID(),
|
3450
4597
|
enableBrowser,
|
3451
4598
|
clientName,
|
3452
4599
|
xataAgentExtra
|
3453
4600
|
};
|
3454
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn =
|
4601
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3455
4602
|
fetch,
|
3456
4603
|
apiKey,
|
3457
4604
|
databaseURL,
|
@@ -3461,16 +4608,14 @@ const buildClient = (plugins) => {
|
|
3461
4608
|
clientName,
|
3462
4609
|
xataAgentExtra
|
3463
4610
|
}) {
|
3464
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3465
|
-
if (!branchValue)
|
3466
|
-
throw new Error("Unable to resolve branch value");
|
3467
4611
|
return {
|
3468
|
-
|
4612
|
+
fetch,
|
3469
4613
|
apiKey,
|
3470
4614
|
apiUrl: "",
|
4615
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3471
4616
|
workspacesApiUrl: (path, params) => {
|
3472
4617
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3473
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4618
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3474
4619
|
return databaseURL + newPath;
|
3475
4620
|
},
|
3476
4621
|
trace,
|
@@ -3478,32 +4623,22 @@ const buildClient = (plugins) => {
|
|
3478
4623
|
clientName,
|
3479
4624
|
xataAgentExtra
|
3480
4625
|
};
|
3481
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3482
|
-
if (__privateGet(this, _branch))
|
3483
|
-
return __privateGet(this, _branch);
|
3484
|
-
if (param === void 0)
|
3485
|
-
return void 0;
|
3486
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3487
|
-
const evaluateBranch = async (strategy) => {
|
3488
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3489
|
-
};
|
3490
|
-
for await (const strategy of strategies) {
|
3491
|
-
const branch = await evaluateBranch(strategy);
|
3492
|
-
if (branch) {
|
3493
|
-
__privateSet(this, _branch, branch);
|
3494
|
-
return branch;
|
3495
|
-
}
|
3496
|
-
}
|
3497
4626
|
}, _a;
|
3498
4627
|
};
|
3499
4628
|
class BaseClient extends buildClient() {
|
3500
4629
|
}
|
3501
4630
|
|
4631
|
+
var __defProp$1 = Object.defineProperty;
|
4632
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4633
|
+
var __publicField$1 = (obj, key, value) => {
|
4634
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4635
|
+
return value;
|
4636
|
+
};
|
3502
4637
|
const META = "__";
|
3503
4638
|
const VALUE = "___";
|
3504
4639
|
class Serializer {
|
3505
4640
|
constructor() {
|
3506
|
-
this
|
4641
|
+
__publicField$1(this, "classes", {});
|
3507
4642
|
}
|
3508
4643
|
add(clazz) {
|
3509
4644
|
this.classes[clazz.name] = clazz;
|
@@ -3581,12 +4716,19 @@ function buildWorkerRunner(config) {
|
|
3581
4716
|
};
|
3582
4717
|
}
|
3583
4718
|
|
4719
|
+
var __defProp = Object.defineProperty;
|
4720
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4721
|
+
var __publicField = (obj, key, value) => {
|
4722
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4723
|
+
return value;
|
4724
|
+
};
|
3584
4725
|
class XataError extends Error {
|
3585
4726
|
constructor(message, status) {
|
3586
4727
|
super(message);
|
4728
|
+
__publicField(this, "status");
|
3587
4729
|
this.status = status;
|
3588
4730
|
}
|
3589
4731
|
}
|
3590
4732
|
|
3591
|
-
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn,
|
4733
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3592
4734
|
//# sourceMappingURL=index.mjs.map
|