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