@xata.io/client 0.0.0-alpha.vf8f3b02 → 0.0.0-alpha.vf90263d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +328 -0
- package/README.md +3 -269
- package/dist/index.cjs +1972 -401
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4032 -1676
- package/dist/index.mjs +1928 -395
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -10
- package/.eslintrc.cjs +0 -12
- package/Usage.md +0 -451
- package/mod.ts +0 -2
- package/rollup.config.mjs +0 -29
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
const defaultTrace = async (
|
1
|
+
const defaultTrace = async (name, fn, _options) => {
|
2
2
|
return await fn({
|
3
|
+
name,
|
3
4
|
setAttributes: () => {
|
4
5
|
return;
|
5
6
|
}
|
@@ -17,7 +18,8 @@ const TraceAttributes = {
|
|
17
18
|
HTTP_METHOD: "http.method",
|
18
19
|
HTTP_URL: "http.url",
|
19
20
|
HTTP_ROUTE: "http.route",
|
20
|
-
HTTP_TARGET: "http.target"
|
21
|
+
HTTP_TARGET: "http.target",
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
21
23
|
};
|
22
24
|
|
23
25
|
function notEmpty(value) {
|
@@ -26,8 +28,18 @@ function notEmpty(value) {
|
|
26
28
|
function compact(arr) {
|
27
29
|
return arr.filter(notEmpty);
|
28
30
|
}
|
31
|
+
function compactObject(obj) {
|
32
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
33
|
+
}
|
34
|
+
function isBlob(value) {
|
35
|
+
try {
|
36
|
+
return value instanceof Blob;
|
37
|
+
} catch (error) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
}
|
29
41
|
function isObject(value) {
|
30
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
31
43
|
}
|
32
44
|
function isDefined(value) {
|
33
45
|
return value !== null && value !== void 0;
|
@@ -41,6 +53,18 @@ function isStringArray(value) {
|
|
41
53
|
function isNumber(value) {
|
42
54
|
return isDefined(value) && typeof value === "number";
|
43
55
|
}
|
56
|
+
function parseNumber(value) {
|
57
|
+
if (isNumber(value)) {
|
58
|
+
return value;
|
59
|
+
}
|
60
|
+
if (isString(value)) {
|
61
|
+
const parsed = Number(value);
|
62
|
+
if (!Number.isNaN(parsed)) {
|
63
|
+
return parsed;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return void 0;
|
67
|
+
}
|
44
68
|
function toBase64(value) {
|
45
69
|
try {
|
46
70
|
return btoa(value);
|
@@ -60,16 +84,49 @@ function deepMerge(a, b) {
|
|
60
84
|
}
|
61
85
|
return result;
|
62
86
|
}
|
87
|
+
function chunk(array, chunkSize) {
|
88
|
+
const result = [];
|
89
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
90
|
+
result.push(array.slice(i, i + chunkSize));
|
91
|
+
}
|
92
|
+
return result;
|
93
|
+
}
|
94
|
+
async function timeout(ms) {
|
95
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
96
|
+
}
|
97
|
+
function timeoutWithCancel(ms) {
|
98
|
+
let timeoutId;
|
99
|
+
const promise = new Promise((resolve) => {
|
100
|
+
timeoutId = setTimeout(() => {
|
101
|
+
resolve();
|
102
|
+
}, ms);
|
103
|
+
});
|
104
|
+
return {
|
105
|
+
cancel: () => clearTimeout(timeoutId),
|
106
|
+
promise
|
107
|
+
};
|
108
|
+
}
|
109
|
+
function promiseMap(inputValues, mapper) {
|
110
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
111
|
+
(acc) => mapper(inputValue).then((result) => {
|
112
|
+
acc.push(result);
|
113
|
+
return acc;
|
114
|
+
})
|
115
|
+
);
|
116
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
117
|
+
}
|
63
118
|
|
64
119
|
function getEnvironment() {
|
65
120
|
try {
|
66
|
-
if (
|
121
|
+
if (isDefined(process) && isDefined(process.env)) {
|
67
122
|
return {
|
68
123
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
69
124
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
70
125
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
71
|
-
|
72
|
-
|
126
|
+
deployPreview: process.env.XATA_PREVIEW,
|
127
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
128
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
129
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
73
130
|
};
|
74
131
|
}
|
75
132
|
} catch (err) {
|
@@ -80,8 +137,10 @@ function getEnvironment() {
|
|
80
137
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
81
138
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
82
139
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
83
|
-
|
84
|
-
|
140
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
141
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
142
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
143
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
85
144
|
};
|
86
145
|
}
|
87
146
|
} catch (err) {
|
@@ -90,8 +149,10 @@ function getEnvironment() {
|
|
90
149
|
apiKey: getGlobalApiKey(),
|
91
150
|
databaseURL: getGlobalDatabaseURL(),
|
92
151
|
branch: getGlobalBranch(),
|
93
|
-
|
94
|
-
|
152
|
+
deployPreview: void 0,
|
153
|
+
deployPreviewBranch: void 0,
|
154
|
+
vercelGitCommitRef: void 0,
|
155
|
+
vercelGitRepoOwner: void 0
|
95
156
|
};
|
96
157
|
}
|
97
158
|
function getEnableBrowserVariable() {
|
@@ -134,56 +195,338 @@ function getGlobalBranch() {
|
|
134
195
|
return void 0;
|
135
196
|
}
|
136
197
|
}
|
137
|
-
function
|
198
|
+
function getDatabaseURL() {
|
138
199
|
try {
|
139
|
-
|
200
|
+
const { databaseURL } = getEnvironment();
|
201
|
+
return databaseURL;
|
140
202
|
} catch (err) {
|
141
203
|
return void 0;
|
142
204
|
}
|
143
205
|
}
|
144
|
-
|
145
|
-
const cmd = ["git", "branch", "--show-current"];
|
146
|
-
const fullCmd = cmd.join(" ");
|
147
|
-
const nodeModule = ["child", "process"].join("_");
|
148
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
206
|
+
function getAPIKey() {
|
149
207
|
try {
|
150
|
-
|
151
|
-
|
152
|
-
}
|
153
|
-
const { execSync } = await import(nodeModule);
|
154
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
208
|
+
const { apiKey } = getEnvironment();
|
209
|
+
return apiKey;
|
155
210
|
} catch (err) {
|
211
|
+
return void 0;
|
156
212
|
}
|
213
|
+
}
|
214
|
+
function getBranch() {
|
157
215
|
try {
|
158
|
-
|
159
|
-
|
160
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
161
|
-
}
|
216
|
+
const { branch } = getEnvironment();
|
217
|
+
return branch;
|
162
218
|
} catch (err) {
|
219
|
+
return void 0;
|
163
220
|
}
|
164
221
|
}
|
165
|
-
|
166
|
-
|
222
|
+
function buildPreviewBranchName({ org, branch }) {
|
223
|
+
return `preview-${org}-${branch}`;
|
224
|
+
}
|
225
|
+
function getPreviewBranch() {
|
167
226
|
try {
|
168
|
-
const {
|
169
|
-
|
227
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
228
|
+
if (deployPreviewBranch)
|
229
|
+
return deployPreviewBranch;
|
230
|
+
switch (deployPreview) {
|
231
|
+
case "vercel": {
|
232
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
233
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
234
|
+
return void 0;
|
235
|
+
}
|
236
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
237
|
+
}
|
238
|
+
}
|
239
|
+
return void 0;
|
170
240
|
} catch (err) {
|
171
241
|
return void 0;
|
172
242
|
}
|
173
243
|
}
|
174
244
|
|
245
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
246
|
+
if (!member.has(obj))
|
247
|
+
throw TypeError("Cannot " + msg);
|
248
|
+
};
|
249
|
+
var __privateGet$8 = (obj, member, getter) => {
|
250
|
+
__accessCheck$8(obj, member, "read from private field");
|
251
|
+
return getter ? getter.call(obj) : member.get(obj);
|
252
|
+
};
|
253
|
+
var __privateAdd$8 = (obj, member, value) => {
|
254
|
+
if (member.has(obj))
|
255
|
+
throw TypeError("Cannot add the same private member more than once");
|
256
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
257
|
+
};
|
258
|
+
var __privateSet$8 = (obj, member, value, setter) => {
|
259
|
+
__accessCheck$8(obj, member, "write to private field");
|
260
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
261
|
+
return value;
|
262
|
+
};
|
263
|
+
var __privateMethod$4 = (obj, member, method) => {
|
264
|
+
__accessCheck$8(obj, member, "access private method");
|
265
|
+
return method;
|
266
|
+
};
|
267
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
175
269
|
function getFetchImplementation(userFetch) {
|
176
270
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
177
|
-
const
|
271
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
272
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
178
273
|
if (!fetchImpl) {
|
179
|
-
throw new Error(
|
180
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
181
|
-
);
|
274
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
182
275
|
}
|
183
276
|
return fetchImpl;
|
184
277
|
}
|
278
|
+
class ApiRequestPool {
|
279
|
+
constructor(concurrency = 10) {
|
280
|
+
__privateAdd$8(this, _enqueue);
|
281
|
+
__privateAdd$8(this, _fetch, void 0);
|
282
|
+
__privateAdd$8(this, _queue, void 0);
|
283
|
+
__privateAdd$8(this, _concurrency, void 0);
|
284
|
+
__privateSet$8(this, _queue, []);
|
285
|
+
__privateSet$8(this, _concurrency, concurrency);
|
286
|
+
this.running = 0;
|
287
|
+
this.started = 0;
|
288
|
+
}
|
289
|
+
setFetch(fetch2) {
|
290
|
+
__privateSet$8(this, _fetch, fetch2);
|
291
|
+
}
|
292
|
+
getFetch() {
|
293
|
+
if (!__privateGet$8(this, _fetch)) {
|
294
|
+
throw new Error("Fetch not set");
|
295
|
+
}
|
296
|
+
return __privateGet$8(this, _fetch);
|
297
|
+
}
|
298
|
+
request(url, options) {
|
299
|
+
const start = /* @__PURE__ */ new Date();
|
300
|
+
const fetchImpl = this.getFetch();
|
301
|
+
const runRequest = async (stalled = false) => {
|
302
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
303
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
304
|
+
if (!response) {
|
305
|
+
throw new Error("Request timed out");
|
306
|
+
}
|
307
|
+
if (response.status === 429) {
|
308
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
309
|
+
await timeout(rateLimitReset * 1e3);
|
310
|
+
return await runRequest(true);
|
311
|
+
}
|
312
|
+
if (stalled) {
|
313
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
314
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
315
|
+
}
|
316
|
+
return response;
|
317
|
+
};
|
318
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
319
|
+
return await runRequest();
|
320
|
+
});
|
321
|
+
}
|
322
|
+
}
|
323
|
+
_fetch = new WeakMap();
|
324
|
+
_queue = new WeakMap();
|
325
|
+
_concurrency = new WeakMap();
|
326
|
+
_enqueue = new WeakSet();
|
327
|
+
enqueue_fn = function(task) {
|
328
|
+
const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
|
329
|
+
this.started--;
|
330
|
+
this.running++;
|
331
|
+
}).then(() => task()).finally(() => {
|
332
|
+
this.running--;
|
333
|
+
const next = __privateGet$8(this, _queue).shift();
|
334
|
+
if (next !== void 0) {
|
335
|
+
this.started++;
|
336
|
+
next();
|
337
|
+
}
|
338
|
+
});
|
339
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
340
|
+
const next = __privateGet$8(this, _queue).shift();
|
341
|
+
if (next !== void 0) {
|
342
|
+
this.started++;
|
343
|
+
next();
|
344
|
+
}
|
345
|
+
}
|
346
|
+
return promise;
|
347
|
+
};
|
348
|
+
|
349
|
+
function generateUUID() {
|
350
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
351
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
352
|
+
return v.toString(16);
|
353
|
+
});
|
354
|
+
}
|
355
|
+
|
356
|
+
async function getBytes(stream, onChunk) {
|
357
|
+
const reader = stream.getReader();
|
358
|
+
let result;
|
359
|
+
while (!(result = await reader.read()).done) {
|
360
|
+
onChunk(result.value);
|
361
|
+
}
|
362
|
+
}
|
363
|
+
function getLines(onLine) {
|
364
|
+
let buffer;
|
365
|
+
let position;
|
366
|
+
let fieldLength;
|
367
|
+
let discardTrailingNewline = false;
|
368
|
+
return function onChunk(arr) {
|
369
|
+
if (buffer === void 0) {
|
370
|
+
buffer = arr;
|
371
|
+
position = 0;
|
372
|
+
fieldLength = -1;
|
373
|
+
} else {
|
374
|
+
buffer = concat(buffer, arr);
|
375
|
+
}
|
376
|
+
const bufLength = buffer.length;
|
377
|
+
let lineStart = 0;
|
378
|
+
while (position < bufLength) {
|
379
|
+
if (discardTrailingNewline) {
|
380
|
+
if (buffer[position] === 10 /* NewLine */) {
|
381
|
+
lineStart = ++position;
|
382
|
+
}
|
383
|
+
discardTrailingNewline = false;
|
384
|
+
}
|
385
|
+
let lineEnd = -1;
|
386
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
387
|
+
switch (buffer[position]) {
|
388
|
+
case 58 /* Colon */:
|
389
|
+
if (fieldLength === -1) {
|
390
|
+
fieldLength = position - lineStart;
|
391
|
+
}
|
392
|
+
break;
|
393
|
+
case 13 /* CarriageReturn */:
|
394
|
+
discardTrailingNewline = true;
|
395
|
+
case 10 /* NewLine */:
|
396
|
+
lineEnd = position;
|
397
|
+
break;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
if (lineEnd === -1) {
|
401
|
+
break;
|
402
|
+
}
|
403
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
404
|
+
lineStart = position;
|
405
|
+
fieldLength = -1;
|
406
|
+
}
|
407
|
+
if (lineStart === bufLength) {
|
408
|
+
buffer = void 0;
|
409
|
+
} else if (lineStart !== 0) {
|
410
|
+
buffer = buffer.subarray(lineStart);
|
411
|
+
position -= lineStart;
|
412
|
+
}
|
413
|
+
};
|
414
|
+
}
|
415
|
+
function getMessages(onId, onRetry, onMessage) {
|
416
|
+
let message = newMessage();
|
417
|
+
const decoder = new TextDecoder();
|
418
|
+
return function onLine(line, fieldLength) {
|
419
|
+
if (line.length === 0) {
|
420
|
+
onMessage?.(message);
|
421
|
+
message = newMessage();
|
422
|
+
} else if (fieldLength > 0) {
|
423
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
424
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
425
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
426
|
+
switch (field) {
|
427
|
+
case "data":
|
428
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
429
|
+
break;
|
430
|
+
case "event":
|
431
|
+
message.event = value;
|
432
|
+
break;
|
433
|
+
case "id":
|
434
|
+
onId(message.id = value);
|
435
|
+
break;
|
436
|
+
case "retry":
|
437
|
+
const retry = parseInt(value, 10);
|
438
|
+
if (!isNaN(retry)) {
|
439
|
+
onRetry(message.retry = retry);
|
440
|
+
}
|
441
|
+
break;
|
442
|
+
}
|
443
|
+
}
|
444
|
+
};
|
445
|
+
}
|
446
|
+
function concat(a, b) {
|
447
|
+
const res = new Uint8Array(a.length + b.length);
|
448
|
+
res.set(a);
|
449
|
+
res.set(b, a.length);
|
450
|
+
return res;
|
451
|
+
}
|
452
|
+
function newMessage() {
|
453
|
+
return {
|
454
|
+
data: "",
|
455
|
+
event: "",
|
456
|
+
id: "",
|
457
|
+
retry: void 0
|
458
|
+
};
|
459
|
+
}
|
460
|
+
const EventStreamContentType = "text/event-stream";
|
461
|
+
const LastEventId = "last-event-id";
|
462
|
+
function fetchEventSource(input, {
|
463
|
+
signal: inputSignal,
|
464
|
+
headers: inputHeaders,
|
465
|
+
onopen: inputOnOpen,
|
466
|
+
onmessage,
|
467
|
+
onclose,
|
468
|
+
onerror,
|
469
|
+
fetch: inputFetch,
|
470
|
+
...rest
|
471
|
+
}) {
|
472
|
+
return new Promise((resolve, reject) => {
|
473
|
+
const headers = { ...inputHeaders };
|
474
|
+
if (!headers.accept) {
|
475
|
+
headers.accept = EventStreamContentType;
|
476
|
+
}
|
477
|
+
let curRequestController;
|
478
|
+
function dispose() {
|
479
|
+
curRequestController.abort();
|
480
|
+
}
|
481
|
+
inputSignal?.addEventListener("abort", () => {
|
482
|
+
dispose();
|
483
|
+
resolve();
|
484
|
+
});
|
485
|
+
const fetchImpl = inputFetch ?? fetch;
|
486
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
487
|
+
async function create() {
|
488
|
+
curRequestController = new AbortController();
|
489
|
+
try {
|
490
|
+
const response = await fetchImpl(input, {
|
491
|
+
...rest,
|
492
|
+
headers,
|
493
|
+
signal: curRequestController.signal
|
494
|
+
});
|
495
|
+
await onopen(response);
|
496
|
+
await getBytes(
|
497
|
+
response.body,
|
498
|
+
getLines(
|
499
|
+
getMessages(
|
500
|
+
(id) => {
|
501
|
+
if (id) {
|
502
|
+
headers[LastEventId] = id;
|
503
|
+
} else {
|
504
|
+
delete headers[LastEventId];
|
505
|
+
}
|
506
|
+
},
|
507
|
+
(_retry) => {
|
508
|
+
},
|
509
|
+
onmessage
|
510
|
+
)
|
511
|
+
)
|
512
|
+
);
|
513
|
+
onclose?.();
|
514
|
+
dispose();
|
515
|
+
resolve();
|
516
|
+
} catch (err) {
|
517
|
+
}
|
518
|
+
}
|
519
|
+
create();
|
520
|
+
});
|
521
|
+
}
|
522
|
+
function defaultOnOpen(response) {
|
523
|
+
const contentType = response.headers?.get("content-type");
|
524
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
525
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
526
|
+
}
|
527
|
+
}
|
185
528
|
|
186
|
-
const VERSION = "0.
|
529
|
+
const VERSION = "0.27.0";
|
187
530
|
|
188
531
|
class ErrorWithCause extends Error {
|
189
532
|
constructor(message, options) {
|
@@ -194,7 +537,7 @@ class FetcherError extends ErrorWithCause {
|
|
194
537
|
constructor(status, data, requestId) {
|
195
538
|
super(getMessage(data));
|
196
539
|
this.status = status;
|
197
|
-
this.errors = isBulkError(data) ? data.errors :
|
540
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
198
541
|
this.requestId = requestId;
|
199
542
|
if (data instanceof Error) {
|
200
543
|
this.stack = data.stack;
|
@@ -226,6 +569,7 @@ function getMessage(data) {
|
|
226
569
|
}
|
227
570
|
}
|
228
571
|
|
572
|
+
const pool = new ApiRequestPool();
|
229
573
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
230
574
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
231
575
|
if (value === void 0 || value === null)
|
@@ -258,14 +602,27 @@ function hostHeader(url) {
|
|
258
602
|
const { groups } = pattern.exec(url) ?? {};
|
259
603
|
return groups?.host ? { Host: groups.host } : {};
|
260
604
|
}
|
605
|
+
async function parseBody(body, headers) {
|
606
|
+
if (!isDefined(body))
|
607
|
+
return void 0;
|
608
|
+
if (isBlob(body) || typeof body.text === "function") {
|
609
|
+
return body;
|
610
|
+
}
|
611
|
+
const { "Content-Type": contentType } = headers ?? {};
|
612
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
613
|
+
return JSON.stringify(body);
|
614
|
+
}
|
615
|
+
return body;
|
616
|
+
}
|
617
|
+
const defaultClientID = generateUUID();
|
261
618
|
async function fetch$1({
|
262
619
|
url: path,
|
263
620
|
method,
|
264
621
|
body,
|
265
|
-
headers,
|
622
|
+
headers: customHeaders,
|
266
623
|
pathParams,
|
267
624
|
queryParams,
|
268
|
-
|
625
|
+
fetch: fetch2,
|
269
626
|
apiKey,
|
270
627
|
endpoint,
|
271
628
|
apiUrl,
|
@@ -274,9 +631,13 @@ async function fetch$1({
|
|
274
631
|
signal,
|
275
632
|
clientID,
|
276
633
|
sessionID,
|
277
|
-
|
634
|
+
clientName,
|
635
|
+
xataAgentExtra,
|
636
|
+
fetchOptions = {},
|
637
|
+
rawResponse = false
|
278
638
|
}) {
|
279
|
-
|
639
|
+
pool.setFetch(fetch2);
|
640
|
+
return await trace(
|
280
641
|
`${method.toUpperCase()} ${path}`,
|
281
642
|
async ({ setAttributes }) => {
|
282
643
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
@@ -286,24 +647,29 @@ async function fetch$1({
|
|
286
647
|
[TraceAttributes.HTTP_URL]: url,
|
287
648
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
288
649
|
});
|
289
|
-
const
|
650
|
+
const xataAgent = compact([
|
651
|
+
["client", "TS_SDK"],
|
652
|
+
["version", VERSION],
|
653
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
654
|
+
...Object.entries(xataAgentExtra ?? {})
|
655
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
656
|
+
const headers = compactObject({
|
657
|
+
"Accept-Encoding": "identity",
|
658
|
+
"Content-Type": "application/json",
|
659
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
660
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
661
|
+
"X-Xata-Agent": xataAgent,
|
662
|
+
...customHeaders,
|
663
|
+
...hostHeader(fullUrl),
|
664
|
+
Authorization: `Bearer ${apiKey}`
|
665
|
+
});
|
666
|
+
const response = await pool.request(url, {
|
290
667
|
...fetchOptions,
|
291
668
|
method: method.toUpperCase(),
|
292
|
-
body:
|
293
|
-
headers
|
294
|
-
"Content-Type": "application/json",
|
295
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
296
|
-
"X-Xata-Client-ID": clientID ?? "",
|
297
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
298
|
-
...headers,
|
299
|
-
...hostHeader(fullUrl),
|
300
|
-
Authorization: `Bearer ${apiKey}`
|
301
|
-
},
|
669
|
+
body: await parseBody(body, headers),
|
670
|
+
headers,
|
302
671
|
signal
|
303
672
|
});
|
304
|
-
if (response.status === 204) {
|
305
|
-
return {};
|
306
|
-
}
|
307
673
|
const { host, protocol } = parseUrl(response.url);
|
308
674
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
309
675
|
setAttributes({
|
@@ -311,10 +677,20 @@ async function fetch$1({
|
|
311
677
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
312
678
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
313
679
|
[TraceAttributes.HTTP_HOST]: host,
|
314
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
680
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
681
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
315
682
|
});
|
683
|
+
const message = response.headers?.get("x-xata-message");
|
684
|
+
if (message)
|
685
|
+
console.warn(message);
|
686
|
+
if (response.status === 204) {
|
687
|
+
return {};
|
688
|
+
}
|
689
|
+
if (response.status === 429) {
|
690
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
691
|
+
}
|
316
692
|
try {
|
317
|
-
const jsonResponse = await response.json();
|
693
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
318
694
|
if (response.ok) {
|
319
695
|
return jsonResponse;
|
320
696
|
}
|
@@ -326,6 +702,59 @@ async function fetch$1({
|
|
326
702
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
327
703
|
);
|
328
704
|
}
|
705
|
+
function fetchSSERequest({
|
706
|
+
url: path,
|
707
|
+
method,
|
708
|
+
body,
|
709
|
+
headers: customHeaders,
|
710
|
+
pathParams,
|
711
|
+
queryParams,
|
712
|
+
fetch: fetch2,
|
713
|
+
apiKey,
|
714
|
+
endpoint,
|
715
|
+
apiUrl,
|
716
|
+
workspacesApiUrl,
|
717
|
+
onMessage,
|
718
|
+
onError,
|
719
|
+
onClose,
|
720
|
+
signal,
|
721
|
+
clientID,
|
722
|
+
sessionID,
|
723
|
+
clientName,
|
724
|
+
xataAgentExtra
|
725
|
+
}) {
|
726
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
727
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
728
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
729
|
+
void fetchEventSource(url, {
|
730
|
+
method,
|
731
|
+
body: JSON.stringify(body),
|
732
|
+
fetch: fetch2,
|
733
|
+
signal,
|
734
|
+
headers: {
|
735
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
736
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
737
|
+
"X-Xata-Agent": compact([
|
738
|
+
["client", "TS_SDK"],
|
739
|
+
["version", VERSION],
|
740
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
741
|
+
...Object.entries(xataAgentExtra ?? {})
|
742
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
743
|
+
...customHeaders,
|
744
|
+
Authorization: `Bearer ${apiKey}`,
|
745
|
+
"Content-Type": "application/json"
|
746
|
+
},
|
747
|
+
onmessage(ev) {
|
748
|
+
onMessage?.(JSON.parse(ev.data));
|
749
|
+
},
|
750
|
+
onerror(ev) {
|
751
|
+
onError?.(JSON.parse(ev.data));
|
752
|
+
},
|
753
|
+
onclose() {
|
754
|
+
onClose?.();
|
755
|
+
}
|
756
|
+
});
|
757
|
+
}
|
329
758
|
function parseUrl(url) {
|
330
759
|
try {
|
331
760
|
const { host, protocol } = new URL(url);
|
@@ -337,17 +766,18 @@ function parseUrl(url) {
|
|
337
766
|
|
338
767
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
339
768
|
|
340
|
-
const
|
769
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({
|
770
|
+
url: "/db/{dbBranchName}/pgroll/apply",
|
771
|
+
method: "post",
|
772
|
+
...variables,
|
773
|
+
signal
|
774
|
+
});
|
341
775
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
342
776
|
url: "/dbs/{dbName}",
|
343
777
|
method: "get",
|
344
778
|
...variables,
|
345
779
|
signal
|
346
780
|
});
|
347
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
348
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
349
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
350
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
351
781
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
352
782
|
url: "/db/{dbBranchName}",
|
353
783
|
method: "get",
|
@@ -361,6 +791,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
361
791
|
...variables,
|
362
792
|
signal
|
363
793
|
});
|
794
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
795
|
+
url: "/db/{dbBranchName}/schema",
|
796
|
+
method: "get",
|
797
|
+
...variables,
|
798
|
+
signal
|
799
|
+
});
|
800
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
801
|
+
url: "/db/{dbBranchName}/copy",
|
802
|
+
method: "post",
|
803
|
+
...variables,
|
804
|
+
signal
|
805
|
+
});
|
364
806
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
365
807
|
url: "/db/{dbBranchName}/metadata",
|
366
808
|
method: "put",
|
@@ -386,7 +828,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
386
828
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
387
829
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
388
830
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
389
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
390
831
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
391
832
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
392
833
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
@@ -411,6 +852,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
411
852
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
412
853
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
413
854
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
855
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
414
856
|
const createTable = (variables, signal) => dataPlaneFetch({
|
415
857
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
416
858
|
method: "put",
|
@@ -453,7 +895,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
453
895
|
...variables,
|
454
896
|
signal
|
455
897
|
});
|
898
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
456
899
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
900
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
901
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
902
|
+
method: "get",
|
903
|
+
...variables,
|
904
|
+
signal
|
905
|
+
});
|
906
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
907
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
908
|
+
method: "put",
|
909
|
+
...variables,
|
910
|
+
signal
|
911
|
+
});
|
912
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
913
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
914
|
+
method: "delete",
|
915
|
+
...variables,
|
916
|
+
signal
|
917
|
+
});
|
918
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
919
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
920
|
+
method: "get",
|
921
|
+
...variables,
|
922
|
+
signal
|
923
|
+
});
|
924
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
925
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
926
|
+
method: "put",
|
927
|
+
...variables,
|
928
|
+
signal
|
929
|
+
});
|
930
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
931
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
932
|
+
method: "delete",
|
933
|
+
...variables,
|
934
|
+
signal
|
935
|
+
});
|
457
936
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
458
937
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
459
938
|
method: "get",
|
@@ -483,21 +962,36 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
483
962
|
...variables,
|
484
963
|
signal
|
485
964
|
});
|
965
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
966
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
967
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
968
|
+
method: "post",
|
969
|
+
...variables,
|
970
|
+
signal
|
971
|
+
});
|
972
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
486
973
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
487
974
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
975
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
976
|
+
url: "/file/{fileId}",
|
977
|
+
method: "get",
|
978
|
+
...variables,
|
979
|
+
signal
|
980
|
+
});
|
981
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
982
|
+
url: "/db/{dbBranchName}/sql",
|
983
|
+
method: "post",
|
984
|
+
...variables,
|
985
|
+
signal
|
986
|
+
});
|
488
987
|
const operationsByTag$2 = {
|
489
|
-
database: {
|
490
|
-
dEPRECATEDgetDatabaseList,
|
491
|
-
dEPRECATEDcreateDatabase,
|
492
|
-
dEPRECATEDdeleteDatabase,
|
493
|
-
dEPRECATEDgetDatabaseMetadata,
|
494
|
-
dEPRECATEDupdateDatabaseMetadata
|
495
|
-
},
|
496
988
|
branch: {
|
989
|
+
applyMigration,
|
497
990
|
getBranchList,
|
498
991
|
getBranchDetails,
|
499
992
|
createBranch,
|
500
993
|
deleteBranch,
|
994
|
+
copyBranch,
|
501
995
|
updateBranchMetadata,
|
502
996
|
getBranchMetadata,
|
503
997
|
getBranchStats,
|
@@ -507,6 +1001,7 @@ const operationsByTag$2 = {
|
|
507
1001
|
resolveBranch
|
508
1002
|
},
|
509
1003
|
migrations: {
|
1004
|
+
getSchema,
|
510
1005
|
getBranchMigrationHistory,
|
511
1006
|
getBranchMigrationPlan,
|
512
1007
|
executeBranchMigrationPlan,
|
@@ -515,17 +1010,8 @@ const operationsByTag$2 = {
|
|
515
1010
|
compareBranchSchemas,
|
516
1011
|
updateBranchSchema,
|
517
1012
|
previewBranchSchemaEdit,
|
518
|
-
applyBranchSchemaEdit
|
519
|
-
|
520
|
-
records: {
|
521
|
-
branchTransaction,
|
522
|
-
insertRecord,
|
523
|
-
getRecord,
|
524
|
-
insertRecordWithID,
|
525
|
-
updateRecordWithID,
|
526
|
-
upsertRecordWithID,
|
527
|
-
deleteRecord,
|
528
|
-
bulkInsertTableRecords
|
1013
|
+
applyBranchSchemaEdit,
|
1014
|
+
pushBranchMigrations
|
529
1015
|
},
|
530
1016
|
migrationRequests: {
|
531
1017
|
queryMigrationRequests,
|
@@ -549,11 +1035,34 @@ const operationsByTag$2 = {
|
|
549
1035
|
updateColumn,
|
550
1036
|
deleteColumn
|
551
1037
|
},
|
552
|
-
|
1038
|
+
records: {
|
1039
|
+
branchTransaction,
|
1040
|
+
insertRecord,
|
1041
|
+
getRecord,
|
1042
|
+
insertRecordWithID,
|
1043
|
+
updateRecordWithID,
|
1044
|
+
upsertRecordWithID,
|
1045
|
+
deleteRecord,
|
1046
|
+
bulkInsertTableRecords
|
1047
|
+
},
|
1048
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
1049
|
+
searchAndFilter: {
|
1050
|
+
queryTable,
|
1051
|
+
searchBranch,
|
1052
|
+
searchTable,
|
1053
|
+
vectorSearchTable,
|
1054
|
+
askTable,
|
1055
|
+
askTableSession,
|
1056
|
+
summarizeTable,
|
1057
|
+
aggregateTable
|
1058
|
+
},
|
1059
|
+
sql: { sqlQuery }
|
553
1060
|
};
|
554
1061
|
|
555
1062
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
556
1063
|
|
1064
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1065
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
557
1066
|
const getUser = (variables, signal) => controlPlaneFetch({
|
558
1067
|
url: "/user",
|
559
1068
|
method: "get",
|
@@ -590,6 +1099,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
590
1099
|
...variables,
|
591
1100
|
signal
|
592
1101
|
});
|
1102
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1103
|
+
url: "/user/oauth/clients",
|
1104
|
+
method: "get",
|
1105
|
+
...variables,
|
1106
|
+
signal
|
1107
|
+
});
|
1108
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1109
|
+
url: "/user/oauth/clients/{clientId}",
|
1110
|
+
method: "delete",
|
1111
|
+
...variables,
|
1112
|
+
signal
|
1113
|
+
});
|
1114
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1115
|
+
url: "/user/oauth/tokens",
|
1116
|
+
method: "get",
|
1117
|
+
...variables,
|
1118
|
+
signal
|
1119
|
+
});
|
1120
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1121
|
+
url: "/user/oauth/tokens/{token}",
|
1122
|
+
method: "delete",
|
1123
|
+
...variables,
|
1124
|
+
signal
|
1125
|
+
});
|
1126
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
593
1127
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
594
1128
|
url: "/workspaces",
|
595
1129
|
method: "get",
|
@@ -633,6 +1167,20 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
633
1167
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
634
1168
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
635
1169
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1170
|
+
const listClusters = (variables, signal) => controlPlaneFetch({
|
1171
|
+
url: "/workspaces/{workspaceId}/clusters",
|
1172
|
+
method: "get",
|
1173
|
+
...variables,
|
1174
|
+
signal
|
1175
|
+
});
|
1176
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1177
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1178
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1179
|
+
method: "get",
|
1180
|
+
...variables,
|
1181
|
+
signal
|
1182
|
+
});
|
1183
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
636
1184
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
637
1185
|
url: "/workspaces/{workspaceId}/dbs",
|
638
1186
|
method: "get",
|
@@ -648,6 +1196,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
648
1196
|
});
|
649
1197
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
650
1198
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1199
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1200
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1201
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1202
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
651
1203
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
652
1204
|
url: "/workspaces/{workspaceId}/regions",
|
653
1205
|
method: "get",
|
@@ -655,6 +1207,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
655
1207
|
signal
|
656
1208
|
});
|
657
1209
|
const operationsByTag$1 = {
|
1210
|
+
oAuth: {
|
1211
|
+
getAuthorizationCode,
|
1212
|
+
grantAuthorizationCode,
|
1213
|
+
getUserOAuthClients,
|
1214
|
+
deleteUserOAuthClient,
|
1215
|
+
getUserOAuthAccessTokens,
|
1216
|
+
deleteOAuthAccessToken,
|
1217
|
+
updateOAuthAccessToken
|
1218
|
+
},
|
658
1219
|
users: { getUser, updateUser, deleteUser },
|
659
1220
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
660
1221
|
workspaces: {
|
@@ -674,12 +1235,17 @@ const operationsByTag$1 = {
|
|
674
1235
|
acceptWorkspaceMemberInvite,
|
675
1236
|
resendWorkspaceMemberInvite
|
676
1237
|
},
|
1238
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
677
1239
|
databases: {
|
678
1240
|
getDatabaseList,
|
679
1241
|
createDatabase,
|
680
1242
|
deleteDatabase,
|
681
1243
|
getDatabaseMetadata,
|
682
1244
|
updateDatabaseMetadata,
|
1245
|
+
renameDatabase,
|
1246
|
+
getDatabaseGithubSettings,
|
1247
|
+
updateDatabaseGithubSettings,
|
1248
|
+
deleteDatabaseGithubSettings,
|
683
1249
|
listRegions
|
684
1250
|
}
|
685
1251
|
};
|
@@ -700,8 +1266,12 @@ const providers = {
|
|
700
1266
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
701
1267
|
},
|
702
1268
|
staging: {
|
703
|
-
main: "https://staging.
|
704
|
-
workspaces: "https://{workspaceId}.
|
1269
|
+
main: "https://api.staging-xata.dev",
|
1270
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1271
|
+
},
|
1272
|
+
dev: {
|
1273
|
+
main: "https://api.dev-xata.dev",
|
1274
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
705
1275
|
}
|
706
1276
|
};
|
707
1277
|
function isHostProviderAlias(alias) {
|
@@ -719,15 +1289,22 @@ function parseProviderString(provider = "production") {
|
|
719
1289
|
return null;
|
720
1290
|
return { main, workspaces };
|
721
1291
|
}
|
1292
|
+
function buildProviderString(provider) {
|
1293
|
+
if (isHostProviderAlias(provider))
|
1294
|
+
return provider;
|
1295
|
+
return `${provider.main},${provider.workspaces}`;
|
1296
|
+
}
|
722
1297
|
function parseWorkspacesUrlParts(url) {
|
723
1298
|
if (!isString(url))
|
724
1299
|
return null;
|
725
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
726
|
-
const
|
727
|
-
const
|
1300
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1301
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1302
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1303
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1304
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
728
1305
|
if (!match)
|
729
1306
|
return null;
|
730
|
-
return { workspace: match[1], region: match[2]
|
1307
|
+
return { workspace: match[1], region: match[2] };
|
731
1308
|
}
|
732
1309
|
|
733
1310
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -756,15 +1333,19 @@ class XataApiClient {
|
|
756
1333
|
const provider = options.host ?? "production";
|
757
1334
|
const apiKey = options.apiKey ?? getAPIKey();
|
758
1335
|
const trace = options.trace ?? defaultTrace;
|
1336
|
+
const clientID = generateUUID();
|
759
1337
|
if (!apiKey) {
|
760
1338
|
throw new Error("Could not resolve a valid apiKey");
|
761
1339
|
}
|
762
1340
|
__privateSet$7(this, _extraProps, {
|
763
1341
|
apiUrl: getHostUrl(provider, "main"),
|
764
1342
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
765
|
-
|
1343
|
+
fetch: getFetchImplementation(options.fetch),
|
766
1344
|
apiKey,
|
767
|
-
trace
|
1345
|
+
trace,
|
1346
|
+
clientName: options.clientName,
|
1347
|
+
xataAgentExtra: options.xataAgentExtra,
|
1348
|
+
clientID
|
768
1349
|
});
|
769
1350
|
}
|
770
1351
|
get user() {
|
@@ -817,6 +1398,11 @@ class XataApiClient {
|
|
817
1398
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
818
1399
|
return __privateGet$7(this, _namespaces).records;
|
819
1400
|
}
|
1401
|
+
get files() {
|
1402
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1403
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1404
|
+
return __privateGet$7(this, _namespaces).files;
|
1405
|
+
}
|
820
1406
|
get searchAndFilter() {
|
821
1407
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
822
1408
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1025,6 +1611,20 @@ class BranchApi {
|
|
1025
1611
|
...this.extraProps
|
1026
1612
|
});
|
1027
1613
|
}
|
1614
|
+
copyBranch({
|
1615
|
+
workspace,
|
1616
|
+
region,
|
1617
|
+
database,
|
1618
|
+
branch,
|
1619
|
+
destinationBranch,
|
1620
|
+
limit
|
1621
|
+
}) {
|
1622
|
+
return operationsByTag.branch.copyBranch({
|
1623
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1624
|
+
body: { destinationBranch, limit },
|
1625
|
+
...this.extraProps
|
1626
|
+
});
|
1627
|
+
}
|
1028
1628
|
updateBranchMetadata({
|
1029
1629
|
workspace,
|
1030
1630
|
region,
|
@@ -1366,6 +1966,177 @@ class RecordsApi {
|
|
1366
1966
|
...this.extraProps
|
1367
1967
|
});
|
1368
1968
|
}
|
1969
|
+
branchTransaction({
|
1970
|
+
workspace,
|
1971
|
+
region,
|
1972
|
+
database,
|
1973
|
+
branch,
|
1974
|
+
operations
|
1975
|
+
}) {
|
1976
|
+
return operationsByTag.records.branchTransaction({
|
1977
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1978
|
+
body: { operations },
|
1979
|
+
...this.extraProps
|
1980
|
+
});
|
1981
|
+
}
|
1982
|
+
}
|
1983
|
+
class FilesApi {
|
1984
|
+
constructor(extraProps) {
|
1985
|
+
this.extraProps = extraProps;
|
1986
|
+
}
|
1987
|
+
getFileItem({
|
1988
|
+
workspace,
|
1989
|
+
region,
|
1990
|
+
database,
|
1991
|
+
branch,
|
1992
|
+
table,
|
1993
|
+
record,
|
1994
|
+
column,
|
1995
|
+
fileId
|
1996
|
+
}) {
|
1997
|
+
return operationsByTag.files.getFileItem({
|
1998
|
+
pathParams: {
|
1999
|
+
workspace,
|
2000
|
+
region,
|
2001
|
+
dbBranchName: `${database}:${branch}`,
|
2002
|
+
tableName: table,
|
2003
|
+
recordId: record,
|
2004
|
+
columnName: column,
|
2005
|
+
fileId
|
2006
|
+
},
|
2007
|
+
...this.extraProps
|
2008
|
+
});
|
2009
|
+
}
|
2010
|
+
putFileItem({
|
2011
|
+
workspace,
|
2012
|
+
region,
|
2013
|
+
database,
|
2014
|
+
branch,
|
2015
|
+
table,
|
2016
|
+
record,
|
2017
|
+
column,
|
2018
|
+
fileId,
|
2019
|
+
file
|
2020
|
+
}) {
|
2021
|
+
return operationsByTag.files.putFileItem({
|
2022
|
+
pathParams: {
|
2023
|
+
workspace,
|
2024
|
+
region,
|
2025
|
+
dbBranchName: `${database}:${branch}`,
|
2026
|
+
tableName: table,
|
2027
|
+
recordId: record,
|
2028
|
+
columnName: column,
|
2029
|
+
fileId
|
2030
|
+
},
|
2031
|
+
// @ts-ignore
|
2032
|
+
body: file,
|
2033
|
+
...this.extraProps
|
2034
|
+
});
|
2035
|
+
}
|
2036
|
+
deleteFileItem({
|
2037
|
+
workspace,
|
2038
|
+
region,
|
2039
|
+
database,
|
2040
|
+
branch,
|
2041
|
+
table,
|
2042
|
+
record,
|
2043
|
+
column,
|
2044
|
+
fileId
|
2045
|
+
}) {
|
2046
|
+
return operationsByTag.files.deleteFileItem({
|
2047
|
+
pathParams: {
|
2048
|
+
workspace,
|
2049
|
+
region,
|
2050
|
+
dbBranchName: `${database}:${branch}`,
|
2051
|
+
tableName: table,
|
2052
|
+
recordId: record,
|
2053
|
+
columnName: column,
|
2054
|
+
fileId
|
2055
|
+
},
|
2056
|
+
...this.extraProps
|
2057
|
+
});
|
2058
|
+
}
|
2059
|
+
getFile({
|
2060
|
+
workspace,
|
2061
|
+
region,
|
2062
|
+
database,
|
2063
|
+
branch,
|
2064
|
+
table,
|
2065
|
+
record,
|
2066
|
+
column
|
2067
|
+
}) {
|
2068
|
+
return operationsByTag.files.getFile({
|
2069
|
+
pathParams: {
|
2070
|
+
workspace,
|
2071
|
+
region,
|
2072
|
+
dbBranchName: `${database}:${branch}`,
|
2073
|
+
tableName: table,
|
2074
|
+
recordId: record,
|
2075
|
+
columnName: column
|
2076
|
+
},
|
2077
|
+
...this.extraProps
|
2078
|
+
});
|
2079
|
+
}
|
2080
|
+
putFile({
|
2081
|
+
workspace,
|
2082
|
+
region,
|
2083
|
+
database,
|
2084
|
+
branch,
|
2085
|
+
table,
|
2086
|
+
record,
|
2087
|
+
column,
|
2088
|
+
file
|
2089
|
+
}) {
|
2090
|
+
return operationsByTag.files.putFile({
|
2091
|
+
pathParams: {
|
2092
|
+
workspace,
|
2093
|
+
region,
|
2094
|
+
dbBranchName: `${database}:${branch}`,
|
2095
|
+
tableName: table,
|
2096
|
+
recordId: record,
|
2097
|
+
columnName: column
|
2098
|
+
},
|
2099
|
+
body: file,
|
2100
|
+
...this.extraProps
|
2101
|
+
});
|
2102
|
+
}
|
2103
|
+
deleteFile({
|
2104
|
+
workspace,
|
2105
|
+
region,
|
2106
|
+
database,
|
2107
|
+
branch,
|
2108
|
+
table,
|
2109
|
+
record,
|
2110
|
+
column
|
2111
|
+
}) {
|
2112
|
+
return operationsByTag.files.deleteFile({
|
2113
|
+
pathParams: {
|
2114
|
+
workspace,
|
2115
|
+
region,
|
2116
|
+
dbBranchName: `${database}:${branch}`,
|
2117
|
+
tableName: table,
|
2118
|
+
recordId: record,
|
2119
|
+
columnName: column
|
2120
|
+
},
|
2121
|
+
...this.extraProps
|
2122
|
+
});
|
2123
|
+
}
|
2124
|
+
fileAccess({
|
2125
|
+
workspace,
|
2126
|
+
region,
|
2127
|
+
fileId,
|
2128
|
+
verify
|
2129
|
+
}) {
|
2130
|
+
return operationsByTag.files.fileAccess({
|
2131
|
+
pathParams: {
|
2132
|
+
workspace,
|
2133
|
+
region,
|
2134
|
+
fileId
|
2135
|
+
},
|
2136
|
+
queryParams: { verify },
|
2137
|
+
...this.extraProps
|
2138
|
+
});
|
2139
|
+
}
|
1369
2140
|
}
|
1370
2141
|
class SearchAndFilterApi {
|
1371
2142
|
constructor(extraProps) {
|
@@ -1426,6 +2197,53 @@ class SearchAndFilterApi {
|
|
1426
2197
|
...this.extraProps
|
1427
2198
|
});
|
1428
2199
|
}
|
2200
|
+
vectorSearchTable({
|
2201
|
+
workspace,
|
2202
|
+
region,
|
2203
|
+
database,
|
2204
|
+
branch,
|
2205
|
+
table,
|
2206
|
+
queryVector,
|
2207
|
+
column,
|
2208
|
+
similarityFunction,
|
2209
|
+
size,
|
2210
|
+
filter
|
2211
|
+
}) {
|
2212
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2213
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2214
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2215
|
+
...this.extraProps
|
2216
|
+
});
|
2217
|
+
}
|
2218
|
+
askTable({
|
2219
|
+
workspace,
|
2220
|
+
region,
|
2221
|
+
database,
|
2222
|
+
branch,
|
2223
|
+
table,
|
2224
|
+
options
|
2225
|
+
}) {
|
2226
|
+
return operationsByTag.searchAndFilter.askTable({
|
2227
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2228
|
+
body: { ...options },
|
2229
|
+
...this.extraProps
|
2230
|
+
});
|
2231
|
+
}
|
2232
|
+
askTableSession({
|
2233
|
+
workspace,
|
2234
|
+
region,
|
2235
|
+
database,
|
2236
|
+
branch,
|
2237
|
+
table,
|
2238
|
+
sessionId,
|
2239
|
+
message
|
2240
|
+
}) {
|
2241
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2242
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2243
|
+
body: { message },
|
2244
|
+
...this.extraProps
|
2245
|
+
});
|
2246
|
+
}
|
1429
2247
|
summarizeTable({
|
1430
2248
|
workspace,
|
1431
2249
|
region,
|
@@ -1626,11 +2444,13 @@ class MigrationsApi {
|
|
1626
2444
|
region,
|
1627
2445
|
database,
|
1628
2446
|
branch,
|
1629
|
-
schema
|
2447
|
+
schema,
|
2448
|
+
schemaOperations,
|
2449
|
+
branchOperations
|
1630
2450
|
}) {
|
1631
2451
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1632
2452
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1633
|
-
body: { schema },
|
2453
|
+
body: { schema, schemaOperations, branchOperations },
|
1634
2454
|
...this.extraProps
|
1635
2455
|
});
|
1636
2456
|
}
|
@@ -1640,11 +2460,12 @@ class MigrationsApi {
|
|
1640
2460
|
database,
|
1641
2461
|
branch,
|
1642
2462
|
compare,
|
1643
|
-
|
2463
|
+
sourceBranchOperations,
|
2464
|
+
targetBranchOperations
|
1644
2465
|
}) {
|
1645
2466
|
return operationsByTag.migrations.compareBranchSchemas({
|
1646
2467
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1647
|
-
body: {
|
2468
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1648
2469
|
...this.extraProps
|
1649
2470
|
});
|
1650
2471
|
}
|
@@ -1687,6 +2508,19 @@ class MigrationsApi {
|
|
1687
2508
|
...this.extraProps
|
1688
2509
|
});
|
1689
2510
|
}
|
2511
|
+
pushBranchMigrations({
|
2512
|
+
workspace,
|
2513
|
+
region,
|
2514
|
+
database,
|
2515
|
+
branch,
|
2516
|
+
migrations
|
2517
|
+
}) {
|
2518
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2519
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2520
|
+
body: { migrations },
|
2521
|
+
...this.extraProps
|
2522
|
+
});
|
2523
|
+
}
|
1690
2524
|
}
|
1691
2525
|
class DatabaseApi {
|
1692
2526
|
constructor(extraProps) {
|
@@ -1701,11 +2535,13 @@ class DatabaseApi {
|
|
1701
2535
|
createDatabase({
|
1702
2536
|
workspace,
|
1703
2537
|
database,
|
1704
|
-
data
|
2538
|
+
data,
|
2539
|
+
headers
|
1705
2540
|
}) {
|
1706
2541
|
return operationsByTag.databases.createDatabase({
|
1707
2542
|
pathParams: { workspaceId: workspace, dbName: database },
|
1708
2543
|
body: data,
|
2544
|
+
headers,
|
1709
2545
|
...this.extraProps
|
1710
2546
|
});
|
1711
2547
|
}
|
@@ -1738,6 +2574,46 @@ class DatabaseApi {
|
|
1738
2574
|
...this.extraProps
|
1739
2575
|
});
|
1740
2576
|
}
|
2577
|
+
renameDatabase({
|
2578
|
+
workspace,
|
2579
|
+
database,
|
2580
|
+
newName
|
2581
|
+
}) {
|
2582
|
+
return operationsByTag.databases.renameDatabase({
|
2583
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2584
|
+
body: { newName },
|
2585
|
+
...this.extraProps
|
2586
|
+
});
|
2587
|
+
}
|
2588
|
+
getDatabaseGithubSettings({
|
2589
|
+
workspace,
|
2590
|
+
database
|
2591
|
+
}) {
|
2592
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2593
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2594
|
+
...this.extraProps
|
2595
|
+
});
|
2596
|
+
}
|
2597
|
+
updateDatabaseGithubSettings({
|
2598
|
+
workspace,
|
2599
|
+
database,
|
2600
|
+
settings
|
2601
|
+
}) {
|
2602
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2603
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2604
|
+
body: settings,
|
2605
|
+
...this.extraProps
|
2606
|
+
});
|
2607
|
+
}
|
2608
|
+
deleteDatabaseGithubSettings({
|
2609
|
+
workspace,
|
2610
|
+
database
|
2611
|
+
}) {
|
2612
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2613
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2614
|
+
...this.extraProps
|
2615
|
+
});
|
2616
|
+
}
|
1741
2617
|
listRegions({ workspace }) {
|
1742
2618
|
return operationsByTag.databases.listRegions({
|
1743
2619
|
pathParams: { workspaceId: workspace },
|
@@ -1747,27 +2623,200 @@ class DatabaseApi {
|
|
1747
2623
|
}
|
1748
2624
|
|
1749
2625
|
class XataApiPlugin {
|
1750
|
-
|
1751
|
-
|
1752
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2626
|
+
build(options) {
|
2627
|
+
return new XataApiClient(options);
|
1753
2628
|
}
|
1754
2629
|
}
|
1755
2630
|
|
1756
2631
|
class XataPlugin {
|
1757
2632
|
}
|
1758
2633
|
|
1759
|
-
function
|
1760
|
-
return
|
1761
|
-
|
1762
|
-
|
2634
|
+
function buildTransformString(transformations) {
|
2635
|
+
return transformations.flatMap(
|
2636
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2637
|
+
if (key === "trim") {
|
2638
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2639
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2640
|
+
}
|
2641
|
+
if (key === "gravity" && typeof value === "object") {
|
2642
|
+
const { x = 0.5, y = 0.5 } = value;
|
2643
|
+
return `${key}=${[x, y].join("x")}`;
|
2644
|
+
}
|
2645
|
+
return `${key}=${value}`;
|
2646
|
+
})
|
2647
|
+
).join(",");
|
2648
|
+
}
|
2649
|
+
function transformImage(url, ...transformations) {
|
2650
|
+
if (!isDefined(url))
|
2651
|
+
return void 0;
|
2652
|
+
const newTransformations = buildTransformString(transformations);
|
2653
|
+
const { hostname, pathname, search } = new URL(url);
|
2654
|
+
const pathParts = pathname.split("/");
|
2655
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2656
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2657
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2658
|
+
const path = pathParts.join("/");
|
2659
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2660
|
+
}
|
2661
|
+
|
2662
|
+
class XataFile {
|
2663
|
+
constructor(file) {
|
2664
|
+
this.id = file.id;
|
2665
|
+
this.name = file.name || "";
|
2666
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
2667
|
+
this.base64Content = file.base64Content;
|
2668
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
2669
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
2670
|
+
this.size = file.size ?? 0;
|
2671
|
+
this.version = file.version ?? 1;
|
2672
|
+
this.url = file.url || "";
|
2673
|
+
this.signedUrl = file.signedUrl;
|
2674
|
+
this.attributes = file.attributes || {};
|
2675
|
+
}
|
2676
|
+
static fromBuffer(buffer, options = {}) {
|
2677
|
+
const base64Content = buffer.toString("base64");
|
2678
|
+
return new XataFile({ ...options, base64Content });
|
2679
|
+
}
|
2680
|
+
toBuffer() {
|
2681
|
+
if (!this.base64Content) {
|
2682
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2683
|
+
}
|
2684
|
+
return Buffer.from(this.base64Content, "base64");
|
2685
|
+
}
|
2686
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2687
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2688
|
+
return this.fromUint8Array(uint8Array, options);
|
2689
|
+
}
|
2690
|
+
toArrayBuffer() {
|
2691
|
+
if (!this.base64Content) {
|
2692
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2693
|
+
}
|
2694
|
+
const binary = atob(this.base64Content);
|
2695
|
+
return new ArrayBuffer(binary.length);
|
2696
|
+
}
|
2697
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2698
|
+
let binary = "";
|
2699
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2700
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2701
|
+
}
|
2702
|
+
const base64Content = btoa(binary);
|
2703
|
+
return new XataFile({ ...options, base64Content });
|
2704
|
+
}
|
2705
|
+
toUint8Array() {
|
2706
|
+
if (!this.base64Content) {
|
2707
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2708
|
+
}
|
2709
|
+
const binary = atob(this.base64Content);
|
2710
|
+
const uint8Array = new Uint8Array(binary.length);
|
2711
|
+
for (let i = 0; i < binary.length; i++) {
|
2712
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2713
|
+
}
|
2714
|
+
return uint8Array;
|
2715
|
+
}
|
2716
|
+
static async fromBlob(file, options = {}) {
|
2717
|
+
const name = options.name ?? file.name;
|
2718
|
+
const mediaType = file.type;
|
2719
|
+
const arrayBuffer = await file.arrayBuffer();
|
2720
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2721
|
+
}
|
2722
|
+
toBlob() {
|
2723
|
+
if (!this.base64Content) {
|
2724
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2725
|
+
}
|
2726
|
+
const binary = atob(this.base64Content);
|
2727
|
+
const uint8Array = new Uint8Array(binary.length);
|
2728
|
+
for (let i = 0; i < binary.length; i++) {
|
2729
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2730
|
+
}
|
2731
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2732
|
+
}
|
2733
|
+
static fromString(string, options = {}) {
|
2734
|
+
const base64Content = btoa(string);
|
2735
|
+
return new XataFile({ ...options, base64Content });
|
2736
|
+
}
|
2737
|
+
toString() {
|
2738
|
+
if (!this.base64Content) {
|
2739
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2740
|
+
}
|
2741
|
+
return atob(this.base64Content);
|
2742
|
+
}
|
2743
|
+
static fromBase64(base64Content, options = {}) {
|
2744
|
+
return new XataFile({ ...options, base64Content });
|
2745
|
+
}
|
2746
|
+
toBase64() {
|
2747
|
+
if (!this.base64Content) {
|
2748
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2749
|
+
}
|
2750
|
+
return this.base64Content;
|
2751
|
+
}
|
2752
|
+
transform(...options) {
|
2753
|
+
return {
|
2754
|
+
url: transformImage(this.url, ...options),
|
2755
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2756
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2757
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2758
|
+
};
|
2759
|
+
}
|
2760
|
+
}
|
2761
|
+
const parseInputFileEntry = async (entry) => {
|
2762
|
+
if (!isDefined(entry))
|
2763
|
+
return null;
|
2764
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
2765
|
+
return compactObject({
|
2766
|
+
id,
|
2767
|
+
// Name cannot be an empty string in our API
|
2768
|
+
name: name ? name : void 0,
|
2769
|
+
mediaType,
|
2770
|
+
base64Content,
|
2771
|
+
enablePublicUrl,
|
2772
|
+
signedUrlTimeout
|
1763
2773
|
});
|
1764
|
-
}
|
2774
|
+
};
|
1765
2775
|
|
1766
2776
|
function cleanFilter(filter) {
|
1767
|
-
if (!filter)
|
2777
|
+
if (!isDefined(filter))
|
1768
2778
|
return void 0;
|
1769
|
-
|
1770
|
-
|
2779
|
+
if (!isObject(filter))
|
2780
|
+
return filter;
|
2781
|
+
const values = Object.fromEntries(
|
2782
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2783
|
+
if (!isDefined(value))
|
2784
|
+
return acc;
|
2785
|
+
if (Array.isArray(value)) {
|
2786
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2787
|
+
if (clean.length === 0)
|
2788
|
+
return acc;
|
2789
|
+
return [...acc, [key, clean]];
|
2790
|
+
}
|
2791
|
+
if (isObject(value)) {
|
2792
|
+
const clean = cleanFilter(value);
|
2793
|
+
if (!isDefined(clean))
|
2794
|
+
return acc;
|
2795
|
+
return [...acc, [key, clean]];
|
2796
|
+
}
|
2797
|
+
return [...acc, [key, value]];
|
2798
|
+
}, [])
|
2799
|
+
);
|
2800
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
2801
|
+
}
|
2802
|
+
|
2803
|
+
function stringifyJson(value) {
|
2804
|
+
if (!isDefined(value))
|
2805
|
+
return value;
|
2806
|
+
if (isString(value))
|
2807
|
+
return value;
|
2808
|
+
try {
|
2809
|
+
return JSON.stringify(value);
|
2810
|
+
} catch (e) {
|
2811
|
+
return value;
|
2812
|
+
}
|
2813
|
+
}
|
2814
|
+
function parseJson(value) {
|
2815
|
+
try {
|
2816
|
+
return JSON.parse(value);
|
2817
|
+
} catch (e) {
|
2818
|
+
return value;
|
2819
|
+
}
|
1771
2820
|
}
|
1772
2821
|
|
1773
2822
|
var __accessCheck$6 = (obj, member, msg) => {
|
@@ -1796,31 +2845,59 @@ class Page {
|
|
1796
2845
|
this.meta = meta;
|
1797
2846
|
this.records = new RecordArray(this, records);
|
1798
2847
|
}
|
2848
|
+
/**
|
2849
|
+
* Retrieves the next page of results.
|
2850
|
+
* @param size Maximum number of results to be retrieved.
|
2851
|
+
* @param offset Number of results to skip when retrieving the results.
|
2852
|
+
* @returns The next page or results.
|
2853
|
+
*/
|
1799
2854
|
async nextPage(size, offset) {
|
1800
2855
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1801
2856
|
}
|
2857
|
+
/**
|
2858
|
+
* Retrieves the previous page of results.
|
2859
|
+
* @param size Maximum number of results to be retrieved.
|
2860
|
+
* @param offset Number of results to skip when retrieving the results.
|
2861
|
+
* @returns The previous page or results.
|
2862
|
+
*/
|
1802
2863
|
async previousPage(size, offset) {
|
1803
2864
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1804
2865
|
}
|
2866
|
+
/**
|
2867
|
+
* Retrieves the start page of results.
|
2868
|
+
* @param size Maximum number of results to be retrieved.
|
2869
|
+
* @param offset Number of results to skip when retrieving the results.
|
2870
|
+
* @returns The start page or results.
|
2871
|
+
*/
|
1805
2872
|
async startPage(size, offset) {
|
1806
2873
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1807
2874
|
}
|
2875
|
+
/**
|
2876
|
+
* Retrieves the end page of results.
|
2877
|
+
* @param size Maximum number of results to be retrieved.
|
2878
|
+
* @param offset Number of results to skip when retrieving the results.
|
2879
|
+
* @returns The end page or results.
|
2880
|
+
*/
|
1808
2881
|
async endPage(size, offset) {
|
1809
2882
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1810
2883
|
}
|
2884
|
+
/**
|
2885
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2886
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2887
|
+
*/
|
1811
2888
|
hasNextPage() {
|
1812
2889
|
return this.meta.page.more;
|
1813
2890
|
}
|
1814
2891
|
}
|
1815
2892
|
_query = new WeakMap();
|
1816
|
-
const PAGINATION_MAX_SIZE =
|
2893
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
1817
2894
|
const PAGINATION_DEFAULT_SIZE = 20;
|
1818
|
-
const PAGINATION_MAX_OFFSET =
|
2895
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
1819
2896
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1820
2897
|
function isCursorPaginationOptions(options) {
|
1821
2898
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1822
2899
|
}
|
1823
|
-
const _RecordArray = class extends Array {
|
2900
|
+
const _RecordArray = class _RecordArray extends Array {
|
1824
2901
|
constructor(...args) {
|
1825
2902
|
super(..._RecordArray.parseConstructorParams(...args));
|
1826
2903
|
__privateAdd$6(this, _page, void 0);
|
@@ -1839,31 +2916,60 @@ const _RecordArray = class extends Array {
|
|
1839
2916
|
toArray() {
|
1840
2917
|
return new Array(...this);
|
1841
2918
|
}
|
2919
|
+
toSerializable() {
|
2920
|
+
return JSON.parse(this.toString());
|
2921
|
+
}
|
2922
|
+
toString() {
|
2923
|
+
return JSON.stringify(this.toArray());
|
2924
|
+
}
|
1842
2925
|
map(callbackfn, thisArg) {
|
1843
2926
|
return this.toArray().map(callbackfn, thisArg);
|
1844
2927
|
}
|
2928
|
+
/**
|
2929
|
+
* Retrieve next page of records
|
2930
|
+
*
|
2931
|
+
* @returns A new array of objects
|
2932
|
+
*/
|
1845
2933
|
async nextPage(size, offset) {
|
1846
2934
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1847
2935
|
return new _RecordArray(newPage);
|
1848
2936
|
}
|
2937
|
+
/**
|
2938
|
+
* Retrieve previous page of records
|
2939
|
+
*
|
2940
|
+
* @returns A new array of objects
|
2941
|
+
*/
|
1849
2942
|
async previousPage(size, offset) {
|
1850
2943
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1851
2944
|
return new _RecordArray(newPage);
|
1852
2945
|
}
|
2946
|
+
/**
|
2947
|
+
* Retrieve start page of records
|
2948
|
+
*
|
2949
|
+
* @returns A new array of objects
|
2950
|
+
*/
|
1853
2951
|
async startPage(size, offset) {
|
1854
2952
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1855
2953
|
return new _RecordArray(newPage);
|
1856
2954
|
}
|
2955
|
+
/**
|
2956
|
+
* Retrieve end page of records
|
2957
|
+
*
|
2958
|
+
* @returns A new array of objects
|
2959
|
+
*/
|
1857
2960
|
async endPage(size, offset) {
|
1858
2961
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1859
2962
|
return new _RecordArray(newPage);
|
1860
2963
|
}
|
2964
|
+
/**
|
2965
|
+
* @returns Boolean indicating if there is a next page
|
2966
|
+
*/
|
1861
2967
|
hasNextPage() {
|
1862
2968
|
return __privateGet$6(this, _page).meta.page.more;
|
1863
2969
|
}
|
1864
2970
|
};
|
1865
|
-
let RecordArray = _RecordArray;
|
1866
2971
|
_page = new WeakMap();
|
2972
|
+
let RecordArray = _RecordArray;
|
1867
2973
|
|
1868
2974
|
var __accessCheck$5 = (obj, member, msg) => {
|
1869
2975
|
if (!member.has(obj))
|
@@ -1888,13 +2994,14 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
1888
2994
|
return method;
|
1889
2995
|
};
|
1890
2996
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1891
|
-
const _Query = class {
|
2997
|
+
const _Query = class _Query {
|
1892
2998
|
constructor(repository, table, data, rawParent) {
|
1893
2999
|
__privateAdd$5(this, _cleanFilterConstraint);
|
1894
3000
|
__privateAdd$5(this, _table$1, void 0);
|
1895
3001
|
__privateAdd$5(this, _repository, void 0);
|
1896
3002
|
__privateAdd$5(this, _data, { filter: {} });
|
1897
|
-
|
3003
|
+
// Implements pagination
|
3004
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1898
3005
|
this.records = new RecordArray(this, []);
|
1899
3006
|
__privateSet$5(this, _table$1, table);
|
1900
3007
|
if (repository) {
|
@@ -1910,6 +3017,7 @@ const _Query = class {
|
|
1910
3017
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1911
3018
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1912
3019
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
3020
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1913
3021
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1914
3022
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
1915
3023
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
@@ -1930,18 +3038,38 @@ const _Query = class {
|
|
1930
3038
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1931
3039
|
return toBase64(key);
|
1932
3040
|
}
|
3041
|
+
/**
|
3042
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3043
|
+
* @param queries An array of subqueries.
|
3044
|
+
* @returns A new Query object.
|
3045
|
+
*/
|
1933
3046
|
any(...queries) {
|
1934
3047
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1935
3048
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
1936
3049
|
}
|
3050
|
+
/**
|
3051
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3052
|
+
* @param queries An array of subqueries.
|
3053
|
+
* @returns A new Query object.
|
3054
|
+
*/
|
1937
3055
|
all(...queries) {
|
1938
3056
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1939
3057
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1940
3058
|
}
|
3059
|
+
/**
|
3060
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3061
|
+
* @param queries An array of subqueries.
|
3062
|
+
* @returns A new Query object.
|
3063
|
+
*/
|
1941
3064
|
not(...queries) {
|
1942
3065
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1943
3066
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
1944
3067
|
}
|
3068
|
+
/**
|
3069
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3070
|
+
* @param queries An array of subqueries.
|
3071
|
+
* @returns A new Query object.
|
3072
|
+
*/
|
1945
3073
|
none(...queries) {
|
1946
3074
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1947
3075
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -1964,6 +3092,11 @@ const _Query = class {
|
|
1964
3092
|
const sort = [...originalSort, { column, direction }];
|
1965
3093
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1966
3094
|
}
|
3095
|
+
/**
|
3096
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3097
|
+
* @param columns Array of column names to be returned by the query.
|
3098
|
+
* @returns A new Query object.
|
3099
|
+
*/
|
1967
3100
|
select(columns) {
|
1968
3101
|
return new _Query(
|
1969
3102
|
__privateGet$5(this, _repository),
|
@@ -1976,6 +3109,12 @@ const _Query = class {
|
|
1976
3109
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1977
3110
|
return __privateGet$5(this, _repository).query(query);
|
1978
3111
|
}
|
3112
|
+
/**
|
3113
|
+
* Get results in an iterator
|
3114
|
+
*
|
3115
|
+
* @async
|
3116
|
+
* @returns Async interable of results
|
3117
|
+
*/
|
1979
3118
|
async *[Symbol.asyncIterator]() {
|
1980
3119
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1981
3120
|
yield record;
|
@@ -2036,26 +3175,53 @@ const _Query = class {
|
|
2036
3175
|
);
|
2037
3176
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2038
3177
|
}
|
3178
|
+
/**
|
3179
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3180
|
+
* @param ttl The cache TTL in milliseconds.
|
3181
|
+
* @returns A new Query object.
|
3182
|
+
*/
|
2039
3183
|
cache(ttl) {
|
2040
3184
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2041
3185
|
}
|
3186
|
+
/**
|
3187
|
+
* Retrieve next page of records
|
3188
|
+
*
|
3189
|
+
* @returns A new page object.
|
3190
|
+
*/
|
2042
3191
|
nextPage(size, offset) {
|
2043
3192
|
return this.startPage(size, offset);
|
2044
3193
|
}
|
3194
|
+
/**
|
3195
|
+
* Retrieve previous page of records
|
3196
|
+
*
|
3197
|
+
* @returns A new page object
|
3198
|
+
*/
|
2045
3199
|
previousPage(size, offset) {
|
2046
3200
|
return this.startPage(size, offset);
|
2047
3201
|
}
|
3202
|
+
/**
|
3203
|
+
* Retrieve start page of records
|
3204
|
+
*
|
3205
|
+
* @returns A new page object
|
3206
|
+
*/
|
2048
3207
|
startPage(size, offset) {
|
2049
3208
|
return this.getPaginated({ pagination: { size, offset } });
|
2050
3209
|
}
|
3210
|
+
/**
|
3211
|
+
* Retrieve last page of records
|
3212
|
+
*
|
3213
|
+
* @returns A new page object
|
3214
|
+
*/
|
2051
3215
|
endPage(size, offset) {
|
2052
3216
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2053
3217
|
}
|
3218
|
+
/**
|
3219
|
+
* @returns Boolean indicating if there is a next page
|
3220
|
+
*/
|
2054
3221
|
hasNextPage() {
|
2055
3222
|
return this.meta.page.more;
|
2056
3223
|
}
|
2057
3224
|
};
|
2058
|
-
let Query = _Query;
|
2059
3225
|
_table$1 = new WeakMap();
|
2060
3226
|
_repository = new WeakMap();
|
2061
3227
|
_data = new WeakMap();
|
@@ -2070,6 +3236,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2070
3236
|
}
|
2071
3237
|
return value;
|
2072
3238
|
};
|
3239
|
+
let Query = _Query;
|
2073
3240
|
function cleanParent(data, parent) {
|
2074
3241
|
if (isCursorPaginationOptions(data.pagination)) {
|
2075
3242
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2077,6 +3244,22 @@ function cleanParent(data, parent) {
|
|
2077
3244
|
return parent;
|
2078
3245
|
}
|
2079
3246
|
|
3247
|
+
const RecordColumnTypes = [
|
3248
|
+
"bool",
|
3249
|
+
"int",
|
3250
|
+
"float",
|
3251
|
+
"string",
|
3252
|
+
"text",
|
3253
|
+
"email",
|
3254
|
+
"multiple",
|
3255
|
+
"link",
|
3256
|
+
"object",
|
3257
|
+
"datetime",
|
3258
|
+
"vector",
|
3259
|
+
"file[]",
|
3260
|
+
"file",
|
3261
|
+
"json"
|
3262
|
+
];
|
2080
3263
|
function isIdentifiable(x) {
|
2081
3264
|
return isObject(x) && isString(x?.id);
|
2082
3265
|
}
|
@@ -2086,11 +3269,33 @@ function isXataRecord(x) {
|
|
2086
3269
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2087
3270
|
}
|
2088
3271
|
|
3272
|
+
function isValidExpandedColumn(column) {
|
3273
|
+
return isObject(column) && isString(column.name);
|
3274
|
+
}
|
3275
|
+
function isValidSelectableColumns(columns) {
|
3276
|
+
if (!Array.isArray(columns)) {
|
3277
|
+
return false;
|
3278
|
+
}
|
3279
|
+
return columns.every((column) => {
|
3280
|
+
if (typeof column === "string") {
|
3281
|
+
return true;
|
3282
|
+
}
|
3283
|
+
if (typeof column === "object") {
|
3284
|
+
return isValidExpandedColumn(column);
|
3285
|
+
}
|
3286
|
+
return false;
|
3287
|
+
});
|
3288
|
+
}
|
3289
|
+
|
2089
3290
|
function isSortFilterString(value) {
|
2090
3291
|
return isString(value);
|
2091
3292
|
}
|
2092
3293
|
function isSortFilterBase(filter) {
|
2093
|
-
return isObject(filter) && Object.
|
3294
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3295
|
+
if (key === "*")
|
3296
|
+
return value === "random";
|
3297
|
+
return value === "asc" || value === "desc";
|
3298
|
+
});
|
2094
3299
|
}
|
2095
3300
|
function isSortFilterObject(filter) {
|
2096
3301
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2131,7 +3336,8 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2131
3336
|
__accessCheck$4(obj, member, "access private method");
|
2132
3337
|
return method;
|
2133
3338
|
};
|
2134
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
3339
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1, _transformObjectToApi, transformObjectToApi_fn;
|
3340
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2135
3341
|
class Repository extends Query {
|
2136
3342
|
}
|
2137
3343
|
class RestRepository extends Query {
|
@@ -2143,13 +3349,16 @@ class RestRepository extends Query {
|
|
2143
3349
|
);
|
2144
3350
|
__privateAdd$4(this, _insertRecordWithoutId);
|
2145
3351
|
__privateAdd$4(this, _insertRecordWithId);
|
2146
|
-
__privateAdd$4(this,
|
3352
|
+
__privateAdd$4(this, _insertRecords);
|
2147
3353
|
__privateAdd$4(this, _updateRecordWithID);
|
3354
|
+
__privateAdd$4(this, _updateRecords);
|
2148
3355
|
__privateAdd$4(this, _upsertRecordWithID);
|
2149
3356
|
__privateAdd$4(this, _deleteRecord);
|
3357
|
+
__privateAdd$4(this, _deleteRecords);
|
2150
3358
|
__privateAdd$4(this, _setCacheQuery);
|
2151
3359
|
__privateAdd$4(this, _getCacheQuery);
|
2152
3360
|
__privateAdd$4(this, _getSchemaTables$1);
|
3361
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2153
3362
|
__privateAdd$4(this, _table, void 0);
|
2154
3363
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2155
3364
|
__privateAdd$4(this, _db, void 0);
|
@@ -2160,10 +3369,7 @@ class RestRepository extends Query {
|
|
2160
3369
|
__privateSet$4(this, _db, options.db);
|
2161
3370
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2162
3371
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2163
|
-
__privateSet$4(this, _getFetchProps,
|
2164
|
-
const props = await options.pluginOptions.getFetchProps();
|
2165
|
-
return { ...props, sessionID: generateUUID() };
|
2166
|
-
});
|
3372
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2167
3373
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2168
3374
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2169
3375
|
return trace(name, fn, {
|
@@ -2180,23 +3386,25 @@ class RestRepository extends Query {
|
|
2180
3386
|
if (Array.isArray(a)) {
|
2181
3387
|
if (a.length === 0)
|
2182
3388
|
return [];
|
2183
|
-
const
|
2184
|
-
|
3389
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3390
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3391
|
+
const result = await this.read(ids, columns);
|
3392
|
+
return result;
|
2185
3393
|
}
|
2186
3394
|
if (isString(a) && isObject(b)) {
|
2187
3395
|
if (a === "")
|
2188
3396
|
throw new Error("The id can't be empty");
|
2189
|
-
const columns =
|
2190
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3397
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3398
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2191
3399
|
}
|
2192
3400
|
if (isObject(a) && isString(a.id)) {
|
2193
3401
|
if (a.id === "")
|
2194
3402
|
throw new Error("The id can't be empty");
|
2195
|
-
const columns =
|
2196
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3403
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3404
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2197
3405
|
}
|
2198
3406
|
if (isObject(a)) {
|
2199
|
-
const columns =
|
3407
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2200
3408
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2201
3409
|
}
|
2202
3410
|
throw new Error("Invalid arguments for create method");
|
@@ -2204,7 +3412,7 @@ class RestRepository extends Query {
|
|
2204
3412
|
}
|
2205
3413
|
async read(a, b) {
|
2206
3414
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2207
|
-
const columns =
|
3415
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2208
3416
|
if (Array.isArray(a)) {
|
2209
3417
|
if (a.length === 0)
|
2210
3418
|
return [];
|
@@ -2218,7 +3426,6 @@ class RestRepository extends Query {
|
|
2218
3426
|
}
|
2219
3427
|
const id = extractId(a);
|
2220
3428
|
if (id) {
|
2221
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2222
3429
|
try {
|
2223
3430
|
const response = await getRecord({
|
2224
3431
|
pathParams: {
|
@@ -2229,10 +3436,16 @@ class RestRepository extends Query {
|
|
2229
3436
|
recordId: id
|
2230
3437
|
},
|
2231
3438
|
queryParams: { columns },
|
2232
|
-
...
|
3439
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2233
3440
|
});
|
2234
3441
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2235
|
-
return initObject(
|
3442
|
+
return initObject(
|
3443
|
+
__privateGet$4(this, _db),
|
3444
|
+
schemaTables,
|
3445
|
+
__privateGet$4(this, _table),
|
3446
|
+
response,
|
3447
|
+
columns
|
3448
|
+
);
|
2236
3449
|
} catch (e) {
|
2237
3450
|
if (isObject(e) && e.status === 404) {
|
2238
3451
|
return null;
|
@@ -2268,19 +3481,29 @@ class RestRepository extends Query {
|
|
2268
3481
|
if (Array.isArray(a)) {
|
2269
3482
|
if (a.length === 0)
|
2270
3483
|
return [];
|
2271
|
-
|
2272
|
-
|
2273
|
-
|
2274
|
-
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
const
|
2279
|
-
return
|
3484
|
+
const existing = await this.read(a, ["id"]);
|
3485
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
3486
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
3487
|
+
ifVersion,
|
3488
|
+
upsert: false
|
3489
|
+
});
|
3490
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3491
|
+
const result = await this.read(a, columns);
|
3492
|
+
return result;
|
2280
3493
|
}
|
2281
|
-
|
2282
|
-
|
2283
|
-
|
3494
|
+
try {
|
3495
|
+
if (isString(a) && isObject(b)) {
|
3496
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3497
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3498
|
+
}
|
3499
|
+
if (isObject(a) && isString(a.id)) {
|
3500
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
3501
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3502
|
+
}
|
3503
|
+
} catch (error) {
|
3504
|
+
if (error.status === 422)
|
3505
|
+
return null;
|
3506
|
+
throw error;
|
2284
3507
|
}
|
2285
3508
|
throw new Error("Invalid arguments for update method");
|
2286
3509
|
});
|
@@ -2310,19 +3533,31 @@ class RestRepository extends Query {
|
|
2310
3533
|
if (Array.isArray(a)) {
|
2311
3534
|
if (a.length === 0)
|
2312
3535
|
return [];
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
|
3536
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
3537
|
+
ifVersion,
|
3538
|
+
upsert: true
|
3539
|
+
});
|
3540
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3541
|
+
const result = await this.read(a, columns);
|
3542
|
+
return result;
|
2318
3543
|
}
|
2319
3544
|
if (isString(a) && isObject(b)) {
|
2320
|
-
|
2321
|
-
|
3545
|
+
if (a === "")
|
3546
|
+
throw new Error("The id can't be empty");
|
3547
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3548
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2322
3549
|
}
|
2323
3550
|
if (isObject(a) && isString(a.id)) {
|
2324
|
-
|
2325
|
-
|
3551
|
+
if (a.id === "")
|
3552
|
+
throw new Error("The id can't be empty");
|
3553
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3554
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3555
|
+
}
|
3556
|
+
if (!isDefined(a) && isObject(b)) {
|
3557
|
+
return await this.create(b, c);
|
3558
|
+
}
|
3559
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3560
|
+
return await this.create(a, b);
|
2326
3561
|
}
|
2327
3562
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2328
3563
|
});
|
@@ -2333,16 +3568,28 @@ class RestRepository extends Query {
|
|
2333
3568
|
if (Array.isArray(a)) {
|
2334
3569
|
if (a.length === 0)
|
2335
3570
|
return [];
|
2336
|
-
const
|
2337
|
-
|
3571
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
3572
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3573
|
+
const result = await this.read(ids, columns);
|
3574
|
+
return result;
|
2338
3575
|
}
|
2339
3576
|
if (isString(a) && isObject(b)) {
|
2340
|
-
|
2341
|
-
|
3577
|
+
if (a === "")
|
3578
|
+
throw new Error("The id can't be empty");
|
3579
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3580
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2342
3581
|
}
|
2343
3582
|
if (isObject(a) && isString(a.id)) {
|
2344
|
-
|
2345
|
-
|
3583
|
+
if (a.id === "")
|
3584
|
+
throw new Error("The id can't be empty");
|
3585
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3586
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3587
|
+
}
|
3588
|
+
if (!isDefined(a) && isObject(b)) {
|
3589
|
+
return await this.create(b, c);
|
3590
|
+
}
|
3591
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3592
|
+
return await this.create(a, b);
|
2346
3593
|
}
|
2347
3594
|
throw new Error("Invalid arguments for createOrReplace method");
|
2348
3595
|
});
|
@@ -2352,10 +3599,17 @@ class RestRepository extends Query {
|
|
2352
3599
|
if (Array.isArray(a)) {
|
2353
3600
|
if (a.length === 0)
|
2354
3601
|
return [];
|
2355
|
-
|
2356
|
-
|
2357
|
-
|
2358
|
-
|
3602
|
+
const ids = a.map((o) => {
|
3603
|
+
if (isString(o))
|
3604
|
+
return o;
|
3605
|
+
if (isString(o.id))
|
3606
|
+
return o.id;
|
3607
|
+
throw new Error("Invalid arguments for delete method");
|
3608
|
+
});
|
3609
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
3610
|
+
const result = await this.read(a, columns);
|
3611
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3612
|
+
return result;
|
2359
3613
|
}
|
2360
3614
|
if (isString(a)) {
|
2361
3615
|
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
@@ -2386,8 +3640,7 @@ class RestRepository extends Query {
|
|
2386
3640
|
}
|
2387
3641
|
async search(query, options = {}) {
|
2388
3642
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2389
|
-
const
|
2390
|
-
const { records } = await searchTable({
|
3643
|
+
const { records, totalCount } = await searchTable({
|
2391
3644
|
pathParams: {
|
2392
3645
|
workspace: "{workspaceId}",
|
2393
3646
|
dbBranchName: "{dbBranch}",
|
@@ -2400,17 +3653,46 @@ class RestRepository extends Query {
|
|
2400
3653
|
prefix: options.prefix,
|
2401
3654
|
highlight: options.highlight,
|
2402
3655
|
filter: options.filter,
|
2403
|
-
boosters: options.boosters
|
3656
|
+
boosters: options.boosters,
|
3657
|
+
page: options.page,
|
3658
|
+
target: options.target
|
3659
|
+
},
|
3660
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3661
|
+
});
|
3662
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3663
|
+
return {
|
3664
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3665
|
+
totalCount
|
3666
|
+
};
|
3667
|
+
});
|
3668
|
+
}
|
3669
|
+
async vectorSearch(column, query, options) {
|
3670
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3671
|
+
const { records, totalCount } = await vectorSearchTable({
|
3672
|
+
pathParams: {
|
3673
|
+
workspace: "{workspaceId}",
|
3674
|
+
dbBranchName: "{dbBranch}",
|
3675
|
+
region: "{region}",
|
3676
|
+
tableName: __privateGet$4(this, _table)
|
2404
3677
|
},
|
2405
|
-
|
3678
|
+
body: {
|
3679
|
+
column,
|
3680
|
+
queryVector: query,
|
3681
|
+
similarityFunction: options?.similarityFunction,
|
3682
|
+
size: options?.size,
|
3683
|
+
filter: options?.filter
|
3684
|
+
},
|
3685
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2406
3686
|
});
|
2407
3687
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2408
|
-
return
|
3688
|
+
return {
|
3689
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3690
|
+
totalCount
|
3691
|
+
};
|
2409
3692
|
});
|
2410
3693
|
}
|
2411
3694
|
async aggregate(aggs, filter) {
|
2412
3695
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2413
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2414
3696
|
const result = await aggregateTable({
|
2415
3697
|
pathParams: {
|
2416
3698
|
workspace: "{workspaceId}",
|
@@ -2419,7 +3701,7 @@ class RestRepository extends Query {
|
|
2419
3701
|
tableName: __privateGet$4(this, _table)
|
2420
3702
|
},
|
2421
3703
|
body: { aggs, filter },
|
2422
|
-
...
|
3704
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2423
3705
|
});
|
2424
3706
|
return result;
|
2425
3707
|
});
|
@@ -2430,7 +3712,6 @@ class RestRepository extends Query {
|
|
2430
3712
|
if (cacheQuery)
|
2431
3713
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2432
3714
|
const data = query.getQueryOptions();
|
2433
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2434
3715
|
const { meta, records: objects } = await queryTable({
|
2435
3716
|
pathParams: {
|
2436
3717
|
workspace: "{workspaceId}",
|
@@ -2442,14 +3723,21 @@ class RestRepository extends Query {
|
|
2442
3723
|
filter: cleanFilter(data.filter),
|
2443
3724
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2444
3725
|
page: data.pagination,
|
2445
|
-
columns: data.columns ?? ["*"]
|
3726
|
+
columns: data.columns ?? ["*"],
|
3727
|
+
consistency: data.consistency
|
2446
3728
|
},
|
2447
3729
|
fetchOptions: data.fetchOptions,
|
2448
|
-
...
|
3730
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2449
3731
|
});
|
2450
3732
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2451
3733
|
const records = objects.map(
|
2452
|
-
(record) => initObject(
|
3734
|
+
(record) => initObject(
|
3735
|
+
__privateGet$4(this, _db),
|
3736
|
+
schemaTables,
|
3737
|
+
__privateGet$4(this, _table),
|
3738
|
+
record,
|
3739
|
+
data.columns ?? ["*"]
|
3740
|
+
)
|
2453
3741
|
);
|
2454
3742
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2455
3743
|
return new Page(query, meta, records);
|
@@ -2458,7 +3746,6 @@ class RestRepository extends Query {
|
|
2458
3746
|
async summarizeTable(query, summaries, summariesFilter) {
|
2459
3747
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2460
3748
|
const data = query.getQueryOptions();
|
2461
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2462
3749
|
const result = await summarizeTable({
|
2463
3750
|
pathParams: {
|
2464
3751
|
workspace: "{workspaceId}",
|
@@ -2470,15 +3757,55 @@ class RestRepository extends Query {
|
|
2470
3757
|
filter: cleanFilter(data.filter),
|
2471
3758
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2472
3759
|
columns: data.columns,
|
3760
|
+
consistency: data.consistency,
|
2473
3761
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2474
3762
|
summaries,
|
2475
3763
|
summariesFilter
|
2476
3764
|
},
|
2477
|
-
...
|
3765
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2478
3766
|
});
|
2479
|
-
|
3767
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3768
|
+
return {
|
3769
|
+
...result,
|
3770
|
+
summaries: result.summaries.map(
|
3771
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3772
|
+
)
|
3773
|
+
};
|
2480
3774
|
});
|
2481
3775
|
}
|
3776
|
+
ask(question, options) {
|
3777
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3778
|
+
const params = {
|
3779
|
+
pathParams: {
|
3780
|
+
workspace: "{workspaceId}",
|
3781
|
+
dbBranchName: "{dbBranch}",
|
3782
|
+
region: "{region}",
|
3783
|
+
tableName: __privateGet$4(this, _table),
|
3784
|
+
sessionId: options?.sessionId
|
3785
|
+
},
|
3786
|
+
body: {
|
3787
|
+
...questionParam,
|
3788
|
+
rules: options?.rules,
|
3789
|
+
searchType: options?.searchType,
|
3790
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3791
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3792
|
+
},
|
3793
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3794
|
+
};
|
3795
|
+
if (options?.onMessage) {
|
3796
|
+
fetchSSERequest({
|
3797
|
+
endpoint: "dataPlane",
|
3798
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3799
|
+
method: "POST",
|
3800
|
+
onMessage: (message) => {
|
3801
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3802
|
+
},
|
3803
|
+
...params
|
3804
|
+
});
|
3805
|
+
} else {
|
3806
|
+
return askTableSession(params);
|
3807
|
+
}
|
3808
|
+
}
|
2482
3809
|
}
|
2483
3810
|
_table = new WeakMap();
|
2484
3811
|
_getFetchProps = new WeakMap();
|
@@ -2488,8 +3815,7 @@ _schemaTables$2 = new WeakMap();
|
|
2488
3815
|
_trace = new WeakMap();
|
2489
3816
|
_insertRecordWithoutId = new WeakSet();
|
2490
3817
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2491
|
-
const
|
2492
|
-
const record = transformObjectLinks(object);
|
3818
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2493
3819
|
const response = await insertRecord({
|
2494
3820
|
pathParams: {
|
2495
3821
|
workspace: "{workspaceId}",
|
@@ -2499,15 +3825,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2499
3825
|
},
|
2500
3826
|
queryParams: { columns },
|
2501
3827
|
body: record,
|
2502
|
-
...
|
3828
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2503
3829
|
});
|
2504
3830
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2505
3831
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2506
3832
|
};
|
2507
3833
|
_insertRecordWithId = new WeakSet();
|
2508
3834
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2509
|
-
|
2510
|
-
|
3835
|
+
if (!recordId)
|
3836
|
+
return null;
|
3837
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2511
3838
|
const response = await insertRecordWithID({
|
2512
3839
|
pathParams: {
|
2513
3840
|
workspace: "{workspaceId}",
|
@@ -2518,36 +3845,44 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2518
3845
|
},
|
2519
3846
|
body: record,
|
2520
3847
|
queryParams: { createOnly, columns, ifVersion },
|
2521
|
-
...
|
3848
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2522
3849
|
});
|
2523
3850
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2524
3851
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2525
3852
|
};
|
2526
|
-
|
2527
|
-
|
2528
|
-
const
|
2529
|
-
|
2530
|
-
|
2531
|
-
pathParams: {
|
2532
|
-
workspace: "{workspaceId}",
|
2533
|
-
dbBranchName: "{dbBranch}",
|
2534
|
-
region: "{region}",
|
2535
|
-
tableName: __privateGet$4(this, _table)
|
2536
|
-
},
|
2537
|
-
queryParams: { columns },
|
2538
|
-
body: { records },
|
2539
|
-
...fetchProps
|
3853
|
+
_insertRecords = new WeakSet();
|
3854
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3855
|
+
const operations = await promiseMap(objects, async (object) => {
|
3856
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3857
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
2540
3858
|
});
|
2541
|
-
|
2542
|
-
|
3859
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3860
|
+
const ids = [];
|
3861
|
+
for (const operations2 of chunkedOperations) {
|
3862
|
+
const { results } = await branchTransaction({
|
3863
|
+
pathParams: {
|
3864
|
+
workspace: "{workspaceId}",
|
3865
|
+
dbBranchName: "{dbBranch}",
|
3866
|
+
region: "{region}"
|
3867
|
+
},
|
3868
|
+
body: { operations: operations2 },
|
3869
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3870
|
+
});
|
3871
|
+
for (const result of results) {
|
3872
|
+
if (result.operation === "insert") {
|
3873
|
+
ids.push(result.id);
|
3874
|
+
} else {
|
3875
|
+
ids.push(null);
|
3876
|
+
}
|
3877
|
+
}
|
2543
3878
|
}
|
2544
|
-
|
2545
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
3879
|
+
return ids;
|
2546
3880
|
};
|
2547
3881
|
_updateRecordWithID = new WeakSet();
|
2548
3882
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2549
|
-
|
2550
|
-
|
3883
|
+
if (!recordId)
|
3884
|
+
return null;
|
3885
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2551
3886
|
try {
|
2552
3887
|
const response = await updateRecordWithID({
|
2553
3888
|
pathParams: {
|
@@ -2559,7 +3894,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2559
3894
|
},
|
2560
3895
|
queryParams: { columns, ifVersion },
|
2561
3896
|
body: record,
|
2562
|
-
...
|
3897
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2563
3898
|
});
|
2564
3899
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2565
3900
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2570,9 +3905,38 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2570
3905
|
throw e;
|
2571
3906
|
}
|
2572
3907
|
};
|
3908
|
+
_updateRecords = new WeakSet();
|
3909
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3910
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3911
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3912
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3913
|
+
});
|
3914
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
3915
|
+
const ids = [];
|
3916
|
+
for (const operations2 of chunkedOperations) {
|
3917
|
+
const { results } = await branchTransaction({
|
3918
|
+
pathParams: {
|
3919
|
+
workspace: "{workspaceId}",
|
3920
|
+
dbBranchName: "{dbBranch}",
|
3921
|
+
region: "{region}"
|
3922
|
+
},
|
3923
|
+
body: { operations: operations2 },
|
3924
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3925
|
+
});
|
3926
|
+
for (const result of results) {
|
3927
|
+
if (result.operation === "update") {
|
3928
|
+
ids.push(result.id);
|
3929
|
+
} else {
|
3930
|
+
ids.push(null);
|
3931
|
+
}
|
3932
|
+
}
|
3933
|
+
}
|
3934
|
+
return ids;
|
3935
|
+
};
|
2573
3936
|
_upsertRecordWithID = new WeakSet();
|
2574
3937
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2575
|
-
|
3938
|
+
if (!recordId)
|
3939
|
+
return null;
|
2576
3940
|
const response = await upsertRecordWithID({
|
2577
3941
|
pathParams: {
|
2578
3942
|
workspace: "{workspaceId}",
|
@@ -2583,14 +3947,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2583
3947
|
},
|
2584
3948
|
queryParams: { columns, ifVersion },
|
2585
3949
|
body: object,
|
2586
|
-
...
|
3950
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2587
3951
|
});
|
2588
3952
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2589
3953
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2590
3954
|
};
|
2591
3955
|
_deleteRecord = new WeakSet();
|
2592
3956
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2593
|
-
|
3957
|
+
if (!recordId)
|
3958
|
+
return null;
|
2594
3959
|
try {
|
2595
3960
|
const response = await deleteRecord({
|
2596
3961
|
pathParams: {
|
@@ -2601,7 +3966,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2601
3966
|
recordId
|
2602
3967
|
},
|
2603
3968
|
queryParams: { columns },
|
2604
|
-
...
|
3969
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2605
3970
|
});
|
2606
3971
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2607
3972
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2612,17 +3977,36 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2612
3977
|
throw e;
|
2613
3978
|
}
|
2614
3979
|
};
|
3980
|
+
_deleteRecords = new WeakSet();
|
3981
|
+
deleteRecords_fn = async function(recordIds) {
|
3982
|
+
const chunkedOperations = chunk(
|
3983
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3984
|
+
BULK_OPERATION_MAX_SIZE
|
3985
|
+
);
|
3986
|
+
for (const operations of chunkedOperations) {
|
3987
|
+
await branchTransaction({
|
3988
|
+
pathParams: {
|
3989
|
+
workspace: "{workspaceId}",
|
3990
|
+
dbBranchName: "{dbBranch}",
|
3991
|
+
region: "{region}"
|
3992
|
+
},
|
3993
|
+
body: { operations },
|
3994
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3995
|
+
});
|
3996
|
+
}
|
3997
|
+
};
|
2615
3998
|
_setCacheQuery = new WeakSet();
|
2616
3999
|
setCacheQuery_fn = async function(query, meta, records) {
|
2617
|
-
await __privateGet$4(this, _cache)
|
4000
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2618
4001
|
};
|
2619
4002
|
_getCacheQuery = new WeakSet();
|
2620
4003
|
getCacheQuery_fn = async function(query) {
|
2621
4004
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2622
|
-
const result = await __privateGet$4(this, _cache)
|
4005
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2623
4006
|
if (!result)
|
2624
4007
|
return null;
|
2625
|
-
const
|
4008
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4009
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2626
4010
|
if (ttl < 0)
|
2627
4011
|
return null;
|
2628
4012
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2632,39 +4016,66 @@ _getSchemaTables$1 = new WeakSet();
|
|
2632
4016
|
getSchemaTables_fn$1 = async function() {
|
2633
4017
|
if (__privateGet$4(this, _schemaTables$2))
|
2634
4018
|
return __privateGet$4(this, _schemaTables$2);
|
2635
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2636
4019
|
const { schema } = await getBranchDetails({
|
2637
4020
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2638
|
-
...
|
4021
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2639
4022
|
});
|
2640
4023
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2641
4024
|
return schema.tables;
|
2642
4025
|
};
|
2643
|
-
|
2644
|
-
|
4026
|
+
_transformObjectToApi = new WeakSet();
|
4027
|
+
transformObjectToApi_fn = async function(object) {
|
4028
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4029
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4030
|
+
if (!schema)
|
4031
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4032
|
+
const result = {};
|
4033
|
+
for (const [key, value] of Object.entries(object)) {
|
2645
4034
|
if (key === "xata")
|
2646
|
-
|
2647
|
-
|
2648
|
-
|
4035
|
+
continue;
|
4036
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4037
|
+
switch (type) {
|
4038
|
+
case "link": {
|
4039
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4040
|
+
break;
|
4041
|
+
}
|
4042
|
+
case "datetime": {
|
4043
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4044
|
+
break;
|
4045
|
+
}
|
4046
|
+
case `file`:
|
4047
|
+
result[key] = await parseInputFileEntry(value);
|
4048
|
+
break;
|
4049
|
+
case "file[]":
|
4050
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4051
|
+
break;
|
4052
|
+
case "json":
|
4053
|
+
result[key] = stringifyJson(value);
|
4054
|
+
break;
|
4055
|
+
default:
|
4056
|
+
result[key] = value;
|
4057
|
+
}
|
4058
|
+
}
|
4059
|
+
return result;
|
2649
4060
|
};
|
2650
4061
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2651
|
-
const
|
4062
|
+
const data = {};
|
2652
4063
|
const { xata, ...rest } = object ?? {};
|
2653
|
-
Object.assign(
|
4064
|
+
Object.assign(data, rest);
|
2654
4065
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2655
4066
|
if (!columns)
|
2656
4067
|
console.error(`Table ${table} not found in schema`);
|
2657
4068
|
for (const column of columns ?? []) {
|
2658
4069
|
if (!isValidColumn(selectedColumns, column))
|
2659
4070
|
continue;
|
2660
|
-
const value =
|
4071
|
+
const value = data[column.name];
|
2661
4072
|
switch (column.type) {
|
2662
4073
|
case "datetime": {
|
2663
|
-
const date = value !== void 0 ? new Date(value) :
|
2664
|
-
if (date && isNaN(date.getTime())) {
|
4074
|
+
const date = value !== void 0 ? new Date(value) : null;
|
4075
|
+
if (date !== null && isNaN(date.getTime())) {
|
2665
4076
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2666
|
-
} else
|
2667
|
-
|
4077
|
+
} else {
|
4078
|
+
data[column.name] = date;
|
2668
4079
|
}
|
2669
4080
|
break;
|
2670
4081
|
}
|
@@ -2677,54 +4088,77 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2677
4088
|
if (item === column.name) {
|
2678
4089
|
return [...acc, "*"];
|
2679
4090
|
}
|
2680
|
-
if (item.startsWith(`${column.name}.`)) {
|
4091
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2681
4092
|
const [, ...path] = item.split(".");
|
2682
4093
|
return [...acc, path.join(".")];
|
2683
4094
|
}
|
2684
4095
|
return acc;
|
2685
4096
|
}, []);
|
2686
|
-
|
4097
|
+
data[column.name] = initObject(
|
4098
|
+
db,
|
4099
|
+
schemaTables,
|
4100
|
+
linkTable,
|
4101
|
+
value,
|
4102
|
+
selectedLinkColumns
|
4103
|
+
);
|
2687
4104
|
} else {
|
2688
|
-
|
4105
|
+
data[column.name] = null;
|
2689
4106
|
}
|
2690
4107
|
break;
|
2691
4108
|
}
|
4109
|
+
case "file":
|
4110
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4111
|
+
break;
|
4112
|
+
case "file[]":
|
4113
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4114
|
+
break;
|
4115
|
+
case "json":
|
4116
|
+
data[column.name] = parseJson(value);
|
4117
|
+
break;
|
2692
4118
|
default:
|
2693
|
-
|
4119
|
+
data[column.name] = value ?? null;
|
2694
4120
|
if (column.notNull === true && value === null) {
|
2695
4121
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2696
4122
|
}
|
2697
4123
|
break;
|
2698
4124
|
}
|
2699
4125
|
}
|
2700
|
-
|
2701
|
-
|
4126
|
+
const record = { ...data };
|
4127
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
4128
|
+
record.read = function(columns2) {
|
4129
|
+
return db[table].read(record["id"], columns2);
|
2702
4130
|
};
|
2703
|
-
|
2704
|
-
const columns2 =
|
4131
|
+
record.update = function(data2, b, c) {
|
4132
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2705
4133
|
const ifVersion = parseIfVersion(b, c);
|
2706
|
-
return db[table].update(
|
4134
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2707
4135
|
};
|
2708
|
-
|
2709
|
-
const columns2 =
|
4136
|
+
record.replace = function(data2, b, c) {
|
4137
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2710
4138
|
const ifVersion = parseIfVersion(b, c);
|
2711
|
-
return db[table].createOrReplace(
|
4139
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
4140
|
+
};
|
4141
|
+
record.delete = function() {
|
4142
|
+
return db[table].delete(record["id"]);
|
4143
|
+
};
|
4144
|
+
if (metadata !== void 0) {
|
4145
|
+
record.xata = Object.freeze(metadata);
|
4146
|
+
}
|
4147
|
+
record.getMetadata = function() {
|
4148
|
+
return record.xata;
|
2712
4149
|
};
|
2713
|
-
|
2714
|
-
return
|
4150
|
+
record.toSerializable = function() {
|
4151
|
+
return JSON.parse(JSON.stringify(record));
|
2715
4152
|
};
|
2716
|
-
|
2717
|
-
return
|
4153
|
+
record.toString = function() {
|
4154
|
+
return JSON.stringify(record);
|
2718
4155
|
};
|
2719
|
-
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
2720
|
-
Object.defineProperty(
|
4156
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
4157
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2721
4158
|
}
|
2722
|
-
Object.freeze(
|
2723
|
-
return
|
4159
|
+
Object.freeze(record);
|
4160
|
+
return record;
|
2724
4161
|
};
|
2725
|
-
function isResponseWithRecords(value) {
|
2726
|
-
return isObject(value) && Array.isArray(value.records);
|
2727
|
-
}
|
2728
4162
|
function extractId(value) {
|
2729
4163
|
if (isString(value))
|
2730
4164
|
return value;
|
@@ -2735,11 +4169,7 @@ function extractId(value) {
|
|
2735
4169
|
function isValidColumn(columns, column) {
|
2736
4170
|
if (columns.includes("*"))
|
2737
4171
|
return true;
|
2738
|
-
|
2739
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2740
|
-
return linkColumns.length > 0;
|
2741
|
-
}
|
2742
|
-
return columns.includes(column.name);
|
4172
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
2743
4173
|
}
|
2744
4174
|
function parseIfVersion(...args) {
|
2745
4175
|
for (const arg of args) {
|
@@ -2816,10 +4246,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
2816
4246
|
const startsWith = (value) => ({ $startsWith: value });
|
2817
4247
|
const endsWith = (value) => ({ $endsWith: value });
|
2818
4248
|
const pattern = (value) => ({ $pattern: value });
|
4249
|
+
const iPattern = (value) => ({ $iPattern: value });
|
2819
4250
|
const is = (value) => ({ $is: value });
|
2820
4251
|
const equals = is;
|
2821
4252
|
const isNot = (value) => ({ $isNot: value });
|
2822
4253
|
const contains = (value) => ({ $contains: value });
|
4254
|
+
const iContains = (value) => ({ $iContains: value });
|
2823
4255
|
const includes = (value) => ({ $includes: value });
|
2824
4256
|
const includesAll = (value) => ({ $includesAll: value });
|
2825
4257
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -2875,6 +4307,80 @@ class SchemaPlugin extends XataPlugin {
|
|
2875
4307
|
_tables = new WeakMap();
|
2876
4308
|
_schemaTables$1 = new WeakMap();
|
2877
4309
|
|
4310
|
+
class FilesPlugin extends XataPlugin {
|
4311
|
+
build(pluginOptions) {
|
4312
|
+
return {
|
4313
|
+
download: async (location) => {
|
4314
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4315
|
+
return await getFileItem({
|
4316
|
+
pathParams: {
|
4317
|
+
workspace: "{workspaceId}",
|
4318
|
+
dbBranchName: "{dbBranch}",
|
4319
|
+
region: "{region}",
|
4320
|
+
tableName: table ?? "",
|
4321
|
+
recordId: record ?? "",
|
4322
|
+
columnName: column ?? "",
|
4323
|
+
fileId
|
4324
|
+
},
|
4325
|
+
...pluginOptions,
|
4326
|
+
rawResponse: true
|
4327
|
+
});
|
4328
|
+
},
|
4329
|
+
upload: async (location, file, options) => {
|
4330
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4331
|
+
const resolvedFile = await file;
|
4332
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4333
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4334
|
+
return await putFileItem({
|
4335
|
+
...pluginOptions,
|
4336
|
+
pathParams: {
|
4337
|
+
workspace: "{workspaceId}",
|
4338
|
+
dbBranchName: "{dbBranch}",
|
4339
|
+
region: "{region}",
|
4340
|
+
tableName: table ?? "",
|
4341
|
+
recordId: record ?? "",
|
4342
|
+
columnName: column ?? "",
|
4343
|
+
fileId
|
4344
|
+
},
|
4345
|
+
body,
|
4346
|
+
headers: { "Content-Type": contentType }
|
4347
|
+
});
|
4348
|
+
},
|
4349
|
+
delete: async (location) => {
|
4350
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4351
|
+
return await deleteFileItem({
|
4352
|
+
pathParams: {
|
4353
|
+
workspace: "{workspaceId}",
|
4354
|
+
dbBranchName: "{dbBranch}",
|
4355
|
+
region: "{region}",
|
4356
|
+
tableName: table ?? "",
|
4357
|
+
recordId: record ?? "",
|
4358
|
+
columnName: column ?? "",
|
4359
|
+
fileId
|
4360
|
+
},
|
4361
|
+
...pluginOptions
|
4362
|
+
});
|
4363
|
+
}
|
4364
|
+
};
|
4365
|
+
}
|
4366
|
+
}
|
4367
|
+
function getContentType(file) {
|
4368
|
+
if (typeof file === "string") {
|
4369
|
+
return "text/plain";
|
4370
|
+
}
|
4371
|
+
if ("mediaType" in file) {
|
4372
|
+
return file.mediaType;
|
4373
|
+
}
|
4374
|
+
if (isBlob(file)) {
|
4375
|
+
return file.type;
|
4376
|
+
}
|
4377
|
+
try {
|
4378
|
+
return file.type;
|
4379
|
+
} catch (e) {
|
4380
|
+
}
|
4381
|
+
return "application/octet-stream";
|
4382
|
+
}
|
4383
|
+
|
2878
4384
|
var __accessCheck$1 = (obj, member, msg) => {
|
2879
4385
|
if (!member.has(obj))
|
2880
4386
|
throw TypeError("Cannot " + msg);
|
@@ -2907,138 +4413,141 @@ class SearchPlugin extends XataPlugin {
|
|
2907
4413
|
__privateAdd$1(this, _schemaTables, void 0);
|
2908
4414
|
__privateSet$1(this, _schemaTables, schemaTables);
|
2909
4415
|
}
|
2910
|
-
build(
|
4416
|
+
build(pluginOptions) {
|
2911
4417
|
return {
|
2912
4418
|
all: async (query, options = {}) => {
|
2913
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
2914
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
2915
|
-
return
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
4419
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4420
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4421
|
+
return {
|
4422
|
+
totalCount,
|
4423
|
+
records: records.map((record) => {
|
4424
|
+
const { table = "orphan" } = record.xata;
|
4425
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4426
|
+
})
|
4427
|
+
};
|
2919
4428
|
},
|
2920
4429
|
byTable: async (query, options = {}) => {
|
2921
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
2922
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
2923
|
-
|
4430
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4431
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4432
|
+
const records = rawRecords.reduce((acc, record) => {
|
2924
4433
|
const { table = "orphan" } = record.xata;
|
2925
4434
|
const items = acc[table] ?? [];
|
2926
4435
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
2927
4436
|
return { ...acc, [table]: [...items, item] };
|
2928
4437
|
}, {});
|
4438
|
+
return { totalCount, records };
|
2929
4439
|
}
|
2930
4440
|
};
|
2931
4441
|
}
|
2932
4442
|
}
|
2933
4443
|
_schemaTables = new WeakMap();
|
2934
4444
|
_search = new WeakSet();
|
2935
|
-
search_fn = async function(query, options,
|
2936
|
-
const
|
2937
|
-
const {
|
2938
|
-
const { records } = await searchBranch({
|
4445
|
+
search_fn = async function(query, options, pluginOptions) {
|
4446
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
4447
|
+
const { records, totalCount } = await searchBranch({
|
2939
4448
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2940
|
-
|
2941
|
-
|
4449
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
4450
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
4451
|
+
...pluginOptions
|
2942
4452
|
});
|
2943
|
-
return records;
|
4453
|
+
return { records, totalCount };
|
2944
4454
|
};
|
2945
4455
|
_getSchemaTables = new WeakSet();
|
2946
|
-
getSchemaTables_fn = async function(
|
4456
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
2947
4457
|
if (__privateGet$1(this, _schemaTables))
|
2948
4458
|
return __privateGet$1(this, _schemaTables);
|
2949
|
-
const fetchProps = await getFetchProps();
|
2950
4459
|
const { schema } = await getBranchDetails({
|
2951
4460
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2952
|
-
...
|
4461
|
+
...pluginOptions
|
2953
4462
|
});
|
2954
4463
|
__privateSet$1(this, _schemaTables, schema.tables);
|
2955
4464
|
return schema.tables;
|
2956
4465
|
};
|
2957
4466
|
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
|
2966
|
-
|
2967
|
-
|
2968
|
-
|
2969
|
-
|
2970
|
-
|
2971
|
-
|
2972
|
-
}
|
2973
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
}
|
2977
|
-
async function resolveXataBranch(gitBranch, options) {
|
2978
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2979
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2980
|
-
if (!databaseURL)
|
2981
|
-
throw new Error(
|
2982
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2983
|
-
);
|
2984
|
-
if (!apiKey)
|
2985
|
-
throw new Error(
|
2986
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2987
|
-
);
|
2988
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
2989
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
2990
|
-
if (!urlParts)
|
2991
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
2992
|
-
const { workspace, region } = urlParts;
|
2993
|
-
const { fallbackBranch } = getEnvironment();
|
2994
|
-
const { branch } = await resolveBranch({
|
2995
|
-
apiKey,
|
2996
|
-
apiUrl: databaseURL,
|
2997
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2998
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
2999
|
-
pathParams: { dbName, workspace, region },
|
3000
|
-
queryParams: { gitBranch, fallbackBranch },
|
3001
|
-
trace: defaultTrace
|
3002
|
-
});
|
3003
|
-
return branch;
|
3004
|
-
}
|
3005
|
-
async function getDatabaseBranch(branch, options) {
|
3006
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3007
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3008
|
-
if (!databaseURL)
|
3009
|
-
throw new Error(
|
3010
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3011
|
-
);
|
3012
|
-
if (!apiKey)
|
3013
|
-
throw new Error(
|
3014
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3015
|
-
);
|
3016
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3017
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3018
|
-
if (!urlParts)
|
3019
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3020
|
-
const { workspace, region } = urlParts;
|
3021
|
-
try {
|
3022
|
-
return await getBranchDetails({
|
3023
|
-
apiKey,
|
3024
|
-
apiUrl: databaseURL,
|
3025
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3026
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3027
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3028
|
-
trace: defaultTrace
|
3029
|
-
});
|
3030
|
-
} catch (err) {
|
3031
|
-
if (isObject(err) && err.status === 404)
|
3032
|
-
return null;
|
3033
|
-
throw err;
|
4467
|
+
function escapeElement(elementRepresentation) {
|
4468
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4469
|
+
return '"' + escaped + '"';
|
4470
|
+
}
|
4471
|
+
function arrayString(val) {
|
4472
|
+
let result = "{";
|
4473
|
+
for (let i = 0; i < val.length; i++) {
|
4474
|
+
if (i > 0) {
|
4475
|
+
result = result + ",";
|
4476
|
+
}
|
4477
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4478
|
+
result = result + "NULL";
|
4479
|
+
} else if (Array.isArray(val[i])) {
|
4480
|
+
result = result + arrayString(val[i]);
|
4481
|
+
} else if (val[i] instanceof Buffer) {
|
4482
|
+
result += "\\\\x" + val[i].toString("hex");
|
4483
|
+
} else {
|
4484
|
+
result += escapeElement(prepareValue(val[i]));
|
4485
|
+
}
|
3034
4486
|
}
|
4487
|
+
result = result + "}";
|
4488
|
+
return result;
|
3035
4489
|
}
|
3036
|
-
function
|
4490
|
+
function prepareValue(value) {
|
4491
|
+
if (!isDefined(value))
|
4492
|
+
return null;
|
4493
|
+
if (value instanceof Date) {
|
4494
|
+
return value.toISOString();
|
4495
|
+
}
|
4496
|
+
if (Array.isArray(value)) {
|
4497
|
+
return arrayString(value);
|
4498
|
+
}
|
4499
|
+
if (isObject(value)) {
|
4500
|
+
return JSON.stringify(value);
|
4501
|
+
}
|
3037
4502
|
try {
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3041
|
-
|
4503
|
+
return value.toString();
|
4504
|
+
} catch (e) {
|
4505
|
+
return value;
|
4506
|
+
}
|
4507
|
+
}
|
4508
|
+
function prepareParams(param1, param2) {
|
4509
|
+
if (isString(param1)) {
|
4510
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4511
|
+
}
|
4512
|
+
if (isStringArray(param1)) {
|
4513
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4514
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4515
|
+
}, "");
|
4516
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4517
|
+
}
|
4518
|
+
if (isObject(param1)) {
|
4519
|
+
const { statement, params, consistency } = param1;
|
4520
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4521
|
+
}
|
4522
|
+
throw new Error("Invalid query");
|
4523
|
+
}
|
4524
|
+
|
4525
|
+
class SQLPlugin extends XataPlugin {
|
4526
|
+
build(pluginOptions) {
|
4527
|
+
return async (param1, ...param2) => {
|
4528
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4529
|
+
const { records, warning } = await sqlQuery({
|
4530
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4531
|
+
body: { statement, params, consistency },
|
4532
|
+
...pluginOptions
|
4533
|
+
});
|
4534
|
+
return { records, warning };
|
4535
|
+
};
|
4536
|
+
}
|
4537
|
+
}
|
4538
|
+
|
4539
|
+
class TransactionPlugin extends XataPlugin {
|
4540
|
+
build(pluginOptions) {
|
4541
|
+
return {
|
4542
|
+
run: async (operations) => {
|
4543
|
+
const response = await branchTransaction({
|
4544
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4545
|
+
body: { operations },
|
4546
|
+
...pluginOptions
|
4547
|
+
});
|
4548
|
+
return response;
|
4549
|
+
}
|
4550
|
+
};
|
3042
4551
|
}
|
3043
4552
|
}
|
3044
4553
|
|
@@ -3065,46 +4574,43 @@ var __privateMethod = (obj, member, method) => {
|
|
3065
4574
|
return method;
|
3066
4575
|
};
|
3067
4576
|
const buildClient = (plugins) => {
|
3068
|
-
var
|
4577
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3069
4578
|
return _a = class {
|
3070
4579
|
constructor(options = {}, schemaTables) {
|
3071
4580
|
__privateAdd(this, _parseOptions);
|
3072
4581
|
__privateAdd(this, _getFetchProps);
|
3073
|
-
__privateAdd(this, _evaluateBranch);
|
3074
|
-
__privateAdd(this, _branch, void 0);
|
3075
4582
|
__privateAdd(this, _options, void 0);
|
3076
4583
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3077
4584
|
__privateSet(this, _options, safeOptions);
|
3078
4585
|
const pluginOptions = {
|
3079
|
-
|
4586
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3080
4587
|
cache: safeOptions.cache,
|
3081
|
-
|
4588
|
+
host: safeOptions.host
|
3082
4589
|
};
|
3083
4590
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3084
4591
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4592
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
4593
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4594
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3085
4595
|
this.db = db;
|
3086
4596
|
this.search = search;
|
4597
|
+
this.transactions = transactions;
|
4598
|
+
this.sql = sql;
|
4599
|
+
this.files = files;
|
3087
4600
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3088
4601
|
if (namespace === void 0)
|
3089
4602
|
continue;
|
3090
|
-
|
3091
|
-
if (result instanceof Promise) {
|
3092
|
-
void result.then((namespace2) => {
|
3093
|
-
this[key] = namespace2;
|
3094
|
-
});
|
3095
|
-
} else {
|
3096
|
-
this[key] = result;
|
3097
|
-
}
|
4603
|
+
this[key] = namespace.build(pluginOptions);
|
3098
4604
|
}
|
3099
4605
|
}
|
3100
4606
|
async getConfig() {
|
3101
4607
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3102
|
-
const branch =
|
4608
|
+
const branch = __privateGet(this, _options).branch;
|
3103
4609
|
return { databaseURL, branch };
|
3104
4610
|
}
|
3105
|
-
},
|
4611
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3106
4612
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3107
|
-
const isBrowser = typeof window !== "undefined";
|
4613
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3108
4614
|
if (isBrowser && !enableBrowser) {
|
3109
4615
|
throw new Error(
|
3110
4616
|
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
@@ -3115,46 +4621,73 @@ const buildClient = (plugins) => {
|
|
3115
4621
|
const apiKey = options?.apiKey || getAPIKey();
|
3116
4622
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3117
4623
|
const trace = options?.trace ?? defaultTrace;
|
3118
|
-
const
|
4624
|
+
const clientName = options?.clientName;
|
4625
|
+
const host = options?.host ?? "production";
|
4626
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3119
4627
|
if (!apiKey) {
|
3120
4628
|
throw new Error("Option apiKey is required");
|
3121
4629
|
}
|
3122
4630
|
if (!databaseURL) {
|
3123
4631
|
throw new Error("Option databaseURL is required");
|
3124
4632
|
}
|
3125
|
-
|
3126
|
-
|
3127
|
-
const
|
3128
|
-
if (
|
3129
|
-
|
4633
|
+
const envBranch = getBranch();
|
4634
|
+
const previewBranch = getPreviewBranch();
|
4635
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4636
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4637
|
+
console.warn(
|
4638
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4639
|
+
);
|
4640
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4641
|
+
console.warn(
|
4642
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4643
|
+
);
|
4644
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4645
|
+
console.warn(
|
4646
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4647
|
+
);
|
4648
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4649
|
+
console.warn(
|
4650
|
+
`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.`
|
4651
|
+
);
|
4652
|
+
}
|
4653
|
+
return {
|
4654
|
+
fetch,
|
4655
|
+
databaseURL,
|
4656
|
+
apiKey,
|
4657
|
+
branch,
|
4658
|
+
cache,
|
4659
|
+
trace,
|
4660
|
+
host,
|
4661
|
+
clientID: generateUUID(),
|
4662
|
+
enableBrowser,
|
4663
|
+
clientName,
|
4664
|
+
xataAgentExtra
|
4665
|
+
};
|
4666
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4667
|
+
fetch,
|
4668
|
+
apiKey,
|
4669
|
+
databaseURL,
|
4670
|
+
branch,
|
4671
|
+
trace,
|
4672
|
+
clientID,
|
4673
|
+
clientName,
|
4674
|
+
xataAgentExtra
|
4675
|
+
}) {
|
3130
4676
|
return {
|
3131
|
-
|
4677
|
+
fetch,
|
3132
4678
|
apiKey,
|
3133
4679
|
apiUrl: "",
|
4680
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3134
4681
|
workspacesApiUrl: (path, params) => {
|
3135
4682
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3136
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4683
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3137
4684
|
return databaseURL + newPath;
|
3138
4685
|
},
|
3139
4686
|
trace,
|
3140
|
-
clientID
|
3141
|
-
|
3142
|
-
|
3143
|
-
if (__privateGet(this, _branch))
|
3144
|
-
return __privateGet(this, _branch);
|
3145
|
-
if (param === void 0)
|
3146
|
-
return void 0;
|
3147
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3148
|
-
const evaluateBranch = async (strategy) => {
|
3149
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
4687
|
+
clientID,
|
4688
|
+
clientName,
|
4689
|
+
xataAgentExtra
|
3150
4690
|
};
|
3151
|
-
for await (const strategy of strategies) {
|
3152
|
-
const branch = await evaluateBranch(strategy);
|
3153
|
-
if (branch) {
|
3154
|
-
__privateSet(this, _branch, branch);
|
3155
|
-
return branch;
|
3156
|
-
}
|
3157
|
-
}
|
3158
4691
|
}, _a;
|
3159
4692
|
};
|
3160
4693
|
class BaseClient extends buildClient() {
|
@@ -3228,7 +4761,7 @@ const deserialize = (json) => {
|
|
3228
4761
|
};
|
3229
4762
|
|
3230
4763
|
function buildWorkerRunner(config) {
|
3231
|
-
return function xataWorker(name,
|
4764
|
+
return function xataWorker(name, worker) {
|
3232
4765
|
return async (...args) => {
|
3233
4766
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3234
4767
|
const result = await fetch(url, {
|
@@ -3249,5 +4782,5 @@ class XataError extends Error {
|
|
3249
4782
|
}
|
3250
4783
|
}
|
3251
4784
|
|
3252
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace,
|
4785
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3253
4786
|
//# sourceMappingURL=index.mjs.map
|