@xata.io/client 0.0.0-alpha.vf8f3b02 → 0.0.0-alpha.vf9117073fa2d41de1cd4690157c24c67ca3a6650
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +342 -0
- package/README.md +3 -269
- package/dist/index.cjs +1697 -1401
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4042 -2337
- package/dist/index.mjs +1651 -1394
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -10
- package/.eslintrc.cjs +0 -12
- package/Usage.md +0 -451
- package/mod.ts +0 -2
- package/rollup.config.mjs +0 -29
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
const defaultTrace = async (
|
1
|
+
const defaultTrace = async (name, fn, _options) => {
|
2
2
|
return await fn({
|
3
|
+
name,
|
3
4
|
setAttributes: () => {
|
4
5
|
return;
|
5
6
|
}
|
@@ -17,7 +18,8 @@ const TraceAttributes = {
|
|
17
18
|
HTTP_METHOD: "http.method",
|
18
19
|
HTTP_URL: "http.url",
|
19
20
|
HTTP_ROUTE: "http.route",
|
20
|
-
HTTP_TARGET: "http.target"
|
21
|
+
HTTP_TARGET: "http.target",
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
21
23
|
};
|
22
24
|
|
23
25
|
function notEmpty(value) {
|
@@ -26,8 +28,18 @@ function notEmpty(value) {
|
|
26
28
|
function compact(arr) {
|
27
29
|
return arr.filter(notEmpty);
|
28
30
|
}
|
31
|
+
function compactObject(obj) {
|
32
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
33
|
+
}
|
34
|
+
function isBlob(value) {
|
35
|
+
try {
|
36
|
+
return value instanceof Blob;
|
37
|
+
} catch (error) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
}
|
29
41
|
function isObject(value) {
|
30
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
31
43
|
}
|
32
44
|
function isDefined(value) {
|
33
45
|
return value !== null && value !== void 0;
|
@@ -41,6 +53,18 @@ function isStringArray(value) {
|
|
41
53
|
function isNumber(value) {
|
42
54
|
return isDefined(value) && typeof value === "number";
|
43
55
|
}
|
56
|
+
function parseNumber(value) {
|
57
|
+
if (isNumber(value)) {
|
58
|
+
return value;
|
59
|
+
}
|
60
|
+
if (isString(value)) {
|
61
|
+
const parsed = Number(value);
|
62
|
+
if (!Number.isNaN(parsed)) {
|
63
|
+
return parsed;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return void 0;
|
67
|
+
}
|
44
68
|
function toBase64(value) {
|
45
69
|
try {
|
46
70
|
return btoa(value);
|
@@ -60,16 +84,49 @@ function deepMerge(a, b) {
|
|
60
84
|
}
|
61
85
|
return result;
|
62
86
|
}
|
87
|
+
function chunk(array, chunkSize) {
|
88
|
+
const result = [];
|
89
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
90
|
+
result.push(array.slice(i, i + chunkSize));
|
91
|
+
}
|
92
|
+
return result;
|
93
|
+
}
|
94
|
+
async function timeout(ms) {
|
95
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
96
|
+
}
|
97
|
+
function timeoutWithCancel(ms) {
|
98
|
+
let timeoutId;
|
99
|
+
const promise = new Promise((resolve) => {
|
100
|
+
timeoutId = setTimeout(() => {
|
101
|
+
resolve();
|
102
|
+
}, ms);
|
103
|
+
});
|
104
|
+
return {
|
105
|
+
cancel: () => clearTimeout(timeoutId),
|
106
|
+
promise
|
107
|
+
};
|
108
|
+
}
|
109
|
+
function promiseMap(inputValues, mapper) {
|
110
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
111
|
+
(acc) => mapper(inputValue).then((result) => {
|
112
|
+
acc.push(result);
|
113
|
+
return acc;
|
114
|
+
})
|
115
|
+
);
|
116
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
117
|
+
}
|
63
118
|
|
64
119
|
function getEnvironment() {
|
65
120
|
try {
|
66
|
-
if (
|
121
|
+
if (isDefined(process) && isDefined(process.env)) {
|
67
122
|
return {
|
68
123
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
69
124
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
70
125
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
71
|
-
|
72
|
-
|
126
|
+
deployPreview: process.env.XATA_PREVIEW,
|
127
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
128
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
129
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
73
130
|
};
|
74
131
|
}
|
75
132
|
} catch (err) {
|
@@ -80,8 +137,10 @@ function getEnvironment() {
|
|
80
137
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
81
138
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
82
139
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
83
|
-
|
84
|
-
|
140
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
141
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
142
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
143
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
85
144
|
};
|
86
145
|
}
|
87
146
|
} catch (err) {
|
@@ -90,8 +149,10 @@ function getEnvironment() {
|
|
90
149
|
apiKey: getGlobalApiKey(),
|
91
150
|
databaseURL: getGlobalDatabaseURL(),
|
92
151
|
branch: getGlobalBranch(),
|
93
|
-
|
94
|
-
|
152
|
+
deployPreview: void 0,
|
153
|
+
deployPreviewBranch: void 0,
|
154
|
+
vercelGitCommitRef: void 0,
|
155
|
+
vercelGitRepoOwner: void 0
|
95
156
|
};
|
96
157
|
}
|
97
158
|
function getEnableBrowserVariable() {
|
@@ -134,56 +195,338 @@ function getGlobalBranch() {
|
|
134
195
|
return void 0;
|
135
196
|
}
|
136
197
|
}
|
137
|
-
function
|
198
|
+
function getDatabaseURL() {
|
138
199
|
try {
|
139
|
-
|
200
|
+
const { databaseURL } = getEnvironment();
|
201
|
+
return databaseURL;
|
140
202
|
} catch (err) {
|
141
203
|
return void 0;
|
142
204
|
}
|
143
205
|
}
|
144
|
-
|
145
|
-
const cmd = ["git", "branch", "--show-current"];
|
146
|
-
const fullCmd = cmd.join(" ");
|
147
|
-
const nodeModule = ["child", "process"].join("_");
|
148
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
206
|
+
function getAPIKey() {
|
149
207
|
try {
|
150
|
-
|
151
|
-
|
152
|
-
}
|
153
|
-
const { execSync } = await import(nodeModule);
|
154
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
208
|
+
const { apiKey } = getEnvironment();
|
209
|
+
return apiKey;
|
155
210
|
} catch (err) {
|
211
|
+
return void 0;
|
156
212
|
}
|
213
|
+
}
|
214
|
+
function getBranch() {
|
157
215
|
try {
|
158
|
-
|
159
|
-
|
160
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
161
|
-
}
|
216
|
+
const { branch } = getEnvironment();
|
217
|
+
return branch;
|
162
218
|
} catch (err) {
|
219
|
+
return void 0;
|
163
220
|
}
|
164
221
|
}
|
165
|
-
|
166
|
-
|
222
|
+
function buildPreviewBranchName({ org, branch }) {
|
223
|
+
return `preview-${org}-${branch}`;
|
224
|
+
}
|
225
|
+
function getPreviewBranch() {
|
167
226
|
try {
|
168
|
-
const {
|
169
|
-
|
227
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
228
|
+
if (deployPreviewBranch)
|
229
|
+
return deployPreviewBranch;
|
230
|
+
switch (deployPreview) {
|
231
|
+
case "vercel": {
|
232
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
233
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
234
|
+
return void 0;
|
235
|
+
}
|
236
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
237
|
+
}
|
238
|
+
}
|
239
|
+
return void 0;
|
170
240
|
} catch (err) {
|
171
241
|
return void 0;
|
172
242
|
}
|
173
243
|
}
|
174
244
|
|
245
|
+
var __accessCheck$7 = (obj, member, msg) => {
|
246
|
+
if (!member.has(obj))
|
247
|
+
throw TypeError("Cannot " + msg);
|
248
|
+
};
|
249
|
+
var __privateGet$7 = (obj, member, getter) => {
|
250
|
+
__accessCheck$7(obj, member, "read from private field");
|
251
|
+
return getter ? getter.call(obj) : member.get(obj);
|
252
|
+
};
|
253
|
+
var __privateAdd$7 = (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$7 = (obj, member, value, setter) => {
|
259
|
+
__accessCheck$7(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$7(obj, member, "access private method");
|
265
|
+
return method;
|
266
|
+
};
|
267
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
175
269
|
function getFetchImplementation(userFetch) {
|
176
270
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
177
|
-
const
|
271
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
272
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
178
273
|
if (!fetchImpl) {
|
179
|
-
throw new Error(
|
180
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
181
|
-
);
|
274
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
182
275
|
}
|
183
276
|
return fetchImpl;
|
184
277
|
}
|
278
|
+
class ApiRequestPool {
|
279
|
+
constructor(concurrency = 10) {
|
280
|
+
__privateAdd$7(this, _enqueue);
|
281
|
+
__privateAdd$7(this, _fetch, void 0);
|
282
|
+
__privateAdd$7(this, _queue, void 0);
|
283
|
+
__privateAdd$7(this, _concurrency, void 0);
|
284
|
+
__privateSet$7(this, _queue, []);
|
285
|
+
__privateSet$7(this, _concurrency, concurrency);
|
286
|
+
this.running = 0;
|
287
|
+
this.started = 0;
|
288
|
+
}
|
289
|
+
setFetch(fetch2) {
|
290
|
+
__privateSet$7(this, _fetch, fetch2);
|
291
|
+
}
|
292
|
+
getFetch() {
|
293
|
+
if (!__privateGet$7(this, _fetch)) {
|
294
|
+
throw new Error("Fetch not set");
|
295
|
+
}
|
296
|
+
return __privateGet$7(this, _fetch);
|
297
|
+
}
|
298
|
+
request(url, options) {
|
299
|
+
const start = /* @__PURE__ */ new Date();
|
300
|
+
const fetchImpl = this.getFetch();
|
301
|
+
const runRequest = async (stalled = false) => {
|
302
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
303
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
304
|
+
if (!response) {
|
305
|
+
throw new Error("Request timed out");
|
306
|
+
}
|
307
|
+
if (response.status === 429) {
|
308
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
309
|
+
await timeout(rateLimitReset * 1e3);
|
310
|
+
return await runRequest(true);
|
311
|
+
}
|
312
|
+
if (stalled) {
|
313
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
314
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
315
|
+
}
|
316
|
+
return response;
|
317
|
+
};
|
318
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
319
|
+
return await runRequest();
|
320
|
+
});
|
321
|
+
}
|
322
|
+
}
|
323
|
+
_fetch = new WeakMap();
|
324
|
+
_queue = new WeakMap();
|
325
|
+
_concurrency = new WeakMap();
|
326
|
+
_enqueue = new WeakSet();
|
327
|
+
enqueue_fn = function(task) {
|
328
|
+
const promise = new Promise((resolve) => __privateGet$7(this, _queue).push(resolve)).finally(() => {
|
329
|
+
this.started--;
|
330
|
+
this.running++;
|
331
|
+
}).then(() => task()).finally(() => {
|
332
|
+
this.running--;
|
333
|
+
const next = __privateGet$7(this, _queue).shift();
|
334
|
+
if (next !== void 0) {
|
335
|
+
this.started++;
|
336
|
+
next();
|
337
|
+
}
|
338
|
+
});
|
339
|
+
if (this.running + this.started < __privateGet$7(this, _concurrency)) {
|
340
|
+
const next = __privateGet$7(this, _queue).shift();
|
341
|
+
if (next !== void 0) {
|
342
|
+
this.started++;
|
343
|
+
next();
|
344
|
+
}
|
345
|
+
}
|
346
|
+
return promise;
|
347
|
+
};
|
348
|
+
|
349
|
+
function generateUUID() {
|
350
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
351
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
352
|
+
return v.toString(16);
|
353
|
+
});
|
354
|
+
}
|
355
|
+
|
356
|
+
async function getBytes(stream, onChunk) {
|
357
|
+
const reader = stream.getReader();
|
358
|
+
let result;
|
359
|
+
while (!(result = await reader.read()).done) {
|
360
|
+
onChunk(result.value);
|
361
|
+
}
|
362
|
+
}
|
363
|
+
function getLines(onLine) {
|
364
|
+
let buffer;
|
365
|
+
let position;
|
366
|
+
let fieldLength;
|
367
|
+
let discardTrailingNewline = false;
|
368
|
+
return function onChunk(arr) {
|
369
|
+
if (buffer === void 0) {
|
370
|
+
buffer = arr;
|
371
|
+
position = 0;
|
372
|
+
fieldLength = -1;
|
373
|
+
} else {
|
374
|
+
buffer = concat(buffer, arr);
|
375
|
+
}
|
376
|
+
const bufLength = buffer.length;
|
377
|
+
let lineStart = 0;
|
378
|
+
while (position < bufLength) {
|
379
|
+
if (discardTrailingNewline) {
|
380
|
+
if (buffer[position] === 10 /* NewLine */) {
|
381
|
+
lineStart = ++position;
|
382
|
+
}
|
383
|
+
discardTrailingNewline = false;
|
384
|
+
}
|
385
|
+
let lineEnd = -1;
|
386
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
387
|
+
switch (buffer[position]) {
|
388
|
+
case 58 /* Colon */:
|
389
|
+
if (fieldLength === -1) {
|
390
|
+
fieldLength = position - lineStart;
|
391
|
+
}
|
392
|
+
break;
|
393
|
+
case 13 /* CarriageReturn */:
|
394
|
+
discardTrailingNewline = true;
|
395
|
+
case 10 /* NewLine */:
|
396
|
+
lineEnd = position;
|
397
|
+
break;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
if (lineEnd === -1) {
|
401
|
+
break;
|
402
|
+
}
|
403
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
404
|
+
lineStart = position;
|
405
|
+
fieldLength = -1;
|
406
|
+
}
|
407
|
+
if (lineStart === bufLength) {
|
408
|
+
buffer = void 0;
|
409
|
+
} else if (lineStart !== 0) {
|
410
|
+
buffer = buffer.subarray(lineStart);
|
411
|
+
position -= lineStart;
|
412
|
+
}
|
413
|
+
};
|
414
|
+
}
|
415
|
+
function getMessages(onId, onRetry, onMessage) {
|
416
|
+
let message = newMessage();
|
417
|
+
const decoder = new TextDecoder();
|
418
|
+
return function onLine(line, fieldLength) {
|
419
|
+
if (line.length === 0) {
|
420
|
+
onMessage?.(message);
|
421
|
+
message = newMessage();
|
422
|
+
} else if (fieldLength > 0) {
|
423
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
424
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
425
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
426
|
+
switch (field) {
|
427
|
+
case "data":
|
428
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
429
|
+
break;
|
430
|
+
case "event":
|
431
|
+
message.event = value;
|
432
|
+
break;
|
433
|
+
case "id":
|
434
|
+
onId(message.id = value);
|
435
|
+
break;
|
436
|
+
case "retry":
|
437
|
+
const retry = parseInt(value, 10);
|
438
|
+
if (!isNaN(retry)) {
|
439
|
+
onRetry(message.retry = retry);
|
440
|
+
}
|
441
|
+
break;
|
442
|
+
}
|
443
|
+
}
|
444
|
+
};
|
445
|
+
}
|
446
|
+
function concat(a, b) {
|
447
|
+
const res = new Uint8Array(a.length + b.length);
|
448
|
+
res.set(a);
|
449
|
+
res.set(b, a.length);
|
450
|
+
return res;
|
451
|
+
}
|
452
|
+
function newMessage() {
|
453
|
+
return {
|
454
|
+
data: "",
|
455
|
+
event: "",
|
456
|
+
id: "",
|
457
|
+
retry: void 0
|
458
|
+
};
|
459
|
+
}
|
460
|
+
const EventStreamContentType = "text/event-stream";
|
461
|
+
const LastEventId = "last-event-id";
|
462
|
+
function fetchEventSource(input, {
|
463
|
+
signal: inputSignal,
|
464
|
+
headers: inputHeaders,
|
465
|
+
onopen: inputOnOpen,
|
466
|
+
onmessage,
|
467
|
+
onclose,
|
468
|
+
onerror,
|
469
|
+
fetch: inputFetch,
|
470
|
+
...rest
|
471
|
+
}) {
|
472
|
+
return new Promise((resolve, reject) => {
|
473
|
+
const headers = { ...inputHeaders };
|
474
|
+
if (!headers.accept) {
|
475
|
+
headers.accept = EventStreamContentType;
|
476
|
+
}
|
477
|
+
let curRequestController;
|
478
|
+
function dispose() {
|
479
|
+
curRequestController.abort();
|
480
|
+
}
|
481
|
+
inputSignal?.addEventListener("abort", () => {
|
482
|
+
dispose();
|
483
|
+
resolve();
|
484
|
+
});
|
485
|
+
const fetchImpl = inputFetch ?? fetch;
|
486
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
487
|
+
async function create() {
|
488
|
+
curRequestController = new AbortController();
|
489
|
+
try {
|
490
|
+
const response = await fetchImpl(input, {
|
491
|
+
...rest,
|
492
|
+
headers,
|
493
|
+
signal: curRequestController.signal
|
494
|
+
});
|
495
|
+
await onopen(response);
|
496
|
+
await getBytes(
|
497
|
+
response.body,
|
498
|
+
getLines(
|
499
|
+
getMessages(
|
500
|
+
(id) => {
|
501
|
+
if (id) {
|
502
|
+
headers[LastEventId] = id;
|
503
|
+
} else {
|
504
|
+
delete headers[LastEventId];
|
505
|
+
}
|
506
|
+
},
|
507
|
+
(_retry) => {
|
508
|
+
},
|
509
|
+
onmessage
|
510
|
+
)
|
511
|
+
)
|
512
|
+
);
|
513
|
+
onclose?.();
|
514
|
+
dispose();
|
515
|
+
resolve();
|
516
|
+
} catch (err) {
|
517
|
+
}
|
518
|
+
}
|
519
|
+
create();
|
520
|
+
});
|
521
|
+
}
|
522
|
+
function defaultOnOpen(response) {
|
523
|
+
const contentType = response.headers?.get("content-type");
|
524
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
525
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
526
|
+
}
|
527
|
+
}
|
185
528
|
|
186
|
-
const VERSION = "0.
|
529
|
+
const VERSION = "0.28.1";
|
187
530
|
|
188
531
|
class ErrorWithCause extends Error {
|
189
532
|
constructor(message, options) {
|
@@ -194,7 +537,7 @@ class FetcherError extends ErrorWithCause {
|
|
194
537
|
constructor(status, data, requestId) {
|
195
538
|
super(getMessage(data));
|
196
539
|
this.status = status;
|
197
|
-
this.errors = isBulkError(data) ? data.errors :
|
540
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
198
541
|
this.requestId = requestId;
|
199
542
|
if (data instanceof Error) {
|
200
543
|
this.stack = data.stack;
|
@@ -226,6 +569,7 @@ function getMessage(data) {
|
|
226
569
|
}
|
227
570
|
}
|
228
571
|
|
572
|
+
const pool = new ApiRequestPool();
|
229
573
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
230
574
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
231
575
|
if (value === void 0 || value === null)
|
@@ -258,14 +602,27 @@ function hostHeader(url) {
|
|
258
602
|
const { groups } = pattern.exec(url) ?? {};
|
259
603
|
return groups?.host ? { Host: groups.host } : {};
|
260
604
|
}
|
605
|
+
async function parseBody(body, headers) {
|
606
|
+
if (!isDefined(body))
|
607
|
+
return void 0;
|
608
|
+
if (isBlob(body) || typeof body.text === "function") {
|
609
|
+
return body;
|
610
|
+
}
|
611
|
+
const { "Content-Type": contentType } = headers ?? {};
|
612
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
613
|
+
return JSON.stringify(body);
|
614
|
+
}
|
615
|
+
return body;
|
616
|
+
}
|
617
|
+
const defaultClientID = generateUUID();
|
261
618
|
async function fetch$1({
|
262
619
|
url: path,
|
263
620
|
method,
|
264
621
|
body,
|
265
|
-
headers,
|
622
|
+
headers: customHeaders,
|
266
623
|
pathParams,
|
267
624
|
queryParams,
|
268
|
-
|
625
|
+
fetch: fetch2,
|
269
626
|
apiKey,
|
270
627
|
endpoint,
|
271
628
|
apiUrl,
|
@@ -274,9 +631,13 @@ async function fetch$1({
|
|
274
631
|
signal,
|
275
632
|
clientID,
|
276
633
|
sessionID,
|
277
|
-
|
634
|
+
clientName,
|
635
|
+
xataAgentExtra,
|
636
|
+
fetchOptions = {},
|
637
|
+
rawResponse = false
|
278
638
|
}) {
|
279
|
-
|
639
|
+
pool.setFetch(fetch2);
|
640
|
+
return await trace(
|
280
641
|
`${method.toUpperCase()} ${path}`,
|
281
642
|
async ({ setAttributes }) => {
|
282
643
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
@@ -286,24 +647,29 @@ async function fetch$1({
|
|
286
647
|
[TraceAttributes.HTTP_URL]: url,
|
287
648
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
288
649
|
});
|
289
|
-
const
|
650
|
+
const xataAgent = compact([
|
651
|
+
["client", "TS_SDK"],
|
652
|
+
["version", VERSION],
|
653
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
654
|
+
...Object.entries(xataAgentExtra ?? {})
|
655
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
656
|
+
const headers = compactObject({
|
657
|
+
"Accept-Encoding": "identity",
|
658
|
+
"Content-Type": "application/json",
|
659
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
660
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
661
|
+
"X-Xata-Agent": xataAgent,
|
662
|
+
...customHeaders,
|
663
|
+
...hostHeader(fullUrl),
|
664
|
+
Authorization: `Bearer ${apiKey}`
|
665
|
+
});
|
666
|
+
const response = await pool.request(url, {
|
290
667
|
...fetchOptions,
|
291
668
|
method: method.toUpperCase(),
|
292
|
-
body:
|
293
|
-
headers
|
294
|
-
"Content-Type": "application/json",
|
295
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
296
|
-
"X-Xata-Client-ID": clientID ?? "",
|
297
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
298
|
-
...headers,
|
299
|
-
...hostHeader(fullUrl),
|
300
|
-
Authorization: `Bearer ${apiKey}`
|
301
|
-
},
|
669
|
+
body: await parseBody(body, headers),
|
670
|
+
headers,
|
302
671
|
signal
|
303
672
|
});
|
304
|
-
if (response.status === 204) {
|
305
|
-
return {};
|
306
|
-
}
|
307
673
|
const { host, protocol } = parseUrl(response.url);
|
308
674
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
309
675
|
setAttributes({
|
@@ -311,10 +677,20 @@ async function fetch$1({
|
|
311
677
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
312
678
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
313
679
|
[TraceAttributes.HTTP_HOST]: host,
|
314
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
680
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
681
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
315
682
|
});
|
683
|
+
const message = response.headers?.get("x-xata-message");
|
684
|
+
if (message)
|
685
|
+
console.warn(message);
|
686
|
+
if (response.status === 204) {
|
687
|
+
return {};
|
688
|
+
}
|
689
|
+
if (response.status === 429) {
|
690
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
691
|
+
}
|
316
692
|
try {
|
317
|
-
const jsonResponse = await response.json();
|
693
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
318
694
|
if (response.ok) {
|
319
695
|
return jsonResponse;
|
320
696
|
}
|
@@ -326,6 +702,59 @@ async function fetch$1({
|
|
326
702
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
327
703
|
);
|
328
704
|
}
|
705
|
+
function fetchSSERequest({
|
706
|
+
url: path,
|
707
|
+
method,
|
708
|
+
body,
|
709
|
+
headers: customHeaders,
|
710
|
+
pathParams,
|
711
|
+
queryParams,
|
712
|
+
fetch: fetch2,
|
713
|
+
apiKey,
|
714
|
+
endpoint,
|
715
|
+
apiUrl,
|
716
|
+
workspacesApiUrl,
|
717
|
+
onMessage,
|
718
|
+
onError,
|
719
|
+
onClose,
|
720
|
+
signal,
|
721
|
+
clientID,
|
722
|
+
sessionID,
|
723
|
+
clientName,
|
724
|
+
xataAgentExtra
|
725
|
+
}) {
|
726
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
727
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
728
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
729
|
+
void fetchEventSource(url, {
|
730
|
+
method,
|
731
|
+
body: JSON.stringify(body),
|
732
|
+
fetch: fetch2,
|
733
|
+
signal,
|
734
|
+
headers: {
|
735
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
736
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
737
|
+
"X-Xata-Agent": compact([
|
738
|
+
["client", "TS_SDK"],
|
739
|
+
["version", VERSION],
|
740
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
741
|
+
...Object.entries(xataAgentExtra ?? {})
|
742
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
743
|
+
...customHeaders,
|
744
|
+
Authorization: `Bearer ${apiKey}`,
|
745
|
+
"Content-Type": "application/json"
|
746
|
+
},
|
747
|
+
onmessage(ev) {
|
748
|
+
onMessage?.(JSON.parse(ev.data));
|
749
|
+
},
|
750
|
+
onerror(ev) {
|
751
|
+
onError?.(JSON.parse(ev.data));
|
752
|
+
},
|
753
|
+
onclose() {
|
754
|
+
onClose?.();
|
755
|
+
}
|
756
|
+
});
|
757
|
+
}
|
329
758
|
function parseUrl(url) {
|
330
759
|
try {
|
331
760
|
const { host, protocol } = new URL(url);
|
@@ -337,17 +766,25 @@ function parseUrl(url) {
|
|
337
766
|
|
338
767
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
339
768
|
|
340
|
-
const
|
769
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
770
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
771
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
772
|
+
method: "get",
|
773
|
+
...variables,
|
774
|
+
signal
|
775
|
+
});
|
776
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
777
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
778
|
+
method: "get",
|
779
|
+
...variables,
|
780
|
+
signal
|
781
|
+
});
|
341
782
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
342
783
|
url: "/dbs/{dbName}",
|
343
784
|
method: "get",
|
344
785
|
...variables,
|
345
786
|
signal
|
346
787
|
});
|
347
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
348
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
349
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
350
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
351
788
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
352
789
|
url: "/db/{dbBranchName}",
|
353
790
|
method: "get",
|
@@ -361,6 +798,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
361
798
|
...variables,
|
362
799
|
signal
|
363
800
|
});
|
801
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
802
|
+
url: "/db/{dbBranchName}/schema",
|
803
|
+
method: "get",
|
804
|
+
...variables,
|
805
|
+
signal
|
806
|
+
});
|
807
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
808
|
+
url: "/db/{dbBranchName}/copy",
|
809
|
+
method: "post",
|
810
|
+
...variables,
|
811
|
+
signal
|
812
|
+
});
|
364
813
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
365
814
|
url: "/db/{dbBranchName}/metadata",
|
366
815
|
method: "put",
|
@@ -386,7 +835,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
386
835
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
387
836
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
388
837
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
389
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
390
838
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
391
839
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
392
840
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -411,6 +859,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
411
859
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
412
860
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
413
861
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
862
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
414
863
|
const createTable = (variables, signal) => dataPlaneFetch({
|
415
864
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
416
865
|
method: "put",
|
@@ -453,7 +902,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
453
902
|
...variables,
|
454
903
|
signal
|
455
904
|
});
|
905
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
456
906
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
907
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
908
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
909
|
+
method: "get",
|
910
|
+
...variables,
|
911
|
+
signal
|
912
|
+
});
|
913
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
914
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
915
|
+
method: "put",
|
916
|
+
...variables,
|
917
|
+
signal
|
918
|
+
});
|
919
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
920
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
921
|
+
method: "delete",
|
922
|
+
...variables,
|
923
|
+
signal
|
924
|
+
});
|
925
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
926
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
927
|
+
method: "get",
|
928
|
+
...variables,
|
929
|
+
signal
|
930
|
+
});
|
931
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
932
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
933
|
+
method: "put",
|
934
|
+
...variables,
|
935
|
+
signal
|
936
|
+
});
|
937
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
938
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
939
|
+
method: "delete",
|
940
|
+
...variables,
|
941
|
+
signal
|
942
|
+
});
|
457
943
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
458
944
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
459
945
|
method: "get",
|
@@ -483,21 +969,38 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
483
969
|
...variables,
|
484
970
|
signal
|
485
971
|
});
|
972
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
973
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
974
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
975
|
+
method: "post",
|
976
|
+
...variables,
|
977
|
+
signal
|
978
|
+
});
|
979
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
486
980
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
487
981
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
982
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
983
|
+
url: "/file/{fileId}",
|
984
|
+
method: "get",
|
985
|
+
...variables,
|
986
|
+
signal
|
987
|
+
});
|
988
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
989
|
+
url: "/db/{dbBranchName}/sql",
|
990
|
+
method: "post",
|
991
|
+
...variables,
|
992
|
+
signal
|
993
|
+
});
|
488
994
|
const operationsByTag$2 = {
|
489
|
-
database: {
|
490
|
-
dEPRECATEDgetDatabaseList,
|
491
|
-
dEPRECATEDcreateDatabase,
|
492
|
-
dEPRECATEDdeleteDatabase,
|
493
|
-
dEPRECATEDgetDatabaseMetadata,
|
494
|
-
dEPRECATEDupdateDatabaseMetadata
|
495
|
-
},
|
496
995
|
branch: {
|
996
|
+
applyMigration,
|
997
|
+
pgRollStatus,
|
998
|
+
pgRollJobStatus,
|
497
999
|
getBranchList,
|
498
1000
|
getBranchDetails,
|
499
1001
|
createBranch,
|
500
1002
|
deleteBranch,
|
1003
|
+
copyBranch,
|
501
1004
|
updateBranchMetadata,
|
502
1005
|
getBranchMetadata,
|
503
1006
|
getBranchStats,
|
@@ -507,6 +1010,7 @@ const operationsByTag$2 = {
|
|
507
1010
|
resolveBranch
|
508
1011
|
},
|
509
1012
|
migrations: {
|
1013
|
+
getSchema,
|
510
1014
|
getBranchMigrationHistory,
|
511
1015
|
getBranchMigrationPlan,
|
512
1016
|
executeBranchMigrationPlan,
|
@@ -515,17 +1019,8 @@ const operationsByTag$2 = {
|
|
515
1019
|
compareBranchSchemas,
|
516
1020
|
updateBranchSchema,
|
517
1021
|
previewBranchSchemaEdit,
|
518
|
-
applyBranchSchemaEdit
|
519
|
-
|
520
|
-
records: {
|
521
|
-
branchTransaction,
|
522
|
-
insertRecord,
|
523
|
-
getRecord,
|
524
|
-
insertRecordWithID,
|
525
|
-
updateRecordWithID,
|
526
|
-
upsertRecordWithID,
|
527
|
-
deleteRecord,
|
528
|
-
bulkInsertTableRecords
|
1022
|
+
applyBranchSchemaEdit,
|
1023
|
+
pushBranchMigrations
|
529
1024
|
},
|
530
1025
|
migrationRequests: {
|
531
1026
|
queryMigrationRequests,
|
@@ -549,11 +1044,34 @@ const operationsByTag$2 = {
|
|
549
1044
|
updateColumn,
|
550
1045
|
deleteColumn
|
551
1046
|
},
|
552
|
-
|
1047
|
+
records: {
|
1048
|
+
branchTransaction,
|
1049
|
+
insertRecord,
|
1050
|
+
getRecord,
|
1051
|
+
insertRecordWithID,
|
1052
|
+
updateRecordWithID,
|
1053
|
+
upsertRecordWithID,
|
1054
|
+
deleteRecord,
|
1055
|
+
bulkInsertTableRecords
|
1056
|
+
},
|
1057
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1058
|
+
searchAndFilter: {
|
1059
|
+
queryTable,
|
1060
|
+
searchBranch,
|
1061
|
+
searchTable,
|
1062
|
+
vectorSearchTable,
|
1063
|
+
askTable,
|
1064
|
+
askTableSession,
|
1065
|
+
summarizeTable,
|
1066
|
+
aggregateTable
|
1067
|
+
},
|
1068
|
+
sql: { sqlQuery }
|
553
1069
|
};
|
554
1070
|
|
555
1071
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
556
1072
|
|
1073
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1074
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
557
1075
|
const getUser = (variables, signal) => controlPlaneFetch({
|
558
1076
|
url: "/user",
|
559
1077
|
method: "get",
|
@@ -590,6 +1108,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
590
1108
|
...variables,
|
591
1109
|
signal
|
592
1110
|
});
|
1111
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1112
|
+
url: "/user/oauth/clients",
|
1113
|
+
method: "get",
|
1114
|
+
...variables,
|
1115
|
+
signal
|
1116
|
+
});
|
1117
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1118
|
+
url: "/user/oauth/clients/{clientId}",
|
1119
|
+
method: "delete",
|
1120
|
+
...variables,
|
1121
|
+
signal
|
1122
|
+
});
|
1123
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1124
|
+
url: "/user/oauth/tokens",
|
1125
|
+
method: "get",
|
1126
|
+
...variables,
|
1127
|
+
signal
|
1128
|
+
});
|
1129
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1130
|
+
url: "/user/oauth/tokens/{token}",
|
1131
|
+
method: "delete",
|
1132
|
+
...variables,
|
1133
|
+
signal
|
1134
|
+
});
|
1135
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
593
1136
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
594
1137
|
url: "/workspaces",
|
595
1138
|
method: "get",
|
@@ -633,6 +1176,20 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
633
1176
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
634
1177
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
635
1178
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1179
|
+
const listClusters = (variables, signal) => controlPlaneFetch({
|
1180
|
+
url: "/workspaces/{workspaceId}/clusters",
|
1181
|
+
method: "get",
|
1182
|
+
...variables,
|
1183
|
+
signal
|
1184
|
+
});
|
1185
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1186
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1187
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1188
|
+
method: "get",
|
1189
|
+
...variables,
|
1190
|
+
signal
|
1191
|
+
});
|
1192
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
636
1193
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
637
1194
|
url: "/workspaces/{workspaceId}/dbs",
|
638
1195
|
method: "get",
|
@@ -648,6 +1205,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
648
1205
|
});
|
649
1206
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
650
1207
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1208
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1209
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1210
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1211
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
651
1212
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
652
1213
|
url: "/workspaces/{workspaceId}/regions",
|
653
1214
|
method: "get",
|
@@ -655,6 +1216,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
655
1216
|
signal
|
656
1217
|
});
|
657
1218
|
const operationsByTag$1 = {
|
1219
|
+
oAuth: {
|
1220
|
+
getAuthorizationCode,
|
1221
|
+
grantAuthorizationCode,
|
1222
|
+
getUserOAuthClients,
|
1223
|
+
deleteUserOAuthClient,
|
1224
|
+
getUserOAuthAccessTokens,
|
1225
|
+
deleteOAuthAccessToken,
|
1226
|
+
updateOAuthAccessToken
|
1227
|
+
},
|
658
1228
|
users: { getUser, updateUser, deleteUser },
|
659
1229
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
660
1230
|
workspaces: {
|
@@ -674,12 +1244,17 @@ const operationsByTag$1 = {
|
|
674
1244
|
acceptWorkspaceMemberInvite,
|
675
1245
|
resendWorkspaceMemberInvite
|
676
1246
|
},
|
1247
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
677
1248
|
databases: {
|
678
1249
|
getDatabaseList,
|
679
1250
|
createDatabase,
|
680
1251
|
deleteDatabase,
|
681
1252
|
getDatabaseMetadata,
|
682
1253
|
updateDatabaseMetadata,
|
1254
|
+
renameDatabase,
|
1255
|
+
getDatabaseGithubSettings,
|
1256
|
+
updateDatabaseGithubSettings,
|
1257
|
+
deleteDatabaseGithubSettings,
|
683
1258
|
listRegions
|
684
1259
|
}
|
685
1260
|
};
|
@@ -700,8 +1275,12 @@ const providers = {
|
|
700
1275
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
701
1276
|
},
|
702
1277
|
staging: {
|
703
|
-
main: "https://staging.
|
704
|
-
workspaces: "https://{workspaceId}.
|
1278
|
+
main: "https://api.staging-xata.dev",
|
1279
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1280
|
+
},
|
1281
|
+
dev: {
|
1282
|
+
main: "https://api.dev-xata.dev",
|
1283
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
705
1284
|
}
|
706
1285
|
};
|
707
1286
|
function isHostProviderAlias(alias) {
|
@@ -719,1055 +1298,264 @@ function parseProviderString(provider = "production") {
|
|
719
1298
|
return null;
|
720
1299
|
return { main, workspaces };
|
721
1300
|
}
|
1301
|
+
function buildProviderString(provider) {
|
1302
|
+
if (isHostProviderAlias(provider))
|
1303
|
+
return provider;
|
1304
|
+
return `${provider.main},${provider.workspaces}`;
|
1305
|
+
}
|
722
1306
|
function parseWorkspacesUrlParts(url) {
|
723
1307
|
if (!isString(url))
|
724
1308
|
return null;
|
725
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
726
|
-
const
|
727
|
-
const
|
1309
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1310
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1311
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1312
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1313
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
728
1314
|
if (!match)
|
729
1315
|
return null;
|
730
|
-
return { workspace: match[1], region: match[2]
|
1316
|
+
return { workspace: match[1], region: match[2] };
|
731
1317
|
}
|
732
1318
|
|
733
|
-
|
734
|
-
if (!member.has(obj))
|
735
|
-
throw TypeError("Cannot " + msg);
|
736
|
-
};
|
737
|
-
var __privateGet$7 = (obj, member, getter) => {
|
738
|
-
__accessCheck$7(obj, member, "read from private field");
|
739
|
-
return getter ? getter.call(obj) : member.get(obj);
|
740
|
-
};
|
741
|
-
var __privateAdd$7 = (obj, member, value) => {
|
742
|
-
if (member.has(obj))
|
743
|
-
throw TypeError("Cannot add the same private member more than once");
|
744
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
745
|
-
};
|
746
|
-
var __privateSet$7 = (obj, member, value, setter) => {
|
747
|
-
__accessCheck$7(obj, member, "write to private field");
|
748
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
749
|
-
return value;
|
750
|
-
};
|
751
|
-
var _extraProps, _namespaces;
|
752
|
-
class XataApiClient {
|
1319
|
+
const buildApiClient = () => class {
|
753
1320
|
constructor(options = {}) {
|
754
|
-
__privateAdd$7(this, _extraProps, void 0);
|
755
|
-
__privateAdd$7(this, _namespaces, {});
|
756
1321
|
const provider = options.host ?? "production";
|
757
1322
|
const apiKey = options.apiKey ?? getAPIKey();
|
758
1323
|
const trace = options.trace ?? defaultTrace;
|
1324
|
+
const clientID = generateUUID();
|
759
1325
|
if (!apiKey) {
|
760
1326
|
throw new Error("Could not resolve a valid apiKey");
|
761
1327
|
}
|
762
|
-
|
1328
|
+
const extraProps = {
|
763
1329
|
apiUrl: getHostUrl(provider, "main"),
|
764
1330
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
765
|
-
|
1331
|
+
fetch: getFetchImplementation(options.fetch),
|
766
1332
|
apiKey,
|
767
|
-
trace
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
__privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
|
793
|
-
return __privateGet$7(this, _namespaces).database;
|
794
|
-
}
|
795
|
-
get branches() {
|
796
|
-
if (!__privateGet$7(this, _namespaces).branches)
|
797
|
-
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
798
|
-
return __privateGet$7(this, _namespaces).branches;
|
799
|
-
}
|
800
|
-
get migrations() {
|
801
|
-
if (!__privateGet$7(this, _namespaces).migrations)
|
802
|
-
__privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
|
803
|
-
return __privateGet$7(this, _namespaces).migrations;
|
804
|
-
}
|
805
|
-
get migrationRequests() {
|
806
|
-
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
807
|
-
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
808
|
-
return __privateGet$7(this, _namespaces).migrationRequests;
|
809
|
-
}
|
810
|
-
get tables() {
|
811
|
-
if (!__privateGet$7(this, _namespaces).tables)
|
812
|
-
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
813
|
-
return __privateGet$7(this, _namespaces).tables;
|
814
|
-
}
|
815
|
-
get records() {
|
816
|
-
if (!__privateGet$7(this, _namespaces).records)
|
817
|
-
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
818
|
-
return __privateGet$7(this, _namespaces).records;
|
819
|
-
}
|
820
|
-
get searchAndFilter() {
|
821
|
-
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
822
|
-
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
823
|
-
return __privateGet$7(this, _namespaces).searchAndFilter;
|
824
|
-
}
|
825
|
-
}
|
826
|
-
_extraProps = new WeakMap();
|
827
|
-
_namespaces = new WeakMap();
|
828
|
-
class UserApi {
|
829
|
-
constructor(extraProps) {
|
830
|
-
this.extraProps = extraProps;
|
831
|
-
}
|
832
|
-
getUser() {
|
833
|
-
return operationsByTag.users.getUser({ ...this.extraProps });
|
834
|
-
}
|
835
|
-
updateUser({ user }) {
|
836
|
-
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
837
|
-
}
|
838
|
-
deleteUser() {
|
839
|
-
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
840
|
-
}
|
841
|
-
}
|
842
|
-
class AuthenticationApi {
|
843
|
-
constructor(extraProps) {
|
844
|
-
this.extraProps = extraProps;
|
845
|
-
}
|
846
|
-
getUserAPIKeys() {
|
847
|
-
return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
|
848
|
-
}
|
849
|
-
createUserAPIKey({ name }) {
|
850
|
-
return operationsByTag.authentication.createUserAPIKey({
|
851
|
-
pathParams: { keyName: name },
|
852
|
-
...this.extraProps
|
853
|
-
});
|
854
|
-
}
|
855
|
-
deleteUserAPIKey({ name }) {
|
856
|
-
return operationsByTag.authentication.deleteUserAPIKey({
|
857
|
-
pathParams: { keyName: name },
|
858
|
-
...this.extraProps
|
859
|
-
});
|
860
|
-
}
|
861
|
-
}
|
862
|
-
class WorkspaceApi {
|
863
|
-
constructor(extraProps) {
|
864
|
-
this.extraProps = extraProps;
|
865
|
-
}
|
866
|
-
getWorkspacesList() {
|
867
|
-
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
868
|
-
}
|
869
|
-
createWorkspace({ data }) {
|
870
|
-
return operationsByTag.workspaces.createWorkspace({
|
871
|
-
body: data,
|
872
|
-
...this.extraProps
|
873
|
-
});
|
874
|
-
}
|
875
|
-
getWorkspace({ workspace }) {
|
876
|
-
return operationsByTag.workspaces.getWorkspace({
|
877
|
-
pathParams: { workspaceId: workspace },
|
878
|
-
...this.extraProps
|
879
|
-
});
|
880
|
-
}
|
881
|
-
updateWorkspace({
|
882
|
-
workspace,
|
883
|
-
update
|
884
|
-
}) {
|
885
|
-
return operationsByTag.workspaces.updateWorkspace({
|
886
|
-
pathParams: { workspaceId: workspace },
|
887
|
-
body: update,
|
888
|
-
...this.extraProps
|
889
|
-
});
|
890
|
-
}
|
891
|
-
deleteWorkspace({ workspace }) {
|
892
|
-
return operationsByTag.workspaces.deleteWorkspace({
|
893
|
-
pathParams: { workspaceId: workspace },
|
894
|
-
...this.extraProps
|
895
|
-
});
|
896
|
-
}
|
897
|
-
getWorkspaceMembersList({ workspace }) {
|
898
|
-
return operationsByTag.workspaces.getWorkspaceMembersList({
|
899
|
-
pathParams: { workspaceId: workspace },
|
900
|
-
...this.extraProps
|
901
|
-
});
|
902
|
-
}
|
903
|
-
updateWorkspaceMemberRole({
|
904
|
-
workspace,
|
905
|
-
user,
|
906
|
-
role
|
907
|
-
}) {
|
908
|
-
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
909
|
-
pathParams: { workspaceId: workspace, userId: user },
|
910
|
-
body: { role },
|
911
|
-
...this.extraProps
|
912
|
-
});
|
913
|
-
}
|
914
|
-
removeWorkspaceMember({
|
915
|
-
workspace,
|
916
|
-
user
|
917
|
-
}) {
|
918
|
-
return operationsByTag.workspaces.removeWorkspaceMember({
|
919
|
-
pathParams: { workspaceId: workspace, userId: user },
|
920
|
-
...this.extraProps
|
921
|
-
});
|
922
|
-
}
|
923
|
-
}
|
924
|
-
class InvitesApi {
|
925
|
-
constructor(extraProps) {
|
926
|
-
this.extraProps = extraProps;
|
927
|
-
}
|
928
|
-
inviteWorkspaceMember({
|
929
|
-
workspace,
|
930
|
-
email,
|
931
|
-
role
|
932
|
-
}) {
|
933
|
-
return operationsByTag.invites.inviteWorkspaceMember({
|
934
|
-
pathParams: { workspaceId: workspace },
|
935
|
-
body: { email, role },
|
936
|
-
...this.extraProps
|
937
|
-
});
|
938
|
-
}
|
939
|
-
updateWorkspaceMemberInvite({
|
940
|
-
workspace,
|
941
|
-
invite,
|
942
|
-
role
|
943
|
-
}) {
|
944
|
-
return operationsByTag.invites.updateWorkspaceMemberInvite({
|
945
|
-
pathParams: { workspaceId: workspace, inviteId: invite },
|
946
|
-
body: { role },
|
947
|
-
...this.extraProps
|
948
|
-
});
|
949
|
-
}
|
950
|
-
cancelWorkspaceMemberInvite({
|
951
|
-
workspace,
|
952
|
-
invite
|
953
|
-
}) {
|
954
|
-
return operationsByTag.invites.cancelWorkspaceMemberInvite({
|
955
|
-
pathParams: { workspaceId: workspace, inviteId: invite },
|
956
|
-
...this.extraProps
|
957
|
-
});
|
958
|
-
}
|
959
|
-
acceptWorkspaceMemberInvite({
|
960
|
-
workspace,
|
961
|
-
key
|
962
|
-
}) {
|
963
|
-
return operationsByTag.invites.acceptWorkspaceMemberInvite({
|
964
|
-
pathParams: { workspaceId: workspace, inviteKey: key },
|
965
|
-
...this.extraProps
|
966
|
-
});
|
967
|
-
}
|
968
|
-
resendWorkspaceMemberInvite({
|
969
|
-
workspace,
|
970
|
-
invite
|
971
|
-
}) {
|
972
|
-
return operationsByTag.invites.resendWorkspaceMemberInvite({
|
973
|
-
pathParams: { workspaceId: workspace, inviteId: invite },
|
974
|
-
...this.extraProps
|
975
|
-
});
|
976
|
-
}
|
977
|
-
}
|
978
|
-
class BranchApi {
|
979
|
-
constructor(extraProps) {
|
980
|
-
this.extraProps = extraProps;
|
981
|
-
}
|
982
|
-
getBranchList({
|
983
|
-
workspace,
|
984
|
-
region,
|
985
|
-
database
|
986
|
-
}) {
|
987
|
-
return operationsByTag.branch.getBranchList({
|
988
|
-
pathParams: { workspace, region, dbName: database },
|
989
|
-
...this.extraProps
|
990
|
-
});
|
991
|
-
}
|
992
|
-
getBranchDetails({
|
993
|
-
workspace,
|
994
|
-
region,
|
995
|
-
database,
|
996
|
-
branch
|
997
|
-
}) {
|
998
|
-
return operationsByTag.branch.getBranchDetails({
|
999
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1000
|
-
...this.extraProps
|
1001
|
-
});
|
1002
|
-
}
|
1003
|
-
createBranch({
|
1004
|
-
workspace,
|
1005
|
-
region,
|
1006
|
-
database,
|
1007
|
-
branch,
|
1008
|
-
from,
|
1009
|
-
metadata
|
1010
|
-
}) {
|
1011
|
-
return operationsByTag.branch.createBranch({
|
1012
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1013
|
-
body: { from, metadata },
|
1014
|
-
...this.extraProps
|
1015
|
-
});
|
1016
|
-
}
|
1017
|
-
deleteBranch({
|
1018
|
-
workspace,
|
1019
|
-
region,
|
1020
|
-
database,
|
1021
|
-
branch
|
1022
|
-
}) {
|
1023
|
-
return operationsByTag.branch.deleteBranch({
|
1024
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1025
|
-
...this.extraProps
|
1026
|
-
});
|
1027
|
-
}
|
1028
|
-
updateBranchMetadata({
|
1029
|
-
workspace,
|
1030
|
-
region,
|
1031
|
-
database,
|
1032
|
-
branch,
|
1033
|
-
metadata
|
1034
|
-
}) {
|
1035
|
-
return operationsByTag.branch.updateBranchMetadata({
|
1036
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1037
|
-
body: metadata,
|
1038
|
-
...this.extraProps
|
1039
|
-
});
|
1040
|
-
}
|
1041
|
-
getBranchMetadata({
|
1042
|
-
workspace,
|
1043
|
-
region,
|
1044
|
-
database,
|
1045
|
-
branch
|
1046
|
-
}) {
|
1047
|
-
return operationsByTag.branch.getBranchMetadata({
|
1048
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1049
|
-
...this.extraProps
|
1050
|
-
});
|
1051
|
-
}
|
1052
|
-
getBranchStats({
|
1053
|
-
workspace,
|
1054
|
-
region,
|
1055
|
-
database,
|
1056
|
-
branch
|
1057
|
-
}) {
|
1058
|
-
return operationsByTag.branch.getBranchStats({
|
1059
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1060
|
-
...this.extraProps
|
1061
|
-
});
|
1062
|
-
}
|
1063
|
-
getGitBranchesMapping({
|
1064
|
-
workspace,
|
1065
|
-
region,
|
1066
|
-
database
|
1067
|
-
}) {
|
1068
|
-
return operationsByTag.branch.getGitBranchesMapping({
|
1069
|
-
pathParams: { workspace, region, dbName: database },
|
1070
|
-
...this.extraProps
|
1071
|
-
});
|
1072
|
-
}
|
1073
|
-
addGitBranchesEntry({
|
1074
|
-
workspace,
|
1075
|
-
region,
|
1076
|
-
database,
|
1077
|
-
gitBranch,
|
1078
|
-
xataBranch
|
1079
|
-
}) {
|
1080
|
-
return operationsByTag.branch.addGitBranchesEntry({
|
1081
|
-
pathParams: { workspace, region, dbName: database },
|
1082
|
-
body: { gitBranch, xataBranch },
|
1083
|
-
...this.extraProps
|
1084
|
-
});
|
1085
|
-
}
|
1086
|
-
removeGitBranchesEntry({
|
1087
|
-
workspace,
|
1088
|
-
region,
|
1089
|
-
database,
|
1090
|
-
gitBranch
|
1091
|
-
}) {
|
1092
|
-
return operationsByTag.branch.removeGitBranchesEntry({
|
1093
|
-
pathParams: { workspace, region, dbName: database },
|
1094
|
-
queryParams: { gitBranch },
|
1095
|
-
...this.extraProps
|
1096
|
-
});
|
1097
|
-
}
|
1098
|
-
resolveBranch({
|
1099
|
-
workspace,
|
1100
|
-
region,
|
1101
|
-
database,
|
1102
|
-
gitBranch,
|
1103
|
-
fallbackBranch
|
1104
|
-
}) {
|
1105
|
-
return operationsByTag.branch.resolveBranch({
|
1106
|
-
pathParams: { workspace, region, dbName: database },
|
1107
|
-
queryParams: { gitBranch, fallbackBranch },
|
1108
|
-
...this.extraProps
|
1333
|
+
trace,
|
1334
|
+
clientName: options.clientName,
|
1335
|
+
xataAgentExtra: options.xataAgentExtra,
|
1336
|
+
clientID
|
1337
|
+
};
|
1338
|
+
return new Proxy(this, {
|
1339
|
+
get: (_target, namespace) => {
|
1340
|
+
if (operationsByTag[namespace] === void 0) {
|
1341
|
+
return void 0;
|
1342
|
+
}
|
1343
|
+
return new Proxy(
|
1344
|
+
{},
|
1345
|
+
{
|
1346
|
+
get: (_target2, operation) => {
|
1347
|
+
if (operationsByTag[namespace][operation] === void 0) {
|
1348
|
+
return void 0;
|
1349
|
+
}
|
1350
|
+
const method = operationsByTag[namespace][operation];
|
1351
|
+
return async (params) => {
|
1352
|
+
return await method({ ...params, ...extraProps });
|
1353
|
+
};
|
1354
|
+
}
|
1355
|
+
}
|
1356
|
+
);
|
1357
|
+
}
|
1109
1358
|
});
|
1110
1359
|
}
|
1360
|
+
};
|
1361
|
+
class XataApiClient extends buildApiClient() {
|
1111
1362
|
}
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
createTable({
|
1117
|
-
workspace,
|
1118
|
-
region,
|
1119
|
-
database,
|
1120
|
-
branch,
|
1121
|
-
table
|
1122
|
-
}) {
|
1123
|
-
return operationsByTag.table.createTable({
|
1124
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1125
|
-
...this.extraProps
|
1126
|
-
});
|
1127
|
-
}
|
1128
|
-
deleteTable({
|
1129
|
-
workspace,
|
1130
|
-
region,
|
1131
|
-
database,
|
1132
|
-
branch,
|
1133
|
-
table
|
1134
|
-
}) {
|
1135
|
-
return operationsByTag.table.deleteTable({
|
1136
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1137
|
-
...this.extraProps
|
1138
|
-
});
|
1139
|
-
}
|
1140
|
-
updateTable({
|
1141
|
-
workspace,
|
1142
|
-
region,
|
1143
|
-
database,
|
1144
|
-
branch,
|
1145
|
-
table,
|
1146
|
-
update
|
1147
|
-
}) {
|
1148
|
-
return operationsByTag.table.updateTable({
|
1149
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1150
|
-
body: update,
|
1151
|
-
...this.extraProps
|
1152
|
-
});
|
1153
|
-
}
|
1154
|
-
getTableSchema({
|
1155
|
-
workspace,
|
1156
|
-
region,
|
1157
|
-
database,
|
1158
|
-
branch,
|
1159
|
-
table
|
1160
|
-
}) {
|
1161
|
-
return operationsByTag.table.getTableSchema({
|
1162
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1163
|
-
...this.extraProps
|
1164
|
-
});
|
1165
|
-
}
|
1166
|
-
setTableSchema({
|
1167
|
-
workspace,
|
1168
|
-
region,
|
1169
|
-
database,
|
1170
|
-
branch,
|
1171
|
-
table,
|
1172
|
-
schema
|
1173
|
-
}) {
|
1174
|
-
return operationsByTag.table.setTableSchema({
|
1175
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1176
|
-
body: schema,
|
1177
|
-
...this.extraProps
|
1178
|
-
});
|
1179
|
-
}
|
1180
|
-
getTableColumns({
|
1181
|
-
workspace,
|
1182
|
-
region,
|
1183
|
-
database,
|
1184
|
-
branch,
|
1185
|
-
table
|
1186
|
-
}) {
|
1187
|
-
return operationsByTag.table.getTableColumns({
|
1188
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1189
|
-
...this.extraProps
|
1190
|
-
});
|
1191
|
-
}
|
1192
|
-
addTableColumn({
|
1193
|
-
workspace,
|
1194
|
-
region,
|
1195
|
-
database,
|
1196
|
-
branch,
|
1197
|
-
table,
|
1198
|
-
column
|
1199
|
-
}) {
|
1200
|
-
return operationsByTag.table.addTableColumn({
|
1201
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1202
|
-
body: column,
|
1203
|
-
...this.extraProps
|
1204
|
-
});
|
1205
|
-
}
|
1206
|
-
getColumn({
|
1207
|
-
workspace,
|
1208
|
-
region,
|
1209
|
-
database,
|
1210
|
-
branch,
|
1211
|
-
table,
|
1212
|
-
column
|
1213
|
-
}) {
|
1214
|
-
return operationsByTag.table.getColumn({
|
1215
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1216
|
-
...this.extraProps
|
1217
|
-
});
|
1218
|
-
}
|
1219
|
-
updateColumn({
|
1220
|
-
workspace,
|
1221
|
-
region,
|
1222
|
-
database,
|
1223
|
-
branch,
|
1224
|
-
table,
|
1225
|
-
column,
|
1226
|
-
update
|
1227
|
-
}) {
|
1228
|
-
return operationsByTag.table.updateColumn({
|
1229
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1230
|
-
body: update,
|
1231
|
-
...this.extraProps
|
1232
|
-
});
|
1233
|
-
}
|
1234
|
-
deleteColumn({
|
1235
|
-
workspace,
|
1236
|
-
region,
|
1237
|
-
database,
|
1238
|
-
branch,
|
1239
|
-
table,
|
1240
|
-
column
|
1241
|
-
}) {
|
1242
|
-
return operationsByTag.table.deleteColumn({
|
1243
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1244
|
-
...this.extraProps
|
1245
|
-
});
|
1363
|
+
|
1364
|
+
class XataApiPlugin {
|
1365
|
+
build(options) {
|
1366
|
+
return new XataApiClient(options);
|
1246
1367
|
}
|
1247
1368
|
}
|
1248
|
-
|
1249
|
-
|
1250
|
-
this.extraProps = extraProps;
|
1251
|
-
}
|
1252
|
-
insertRecord({
|
1253
|
-
workspace,
|
1254
|
-
region,
|
1255
|
-
database,
|
1256
|
-
branch,
|
1257
|
-
table,
|
1258
|
-
record,
|
1259
|
-
columns
|
1260
|
-
}) {
|
1261
|
-
return operationsByTag.records.insertRecord({
|
1262
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1263
|
-
queryParams: { columns },
|
1264
|
-
body: record,
|
1265
|
-
...this.extraProps
|
1266
|
-
});
|
1267
|
-
}
|
1268
|
-
getRecord({
|
1269
|
-
workspace,
|
1270
|
-
region,
|
1271
|
-
database,
|
1272
|
-
branch,
|
1273
|
-
table,
|
1274
|
-
id,
|
1275
|
-
columns
|
1276
|
-
}) {
|
1277
|
-
return operationsByTag.records.getRecord({
|
1278
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1279
|
-
queryParams: { columns },
|
1280
|
-
...this.extraProps
|
1281
|
-
});
|
1282
|
-
}
|
1283
|
-
insertRecordWithID({
|
1284
|
-
workspace,
|
1285
|
-
region,
|
1286
|
-
database,
|
1287
|
-
branch,
|
1288
|
-
table,
|
1289
|
-
id,
|
1290
|
-
record,
|
1291
|
-
columns,
|
1292
|
-
createOnly,
|
1293
|
-
ifVersion
|
1294
|
-
}) {
|
1295
|
-
return operationsByTag.records.insertRecordWithID({
|
1296
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1297
|
-
queryParams: { columns, createOnly, ifVersion },
|
1298
|
-
body: record,
|
1299
|
-
...this.extraProps
|
1300
|
-
});
|
1301
|
-
}
|
1302
|
-
updateRecordWithID({
|
1303
|
-
workspace,
|
1304
|
-
region,
|
1305
|
-
database,
|
1306
|
-
branch,
|
1307
|
-
table,
|
1308
|
-
id,
|
1309
|
-
record,
|
1310
|
-
columns,
|
1311
|
-
ifVersion
|
1312
|
-
}) {
|
1313
|
-
return operationsByTag.records.updateRecordWithID({
|
1314
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1315
|
-
queryParams: { columns, ifVersion },
|
1316
|
-
body: record,
|
1317
|
-
...this.extraProps
|
1318
|
-
});
|
1319
|
-
}
|
1320
|
-
upsertRecordWithID({
|
1321
|
-
workspace,
|
1322
|
-
region,
|
1323
|
-
database,
|
1324
|
-
branch,
|
1325
|
-
table,
|
1326
|
-
id,
|
1327
|
-
record,
|
1328
|
-
columns,
|
1329
|
-
ifVersion
|
1330
|
-
}) {
|
1331
|
-
return operationsByTag.records.upsertRecordWithID({
|
1332
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1333
|
-
queryParams: { columns, ifVersion },
|
1334
|
-
body: record,
|
1335
|
-
...this.extraProps
|
1336
|
-
});
|
1337
|
-
}
|
1338
|
-
deleteRecord({
|
1339
|
-
workspace,
|
1340
|
-
region,
|
1341
|
-
database,
|
1342
|
-
branch,
|
1343
|
-
table,
|
1344
|
-
id,
|
1345
|
-
columns
|
1346
|
-
}) {
|
1347
|
-
return operationsByTag.records.deleteRecord({
|
1348
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1349
|
-
queryParams: { columns },
|
1350
|
-
...this.extraProps
|
1351
|
-
});
|
1352
|
-
}
|
1353
|
-
bulkInsertTableRecords({
|
1354
|
-
workspace,
|
1355
|
-
region,
|
1356
|
-
database,
|
1357
|
-
branch,
|
1358
|
-
table,
|
1359
|
-
records,
|
1360
|
-
columns
|
1361
|
-
}) {
|
1362
|
-
return operationsByTag.records.bulkInsertTableRecords({
|
1363
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1364
|
-
queryParams: { columns },
|
1365
|
-
body: { records },
|
1366
|
-
...this.extraProps
|
1367
|
-
});
|
1368
|
-
}
|
1369
|
+
|
1370
|
+
class XataPlugin {
|
1369
1371
|
}
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
}) {
|
1386
|
-
return operationsByTag.searchAndFilter.queryTable({
|
1387
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1388
|
-
body: { filter, sort, page, columns, consistency },
|
1389
|
-
...this.extraProps
|
1390
|
-
});
|
1391
|
-
}
|
1392
|
-
searchTable({
|
1393
|
-
workspace,
|
1394
|
-
region,
|
1395
|
-
database,
|
1396
|
-
branch,
|
1397
|
-
table,
|
1398
|
-
query,
|
1399
|
-
fuzziness,
|
1400
|
-
target,
|
1401
|
-
prefix,
|
1402
|
-
filter,
|
1403
|
-
highlight,
|
1404
|
-
boosters
|
1405
|
-
}) {
|
1406
|
-
return operationsByTag.searchAndFilter.searchTable({
|
1407
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1408
|
-
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
1409
|
-
...this.extraProps
|
1410
|
-
});
|
1411
|
-
}
|
1412
|
-
searchBranch({
|
1413
|
-
workspace,
|
1414
|
-
region,
|
1415
|
-
database,
|
1416
|
-
branch,
|
1417
|
-
tables,
|
1418
|
-
query,
|
1419
|
-
fuzziness,
|
1420
|
-
prefix,
|
1421
|
-
highlight
|
1422
|
-
}) {
|
1423
|
-
return operationsByTag.searchAndFilter.searchBranch({
|
1424
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1425
|
-
body: { tables, query, fuzziness, prefix, highlight },
|
1426
|
-
...this.extraProps
|
1427
|
-
});
|
1428
|
-
}
|
1429
|
-
summarizeTable({
|
1430
|
-
workspace,
|
1431
|
-
region,
|
1432
|
-
database,
|
1433
|
-
branch,
|
1434
|
-
table,
|
1435
|
-
filter,
|
1436
|
-
columns,
|
1437
|
-
summaries,
|
1438
|
-
sort,
|
1439
|
-
summariesFilter,
|
1440
|
-
page,
|
1441
|
-
consistency
|
1442
|
-
}) {
|
1443
|
-
return operationsByTag.searchAndFilter.summarizeTable({
|
1444
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1445
|
-
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
1446
|
-
...this.extraProps
|
1447
|
-
});
|
1448
|
-
}
|
1449
|
-
aggregateTable({
|
1450
|
-
workspace,
|
1451
|
-
region,
|
1452
|
-
database,
|
1453
|
-
branch,
|
1454
|
-
table,
|
1455
|
-
filter,
|
1456
|
-
aggs
|
1457
|
-
}) {
|
1458
|
-
return operationsByTag.searchAndFilter.aggregateTable({
|
1459
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1460
|
-
body: { filter, aggs },
|
1461
|
-
...this.extraProps
|
1462
|
-
});
|
1463
|
-
}
|
1372
|
+
|
1373
|
+
function buildTransformString(transformations) {
|
1374
|
+
return transformations.flatMap(
|
1375
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
1376
|
+
if (key === "trim") {
|
1377
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
1378
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
1379
|
+
}
|
1380
|
+
if (key === "gravity" && typeof value === "object") {
|
1381
|
+
const { x = 0.5, y = 0.5 } = value;
|
1382
|
+
return `${key}=${[x, y].join("x")}`;
|
1383
|
+
}
|
1384
|
+
return `${key}=${value}`;
|
1385
|
+
})
|
1386
|
+
).join(",");
|
1464
1387
|
}
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
columns
|
1477
|
-
}) {
|
1478
|
-
return operationsByTag.migrationRequests.queryMigrationRequests({
|
1479
|
-
pathParams: { workspace, region, dbName: database },
|
1480
|
-
body: { filter, sort, page, columns },
|
1481
|
-
...this.extraProps
|
1482
|
-
});
|
1483
|
-
}
|
1484
|
-
createMigrationRequest({
|
1485
|
-
workspace,
|
1486
|
-
region,
|
1487
|
-
database,
|
1488
|
-
migration
|
1489
|
-
}) {
|
1490
|
-
return operationsByTag.migrationRequests.createMigrationRequest({
|
1491
|
-
pathParams: { workspace, region, dbName: database },
|
1492
|
-
body: migration,
|
1493
|
-
...this.extraProps
|
1494
|
-
});
|
1495
|
-
}
|
1496
|
-
getMigrationRequest({
|
1497
|
-
workspace,
|
1498
|
-
region,
|
1499
|
-
database,
|
1500
|
-
migrationRequest
|
1501
|
-
}) {
|
1502
|
-
return operationsByTag.migrationRequests.getMigrationRequest({
|
1503
|
-
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1504
|
-
...this.extraProps
|
1505
|
-
});
|
1506
|
-
}
|
1507
|
-
updateMigrationRequest({
|
1508
|
-
workspace,
|
1509
|
-
region,
|
1510
|
-
database,
|
1511
|
-
migrationRequest,
|
1512
|
-
update
|
1513
|
-
}) {
|
1514
|
-
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1515
|
-
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1516
|
-
body: update,
|
1517
|
-
...this.extraProps
|
1518
|
-
});
|
1519
|
-
}
|
1520
|
-
listMigrationRequestsCommits({
|
1521
|
-
workspace,
|
1522
|
-
region,
|
1523
|
-
database,
|
1524
|
-
migrationRequest,
|
1525
|
-
page
|
1526
|
-
}) {
|
1527
|
-
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1528
|
-
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1529
|
-
body: { page },
|
1530
|
-
...this.extraProps
|
1531
|
-
});
|
1532
|
-
}
|
1533
|
-
compareMigrationRequest({
|
1534
|
-
workspace,
|
1535
|
-
region,
|
1536
|
-
database,
|
1537
|
-
migrationRequest
|
1538
|
-
}) {
|
1539
|
-
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1540
|
-
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1541
|
-
...this.extraProps
|
1542
|
-
});
|
1543
|
-
}
|
1544
|
-
getMigrationRequestIsMerged({
|
1545
|
-
workspace,
|
1546
|
-
region,
|
1547
|
-
database,
|
1548
|
-
migrationRequest
|
1549
|
-
}) {
|
1550
|
-
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1551
|
-
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1552
|
-
...this.extraProps
|
1553
|
-
});
|
1554
|
-
}
|
1555
|
-
mergeMigrationRequest({
|
1556
|
-
workspace,
|
1557
|
-
region,
|
1558
|
-
database,
|
1559
|
-
migrationRequest
|
1560
|
-
}) {
|
1561
|
-
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1562
|
-
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1563
|
-
...this.extraProps
|
1564
|
-
});
|
1565
|
-
}
|
1388
|
+
function transformImage(url, ...transformations) {
|
1389
|
+
if (!isDefined(url))
|
1390
|
+
return void 0;
|
1391
|
+
const newTransformations = buildTransformString(transformations);
|
1392
|
+
const { hostname, pathname, search } = new URL(url);
|
1393
|
+
const pathParts = pathname.split("/");
|
1394
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
1395
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
1396
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
1397
|
+
const path = pathParts.join("/");
|
1398
|
+
return `https://${hostname}${transform}${path}${search}`;
|
1566
1399
|
}
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
}) {
|
1592
|
-
return operationsByTag.migrations.getBranchMigrationPlan({
|
1593
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1594
|
-
body: schema,
|
1595
|
-
...this.extraProps
|
1596
|
-
});
|
1597
|
-
}
|
1598
|
-
executeBranchMigrationPlan({
|
1599
|
-
workspace,
|
1600
|
-
region,
|
1601
|
-
database,
|
1602
|
-
branch,
|
1603
|
-
plan
|
1604
|
-
}) {
|
1605
|
-
return operationsByTag.migrations.executeBranchMigrationPlan({
|
1606
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1607
|
-
body: plan,
|
1608
|
-
...this.extraProps
|
1609
|
-
});
|
1610
|
-
}
|
1611
|
-
getBranchSchemaHistory({
|
1612
|
-
workspace,
|
1613
|
-
region,
|
1614
|
-
database,
|
1615
|
-
branch,
|
1616
|
-
page
|
1617
|
-
}) {
|
1618
|
-
return operationsByTag.migrations.getBranchSchemaHistory({
|
1619
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1620
|
-
body: { page },
|
1621
|
-
...this.extraProps
|
1622
|
-
});
|
1623
|
-
}
|
1624
|
-
compareBranchWithUserSchema({
|
1625
|
-
workspace,
|
1626
|
-
region,
|
1627
|
-
database,
|
1628
|
-
branch,
|
1629
|
-
schema
|
1630
|
-
}) {
|
1631
|
-
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1632
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1633
|
-
body: { schema },
|
1634
|
-
...this.extraProps
|
1635
|
-
});
|
1636
|
-
}
|
1637
|
-
compareBranchSchemas({
|
1638
|
-
workspace,
|
1639
|
-
region,
|
1640
|
-
database,
|
1641
|
-
branch,
|
1642
|
-
compare,
|
1643
|
-
schema
|
1644
|
-
}) {
|
1645
|
-
return operationsByTag.migrations.compareBranchSchemas({
|
1646
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1647
|
-
body: { schema },
|
1648
|
-
...this.extraProps
|
1649
|
-
});
|
1400
|
+
|
1401
|
+
class XataFile {
|
1402
|
+
constructor(file) {
|
1403
|
+
this.id = file.id;
|
1404
|
+
this.name = file.name;
|
1405
|
+
this.mediaType = file.mediaType;
|
1406
|
+
this.base64Content = file.base64Content;
|
1407
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
1408
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
1409
|
+
this.size = file.size;
|
1410
|
+
this.version = file.version;
|
1411
|
+
this.url = file.url;
|
1412
|
+
this.signedUrl = file.signedUrl;
|
1413
|
+
this.attributes = file.attributes;
|
1414
|
+
}
|
1415
|
+
static fromBuffer(buffer, options = {}) {
|
1416
|
+
const base64Content = buffer.toString("base64");
|
1417
|
+
return new XataFile({ ...options, base64Content });
|
1418
|
+
}
|
1419
|
+
toBuffer() {
|
1420
|
+
if (!this.base64Content) {
|
1421
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1422
|
+
}
|
1423
|
+
return Buffer.from(this.base64Content, "base64");
|
1650
1424
|
}
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
database,
|
1655
|
-
branch,
|
1656
|
-
migration
|
1657
|
-
}) {
|
1658
|
-
return operationsByTag.migrations.updateBranchSchema({
|
1659
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1660
|
-
body: migration,
|
1661
|
-
...this.extraProps
|
1662
|
-
});
|
1425
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
1426
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
1427
|
+
return this.fromUint8Array(uint8Array, options);
|
1663
1428
|
}
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
}) {
|
1671
|
-
return operationsByTag.migrations.previewBranchSchemaEdit({
|
1672
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1673
|
-
body: data,
|
1674
|
-
...this.extraProps
|
1675
|
-
});
|
1429
|
+
toArrayBuffer() {
|
1430
|
+
if (!this.base64Content) {
|
1431
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1432
|
+
}
|
1433
|
+
const binary = atob(this.base64Content);
|
1434
|
+
return new ArrayBuffer(binary.length);
|
1676
1435
|
}
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
return operationsByTag.migrations.applyBranchSchemaEdit({
|
1685
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1686
|
-
body: { edits },
|
1687
|
-
...this.extraProps
|
1688
|
-
});
|
1436
|
+
static fromUint8Array(uint8Array, options = {}) {
|
1437
|
+
let binary = "";
|
1438
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
1439
|
+
binary += String.fromCharCode(uint8Array[i]);
|
1440
|
+
}
|
1441
|
+
const base64Content = btoa(binary);
|
1442
|
+
return new XataFile({ ...options, base64Content });
|
1689
1443
|
}
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1444
|
+
toUint8Array() {
|
1445
|
+
if (!this.base64Content) {
|
1446
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1447
|
+
}
|
1448
|
+
const binary = atob(this.base64Content);
|
1449
|
+
const uint8Array = new Uint8Array(binary.length);
|
1450
|
+
for (let i = 0; i < binary.length; i++) {
|
1451
|
+
uint8Array[i] = binary.charCodeAt(i);
|
1452
|
+
}
|
1453
|
+
return uint8Array;
|
1694
1454
|
}
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
});
|
1455
|
+
static async fromBlob(file, options = {}) {
|
1456
|
+
const name = options.name ?? file.name;
|
1457
|
+
const mediaType = file.type;
|
1458
|
+
const arrayBuffer = await file.arrayBuffer();
|
1459
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
1700
1460
|
}
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
});
|
1461
|
+
toBlob() {
|
1462
|
+
if (!this.base64Content) {
|
1463
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1464
|
+
}
|
1465
|
+
const binary = atob(this.base64Content);
|
1466
|
+
const uint8Array = new Uint8Array(binary.length);
|
1467
|
+
for (let i = 0; i < binary.length; i++) {
|
1468
|
+
uint8Array[i] = binary.charCodeAt(i);
|
1469
|
+
}
|
1470
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
1711
1471
|
}
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
}) {
|
1716
|
-
return operationsByTag.databases.deleteDatabase({
|
1717
|
-
pathParams: { workspaceId: workspace, dbName: database },
|
1718
|
-
...this.extraProps
|
1719
|
-
});
|
1472
|
+
static fromString(string, options = {}) {
|
1473
|
+
const base64Content = btoa(string);
|
1474
|
+
return new XataFile({ ...options, base64Content });
|
1720
1475
|
}
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
return
|
1726
|
-
pathParams: { workspaceId: workspace, dbName: database },
|
1727
|
-
...this.extraProps
|
1728
|
-
});
|
1476
|
+
toString() {
|
1477
|
+
if (!this.base64Content) {
|
1478
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1479
|
+
}
|
1480
|
+
return atob(this.base64Content);
|
1729
1481
|
}
|
1730
|
-
|
1731
|
-
|
1732
|
-
database,
|
1733
|
-
metadata
|
1734
|
-
}) {
|
1735
|
-
return operationsByTag.databases.updateDatabaseMetadata({
|
1736
|
-
pathParams: { workspaceId: workspace, dbName: database },
|
1737
|
-
body: metadata,
|
1738
|
-
...this.extraProps
|
1739
|
-
});
|
1482
|
+
static fromBase64(base64Content, options = {}) {
|
1483
|
+
return new XataFile({ ...options, base64Content });
|
1740
1484
|
}
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1485
|
+
toBase64() {
|
1486
|
+
if (!this.base64Content) {
|
1487
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1488
|
+
}
|
1489
|
+
return this.base64Content;
|
1746
1490
|
}
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1491
|
+
transform(...options) {
|
1492
|
+
return {
|
1493
|
+
url: transformImage(this.url, ...options),
|
1494
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
1495
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
1496
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
1497
|
+
};
|
1753
1498
|
}
|
1754
1499
|
}
|
1500
|
+
const parseInputFileEntry = async (entry) => {
|
1501
|
+
if (!isDefined(entry))
|
1502
|
+
return null;
|
1503
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
1504
|
+
return compactObject({
|
1505
|
+
id,
|
1506
|
+
// Name cannot be an empty string in our API
|
1507
|
+
name: name ? name : void 0,
|
1508
|
+
mediaType,
|
1509
|
+
base64Content,
|
1510
|
+
enablePublicUrl,
|
1511
|
+
signedUrlTimeout
|
1512
|
+
});
|
1513
|
+
};
|
1755
1514
|
|
1756
|
-
|
1515
|
+
function cleanFilter(filter) {
|
1516
|
+
if (!isDefined(filter))
|
1517
|
+
return void 0;
|
1518
|
+
if (!isObject(filter))
|
1519
|
+
return filter;
|
1520
|
+
const values = Object.fromEntries(
|
1521
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
1522
|
+
if (!isDefined(value))
|
1523
|
+
return acc;
|
1524
|
+
if (Array.isArray(value)) {
|
1525
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
1526
|
+
if (clean.length === 0)
|
1527
|
+
return acc;
|
1528
|
+
return [...acc, [key, clean]];
|
1529
|
+
}
|
1530
|
+
if (isObject(value)) {
|
1531
|
+
const clean = cleanFilter(value);
|
1532
|
+
if (!isDefined(clean))
|
1533
|
+
return acc;
|
1534
|
+
return [...acc, [key, clean]];
|
1535
|
+
}
|
1536
|
+
return [...acc, [key, value]];
|
1537
|
+
}, [])
|
1538
|
+
);
|
1539
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
1757
1540
|
}
|
1758
1541
|
|
1759
|
-
function
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1542
|
+
function stringifyJson(value) {
|
1543
|
+
if (!isDefined(value))
|
1544
|
+
return value;
|
1545
|
+
if (isString(value))
|
1546
|
+
return value;
|
1547
|
+
try {
|
1548
|
+
return JSON.stringify(value);
|
1549
|
+
} catch (e) {
|
1550
|
+
return value;
|
1551
|
+
}
|
1764
1552
|
}
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1553
|
+
function parseJson(value) {
|
1554
|
+
try {
|
1555
|
+
return JSON.parse(value);
|
1556
|
+
} catch (e) {
|
1557
|
+
return value;
|
1558
|
+
}
|
1771
1559
|
}
|
1772
1560
|
|
1773
1561
|
var __accessCheck$6 = (obj, member, msg) => {
|
@@ -1796,31 +1584,59 @@ class Page {
|
|
1796
1584
|
this.meta = meta;
|
1797
1585
|
this.records = new RecordArray(this, records);
|
1798
1586
|
}
|
1587
|
+
/**
|
1588
|
+
* Retrieves the next page of results.
|
1589
|
+
* @param size Maximum number of results to be retrieved.
|
1590
|
+
* @param offset Number of results to skip when retrieving the results.
|
1591
|
+
* @returns The next page or results.
|
1592
|
+
*/
|
1799
1593
|
async nextPage(size, offset) {
|
1800
1594
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1801
1595
|
}
|
1596
|
+
/**
|
1597
|
+
* Retrieves the previous page of results.
|
1598
|
+
* @param size Maximum number of results to be retrieved.
|
1599
|
+
* @param offset Number of results to skip when retrieving the results.
|
1600
|
+
* @returns The previous page or results.
|
1601
|
+
*/
|
1802
1602
|
async previousPage(size, offset) {
|
1803
1603
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1804
1604
|
}
|
1605
|
+
/**
|
1606
|
+
* Retrieves the start page of results.
|
1607
|
+
* @param size Maximum number of results to be retrieved.
|
1608
|
+
* @param offset Number of results to skip when retrieving the results.
|
1609
|
+
* @returns The start page or results.
|
1610
|
+
*/
|
1805
1611
|
async startPage(size, offset) {
|
1806
1612
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1807
1613
|
}
|
1614
|
+
/**
|
1615
|
+
* Retrieves the end page of results.
|
1616
|
+
* @param size Maximum number of results to be retrieved.
|
1617
|
+
* @param offset Number of results to skip when retrieving the results.
|
1618
|
+
* @returns The end page or results.
|
1619
|
+
*/
|
1808
1620
|
async endPage(size, offset) {
|
1809
1621
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1810
1622
|
}
|
1623
|
+
/**
|
1624
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
1625
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
1626
|
+
*/
|
1811
1627
|
hasNextPage() {
|
1812
1628
|
return this.meta.page.more;
|
1813
1629
|
}
|
1814
1630
|
}
|
1815
1631
|
_query = new WeakMap();
|
1816
|
-
const PAGINATION_MAX_SIZE =
|
1632
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
1817
1633
|
const PAGINATION_DEFAULT_SIZE = 20;
|
1818
|
-
const PAGINATION_MAX_OFFSET =
|
1634
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
1819
1635
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1820
1636
|
function isCursorPaginationOptions(options) {
|
1821
1637
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1822
1638
|
}
|
1823
|
-
const _RecordArray = class extends Array {
|
1639
|
+
const _RecordArray = class _RecordArray extends Array {
|
1824
1640
|
constructor(...args) {
|
1825
1641
|
super(..._RecordArray.parseConstructorParams(...args));
|
1826
1642
|
__privateAdd$6(this, _page, void 0);
|
@@ -1839,31 +1655,60 @@ const _RecordArray = class extends Array {
|
|
1839
1655
|
toArray() {
|
1840
1656
|
return new Array(...this);
|
1841
1657
|
}
|
1658
|
+
toSerializable() {
|
1659
|
+
return JSON.parse(this.toString());
|
1660
|
+
}
|
1661
|
+
toString() {
|
1662
|
+
return JSON.stringify(this.toArray());
|
1663
|
+
}
|
1842
1664
|
map(callbackfn, thisArg) {
|
1843
1665
|
return this.toArray().map(callbackfn, thisArg);
|
1844
1666
|
}
|
1667
|
+
/**
|
1668
|
+
* Retrieve next page of records
|
1669
|
+
*
|
1670
|
+
* @returns A new array of objects
|
1671
|
+
*/
|
1845
1672
|
async nextPage(size, offset) {
|
1846
1673
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1847
1674
|
return new _RecordArray(newPage);
|
1848
1675
|
}
|
1676
|
+
/**
|
1677
|
+
* Retrieve previous page of records
|
1678
|
+
*
|
1679
|
+
* @returns A new array of objects
|
1680
|
+
*/
|
1849
1681
|
async previousPage(size, offset) {
|
1850
1682
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1851
1683
|
return new _RecordArray(newPage);
|
1852
1684
|
}
|
1685
|
+
/**
|
1686
|
+
* Retrieve start page of records
|
1687
|
+
*
|
1688
|
+
* @returns A new array of objects
|
1689
|
+
*/
|
1853
1690
|
async startPage(size, offset) {
|
1854
1691
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1855
1692
|
return new _RecordArray(newPage);
|
1856
1693
|
}
|
1694
|
+
/**
|
1695
|
+
* Retrieve end page of records
|
1696
|
+
*
|
1697
|
+
* @returns A new array of objects
|
1698
|
+
*/
|
1857
1699
|
async endPage(size, offset) {
|
1858
1700
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1859
1701
|
return new _RecordArray(newPage);
|
1860
1702
|
}
|
1703
|
+
/**
|
1704
|
+
* @returns Boolean indicating if there is a next page
|
1705
|
+
*/
|
1861
1706
|
hasNextPage() {
|
1862
1707
|
return __privateGet$6(this, _page).meta.page.more;
|
1863
1708
|
}
|
1864
1709
|
};
|
1865
|
-
let RecordArray = _RecordArray;
|
1866
1710
|
_page = new WeakMap();
|
1711
|
+
let RecordArray = _RecordArray;
|
1867
1712
|
|
1868
1713
|
var __accessCheck$5 = (obj, member, msg) => {
|
1869
1714
|
if (!member.has(obj))
|
@@ -1888,13 +1733,14 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
1888
1733
|
return method;
|
1889
1734
|
};
|
1890
1735
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1891
|
-
const _Query = class {
|
1736
|
+
const _Query = class _Query {
|
1892
1737
|
constructor(repository, table, data, rawParent) {
|
1893
1738
|
__privateAdd$5(this, _cleanFilterConstraint);
|
1894
1739
|
__privateAdd$5(this, _table$1, void 0);
|
1895
1740
|
__privateAdd$5(this, _repository, void 0);
|
1896
1741
|
__privateAdd$5(this, _data, { filter: {} });
|
1897
|
-
|
1742
|
+
// Implements pagination
|
1743
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1898
1744
|
this.records = new RecordArray(this, []);
|
1899
1745
|
__privateSet$5(this, _table$1, table);
|
1900
1746
|
if (repository) {
|
@@ -1910,6 +1756,7 @@ const _Query = class {
|
|
1910
1756
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1911
1757
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1912
1758
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
1759
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1913
1760
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1914
1761
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
1915
1762
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -1930,18 +1777,38 @@ const _Query = class {
|
|
1930
1777
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1931
1778
|
return toBase64(key);
|
1932
1779
|
}
|
1780
|
+
/**
|
1781
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
1782
|
+
* @param queries An array of subqueries.
|
1783
|
+
* @returns A new Query object.
|
1784
|
+
*/
|
1933
1785
|
any(...queries) {
|
1934
1786
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1935
1787
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
1936
1788
|
}
|
1789
|
+
/**
|
1790
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
1791
|
+
* @param queries An array of subqueries.
|
1792
|
+
* @returns A new Query object.
|
1793
|
+
*/
|
1937
1794
|
all(...queries) {
|
1938
1795
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1939
1796
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1940
1797
|
}
|
1798
|
+
/**
|
1799
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
1800
|
+
* @param queries An array of subqueries.
|
1801
|
+
* @returns A new Query object.
|
1802
|
+
*/
|
1941
1803
|
not(...queries) {
|
1942
1804
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1943
1805
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
1944
1806
|
}
|
1807
|
+
/**
|
1808
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
1809
|
+
* @param queries An array of subqueries.
|
1810
|
+
* @returns A new Query object.
|
1811
|
+
*/
|
1945
1812
|
none(...queries) {
|
1946
1813
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1947
1814
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -1964,6 +1831,11 @@ const _Query = class {
|
|
1964
1831
|
const sort = [...originalSort, { column, direction }];
|
1965
1832
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1966
1833
|
}
|
1834
|
+
/**
|
1835
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
1836
|
+
* @param columns Array of column names to be returned by the query.
|
1837
|
+
* @returns A new Query object.
|
1838
|
+
*/
|
1967
1839
|
select(columns) {
|
1968
1840
|
return new _Query(
|
1969
1841
|
__privateGet$5(this, _repository),
|
@@ -1976,6 +1848,12 @@ const _Query = class {
|
|
1976
1848
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1977
1849
|
return __privateGet$5(this, _repository).query(query);
|
1978
1850
|
}
|
1851
|
+
/**
|
1852
|
+
* Get results in an iterator
|
1853
|
+
*
|
1854
|
+
* @async
|
1855
|
+
* @returns Async interable of results
|
1856
|
+
*/
|
1979
1857
|
async *[Symbol.asyncIterator]() {
|
1980
1858
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1981
1859
|
yield record;
|
@@ -2036,26 +1914,53 @@ const _Query = class {
|
|
2036
1914
|
);
|
2037
1915
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2038
1916
|
}
|
1917
|
+
/**
|
1918
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
1919
|
+
* @param ttl The cache TTL in milliseconds.
|
1920
|
+
* @returns A new Query object.
|
1921
|
+
*/
|
2039
1922
|
cache(ttl) {
|
2040
1923
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2041
1924
|
}
|
1925
|
+
/**
|
1926
|
+
* Retrieve next page of records
|
1927
|
+
*
|
1928
|
+
* @returns A new page object.
|
1929
|
+
*/
|
2042
1930
|
nextPage(size, offset) {
|
2043
1931
|
return this.startPage(size, offset);
|
2044
1932
|
}
|
1933
|
+
/**
|
1934
|
+
* Retrieve previous page of records
|
1935
|
+
*
|
1936
|
+
* @returns A new page object
|
1937
|
+
*/
|
2045
1938
|
previousPage(size, offset) {
|
2046
1939
|
return this.startPage(size, offset);
|
2047
1940
|
}
|
1941
|
+
/**
|
1942
|
+
* Retrieve start page of records
|
1943
|
+
*
|
1944
|
+
* @returns A new page object
|
1945
|
+
*/
|
2048
1946
|
startPage(size, offset) {
|
2049
1947
|
return this.getPaginated({ pagination: { size, offset } });
|
2050
1948
|
}
|
1949
|
+
/**
|
1950
|
+
* Retrieve last page of records
|
1951
|
+
*
|
1952
|
+
* @returns A new page object
|
1953
|
+
*/
|
2051
1954
|
endPage(size, offset) {
|
2052
1955
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2053
1956
|
}
|
1957
|
+
/**
|
1958
|
+
* @returns Boolean indicating if there is a next page
|
1959
|
+
*/
|
2054
1960
|
hasNextPage() {
|
2055
1961
|
return this.meta.page.more;
|
2056
1962
|
}
|
2057
1963
|
};
|
2058
|
-
let Query = _Query;
|
2059
1964
|
_table$1 = new WeakMap();
|
2060
1965
|
_repository = new WeakMap();
|
2061
1966
|
_data = new WeakMap();
|
@@ -2070,6 +1975,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2070
1975
|
}
|
2071
1976
|
return value;
|
2072
1977
|
};
|
1978
|
+
let Query = _Query;
|
2073
1979
|
function cleanParent(data, parent) {
|
2074
1980
|
if (isCursorPaginationOptions(data.pagination)) {
|
2075
1981
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2077,6 +1983,22 @@ function cleanParent(data, parent) {
|
|
2077
1983
|
return parent;
|
2078
1984
|
}
|
2079
1985
|
|
1986
|
+
const RecordColumnTypes = [
|
1987
|
+
"bool",
|
1988
|
+
"int",
|
1989
|
+
"float",
|
1990
|
+
"string",
|
1991
|
+
"text",
|
1992
|
+
"email",
|
1993
|
+
"multiple",
|
1994
|
+
"link",
|
1995
|
+
"object",
|
1996
|
+
"datetime",
|
1997
|
+
"vector",
|
1998
|
+
"file[]",
|
1999
|
+
"file",
|
2000
|
+
"json"
|
2001
|
+
];
|
2080
2002
|
function isIdentifiable(x) {
|
2081
2003
|
return isObject(x) && isString(x?.id);
|
2082
2004
|
}
|
@@ -2086,11 +2008,33 @@ function isXataRecord(x) {
|
|
2086
2008
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2087
2009
|
}
|
2088
2010
|
|
2011
|
+
function isValidExpandedColumn(column) {
|
2012
|
+
return isObject(column) && isString(column.name);
|
2013
|
+
}
|
2014
|
+
function isValidSelectableColumns(columns) {
|
2015
|
+
if (!Array.isArray(columns)) {
|
2016
|
+
return false;
|
2017
|
+
}
|
2018
|
+
return columns.every((column) => {
|
2019
|
+
if (typeof column === "string") {
|
2020
|
+
return true;
|
2021
|
+
}
|
2022
|
+
if (typeof column === "object") {
|
2023
|
+
return isValidExpandedColumn(column);
|
2024
|
+
}
|
2025
|
+
return false;
|
2026
|
+
});
|
2027
|
+
}
|
2028
|
+
|
2089
2029
|
function isSortFilterString(value) {
|
2090
2030
|
return isString(value);
|
2091
2031
|
}
|
2092
2032
|
function isSortFilterBase(filter) {
|
2093
|
-
return isObject(filter) && Object.
|
2033
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
2034
|
+
if (key === "*")
|
2035
|
+
return value === "random";
|
2036
|
+
return value === "asc" || value === "desc";
|
2037
|
+
});
|
2094
2038
|
}
|
2095
2039
|
function isSortFilterObject(filter) {
|
2096
2040
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2131,7 +2075,8 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2131
2075
|
__accessCheck$4(obj, member, "access private method");
|
2132
2076
|
return method;
|
2133
2077
|
};
|
2134
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2078
|
+
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;
|
2079
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2135
2080
|
class Repository extends Query {
|
2136
2081
|
}
|
2137
2082
|
class RestRepository extends Query {
|
@@ -2143,13 +2088,16 @@ class RestRepository extends Query {
|
|
2143
2088
|
);
|
2144
2089
|
__privateAdd$4(this, _insertRecordWithoutId);
|
2145
2090
|
__privateAdd$4(this, _insertRecordWithId);
|
2146
|
-
__privateAdd$4(this,
|
2091
|
+
__privateAdd$4(this, _insertRecords);
|
2147
2092
|
__privateAdd$4(this, _updateRecordWithID);
|
2093
|
+
__privateAdd$4(this, _updateRecords);
|
2148
2094
|
__privateAdd$4(this, _upsertRecordWithID);
|
2149
2095
|
__privateAdd$4(this, _deleteRecord);
|
2096
|
+
__privateAdd$4(this, _deleteRecords);
|
2150
2097
|
__privateAdd$4(this, _setCacheQuery);
|
2151
2098
|
__privateAdd$4(this, _getCacheQuery);
|
2152
2099
|
__privateAdd$4(this, _getSchemaTables$1);
|
2100
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2153
2101
|
__privateAdd$4(this, _table, void 0);
|
2154
2102
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2155
2103
|
__privateAdd$4(this, _db, void 0);
|
@@ -2160,10 +2108,7 @@ class RestRepository extends Query {
|
|
2160
2108
|
__privateSet$4(this, _db, options.db);
|
2161
2109
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2162
2110
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2163
|
-
__privateSet$4(this, _getFetchProps,
|
2164
|
-
const props = await options.pluginOptions.getFetchProps();
|
2165
|
-
return { ...props, sessionID: generateUUID() };
|
2166
|
-
});
|
2111
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2167
2112
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2168
2113
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2169
2114
|
return trace(name, fn, {
|
@@ -2180,23 +2125,25 @@ class RestRepository extends Query {
|
|
2180
2125
|
if (Array.isArray(a)) {
|
2181
2126
|
if (a.length === 0)
|
2182
2127
|
return [];
|
2183
|
-
const
|
2184
|
-
|
2128
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2129
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2130
|
+
const result = await this.read(ids, columns);
|
2131
|
+
return result;
|
2185
2132
|
}
|
2186
2133
|
if (isString(a) && isObject(b)) {
|
2187
2134
|
if (a === "")
|
2188
2135
|
throw new Error("The id can't be empty");
|
2189
|
-
const columns =
|
2190
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2136
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2137
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2191
2138
|
}
|
2192
2139
|
if (isObject(a) && isString(a.id)) {
|
2193
2140
|
if (a.id === "")
|
2194
2141
|
throw new Error("The id can't be empty");
|
2195
|
-
const columns =
|
2196
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2142
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2143
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2197
2144
|
}
|
2198
2145
|
if (isObject(a)) {
|
2199
|
-
const columns =
|
2146
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2200
2147
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2201
2148
|
}
|
2202
2149
|
throw new Error("Invalid arguments for create method");
|
@@ -2204,7 +2151,7 @@ class RestRepository extends Query {
|
|
2204
2151
|
}
|
2205
2152
|
async read(a, b) {
|
2206
2153
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2207
|
-
const columns =
|
2154
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2208
2155
|
if (Array.isArray(a)) {
|
2209
2156
|
if (a.length === 0)
|
2210
2157
|
return [];
|
@@ -2218,7 +2165,6 @@ class RestRepository extends Query {
|
|
2218
2165
|
}
|
2219
2166
|
const id = extractId(a);
|
2220
2167
|
if (id) {
|
2221
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2222
2168
|
try {
|
2223
2169
|
const response = await getRecord({
|
2224
2170
|
pathParams: {
|
@@ -2229,10 +2175,16 @@ class RestRepository extends Query {
|
|
2229
2175
|
recordId: id
|
2230
2176
|
},
|
2231
2177
|
queryParams: { columns },
|
2232
|
-
...
|
2178
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2233
2179
|
});
|
2234
2180
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2235
|
-
return initObject(
|
2181
|
+
return initObject(
|
2182
|
+
__privateGet$4(this, _db),
|
2183
|
+
schemaTables,
|
2184
|
+
__privateGet$4(this, _table),
|
2185
|
+
response,
|
2186
|
+
columns
|
2187
|
+
);
|
2236
2188
|
} catch (e) {
|
2237
2189
|
if (isObject(e) && e.status === 404) {
|
2238
2190
|
return null;
|
@@ -2268,19 +2220,29 @@ class RestRepository extends Query {
|
|
2268
2220
|
if (Array.isArray(a)) {
|
2269
2221
|
if (a.length === 0)
|
2270
2222
|
return [];
|
2271
|
-
|
2272
|
-
|
2273
|
-
|
2274
|
-
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
const
|
2279
|
-
return
|
2223
|
+
const existing = await this.read(a, ["id"]);
|
2224
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
2225
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2226
|
+
ifVersion,
|
2227
|
+
upsert: false
|
2228
|
+
});
|
2229
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2230
|
+
const result = await this.read(a, columns);
|
2231
|
+
return result;
|
2280
2232
|
}
|
2281
|
-
|
2282
|
-
|
2283
|
-
|
2233
|
+
try {
|
2234
|
+
if (isString(a) && isObject(b)) {
|
2235
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2236
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2237
|
+
}
|
2238
|
+
if (isObject(a) && isString(a.id)) {
|
2239
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2240
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2241
|
+
}
|
2242
|
+
} catch (error) {
|
2243
|
+
if (error.status === 422)
|
2244
|
+
return null;
|
2245
|
+
throw error;
|
2284
2246
|
}
|
2285
2247
|
throw new Error("Invalid arguments for update method");
|
2286
2248
|
});
|
@@ -2310,19 +2272,31 @@ class RestRepository extends Query {
|
|
2310
2272
|
if (Array.isArray(a)) {
|
2311
2273
|
if (a.length === 0)
|
2312
2274
|
return [];
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
|
2275
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
2276
|
+
ifVersion,
|
2277
|
+
upsert: true
|
2278
|
+
});
|
2279
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2280
|
+
const result = await this.read(a, columns);
|
2281
|
+
return result;
|
2318
2282
|
}
|
2319
2283
|
if (isString(a) && isObject(b)) {
|
2320
|
-
|
2321
|
-
|
2284
|
+
if (a === "")
|
2285
|
+
throw new Error("The id can't be empty");
|
2286
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2287
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2322
2288
|
}
|
2323
2289
|
if (isObject(a) && isString(a.id)) {
|
2324
|
-
|
2325
|
-
|
2290
|
+
if (a.id === "")
|
2291
|
+
throw new Error("The id can't be empty");
|
2292
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2293
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2294
|
+
}
|
2295
|
+
if (!isDefined(a) && isObject(b)) {
|
2296
|
+
return await this.create(b, c);
|
2297
|
+
}
|
2298
|
+
if (isObject(a) && !isDefined(a.id)) {
|
2299
|
+
return await this.create(a, b);
|
2326
2300
|
}
|
2327
2301
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2328
2302
|
});
|
@@ -2333,16 +2307,28 @@ class RestRepository extends Query {
|
|
2333
2307
|
if (Array.isArray(a)) {
|
2334
2308
|
if (a.length === 0)
|
2335
2309
|
return [];
|
2336
|
-
const
|
2337
|
-
|
2310
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2311
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2312
|
+
const result = await this.read(ids, columns);
|
2313
|
+
return result;
|
2338
2314
|
}
|
2339
2315
|
if (isString(a) && isObject(b)) {
|
2340
|
-
|
2341
|
-
|
2316
|
+
if (a === "")
|
2317
|
+
throw new Error("The id can't be empty");
|
2318
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2319
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2342
2320
|
}
|
2343
2321
|
if (isObject(a) && isString(a.id)) {
|
2344
|
-
|
2345
|
-
|
2322
|
+
if (a.id === "")
|
2323
|
+
throw new Error("The id can't be empty");
|
2324
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2325
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
2326
|
+
}
|
2327
|
+
if (!isDefined(a) && isObject(b)) {
|
2328
|
+
return await this.create(b, c);
|
2329
|
+
}
|
2330
|
+
if (isObject(a) && !isDefined(a.id)) {
|
2331
|
+
return await this.create(a, b);
|
2346
2332
|
}
|
2347
2333
|
throw new Error("Invalid arguments for createOrReplace method");
|
2348
2334
|
});
|
@@ -2352,10 +2338,17 @@ class RestRepository extends Query {
|
|
2352
2338
|
if (Array.isArray(a)) {
|
2353
2339
|
if (a.length === 0)
|
2354
2340
|
return [];
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
2341
|
+
const ids = a.map((o) => {
|
2342
|
+
if (isString(o))
|
2343
|
+
return o;
|
2344
|
+
if (isString(o.id))
|
2345
|
+
return o.id;
|
2346
|
+
throw new Error("Invalid arguments for delete method");
|
2347
|
+
});
|
2348
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2349
|
+
const result = await this.read(a, columns);
|
2350
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2351
|
+
return result;
|
2359
2352
|
}
|
2360
2353
|
if (isString(a)) {
|
2361
2354
|
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
@@ -2386,8 +2379,7 @@ class RestRepository extends Query {
|
|
2386
2379
|
}
|
2387
2380
|
async search(query, options = {}) {
|
2388
2381
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2389
|
-
const
|
2390
|
-
const { records } = await searchTable({
|
2382
|
+
const { records, totalCount } = await searchTable({
|
2391
2383
|
pathParams: {
|
2392
2384
|
workspace: "{workspaceId}",
|
2393
2385
|
dbBranchName: "{dbBranch}",
|
@@ -2400,17 +2392,46 @@ class RestRepository extends Query {
|
|
2400
2392
|
prefix: options.prefix,
|
2401
2393
|
highlight: options.highlight,
|
2402
2394
|
filter: options.filter,
|
2403
|
-
boosters: options.boosters
|
2395
|
+
boosters: options.boosters,
|
2396
|
+
page: options.page,
|
2397
|
+
target: options.target
|
2398
|
+
},
|
2399
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2400
|
+
});
|
2401
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2402
|
+
return {
|
2403
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
2404
|
+
totalCount
|
2405
|
+
};
|
2406
|
+
});
|
2407
|
+
}
|
2408
|
+
async vectorSearch(column, query, options) {
|
2409
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
2410
|
+
const { records, totalCount } = await vectorSearchTable({
|
2411
|
+
pathParams: {
|
2412
|
+
workspace: "{workspaceId}",
|
2413
|
+
dbBranchName: "{dbBranch}",
|
2414
|
+
region: "{region}",
|
2415
|
+
tableName: __privateGet$4(this, _table)
|
2416
|
+
},
|
2417
|
+
body: {
|
2418
|
+
column,
|
2419
|
+
queryVector: query,
|
2420
|
+
similarityFunction: options?.similarityFunction,
|
2421
|
+
size: options?.size,
|
2422
|
+
filter: options?.filter
|
2404
2423
|
},
|
2405
|
-
...
|
2424
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2406
2425
|
});
|
2407
2426
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2408
|
-
return
|
2427
|
+
return {
|
2428
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
2429
|
+
totalCount
|
2430
|
+
};
|
2409
2431
|
});
|
2410
2432
|
}
|
2411
2433
|
async aggregate(aggs, filter) {
|
2412
2434
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2413
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2414
2435
|
const result = await aggregateTable({
|
2415
2436
|
pathParams: {
|
2416
2437
|
workspace: "{workspaceId}",
|
@@ -2419,7 +2440,7 @@ class RestRepository extends Query {
|
|
2419
2440
|
tableName: __privateGet$4(this, _table)
|
2420
2441
|
},
|
2421
2442
|
body: { aggs, filter },
|
2422
|
-
...
|
2443
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2423
2444
|
});
|
2424
2445
|
return result;
|
2425
2446
|
});
|
@@ -2430,7 +2451,6 @@ class RestRepository extends Query {
|
|
2430
2451
|
if (cacheQuery)
|
2431
2452
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2432
2453
|
const data = query.getQueryOptions();
|
2433
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2434
2454
|
const { meta, records: objects } = await queryTable({
|
2435
2455
|
pathParams: {
|
2436
2456
|
workspace: "{workspaceId}",
|
@@ -2442,14 +2462,21 @@ class RestRepository extends Query {
|
|
2442
2462
|
filter: cleanFilter(data.filter),
|
2443
2463
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2444
2464
|
page: data.pagination,
|
2445
|
-
columns: data.columns ?? ["*"]
|
2465
|
+
columns: data.columns ?? ["*"],
|
2466
|
+
consistency: data.consistency
|
2446
2467
|
},
|
2447
2468
|
fetchOptions: data.fetchOptions,
|
2448
|
-
...
|
2469
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2449
2470
|
});
|
2450
2471
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2451
2472
|
const records = objects.map(
|
2452
|
-
(record) => initObject(
|
2473
|
+
(record) => initObject(
|
2474
|
+
__privateGet$4(this, _db),
|
2475
|
+
schemaTables,
|
2476
|
+
__privateGet$4(this, _table),
|
2477
|
+
record,
|
2478
|
+
data.columns ?? ["*"]
|
2479
|
+
)
|
2453
2480
|
);
|
2454
2481
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2455
2482
|
return new Page(query, meta, records);
|
@@ -2458,7 +2485,6 @@ class RestRepository extends Query {
|
|
2458
2485
|
async summarizeTable(query, summaries, summariesFilter) {
|
2459
2486
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2460
2487
|
const data = query.getQueryOptions();
|
2461
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2462
2488
|
const result = await summarizeTable({
|
2463
2489
|
pathParams: {
|
2464
2490
|
workspace: "{workspaceId}",
|
@@ -2470,15 +2496,55 @@ class RestRepository extends Query {
|
|
2470
2496
|
filter: cleanFilter(data.filter),
|
2471
2497
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2472
2498
|
columns: data.columns,
|
2499
|
+
consistency: data.consistency,
|
2473
2500
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2474
2501
|
summaries,
|
2475
2502
|
summariesFilter
|
2476
2503
|
},
|
2477
|
-
...
|
2504
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2478
2505
|
});
|
2479
|
-
|
2506
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2507
|
+
return {
|
2508
|
+
...result,
|
2509
|
+
summaries: result.summaries.map(
|
2510
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
2511
|
+
)
|
2512
|
+
};
|
2480
2513
|
});
|
2481
2514
|
}
|
2515
|
+
ask(question, options) {
|
2516
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
2517
|
+
const params = {
|
2518
|
+
pathParams: {
|
2519
|
+
workspace: "{workspaceId}",
|
2520
|
+
dbBranchName: "{dbBranch}",
|
2521
|
+
region: "{region}",
|
2522
|
+
tableName: __privateGet$4(this, _table),
|
2523
|
+
sessionId: options?.sessionId
|
2524
|
+
},
|
2525
|
+
body: {
|
2526
|
+
...questionParam,
|
2527
|
+
rules: options?.rules,
|
2528
|
+
searchType: options?.searchType,
|
2529
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
2530
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
2531
|
+
},
|
2532
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2533
|
+
};
|
2534
|
+
if (options?.onMessage) {
|
2535
|
+
fetchSSERequest({
|
2536
|
+
endpoint: "dataPlane",
|
2537
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
2538
|
+
method: "POST",
|
2539
|
+
onMessage: (message) => {
|
2540
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
2541
|
+
},
|
2542
|
+
...params
|
2543
|
+
});
|
2544
|
+
} else {
|
2545
|
+
return askTableSession(params);
|
2546
|
+
}
|
2547
|
+
}
|
2482
2548
|
}
|
2483
2549
|
_table = new WeakMap();
|
2484
2550
|
_getFetchProps = new WeakMap();
|
@@ -2488,8 +2554,7 @@ _schemaTables$2 = new WeakMap();
|
|
2488
2554
|
_trace = new WeakMap();
|
2489
2555
|
_insertRecordWithoutId = new WeakSet();
|
2490
2556
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2491
|
-
const
|
2492
|
-
const record = transformObjectLinks(object);
|
2557
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2493
2558
|
const response = await insertRecord({
|
2494
2559
|
pathParams: {
|
2495
2560
|
workspace: "{workspaceId}",
|
@@ -2499,15 +2564,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2499
2564
|
},
|
2500
2565
|
queryParams: { columns },
|
2501
2566
|
body: record,
|
2502
|
-
...
|
2567
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2503
2568
|
});
|
2504
2569
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2505
2570
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2506
2571
|
};
|
2507
2572
|
_insertRecordWithId = new WeakSet();
|
2508
2573
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2509
|
-
|
2510
|
-
|
2574
|
+
if (!recordId)
|
2575
|
+
return null;
|
2576
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2511
2577
|
const response = await insertRecordWithID({
|
2512
2578
|
pathParams: {
|
2513
2579
|
workspace: "{workspaceId}",
|
@@ -2518,36 +2584,44 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2518
2584
|
},
|
2519
2585
|
body: record,
|
2520
2586
|
queryParams: { createOnly, columns, ifVersion },
|
2521
|
-
...
|
2587
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2522
2588
|
});
|
2523
2589
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2524
2590
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2525
2591
|
};
|
2526
|
-
|
2527
|
-
|
2528
|
-
const
|
2529
|
-
|
2530
|
-
|
2531
|
-
pathParams: {
|
2532
|
-
workspace: "{workspaceId}",
|
2533
|
-
dbBranchName: "{dbBranch}",
|
2534
|
-
region: "{region}",
|
2535
|
-
tableName: __privateGet$4(this, _table)
|
2536
|
-
},
|
2537
|
-
queryParams: { columns },
|
2538
|
-
body: { records },
|
2539
|
-
...fetchProps
|
2592
|
+
_insertRecords = new WeakSet();
|
2593
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2594
|
+
const operations = await promiseMap(objects, async (object) => {
|
2595
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2596
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
2540
2597
|
});
|
2541
|
-
|
2542
|
-
|
2598
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2599
|
+
const ids = [];
|
2600
|
+
for (const operations2 of chunkedOperations) {
|
2601
|
+
const { results } = await branchTransaction({
|
2602
|
+
pathParams: {
|
2603
|
+
workspace: "{workspaceId}",
|
2604
|
+
dbBranchName: "{dbBranch}",
|
2605
|
+
region: "{region}"
|
2606
|
+
},
|
2607
|
+
body: { operations: operations2 },
|
2608
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2609
|
+
});
|
2610
|
+
for (const result of results) {
|
2611
|
+
if (result.operation === "insert") {
|
2612
|
+
ids.push(result.id);
|
2613
|
+
} else {
|
2614
|
+
ids.push(null);
|
2615
|
+
}
|
2616
|
+
}
|
2543
2617
|
}
|
2544
|
-
|
2545
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
2618
|
+
return ids;
|
2546
2619
|
};
|
2547
2620
|
_updateRecordWithID = new WeakSet();
|
2548
2621
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2549
|
-
|
2550
|
-
|
2622
|
+
if (!recordId)
|
2623
|
+
return null;
|
2624
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2551
2625
|
try {
|
2552
2626
|
const response = await updateRecordWithID({
|
2553
2627
|
pathParams: {
|
@@ -2559,7 +2633,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2559
2633
|
},
|
2560
2634
|
queryParams: { columns, ifVersion },
|
2561
2635
|
body: record,
|
2562
|
-
...
|
2636
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2563
2637
|
});
|
2564
2638
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2565
2639
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2570,9 +2644,38 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2570
2644
|
throw e;
|
2571
2645
|
}
|
2572
2646
|
};
|
2647
|
+
_updateRecords = new WeakSet();
|
2648
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2649
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
2650
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2651
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
2652
|
+
});
|
2653
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2654
|
+
const ids = [];
|
2655
|
+
for (const operations2 of chunkedOperations) {
|
2656
|
+
const { results } = await branchTransaction({
|
2657
|
+
pathParams: {
|
2658
|
+
workspace: "{workspaceId}",
|
2659
|
+
dbBranchName: "{dbBranch}",
|
2660
|
+
region: "{region}"
|
2661
|
+
},
|
2662
|
+
body: { operations: operations2 },
|
2663
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2664
|
+
});
|
2665
|
+
for (const result of results) {
|
2666
|
+
if (result.operation === "update") {
|
2667
|
+
ids.push(result.id);
|
2668
|
+
} else {
|
2669
|
+
ids.push(null);
|
2670
|
+
}
|
2671
|
+
}
|
2672
|
+
}
|
2673
|
+
return ids;
|
2674
|
+
};
|
2573
2675
|
_upsertRecordWithID = new WeakSet();
|
2574
2676
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2575
|
-
|
2677
|
+
if (!recordId)
|
2678
|
+
return null;
|
2576
2679
|
const response = await upsertRecordWithID({
|
2577
2680
|
pathParams: {
|
2578
2681
|
workspace: "{workspaceId}",
|
@@ -2583,14 +2686,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2583
2686
|
},
|
2584
2687
|
queryParams: { columns, ifVersion },
|
2585
2688
|
body: object,
|
2586
|
-
...
|
2689
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2587
2690
|
});
|
2588
2691
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2589
2692
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2590
2693
|
};
|
2591
2694
|
_deleteRecord = new WeakSet();
|
2592
2695
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2593
|
-
|
2696
|
+
if (!recordId)
|
2697
|
+
return null;
|
2594
2698
|
try {
|
2595
2699
|
const response = await deleteRecord({
|
2596
2700
|
pathParams: {
|
@@ -2601,7 +2705,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2601
2705
|
recordId
|
2602
2706
|
},
|
2603
2707
|
queryParams: { columns },
|
2604
|
-
...
|
2708
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2605
2709
|
});
|
2606
2710
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2607
2711
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2612,17 +2716,36 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2612
2716
|
throw e;
|
2613
2717
|
}
|
2614
2718
|
};
|
2719
|
+
_deleteRecords = new WeakSet();
|
2720
|
+
deleteRecords_fn = async function(recordIds) {
|
2721
|
+
const chunkedOperations = chunk(
|
2722
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2723
|
+
BULK_OPERATION_MAX_SIZE
|
2724
|
+
);
|
2725
|
+
for (const operations of chunkedOperations) {
|
2726
|
+
await branchTransaction({
|
2727
|
+
pathParams: {
|
2728
|
+
workspace: "{workspaceId}",
|
2729
|
+
dbBranchName: "{dbBranch}",
|
2730
|
+
region: "{region}"
|
2731
|
+
},
|
2732
|
+
body: { operations },
|
2733
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2734
|
+
});
|
2735
|
+
}
|
2736
|
+
};
|
2615
2737
|
_setCacheQuery = new WeakSet();
|
2616
2738
|
setCacheQuery_fn = async function(query, meta, records) {
|
2617
|
-
await __privateGet$4(this, _cache)
|
2739
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2618
2740
|
};
|
2619
2741
|
_getCacheQuery = new WeakSet();
|
2620
2742
|
getCacheQuery_fn = async function(query) {
|
2621
2743
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2622
|
-
const result = await __privateGet$4(this, _cache)
|
2744
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2623
2745
|
if (!result)
|
2624
2746
|
return null;
|
2625
|
-
const
|
2747
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
2748
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2626
2749
|
if (ttl < 0)
|
2627
2750
|
return null;
|
2628
2751
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2632,39 +2755,66 @@ _getSchemaTables$1 = new WeakSet();
|
|
2632
2755
|
getSchemaTables_fn$1 = async function() {
|
2633
2756
|
if (__privateGet$4(this, _schemaTables$2))
|
2634
2757
|
return __privateGet$4(this, _schemaTables$2);
|
2635
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2636
2758
|
const { schema } = await getBranchDetails({
|
2637
2759
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2638
|
-
...
|
2760
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2639
2761
|
});
|
2640
2762
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2641
2763
|
return schema.tables;
|
2642
2764
|
};
|
2643
|
-
|
2644
|
-
|
2765
|
+
_transformObjectToApi = new WeakSet();
|
2766
|
+
transformObjectToApi_fn = async function(object) {
|
2767
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2768
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
2769
|
+
if (!schema)
|
2770
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
2771
|
+
const result = {};
|
2772
|
+
for (const [key, value] of Object.entries(object)) {
|
2645
2773
|
if (key === "xata")
|
2646
|
-
|
2647
|
-
|
2648
|
-
|
2774
|
+
continue;
|
2775
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
2776
|
+
switch (type) {
|
2777
|
+
case "link": {
|
2778
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
2779
|
+
break;
|
2780
|
+
}
|
2781
|
+
case "datetime": {
|
2782
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
2783
|
+
break;
|
2784
|
+
}
|
2785
|
+
case `file`:
|
2786
|
+
result[key] = await parseInputFileEntry(value);
|
2787
|
+
break;
|
2788
|
+
case "file[]":
|
2789
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
2790
|
+
break;
|
2791
|
+
case "json":
|
2792
|
+
result[key] = stringifyJson(value);
|
2793
|
+
break;
|
2794
|
+
default:
|
2795
|
+
result[key] = value;
|
2796
|
+
}
|
2797
|
+
}
|
2798
|
+
return result;
|
2649
2799
|
};
|
2650
2800
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2651
|
-
const
|
2801
|
+
const data = {};
|
2652
2802
|
const { xata, ...rest } = object ?? {};
|
2653
|
-
Object.assign(
|
2803
|
+
Object.assign(data, rest);
|
2654
2804
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2655
2805
|
if (!columns)
|
2656
2806
|
console.error(`Table ${table} not found in schema`);
|
2657
2807
|
for (const column of columns ?? []) {
|
2658
2808
|
if (!isValidColumn(selectedColumns, column))
|
2659
2809
|
continue;
|
2660
|
-
const value =
|
2810
|
+
const value = data[column.name];
|
2661
2811
|
switch (column.type) {
|
2662
2812
|
case "datetime": {
|
2663
|
-
const date = value !== void 0 ? new Date(value) :
|
2664
|
-
if (date && isNaN(date.getTime())) {
|
2813
|
+
const date = value !== void 0 ? new Date(value) : null;
|
2814
|
+
if (date !== null && isNaN(date.getTime())) {
|
2665
2815
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2666
|
-
} else
|
2667
|
-
|
2816
|
+
} else {
|
2817
|
+
data[column.name] = date;
|
2668
2818
|
}
|
2669
2819
|
break;
|
2670
2820
|
}
|
@@ -2677,54 +2827,77 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2677
2827
|
if (item === column.name) {
|
2678
2828
|
return [...acc, "*"];
|
2679
2829
|
}
|
2680
|
-
if (item.startsWith(`${column.name}.`)) {
|
2830
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2681
2831
|
const [, ...path] = item.split(".");
|
2682
2832
|
return [...acc, path.join(".")];
|
2683
2833
|
}
|
2684
2834
|
return acc;
|
2685
2835
|
}, []);
|
2686
|
-
|
2836
|
+
data[column.name] = initObject(
|
2837
|
+
db,
|
2838
|
+
schemaTables,
|
2839
|
+
linkTable,
|
2840
|
+
value,
|
2841
|
+
selectedLinkColumns
|
2842
|
+
);
|
2687
2843
|
} else {
|
2688
|
-
|
2844
|
+
data[column.name] = null;
|
2689
2845
|
}
|
2690
2846
|
break;
|
2691
2847
|
}
|
2848
|
+
case "file":
|
2849
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
2850
|
+
break;
|
2851
|
+
case "file[]":
|
2852
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
2853
|
+
break;
|
2854
|
+
case "json":
|
2855
|
+
data[column.name] = parseJson(value);
|
2856
|
+
break;
|
2692
2857
|
default:
|
2693
|
-
|
2858
|
+
data[column.name] = value ?? null;
|
2694
2859
|
if (column.notNull === true && value === null) {
|
2695
2860
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2696
2861
|
}
|
2697
2862
|
break;
|
2698
2863
|
}
|
2699
2864
|
}
|
2700
|
-
|
2701
|
-
|
2865
|
+
const record = { ...data };
|
2866
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2867
|
+
record.read = function(columns2) {
|
2868
|
+
return db[table].read(record["id"], columns2);
|
2702
2869
|
};
|
2703
|
-
|
2704
|
-
const columns2 =
|
2870
|
+
record.update = function(data2, b, c) {
|
2871
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2705
2872
|
const ifVersion = parseIfVersion(b, c);
|
2706
|
-
return db[table].update(
|
2873
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2707
2874
|
};
|
2708
|
-
|
2709
|
-
const columns2 =
|
2875
|
+
record.replace = function(data2, b, c) {
|
2876
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2710
2877
|
const ifVersion = parseIfVersion(b, c);
|
2711
|
-
return db[table].createOrReplace(
|
2878
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
2879
|
+
};
|
2880
|
+
record.delete = function() {
|
2881
|
+
return db[table].delete(record["id"]);
|
2882
|
+
};
|
2883
|
+
if (metadata !== void 0) {
|
2884
|
+
record.xata = Object.freeze(metadata);
|
2885
|
+
}
|
2886
|
+
record.getMetadata = function() {
|
2887
|
+
return record.xata;
|
2712
2888
|
};
|
2713
|
-
|
2714
|
-
return
|
2889
|
+
record.toSerializable = function() {
|
2890
|
+
return JSON.parse(JSON.stringify(record));
|
2715
2891
|
};
|
2716
|
-
|
2717
|
-
return
|
2892
|
+
record.toString = function() {
|
2893
|
+
return JSON.stringify(record);
|
2718
2894
|
};
|
2719
|
-
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
2720
|
-
Object.defineProperty(
|
2895
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2896
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2721
2897
|
}
|
2722
|
-
Object.freeze(
|
2723
|
-
return
|
2898
|
+
Object.freeze(record);
|
2899
|
+
return record;
|
2724
2900
|
};
|
2725
|
-
function isResponseWithRecords(value) {
|
2726
|
-
return isObject(value) && Array.isArray(value.records);
|
2727
|
-
}
|
2728
2901
|
function extractId(value) {
|
2729
2902
|
if (isString(value))
|
2730
2903
|
return value;
|
@@ -2735,11 +2908,7 @@ function extractId(value) {
|
|
2735
2908
|
function isValidColumn(columns, column) {
|
2736
2909
|
if (columns.includes("*"))
|
2737
2910
|
return true;
|
2738
|
-
|
2739
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2740
|
-
return linkColumns.length > 0;
|
2741
|
-
}
|
2742
|
-
return columns.includes(column.name);
|
2911
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
2743
2912
|
}
|
2744
2913
|
function parseIfVersion(...args) {
|
2745
2914
|
for (const arg of args) {
|
@@ -2816,10 +2985,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
2816
2985
|
const startsWith = (value) => ({ $startsWith: value });
|
2817
2986
|
const endsWith = (value) => ({ $endsWith: value });
|
2818
2987
|
const pattern = (value) => ({ $pattern: value });
|
2988
|
+
const iPattern = (value) => ({ $iPattern: value });
|
2819
2989
|
const is = (value) => ({ $is: value });
|
2820
2990
|
const equals = is;
|
2821
2991
|
const isNot = (value) => ({ $isNot: value });
|
2822
2992
|
const contains = (value) => ({ $contains: value });
|
2993
|
+
const iContains = (value) => ({ $iContains: value });
|
2823
2994
|
const includes = (value) => ({ $includes: value });
|
2824
2995
|
const includesAll = (value) => ({ $includesAll: value });
|
2825
2996
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -2875,6 +3046,80 @@ class SchemaPlugin extends XataPlugin {
|
|
2875
3046
|
_tables = new WeakMap();
|
2876
3047
|
_schemaTables$1 = new WeakMap();
|
2877
3048
|
|
3049
|
+
class FilesPlugin extends XataPlugin {
|
3050
|
+
build(pluginOptions) {
|
3051
|
+
return {
|
3052
|
+
download: async (location) => {
|
3053
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3054
|
+
return await getFileItem({
|
3055
|
+
pathParams: {
|
3056
|
+
workspace: "{workspaceId}",
|
3057
|
+
dbBranchName: "{dbBranch}",
|
3058
|
+
region: "{region}",
|
3059
|
+
tableName: table ?? "",
|
3060
|
+
recordId: record ?? "",
|
3061
|
+
columnName: column ?? "",
|
3062
|
+
fileId
|
3063
|
+
},
|
3064
|
+
...pluginOptions,
|
3065
|
+
rawResponse: true
|
3066
|
+
});
|
3067
|
+
},
|
3068
|
+
upload: async (location, file, options) => {
|
3069
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3070
|
+
const resolvedFile = await file;
|
3071
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
3072
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
3073
|
+
return await putFileItem({
|
3074
|
+
...pluginOptions,
|
3075
|
+
pathParams: {
|
3076
|
+
workspace: "{workspaceId}",
|
3077
|
+
dbBranchName: "{dbBranch}",
|
3078
|
+
region: "{region}",
|
3079
|
+
tableName: table ?? "",
|
3080
|
+
recordId: record ?? "",
|
3081
|
+
columnName: column ?? "",
|
3082
|
+
fileId
|
3083
|
+
},
|
3084
|
+
body,
|
3085
|
+
headers: { "Content-Type": contentType }
|
3086
|
+
});
|
3087
|
+
},
|
3088
|
+
delete: async (location) => {
|
3089
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3090
|
+
return await deleteFileItem({
|
3091
|
+
pathParams: {
|
3092
|
+
workspace: "{workspaceId}",
|
3093
|
+
dbBranchName: "{dbBranch}",
|
3094
|
+
region: "{region}",
|
3095
|
+
tableName: table ?? "",
|
3096
|
+
recordId: record ?? "",
|
3097
|
+
columnName: column ?? "",
|
3098
|
+
fileId
|
3099
|
+
},
|
3100
|
+
...pluginOptions
|
3101
|
+
});
|
3102
|
+
}
|
3103
|
+
};
|
3104
|
+
}
|
3105
|
+
}
|
3106
|
+
function getContentType(file) {
|
3107
|
+
if (typeof file === "string") {
|
3108
|
+
return "text/plain";
|
3109
|
+
}
|
3110
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
3111
|
+
return file.mediaType;
|
3112
|
+
}
|
3113
|
+
if (isBlob(file)) {
|
3114
|
+
return file.type;
|
3115
|
+
}
|
3116
|
+
try {
|
3117
|
+
return file.type;
|
3118
|
+
} catch (e) {
|
3119
|
+
}
|
3120
|
+
return "application/octet-stream";
|
3121
|
+
}
|
3122
|
+
|
2878
3123
|
var __accessCheck$1 = (obj, member, msg) => {
|
2879
3124
|
if (!member.has(obj))
|
2880
3125
|
throw TypeError("Cannot " + msg);
|
@@ -2907,138 +3152,141 @@ class SearchPlugin extends XataPlugin {
|
|
2907
3152
|
__privateAdd$1(this, _schemaTables, void 0);
|
2908
3153
|
__privateSet$1(this, _schemaTables, schemaTables);
|
2909
3154
|
}
|
2910
|
-
build(
|
3155
|
+
build(pluginOptions) {
|
2911
3156
|
return {
|
2912
3157
|
all: async (query, options = {}) => {
|
2913
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
2914
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
2915
|
-
return
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
3158
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3159
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3160
|
+
return {
|
3161
|
+
totalCount,
|
3162
|
+
records: records.map((record) => {
|
3163
|
+
const { table = "orphan" } = record.xata;
|
3164
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3165
|
+
})
|
3166
|
+
};
|
2919
3167
|
},
|
2920
3168
|
byTable: async (query, options = {}) => {
|
2921
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
2922
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
2923
|
-
|
3169
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3170
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3171
|
+
const records = rawRecords.reduce((acc, record) => {
|
2924
3172
|
const { table = "orphan" } = record.xata;
|
2925
3173
|
const items = acc[table] ?? [];
|
2926
3174
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
2927
3175
|
return { ...acc, [table]: [...items, item] };
|
2928
3176
|
}, {});
|
3177
|
+
return { totalCount, records };
|
2929
3178
|
}
|
2930
3179
|
};
|
2931
3180
|
}
|
2932
3181
|
}
|
2933
3182
|
_schemaTables = new WeakMap();
|
2934
3183
|
_search = new WeakSet();
|
2935
|
-
search_fn = async function(query, options,
|
2936
|
-
const
|
2937
|
-
const {
|
2938
|
-
const { records } = await searchBranch({
|
3184
|
+
search_fn = async function(query, options, pluginOptions) {
|
3185
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3186
|
+
const { records, totalCount } = await searchBranch({
|
2939
3187
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2940
|
-
|
2941
|
-
|
3188
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3189
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
3190
|
+
...pluginOptions
|
2942
3191
|
});
|
2943
|
-
return records;
|
3192
|
+
return { records, totalCount };
|
2944
3193
|
};
|
2945
3194
|
_getSchemaTables = new WeakSet();
|
2946
|
-
getSchemaTables_fn = async function(
|
3195
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
2947
3196
|
if (__privateGet$1(this, _schemaTables))
|
2948
3197
|
return __privateGet$1(this, _schemaTables);
|
2949
|
-
const fetchProps = await getFetchProps();
|
2950
3198
|
const { schema } = await getBranchDetails({
|
2951
3199
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2952
|
-
...
|
3200
|
+
...pluginOptions
|
2953
3201
|
});
|
2954
3202
|
__privateSet$1(this, _schemaTables, schema.tables);
|
2955
3203
|
return schema.tables;
|
2956
3204
|
};
|
2957
3205
|
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2967
|
-
|
2968
|
-
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
2972
|
-
}
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
}
|
2977
|
-
async function resolveXataBranch(gitBranch, options) {
|
2978
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2979
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2980
|
-
if (!databaseURL)
|
2981
|
-
throw new Error(
|
2982
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2983
|
-
);
|
2984
|
-
if (!apiKey)
|
2985
|
-
throw new Error(
|
2986
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2987
|
-
);
|
2988
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
2989
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
2990
|
-
if (!urlParts)
|
2991
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
2992
|
-
const { workspace, region } = urlParts;
|
2993
|
-
const { fallbackBranch } = getEnvironment();
|
2994
|
-
const { branch } = await resolveBranch({
|
2995
|
-
apiKey,
|
2996
|
-
apiUrl: databaseURL,
|
2997
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2998
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
2999
|
-
pathParams: { dbName, workspace, region },
|
3000
|
-
queryParams: { gitBranch, fallbackBranch },
|
3001
|
-
trace: defaultTrace
|
3002
|
-
});
|
3003
|
-
return branch;
|
3004
|
-
}
|
3005
|
-
async function getDatabaseBranch(branch, options) {
|
3006
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3007
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3008
|
-
if (!databaseURL)
|
3009
|
-
throw new Error(
|
3010
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3011
|
-
);
|
3012
|
-
if (!apiKey)
|
3013
|
-
throw new Error(
|
3014
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3015
|
-
);
|
3016
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3017
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3018
|
-
if (!urlParts)
|
3019
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3020
|
-
const { workspace, region } = urlParts;
|
3021
|
-
try {
|
3022
|
-
return await getBranchDetails({
|
3023
|
-
apiKey,
|
3024
|
-
apiUrl: databaseURL,
|
3025
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3026
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3027
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3028
|
-
trace: defaultTrace
|
3029
|
-
});
|
3030
|
-
} catch (err) {
|
3031
|
-
if (isObject(err) && err.status === 404)
|
3032
|
-
return null;
|
3033
|
-
throw err;
|
3206
|
+
function escapeElement(elementRepresentation) {
|
3207
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
3208
|
+
return '"' + escaped + '"';
|
3209
|
+
}
|
3210
|
+
function arrayString(val) {
|
3211
|
+
let result = "{";
|
3212
|
+
for (let i = 0; i < val.length; i++) {
|
3213
|
+
if (i > 0) {
|
3214
|
+
result = result + ",";
|
3215
|
+
}
|
3216
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
3217
|
+
result = result + "NULL";
|
3218
|
+
} else if (Array.isArray(val[i])) {
|
3219
|
+
result = result + arrayString(val[i]);
|
3220
|
+
} else if (val[i] instanceof Buffer) {
|
3221
|
+
result += "\\\\x" + val[i].toString("hex");
|
3222
|
+
} else {
|
3223
|
+
result += escapeElement(prepareValue(val[i]));
|
3224
|
+
}
|
3034
3225
|
}
|
3226
|
+
result = result + "}";
|
3227
|
+
return result;
|
3035
3228
|
}
|
3036
|
-
function
|
3229
|
+
function prepareValue(value) {
|
3230
|
+
if (!isDefined(value))
|
3231
|
+
return null;
|
3232
|
+
if (value instanceof Date) {
|
3233
|
+
return value.toISOString();
|
3234
|
+
}
|
3235
|
+
if (Array.isArray(value)) {
|
3236
|
+
return arrayString(value);
|
3237
|
+
}
|
3238
|
+
if (isObject(value)) {
|
3239
|
+
return JSON.stringify(value);
|
3240
|
+
}
|
3037
3241
|
try {
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3041
|
-
|
3242
|
+
return value.toString();
|
3243
|
+
} catch (e) {
|
3244
|
+
return value;
|
3245
|
+
}
|
3246
|
+
}
|
3247
|
+
function prepareParams(param1, param2) {
|
3248
|
+
if (isString(param1)) {
|
3249
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
3250
|
+
}
|
3251
|
+
if (isStringArray(param1)) {
|
3252
|
+
const statement = param1.reduce((acc, curr, index) => {
|
3253
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
3254
|
+
}, "");
|
3255
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
3256
|
+
}
|
3257
|
+
if (isObject(param1)) {
|
3258
|
+
const { statement, params, consistency } = param1;
|
3259
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
3260
|
+
}
|
3261
|
+
throw new Error("Invalid query");
|
3262
|
+
}
|
3263
|
+
|
3264
|
+
class SQLPlugin extends XataPlugin {
|
3265
|
+
build(pluginOptions) {
|
3266
|
+
return async (param1, ...param2) => {
|
3267
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
3268
|
+
const { records, warning } = await sqlQuery({
|
3269
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3270
|
+
body: { statement, params, consistency },
|
3271
|
+
...pluginOptions
|
3272
|
+
});
|
3273
|
+
return { records, warning };
|
3274
|
+
};
|
3275
|
+
}
|
3276
|
+
}
|
3277
|
+
|
3278
|
+
class TransactionPlugin extends XataPlugin {
|
3279
|
+
build(pluginOptions) {
|
3280
|
+
return {
|
3281
|
+
run: async (operations) => {
|
3282
|
+
const response = await branchTransaction({
|
3283
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3284
|
+
body: { operations },
|
3285
|
+
...pluginOptions
|
3286
|
+
});
|
3287
|
+
return response;
|
3288
|
+
}
|
3289
|
+
};
|
3042
3290
|
}
|
3043
3291
|
}
|
3044
3292
|
|
@@ -3065,46 +3313,43 @@ var __privateMethod = (obj, member, method) => {
|
|
3065
3313
|
return method;
|
3066
3314
|
};
|
3067
3315
|
const buildClient = (plugins) => {
|
3068
|
-
var
|
3316
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3069
3317
|
return _a = class {
|
3070
3318
|
constructor(options = {}, schemaTables) {
|
3071
3319
|
__privateAdd(this, _parseOptions);
|
3072
3320
|
__privateAdd(this, _getFetchProps);
|
3073
|
-
__privateAdd(this, _evaluateBranch);
|
3074
|
-
__privateAdd(this, _branch, void 0);
|
3075
3321
|
__privateAdd(this, _options, void 0);
|
3076
3322
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3077
3323
|
__privateSet(this, _options, safeOptions);
|
3078
3324
|
const pluginOptions = {
|
3079
|
-
|
3325
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3080
3326
|
cache: safeOptions.cache,
|
3081
|
-
|
3327
|
+
host: safeOptions.host
|
3082
3328
|
};
|
3083
3329
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3084
3330
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3331
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
3332
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
3333
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3085
3334
|
this.db = db;
|
3086
3335
|
this.search = search;
|
3336
|
+
this.transactions = transactions;
|
3337
|
+
this.sql = sql;
|
3338
|
+
this.files = files;
|
3087
3339
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3088
3340
|
if (namespace === void 0)
|
3089
3341
|
continue;
|
3090
|
-
|
3091
|
-
if (result instanceof Promise) {
|
3092
|
-
void result.then((namespace2) => {
|
3093
|
-
this[key] = namespace2;
|
3094
|
-
});
|
3095
|
-
} else {
|
3096
|
-
this[key] = result;
|
3097
|
-
}
|
3342
|
+
this[key] = namespace.build(pluginOptions);
|
3098
3343
|
}
|
3099
3344
|
}
|
3100
3345
|
async getConfig() {
|
3101
3346
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3102
|
-
const branch =
|
3347
|
+
const branch = __privateGet(this, _options).branch;
|
3103
3348
|
return { databaseURL, branch };
|
3104
3349
|
}
|
3105
|
-
},
|
3350
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3106
3351
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3107
|
-
const isBrowser = typeof window !== "undefined";
|
3352
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3108
3353
|
if (isBrowser && !enableBrowser) {
|
3109
3354
|
throw new Error(
|
3110
3355
|
"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."
|
@@ -3115,46 +3360,73 @@ const buildClient = (plugins) => {
|
|
3115
3360
|
const apiKey = options?.apiKey || getAPIKey();
|
3116
3361
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3117
3362
|
const trace = options?.trace ?? defaultTrace;
|
3118
|
-
const
|
3363
|
+
const clientName = options?.clientName;
|
3364
|
+
const host = options?.host ?? "production";
|
3365
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3119
3366
|
if (!apiKey) {
|
3120
3367
|
throw new Error("Option apiKey is required");
|
3121
3368
|
}
|
3122
3369
|
if (!databaseURL) {
|
3123
3370
|
throw new Error("Option databaseURL is required");
|
3124
3371
|
}
|
3125
|
-
|
3126
|
-
|
3127
|
-
const
|
3128
|
-
if (
|
3129
|
-
|
3372
|
+
const envBranch = getBranch();
|
3373
|
+
const previewBranch = getPreviewBranch();
|
3374
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
3375
|
+
if (!!previewBranch && branch !== previewBranch) {
|
3376
|
+
console.warn(
|
3377
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
3378
|
+
);
|
3379
|
+
} else if (!!envBranch && branch !== envBranch) {
|
3380
|
+
console.warn(
|
3381
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
3382
|
+
);
|
3383
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
3384
|
+
console.warn(
|
3385
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
3386
|
+
);
|
3387
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
3388
|
+
console.warn(
|
3389
|
+
`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.`
|
3390
|
+
);
|
3391
|
+
}
|
3392
|
+
return {
|
3393
|
+
fetch,
|
3394
|
+
databaseURL,
|
3395
|
+
apiKey,
|
3396
|
+
branch,
|
3397
|
+
cache,
|
3398
|
+
trace,
|
3399
|
+
host,
|
3400
|
+
clientID: generateUUID(),
|
3401
|
+
enableBrowser,
|
3402
|
+
clientName,
|
3403
|
+
xataAgentExtra
|
3404
|
+
};
|
3405
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3406
|
+
fetch,
|
3407
|
+
apiKey,
|
3408
|
+
databaseURL,
|
3409
|
+
branch,
|
3410
|
+
trace,
|
3411
|
+
clientID,
|
3412
|
+
clientName,
|
3413
|
+
xataAgentExtra
|
3414
|
+
}) {
|
3130
3415
|
return {
|
3131
|
-
|
3416
|
+
fetch,
|
3132
3417
|
apiKey,
|
3133
3418
|
apiUrl: "",
|
3419
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3134
3420
|
workspacesApiUrl: (path, params) => {
|
3135
3421
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3136
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
3422
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3137
3423
|
return databaseURL + newPath;
|
3138
3424
|
},
|
3139
3425
|
trace,
|
3140
|
-
clientID
|
3141
|
-
|
3142
|
-
|
3143
|
-
if (__privateGet(this, _branch))
|
3144
|
-
return __privateGet(this, _branch);
|
3145
|
-
if (param === void 0)
|
3146
|
-
return void 0;
|
3147
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3148
|
-
const evaluateBranch = async (strategy) => {
|
3149
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3426
|
+
clientID,
|
3427
|
+
clientName,
|
3428
|
+
xataAgentExtra
|
3150
3429
|
};
|
3151
|
-
for await (const strategy of strategies) {
|
3152
|
-
const branch = await evaluateBranch(strategy);
|
3153
|
-
if (branch) {
|
3154
|
-
__privateSet(this, _branch, branch);
|
3155
|
-
return branch;
|
3156
|
-
}
|
3157
|
-
}
|
3158
3430
|
}, _a;
|
3159
3431
|
};
|
3160
3432
|
class BaseClient extends buildClient() {
|
@@ -3227,21 +3499,6 @@ const deserialize = (json) => {
|
|
3227
3499
|
return defaultSerializer.fromJSON(json);
|
3228
3500
|
};
|
3229
3501
|
|
3230
|
-
function buildWorkerRunner(config) {
|
3231
|
-
return function xataWorker(name, _worker) {
|
3232
|
-
return async (...args) => {
|
3233
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3234
|
-
const result = await fetch(url, {
|
3235
|
-
method: "POST",
|
3236
|
-
headers: { "Content-Type": "application/json" },
|
3237
|
-
body: serialize({ args })
|
3238
|
-
});
|
3239
|
-
const text = await result.text();
|
3240
|
-
return deserialize(text);
|
3241
|
-
};
|
3242
|
-
};
|
3243
|
-
}
|
3244
|
-
|
3245
3502
|
class XataError extends Error {
|
3246
3503
|
constructor(message, status) {
|
3247
3504
|
super(message);
|
@@ -3249,5 +3506,5 @@ class XataError extends Error {
|
|
3249
3506
|
}
|
3250
3507
|
}
|
3251
3508
|
|
3252
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient,
|
3509
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3253
3510
|
//# sourceMappingURL=index.mjs.map
|