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