@xata.io/client 0.0.0-alpha.vf76843f → 0.0.0-alpha.vf7ac0d1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +18 -0
- package/CHANGELOG.md +224 -0
- package/README.md +3 -269
- package/dist/index.cjs +1680 -353
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3589 -1726
- package/dist/index.mjs +1651 -347
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -10
- package/.eslintrc.cjs +0 -12
- package/Usage.md +0 -451
- package/rollup.config.mjs +0 -29
- package/tsconfig.json +0 -23
package/dist/index.cjs
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
const defaultTrace = async (
|
3
|
+
const defaultTrace = async (name, fn, _options) => {
|
4
4
|
return await fn({
|
5
|
+
name,
|
5
6
|
setAttributes: () => {
|
6
7
|
return;
|
7
8
|
}
|
@@ -28,8 +29,11 @@ function notEmpty(value) {
|
|
28
29
|
function compact(arr) {
|
29
30
|
return arr.filter(notEmpty);
|
30
31
|
}
|
32
|
+
function compactObject(obj) {
|
33
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
34
|
+
}
|
31
35
|
function isObject(value) {
|
32
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
36
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
33
37
|
}
|
34
38
|
function isDefined(value) {
|
35
39
|
return value !== null && value !== void 0;
|
@@ -43,6 +47,18 @@ function isStringArray(value) {
|
|
43
47
|
function isNumber(value) {
|
44
48
|
return isDefined(value) && typeof value === "number";
|
45
49
|
}
|
50
|
+
function parseNumber(value) {
|
51
|
+
if (isNumber(value)) {
|
52
|
+
return value;
|
53
|
+
}
|
54
|
+
if (isString(value)) {
|
55
|
+
const parsed = Number(value);
|
56
|
+
if (!Number.isNaN(parsed)) {
|
57
|
+
return parsed;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
return void 0;
|
61
|
+
}
|
46
62
|
function toBase64(value) {
|
47
63
|
try {
|
48
64
|
return btoa(value);
|
@@ -69,16 +85,42 @@ function chunk(array, chunkSize) {
|
|
69
85
|
}
|
70
86
|
return result;
|
71
87
|
}
|
88
|
+
async function timeout(ms) {
|
89
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
90
|
+
}
|
91
|
+
function timeoutWithCancel(ms) {
|
92
|
+
let timeoutId;
|
93
|
+
const promise = new Promise((resolve) => {
|
94
|
+
timeoutId = setTimeout(() => {
|
95
|
+
resolve();
|
96
|
+
}, ms);
|
97
|
+
});
|
98
|
+
return {
|
99
|
+
cancel: () => clearTimeout(timeoutId),
|
100
|
+
promise
|
101
|
+
};
|
102
|
+
}
|
103
|
+
function promiseMap(inputValues, mapper) {
|
104
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
105
|
+
(acc) => mapper(inputValue).then((result) => {
|
106
|
+
acc.push(result);
|
107
|
+
return acc;
|
108
|
+
})
|
109
|
+
);
|
110
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
111
|
+
}
|
72
112
|
|
73
113
|
function getEnvironment() {
|
74
114
|
try {
|
75
|
-
if (
|
115
|
+
if (isDefined(process) && isDefined(process.env)) {
|
76
116
|
return {
|
77
117
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
78
118
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
79
119
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
80
|
-
|
81
|
-
|
120
|
+
deployPreview: process.env.XATA_PREVIEW,
|
121
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
122
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
123
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
82
124
|
};
|
83
125
|
}
|
84
126
|
} catch (err) {
|
@@ -89,8 +131,10 @@ function getEnvironment() {
|
|
89
131
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
90
132
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
91
133
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
92
|
-
|
93
|
-
|
134
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
135
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
136
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
137
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
94
138
|
};
|
95
139
|
}
|
96
140
|
} catch (err) {
|
@@ -99,8 +143,10 @@ function getEnvironment() {
|
|
99
143
|
apiKey: getGlobalApiKey(),
|
100
144
|
databaseURL: getGlobalDatabaseURL(),
|
101
145
|
branch: getGlobalBranch(),
|
102
|
-
|
103
|
-
|
146
|
+
deployPreview: void 0,
|
147
|
+
deployPreviewBranch: void 0,
|
148
|
+
vercelGitCommitRef: void 0,
|
149
|
+
vercelGitRepoOwner: void 0
|
104
150
|
};
|
105
151
|
}
|
106
152
|
function getEnableBrowserVariable() {
|
@@ -143,44 +189,83 @@ function getGlobalBranch() {
|
|
143
189
|
return void 0;
|
144
190
|
}
|
145
191
|
}
|
146
|
-
function
|
192
|
+
function getDatabaseURL() {
|
147
193
|
try {
|
148
|
-
|
194
|
+
const { databaseURL } = getEnvironment();
|
195
|
+
return databaseURL;
|
149
196
|
} catch (err) {
|
150
197
|
return void 0;
|
151
198
|
}
|
152
199
|
}
|
153
|
-
|
154
|
-
const cmd = ["git", "branch", "--show-current"];
|
155
|
-
const fullCmd = cmd.join(" ");
|
156
|
-
const nodeModule = ["child", "process"].join("_");
|
157
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
200
|
+
function getAPIKey() {
|
158
201
|
try {
|
159
|
-
|
160
|
-
|
161
|
-
}
|
162
|
-
const { execSync } = await import(nodeModule);
|
163
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
202
|
+
const { apiKey } = getEnvironment();
|
203
|
+
return apiKey;
|
164
204
|
} catch (err) {
|
205
|
+
return void 0;
|
165
206
|
}
|
207
|
+
}
|
208
|
+
function getBranch() {
|
166
209
|
try {
|
167
|
-
|
168
|
-
|
169
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
170
|
-
}
|
210
|
+
const { branch } = getEnvironment();
|
211
|
+
return branch;
|
171
212
|
} catch (err) {
|
213
|
+
return void 0;
|
172
214
|
}
|
173
215
|
}
|
174
|
-
|
175
|
-
|
216
|
+
function buildPreviewBranchName({ org, branch }) {
|
217
|
+
return `preview-${org}-${branch}`;
|
218
|
+
}
|
219
|
+
function getPreviewBranch() {
|
176
220
|
try {
|
177
|
-
const {
|
178
|
-
|
221
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
222
|
+
if (deployPreviewBranch)
|
223
|
+
return deployPreviewBranch;
|
224
|
+
switch (deployPreview) {
|
225
|
+
case "vercel": {
|
226
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
227
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
228
|
+
return void 0;
|
229
|
+
}
|
230
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
231
|
+
}
|
232
|
+
}
|
233
|
+
return void 0;
|
179
234
|
} catch (err) {
|
180
235
|
return void 0;
|
181
236
|
}
|
182
237
|
}
|
183
238
|
|
239
|
+
var __defProp$8 = Object.defineProperty;
|
240
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
241
|
+
var __publicField$8 = (obj, key, value) => {
|
242
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
243
|
+
return value;
|
244
|
+
};
|
245
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
246
|
+
if (!member.has(obj))
|
247
|
+
throw TypeError("Cannot " + msg);
|
248
|
+
};
|
249
|
+
var __privateGet$8 = (obj, member, getter) => {
|
250
|
+
__accessCheck$8(obj, member, "read from private field");
|
251
|
+
return getter ? getter.call(obj) : member.get(obj);
|
252
|
+
};
|
253
|
+
var __privateAdd$8 = (obj, member, value) => {
|
254
|
+
if (member.has(obj))
|
255
|
+
throw TypeError("Cannot add the same private member more than once");
|
256
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
257
|
+
};
|
258
|
+
var __privateSet$8 = (obj, member, value, setter) => {
|
259
|
+
__accessCheck$8(obj, member, "write to private field");
|
260
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
261
|
+
return value;
|
262
|
+
};
|
263
|
+
var __privateMethod$4 = (obj, member, method) => {
|
264
|
+
__accessCheck$8(obj, member, "access private method");
|
265
|
+
return method;
|
266
|
+
};
|
267
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
+
const REQUEST_TIMEOUT = 3e4;
|
184
269
|
function getFetchImplementation(userFetch) {
|
185
270
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
186
271
|
const fetchImpl = userFetch ?? globalFetch;
|
@@ -191,19 +276,281 @@ function getFetchImplementation(userFetch) {
|
|
191
276
|
}
|
192
277
|
return fetchImpl;
|
193
278
|
}
|
279
|
+
class ApiRequestPool {
|
280
|
+
constructor(concurrency = 10) {
|
281
|
+
__privateAdd$8(this, _enqueue);
|
282
|
+
__privateAdd$8(this, _fetch, void 0);
|
283
|
+
__privateAdd$8(this, _queue, void 0);
|
284
|
+
__privateAdd$8(this, _concurrency, void 0);
|
285
|
+
__publicField$8(this, "running");
|
286
|
+
__publicField$8(this, "started");
|
287
|
+
__privateSet$8(this, _queue, []);
|
288
|
+
__privateSet$8(this, _concurrency, concurrency);
|
289
|
+
this.running = 0;
|
290
|
+
this.started = 0;
|
291
|
+
}
|
292
|
+
setFetch(fetch2) {
|
293
|
+
__privateSet$8(this, _fetch, fetch2);
|
294
|
+
}
|
295
|
+
getFetch() {
|
296
|
+
if (!__privateGet$8(this, _fetch)) {
|
297
|
+
throw new Error("Fetch not set");
|
298
|
+
}
|
299
|
+
return __privateGet$8(this, _fetch);
|
300
|
+
}
|
301
|
+
request(url, options) {
|
302
|
+
const start = /* @__PURE__ */ new Date();
|
303
|
+
const fetchImpl = this.getFetch();
|
304
|
+
const runRequest = async (stalled = false) => {
|
305
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
306
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
307
|
+
if (!response) {
|
308
|
+
throw new Error("Request timed out");
|
309
|
+
}
|
310
|
+
if (response.status === 429) {
|
311
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
312
|
+
await timeout(rateLimitReset * 1e3);
|
313
|
+
return await runRequest(true);
|
314
|
+
}
|
315
|
+
if (stalled) {
|
316
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
317
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
318
|
+
}
|
319
|
+
return response;
|
320
|
+
};
|
321
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
322
|
+
return await runRequest();
|
323
|
+
});
|
324
|
+
}
|
325
|
+
}
|
326
|
+
_fetch = new WeakMap();
|
327
|
+
_queue = new WeakMap();
|
328
|
+
_concurrency = new WeakMap();
|
329
|
+
_enqueue = new WeakSet();
|
330
|
+
enqueue_fn = function(task) {
|
331
|
+
const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
|
332
|
+
this.started--;
|
333
|
+
this.running++;
|
334
|
+
}).then(() => task()).finally(() => {
|
335
|
+
this.running--;
|
336
|
+
const next = __privateGet$8(this, _queue).shift();
|
337
|
+
if (next !== void 0) {
|
338
|
+
this.started++;
|
339
|
+
next();
|
340
|
+
}
|
341
|
+
});
|
342
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
343
|
+
const next = __privateGet$8(this, _queue).shift();
|
344
|
+
if (next !== void 0) {
|
345
|
+
this.started++;
|
346
|
+
next();
|
347
|
+
}
|
348
|
+
}
|
349
|
+
return promise;
|
350
|
+
};
|
351
|
+
|
352
|
+
function generateUUID() {
|
353
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
354
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
355
|
+
return v.toString(16);
|
356
|
+
});
|
357
|
+
}
|
358
|
+
|
359
|
+
async function getBytes(stream, onChunk) {
|
360
|
+
const reader = stream.getReader();
|
361
|
+
let result;
|
362
|
+
while (!(result = await reader.read()).done) {
|
363
|
+
onChunk(result.value);
|
364
|
+
}
|
365
|
+
}
|
366
|
+
function getLines(onLine) {
|
367
|
+
let buffer;
|
368
|
+
let position;
|
369
|
+
let fieldLength;
|
370
|
+
let discardTrailingNewline = false;
|
371
|
+
return function onChunk(arr) {
|
372
|
+
if (buffer === void 0) {
|
373
|
+
buffer = arr;
|
374
|
+
position = 0;
|
375
|
+
fieldLength = -1;
|
376
|
+
} else {
|
377
|
+
buffer = concat(buffer, arr);
|
378
|
+
}
|
379
|
+
const bufLength = buffer.length;
|
380
|
+
let lineStart = 0;
|
381
|
+
while (position < bufLength) {
|
382
|
+
if (discardTrailingNewline) {
|
383
|
+
if (buffer[position] === 10 /* NewLine */) {
|
384
|
+
lineStart = ++position;
|
385
|
+
}
|
386
|
+
discardTrailingNewline = false;
|
387
|
+
}
|
388
|
+
let lineEnd = -1;
|
389
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
390
|
+
switch (buffer[position]) {
|
391
|
+
case 58 /* Colon */:
|
392
|
+
if (fieldLength === -1) {
|
393
|
+
fieldLength = position - lineStart;
|
394
|
+
}
|
395
|
+
break;
|
396
|
+
case 13 /* CarriageReturn */:
|
397
|
+
discardTrailingNewline = true;
|
398
|
+
case 10 /* NewLine */:
|
399
|
+
lineEnd = position;
|
400
|
+
break;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
if (lineEnd === -1) {
|
404
|
+
break;
|
405
|
+
}
|
406
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
407
|
+
lineStart = position;
|
408
|
+
fieldLength = -1;
|
409
|
+
}
|
410
|
+
if (lineStart === bufLength) {
|
411
|
+
buffer = void 0;
|
412
|
+
} else if (lineStart !== 0) {
|
413
|
+
buffer = buffer.subarray(lineStart);
|
414
|
+
position -= lineStart;
|
415
|
+
}
|
416
|
+
};
|
417
|
+
}
|
418
|
+
function getMessages(onId, onRetry, onMessage) {
|
419
|
+
let message = newMessage();
|
420
|
+
const decoder = new TextDecoder();
|
421
|
+
return function onLine(line, fieldLength) {
|
422
|
+
if (line.length === 0) {
|
423
|
+
onMessage?.(message);
|
424
|
+
message = newMessage();
|
425
|
+
} else if (fieldLength > 0) {
|
426
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
427
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
428
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
429
|
+
switch (field) {
|
430
|
+
case "data":
|
431
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
432
|
+
break;
|
433
|
+
case "event":
|
434
|
+
message.event = value;
|
435
|
+
break;
|
436
|
+
case "id":
|
437
|
+
onId(message.id = value);
|
438
|
+
break;
|
439
|
+
case "retry":
|
440
|
+
const retry = parseInt(value, 10);
|
441
|
+
if (!isNaN(retry)) {
|
442
|
+
onRetry(message.retry = retry);
|
443
|
+
}
|
444
|
+
break;
|
445
|
+
}
|
446
|
+
}
|
447
|
+
};
|
448
|
+
}
|
449
|
+
function concat(a, b) {
|
450
|
+
const res = new Uint8Array(a.length + b.length);
|
451
|
+
res.set(a);
|
452
|
+
res.set(b, a.length);
|
453
|
+
return res;
|
454
|
+
}
|
455
|
+
function newMessage() {
|
456
|
+
return {
|
457
|
+
data: "",
|
458
|
+
event: "",
|
459
|
+
id: "",
|
460
|
+
retry: void 0
|
461
|
+
};
|
462
|
+
}
|
463
|
+
const EventStreamContentType = "text/event-stream";
|
464
|
+
const LastEventId = "last-event-id";
|
465
|
+
function fetchEventSource(input, {
|
466
|
+
signal: inputSignal,
|
467
|
+
headers: inputHeaders,
|
468
|
+
onopen: inputOnOpen,
|
469
|
+
onmessage,
|
470
|
+
onclose,
|
471
|
+
onerror,
|
472
|
+
fetch: inputFetch,
|
473
|
+
...rest
|
474
|
+
}) {
|
475
|
+
return new Promise((resolve, reject) => {
|
476
|
+
const headers = { ...inputHeaders };
|
477
|
+
if (!headers.accept) {
|
478
|
+
headers.accept = EventStreamContentType;
|
479
|
+
}
|
480
|
+
let curRequestController;
|
481
|
+
function dispose() {
|
482
|
+
curRequestController.abort();
|
483
|
+
}
|
484
|
+
inputSignal?.addEventListener("abort", () => {
|
485
|
+
dispose();
|
486
|
+
resolve();
|
487
|
+
});
|
488
|
+
const fetchImpl = inputFetch ?? fetch;
|
489
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
490
|
+
async function create() {
|
491
|
+
curRequestController = new AbortController();
|
492
|
+
try {
|
493
|
+
const response = await fetchImpl(input, {
|
494
|
+
...rest,
|
495
|
+
headers,
|
496
|
+
signal: curRequestController.signal
|
497
|
+
});
|
498
|
+
await onopen(response);
|
499
|
+
await getBytes(
|
500
|
+
response.body,
|
501
|
+
getLines(
|
502
|
+
getMessages(
|
503
|
+
(id) => {
|
504
|
+
if (id) {
|
505
|
+
headers[LastEventId] = id;
|
506
|
+
} else {
|
507
|
+
delete headers[LastEventId];
|
508
|
+
}
|
509
|
+
},
|
510
|
+
(_retry) => {
|
511
|
+
},
|
512
|
+
onmessage
|
513
|
+
)
|
514
|
+
)
|
515
|
+
);
|
516
|
+
onclose?.();
|
517
|
+
dispose();
|
518
|
+
resolve();
|
519
|
+
} catch (err) {
|
520
|
+
}
|
521
|
+
}
|
522
|
+
create();
|
523
|
+
});
|
524
|
+
}
|
525
|
+
function defaultOnOpen(response) {
|
526
|
+
const contentType = response.headers?.get("content-type");
|
527
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
528
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
529
|
+
}
|
530
|
+
}
|
194
531
|
|
195
|
-
const VERSION = "0.
|
532
|
+
const VERSION = "0.25.2";
|
196
533
|
|
534
|
+
var __defProp$7 = Object.defineProperty;
|
535
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
536
|
+
var __publicField$7 = (obj, key, value) => {
|
537
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
538
|
+
return value;
|
539
|
+
};
|
197
540
|
class ErrorWithCause extends Error {
|
198
541
|
constructor(message, options) {
|
199
542
|
super(message, options);
|
543
|
+
__publicField$7(this, "cause");
|
200
544
|
}
|
201
545
|
}
|
202
546
|
class FetcherError extends ErrorWithCause {
|
203
547
|
constructor(status, data, requestId) {
|
204
548
|
super(getMessage(data));
|
549
|
+
__publicField$7(this, "status");
|
550
|
+
__publicField$7(this, "requestId");
|
551
|
+
__publicField$7(this, "errors");
|
205
552
|
this.status = status;
|
206
|
-
this.errors = isBulkError(data) ? data.errors :
|
553
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
207
554
|
this.requestId = requestId;
|
208
555
|
if (data instanceof Error) {
|
209
556
|
this.stack = data.stack;
|
@@ -235,6 +582,7 @@ function getMessage(data) {
|
|
235
582
|
}
|
236
583
|
}
|
237
584
|
|
585
|
+
const pool = new ApiRequestPool();
|
238
586
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
239
587
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
240
588
|
if (value === void 0 || value === null)
|
@@ -267,14 +615,24 @@ function hostHeader(url) {
|
|
267
615
|
const { groups } = pattern.exec(url) ?? {};
|
268
616
|
return groups?.host ? { Host: groups.host } : {};
|
269
617
|
}
|
618
|
+
function parseBody(body, headers) {
|
619
|
+
if (!isDefined(body))
|
620
|
+
return void 0;
|
621
|
+
const { "Content-Type": contentType } = headers ?? {};
|
622
|
+
if (String(contentType).toLowerCase() === "application/json") {
|
623
|
+
return JSON.stringify(body);
|
624
|
+
}
|
625
|
+
return body;
|
626
|
+
}
|
627
|
+
const defaultClientID = generateUUID();
|
270
628
|
async function fetch$1({
|
271
629
|
url: path,
|
272
630
|
method,
|
273
631
|
body,
|
274
|
-
headers,
|
632
|
+
headers: customHeaders,
|
275
633
|
pathParams,
|
276
634
|
queryParams,
|
277
|
-
|
635
|
+
fetch: fetch2,
|
278
636
|
apiKey,
|
279
637
|
endpoint,
|
280
638
|
apiUrl,
|
@@ -283,9 +641,13 @@ async function fetch$1({
|
|
283
641
|
signal,
|
284
642
|
clientID,
|
285
643
|
sessionID,
|
286
|
-
|
644
|
+
clientName,
|
645
|
+
xataAgentExtra,
|
646
|
+
fetchOptions = {},
|
647
|
+
rawResponse = false
|
287
648
|
}) {
|
288
|
-
|
649
|
+
pool.setFetch(fetch2);
|
650
|
+
return await trace(
|
289
651
|
`${method.toUpperCase()} ${path}`,
|
290
652
|
async ({ setAttributes }) => {
|
291
653
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
@@ -295,24 +657,29 @@ async function fetch$1({
|
|
295
657
|
[TraceAttributes.HTTP_URL]: url,
|
296
658
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
297
659
|
});
|
298
|
-
const
|
660
|
+
const xataAgent = compact([
|
661
|
+
["client", "TS_SDK"],
|
662
|
+
["version", VERSION],
|
663
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
664
|
+
...Object.entries(xataAgentExtra ?? {})
|
665
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
666
|
+
const headers = compactObject({
|
667
|
+
"Accept-Encoding": "identity",
|
668
|
+
"Content-Type": "application/json",
|
669
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
670
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
671
|
+
"X-Xata-Agent": xataAgent,
|
672
|
+
...customHeaders,
|
673
|
+
...hostHeader(fullUrl),
|
674
|
+
Authorization: `Bearer ${apiKey}`
|
675
|
+
});
|
676
|
+
const response = await pool.request(url, {
|
299
677
|
...fetchOptions,
|
300
678
|
method: method.toUpperCase(),
|
301
|
-
body: body
|
302
|
-
headers
|
303
|
-
"Content-Type": "application/json",
|
304
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
305
|
-
"X-Xata-Client-ID": clientID ?? "",
|
306
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
307
|
-
...headers,
|
308
|
-
...hostHeader(fullUrl),
|
309
|
-
Authorization: `Bearer ${apiKey}`
|
310
|
-
},
|
679
|
+
body: parseBody(body, headers),
|
680
|
+
headers,
|
311
681
|
signal
|
312
682
|
});
|
313
|
-
if (response.status === 204) {
|
314
|
-
return {};
|
315
|
-
}
|
316
683
|
const { host, protocol } = parseUrl(response.url);
|
317
684
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
318
685
|
setAttributes({
|
@@ -322,8 +689,17 @@ async function fetch$1({
|
|
322
689
|
[TraceAttributes.HTTP_HOST]: host,
|
323
690
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
324
691
|
});
|
692
|
+
const message = response.headers?.get("x-xata-message");
|
693
|
+
if (message)
|
694
|
+
console.warn(message);
|
695
|
+
if (response.status === 204) {
|
696
|
+
return {};
|
697
|
+
}
|
698
|
+
if (response.status === 429) {
|
699
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
700
|
+
}
|
325
701
|
try {
|
326
|
-
const jsonResponse = await response.json();
|
702
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
327
703
|
if (response.ok) {
|
328
704
|
return jsonResponse;
|
329
705
|
}
|
@@ -335,6 +711,59 @@ async function fetch$1({
|
|
335
711
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
336
712
|
);
|
337
713
|
}
|
714
|
+
function fetchSSERequest({
|
715
|
+
url: path,
|
716
|
+
method,
|
717
|
+
body,
|
718
|
+
headers: customHeaders,
|
719
|
+
pathParams,
|
720
|
+
queryParams,
|
721
|
+
fetch: fetch2,
|
722
|
+
apiKey,
|
723
|
+
endpoint,
|
724
|
+
apiUrl,
|
725
|
+
workspacesApiUrl,
|
726
|
+
onMessage,
|
727
|
+
onError,
|
728
|
+
onClose,
|
729
|
+
signal,
|
730
|
+
clientID,
|
731
|
+
sessionID,
|
732
|
+
clientName,
|
733
|
+
xataAgentExtra
|
734
|
+
}) {
|
735
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
736
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
737
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
738
|
+
void fetchEventSource(url, {
|
739
|
+
method,
|
740
|
+
body: JSON.stringify(body),
|
741
|
+
fetch: fetch2,
|
742
|
+
signal,
|
743
|
+
headers: {
|
744
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
745
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
746
|
+
"X-Xata-Agent": compact([
|
747
|
+
["client", "TS_SDK"],
|
748
|
+
["version", VERSION],
|
749
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
750
|
+
...Object.entries(xataAgentExtra ?? {})
|
751
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
752
|
+
...customHeaders,
|
753
|
+
Authorization: `Bearer ${apiKey}`,
|
754
|
+
"Content-Type": "application/json"
|
755
|
+
},
|
756
|
+
onmessage(ev) {
|
757
|
+
onMessage?.(JSON.parse(ev.data));
|
758
|
+
},
|
759
|
+
onerror(ev) {
|
760
|
+
onError?.(JSON.parse(ev.data));
|
761
|
+
},
|
762
|
+
onclose() {
|
763
|
+
onClose?.();
|
764
|
+
}
|
765
|
+
});
|
766
|
+
}
|
338
767
|
function parseUrl(url) {
|
339
768
|
try {
|
340
769
|
const { host, protocol } = new URL(url);
|
@@ -346,17 +775,12 @@ function parseUrl(url) {
|
|
346
775
|
|
347
776
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
348
777
|
|
349
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
350
778
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
351
779
|
url: "/dbs/{dbName}",
|
352
780
|
method: "get",
|
353
781
|
...variables,
|
354
782
|
signal
|
355
783
|
});
|
356
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
357
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
358
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
359
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
360
784
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
361
785
|
url: "/db/{dbBranchName}",
|
362
786
|
method: "get",
|
@@ -370,6 +794,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
370
794
|
...variables,
|
371
795
|
signal
|
372
796
|
});
|
797
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
798
|
+
url: "/db/{dbBranchName}/copy",
|
799
|
+
method: "post",
|
800
|
+
...variables,
|
801
|
+
signal
|
802
|
+
});
|
373
803
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
374
804
|
url: "/db/{dbBranchName}/metadata",
|
375
805
|
method: "put",
|
@@ -395,7 +825,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
395
825
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
396
826
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
397
827
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
398
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
399
828
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
400
829
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
401
830
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -420,6 +849,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
420
849
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
421
850
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
422
851
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
852
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
423
853
|
const createTable = (variables, signal) => dataPlaneFetch({
|
424
854
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
425
855
|
method: "put",
|
@@ -462,7 +892,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
462
892
|
...variables,
|
463
893
|
signal
|
464
894
|
});
|
895
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
465
896
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
897
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
898
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
899
|
+
method: "get",
|
900
|
+
...variables,
|
901
|
+
signal
|
902
|
+
});
|
903
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
904
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
905
|
+
method: "put",
|
906
|
+
...variables,
|
907
|
+
signal
|
908
|
+
});
|
909
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
910
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
911
|
+
method: "delete",
|
912
|
+
...variables,
|
913
|
+
signal
|
914
|
+
});
|
915
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
916
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
917
|
+
method: "get",
|
918
|
+
...variables,
|
919
|
+
signal
|
920
|
+
});
|
921
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
922
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
923
|
+
method: "put",
|
924
|
+
...variables,
|
925
|
+
signal
|
926
|
+
});
|
927
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
928
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
929
|
+
method: "delete",
|
930
|
+
...variables,
|
931
|
+
signal
|
932
|
+
});
|
466
933
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
467
934
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
468
935
|
method: "get",
|
@@ -492,21 +959,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
492
959
|
...variables,
|
493
960
|
signal
|
494
961
|
});
|
962
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
963
|
+
url: "/db/{dbBranchName}/sql",
|
964
|
+
method: "post",
|
965
|
+
...variables,
|
966
|
+
signal
|
967
|
+
});
|
968
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
969
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
970
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
971
|
+
method: "post",
|
972
|
+
...variables,
|
973
|
+
signal
|
974
|
+
});
|
975
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
495
976
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
496
977
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
978
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
979
|
+
url: "/file/{fileId}",
|
980
|
+
method: "get",
|
981
|
+
...variables,
|
982
|
+
signal
|
983
|
+
});
|
497
984
|
const operationsByTag$2 = {
|
498
|
-
database: {
|
499
|
-
dEPRECATEDgetDatabaseList,
|
500
|
-
dEPRECATEDcreateDatabase,
|
501
|
-
dEPRECATEDdeleteDatabase,
|
502
|
-
dEPRECATEDgetDatabaseMetadata,
|
503
|
-
dEPRECATEDupdateDatabaseMetadata
|
504
|
-
},
|
505
985
|
branch: {
|
506
986
|
getBranchList,
|
507
987
|
getBranchDetails,
|
508
988
|
createBranch,
|
509
989
|
deleteBranch,
|
990
|
+
copyBranch,
|
510
991
|
updateBranchMetadata,
|
511
992
|
getBranchMetadata,
|
512
993
|
getBranchStats,
|
@@ -524,17 +1005,8 @@ const operationsByTag$2 = {
|
|
524
1005
|
compareBranchSchemas,
|
525
1006
|
updateBranchSchema,
|
526
1007
|
previewBranchSchemaEdit,
|
527
|
-
applyBranchSchemaEdit
|
528
|
-
|
529
|
-
records: {
|
530
|
-
branchTransaction,
|
531
|
-
insertRecord,
|
532
|
-
getRecord,
|
533
|
-
insertRecordWithID,
|
534
|
-
updateRecordWithID,
|
535
|
-
upsertRecordWithID,
|
536
|
-
deleteRecord,
|
537
|
-
bulkInsertTableRecords
|
1008
|
+
applyBranchSchemaEdit,
|
1009
|
+
pushBranchMigrations
|
538
1010
|
},
|
539
1011
|
migrationRequests: {
|
540
1012
|
queryMigrationRequests,
|
@@ -558,11 +1030,34 @@ const operationsByTag$2 = {
|
|
558
1030
|
updateColumn,
|
559
1031
|
deleteColumn
|
560
1032
|
},
|
561
|
-
|
1033
|
+
records: {
|
1034
|
+
branchTransaction,
|
1035
|
+
insertRecord,
|
1036
|
+
getRecord,
|
1037
|
+
insertRecordWithID,
|
1038
|
+
updateRecordWithID,
|
1039
|
+
upsertRecordWithID,
|
1040
|
+
deleteRecord,
|
1041
|
+
bulkInsertTableRecords
|
1042
|
+
},
|
1043
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1044
|
+
searchAndFilter: {
|
1045
|
+
queryTable,
|
1046
|
+
searchBranch,
|
1047
|
+
searchTable,
|
1048
|
+
sqlQuery,
|
1049
|
+
vectorSearchTable,
|
1050
|
+
askTable,
|
1051
|
+
askTableSession,
|
1052
|
+
summarizeTable,
|
1053
|
+
aggregateTable
|
1054
|
+
}
|
562
1055
|
};
|
563
1056
|
|
564
1057
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
565
1058
|
|
1059
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1060
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
566
1061
|
const getUser = (variables, signal) => controlPlaneFetch({
|
567
1062
|
url: "/user",
|
568
1063
|
method: "get",
|
@@ -599,6 +1094,18 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
599
1094
|
...variables,
|
600
1095
|
signal
|
601
1096
|
});
|
1097
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1098
|
+
url: "/user/oauth/clients",
|
1099
|
+
method: "get",
|
1100
|
+
...variables,
|
1101
|
+
signal
|
1102
|
+
});
|
1103
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1104
|
+
url: "/user/oauth/tokens",
|
1105
|
+
method: "get",
|
1106
|
+
...variables,
|
1107
|
+
signal
|
1108
|
+
});
|
602
1109
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
603
1110
|
url: "/workspaces",
|
604
1111
|
method: "get",
|
@@ -657,6 +1164,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
657
1164
|
});
|
658
1165
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
659
1166
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1167
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1168
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1169
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1170
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
660
1171
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
661
1172
|
url: "/workspaces/{workspaceId}/regions",
|
662
1173
|
method: "get",
|
@@ -664,8 +1175,9 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
664
1175
|
signal
|
665
1176
|
});
|
666
1177
|
const operationsByTag$1 = {
|
1178
|
+
authOther: { getAuthorizationCode, grantAuthorizationCode },
|
667
1179
|
users: { getUser, updateUser, deleteUser },
|
668
|
-
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1180
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey, getUserOAuthClients, getUserOAuthAccessTokens },
|
669
1181
|
workspaces: {
|
670
1182
|
getWorkspacesList,
|
671
1183
|
createWorkspace,
|
@@ -689,6 +1201,10 @@ const operationsByTag$1 = {
|
|
689
1201
|
deleteDatabase,
|
690
1202
|
getDatabaseMetadata,
|
691
1203
|
updateDatabaseMetadata,
|
1204
|
+
renameDatabase,
|
1205
|
+
getDatabaseGithubSettings,
|
1206
|
+
updateDatabaseGithubSettings,
|
1207
|
+
deleteDatabaseGithubSettings,
|
692
1208
|
listRegions
|
693
1209
|
}
|
694
1210
|
};
|
@@ -709,8 +1225,12 @@ const providers = {
|
|
709
1225
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
710
1226
|
},
|
711
1227
|
staging: {
|
712
|
-
main: "https://staging.
|
713
|
-
workspaces: "https://{workspaceId}.
|
1228
|
+
main: "https://api.staging-xata.dev",
|
1229
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1230
|
+
},
|
1231
|
+
dev: {
|
1232
|
+
main: "https://api.dev-xata.dev",
|
1233
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
714
1234
|
}
|
715
1235
|
};
|
716
1236
|
function isHostProviderAlias(alias) {
|
@@ -728,15 +1248,22 @@ function parseProviderString(provider = "production") {
|
|
728
1248
|
return null;
|
729
1249
|
return { main, workspaces };
|
730
1250
|
}
|
1251
|
+
function buildProviderString(provider) {
|
1252
|
+
if (isHostProviderAlias(provider))
|
1253
|
+
return provider;
|
1254
|
+
return `${provider.main},${provider.workspaces}`;
|
1255
|
+
}
|
731
1256
|
function parseWorkspacesUrlParts(url) {
|
732
1257
|
if (!isString(url))
|
733
1258
|
return null;
|
734
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
735
|
-
const
|
736
|
-
const
|
1259
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1260
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1261
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1262
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1263
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
737
1264
|
if (!match)
|
738
1265
|
return null;
|
739
|
-
return { workspace: match[1], region: match[2]
|
1266
|
+
return { workspace: match[1], region: match[2] };
|
740
1267
|
}
|
741
1268
|
|
742
1269
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -765,15 +1292,19 @@ class XataApiClient {
|
|
765
1292
|
const provider = options.host ?? "production";
|
766
1293
|
const apiKey = options.apiKey ?? getAPIKey();
|
767
1294
|
const trace = options.trace ?? defaultTrace;
|
1295
|
+
const clientID = generateUUID();
|
768
1296
|
if (!apiKey) {
|
769
1297
|
throw new Error("Could not resolve a valid apiKey");
|
770
1298
|
}
|
771
1299
|
__privateSet$7(this, _extraProps, {
|
772
1300
|
apiUrl: getHostUrl(provider, "main"),
|
773
1301
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
774
|
-
|
1302
|
+
fetch: getFetchImplementation(options.fetch),
|
775
1303
|
apiKey,
|
776
|
-
trace
|
1304
|
+
trace,
|
1305
|
+
clientName: options.clientName,
|
1306
|
+
xataAgentExtra: options.xataAgentExtra,
|
1307
|
+
clientID
|
777
1308
|
});
|
778
1309
|
}
|
779
1310
|
get user() {
|
@@ -826,6 +1357,11 @@ class XataApiClient {
|
|
826
1357
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
827
1358
|
return __privateGet$7(this, _namespaces).records;
|
828
1359
|
}
|
1360
|
+
get files() {
|
1361
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1362
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1363
|
+
return __privateGet$7(this, _namespaces).files;
|
1364
|
+
}
|
829
1365
|
get searchAndFilter() {
|
830
1366
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
831
1367
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1034,6 +1570,20 @@ class BranchApi {
|
|
1034
1570
|
...this.extraProps
|
1035
1571
|
});
|
1036
1572
|
}
|
1573
|
+
copyBranch({
|
1574
|
+
workspace,
|
1575
|
+
region,
|
1576
|
+
database,
|
1577
|
+
branch,
|
1578
|
+
destinationBranch,
|
1579
|
+
limit
|
1580
|
+
}) {
|
1581
|
+
return operationsByTag.branch.copyBranch({
|
1582
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1583
|
+
body: { destinationBranch, limit },
|
1584
|
+
...this.extraProps
|
1585
|
+
});
|
1586
|
+
}
|
1037
1587
|
updateBranchMetadata({
|
1038
1588
|
workspace,
|
1039
1589
|
region,
|
@@ -1389,6 +1939,164 @@ class RecordsApi {
|
|
1389
1939
|
});
|
1390
1940
|
}
|
1391
1941
|
}
|
1942
|
+
class FilesApi {
|
1943
|
+
constructor(extraProps) {
|
1944
|
+
this.extraProps = extraProps;
|
1945
|
+
}
|
1946
|
+
getFileItem({
|
1947
|
+
workspace,
|
1948
|
+
region,
|
1949
|
+
database,
|
1950
|
+
branch,
|
1951
|
+
table,
|
1952
|
+
record,
|
1953
|
+
column,
|
1954
|
+
fileId
|
1955
|
+
}) {
|
1956
|
+
return operationsByTag.files.getFileItem({
|
1957
|
+
pathParams: {
|
1958
|
+
workspace,
|
1959
|
+
region,
|
1960
|
+
dbBranchName: `${database}:${branch}`,
|
1961
|
+
tableName: table,
|
1962
|
+
recordId: record,
|
1963
|
+
columnName: column,
|
1964
|
+
fileId
|
1965
|
+
},
|
1966
|
+
...this.extraProps
|
1967
|
+
});
|
1968
|
+
}
|
1969
|
+
putFileItem({
|
1970
|
+
workspace,
|
1971
|
+
region,
|
1972
|
+
database,
|
1973
|
+
branch,
|
1974
|
+
table,
|
1975
|
+
record,
|
1976
|
+
column,
|
1977
|
+
fileId,
|
1978
|
+
file
|
1979
|
+
}) {
|
1980
|
+
return operationsByTag.files.putFileItem({
|
1981
|
+
pathParams: {
|
1982
|
+
workspace,
|
1983
|
+
region,
|
1984
|
+
dbBranchName: `${database}:${branch}`,
|
1985
|
+
tableName: table,
|
1986
|
+
recordId: record,
|
1987
|
+
columnName: column,
|
1988
|
+
fileId
|
1989
|
+
},
|
1990
|
+
// @ts-ignore
|
1991
|
+
body: file,
|
1992
|
+
...this.extraProps
|
1993
|
+
});
|
1994
|
+
}
|
1995
|
+
deleteFileItem({
|
1996
|
+
workspace,
|
1997
|
+
region,
|
1998
|
+
database,
|
1999
|
+
branch,
|
2000
|
+
table,
|
2001
|
+
record,
|
2002
|
+
column,
|
2003
|
+
fileId
|
2004
|
+
}) {
|
2005
|
+
return operationsByTag.files.deleteFileItem({
|
2006
|
+
pathParams: {
|
2007
|
+
workspace,
|
2008
|
+
region,
|
2009
|
+
dbBranchName: `${database}:${branch}`,
|
2010
|
+
tableName: table,
|
2011
|
+
recordId: record,
|
2012
|
+
columnName: column,
|
2013
|
+
fileId
|
2014
|
+
},
|
2015
|
+
...this.extraProps
|
2016
|
+
});
|
2017
|
+
}
|
2018
|
+
getFile({
|
2019
|
+
workspace,
|
2020
|
+
region,
|
2021
|
+
database,
|
2022
|
+
branch,
|
2023
|
+
table,
|
2024
|
+
record,
|
2025
|
+
column
|
2026
|
+
}) {
|
2027
|
+
return operationsByTag.files.getFile({
|
2028
|
+
pathParams: {
|
2029
|
+
workspace,
|
2030
|
+
region,
|
2031
|
+
dbBranchName: `${database}:${branch}`,
|
2032
|
+
tableName: table,
|
2033
|
+
recordId: record,
|
2034
|
+
columnName: column
|
2035
|
+
},
|
2036
|
+
...this.extraProps
|
2037
|
+
});
|
2038
|
+
}
|
2039
|
+
putFile({
|
2040
|
+
workspace,
|
2041
|
+
region,
|
2042
|
+
database,
|
2043
|
+
branch,
|
2044
|
+
table,
|
2045
|
+
record,
|
2046
|
+
column,
|
2047
|
+
file
|
2048
|
+
}) {
|
2049
|
+
return operationsByTag.files.putFile({
|
2050
|
+
pathParams: {
|
2051
|
+
workspace,
|
2052
|
+
region,
|
2053
|
+
dbBranchName: `${database}:${branch}`,
|
2054
|
+
tableName: table,
|
2055
|
+
recordId: record,
|
2056
|
+
columnName: column
|
2057
|
+
},
|
2058
|
+
body: file,
|
2059
|
+
...this.extraProps
|
2060
|
+
});
|
2061
|
+
}
|
2062
|
+
deleteFile({
|
2063
|
+
workspace,
|
2064
|
+
region,
|
2065
|
+
database,
|
2066
|
+
branch,
|
2067
|
+
table,
|
2068
|
+
record,
|
2069
|
+
column
|
2070
|
+
}) {
|
2071
|
+
return operationsByTag.files.deleteFile({
|
2072
|
+
pathParams: {
|
2073
|
+
workspace,
|
2074
|
+
region,
|
2075
|
+
dbBranchName: `${database}:${branch}`,
|
2076
|
+
tableName: table,
|
2077
|
+
recordId: record,
|
2078
|
+
columnName: column
|
2079
|
+
},
|
2080
|
+
...this.extraProps
|
2081
|
+
});
|
2082
|
+
}
|
2083
|
+
fileAccess({
|
2084
|
+
workspace,
|
2085
|
+
region,
|
2086
|
+
fileId,
|
2087
|
+
verify
|
2088
|
+
}) {
|
2089
|
+
return operationsByTag.files.fileAccess({
|
2090
|
+
pathParams: {
|
2091
|
+
workspace,
|
2092
|
+
region,
|
2093
|
+
fileId
|
2094
|
+
},
|
2095
|
+
queryParams: { verify },
|
2096
|
+
...this.extraProps
|
2097
|
+
});
|
2098
|
+
}
|
2099
|
+
}
|
1392
2100
|
class SearchAndFilterApi {
|
1393
2101
|
constructor(extraProps) {
|
1394
2102
|
this.extraProps = extraProps;
|
@@ -1448,6 +2156,53 @@ class SearchAndFilterApi {
|
|
1448
2156
|
...this.extraProps
|
1449
2157
|
});
|
1450
2158
|
}
|
2159
|
+
vectorSearchTable({
|
2160
|
+
workspace,
|
2161
|
+
region,
|
2162
|
+
database,
|
2163
|
+
branch,
|
2164
|
+
table,
|
2165
|
+
queryVector,
|
2166
|
+
column,
|
2167
|
+
similarityFunction,
|
2168
|
+
size,
|
2169
|
+
filter
|
2170
|
+
}) {
|
2171
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2172
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2173
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2174
|
+
...this.extraProps
|
2175
|
+
});
|
2176
|
+
}
|
2177
|
+
askTable({
|
2178
|
+
workspace,
|
2179
|
+
region,
|
2180
|
+
database,
|
2181
|
+
branch,
|
2182
|
+
table,
|
2183
|
+
options
|
2184
|
+
}) {
|
2185
|
+
return operationsByTag.searchAndFilter.askTable({
|
2186
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2187
|
+
body: { ...options },
|
2188
|
+
...this.extraProps
|
2189
|
+
});
|
2190
|
+
}
|
2191
|
+
askTableSession({
|
2192
|
+
workspace,
|
2193
|
+
region,
|
2194
|
+
database,
|
2195
|
+
branch,
|
2196
|
+
table,
|
2197
|
+
sessionId,
|
2198
|
+
message
|
2199
|
+
}) {
|
2200
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2201
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2202
|
+
body: { message },
|
2203
|
+
...this.extraProps
|
2204
|
+
});
|
2205
|
+
}
|
1451
2206
|
summarizeTable({
|
1452
2207
|
workspace,
|
1453
2208
|
region,
|
@@ -1648,11 +2403,13 @@ class MigrationsApi {
|
|
1648
2403
|
region,
|
1649
2404
|
database,
|
1650
2405
|
branch,
|
1651
|
-
schema
|
2406
|
+
schema,
|
2407
|
+
schemaOperations,
|
2408
|
+
branchOperations
|
1652
2409
|
}) {
|
1653
2410
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1654
2411
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1655
|
-
body: { schema },
|
2412
|
+
body: { schema, schemaOperations, branchOperations },
|
1656
2413
|
...this.extraProps
|
1657
2414
|
});
|
1658
2415
|
}
|
@@ -1662,11 +2419,12 @@ class MigrationsApi {
|
|
1662
2419
|
database,
|
1663
2420
|
branch,
|
1664
2421
|
compare,
|
1665
|
-
|
2422
|
+
sourceBranchOperations,
|
2423
|
+
targetBranchOperations
|
1666
2424
|
}) {
|
1667
2425
|
return operationsByTag.migrations.compareBranchSchemas({
|
1668
2426
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1669
|
-
body: {
|
2427
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1670
2428
|
...this.extraProps
|
1671
2429
|
});
|
1672
2430
|
}
|
@@ -1709,6 +2467,19 @@ class MigrationsApi {
|
|
1709
2467
|
...this.extraProps
|
1710
2468
|
});
|
1711
2469
|
}
|
2470
|
+
pushBranchMigrations({
|
2471
|
+
workspace,
|
2472
|
+
region,
|
2473
|
+
database,
|
2474
|
+
branch,
|
2475
|
+
migrations
|
2476
|
+
}) {
|
2477
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2478
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2479
|
+
body: { migrations },
|
2480
|
+
...this.extraProps
|
2481
|
+
});
|
2482
|
+
}
|
1712
2483
|
}
|
1713
2484
|
class DatabaseApi {
|
1714
2485
|
constructor(extraProps) {
|
@@ -1723,11 +2494,13 @@ class DatabaseApi {
|
|
1723
2494
|
createDatabase({
|
1724
2495
|
workspace,
|
1725
2496
|
database,
|
1726
|
-
data
|
2497
|
+
data,
|
2498
|
+
headers
|
1727
2499
|
}) {
|
1728
2500
|
return operationsByTag.databases.createDatabase({
|
1729
2501
|
pathParams: { workspaceId: workspace, dbName: database },
|
1730
2502
|
body: data,
|
2503
|
+
headers,
|
1731
2504
|
...this.extraProps
|
1732
2505
|
});
|
1733
2506
|
}
|
@@ -1760,6 +2533,46 @@ class DatabaseApi {
|
|
1760
2533
|
...this.extraProps
|
1761
2534
|
});
|
1762
2535
|
}
|
2536
|
+
renameDatabase({
|
2537
|
+
workspace,
|
2538
|
+
database,
|
2539
|
+
newName
|
2540
|
+
}) {
|
2541
|
+
return operationsByTag.databases.renameDatabase({
|
2542
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2543
|
+
body: { newName },
|
2544
|
+
...this.extraProps
|
2545
|
+
});
|
2546
|
+
}
|
2547
|
+
getDatabaseGithubSettings({
|
2548
|
+
workspace,
|
2549
|
+
database
|
2550
|
+
}) {
|
2551
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2552
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2553
|
+
...this.extraProps
|
2554
|
+
});
|
2555
|
+
}
|
2556
|
+
updateDatabaseGithubSettings({
|
2557
|
+
workspace,
|
2558
|
+
database,
|
2559
|
+
settings
|
2560
|
+
}) {
|
2561
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2562
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2563
|
+
body: settings,
|
2564
|
+
...this.extraProps
|
2565
|
+
});
|
2566
|
+
}
|
2567
|
+
deleteDatabaseGithubSettings({
|
2568
|
+
workspace,
|
2569
|
+
database
|
2570
|
+
}) {
|
2571
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2572
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2573
|
+
...this.extraProps
|
2574
|
+
});
|
2575
|
+
}
|
1763
2576
|
listRegions({ workspace }) {
|
1764
2577
|
return operationsByTag.databases.listRegions({
|
1765
2578
|
pathParams: { workspaceId: workspace },
|
@@ -1769,29 +2582,269 @@ class DatabaseApi {
|
|
1769
2582
|
}
|
1770
2583
|
|
1771
2584
|
class XataApiPlugin {
|
1772
|
-
|
1773
|
-
|
1774
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2585
|
+
build(options) {
|
2586
|
+
return new XataApiClient(options);
|
1775
2587
|
}
|
1776
2588
|
}
|
1777
2589
|
|
1778
2590
|
class XataPlugin {
|
1779
2591
|
}
|
1780
2592
|
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
2593
|
+
class FilesPlugin extends XataPlugin {
|
2594
|
+
build(pluginOptions) {
|
2595
|
+
return {
|
2596
|
+
download: async (location) => {
|
2597
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2598
|
+
return await getFileItem({
|
2599
|
+
pathParams: {
|
2600
|
+
workspace: "{workspaceId}",
|
2601
|
+
dbBranchName: "{dbBranch}",
|
2602
|
+
region: "{region}",
|
2603
|
+
tableName: table ?? "",
|
2604
|
+
recordId: record ?? "",
|
2605
|
+
columnName: column ?? "",
|
2606
|
+
fileId
|
2607
|
+
},
|
2608
|
+
...pluginOptions,
|
2609
|
+
rawResponse: true
|
2610
|
+
});
|
2611
|
+
},
|
2612
|
+
upload: async (location, file) => {
|
2613
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2614
|
+
return await putFileItem({
|
2615
|
+
pathParams: {
|
2616
|
+
workspace: "{workspaceId}",
|
2617
|
+
dbBranchName: "{dbBranch}",
|
2618
|
+
region: "{region}",
|
2619
|
+
tableName: table ?? "",
|
2620
|
+
recordId: record ?? "",
|
2621
|
+
columnName: column ?? "",
|
2622
|
+
fileId
|
2623
|
+
},
|
2624
|
+
body: file,
|
2625
|
+
...pluginOptions
|
2626
|
+
});
|
2627
|
+
},
|
2628
|
+
delete: async (location) => {
|
2629
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
2630
|
+
return await deleteFileItem({
|
2631
|
+
pathParams: {
|
2632
|
+
workspace: "{workspaceId}",
|
2633
|
+
dbBranchName: "{dbBranch}",
|
2634
|
+
region: "{region}",
|
2635
|
+
tableName: table ?? "",
|
2636
|
+
recordId: record ?? "",
|
2637
|
+
columnName: column ?? "",
|
2638
|
+
fileId
|
2639
|
+
},
|
2640
|
+
...pluginOptions
|
2641
|
+
});
|
2642
|
+
}
|
2643
|
+
};
|
2644
|
+
}
|
2645
|
+
}
|
2646
|
+
|
2647
|
+
function buildTransformString(transformations) {
|
2648
|
+
return transformations.flatMap(
|
2649
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2650
|
+
if (key === "trim") {
|
2651
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2652
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2653
|
+
}
|
2654
|
+
if (key === "gravity" && typeof value === "object") {
|
2655
|
+
const { x = 0.5, y = 0.5 } = value;
|
2656
|
+
return `${key}=${[x, y].join("x")}`;
|
2657
|
+
}
|
2658
|
+
return `${key}=${value}`;
|
2659
|
+
})
|
2660
|
+
).join(",");
|
2661
|
+
}
|
2662
|
+
function transformImage(url, transformations) {
|
2663
|
+
if (!isDefined(url))
|
2664
|
+
return void 0;
|
2665
|
+
const transformationsString = buildTransformString(transformations);
|
2666
|
+
const { hostname, pathname, search } = new URL(url);
|
2667
|
+
return `https://${hostname}/transform/${transformationsString}${pathname}${search}`;
|
2668
|
+
}
|
2669
|
+
|
2670
|
+
var __defProp$6 = Object.defineProperty;
|
2671
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2672
|
+
var __publicField$6 = (obj, key, value) => {
|
2673
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2674
|
+
return value;
|
2675
|
+
};
|
2676
|
+
class XataFile {
|
2677
|
+
constructor(file) {
|
2678
|
+
/**
|
2679
|
+
* Name of this file.
|
2680
|
+
*/
|
2681
|
+
__publicField$6(this, "name");
|
2682
|
+
/**
|
2683
|
+
* Media type of this file.
|
2684
|
+
*/
|
2685
|
+
__publicField$6(this, "mediaType");
|
2686
|
+
/**
|
2687
|
+
* Base64 encoded content of this file.
|
2688
|
+
*/
|
2689
|
+
__publicField$6(this, "base64Content");
|
2690
|
+
/**
|
2691
|
+
* Whether to enable public url for this file.
|
2692
|
+
*/
|
2693
|
+
__publicField$6(this, "enablePublicUrl");
|
2694
|
+
/**
|
2695
|
+
* Timeout for the signed url.
|
2696
|
+
*/
|
2697
|
+
__publicField$6(this, "signedUrlTimeout");
|
2698
|
+
/**
|
2699
|
+
* Size of this file.
|
2700
|
+
*/
|
2701
|
+
__publicField$6(this, "size");
|
2702
|
+
/**
|
2703
|
+
* Version of this file.
|
2704
|
+
*/
|
2705
|
+
__publicField$6(this, "version");
|
2706
|
+
/**
|
2707
|
+
* Url of this file.
|
2708
|
+
*/
|
2709
|
+
__publicField$6(this, "url");
|
2710
|
+
/**
|
2711
|
+
* Signed url of this file.
|
2712
|
+
*/
|
2713
|
+
__publicField$6(this, "signedUrl");
|
2714
|
+
/**
|
2715
|
+
* Attributes of this file.
|
2716
|
+
*/
|
2717
|
+
__publicField$6(this, "attributes");
|
2718
|
+
this.name = file.name;
|
2719
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2720
|
+
this.base64Content = file.base64Content;
|
2721
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2722
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2723
|
+
this.size = file.size;
|
2724
|
+
this.version = file.version;
|
2725
|
+
this.url = file.url;
|
2726
|
+
this.signedUrl = file.signedUrl;
|
2727
|
+
this.attributes = file.attributes;
|
2728
|
+
}
|
2729
|
+
static fromBuffer(buffer, options = {}) {
|
2730
|
+
const base64Content = buffer.toString("base64");
|
2731
|
+
return new XataFile({ ...options, base64Content });
|
2732
|
+
}
|
2733
|
+
toBuffer() {
|
2734
|
+
if (!this.base64Content) {
|
2735
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2736
|
+
}
|
2737
|
+
return Buffer.from(this.base64Content, "base64");
|
2738
|
+
}
|
2739
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2740
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2741
|
+
return this.fromUint8Array(uint8Array, options);
|
2742
|
+
}
|
2743
|
+
toArrayBuffer() {
|
2744
|
+
if (!this.base64Content) {
|
2745
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2746
|
+
}
|
2747
|
+
const binary = atob(this.base64Content);
|
2748
|
+
return new ArrayBuffer(binary.length);
|
2749
|
+
}
|
2750
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2751
|
+
let binary = "";
|
2752
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2753
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2754
|
+
}
|
2755
|
+
const base64Content = btoa(binary);
|
2756
|
+
return new XataFile({ ...options, base64Content });
|
2757
|
+
}
|
2758
|
+
toUint8Array() {
|
2759
|
+
if (!this.base64Content) {
|
2760
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2761
|
+
}
|
2762
|
+
const binary = atob(this.base64Content);
|
2763
|
+
const uint8Array = new Uint8Array(binary.length);
|
2764
|
+
for (let i = 0; i < binary.length; i++) {
|
2765
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2766
|
+
}
|
2767
|
+
return uint8Array;
|
2768
|
+
}
|
2769
|
+
static async fromBlob(file, options = {}) {
|
2770
|
+
const name = options.name ?? file.name;
|
2771
|
+
const mediaType = file.type;
|
2772
|
+
const arrayBuffer = await file.arrayBuffer();
|
2773
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2774
|
+
}
|
2775
|
+
toBlob() {
|
2776
|
+
if (!this.base64Content) {
|
2777
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2778
|
+
}
|
2779
|
+
const arrayBuffer = this.toArrayBuffer();
|
2780
|
+
return new Blob([arrayBuffer], { type: this.mediaType });
|
2781
|
+
}
|
2782
|
+
static fromString(string, options = {}) {
|
2783
|
+
const base64Content = btoa(string);
|
2784
|
+
return new XataFile({ ...options, base64Content });
|
2785
|
+
}
|
2786
|
+
toString() {
|
2787
|
+
if (!this.base64Content) {
|
2788
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2789
|
+
}
|
2790
|
+
return atob(this.base64Content);
|
2791
|
+
}
|
2792
|
+
static fromBase64(base64Content, options = {}) {
|
2793
|
+
return new XataFile({ ...options, base64Content });
|
2794
|
+
}
|
2795
|
+
toBase64() {
|
2796
|
+
if (!this.base64Content) {
|
2797
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2798
|
+
}
|
2799
|
+
return this.base64Content;
|
2800
|
+
}
|
2801
|
+
transform(...options) {
|
2802
|
+
return {
|
2803
|
+
url: transformImage(this.url, options),
|
2804
|
+
signedUrl: transformImage(this.signedUrl, options)
|
2805
|
+
};
|
2806
|
+
}
|
1786
2807
|
}
|
2808
|
+
const parseInputFileEntry = async (entry) => {
|
2809
|
+
if (!isDefined(entry))
|
2810
|
+
return null;
|
2811
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2812
|
+
return compactObject({ id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout });
|
2813
|
+
};
|
1787
2814
|
|
1788
2815
|
function cleanFilter(filter) {
|
1789
|
-
if (!filter)
|
2816
|
+
if (!isDefined(filter))
|
1790
2817
|
return void 0;
|
1791
|
-
|
1792
|
-
|
2818
|
+
if (!isObject(filter))
|
2819
|
+
return filter;
|
2820
|
+
const values = Object.fromEntries(
|
2821
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2822
|
+
if (!isDefined(value))
|
2823
|
+
return acc;
|
2824
|
+
if (Array.isArray(value)) {
|
2825
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2826
|
+
if (clean.length === 0)
|
2827
|
+
return acc;
|
2828
|
+
return [...acc, [key, clean]];
|
2829
|
+
}
|
2830
|
+
if (isObject(value)) {
|
2831
|
+
const clean = cleanFilter(value);
|
2832
|
+
if (!isDefined(clean))
|
2833
|
+
return acc;
|
2834
|
+
return [...acc, [key, clean]];
|
2835
|
+
}
|
2836
|
+
return [...acc, [key, value]];
|
2837
|
+
}, [])
|
2838
|
+
);
|
2839
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
1793
2840
|
}
|
1794
2841
|
|
2842
|
+
var __defProp$5 = Object.defineProperty;
|
2843
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2844
|
+
var __publicField$5 = (obj, key, value) => {
|
2845
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
2846
|
+
return value;
|
2847
|
+
};
|
1795
2848
|
var __accessCheck$6 = (obj, member, msg) => {
|
1796
2849
|
if (!member.has(obj))
|
1797
2850
|
throw TypeError("Cannot " + msg);
|
@@ -1814,22 +2867,58 @@ var _query, _page;
|
|
1814
2867
|
class Page {
|
1815
2868
|
constructor(query, meta, records = []) {
|
1816
2869
|
__privateAdd$6(this, _query, void 0);
|
2870
|
+
/**
|
2871
|
+
* Page metadata, required to retrieve additional records.
|
2872
|
+
*/
|
2873
|
+
__publicField$5(this, "meta");
|
2874
|
+
/**
|
2875
|
+
* The set of results for this page.
|
2876
|
+
*/
|
2877
|
+
__publicField$5(this, "records");
|
1817
2878
|
__privateSet$6(this, _query, query);
|
1818
2879
|
this.meta = meta;
|
1819
2880
|
this.records = new RecordArray(this, records);
|
1820
2881
|
}
|
2882
|
+
/**
|
2883
|
+
* Retrieves the next page of results.
|
2884
|
+
* @param size Maximum number of results to be retrieved.
|
2885
|
+
* @param offset Number of results to skip when retrieving the results.
|
2886
|
+
* @returns The next page or results.
|
2887
|
+
*/
|
1821
2888
|
async nextPage(size, offset) {
|
1822
2889
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1823
2890
|
}
|
2891
|
+
/**
|
2892
|
+
* Retrieves the previous page of results.
|
2893
|
+
* @param size Maximum number of results to be retrieved.
|
2894
|
+
* @param offset Number of results to skip when retrieving the results.
|
2895
|
+
* @returns The previous page or results.
|
2896
|
+
*/
|
1824
2897
|
async previousPage(size, offset) {
|
1825
2898
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1826
2899
|
}
|
2900
|
+
/**
|
2901
|
+
* Retrieves the start page of results.
|
2902
|
+
* @param size Maximum number of results to be retrieved.
|
2903
|
+
* @param offset Number of results to skip when retrieving the results.
|
2904
|
+
* @returns The start page or results.
|
2905
|
+
*/
|
1827
2906
|
async startPage(size, offset) {
|
1828
2907
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1829
2908
|
}
|
2909
|
+
/**
|
2910
|
+
* Retrieves the end page of results.
|
2911
|
+
* @param size Maximum number of results to be retrieved.
|
2912
|
+
* @param offset Number of results to skip when retrieving the results.
|
2913
|
+
* @returns The end page or results.
|
2914
|
+
*/
|
1830
2915
|
async endPage(size, offset) {
|
1831
2916
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1832
2917
|
}
|
2918
|
+
/**
|
2919
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2920
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2921
|
+
*/
|
1833
2922
|
hasNextPage() {
|
1834
2923
|
return this.meta.page.more;
|
1835
2924
|
}
|
@@ -1842,7 +2931,7 @@ const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1842
2931
|
function isCursorPaginationOptions(options) {
|
1843
2932
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1844
2933
|
}
|
1845
|
-
const _RecordArray = class extends Array {
|
2934
|
+
const _RecordArray = class _RecordArray extends Array {
|
1846
2935
|
constructor(...args) {
|
1847
2936
|
super(..._RecordArray.parseConstructorParams(...args));
|
1848
2937
|
__privateAdd$6(this, _page, void 0);
|
@@ -1861,32 +2950,67 @@ const _RecordArray = class extends Array {
|
|
1861
2950
|
toArray() {
|
1862
2951
|
return new Array(...this);
|
1863
2952
|
}
|
2953
|
+
toSerializable() {
|
2954
|
+
return JSON.parse(this.toString());
|
2955
|
+
}
|
2956
|
+
toString() {
|
2957
|
+
return JSON.stringify(this.toArray());
|
2958
|
+
}
|
1864
2959
|
map(callbackfn, thisArg) {
|
1865
2960
|
return this.toArray().map(callbackfn, thisArg);
|
1866
2961
|
}
|
2962
|
+
/**
|
2963
|
+
* Retrieve next page of records
|
2964
|
+
*
|
2965
|
+
* @returns A new array of objects
|
2966
|
+
*/
|
1867
2967
|
async nextPage(size, offset) {
|
1868
2968
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1869
2969
|
return new _RecordArray(newPage);
|
1870
2970
|
}
|
2971
|
+
/**
|
2972
|
+
* Retrieve previous page of records
|
2973
|
+
*
|
2974
|
+
* @returns A new array of objects
|
2975
|
+
*/
|
1871
2976
|
async previousPage(size, offset) {
|
1872
2977
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1873
2978
|
return new _RecordArray(newPage);
|
1874
2979
|
}
|
2980
|
+
/**
|
2981
|
+
* Retrieve start page of records
|
2982
|
+
*
|
2983
|
+
* @returns A new array of objects
|
2984
|
+
*/
|
1875
2985
|
async startPage(size, offset) {
|
1876
2986
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1877
2987
|
return new _RecordArray(newPage);
|
1878
2988
|
}
|
2989
|
+
/**
|
2990
|
+
* Retrieve end page of records
|
2991
|
+
*
|
2992
|
+
* @returns A new array of objects
|
2993
|
+
*/
|
1879
2994
|
async endPage(size, offset) {
|
1880
2995
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1881
2996
|
return new _RecordArray(newPage);
|
1882
2997
|
}
|
2998
|
+
/**
|
2999
|
+
* @returns Boolean indicating if there is a next page
|
3000
|
+
*/
|
1883
3001
|
hasNextPage() {
|
1884
3002
|
return __privateGet$6(this, _page).meta.page.more;
|
1885
3003
|
}
|
1886
3004
|
};
|
1887
|
-
let RecordArray = _RecordArray;
|
1888
3005
|
_page = new WeakMap();
|
3006
|
+
let RecordArray = _RecordArray;
|
1889
3007
|
|
3008
|
+
var __defProp$4 = Object.defineProperty;
|
3009
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
3010
|
+
var __publicField$4 = (obj, key, value) => {
|
3011
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
3012
|
+
return value;
|
3013
|
+
};
|
1890
3014
|
var __accessCheck$5 = (obj, member, msg) => {
|
1891
3015
|
if (!member.has(obj))
|
1892
3016
|
throw TypeError("Cannot " + msg);
|
@@ -1910,14 +3034,15 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
1910
3034
|
return method;
|
1911
3035
|
};
|
1912
3036
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1913
|
-
const _Query = class {
|
3037
|
+
const _Query = class _Query {
|
1914
3038
|
constructor(repository, table, data, rawParent) {
|
1915
3039
|
__privateAdd$5(this, _cleanFilterConstraint);
|
1916
3040
|
__privateAdd$5(this, _table$1, void 0);
|
1917
3041
|
__privateAdd$5(this, _repository, void 0);
|
1918
3042
|
__privateAdd$5(this, _data, { filter: {} });
|
1919
|
-
|
1920
|
-
this
|
3043
|
+
// Implements pagination
|
3044
|
+
__publicField$4(this, "meta", { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } });
|
3045
|
+
__publicField$4(this, "records", new RecordArray(this, []));
|
1921
3046
|
__privateSet$5(this, _table$1, table);
|
1922
3047
|
if (repository) {
|
1923
3048
|
__privateSet$5(this, _repository, repository);
|
@@ -1932,6 +3057,7 @@ const _Query = class {
|
|
1932
3057
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1933
3058
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1934
3059
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
3060
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1935
3061
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1936
3062
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
1937
3063
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -1952,18 +3078,38 @@ const _Query = class {
|
|
1952
3078
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1953
3079
|
return toBase64(key);
|
1954
3080
|
}
|
3081
|
+
/**
|
3082
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3083
|
+
* @param queries An array of subqueries.
|
3084
|
+
* @returns A new Query object.
|
3085
|
+
*/
|
1955
3086
|
any(...queries) {
|
1956
3087
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1957
3088
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
1958
3089
|
}
|
3090
|
+
/**
|
3091
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3092
|
+
* @param queries An array of subqueries.
|
3093
|
+
* @returns A new Query object.
|
3094
|
+
*/
|
1959
3095
|
all(...queries) {
|
1960
3096
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1961
3097
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1962
3098
|
}
|
3099
|
+
/**
|
3100
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3101
|
+
* @param queries An array of subqueries.
|
3102
|
+
* @returns A new Query object.
|
3103
|
+
*/
|
1963
3104
|
not(...queries) {
|
1964
3105
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1965
3106
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
1966
3107
|
}
|
3108
|
+
/**
|
3109
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3110
|
+
* @param queries An array of subqueries.
|
3111
|
+
* @returns A new Query object.
|
3112
|
+
*/
|
1967
3113
|
none(...queries) {
|
1968
3114
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1969
3115
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -1986,6 +3132,11 @@ const _Query = class {
|
|
1986
3132
|
const sort = [...originalSort, { column, direction }];
|
1987
3133
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1988
3134
|
}
|
3135
|
+
/**
|
3136
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3137
|
+
* @param columns Array of column names to be returned by the query.
|
3138
|
+
* @returns A new Query object.
|
3139
|
+
*/
|
1989
3140
|
select(columns) {
|
1990
3141
|
return new _Query(
|
1991
3142
|
__privateGet$5(this, _repository),
|
@@ -1998,6 +3149,12 @@ const _Query = class {
|
|
1998
3149
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1999
3150
|
return __privateGet$5(this, _repository).query(query);
|
2000
3151
|
}
|
3152
|
+
/**
|
3153
|
+
* Get results in an iterator
|
3154
|
+
*
|
3155
|
+
* @async
|
3156
|
+
* @returns Async interable of results
|
3157
|
+
*/
|
2001
3158
|
async *[Symbol.asyncIterator]() {
|
2002
3159
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2003
3160
|
yield record;
|
@@ -2058,26 +3215,53 @@ const _Query = class {
|
|
2058
3215
|
);
|
2059
3216
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2060
3217
|
}
|
3218
|
+
/**
|
3219
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3220
|
+
* @param ttl The cache TTL in milliseconds.
|
3221
|
+
* @returns A new Query object.
|
3222
|
+
*/
|
2061
3223
|
cache(ttl) {
|
2062
3224
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2063
3225
|
}
|
3226
|
+
/**
|
3227
|
+
* Retrieve next page of records
|
3228
|
+
*
|
3229
|
+
* @returns A new page object.
|
3230
|
+
*/
|
2064
3231
|
nextPage(size, offset) {
|
2065
3232
|
return this.startPage(size, offset);
|
2066
3233
|
}
|
3234
|
+
/**
|
3235
|
+
* Retrieve previous page of records
|
3236
|
+
*
|
3237
|
+
* @returns A new page object
|
3238
|
+
*/
|
2067
3239
|
previousPage(size, offset) {
|
2068
3240
|
return this.startPage(size, offset);
|
2069
3241
|
}
|
3242
|
+
/**
|
3243
|
+
* Retrieve start page of records
|
3244
|
+
*
|
3245
|
+
* @returns A new page object
|
3246
|
+
*/
|
2070
3247
|
startPage(size, offset) {
|
2071
3248
|
return this.getPaginated({ pagination: { size, offset } });
|
2072
3249
|
}
|
3250
|
+
/**
|
3251
|
+
* Retrieve last page of records
|
3252
|
+
*
|
3253
|
+
* @returns A new page object
|
3254
|
+
*/
|
2073
3255
|
endPage(size, offset) {
|
2074
3256
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2075
3257
|
}
|
3258
|
+
/**
|
3259
|
+
* @returns Boolean indicating if there is a next page
|
3260
|
+
*/
|
2076
3261
|
hasNextPage() {
|
2077
3262
|
return this.meta.page.more;
|
2078
3263
|
}
|
2079
3264
|
};
|
2080
|
-
let Query = _Query;
|
2081
3265
|
_table$1 = new WeakMap();
|
2082
3266
|
_repository = new WeakMap();
|
2083
3267
|
_data = new WeakMap();
|
@@ -2092,6 +3276,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2092
3276
|
}
|
2093
3277
|
return value;
|
2094
3278
|
};
|
3279
|
+
let Query = _Query;
|
2095
3280
|
function cleanParent(data, parent) {
|
2096
3281
|
if (isCursorPaginationOptions(data.pagination)) {
|
2097
3282
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2099,6 +3284,21 @@ function cleanParent(data, parent) {
|
|
2099
3284
|
return parent;
|
2100
3285
|
}
|
2101
3286
|
|
3287
|
+
const RecordColumnTypes = [
|
3288
|
+
"bool",
|
3289
|
+
"int",
|
3290
|
+
"float",
|
3291
|
+
"string",
|
3292
|
+
"text",
|
3293
|
+
"email",
|
3294
|
+
"multiple",
|
3295
|
+
"link",
|
3296
|
+
"object",
|
3297
|
+
"datetime",
|
3298
|
+
"vector",
|
3299
|
+
"file[]",
|
3300
|
+
"file"
|
3301
|
+
];
|
2102
3302
|
function isIdentifiable(x) {
|
2103
3303
|
return isObject(x) && isString(x?.id);
|
2104
3304
|
}
|
@@ -2112,7 +3312,11 @@ function isSortFilterString(value) {
|
|
2112
3312
|
return isString(value);
|
2113
3313
|
}
|
2114
3314
|
function isSortFilterBase(filter) {
|
2115
|
-
return isObject(filter) && Object.
|
3315
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3316
|
+
if (key === "*")
|
3317
|
+
return value === "random";
|
3318
|
+
return value === "asc" || value === "desc";
|
3319
|
+
});
|
2116
3320
|
}
|
2117
3321
|
function isSortFilterObject(filter) {
|
2118
3322
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2153,7 +3357,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2153
3357
|
__accessCheck$4(obj, member, "access private method");
|
2154
3358
|
return method;
|
2155
3359
|
};
|
2156
|
-
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;
|
3360
|
+
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;
|
2157
3361
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2158
3362
|
class Repository extends Query {
|
2159
3363
|
}
|
@@ -2175,6 +3379,7 @@ class RestRepository extends Query {
|
|
2175
3379
|
__privateAdd$4(this, _setCacheQuery);
|
2176
3380
|
__privateAdd$4(this, _getCacheQuery);
|
2177
3381
|
__privateAdd$4(this, _getSchemaTables$1);
|
3382
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2178
3383
|
__privateAdd$4(this, _table, void 0);
|
2179
3384
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2180
3385
|
__privateAdd$4(this, _db, void 0);
|
@@ -2185,10 +3390,7 @@ class RestRepository extends Query {
|
|
2185
3390
|
__privateSet$4(this, _db, options.db);
|
2186
3391
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2187
3392
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2188
|
-
__privateSet$4(this, _getFetchProps,
|
2189
|
-
const props = await options.pluginOptions.getFetchProps();
|
2190
|
-
return { ...props, sessionID: generateUUID() };
|
2191
|
-
});
|
3393
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2192
3394
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2193
3395
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2194
3396
|
return trace(name, fn, {
|
@@ -2245,7 +3447,6 @@ class RestRepository extends Query {
|
|
2245
3447
|
}
|
2246
3448
|
const id = extractId(a);
|
2247
3449
|
if (id) {
|
2248
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2249
3450
|
try {
|
2250
3451
|
const response = await getRecord({
|
2251
3452
|
pathParams: {
|
@@ -2256,7 +3457,7 @@ class RestRepository extends Query {
|
|
2256
3457
|
recordId: id
|
2257
3458
|
},
|
2258
3459
|
queryParams: { columns },
|
2259
|
-
...
|
3460
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2260
3461
|
});
|
2261
3462
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2262
3463
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2305,13 +3506,19 @@ class RestRepository extends Query {
|
|
2305
3506
|
const result = await this.read(a, columns);
|
2306
3507
|
return result;
|
2307
3508
|
}
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
3509
|
+
try {
|
3510
|
+
if (isString(a) && isObject(b)) {
|
3511
|
+
const columns = isStringArray(c) ? c : void 0;
|
3512
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3513
|
+
}
|
3514
|
+
if (isObject(a) && isString(a.id)) {
|
3515
|
+
const columns = isStringArray(b) ? b : void 0;
|
3516
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3517
|
+
}
|
3518
|
+
} catch (error) {
|
3519
|
+
if (error.status === 422)
|
3520
|
+
return null;
|
3521
|
+
throw error;
|
2315
3522
|
}
|
2316
3523
|
throw new Error("Invalid arguments for update method");
|
2317
3524
|
});
|
@@ -2350,12 +3557,22 @@ class RestRepository extends Query {
|
|
2350
3557
|
return result;
|
2351
3558
|
}
|
2352
3559
|
if (isString(a) && isObject(b)) {
|
3560
|
+
if (a === "")
|
3561
|
+
throw new Error("The id can't be empty");
|
2353
3562
|
const columns = isStringArray(c) ? c : void 0;
|
2354
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3563
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2355
3564
|
}
|
2356
3565
|
if (isObject(a) && isString(a.id)) {
|
3566
|
+
if (a.id === "")
|
3567
|
+
throw new Error("The id can't be empty");
|
2357
3568
|
const columns = isStringArray(c) ? c : void 0;
|
2358
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3569
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3570
|
+
}
|
3571
|
+
if (!isDefined(a) && isObject(b)) {
|
3572
|
+
return await this.create(b, c);
|
3573
|
+
}
|
3574
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3575
|
+
return await this.create(a, b);
|
2359
3576
|
}
|
2360
3577
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2361
3578
|
});
|
@@ -2372,12 +3589,22 @@ class RestRepository extends Query {
|
|
2372
3589
|
return result;
|
2373
3590
|
}
|
2374
3591
|
if (isString(a) && isObject(b)) {
|
3592
|
+
if (a === "")
|
3593
|
+
throw new Error("The id can't be empty");
|
2375
3594
|
const columns = isStringArray(c) ? c : void 0;
|
2376
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3595
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2377
3596
|
}
|
2378
3597
|
if (isObject(a) && isString(a.id)) {
|
3598
|
+
if (a.id === "")
|
3599
|
+
throw new Error("The id can't be empty");
|
2379
3600
|
const columns = isStringArray(c) ? c : void 0;
|
2380
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3601
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3602
|
+
}
|
3603
|
+
if (!isDefined(a) && isObject(b)) {
|
3604
|
+
return await this.create(b, c);
|
3605
|
+
}
|
3606
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3607
|
+
return await this.create(a, b);
|
2381
3608
|
}
|
2382
3609
|
throw new Error("Invalid arguments for createOrReplace method");
|
2383
3610
|
});
|
@@ -2428,7 +3655,6 @@ class RestRepository extends Query {
|
|
2428
3655
|
}
|
2429
3656
|
async search(query, options = {}) {
|
2430
3657
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2431
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2432
3658
|
const { records } = await searchTable({
|
2433
3659
|
pathParams: {
|
2434
3660
|
workspace: "{workspaceId}",
|
@@ -2442,9 +3668,33 @@ class RestRepository extends Query {
|
|
2442
3668
|
prefix: options.prefix,
|
2443
3669
|
highlight: options.highlight,
|
2444
3670
|
filter: options.filter,
|
2445
|
-
boosters: options.boosters
|
3671
|
+
boosters: options.boosters,
|
3672
|
+
page: options.page,
|
3673
|
+
target: options.target
|
3674
|
+
},
|
3675
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3676
|
+
});
|
3677
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3678
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3679
|
+
});
|
3680
|
+
}
|
3681
|
+
async vectorSearch(column, query, options) {
|
3682
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3683
|
+
const { records } = await vectorSearchTable({
|
3684
|
+
pathParams: {
|
3685
|
+
workspace: "{workspaceId}",
|
3686
|
+
dbBranchName: "{dbBranch}",
|
3687
|
+
region: "{region}",
|
3688
|
+
tableName: __privateGet$4(this, _table)
|
2446
3689
|
},
|
2447
|
-
|
3690
|
+
body: {
|
3691
|
+
column,
|
3692
|
+
queryVector: query,
|
3693
|
+
similarityFunction: options?.similarityFunction,
|
3694
|
+
size: options?.size,
|
3695
|
+
filter: options?.filter
|
3696
|
+
},
|
3697
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2448
3698
|
});
|
2449
3699
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2450
3700
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2452,7 +3702,6 @@ class RestRepository extends Query {
|
|
2452
3702
|
}
|
2453
3703
|
async aggregate(aggs, filter) {
|
2454
3704
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2455
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2456
3705
|
const result = await aggregateTable({
|
2457
3706
|
pathParams: {
|
2458
3707
|
workspace: "{workspaceId}",
|
@@ -2461,7 +3710,7 @@ class RestRepository extends Query {
|
|
2461
3710
|
tableName: __privateGet$4(this, _table)
|
2462
3711
|
},
|
2463
3712
|
body: { aggs, filter },
|
2464
|
-
...
|
3713
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2465
3714
|
});
|
2466
3715
|
return result;
|
2467
3716
|
});
|
@@ -2472,7 +3721,6 @@ class RestRepository extends Query {
|
|
2472
3721
|
if (cacheQuery)
|
2473
3722
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2474
3723
|
const data = query.getQueryOptions();
|
2475
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2476
3724
|
const { meta, records: objects } = await queryTable({
|
2477
3725
|
pathParams: {
|
2478
3726
|
workspace: "{workspaceId}",
|
@@ -2484,10 +3732,11 @@ class RestRepository extends Query {
|
|
2484
3732
|
filter: cleanFilter(data.filter),
|
2485
3733
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2486
3734
|
page: data.pagination,
|
2487
|
-
columns: data.columns ?? ["*"]
|
3735
|
+
columns: data.columns ?? ["*"],
|
3736
|
+
consistency: data.consistency
|
2488
3737
|
},
|
2489
3738
|
fetchOptions: data.fetchOptions,
|
2490
|
-
...
|
3739
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2491
3740
|
});
|
2492
3741
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2493
3742
|
const records = objects.map(
|
@@ -2500,7 +3749,6 @@ class RestRepository extends Query {
|
|
2500
3749
|
async summarizeTable(query, summaries, summariesFilter) {
|
2501
3750
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2502
3751
|
const data = query.getQueryOptions();
|
2503
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2504
3752
|
const result = await summarizeTable({
|
2505
3753
|
pathParams: {
|
2506
3754
|
workspace: "{workspaceId}",
|
@@ -2512,15 +3760,49 @@ class RestRepository extends Query {
|
|
2512
3760
|
filter: cleanFilter(data.filter),
|
2513
3761
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2514
3762
|
columns: data.columns,
|
3763
|
+
consistency: data.consistency,
|
2515
3764
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2516
3765
|
summaries,
|
2517
3766
|
summariesFilter
|
2518
3767
|
},
|
2519
|
-
...
|
3768
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2520
3769
|
});
|
2521
3770
|
return result;
|
2522
3771
|
});
|
2523
3772
|
}
|
3773
|
+
ask(question, options) {
|
3774
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3775
|
+
const params = {
|
3776
|
+
pathParams: {
|
3777
|
+
workspace: "{workspaceId}",
|
3778
|
+
dbBranchName: "{dbBranch}",
|
3779
|
+
region: "{region}",
|
3780
|
+
tableName: __privateGet$4(this, _table),
|
3781
|
+
sessionId: options?.sessionId
|
3782
|
+
},
|
3783
|
+
body: {
|
3784
|
+
...questionParam,
|
3785
|
+
rules: options?.rules,
|
3786
|
+
searchType: options?.searchType,
|
3787
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3788
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3789
|
+
},
|
3790
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3791
|
+
};
|
3792
|
+
if (options?.onMessage) {
|
3793
|
+
fetchSSERequest({
|
3794
|
+
endpoint: "dataPlane",
|
3795
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3796
|
+
method: "POST",
|
3797
|
+
onMessage: (message) => {
|
3798
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3799
|
+
},
|
3800
|
+
...params
|
3801
|
+
});
|
3802
|
+
} else {
|
3803
|
+
return askTableSession(params);
|
3804
|
+
}
|
3805
|
+
}
|
2524
3806
|
}
|
2525
3807
|
_table = new WeakMap();
|
2526
3808
|
_getFetchProps = new WeakMap();
|
@@ -2530,8 +3812,7 @@ _schemaTables$2 = new WeakMap();
|
|
2530
3812
|
_trace = new WeakMap();
|
2531
3813
|
_insertRecordWithoutId = new WeakSet();
|
2532
3814
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2533
|
-
const
|
2534
|
-
const record = transformObjectLinks(object);
|
3815
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2535
3816
|
const response = await insertRecord({
|
2536
3817
|
pathParams: {
|
2537
3818
|
workspace: "{workspaceId}",
|
@@ -2541,15 +3822,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2541
3822
|
},
|
2542
3823
|
queryParams: { columns },
|
2543
3824
|
body: record,
|
2544
|
-
...
|
3825
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2545
3826
|
});
|
2546
3827
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2547
3828
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2548
3829
|
};
|
2549
3830
|
_insertRecordWithId = new WeakSet();
|
2550
3831
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2551
|
-
|
2552
|
-
|
3832
|
+
if (!recordId)
|
3833
|
+
return null;
|
3834
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2553
3835
|
const response = await insertRecordWithID({
|
2554
3836
|
pathParams: {
|
2555
3837
|
workspace: "{workspaceId}",
|
@@ -2560,30 +3842,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2560
3842
|
},
|
2561
3843
|
body: record,
|
2562
3844
|
queryParams: { createOnly, columns, ifVersion },
|
2563
|
-
...
|
3845
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2564
3846
|
});
|
2565
3847
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2566
3848
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2567
3849
|
};
|
2568
3850
|
_insertRecords = new WeakSet();
|
2569
3851
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2570
|
-
const
|
2571
|
-
|
2572
|
-
|
2573
|
-
|
2574
|
-
|
2575
|
-
BULK_OPERATION_MAX_SIZE
|
2576
|
-
);
|
3852
|
+
const operations = await promiseMap(objects, async (object) => {
|
3853
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3854
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3855
|
+
});
|
3856
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2577
3857
|
const ids = [];
|
2578
|
-
for (const
|
3858
|
+
for (const operations2 of chunkedOperations) {
|
2579
3859
|
const { results } = await branchTransaction({
|
2580
3860
|
pathParams: {
|
2581
3861
|
workspace: "{workspaceId}",
|
2582
3862
|
dbBranchName: "{dbBranch}",
|
2583
3863
|
region: "{region}"
|
2584
3864
|
},
|
2585
|
-
body: { operations },
|
2586
|
-
...
|
3865
|
+
body: { operations: operations2 },
|
3866
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2587
3867
|
});
|
2588
3868
|
for (const result of results) {
|
2589
3869
|
if (result.operation === "insert") {
|
@@ -2597,8 +3877,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2597
3877
|
};
|
2598
3878
|
_updateRecordWithID = new WeakSet();
|
2599
3879
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2600
|
-
|
2601
|
-
|
3880
|
+
if (!recordId)
|
3881
|
+
return null;
|
3882
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2602
3883
|
try {
|
2603
3884
|
const response = await updateRecordWithID({
|
2604
3885
|
pathParams: {
|
@@ -2610,7 +3891,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2610
3891
|
},
|
2611
3892
|
queryParams: { columns, ifVersion },
|
2612
3893
|
body: record,
|
2613
|
-
...
|
3894
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2614
3895
|
});
|
2615
3896
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2616
3897
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2623,23 +3904,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2623
3904
|
};
|
2624
3905
|
_updateRecords = new WeakSet();
|
2625
3906
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2626
|
-
const
|
2627
|
-
|
2628
|
-
|
2629
|
-
|
2630
|
-
|
2631
|
-
BULK_OPERATION_MAX_SIZE
|
2632
|
-
);
|
3907
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3908
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3909
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3910
|
+
});
|
3911
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2633
3912
|
const ids = [];
|
2634
|
-
for (const
|
3913
|
+
for (const operations2 of chunkedOperations) {
|
2635
3914
|
const { results } = await branchTransaction({
|
2636
3915
|
pathParams: {
|
2637
3916
|
workspace: "{workspaceId}",
|
2638
3917
|
dbBranchName: "{dbBranch}",
|
2639
3918
|
region: "{region}"
|
2640
3919
|
},
|
2641
|
-
body: { operations },
|
2642
|
-
...
|
3920
|
+
body: { operations: operations2 },
|
3921
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2643
3922
|
});
|
2644
3923
|
for (const result of results) {
|
2645
3924
|
if (result.operation === "update") {
|
@@ -2653,7 +3932,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2653
3932
|
};
|
2654
3933
|
_upsertRecordWithID = new WeakSet();
|
2655
3934
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2656
|
-
|
3935
|
+
if (!recordId)
|
3936
|
+
return null;
|
2657
3937
|
const response = await upsertRecordWithID({
|
2658
3938
|
pathParams: {
|
2659
3939
|
workspace: "{workspaceId}",
|
@@ -2664,14 +3944,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2664
3944
|
},
|
2665
3945
|
queryParams: { columns, ifVersion },
|
2666
3946
|
body: object,
|
2667
|
-
...
|
3947
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2668
3948
|
});
|
2669
3949
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2670
3950
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2671
3951
|
};
|
2672
3952
|
_deleteRecord = new WeakSet();
|
2673
3953
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2674
|
-
|
3954
|
+
if (!recordId)
|
3955
|
+
return null;
|
2675
3956
|
try {
|
2676
3957
|
const response = await deleteRecord({
|
2677
3958
|
pathParams: {
|
@@ -2682,7 +3963,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2682
3963
|
recordId
|
2683
3964
|
},
|
2684
3965
|
queryParams: { columns },
|
2685
|
-
...
|
3966
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2686
3967
|
});
|
2687
3968
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2688
3969
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2695,9 +3976,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2695
3976
|
};
|
2696
3977
|
_deleteRecords = new WeakSet();
|
2697
3978
|
deleteRecords_fn = async function(recordIds) {
|
2698
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2699
3979
|
const chunkedOperations = chunk(
|
2700
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3980
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2701
3981
|
BULK_OPERATION_MAX_SIZE
|
2702
3982
|
);
|
2703
3983
|
for (const operations of chunkedOperations) {
|
@@ -2708,21 +3988,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2708
3988
|
region: "{region}"
|
2709
3989
|
},
|
2710
3990
|
body: { operations },
|
2711
|
-
...
|
3991
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2712
3992
|
});
|
2713
3993
|
}
|
2714
3994
|
};
|
2715
3995
|
_setCacheQuery = new WeakSet();
|
2716
3996
|
setCacheQuery_fn = async function(query, meta, records) {
|
2717
|
-
await __privateGet$4(this, _cache)
|
3997
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2718
3998
|
};
|
2719
3999
|
_getCacheQuery = new WeakSet();
|
2720
4000
|
getCacheQuery_fn = async function(query) {
|
2721
4001
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2722
|
-
const result = await __privateGet$4(this, _cache)
|
4002
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2723
4003
|
if (!result)
|
2724
4004
|
return null;
|
2725
|
-
const
|
4005
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4006
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2726
4007
|
if (ttl < 0)
|
2727
4008
|
return null;
|
2728
4009
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2732,15 +4013,46 @@ _getSchemaTables$1 = new WeakSet();
|
|
2732
4013
|
getSchemaTables_fn$1 = async function() {
|
2733
4014
|
if (__privateGet$4(this, _schemaTables$2))
|
2734
4015
|
return __privateGet$4(this, _schemaTables$2);
|
2735
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2736
4016
|
const { schema } = await getBranchDetails({
|
2737
4017
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2738
|
-
...
|
4018
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2739
4019
|
});
|
2740
4020
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2741
4021
|
return schema.tables;
|
2742
4022
|
};
|
2743
|
-
|
4023
|
+
_transformObjectToApi = new WeakSet();
|
4024
|
+
transformObjectToApi_fn = async function(object) {
|
4025
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4026
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4027
|
+
if (!schema)
|
4028
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4029
|
+
const result = {};
|
4030
|
+
for (const [key, value] of Object.entries(object)) {
|
4031
|
+
if (key === "xata")
|
4032
|
+
continue;
|
4033
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4034
|
+
switch (type) {
|
4035
|
+
case "link": {
|
4036
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4037
|
+
break;
|
4038
|
+
}
|
4039
|
+
case "datetime": {
|
4040
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4041
|
+
break;
|
4042
|
+
}
|
4043
|
+
case `file`:
|
4044
|
+
result[key] = await parseInputFileEntry(value);
|
4045
|
+
break;
|
4046
|
+
case "file[]":
|
4047
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4048
|
+
break;
|
4049
|
+
default:
|
4050
|
+
result[key] = value;
|
4051
|
+
}
|
4052
|
+
}
|
4053
|
+
return result;
|
4054
|
+
};
|
4055
|
+
const removeLinksFromObject = (object) => {
|
2744
4056
|
return Object.entries(object).reduce((acc, [key, value]) => {
|
2745
4057
|
if (key === "xata")
|
2746
4058
|
return acc;
|
@@ -2748,23 +4060,23 @@ const transformObjectLinks = (object) => {
|
|
2748
4060
|
}, {});
|
2749
4061
|
};
|
2750
4062
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2751
|
-
const
|
4063
|
+
const data = {};
|
2752
4064
|
const { xata, ...rest } = object ?? {};
|
2753
|
-
Object.assign(
|
4065
|
+
Object.assign(data, rest);
|
2754
4066
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2755
4067
|
if (!columns)
|
2756
4068
|
console.error(`Table ${table} not found in schema`);
|
2757
4069
|
for (const column of columns ?? []) {
|
2758
4070
|
if (!isValidColumn(selectedColumns, column))
|
2759
4071
|
continue;
|
2760
|
-
const value =
|
4072
|
+
const value = data[column.name];
|
2761
4073
|
switch (column.type) {
|
2762
4074
|
case "datetime": {
|
2763
|
-
const date = value !== void 0 ? new Date(value) :
|
2764
|
-
if (date && isNaN(date.getTime())) {
|
4075
|
+
const date = value !== void 0 ? new Date(value) : null;
|
4076
|
+
if (date !== null && isNaN(date.getTime())) {
|
2765
4077
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2766
|
-
} else
|
2767
|
-
|
4078
|
+
} else {
|
4079
|
+
data[column.name] = date;
|
2768
4080
|
}
|
2769
4081
|
break;
|
2770
4082
|
}
|
@@ -2783,44 +4095,60 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2783
4095
|
}
|
2784
4096
|
return acc;
|
2785
4097
|
}, []);
|
2786
|
-
|
4098
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2787
4099
|
} else {
|
2788
|
-
|
4100
|
+
data[column.name] = null;
|
2789
4101
|
}
|
2790
4102
|
break;
|
2791
4103
|
}
|
4104
|
+
case "file":
|
4105
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4106
|
+
break;
|
4107
|
+
case "file[]":
|
4108
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4109
|
+
break;
|
2792
4110
|
default:
|
2793
|
-
|
4111
|
+
data[column.name] = value ?? null;
|
2794
4112
|
if (column.notNull === true && value === null) {
|
2795
4113
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2796
4114
|
}
|
2797
4115
|
break;
|
2798
4116
|
}
|
2799
4117
|
}
|
2800
|
-
|
2801
|
-
|
4118
|
+
const record = { ...data };
|
4119
|
+
const serializable = { xata, ...removeLinksFromObject(data) };
|
4120
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4121
|
+
record.read = function(columns2) {
|
4122
|
+
return db[table].read(record["id"], columns2);
|
2802
4123
|
};
|
2803
|
-
|
4124
|
+
record.update = function(data2, b, c) {
|
2804
4125
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2805
4126
|
const ifVersion = parseIfVersion(b, c);
|
2806
|
-
return db[table].update(
|
4127
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2807
4128
|
};
|
2808
|
-
|
4129
|
+
record.replace = function(data2, b, c) {
|
2809
4130
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2810
4131
|
const ifVersion = parseIfVersion(b, c);
|
2811
|
-
return db[table].createOrReplace(
|
4132
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4133
|
+
};
|
4134
|
+
record.delete = function() {
|
4135
|
+
return db[table].delete(record["id"]);
|
2812
4136
|
};
|
2813
|
-
|
2814
|
-
|
4137
|
+
record.xata = Object.freeze(metadata);
|
4138
|
+
record.getMetadata = function() {
|
4139
|
+
return record.xata;
|
2815
4140
|
};
|
2816
|
-
|
2817
|
-
return
|
4141
|
+
record.toSerializable = function() {
|
4142
|
+
return JSON.parse(JSON.stringify(serializable));
|
2818
4143
|
};
|
2819
|
-
|
2820
|
-
|
4144
|
+
record.toString = function() {
|
4145
|
+
return JSON.stringify(serializable);
|
4146
|
+
};
|
4147
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4148
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2821
4149
|
}
|
2822
|
-
Object.freeze(
|
2823
|
-
return
|
4150
|
+
Object.freeze(record);
|
4151
|
+
return record;
|
2824
4152
|
};
|
2825
4153
|
function extractId(value) {
|
2826
4154
|
if (isString(value))
|
@@ -2832,11 +4160,7 @@ function extractId(value) {
|
|
2832
4160
|
function isValidColumn(columns, column) {
|
2833
4161
|
if (columns.includes("*"))
|
2834
4162
|
return true;
|
2835
|
-
|
2836
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2837
|
-
return linkColumns.length > 0;
|
2838
|
-
}
|
2839
|
-
return columns.includes(column.name);
|
4163
|
+
return columns.filter((item) => item.startsWith(column.name)).length > 0;
|
2840
4164
|
}
|
2841
4165
|
function parseIfVersion(...args) {
|
2842
4166
|
for (const arg of args) {
|
@@ -2847,6 +4171,12 @@ function parseIfVersion(...args) {
|
|
2847
4171
|
return void 0;
|
2848
4172
|
}
|
2849
4173
|
|
4174
|
+
var __defProp$3 = Object.defineProperty;
|
4175
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4176
|
+
var __publicField$3 = (obj, key, value) => {
|
4177
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4178
|
+
return value;
|
4179
|
+
};
|
2850
4180
|
var __accessCheck$3 = (obj, member, msg) => {
|
2851
4181
|
if (!member.has(obj))
|
2852
4182
|
throw TypeError("Cannot " + msg);
|
@@ -2869,6 +4199,8 @@ var _map;
|
|
2869
4199
|
class SimpleCache {
|
2870
4200
|
constructor(options = {}) {
|
2871
4201
|
__privateAdd$3(this, _map, void 0);
|
4202
|
+
__publicField$3(this, "capacity");
|
4203
|
+
__publicField$3(this, "defaultQueryTTL");
|
2872
4204
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
2873
4205
|
this.capacity = options.max ?? 500;
|
2874
4206
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
@@ -3004,19 +4336,19 @@ class SearchPlugin extends XataPlugin {
|
|
3004
4336
|
__privateAdd$1(this, _schemaTables, void 0);
|
3005
4337
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3006
4338
|
}
|
3007
|
-
build(
|
4339
|
+
build(pluginOptions) {
|
3008
4340
|
return {
|
3009
4341
|
all: async (query, options = {}) => {
|
3010
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3011
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4342
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4343
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3012
4344
|
return records.map((record) => {
|
3013
4345
|
const { table = "orphan" } = record.xata;
|
3014
4346
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3015
4347
|
});
|
3016
4348
|
},
|
3017
4349
|
byTable: async (query, options = {}) => {
|
3018
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3019
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
4350
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4351
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3020
4352
|
return records.reduce((acc, record) => {
|
3021
4353
|
const { table = "orphan" } = record.xata;
|
3022
4354
|
const items = acc[table] ?? [];
|
@@ -3029,116 +4361,49 @@ class SearchPlugin extends XataPlugin {
|
|
3029
4361
|
}
|
3030
4362
|
_schemaTables = new WeakMap();
|
3031
4363
|
_search = new WeakSet();
|
3032
|
-
search_fn = async function(query, options,
|
3033
|
-
const
|
3034
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
4364
|
+
search_fn = async function(query, options, pluginOptions) {
|
4365
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3035
4366
|
const { records } = await searchBranch({
|
3036
4367
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3037
|
-
|
3038
|
-
|
4368
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4369
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
4370
|
+
...pluginOptions
|
3039
4371
|
});
|
3040
4372
|
return records;
|
3041
4373
|
};
|
3042
4374
|
_getSchemaTables = new WeakSet();
|
3043
|
-
getSchemaTables_fn = async function(
|
4375
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3044
4376
|
if (__privateGet$1(this, _schemaTables))
|
3045
4377
|
return __privateGet$1(this, _schemaTables);
|
3046
|
-
const fetchProps = await getFetchProps();
|
3047
4378
|
const { schema } = await getBranchDetails({
|
3048
4379
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3049
|
-
...
|
4380
|
+
...pluginOptions
|
3050
4381
|
});
|
3051
4382
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3052
4383
|
return schema.tables;
|
3053
4384
|
};
|
3054
4385
|
|
3055
|
-
|
3056
|
-
|
3057
|
-
|
3058
|
-
|
3059
|
-
|
3060
|
-
|
3061
|
-
|
3062
|
-
|
3063
|
-
|
3064
|
-
|
3065
|
-
|
3066
|
-
|
3067
|
-
const gitBranch = envBranch || await getGitBranch();
|
3068
|
-
return resolveXataBranch(gitBranch, options);
|
3069
|
-
}
|
3070
|
-
async function getCurrentBranchDetails(options) {
|
3071
|
-
const branch = await getCurrentBranchName(options);
|
3072
|
-
return getDatabaseBranch(branch, options);
|
3073
|
-
}
|
3074
|
-
async function resolveXataBranch(gitBranch, options) {
|
3075
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3076
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3077
|
-
if (!databaseURL)
|
3078
|
-
throw new Error(
|
3079
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3080
|
-
);
|
3081
|
-
if (!apiKey)
|
3082
|
-
throw new Error(
|
3083
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3084
|
-
);
|
3085
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3086
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3087
|
-
if (!urlParts)
|
3088
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3089
|
-
const { workspace, region } = urlParts;
|
3090
|
-
const { fallbackBranch } = getEnvironment();
|
3091
|
-
const { branch } = await resolveBranch({
|
3092
|
-
apiKey,
|
3093
|
-
apiUrl: databaseURL,
|
3094
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3095
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3096
|
-
pathParams: { dbName, workspace, region },
|
3097
|
-
queryParams: { gitBranch, fallbackBranch },
|
3098
|
-
trace: defaultTrace
|
3099
|
-
});
|
3100
|
-
return branch;
|
3101
|
-
}
|
3102
|
-
async function getDatabaseBranch(branch, options) {
|
3103
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3104
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3105
|
-
if (!databaseURL)
|
3106
|
-
throw new Error(
|
3107
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3108
|
-
);
|
3109
|
-
if (!apiKey)
|
3110
|
-
throw new Error(
|
3111
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3112
|
-
);
|
3113
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3114
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3115
|
-
if (!urlParts)
|
3116
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3117
|
-
const { workspace, region } = urlParts;
|
3118
|
-
try {
|
3119
|
-
return await getBranchDetails({
|
3120
|
-
apiKey,
|
3121
|
-
apiUrl: databaseURL,
|
3122
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3123
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3124
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3125
|
-
trace: defaultTrace
|
3126
|
-
});
|
3127
|
-
} catch (err) {
|
3128
|
-
if (isObject(err) && err.status === 404)
|
3129
|
-
return null;
|
3130
|
-
throw err;
|
3131
|
-
}
|
3132
|
-
}
|
3133
|
-
function getDatabaseURL() {
|
3134
|
-
try {
|
3135
|
-
const { databaseURL } = getEnvironment();
|
3136
|
-
return databaseURL;
|
3137
|
-
} catch (err) {
|
3138
|
-
return void 0;
|
4386
|
+
class TransactionPlugin extends XataPlugin {
|
4387
|
+
build(pluginOptions) {
|
4388
|
+
return {
|
4389
|
+
run: async (operations) => {
|
4390
|
+
const response = await branchTransaction({
|
4391
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4392
|
+
body: { operations },
|
4393
|
+
...pluginOptions
|
4394
|
+
});
|
4395
|
+
return response;
|
4396
|
+
}
|
4397
|
+
};
|
3139
4398
|
}
|
3140
4399
|
}
|
3141
4400
|
|
4401
|
+
var __defProp$2 = Object.defineProperty;
|
4402
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4403
|
+
var __publicField$2 = (obj, key, value) => {
|
4404
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4405
|
+
return value;
|
4406
|
+
};
|
3142
4407
|
var __accessCheck = (obj, member, msg) => {
|
3143
4408
|
if (!member.has(obj))
|
3144
4409
|
throw TypeError("Cannot " + msg);
|
@@ -3162,46 +4427,45 @@ var __privateMethod = (obj, member, method) => {
|
|
3162
4427
|
return method;
|
3163
4428
|
};
|
3164
4429
|
const buildClient = (plugins) => {
|
3165
|
-
var
|
4430
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3166
4431
|
return _a = class {
|
3167
4432
|
constructor(options = {}, schemaTables) {
|
3168
4433
|
__privateAdd(this, _parseOptions);
|
3169
4434
|
__privateAdd(this, _getFetchProps);
|
3170
|
-
__privateAdd(this, _evaluateBranch);
|
3171
|
-
__privateAdd(this, _branch, void 0);
|
3172
4435
|
__privateAdd(this, _options, void 0);
|
4436
|
+
__publicField$2(this, "db");
|
4437
|
+
__publicField$2(this, "search");
|
4438
|
+
__publicField$2(this, "transactions");
|
4439
|
+
__publicField$2(this, "files");
|
3173
4440
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3174
4441
|
__privateSet(this, _options, safeOptions);
|
3175
4442
|
const pluginOptions = {
|
3176
|
-
|
4443
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3177
4444
|
cache: safeOptions.cache,
|
3178
|
-
|
4445
|
+
host: safeOptions.host
|
3179
4446
|
};
|
3180
4447
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3181
4448
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4449
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
4450
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3182
4451
|
this.db = db;
|
3183
4452
|
this.search = search;
|
4453
|
+
this.transactions = transactions;
|
4454
|
+
this.files = files;
|
3184
4455
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3185
4456
|
if (namespace === void 0)
|
3186
4457
|
continue;
|
3187
|
-
|
3188
|
-
if (result instanceof Promise) {
|
3189
|
-
void result.then((namespace2) => {
|
3190
|
-
this[key] = namespace2;
|
3191
|
-
});
|
3192
|
-
} else {
|
3193
|
-
this[key] = result;
|
3194
|
-
}
|
4458
|
+
this[key] = namespace.build(pluginOptions);
|
3195
4459
|
}
|
3196
4460
|
}
|
3197
4461
|
async getConfig() {
|
3198
4462
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3199
|
-
const branch =
|
4463
|
+
const branch = __privateGet(this, _options).branch;
|
3200
4464
|
return { databaseURL, branch };
|
3201
4465
|
}
|
3202
|
-
},
|
4466
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3203
4467
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3204
|
-
const isBrowser = typeof window !== "undefined";
|
4468
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3205
4469
|
if (isBrowser && !enableBrowser) {
|
3206
4470
|
throw new Error(
|
3207
4471
|
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
@@ -3212,56 +4476,89 @@ const buildClient = (plugins) => {
|
|
3212
4476
|
const apiKey = options?.apiKey || getAPIKey();
|
3213
4477
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3214
4478
|
const trace = options?.trace ?? defaultTrace;
|
3215
|
-
const
|
4479
|
+
const clientName = options?.clientName;
|
4480
|
+
const host = options?.host ?? "production";
|
4481
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3216
4482
|
if (!apiKey) {
|
3217
4483
|
throw new Error("Option apiKey is required");
|
3218
4484
|
}
|
3219
4485
|
if (!databaseURL) {
|
3220
4486
|
throw new Error("Option databaseURL is required");
|
3221
4487
|
}
|
3222
|
-
|
3223
|
-
|
3224
|
-
const
|
3225
|
-
if (
|
3226
|
-
|
4488
|
+
const envBranch = getBranch();
|
4489
|
+
const previewBranch = getPreviewBranch();
|
4490
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4491
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4492
|
+
console.warn(
|
4493
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4494
|
+
);
|
4495
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4496
|
+
console.warn(
|
4497
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4498
|
+
);
|
4499
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4500
|
+
console.warn(
|
4501
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4502
|
+
);
|
4503
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4504
|
+
console.warn(
|
4505
|
+
`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.`
|
4506
|
+
);
|
4507
|
+
}
|
4508
|
+
return {
|
4509
|
+
fetch,
|
4510
|
+
databaseURL,
|
4511
|
+
apiKey,
|
4512
|
+
branch,
|
4513
|
+
cache,
|
4514
|
+
trace,
|
4515
|
+
host,
|
4516
|
+
clientID: generateUUID(),
|
4517
|
+
enableBrowser,
|
4518
|
+
clientName,
|
4519
|
+
xataAgentExtra
|
4520
|
+
};
|
4521
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4522
|
+
fetch,
|
4523
|
+
apiKey,
|
4524
|
+
databaseURL,
|
4525
|
+
branch,
|
4526
|
+
trace,
|
4527
|
+
clientID,
|
4528
|
+
clientName,
|
4529
|
+
xataAgentExtra
|
4530
|
+
}) {
|
3227
4531
|
return {
|
3228
|
-
|
4532
|
+
fetch,
|
3229
4533
|
apiKey,
|
3230
4534
|
apiUrl: "",
|
4535
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3231
4536
|
workspacesApiUrl: (path, params) => {
|
3232
4537
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3233
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4538
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3234
4539
|
return databaseURL + newPath;
|
3235
4540
|
},
|
3236
4541
|
trace,
|
3237
|
-
clientID
|
3238
|
-
|
3239
|
-
|
3240
|
-
if (__privateGet(this, _branch))
|
3241
|
-
return __privateGet(this, _branch);
|
3242
|
-
if (param === void 0)
|
3243
|
-
return void 0;
|
3244
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3245
|
-
const evaluateBranch = async (strategy) => {
|
3246
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
4542
|
+
clientID,
|
4543
|
+
clientName,
|
4544
|
+
xataAgentExtra
|
3247
4545
|
};
|
3248
|
-
for await (const strategy of strategies) {
|
3249
|
-
const branch = await evaluateBranch(strategy);
|
3250
|
-
if (branch) {
|
3251
|
-
__privateSet(this, _branch, branch);
|
3252
|
-
return branch;
|
3253
|
-
}
|
3254
|
-
}
|
3255
4546
|
}, _a;
|
3256
4547
|
};
|
3257
4548
|
class BaseClient extends buildClient() {
|
3258
4549
|
}
|
3259
4550
|
|
4551
|
+
var __defProp$1 = Object.defineProperty;
|
4552
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4553
|
+
var __publicField$1 = (obj, key, value) => {
|
4554
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4555
|
+
return value;
|
4556
|
+
};
|
3260
4557
|
const META = "__";
|
3261
4558
|
const VALUE = "___";
|
3262
4559
|
class Serializer {
|
3263
4560
|
constructor() {
|
3264
|
-
this
|
4561
|
+
__publicField$1(this, "classes", {});
|
3265
4562
|
}
|
3266
4563
|
add(clazz) {
|
3267
4564
|
this.classes[clazz.name] = clazz;
|
@@ -3325,7 +4622,7 @@ const deserialize = (json) => {
|
|
3325
4622
|
};
|
3326
4623
|
|
3327
4624
|
function buildWorkerRunner(config) {
|
3328
|
-
return function xataWorker(name,
|
4625
|
+
return function xataWorker(name, worker) {
|
3329
4626
|
return async (...args) => {
|
3330
4627
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3331
4628
|
const result = await fetch(url, {
|
@@ -3339,14 +4636,23 @@ function buildWorkerRunner(config) {
|
|
3339
4636
|
};
|
3340
4637
|
}
|
3341
4638
|
|
4639
|
+
var __defProp = Object.defineProperty;
|
4640
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4641
|
+
var __publicField = (obj, key, value) => {
|
4642
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
4643
|
+
return value;
|
4644
|
+
};
|
3342
4645
|
class XataError extends Error {
|
3343
4646
|
constructor(message, status) {
|
3344
4647
|
super(message);
|
4648
|
+
__publicField(this, "status");
|
3345
4649
|
this.status = status;
|
3346
4650
|
}
|
3347
4651
|
}
|
3348
4652
|
|
3349
4653
|
exports.BaseClient = BaseClient;
|
4654
|
+
exports.FetcherError = FetcherError;
|
4655
|
+
exports.FilesPlugin = FilesPlugin;
|
3350
4656
|
exports.Operations = operationsByTag;
|
3351
4657
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
3352
4658
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -3355,6 +4661,7 @@ exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
|
|
3355
4661
|
exports.Page = Page;
|
3356
4662
|
exports.Query = Query;
|
3357
4663
|
exports.RecordArray = RecordArray;
|
4664
|
+
exports.RecordColumnTypes = RecordColumnTypes;
|
3358
4665
|
exports.Repository = Repository;
|
3359
4666
|
exports.RestRepository = RestRepository;
|
3360
4667
|
exports.SchemaPlugin = SchemaPlugin;
|
@@ -3364,14 +4671,19 @@ exports.SimpleCache = SimpleCache;
|
|
3364
4671
|
exports.XataApiClient = XataApiClient;
|
3365
4672
|
exports.XataApiPlugin = XataApiPlugin;
|
3366
4673
|
exports.XataError = XataError;
|
4674
|
+
exports.XataFile = XataFile;
|
3367
4675
|
exports.XataPlugin = XataPlugin;
|
3368
4676
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
3369
4677
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
3370
4678
|
exports.addTableColumn = addTableColumn;
|
3371
4679
|
exports.aggregateTable = aggregateTable;
|
3372
4680
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4681
|
+
exports.askTable = askTable;
|
4682
|
+
exports.askTableSession = askTableSession;
|
3373
4683
|
exports.branchTransaction = branchTransaction;
|
3374
4684
|
exports.buildClient = buildClient;
|
4685
|
+
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4686
|
+
exports.buildProviderString = buildProviderString;
|
3375
4687
|
exports.buildWorkerRunner = buildWorkerRunner;
|
3376
4688
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
3377
4689
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
@@ -3379,20 +4691,19 @@ exports.compareBranchSchemas = compareBranchSchemas;
|
|
3379
4691
|
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3380
4692
|
exports.compareMigrationRequest = compareMigrationRequest;
|
3381
4693
|
exports.contains = contains;
|
4694
|
+
exports.copyBranch = copyBranch;
|
3382
4695
|
exports.createBranch = createBranch;
|
3383
4696
|
exports.createDatabase = createDatabase;
|
3384
4697
|
exports.createMigrationRequest = createMigrationRequest;
|
3385
4698
|
exports.createTable = createTable;
|
3386
4699
|
exports.createUserAPIKey = createUserAPIKey;
|
3387
4700
|
exports.createWorkspace = createWorkspace;
|
3388
|
-
exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
|
3389
|
-
exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
|
3390
|
-
exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
|
3391
|
-
exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
|
3392
|
-
exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
|
3393
4701
|
exports.deleteBranch = deleteBranch;
|
3394
4702
|
exports.deleteColumn = deleteColumn;
|
3395
4703
|
exports.deleteDatabase = deleteDatabase;
|
4704
|
+
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
4705
|
+
exports.deleteFile = deleteFile;
|
4706
|
+
exports.deleteFileItem = deleteFileItem;
|
3396
4707
|
exports.deleteRecord = deleteRecord;
|
3397
4708
|
exports.deleteTable = deleteTable;
|
3398
4709
|
exports.deleteUser = deleteUser;
|
@@ -3403,8 +4714,11 @@ exports.endsWith = endsWith;
|
|
3403
4714
|
exports.equals = equals;
|
3404
4715
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
3405
4716
|
exports.exists = exists;
|
4717
|
+
exports.fileAccess = fileAccess;
|
3406
4718
|
exports.ge = ge;
|
3407
4719
|
exports.getAPIKey = getAPIKey;
|
4720
|
+
exports.getAuthorizationCode = getAuthorizationCode;
|
4721
|
+
exports.getBranch = getBranch;
|
3408
4722
|
exports.getBranchDetails = getBranchDetails;
|
3409
4723
|
exports.getBranchList = getBranchList;
|
3410
4724
|
exports.getBranchMetadata = getBranchMetadata;
|
@@ -3413,23 +4727,28 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
|
3413
4727
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
3414
4728
|
exports.getBranchStats = getBranchStats;
|
3415
4729
|
exports.getColumn = getColumn;
|
3416
|
-
exports.
|
3417
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
4730
|
+
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
3418
4731
|
exports.getDatabaseList = getDatabaseList;
|
3419
4732
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
3420
4733
|
exports.getDatabaseURL = getDatabaseURL;
|
4734
|
+
exports.getFile = getFile;
|
4735
|
+
exports.getFileItem = getFileItem;
|
3421
4736
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3422
4737
|
exports.getHostUrl = getHostUrl;
|
3423
4738
|
exports.getMigrationRequest = getMigrationRequest;
|
3424
4739
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4740
|
+
exports.getPreviewBranch = getPreviewBranch;
|
3425
4741
|
exports.getRecord = getRecord;
|
3426
4742
|
exports.getTableColumns = getTableColumns;
|
3427
4743
|
exports.getTableSchema = getTableSchema;
|
3428
4744
|
exports.getUser = getUser;
|
3429
4745
|
exports.getUserAPIKeys = getUserAPIKeys;
|
4746
|
+
exports.getUserOAuthAccessTokens = getUserOAuthAccessTokens;
|
4747
|
+
exports.getUserOAuthClients = getUserOAuthClients;
|
3430
4748
|
exports.getWorkspace = getWorkspace;
|
3431
4749
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
3432
4750
|
exports.getWorkspacesList = getWorkspacesList;
|
4751
|
+
exports.grantAuthorizationCode = grantAuthorizationCode;
|
3433
4752
|
exports.greaterEquals = greaterEquals;
|
3434
4753
|
exports.greaterThan = greaterThan;
|
3435
4754
|
exports.greaterThanEquals = greaterThanEquals;
|
@@ -3464,21 +4783,28 @@ exports.parseProviderString = parseProviderString;
|
|
3464
4783
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
3465
4784
|
exports.pattern = pattern;
|
3466
4785
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4786
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
4787
|
+
exports.putFile = putFile;
|
4788
|
+
exports.putFileItem = putFileItem;
|
3467
4789
|
exports.queryMigrationRequests = queryMigrationRequests;
|
3468
4790
|
exports.queryTable = queryTable;
|
3469
4791
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
3470
4792
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
4793
|
+
exports.renameDatabase = renameDatabase;
|
3471
4794
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
3472
4795
|
exports.resolveBranch = resolveBranch;
|
3473
4796
|
exports.searchBranch = searchBranch;
|
3474
4797
|
exports.searchTable = searchTable;
|
3475
4798
|
exports.serialize = serialize;
|
3476
4799
|
exports.setTableSchema = setTableSchema;
|
4800
|
+
exports.sqlQuery = sqlQuery;
|
3477
4801
|
exports.startsWith = startsWith;
|
3478
4802
|
exports.summarizeTable = summarizeTable;
|
4803
|
+
exports.transformImage = transformImage;
|
3479
4804
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3480
4805
|
exports.updateBranchSchema = updateBranchSchema;
|
3481
4806
|
exports.updateColumn = updateColumn;
|
4807
|
+
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3482
4808
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3483
4809
|
exports.updateMigrationRequest = updateMigrationRequest;
|
3484
4810
|
exports.updateRecordWithID = updateRecordWithID;
|
@@ -3488,4 +4814,5 @@ exports.updateWorkspace = updateWorkspace;
|
|
3488
4814
|
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
3489
4815
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
3490
4816
|
exports.upsertRecordWithID = upsertRecordWithID;
|
4817
|
+
exports.vectorSearchTable = vectorSearchTable;
|
3491
4818
|
//# sourceMappingURL=index.cjs.map
|