@xata.io/client 0.0.0-alpha.vff52a72 → 0.0.0-alpha.vffe924c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +228 -0
- package/README.md +3 -269
- package/dist/index.cjs +1377 -391
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3174 -1536
- package/dist/index.mjs +1356 -365
- 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.js +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
|
}
|
@@ -41,6 +42,18 @@ function isStringArray(value) {
|
|
41
42
|
function isNumber(value) {
|
42
43
|
return isDefined(value) && typeof value === "number";
|
43
44
|
}
|
45
|
+
function parseNumber(value) {
|
46
|
+
if (isNumber(value)) {
|
47
|
+
return value;
|
48
|
+
}
|
49
|
+
if (isString(value)) {
|
50
|
+
const parsed = Number(value);
|
51
|
+
if (!Number.isNaN(parsed)) {
|
52
|
+
return parsed;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
return void 0;
|
56
|
+
}
|
44
57
|
function toBase64(value) {
|
45
58
|
try {
|
46
59
|
return btoa(value);
|
@@ -60,16 +73,28 @@ function deepMerge(a, b) {
|
|
60
73
|
}
|
61
74
|
return result;
|
62
75
|
}
|
76
|
+
function chunk(array, chunkSize) {
|
77
|
+
const result = [];
|
78
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
79
|
+
result.push(array.slice(i, i + chunkSize));
|
80
|
+
}
|
81
|
+
return result;
|
82
|
+
}
|
83
|
+
async function timeout(ms) {
|
84
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
85
|
+
}
|
63
86
|
|
64
87
|
function getEnvironment() {
|
65
88
|
try {
|
66
|
-
if (
|
89
|
+
if (isDefined(process) && isDefined(process.env)) {
|
67
90
|
return {
|
68
91
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
69
92
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
70
93
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
71
|
-
|
72
|
-
|
94
|
+
deployPreview: process.env.XATA_PREVIEW,
|
95
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
96
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
97
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
73
98
|
};
|
74
99
|
}
|
75
100
|
} catch (err) {
|
@@ -80,8 +105,10 @@ function getEnvironment() {
|
|
80
105
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
81
106
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
82
107
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
83
|
-
|
84
|
-
|
108
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
109
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
110
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
111
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
85
112
|
};
|
86
113
|
}
|
87
114
|
} catch (err) {
|
@@ -90,10 +117,31 @@ function getEnvironment() {
|
|
90
117
|
apiKey: getGlobalApiKey(),
|
91
118
|
databaseURL: getGlobalDatabaseURL(),
|
92
119
|
branch: getGlobalBranch(),
|
93
|
-
|
94
|
-
|
120
|
+
deployPreview: void 0,
|
121
|
+
deployPreviewBranch: void 0,
|
122
|
+
vercelGitCommitRef: void 0,
|
123
|
+
vercelGitRepoOwner: void 0
|
95
124
|
};
|
96
125
|
}
|
126
|
+
function getEnableBrowserVariable() {
|
127
|
+
try {
|
128
|
+
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
129
|
+
return process.env.XATA_ENABLE_BROWSER === "true";
|
130
|
+
}
|
131
|
+
} catch (err) {
|
132
|
+
}
|
133
|
+
try {
|
134
|
+
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
135
|
+
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
136
|
+
}
|
137
|
+
} catch (err) {
|
138
|
+
}
|
139
|
+
try {
|
140
|
+
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
141
|
+
} catch (err) {
|
142
|
+
return void 0;
|
143
|
+
}
|
144
|
+
}
|
97
145
|
function getGlobalApiKey() {
|
98
146
|
try {
|
99
147
|
return XATA_API_KEY;
|
@@ -115,44 +163,76 @@ function getGlobalBranch() {
|
|
115
163
|
return void 0;
|
116
164
|
}
|
117
165
|
}
|
118
|
-
function
|
166
|
+
function getDatabaseURL() {
|
119
167
|
try {
|
120
|
-
|
168
|
+
const { databaseURL } = getEnvironment();
|
169
|
+
return databaseURL;
|
121
170
|
} catch (err) {
|
122
171
|
return void 0;
|
123
172
|
}
|
124
173
|
}
|
125
|
-
|
126
|
-
const cmd = ["git", "branch", "--show-current"];
|
127
|
-
const fullCmd = cmd.join(" ");
|
128
|
-
const nodeModule = ["child", "process"].join("_");
|
129
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
174
|
+
function getAPIKey() {
|
130
175
|
try {
|
131
|
-
|
132
|
-
|
133
|
-
}
|
134
|
-
const { execSync } = await import(nodeModule);
|
135
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
176
|
+
const { apiKey } = getEnvironment();
|
177
|
+
return apiKey;
|
136
178
|
} catch (err) {
|
179
|
+
return void 0;
|
137
180
|
}
|
181
|
+
}
|
182
|
+
function getBranch() {
|
138
183
|
try {
|
139
|
-
|
140
|
-
|
141
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
142
|
-
}
|
184
|
+
const { branch } = getEnvironment();
|
185
|
+
return branch ?? "main";
|
143
186
|
} catch (err) {
|
187
|
+
return void 0;
|
144
188
|
}
|
145
189
|
}
|
146
|
-
|
147
|
-
|
190
|
+
function buildPreviewBranchName({ org, branch }) {
|
191
|
+
return `preview-${org}-${branch}`;
|
192
|
+
}
|
193
|
+
function getPreviewBranch() {
|
148
194
|
try {
|
149
|
-
const {
|
150
|
-
|
195
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
196
|
+
if (deployPreviewBranch)
|
197
|
+
return deployPreviewBranch;
|
198
|
+
switch (deployPreview) {
|
199
|
+
case "vercel": {
|
200
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
201
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
202
|
+
return void 0;
|
203
|
+
}
|
204
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
205
|
+
}
|
206
|
+
}
|
207
|
+
return void 0;
|
151
208
|
} catch (err) {
|
152
209
|
return void 0;
|
153
210
|
}
|
154
211
|
}
|
155
212
|
|
213
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
214
|
+
if (!member.has(obj))
|
215
|
+
throw TypeError("Cannot " + msg);
|
216
|
+
};
|
217
|
+
var __privateGet$8 = (obj, member, getter) => {
|
218
|
+
__accessCheck$8(obj, member, "read from private field");
|
219
|
+
return getter ? getter.call(obj) : member.get(obj);
|
220
|
+
};
|
221
|
+
var __privateAdd$8 = (obj, member, value) => {
|
222
|
+
if (member.has(obj))
|
223
|
+
throw TypeError("Cannot add the same private member more than once");
|
224
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
225
|
+
};
|
226
|
+
var __privateSet$8 = (obj, member, value, setter) => {
|
227
|
+
__accessCheck$8(obj, member, "write to private field");
|
228
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
229
|
+
return value;
|
230
|
+
};
|
231
|
+
var __privateMethod$4 = (obj, member, method) => {
|
232
|
+
__accessCheck$8(obj, member, "access private method");
|
233
|
+
return method;
|
234
|
+
};
|
235
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
156
236
|
function getFetchImplementation(userFetch) {
|
157
237
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
158
238
|
const fetchImpl = userFetch ?? globalFetch;
|
@@ -163,8 +243,254 @@ function getFetchImplementation(userFetch) {
|
|
163
243
|
}
|
164
244
|
return fetchImpl;
|
165
245
|
}
|
246
|
+
class ApiRequestPool {
|
247
|
+
constructor(concurrency = 10) {
|
248
|
+
__privateAdd$8(this, _enqueue);
|
249
|
+
__privateAdd$8(this, _fetch, void 0);
|
250
|
+
__privateAdd$8(this, _queue, void 0);
|
251
|
+
__privateAdd$8(this, _concurrency, void 0);
|
252
|
+
__privateSet$8(this, _queue, []);
|
253
|
+
__privateSet$8(this, _concurrency, concurrency);
|
254
|
+
this.running = 0;
|
255
|
+
this.started = 0;
|
256
|
+
}
|
257
|
+
setFetch(fetch2) {
|
258
|
+
__privateSet$8(this, _fetch, fetch2);
|
259
|
+
}
|
260
|
+
getFetch() {
|
261
|
+
if (!__privateGet$8(this, _fetch)) {
|
262
|
+
throw new Error("Fetch not set");
|
263
|
+
}
|
264
|
+
return __privateGet$8(this, _fetch);
|
265
|
+
}
|
266
|
+
request(url, options) {
|
267
|
+
const start = /* @__PURE__ */ new Date();
|
268
|
+
const fetch2 = this.getFetch();
|
269
|
+
const runRequest = async (stalled = false) => {
|
270
|
+
const response = await fetch2(url, options);
|
271
|
+
if (response.status === 429) {
|
272
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
273
|
+
await timeout(rateLimitReset * 1e3);
|
274
|
+
return await runRequest(true);
|
275
|
+
}
|
276
|
+
if (stalled) {
|
277
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
278
|
+
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
279
|
+
}
|
280
|
+
return response;
|
281
|
+
};
|
282
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
283
|
+
return await runRequest();
|
284
|
+
});
|
285
|
+
}
|
286
|
+
}
|
287
|
+
_fetch = new WeakMap();
|
288
|
+
_queue = new WeakMap();
|
289
|
+
_concurrency = new WeakMap();
|
290
|
+
_enqueue = new WeakSet();
|
291
|
+
enqueue_fn = function(task) {
|
292
|
+
const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
|
293
|
+
this.started--;
|
294
|
+
this.running++;
|
295
|
+
}).then(() => task()).finally(() => {
|
296
|
+
this.running--;
|
297
|
+
const next = __privateGet$8(this, _queue).shift();
|
298
|
+
if (next !== void 0) {
|
299
|
+
this.started++;
|
300
|
+
next();
|
301
|
+
}
|
302
|
+
});
|
303
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
304
|
+
const next = __privateGet$8(this, _queue).shift();
|
305
|
+
if (next !== void 0) {
|
306
|
+
this.started++;
|
307
|
+
next();
|
308
|
+
}
|
309
|
+
}
|
310
|
+
return promise;
|
311
|
+
};
|
312
|
+
|
313
|
+
function generateUUID() {
|
314
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
315
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
316
|
+
return v.toString(16);
|
317
|
+
});
|
318
|
+
}
|
166
319
|
|
167
|
-
|
320
|
+
async function getBytes(stream, onChunk) {
|
321
|
+
const reader = stream.getReader();
|
322
|
+
let result;
|
323
|
+
while (!(result = await reader.read()).done) {
|
324
|
+
onChunk(result.value);
|
325
|
+
}
|
326
|
+
}
|
327
|
+
function getLines(onLine) {
|
328
|
+
let buffer;
|
329
|
+
let position;
|
330
|
+
let fieldLength;
|
331
|
+
let discardTrailingNewline = false;
|
332
|
+
return function onChunk(arr) {
|
333
|
+
if (buffer === void 0) {
|
334
|
+
buffer = arr;
|
335
|
+
position = 0;
|
336
|
+
fieldLength = -1;
|
337
|
+
} else {
|
338
|
+
buffer = concat(buffer, arr);
|
339
|
+
}
|
340
|
+
const bufLength = buffer.length;
|
341
|
+
let lineStart = 0;
|
342
|
+
while (position < bufLength) {
|
343
|
+
if (discardTrailingNewline) {
|
344
|
+
if (buffer[position] === 10 /* NewLine */) {
|
345
|
+
lineStart = ++position;
|
346
|
+
}
|
347
|
+
discardTrailingNewline = false;
|
348
|
+
}
|
349
|
+
let lineEnd = -1;
|
350
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
351
|
+
switch (buffer[position]) {
|
352
|
+
case 58 /* Colon */:
|
353
|
+
if (fieldLength === -1) {
|
354
|
+
fieldLength = position - lineStart;
|
355
|
+
}
|
356
|
+
break;
|
357
|
+
case 13 /* CarriageReturn */:
|
358
|
+
discardTrailingNewline = true;
|
359
|
+
case 10 /* NewLine */:
|
360
|
+
lineEnd = position;
|
361
|
+
break;
|
362
|
+
}
|
363
|
+
}
|
364
|
+
if (lineEnd === -1) {
|
365
|
+
break;
|
366
|
+
}
|
367
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
368
|
+
lineStart = position;
|
369
|
+
fieldLength = -1;
|
370
|
+
}
|
371
|
+
if (lineStart === bufLength) {
|
372
|
+
buffer = void 0;
|
373
|
+
} else if (lineStart !== 0) {
|
374
|
+
buffer = buffer.subarray(lineStart);
|
375
|
+
position -= lineStart;
|
376
|
+
}
|
377
|
+
};
|
378
|
+
}
|
379
|
+
function getMessages(onId, onRetry, onMessage) {
|
380
|
+
let message = newMessage();
|
381
|
+
const decoder = new TextDecoder();
|
382
|
+
return function onLine(line, fieldLength) {
|
383
|
+
if (line.length === 0) {
|
384
|
+
onMessage?.(message);
|
385
|
+
message = newMessage();
|
386
|
+
} else if (fieldLength > 0) {
|
387
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
388
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
389
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
390
|
+
switch (field) {
|
391
|
+
case "data":
|
392
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
393
|
+
break;
|
394
|
+
case "event":
|
395
|
+
message.event = value;
|
396
|
+
break;
|
397
|
+
case "id":
|
398
|
+
onId(message.id = value);
|
399
|
+
break;
|
400
|
+
case "retry":
|
401
|
+
const retry = parseInt(value, 10);
|
402
|
+
if (!isNaN(retry)) {
|
403
|
+
onRetry(message.retry = retry);
|
404
|
+
}
|
405
|
+
break;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
};
|
409
|
+
}
|
410
|
+
function concat(a, b) {
|
411
|
+
const res = new Uint8Array(a.length + b.length);
|
412
|
+
res.set(a);
|
413
|
+
res.set(b, a.length);
|
414
|
+
return res;
|
415
|
+
}
|
416
|
+
function newMessage() {
|
417
|
+
return {
|
418
|
+
data: "",
|
419
|
+
event: "",
|
420
|
+
id: "",
|
421
|
+
retry: void 0
|
422
|
+
};
|
423
|
+
}
|
424
|
+
const EventStreamContentType = "text/event-stream";
|
425
|
+
const LastEventId = "last-event-id";
|
426
|
+
function fetchEventSource(input, {
|
427
|
+
signal: inputSignal,
|
428
|
+
headers: inputHeaders,
|
429
|
+
onopen: inputOnOpen,
|
430
|
+
onmessage,
|
431
|
+
onclose,
|
432
|
+
onerror,
|
433
|
+
fetch: inputFetch,
|
434
|
+
...rest
|
435
|
+
}) {
|
436
|
+
return new Promise((resolve, reject) => {
|
437
|
+
const headers = { ...inputHeaders };
|
438
|
+
if (!headers.accept) {
|
439
|
+
headers.accept = EventStreamContentType;
|
440
|
+
}
|
441
|
+
let curRequestController;
|
442
|
+
function dispose() {
|
443
|
+
curRequestController.abort();
|
444
|
+
}
|
445
|
+
inputSignal?.addEventListener("abort", () => {
|
446
|
+
dispose();
|
447
|
+
resolve();
|
448
|
+
});
|
449
|
+
const fetchImpl = inputFetch ?? fetch;
|
450
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
451
|
+
async function create() {
|
452
|
+
curRequestController = new AbortController();
|
453
|
+
try {
|
454
|
+
const response = await fetchImpl(input, {
|
455
|
+
...rest,
|
456
|
+
headers,
|
457
|
+
signal: curRequestController.signal
|
458
|
+
});
|
459
|
+
await onopen(response);
|
460
|
+
await getBytes(
|
461
|
+
response.body,
|
462
|
+
getLines(
|
463
|
+
getMessages(
|
464
|
+
(id) => {
|
465
|
+
if (id) {
|
466
|
+
headers[LastEventId] = id;
|
467
|
+
} else {
|
468
|
+
delete headers[LastEventId];
|
469
|
+
}
|
470
|
+
},
|
471
|
+
(_retry) => {
|
472
|
+
},
|
473
|
+
onmessage
|
474
|
+
)
|
475
|
+
)
|
476
|
+
);
|
477
|
+
onclose?.();
|
478
|
+
dispose();
|
479
|
+
resolve();
|
480
|
+
} catch (err) {
|
481
|
+
}
|
482
|
+
}
|
483
|
+
create();
|
484
|
+
});
|
485
|
+
}
|
486
|
+
function defaultOnOpen(response) {
|
487
|
+
const contentType = response.headers?.get("content-type");
|
488
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
489
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
const VERSION = "0.24.2";
|
168
494
|
|
169
495
|
class ErrorWithCause extends Error {
|
170
496
|
constructor(message, options) {
|
@@ -175,7 +501,7 @@ class FetcherError extends ErrorWithCause {
|
|
175
501
|
constructor(status, data, requestId) {
|
176
502
|
super(getMessage(data));
|
177
503
|
this.status = status;
|
178
|
-
this.errors = isBulkError(data) ? data.errors :
|
504
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
179
505
|
this.requestId = requestId;
|
180
506
|
if (data instanceof Error) {
|
181
507
|
this.stack = data.stack;
|
@@ -207,6 +533,7 @@ function getMessage(data) {
|
|
207
533
|
}
|
208
534
|
}
|
209
535
|
|
536
|
+
const pool = new ApiRequestPool();
|
210
537
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
211
538
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
212
539
|
if (value === void 0 || value === null)
|
@@ -239,14 +566,15 @@ function hostHeader(url) {
|
|
239
566
|
const { groups } = pattern.exec(url) ?? {};
|
240
567
|
return groups?.host ? { Host: groups.host } : {};
|
241
568
|
}
|
569
|
+
const defaultClientID = generateUUID();
|
242
570
|
async function fetch$1({
|
243
571
|
url: path,
|
244
572
|
method,
|
245
573
|
body,
|
246
|
-
headers,
|
574
|
+
headers: customHeaders,
|
247
575
|
pathParams,
|
248
576
|
queryParams,
|
249
|
-
|
577
|
+
fetch: fetch2,
|
250
578
|
apiKey,
|
251
579
|
endpoint,
|
252
580
|
apiUrl,
|
@@ -254,9 +582,13 @@ async function fetch$1({
|
|
254
582
|
trace,
|
255
583
|
signal,
|
256
584
|
clientID,
|
257
|
-
sessionID
|
585
|
+
sessionID,
|
586
|
+
clientName,
|
587
|
+
xataAgentExtra,
|
588
|
+
fetchOptions = {}
|
258
589
|
}) {
|
259
|
-
|
590
|
+
pool.setFetch(fetch2);
|
591
|
+
return await trace(
|
260
592
|
`${method.toUpperCase()} ${path}`,
|
261
593
|
async ({ setAttributes }) => {
|
262
594
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
@@ -266,23 +598,29 @@ async function fetch$1({
|
|
266
598
|
[TraceAttributes.HTTP_URL]: url,
|
267
599
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
268
600
|
});
|
269
|
-
const
|
601
|
+
const xataAgent = compact([
|
602
|
+
["client", "TS_SDK"],
|
603
|
+
["version", VERSION],
|
604
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
605
|
+
...Object.entries(xataAgentExtra ?? {})
|
606
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
607
|
+
const headers = {
|
608
|
+
"Accept-Encoding": "identity",
|
609
|
+
"Content-Type": "application/json",
|
610
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
611
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
612
|
+
"X-Xata-Agent": xataAgent,
|
613
|
+
...customHeaders,
|
614
|
+
...hostHeader(fullUrl),
|
615
|
+
Authorization: `Bearer ${apiKey}`
|
616
|
+
};
|
617
|
+
const response = await pool.request(url, {
|
618
|
+
...fetchOptions,
|
270
619
|
method: method.toUpperCase(),
|
271
620
|
body: body ? JSON.stringify(body) : void 0,
|
272
|
-
headers
|
273
|
-
"Content-Type": "application/json",
|
274
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
275
|
-
"X-Xata-Client-ID": clientID ?? "",
|
276
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
277
|
-
...headers,
|
278
|
-
...hostHeader(fullUrl),
|
279
|
-
Authorization: `Bearer ${apiKey}`
|
280
|
-
},
|
621
|
+
headers,
|
281
622
|
signal
|
282
623
|
});
|
283
|
-
if (response.status === 204) {
|
284
|
-
return {};
|
285
|
-
}
|
286
624
|
const { host, protocol } = parseUrl(response.url);
|
287
625
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
288
626
|
setAttributes({
|
@@ -292,6 +630,12 @@ async function fetch$1({
|
|
292
630
|
[TraceAttributes.HTTP_HOST]: host,
|
293
631
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
294
632
|
});
|
633
|
+
if (response.status === 204) {
|
634
|
+
return {};
|
635
|
+
}
|
636
|
+
if (response.status === 429) {
|
637
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
638
|
+
}
|
295
639
|
try {
|
296
640
|
const jsonResponse = await response.json();
|
297
641
|
if (response.ok) {
|
@@ -305,6 +649,59 @@ async function fetch$1({
|
|
305
649
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
306
650
|
);
|
307
651
|
}
|
652
|
+
function fetchSSERequest({
|
653
|
+
url: path,
|
654
|
+
method,
|
655
|
+
body,
|
656
|
+
headers: customHeaders,
|
657
|
+
pathParams,
|
658
|
+
queryParams,
|
659
|
+
fetch: fetch2,
|
660
|
+
apiKey,
|
661
|
+
endpoint,
|
662
|
+
apiUrl,
|
663
|
+
workspacesApiUrl,
|
664
|
+
onMessage,
|
665
|
+
onError,
|
666
|
+
onClose,
|
667
|
+
signal,
|
668
|
+
clientID,
|
669
|
+
sessionID,
|
670
|
+
clientName,
|
671
|
+
xataAgentExtra
|
672
|
+
}) {
|
673
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
674
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
675
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
676
|
+
void fetchEventSource(url, {
|
677
|
+
method,
|
678
|
+
body: JSON.stringify(body),
|
679
|
+
fetch: fetch2,
|
680
|
+
signal,
|
681
|
+
headers: {
|
682
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
683
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
684
|
+
"X-Xata-Agent": compact([
|
685
|
+
["client", "TS_SDK"],
|
686
|
+
["version", VERSION],
|
687
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
688
|
+
...Object.entries(xataAgentExtra ?? {})
|
689
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
690
|
+
...customHeaders,
|
691
|
+
Authorization: `Bearer ${apiKey}`,
|
692
|
+
"Content-Type": "application/json"
|
693
|
+
},
|
694
|
+
onmessage(ev) {
|
695
|
+
onMessage?.(JSON.parse(ev.data));
|
696
|
+
},
|
697
|
+
onerror(ev) {
|
698
|
+
onError?.(JSON.parse(ev.data));
|
699
|
+
},
|
700
|
+
onclose() {
|
701
|
+
onClose?.();
|
702
|
+
}
|
703
|
+
});
|
704
|
+
}
|
308
705
|
function parseUrl(url) {
|
309
706
|
try {
|
310
707
|
const { host, protocol } = new URL(url);
|
@@ -316,17 +713,12 @@ function parseUrl(url) {
|
|
316
713
|
|
317
714
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
318
715
|
|
319
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
320
716
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
321
717
|
url: "/dbs/{dbName}",
|
322
718
|
method: "get",
|
323
719
|
...variables,
|
324
720
|
signal
|
325
721
|
});
|
326
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
327
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
328
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
329
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
330
722
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
331
723
|
url: "/db/{dbBranchName}",
|
332
724
|
method: "get",
|
@@ -340,6 +732,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
340
732
|
...variables,
|
341
733
|
signal
|
342
734
|
});
|
735
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
736
|
+
url: "/db/{dbBranchName}/copy",
|
737
|
+
method: "post",
|
738
|
+
...variables,
|
739
|
+
signal
|
740
|
+
});
|
343
741
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
344
742
|
url: "/db/{dbBranchName}/metadata",
|
345
743
|
method: "put",
|
@@ -389,6 +787,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
389
787
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
390
788
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
391
789
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
790
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
392
791
|
const createTable = (variables, signal) => dataPlaneFetch({
|
393
792
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
394
793
|
method: "put",
|
@@ -431,7 +830,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
431
830
|
...variables,
|
432
831
|
signal
|
433
832
|
});
|
833
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
434
834
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
835
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
836
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
837
|
+
method: "get",
|
838
|
+
...variables,
|
839
|
+
signal
|
840
|
+
});
|
841
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
842
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
843
|
+
method: "put",
|
844
|
+
...variables,
|
845
|
+
signal
|
846
|
+
});
|
847
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
848
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
849
|
+
method: "delete",
|
850
|
+
...variables,
|
851
|
+
signal
|
852
|
+
});
|
853
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
854
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
855
|
+
method: "get",
|
856
|
+
...variables,
|
857
|
+
signal
|
858
|
+
});
|
859
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
860
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
861
|
+
method: "put",
|
862
|
+
...variables,
|
863
|
+
signal
|
864
|
+
});
|
865
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
866
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
867
|
+
method: "delete",
|
868
|
+
...variables,
|
869
|
+
signal
|
870
|
+
});
|
435
871
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
436
872
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
437
873
|
method: "get",
|
@@ -461,21 +897,34 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
461
897
|
...variables,
|
462
898
|
signal
|
463
899
|
});
|
900
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
901
|
+
url: "/db/{dbBranchName}/sql",
|
902
|
+
method: "post",
|
903
|
+
...variables,
|
904
|
+
signal
|
905
|
+
});
|
906
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
907
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
908
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
909
|
+
method: "post",
|
910
|
+
...variables,
|
911
|
+
signal
|
912
|
+
});
|
464
913
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
465
914
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
915
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
916
|
+
url: "/file/{fileId}",
|
917
|
+
method: "get",
|
918
|
+
...variables,
|
919
|
+
signal
|
920
|
+
});
|
466
921
|
const operationsByTag$2 = {
|
467
|
-
database: {
|
468
|
-
dEPRECATEDgetDatabaseList,
|
469
|
-
dEPRECATEDcreateDatabase,
|
470
|
-
dEPRECATEDdeleteDatabase,
|
471
|
-
dEPRECATEDgetDatabaseMetadata,
|
472
|
-
dEPRECATEDupdateDatabaseMetadata
|
473
|
-
},
|
474
922
|
branch: {
|
475
923
|
getBranchList,
|
476
924
|
getBranchDetails,
|
477
925
|
createBranch,
|
478
926
|
deleteBranch,
|
927
|
+
copyBranch,
|
479
928
|
updateBranchMetadata,
|
480
929
|
getBranchMetadata,
|
481
930
|
getBranchStats,
|
@@ -493,7 +942,8 @@ const operationsByTag$2 = {
|
|
493
942
|
compareBranchSchemas,
|
494
943
|
updateBranchSchema,
|
495
944
|
previewBranchSchemaEdit,
|
496
|
-
applyBranchSchemaEdit
|
945
|
+
applyBranchSchemaEdit,
|
946
|
+
pushBranchMigrations
|
497
947
|
},
|
498
948
|
migrationRequests: {
|
499
949
|
queryMigrationRequests,
|
@@ -518,6 +968,7 @@ const operationsByTag$2 = {
|
|
518
968
|
deleteColumn
|
519
969
|
},
|
520
970
|
records: {
|
971
|
+
branchTransaction,
|
521
972
|
insertRecord,
|
522
973
|
getRecord,
|
523
974
|
insertRecordWithID,
|
@@ -526,7 +977,17 @@ const operationsByTag$2 = {
|
|
526
977
|
deleteRecord,
|
527
978
|
bulkInsertTableRecords
|
528
979
|
},
|
529
|
-
|
980
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
981
|
+
searchAndFilter: {
|
982
|
+
queryTable,
|
983
|
+
searchBranch,
|
984
|
+
searchTable,
|
985
|
+
sqlQuery,
|
986
|
+
vectorSearchTable,
|
987
|
+
askTable,
|
988
|
+
summarizeTable,
|
989
|
+
aggregateTable
|
990
|
+
}
|
530
991
|
};
|
531
992
|
|
532
993
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -625,6 +1086,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
625
1086
|
});
|
626
1087
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
627
1088
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1089
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1090
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1091
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1092
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
628
1093
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
629
1094
|
url: "/workspaces/{workspaceId}/regions",
|
630
1095
|
method: "get",
|
@@ -657,6 +1122,10 @@ const operationsByTag$1 = {
|
|
657
1122
|
deleteDatabase,
|
658
1123
|
getDatabaseMetadata,
|
659
1124
|
updateDatabaseMetadata,
|
1125
|
+
renameDatabase,
|
1126
|
+
getDatabaseGithubSettings,
|
1127
|
+
updateDatabaseGithubSettings,
|
1128
|
+
deleteDatabaseGithubSettings,
|
660
1129
|
listRegions
|
661
1130
|
}
|
662
1131
|
};
|
@@ -677,8 +1146,12 @@ const providers = {
|
|
677
1146
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
678
1147
|
},
|
679
1148
|
staging: {
|
680
|
-
main: "https://staging.
|
681
|
-
workspaces: "https://{workspaceId}.
|
1149
|
+
main: "https://api.staging-xata.dev",
|
1150
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1151
|
+
},
|
1152
|
+
dev: {
|
1153
|
+
main: "https://api.dev-xata.dev",
|
1154
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
682
1155
|
}
|
683
1156
|
};
|
684
1157
|
function isHostProviderAlias(alias) {
|
@@ -696,15 +1169,22 @@ function parseProviderString(provider = "production") {
|
|
696
1169
|
return null;
|
697
1170
|
return { main, workspaces };
|
698
1171
|
}
|
1172
|
+
function buildProviderString(provider) {
|
1173
|
+
if (isHostProviderAlias(provider))
|
1174
|
+
return provider;
|
1175
|
+
return `${provider.main},${provider.workspaces}`;
|
1176
|
+
}
|
699
1177
|
function parseWorkspacesUrlParts(url) {
|
700
1178
|
if (!isString(url))
|
701
1179
|
return null;
|
702
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
703
|
-
const
|
704
|
-
const
|
1180
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1181
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1182
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1183
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1184
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
705
1185
|
if (!match)
|
706
1186
|
return null;
|
707
|
-
return { workspace: match[1], region: match[2]
|
1187
|
+
return { workspace: match[1], region: match[2] };
|
708
1188
|
}
|
709
1189
|
|
710
1190
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -733,15 +1213,19 @@ class XataApiClient {
|
|
733
1213
|
const provider = options.host ?? "production";
|
734
1214
|
const apiKey = options.apiKey ?? getAPIKey();
|
735
1215
|
const trace = options.trace ?? defaultTrace;
|
1216
|
+
const clientID = generateUUID();
|
736
1217
|
if (!apiKey) {
|
737
1218
|
throw new Error("Could not resolve a valid apiKey");
|
738
1219
|
}
|
739
1220
|
__privateSet$7(this, _extraProps, {
|
740
1221
|
apiUrl: getHostUrl(provider, "main"),
|
741
1222
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
742
|
-
|
1223
|
+
fetch: getFetchImplementation(options.fetch),
|
743
1224
|
apiKey,
|
744
|
-
trace
|
1225
|
+
trace,
|
1226
|
+
clientName: options.clientName,
|
1227
|
+
xataAgentExtra: options.xataAgentExtra,
|
1228
|
+
clientID
|
745
1229
|
});
|
746
1230
|
}
|
747
1231
|
get user() {
|
@@ -794,6 +1278,11 @@ class XataApiClient {
|
|
794
1278
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
795
1279
|
return __privateGet$7(this, _namespaces).records;
|
796
1280
|
}
|
1281
|
+
get files() {
|
1282
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1283
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1284
|
+
return __privateGet$7(this, _namespaces).files;
|
1285
|
+
}
|
797
1286
|
get searchAndFilter() {
|
798
1287
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
799
1288
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1002,6 +1491,20 @@ class BranchApi {
|
|
1002
1491
|
...this.extraProps
|
1003
1492
|
});
|
1004
1493
|
}
|
1494
|
+
copyBranch({
|
1495
|
+
workspace,
|
1496
|
+
region,
|
1497
|
+
database,
|
1498
|
+
branch,
|
1499
|
+
destinationBranch,
|
1500
|
+
limit
|
1501
|
+
}) {
|
1502
|
+
return operationsByTag.branch.copyBranch({
|
1503
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1504
|
+
body: { destinationBranch, limit },
|
1505
|
+
...this.extraProps
|
1506
|
+
});
|
1507
|
+
}
|
1005
1508
|
updateBranchMetadata({
|
1006
1509
|
workspace,
|
1007
1510
|
region,
|
@@ -1321,25 +1824,196 @@ class RecordsApi {
|
|
1321
1824
|
id,
|
1322
1825
|
columns
|
1323
1826
|
}) {
|
1324
|
-
return operationsByTag.records.deleteRecord({
|
1325
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1326
|
-
queryParams: { columns },
|
1827
|
+
return operationsByTag.records.deleteRecord({
|
1828
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1829
|
+
queryParams: { columns },
|
1830
|
+
...this.extraProps
|
1831
|
+
});
|
1832
|
+
}
|
1833
|
+
bulkInsertTableRecords({
|
1834
|
+
workspace,
|
1835
|
+
region,
|
1836
|
+
database,
|
1837
|
+
branch,
|
1838
|
+
table,
|
1839
|
+
records,
|
1840
|
+
columns
|
1841
|
+
}) {
|
1842
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
1843
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1844
|
+
queryParams: { columns },
|
1845
|
+
body: { records },
|
1846
|
+
...this.extraProps
|
1847
|
+
});
|
1848
|
+
}
|
1849
|
+
branchTransaction({
|
1850
|
+
workspace,
|
1851
|
+
region,
|
1852
|
+
database,
|
1853
|
+
branch,
|
1854
|
+
operations
|
1855
|
+
}) {
|
1856
|
+
return operationsByTag.records.branchTransaction({
|
1857
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1858
|
+
body: { operations },
|
1859
|
+
...this.extraProps
|
1860
|
+
});
|
1861
|
+
}
|
1862
|
+
}
|
1863
|
+
class FilesApi {
|
1864
|
+
constructor(extraProps) {
|
1865
|
+
this.extraProps = extraProps;
|
1866
|
+
}
|
1867
|
+
getFileItem({
|
1868
|
+
workspace,
|
1869
|
+
region,
|
1870
|
+
database,
|
1871
|
+
branch,
|
1872
|
+
table,
|
1873
|
+
record,
|
1874
|
+
column,
|
1875
|
+
fileId
|
1876
|
+
}) {
|
1877
|
+
return operationsByTag.files.getFileItem({
|
1878
|
+
pathParams: {
|
1879
|
+
workspace,
|
1880
|
+
region,
|
1881
|
+
dbBranchName: `${database}:${branch}`,
|
1882
|
+
tableName: table,
|
1883
|
+
recordId: record,
|
1884
|
+
columnName: column,
|
1885
|
+
fileId
|
1886
|
+
},
|
1887
|
+
...this.extraProps
|
1888
|
+
});
|
1889
|
+
}
|
1890
|
+
putFileItem({
|
1891
|
+
workspace,
|
1892
|
+
region,
|
1893
|
+
database,
|
1894
|
+
branch,
|
1895
|
+
table,
|
1896
|
+
record,
|
1897
|
+
column,
|
1898
|
+
fileId,
|
1899
|
+
file
|
1900
|
+
}) {
|
1901
|
+
return operationsByTag.files.putFileItem({
|
1902
|
+
pathParams: {
|
1903
|
+
workspace,
|
1904
|
+
region,
|
1905
|
+
dbBranchName: `${database}:${branch}`,
|
1906
|
+
tableName: table,
|
1907
|
+
recordId: record,
|
1908
|
+
columnName: column,
|
1909
|
+
fileId
|
1910
|
+
},
|
1911
|
+
// @ts-ignore
|
1912
|
+
body: file,
|
1913
|
+
...this.extraProps
|
1914
|
+
});
|
1915
|
+
}
|
1916
|
+
deleteFileItem({
|
1917
|
+
workspace,
|
1918
|
+
region,
|
1919
|
+
database,
|
1920
|
+
branch,
|
1921
|
+
table,
|
1922
|
+
record,
|
1923
|
+
column,
|
1924
|
+
fileId
|
1925
|
+
}) {
|
1926
|
+
return operationsByTag.files.deleteFileItem({
|
1927
|
+
pathParams: {
|
1928
|
+
workspace,
|
1929
|
+
region,
|
1930
|
+
dbBranchName: `${database}:${branch}`,
|
1931
|
+
tableName: table,
|
1932
|
+
recordId: record,
|
1933
|
+
columnName: column,
|
1934
|
+
fileId
|
1935
|
+
},
|
1936
|
+
...this.extraProps
|
1937
|
+
});
|
1938
|
+
}
|
1939
|
+
getFile({
|
1940
|
+
workspace,
|
1941
|
+
region,
|
1942
|
+
database,
|
1943
|
+
branch,
|
1944
|
+
table,
|
1945
|
+
record,
|
1946
|
+
column
|
1947
|
+
}) {
|
1948
|
+
return operationsByTag.files.getFile({
|
1949
|
+
pathParams: {
|
1950
|
+
workspace,
|
1951
|
+
region,
|
1952
|
+
dbBranchName: `${database}:${branch}`,
|
1953
|
+
tableName: table,
|
1954
|
+
recordId: record,
|
1955
|
+
columnName: column
|
1956
|
+
},
|
1957
|
+
...this.extraProps
|
1958
|
+
});
|
1959
|
+
}
|
1960
|
+
putFile({
|
1961
|
+
workspace,
|
1962
|
+
region,
|
1963
|
+
database,
|
1964
|
+
branch,
|
1965
|
+
table,
|
1966
|
+
record,
|
1967
|
+
column,
|
1968
|
+
file
|
1969
|
+
}) {
|
1970
|
+
return operationsByTag.files.putFile({
|
1971
|
+
pathParams: {
|
1972
|
+
workspace,
|
1973
|
+
region,
|
1974
|
+
dbBranchName: `${database}:${branch}`,
|
1975
|
+
tableName: table,
|
1976
|
+
recordId: record,
|
1977
|
+
columnName: column
|
1978
|
+
},
|
1979
|
+
body: file,
|
1980
|
+
...this.extraProps
|
1981
|
+
});
|
1982
|
+
}
|
1983
|
+
deleteFile({
|
1984
|
+
workspace,
|
1985
|
+
region,
|
1986
|
+
database,
|
1987
|
+
branch,
|
1988
|
+
table,
|
1989
|
+
record,
|
1990
|
+
column
|
1991
|
+
}) {
|
1992
|
+
return operationsByTag.files.deleteFile({
|
1993
|
+
pathParams: {
|
1994
|
+
workspace,
|
1995
|
+
region,
|
1996
|
+
dbBranchName: `${database}:${branch}`,
|
1997
|
+
tableName: table,
|
1998
|
+
recordId: record,
|
1999
|
+
columnName: column
|
2000
|
+
},
|
1327
2001
|
...this.extraProps
|
1328
2002
|
});
|
1329
2003
|
}
|
1330
|
-
|
2004
|
+
fileAccess({
|
1331
2005
|
workspace,
|
1332
2006
|
region,
|
1333
|
-
|
1334
|
-
|
1335
|
-
table,
|
1336
|
-
records,
|
1337
|
-
columns
|
2007
|
+
fileId,
|
2008
|
+
verify
|
1338
2009
|
}) {
|
1339
|
-
return operationsByTag.
|
1340
|
-
pathParams: {
|
1341
|
-
|
1342
|
-
|
2010
|
+
return operationsByTag.files.fileAccess({
|
2011
|
+
pathParams: {
|
2012
|
+
workspace,
|
2013
|
+
region,
|
2014
|
+
fileId
|
2015
|
+
},
|
2016
|
+
queryParams: { verify },
|
1343
2017
|
...this.extraProps
|
1344
2018
|
});
|
1345
2019
|
}
|
@@ -1357,11 +2031,12 @@ class SearchAndFilterApi {
|
|
1357
2031
|
filter,
|
1358
2032
|
sort,
|
1359
2033
|
page,
|
1360
|
-
columns
|
2034
|
+
columns,
|
2035
|
+
consistency
|
1361
2036
|
}) {
|
1362
2037
|
return operationsByTag.searchAndFilter.queryTable({
|
1363
2038
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1364
|
-
body: { filter, sort, page, columns },
|
2039
|
+
body: { filter, sort, page, columns, consistency },
|
1365
2040
|
...this.extraProps
|
1366
2041
|
});
|
1367
2042
|
}
|
@@ -1402,6 +2077,38 @@ class SearchAndFilterApi {
|
|
1402
2077
|
...this.extraProps
|
1403
2078
|
});
|
1404
2079
|
}
|
2080
|
+
vectorSearchTable({
|
2081
|
+
workspace,
|
2082
|
+
region,
|
2083
|
+
database,
|
2084
|
+
branch,
|
2085
|
+
table,
|
2086
|
+
queryVector,
|
2087
|
+
column,
|
2088
|
+
similarityFunction,
|
2089
|
+
size,
|
2090
|
+
filter
|
2091
|
+
}) {
|
2092
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2093
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2094
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2095
|
+
...this.extraProps
|
2096
|
+
});
|
2097
|
+
}
|
2098
|
+
askTable({
|
2099
|
+
workspace,
|
2100
|
+
region,
|
2101
|
+
database,
|
2102
|
+
branch,
|
2103
|
+
table,
|
2104
|
+
options
|
2105
|
+
}) {
|
2106
|
+
return operationsByTag.searchAndFilter.askTable({
|
2107
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2108
|
+
body: { ...options },
|
2109
|
+
...this.extraProps
|
2110
|
+
});
|
2111
|
+
}
|
1405
2112
|
summarizeTable({
|
1406
2113
|
workspace,
|
1407
2114
|
region,
|
@@ -1413,11 +2120,12 @@ class SearchAndFilterApi {
|
|
1413
2120
|
summaries,
|
1414
2121
|
sort,
|
1415
2122
|
summariesFilter,
|
1416
|
-
page
|
2123
|
+
page,
|
2124
|
+
consistency
|
1417
2125
|
}) {
|
1418
2126
|
return operationsByTag.searchAndFilter.summarizeTable({
|
1419
2127
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1420
|
-
body: { filter, columns, summaries, sort, summariesFilter, page },
|
2128
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
1421
2129
|
...this.extraProps
|
1422
2130
|
});
|
1423
2131
|
}
|
@@ -1601,11 +2309,13 @@ class MigrationsApi {
|
|
1601
2309
|
region,
|
1602
2310
|
database,
|
1603
2311
|
branch,
|
1604
|
-
schema
|
2312
|
+
schema,
|
2313
|
+
schemaOperations,
|
2314
|
+
branchOperations
|
1605
2315
|
}) {
|
1606
2316
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1607
2317
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1608
|
-
body: { schema },
|
2318
|
+
body: { schema, schemaOperations, branchOperations },
|
1609
2319
|
...this.extraProps
|
1610
2320
|
});
|
1611
2321
|
}
|
@@ -1615,11 +2325,12 @@ class MigrationsApi {
|
|
1615
2325
|
database,
|
1616
2326
|
branch,
|
1617
2327
|
compare,
|
1618
|
-
|
2328
|
+
sourceBranchOperations,
|
2329
|
+
targetBranchOperations
|
1619
2330
|
}) {
|
1620
2331
|
return operationsByTag.migrations.compareBranchSchemas({
|
1621
2332
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1622
|
-
body: {
|
2333
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1623
2334
|
...this.extraProps
|
1624
2335
|
});
|
1625
2336
|
}
|
@@ -1662,6 +2373,19 @@ class MigrationsApi {
|
|
1662
2373
|
...this.extraProps
|
1663
2374
|
});
|
1664
2375
|
}
|
2376
|
+
pushBranchMigrations({
|
2377
|
+
workspace,
|
2378
|
+
region,
|
2379
|
+
database,
|
2380
|
+
branch,
|
2381
|
+
migrations
|
2382
|
+
}) {
|
2383
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2384
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2385
|
+
body: { migrations },
|
2386
|
+
...this.extraProps
|
2387
|
+
});
|
2388
|
+
}
|
1665
2389
|
}
|
1666
2390
|
class DatabaseApi {
|
1667
2391
|
constructor(extraProps) {
|
@@ -1713,6 +2437,46 @@ class DatabaseApi {
|
|
1713
2437
|
...this.extraProps
|
1714
2438
|
});
|
1715
2439
|
}
|
2440
|
+
renameDatabase({
|
2441
|
+
workspace,
|
2442
|
+
database,
|
2443
|
+
newName
|
2444
|
+
}) {
|
2445
|
+
return operationsByTag.databases.renameDatabase({
|
2446
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2447
|
+
body: { newName },
|
2448
|
+
...this.extraProps
|
2449
|
+
});
|
2450
|
+
}
|
2451
|
+
getDatabaseGithubSettings({
|
2452
|
+
workspace,
|
2453
|
+
database
|
2454
|
+
}) {
|
2455
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2456
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2457
|
+
...this.extraProps
|
2458
|
+
});
|
2459
|
+
}
|
2460
|
+
updateDatabaseGithubSettings({
|
2461
|
+
workspace,
|
2462
|
+
database,
|
2463
|
+
settings
|
2464
|
+
}) {
|
2465
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2466
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2467
|
+
body: settings,
|
2468
|
+
...this.extraProps
|
2469
|
+
});
|
2470
|
+
}
|
2471
|
+
deleteDatabaseGithubSettings({
|
2472
|
+
workspace,
|
2473
|
+
database
|
2474
|
+
}) {
|
2475
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2476
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2477
|
+
...this.extraProps
|
2478
|
+
});
|
2479
|
+
}
|
1716
2480
|
listRegions({ workspace }) {
|
1717
2481
|
return operationsByTag.databases.listRegions({
|
1718
2482
|
pathParams: { workspaceId: workspace },
|
@@ -1722,22 +2486,14 @@ class DatabaseApi {
|
|
1722
2486
|
}
|
1723
2487
|
|
1724
2488
|
class XataApiPlugin {
|
1725
|
-
|
1726
|
-
|
1727
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2489
|
+
build(options) {
|
2490
|
+
return new XataApiClient(options);
|
1728
2491
|
}
|
1729
2492
|
}
|
1730
2493
|
|
1731
2494
|
class XataPlugin {
|
1732
2495
|
}
|
1733
2496
|
|
1734
|
-
function generateUUID() {
|
1735
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1736
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1737
|
-
return v.toString(16);
|
1738
|
-
});
|
1739
|
-
}
|
1740
|
-
|
1741
2497
|
function cleanFilter(filter) {
|
1742
2498
|
if (!filter)
|
1743
2499
|
return void 0;
|
@@ -1771,18 +2527,46 @@ class Page {
|
|
1771
2527
|
this.meta = meta;
|
1772
2528
|
this.records = new RecordArray(this, records);
|
1773
2529
|
}
|
2530
|
+
/**
|
2531
|
+
* Retrieves the next page of results.
|
2532
|
+
* @param size Maximum number of results to be retrieved.
|
2533
|
+
* @param offset Number of results to skip when retrieving the results.
|
2534
|
+
* @returns The next page or results.
|
2535
|
+
*/
|
1774
2536
|
async nextPage(size, offset) {
|
1775
2537
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1776
2538
|
}
|
2539
|
+
/**
|
2540
|
+
* Retrieves the previous page of results.
|
2541
|
+
* @param size Maximum number of results to be retrieved.
|
2542
|
+
* @param offset Number of results to skip when retrieving the results.
|
2543
|
+
* @returns The previous page or results.
|
2544
|
+
*/
|
1777
2545
|
async previousPage(size, offset) {
|
1778
2546
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1779
2547
|
}
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
2548
|
+
/**
|
2549
|
+
* Retrieves the start page of results.
|
2550
|
+
* @param size Maximum number of results to be retrieved.
|
2551
|
+
* @param offset Number of results to skip when retrieving the results.
|
2552
|
+
* @returns The start page or results.
|
2553
|
+
*/
|
2554
|
+
async startPage(size, offset) {
|
2555
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
2556
|
+
}
|
2557
|
+
/**
|
2558
|
+
* Retrieves the end page of results.
|
2559
|
+
* @param size Maximum number of results to be retrieved.
|
2560
|
+
* @param offset Number of results to skip when retrieving the results.
|
2561
|
+
* @returns The end page or results.
|
2562
|
+
*/
|
2563
|
+
async endPage(size, offset) {
|
2564
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
2565
|
+
}
|
2566
|
+
/**
|
2567
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2568
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2569
|
+
*/
|
1786
2570
|
hasNextPage() {
|
1787
2571
|
return this.meta.page.more;
|
1788
2572
|
}
|
@@ -1793,7 +2577,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
|
|
1793
2577
|
const PAGINATION_MAX_OFFSET = 800;
|
1794
2578
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1795
2579
|
function isCursorPaginationOptions(options) {
|
1796
|
-
return isDefined(options) && (isDefined(options.
|
2580
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1797
2581
|
}
|
1798
2582
|
const _RecordArray = class extends Array {
|
1799
2583
|
constructor(...args) {
|
@@ -1814,25 +2598,54 @@ const _RecordArray = class extends Array {
|
|
1814
2598
|
toArray() {
|
1815
2599
|
return new Array(...this);
|
1816
2600
|
}
|
2601
|
+
toSerializable() {
|
2602
|
+
return JSON.parse(this.toString());
|
2603
|
+
}
|
2604
|
+
toString() {
|
2605
|
+
return JSON.stringify(this.toArray());
|
2606
|
+
}
|
1817
2607
|
map(callbackfn, thisArg) {
|
1818
2608
|
return this.toArray().map(callbackfn, thisArg);
|
1819
2609
|
}
|
2610
|
+
/**
|
2611
|
+
* Retrieve next page of records
|
2612
|
+
*
|
2613
|
+
* @returns A new array of objects
|
2614
|
+
*/
|
1820
2615
|
async nextPage(size, offset) {
|
1821
2616
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1822
2617
|
return new _RecordArray(newPage);
|
1823
2618
|
}
|
2619
|
+
/**
|
2620
|
+
* Retrieve previous page of records
|
2621
|
+
*
|
2622
|
+
* @returns A new array of objects
|
2623
|
+
*/
|
1824
2624
|
async previousPage(size, offset) {
|
1825
2625
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1826
2626
|
return new _RecordArray(newPage);
|
1827
2627
|
}
|
1828
|
-
|
1829
|
-
|
2628
|
+
/**
|
2629
|
+
* Retrieve start page of records
|
2630
|
+
*
|
2631
|
+
* @returns A new array of objects
|
2632
|
+
*/
|
2633
|
+
async startPage(size, offset) {
|
2634
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1830
2635
|
return new _RecordArray(newPage);
|
1831
2636
|
}
|
1832
|
-
|
1833
|
-
|
2637
|
+
/**
|
2638
|
+
* Retrieve end page of records
|
2639
|
+
*
|
2640
|
+
* @returns A new array of objects
|
2641
|
+
*/
|
2642
|
+
async endPage(size, offset) {
|
2643
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1834
2644
|
return new _RecordArray(newPage);
|
1835
2645
|
}
|
2646
|
+
/**
|
2647
|
+
* @returns Boolean indicating if there is a next page
|
2648
|
+
*/
|
1836
2649
|
hasNextPage() {
|
1837
2650
|
return __privateGet$6(this, _page).meta.page.more;
|
1838
2651
|
}
|
@@ -1869,7 +2682,8 @@ const _Query = class {
|
|
1869
2682
|
__privateAdd$5(this, _table$1, void 0);
|
1870
2683
|
__privateAdd$5(this, _repository, void 0);
|
1871
2684
|
__privateAdd$5(this, _data, { filter: {} });
|
1872
|
-
|
2685
|
+
// Implements pagination
|
2686
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1873
2687
|
this.records = new RecordArray(this, []);
|
1874
2688
|
__privateSet$5(this, _table$1, table);
|
1875
2689
|
if (repository) {
|
@@ -1885,8 +2699,10 @@ const _Query = class {
|
|
1885
2699
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1886
2700
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1887
2701
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
2702
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1888
2703
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1889
2704
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2705
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1890
2706
|
this.any = this.any.bind(this);
|
1891
2707
|
this.all = this.all.bind(this);
|
1892
2708
|
this.not = this.not.bind(this);
|
@@ -1904,18 +2720,38 @@ const _Query = class {
|
|
1904
2720
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1905
2721
|
return toBase64(key);
|
1906
2722
|
}
|
2723
|
+
/**
|
2724
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
2725
|
+
* @param queries An array of subqueries.
|
2726
|
+
* @returns A new Query object.
|
2727
|
+
*/
|
1907
2728
|
any(...queries) {
|
1908
2729
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1909
2730
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
1910
2731
|
}
|
2732
|
+
/**
|
2733
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
2734
|
+
* @param queries An array of subqueries.
|
2735
|
+
* @returns A new Query object.
|
2736
|
+
*/
|
1911
2737
|
all(...queries) {
|
1912
2738
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1913
2739
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1914
2740
|
}
|
2741
|
+
/**
|
2742
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
2743
|
+
* @param queries An array of subqueries.
|
2744
|
+
* @returns A new Query object.
|
2745
|
+
*/
|
1915
2746
|
not(...queries) {
|
1916
2747
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1917
2748
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
1918
2749
|
}
|
2750
|
+
/**
|
2751
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
2752
|
+
* @param queries An array of subqueries.
|
2753
|
+
* @returns A new Query object.
|
2754
|
+
*/
|
1919
2755
|
none(...queries) {
|
1920
2756
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1921
2757
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -1938,6 +2774,11 @@ const _Query = class {
|
|
1938
2774
|
const sort = [...originalSort, { column, direction }];
|
1939
2775
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1940
2776
|
}
|
2777
|
+
/**
|
2778
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
2779
|
+
* @param columns Array of column names to be returned by the query.
|
2780
|
+
* @returns A new Query object.
|
2781
|
+
*/
|
1941
2782
|
select(columns) {
|
1942
2783
|
return new _Query(
|
1943
2784
|
__privateGet$5(this, _repository),
|
@@ -1950,6 +2791,12 @@ const _Query = class {
|
|
1950
2791
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1951
2792
|
return __privateGet$5(this, _repository).query(query);
|
1952
2793
|
}
|
2794
|
+
/**
|
2795
|
+
* Get results in an iterator
|
2796
|
+
*
|
2797
|
+
* @async
|
2798
|
+
* @returns Async interable of results
|
2799
|
+
*/
|
1953
2800
|
async *[Symbol.asyncIterator]() {
|
1954
2801
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1955
2802
|
yield record;
|
@@ -2010,21 +2857,49 @@ const _Query = class {
|
|
2010
2857
|
);
|
2011
2858
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2012
2859
|
}
|
2860
|
+
/**
|
2861
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
2862
|
+
* @param ttl The cache TTL in milliseconds.
|
2863
|
+
* @returns A new Query object.
|
2864
|
+
*/
|
2013
2865
|
cache(ttl) {
|
2014
2866
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2015
2867
|
}
|
2868
|
+
/**
|
2869
|
+
* Retrieve next page of records
|
2870
|
+
*
|
2871
|
+
* @returns A new page object.
|
2872
|
+
*/
|
2016
2873
|
nextPage(size, offset) {
|
2017
|
-
return this.
|
2874
|
+
return this.startPage(size, offset);
|
2018
2875
|
}
|
2876
|
+
/**
|
2877
|
+
* Retrieve previous page of records
|
2878
|
+
*
|
2879
|
+
* @returns A new page object
|
2880
|
+
*/
|
2019
2881
|
previousPage(size, offset) {
|
2020
|
-
return this.
|
2021
|
-
}
|
2022
|
-
|
2882
|
+
return this.startPage(size, offset);
|
2883
|
+
}
|
2884
|
+
/**
|
2885
|
+
* Retrieve start page of records
|
2886
|
+
*
|
2887
|
+
* @returns A new page object
|
2888
|
+
*/
|
2889
|
+
startPage(size, offset) {
|
2023
2890
|
return this.getPaginated({ pagination: { size, offset } });
|
2024
2891
|
}
|
2025
|
-
|
2892
|
+
/**
|
2893
|
+
* Retrieve last page of records
|
2894
|
+
*
|
2895
|
+
* @returns A new page object
|
2896
|
+
*/
|
2897
|
+
endPage(size, offset) {
|
2026
2898
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2027
2899
|
}
|
2900
|
+
/**
|
2901
|
+
* @returns Boolean indicating if there is a next page
|
2902
|
+
*/
|
2028
2903
|
hasNextPage() {
|
2029
2904
|
return this.meta.page.more;
|
2030
2905
|
}
|
@@ -2064,7 +2939,11 @@ function isSortFilterString(value) {
|
|
2064
2939
|
return isString(value);
|
2065
2940
|
}
|
2066
2941
|
function isSortFilterBase(filter) {
|
2067
|
-
return isObject(filter) && Object.
|
2942
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
2943
|
+
if (key === "*")
|
2944
|
+
return value === "random";
|
2945
|
+
return value === "asc" || value === "desc";
|
2946
|
+
});
|
2068
2947
|
}
|
2069
2948
|
function isSortFilterObject(filter) {
|
2070
2949
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2105,7 +2984,8 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2105
2984
|
__accessCheck$4(obj, member, "access private method");
|
2106
2985
|
return method;
|
2107
2986
|
};
|
2108
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2987
|
+
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;
|
2988
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2109
2989
|
class Repository extends Query {
|
2110
2990
|
}
|
2111
2991
|
class RestRepository extends Query {
|
@@ -2117,10 +2997,12 @@ class RestRepository extends Query {
|
|
2117
2997
|
);
|
2118
2998
|
__privateAdd$4(this, _insertRecordWithoutId);
|
2119
2999
|
__privateAdd$4(this, _insertRecordWithId);
|
2120
|
-
__privateAdd$4(this,
|
3000
|
+
__privateAdd$4(this, _insertRecords);
|
2121
3001
|
__privateAdd$4(this, _updateRecordWithID);
|
3002
|
+
__privateAdd$4(this, _updateRecords);
|
2122
3003
|
__privateAdd$4(this, _upsertRecordWithID);
|
2123
3004
|
__privateAdd$4(this, _deleteRecord);
|
3005
|
+
__privateAdd$4(this, _deleteRecords);
|
2124
3006
|
__privateAdd$4(this, _setCacheQuery);
|
2125
3007
|
__privateAdd$4(this, _getCacheQuery);
|
2126
3008
|
__privateAdd$4(this, _getSchemaTables$1);
|
@@ -2134,10 +3016,7 @@ class RestRepository extends Query {
|
|
2134
3016
|
__privateSet$4(this, _db, options.db);
|
2135
3017
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2136
3018
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2137
|
-
__privateSet$4(this, _getFetchProps,
|
2138
|
-
const props = await options.pluginOptions.getFetchProps();
|
2139
|
-
return { ...props, sessionID: generateUUID() };
|
2140
|
-
});
|
3019
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2141
3020
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2142
3021
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2143
3022
|
return trace(name, fn, {
|
@@ -2154,20 +3033,22 @@ class RestRepository extends Query {
|
|
2154
3033
|
if (Array.isArray(a)) {
|
2155
3034
|
if (a.length === 0)
|
2156
3035
|
return [];
|
2157
|
-
const
|
2158
|
-
|
3036
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3037
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3038
|
+
const result = await this.read(ids, columns);
|
3039
|
+
return result;
|
2159
3040
|
}
|
2160
3041
|
if (isString(a) && isObject(b)) {
|
2161
3042
|
if (a === "")
|
2162
3043
|
throw new Error("The id can't be empty");
|
2163
3044
|
const columns = isStringArray(c) ? c : void 0;
|
2164
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3045
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2165
3046
|
}
|
2166
3047
|
if (isObject(a) && isString(a.id)) {
|
2167
3048
|
if (a.id === "")
|
2168
3049
|
throw new Error("The id can't be empty");
|
2169
3050
|
const columns = isStringArray(b) ? b : void 0;
|
2170
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3051
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2171
3052
|
}
|
2172
3053
|
if (isObject(a)) {
|
2173
3054
|
const columns = isStringArray(b) ? b : void 0;
|
@@ -2192,7 +3073,6 @@ class RestRepository extends Query {
|
|
2192
3073
|
}
|
2193
3074
|
const id = extractId(a);
|
2194
3075
|
if (id) {
|
2195
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2196
3076
|
try {
|
2197
3077
|
const response = await getRecord({
|
2198
3078
|
pathParams: {
|
@@ -2203,7 +3083,7 @@ class RestRepository extends Query {
|
|
2203
3083
|
recordId: id
|
2204
3084
|
},
|
2205
3085
|
queryParams: { columns },
|
2206
|
-
...
|
3086
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2207
3087
|
});
|
2208
3088
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2209
3089
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2242,19 +3122,29 @@ class RestRepository extends Query {
|
|
2242
3122
|
if (Array.isArray(a)) {
|
2243
3123
|
if (a.length === 0)
|
2244
3124
|
return [];
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
3125
|
+
const existing = await this.read(a, ["id"]);
|
3126
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
3127
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
3128
|
+
ifVersion,
|
3129
|
+
upsert: false
|
3130
|
+
});
|
2248
3131
|
const columns = isStringArray(b) ? b : ["*"];
|
2249
|
-
|
2250
|
-
|
2251
|
-
if (isString(a) && isObject(b)) {
|
2252
|
-
const columns = isStringArray(c) ? c : void 0;
|
2253
|
-
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3132
|
+
const result = await this.read(a, columns);
|
3133
|
+
return result;
|
2254
3134
|
}
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
3135
|
+
try {
|
3136
|
+
if (isString(a) && isObject(b)) {
|
3137
|
+
const columns = isStringArray(c) ? c : void 0;
|
3138
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3139
|
+
}
|
3140
|
+
if (isObject(a) && isString(a.id)) {
|
3141
|
+
const columns = isStringArray(b) ? b : void 0;
|
3142
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3143
|
+
}
|
3144
|
+
} catch (error) {
|
3145
|
+
if (error.status === 422)
|
3146
|
+
return null;
|
3147
|
+
throw error;
|
2258
3148
|
}
|
2259
3149
|
throw new Error("Invalid arguments for update method");
|
2260
3150
|
});
|
@@ -2284,19 +3174,31 @@ class RestRepository extends Query {
|
|
2284
3174
|
if (Array.isArray(a)) {
|
2285
3175
|
if (a.length === 0)
|
2286
3176
|
return [];
|
2287
|
-
|
2288
|
-
|
2289
|
-
|
3177
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
3178
|
+
ifVersion,
|
3179
|
+
upsert: true
|
3180
|
+
});
|
2290
3181
|
const columns = isStringArray(b) ? b : ["*"];
|
2291
|
-
|
3182
|
+
const result = await this.read(a, columns);
|
3183
|
+
return result;
|
2292
3184
|
}
|
2293
3185
|
if (isString(a) && isObject(b)) {
|
3186
|
+
if (a === "")
|
3187
|
+
throw new Error("The id can't be empty");
|
2294
3188
|
const columns = isStringArray(c) ? c : void 0;
|
2295
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3189
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2296
3190
|
}
|
2297
3191
|
if (isObject(a) && isString(a.id)) {
|
3192
|
+
if (a.id === "")
|
3193
|
+
throw new Error("The id can't be empty");
|
2298
3194
|
const columns = isStringArray(c) ? c : void 0;
|
2299
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3195
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3196
|
+
}
|
3197
|
+
if (!isDefined(a) && isObject(b)) {
|
3198
|
+
return await this.create(b, c);
|
3199
|
+
}
|
3200
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3201
|
+
return await this.create(a, b);
|
2300
3202
|
}
|
2301
3203
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2302
3204
|
});
|
@@ -2307,16 +3209,28 @@ class RestRepository extends Query {
|
|
2307
3209
|
if (Array.isArray(a)) {
|
2308
3210
|
if (a.length === 0)
|
2309
3211
|
return [];
|
3212
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2310
3213
|
const columns = isStringArray(b) ? b : ["*"];
|
2311
|
-
|
3214
|
+
const result = await this.read(ids, columns);
|
3215
|
+
return result;
|
2312
3216
|
}
|
2313
3217
|
if (isString(a) && isObject(b)) {
|
3218
|
+
if (a === "")
|
3219
|
+
throw new Error("The id can't be empty");
|
2314
3220
|
const columns = isStringArray(c) ? c : void 0;
|
2315
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3221
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2316
3222
|
}
|
2317
3223
|
if (isObject(a) && isString(a.id)) {
|
3224
|
+
if (a.id === "")
|
3225
|
+
throw new Error("The id can't be empty");
|
2318
3226
|
const columns = isStringArray(c) ? c : void 0;
|
2319
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3227
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3228
|
+
}
|
3229
|
+
if (!isDefined(a) && isObject(b)) {
|
3230
|
+
return await this.create(b, c);
|
3231
|
+
}
|
3232
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3233
|
+
return await this.create(a, b);
|
2320
3234
|
}
|
2321
3235
|
throw new Error("Invalid arguments for createOrReplace method");
|
2322
3236
|
});
|
@@ -2326,10 +3240,17 @@ class RestRepository extends Query {
|
|
2326
3240
|
if (Array.isArray(a)) {
|
2327
3241
|
if (a.length === 0)
|
2328
3242
|
return [];
|
2329
|
-
|
2330
|
-
|
2331
|
-
|
2332
|
-
|
3243
|
+
const ids = a.map((o) => {
|
3244
|
+
if (isString(o))
|
3245
|
+
return o;
|
3246
|
+
if (isString(o.id))
|
3247
|
+
return o.id;
|
3248
|
+
throw new Error("Invalid arguments for delete method");
|
3249
|
+
});
|
3250
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3251
|
+
const result = await this.read(a, columns);
|
3252
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3253
|
+
return result;
|
2333
3254
|
}
|
2334
3255
|
if (isString(a)) {
|
2335
3256
|
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
@@ -2360,7 +3281,6 @@ class RestRepository extends Query {
|
|
2360
3281
|
}
|
2361
3282
|
async search(query, options = {}) {
|
2362
3283
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2363
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2364
3284
|
const { records } = await searchTable({
|
2365
3285
|
pathParams: {
|
2366
3286
|
workspace: "{workspaceId}",
|
@@ -2374,9 +3294,33 @@ class RestRepository extends Query {
|
|
2374
3294
|
prefix: options.prefix,
|
2375
3295
|
highlight: options.highlight,
|
2376
3296
|
filter: options.filter,
|
2377
|
-
boosters: options.boosters
|
3297
|
+
boosters: options.boosters,
|
3298
|
+
page: options.page,
|
3299
|
+
target: options.target
|
3300
|
+
},
|
3301
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3302
|
+
});
|
3303
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3304
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3305
|
+
});
|
3306
|
+
}
|
3307
|
+
async vectorSearch(column, query, options) {
|
3308
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3309
|
+
const { records } = await vectorSearchTable({
|
3310
|
+
pathParams: {
|
3311
|
+
workspace: "{workspaceId}",
|
3312
|
+
dbBranchName: "{dbBranch}",
|
3313
|
+
region: "{region}",
|
3314
|
+
tableName: __privateGet$4(this, _table)
|
3315
|
+
},
|
3316
|
+
body: {
|
3317
|
+
column,
|
3318
|
+
queryVector: query,
|
3319
|
+
similarityFunction: options?.similarityFunction,
|
3320
|
+
size: options?.size,
|
3321
|
+
filter: options?.filter
|
2378
3322
|
},
|
2379
|
-
...
|
3323
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2380
3324
|
});
|
2381
3325
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2382
3326
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2384,7 +3328,6 @@ class RestRepository extends Query {
|
|
2384
3328
|
}
|
2385
3329
|
async aggregate(aggs, filter) {
|
2386
3330
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2387
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2388
3331
|
const result = await aggregateTable({
|
2389
3332
|
pathParams: {
|
2390
3333
|
workspace: "{workspaceId}",
|
@@ -2393,7 +3336,7 @@ class RestRepository extends Query {
|
|
2393
3336
|
tableName: __privateGet$4(this, _table)
|
2394
3337
|
},
|
2395
3338
|
body: { aggs, filter },
|
2396
|
-
...
|
3339
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2397
3340
|
});
|
2398
3341
|
return result;
|
2399
3342
|
});
|
@@ -2404,7 +3347,6 @@ class RestRepository extends Query {
|
|
2404
3347
|
if (cacheQuery)
|
2405
3348
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2406
3349
|
const data = query.getQueryOptions();
|
2407
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2408
3350
|
const { meta, records: objects } = await queryTable({
|
2409
3351
|
pathParams: {
|
2410
3352
|
workspace: "{workspaceId}",
|
@@ -2416,9 +3358,11 @@ class RestRepository extends Query {
|
|
2416
3358
|
filter: cleanFilter(data.filter),
|
2417
3359
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2418
3360
|
page: data.pagination,
|
2419
|
-
columns: data.columns ?? ["*"]
|
3361
|
+
columns: data.columns ?? ["*"],
|
3362
|
+
consistency: data.consistency
|
2420
3363
|
},
|
2421
|
-
|
3364
|
+
fetchOptions: data.fetchOptions,
|
3365
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2422
3366
|
});
|
2423
3367
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2424
3368
|
const records = objects.map(
|
@@ -2431,7 +3375,6 @@ class RestRepository extends Query {
|
|
2431
3375
|
async summarizeTable(query, summaries, summariesFilter) {
|
2432
3376
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2433
3377
|
const data = query.getQueryOptions();
|
2434
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2435
3378
|
const result = await summarizeTable({
|
2436
3379
|
pathParams: {
|
2437
3380
|
workspace: "{workspaceId}",
|
@@ -2443,15 +3386,44 @@ class RestRepository extends Query {
|
|
2443
3386
|
filter: cleanFilter(data.filter),
|
2444
3387
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2445
3388
|
columns: data.columns,
|
3389
|
+
consistency: data.consistency,
|
2446
3390
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2447
3391
|
summaries,
|
2448
3392
|
summariesFilter
|
2449
3393
|
},
|
2450
|
-
...
|
3394
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2451
3395
|
});
|
2452
3396
|
return result;
|
2453
3397
|
});
|
2454
3398
|
}
|
3399
|
+
ask(question, options) {
|
3400
|
+
const params = {
|
3401
|
+
pathParams: {
|
3402
|
+
workspace: "{workspaceId}",
|
3403
|
+
dbBranchName: "{dbBranch}",
|
3404
|
+
region: "{region}",
|
3405
|
+
tableName: __privateGet$4(this, _table)
|
3406
|
+
},
|
3407
|
+
body: {
|
3408
|
+
question,
|
3409
|
+
...options
|
3410
|
+
},
|
3411
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3412
|
+
};
|
3413
|
+
if (options?.onMessage) {
|
3414
|
+
fetchSSERequest({
|
3415
|
+
endpoint: "dataPlane",
|
3416
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3417
|
+
method: "POST",
|
3418
|
+
onMessage: (message) => {
|
3419
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3420
|
+
},
|
3421
|
+
...params
|
3422
|
+
});
|
3423
|
+
} else {
|
3424
|
+
return askTable(params);
|
3425
|
+
}
|
3426
|
+
}
|
2455
3427
|
}
|
2456
3428
|
_table = new WeakMap();
|
2457
3429
|
_getFetchProps = new WeakMap();
|
@@ -2461,7 +3433,6 @@ _schemaTables$2 = new WeakMap();
|
|
2461
3433
|
_trace = new WeakMap();
|
2462
3434
|
_insertRecordWithoutId = new WeakSet();
|
2463
3435
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2464
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2465
3436
|
const record = transformObjectLinks(object);
|
2466
3437
|
const response = await insertRecord({
|
2467
3438
|
pathParams: {
|
@@ -2472,14 +3443,15 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2472
3443
|
},
|
2473
3444
|
queryParams: { columns },
|
2474
3445
|
body: record,
|
2475
|
-
...
|
3446
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2476
3447
|
});
|
2477
3448
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2478
3449
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2479
3450
|
};
|
2480
3451
|
_insertRecordWithId = new WeakSet();
|
2481
3452
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2482
|
-
|
3453
|
+
if (!recordId)
|
3454
|
+
return null;
|
2483
3455
|
const record = transformObjectLinks(object);
|
2484
3456
|
const response = await insertRecordWithID({
|
2485
3457
|
pathParams: {
|
@@ -2491,36 +3463,45 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2491
3463
|
},
|
2492
3464
|
body: record,
|
2493
3465
|
queryParams: { createOnly, columns, ifVersion },
|
2494
|
-
...
|
3466
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2495
3467
|
});
|
2496
3468
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2497
3469
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2498
3470
|
};
|
2499
|
-
|
2500
|
-
|
2501
|
-
const
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2506
|
-
|
2507
|
-
|
2508
|
-
|
2509
|
-
}
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
3471
|
+
_insertRecords = new WeakSet();
|
3472
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3473
|
+
const chunkedOperations = chunk(
|
3474
|
+
objects.map((object) => ({
|
3475
|
+
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
3476
|
+
})),
|
3477
|
+
BULK_OPERATION_MAX_SIZE
|
3478
|
+
);
|
3479
|
+
const ids = [];
|
3480
|
+
for (const operations of chunkedOperations) {
|
3481
|
+
const { results } = await branchTransaction({
|
3482
|
+
pathParams: {
|
3483
|
+
workspace: "{workspaceId}",
|
3484
|
+
dbBranchName: "{dbBranch}",
|
3485
|
+
region: "{region}"
|
3486
|
+
},
|
3487
|
+
body: { operations },
|
3488
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3489
|
+
});
|
3490
|
+
for (const result of results) {
|
3491
|
+
if (result.operation === "insert") {
|
3492
|
+
ids.push(result.id);
|
3493
|
+
} else {
|
3494
|
+
ids.push(null);
|
3495
|
+
}
|
3496
|
+
}
|
2516
3497
|
}
|
2517
|
-
|
2518
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
3498
|
+
return ids;
|
2519
3499
|
};
|
2520
3500
|
_updateRecordWithID = new WeakSet();
|
2521
3501
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2522
|
-
|
2523
|
-
|
3502
|
+
if (!recordId)
|
3503
|
+
return null;
|
3504
|
+
const { id: _id, ...record } = transformObjectLinks(object);
|
2524
3505
|
try {
|
2525
3506
|
const response = await updateRecordWithID({
|
2526
3507
|
pathParams: {
|
@@ -2532,7 +3513,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2532
3513
|
},
|
2533
3514
|
queryParams: { columns, ifVersion },
|
2534
3515
|
body: record,
|
2535
|
-
...
|
3516
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2536
3517
|
});
|
2537
3518
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2538
3519
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2543,9 +3524,39 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2543
3524
|
throw e;
|
2544
3525
|
}
|
2545
3526
|
};
|
3527
|
+
_updateRecords = new WeakSet();
|
3528
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3529
|
+
const chunkedOperations = chunk(
|
3530
|
+
objects.map(({ id, ...object }) => ({
|
3531
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
3532
|
+
})),
|
3533
|
+
BULK_OPERATION_MAX_SIZE
|
3534
|
+
);
|
3535
|
+
const ids = [];
|
3536
|
+
for (const operations of chunkedOperations) {
|
3537
|
+
const { results } = await branchTransaction({
|
3538
|
+
pathParams: {
|
3539
|
+
workspace: "{workspaceId}",
|
3540
|
+
dbBranchName: "{dbBranch}",
|
3541
|
+
region: "{region}"
|
3542
|
+
},
|
3543
|
+
body: { operations },
|
3544
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3545
|
+
});
|
3546
|
+
for (const result of results) {
|
3547
|
+
if (result.operation === "update") {
|
3548
|
+
ids.push(result.id);
|
3549
|
+
} else {
|
3550
|
+
ids.push(null);
|
3551
|
+
}
|
3552
|
+
}
|
3553
|
+
}
|
3554
|
+
return ids;
|
3555
|
+
};
|
2546
3556
|
_upsertRecordWithID = new WeakSet();
|
2547
3557
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2548
|
-
|
3558
|
+
if (!recordId)
|
3559
|
+
return null;
|
2549
3560
|
const response = await upsertRecordWithID({
|
2550
3561
|
pathParams: {
|
2551
3562
|
workspace: "{workspaceId}",
|
@@ -2556,14 +3567,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2556
3567
|
},
|
2557
3568
|
queryParams: { columns, ifVersion },
|
2558
3569
|
body: object,
|
2559
|
-
...
|
3570
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2560
3571
|
});
|
2561
3572
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2562
3573
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2563
3574
|
};
|
2564
3575
|
_deleteRecord = new WeakSet();
|
2565
3576
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2566
|
-
|
3577
|
+
if (!recordId)
|
3578
|
+
return null;
|
2567
3579
|
try {
|
2568
3580
|
const response = await deleteRecord({
|
2569
3581
|
pathParams: {
|
@@ -2574,7 +3586,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2574
3586
|
recordId
|
2575
3587
|
},
|
2576
3588
|
queryParams: { columns },
|
2577
|
-
...
|
3589
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2578
3590
|
});
|
2579
3591
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2580
3592
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2585,17 +3597,36 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2585
3597
|
throw e;
|
2586
3598
|
}
|
2587
3599
|
};
|
3600
|
+
_deleteRecords = new WeakSet();
|
3601
|
+
deleteRecords_fn = async function(recordIds) {
|
3602
|
+
const chunkedOperations = chunk(
|
3603
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3604
|
+
BULK_OPERATION_MAX_SIZE
|
3605
|
+
);
|
3606
|
+
for (const operations of chunkedOperations) {
|
3607
|
+
await branchTransaction({
|
3608
|
+
pathParams: {
|
3609
|
+
workspace: "{workspaceId}",
|
3610
|
+
dbBranchName: "{dbBranch}",
|
3611
|
+
region: "{region}"
|
3612
|
+
},
|
3613
|
+
body: { operations },
|
3614
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3615
|
+
});
|
3616
|
+
}
|
3617
|
+
};
|
2588
3618
|
_setCacheQuery = new WeakSet();
|
2589
3619
|
setCacheQuery_fn = async function(query, meta, records) {
|
2590
|
-
await __privateGet$4(this, _cache)
|
3620
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2591
3621
|
};
|
2592
3622
|
_getCacheQuery = new WeakSet();
|
2593
3623
|
getCacheQuery_fn = async function(query) {
|
2594
3624
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2595
|
-
const result = await __privateGet$4(this, _cache)
|
3625
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2596
3626
|
if (!result)
|
2597
3627
|
return null;
|
2598
|
-
const
|
3628
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3629
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2599
3630
|
if (ttl < 0)
|
2600
3631
|
return null;
|
2601
3632
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2605,10 +3636,9 @@ _getSchemaTables$1 = new WeakSet();
|
|
2605
3636
|
getSchemaTables_fn$1 = async function() {
|
2606
3637
|
if (__privateGet$4(this, _schemaTables$2))
|
2607
3638
|
return __privateGet$4(this, _schemaTables$2);
|
2608
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2609
3639
|
const { schema } = await getBranchDetails({
|
2610
3640
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2611
|
-
...
|
3641
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2612
3642
|
});
|
2613
3643
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2614
3644
|
return schema.tables;
|
@@ -2621,23 +3651,23 @@ const transformObjectLinks = (object) => {
|
|
2621
3651
|
}, {});
|
2622
3652
|
};
|
2623
3653
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2624
|
-
const
|
3654
|
+
const data = {};
|
2625
3655
|
const { xata, ...rest } = object ?? {};
|
2626
|
-
Object.assign(
|
3656
|
+
Object.assign(data, rest);
|
2627
3657
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2628
3658
|
if (!columns)
|
2629
3659
|
console.error(`Table ${table} not found in schema`);
|
2630
3660
|
for (const column of columns ?? []) {
|
2631
3661
|
if (!isValidColumn(selectedColumns, column))
|
2632
3662
|
continue;
|
2633
|
-
const value =
|
3663
|
+
const value = data[column.name];
|
2634
3664
|
switch (column.type) {
|
2635
3665
|
case "datetime": {
|
2636
|
-
const date = value !== void 0 ? new Date(value) :
|
2637
|
-
if (date && isNaN(date.getTime())) {
|
3666
|
+
const date = value !== void 0 ? new Date(value) : null;
|
3667
|
+
if (date !== null && isNaN(date.getTime())) {
|
2638
3668
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2639
|
-
} else
|
2640
|
-
|
3669
|
+
} else {
|
3670
|
+
data[column.name] = date;
|
2641
3671
|
}
|
2642
3672
|
break;
|
2643
3673
|
}
|
@@ -2656,48 +3686,55 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2656
3686
|
}
|
2657
3687
|
return acc;
|
2658
3688
|
}, []);
|
2659
|
-
|
3689
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2660
3690
|
} else {
|
2661
|
-
|
3691
|
+
data[column.name] = null;
|
2662
3692
|
}
|
2663
3693
|
break;
|
2664
3694
|
}
|
2665
3695
|
default:
|
2666
|
-
|
3696
|
+
data[column.name] = value ?? null;
|
2667
3697
|
if (column.notNull === true && value === null) {
|
2668
3698
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2669
3699
|
}
|
2670
3700
|
break;
|
2671
3701
|
}
|
2672
3702
|
}
|
2673
|
-
|
2674
|
-
|
3703
|
+
const record = { ...data };
|
3704
|
+
const serializable = { xata, ...transformObjectLinks(data) };
|
3705
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
3706
|
+
record.read = function(columns2) {
|
3707
|
+
return db[table].read(record["id"], columns2);
|
2675
3708
|
};
|
2676
|
-
|
3709
|
+
record.update = function(data2, b, c) {
|
2677
3710
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2678
3711
|
const ifVersion = parseIfVersion(b, c);
|
2679
|
-
return db[table].update(
|
3712
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2680
3713
|
};
|
2681
|
-
|
3714
|
+
record.replace = function(data2, b, c) {
|
2682
3715
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2683
3716
|
const ifVersion = parseIfVersion(b, c);
|
2684
|
-
return db[table].createOrReplace(
|
3717
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
3718
|
+
};
|
3719
|
+
record.delete = function() {
|
3720
|
+
return db[table].delete(record["id"]);
|
2685
3721
|
};
|
2686
|
-
|
2687
|
-
|
3722
|
+
record.xata = Object.freeze(metadata);
|
3723
|
+
record.getMetadata = function() {
|
3724
|
+
return record.xata;
|
2688
3725
|
};
|
2689
|
-
|
2690
|
-
return
|
3726
|
+
record.toSerializable = function() {
|
3727
|
+
return JSON.parse(JSON.stringify(serializable));
|
2691
3728
|
};
|
2692
|
-
|
2693
|
-
|
3729
|
+
record.toString = function() {
|
3730
|
+
return JSON.stringify(transformObjectLinks(serializable));
|
3731
|
+
};
|
3732
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3733
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2694
3734
|
}
|
2695
|
-
Object.freeze(
|
2696
|
-
return
|
3735
|
+
Object.freeze(record);
|
3736
|
+
return record;
|
2697
3737
|
};
|
2698
|
-
function isResponseWithRecords(value) {
|
2699
|
-
return isObject(value) && Array.isArray(value.records);
|
2700
|
-
}
|
2701
3738
|
function extractId(value) {
|
2702
3739
|
if (isString(value))
|
2703
3740
|
return value;
|
@@ -2880,19 +3917,19 @@ class SearchPlugin extends XataPlugin {
|
|
2880
3917
|
__privateAdd$1(this, _schemaTables, void 0);
|
2881
3918
|
__privateSet$1(this, _schemaTables, schemaTables);
|
2882
3919
|
}
|
2883
|
-
build(
|
3920
|
+
build(pluginOptions) {
|
2884
3921
|
return {
|
2885
3922
|
all: async (query, options = {}) => {
|
2886
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
2887
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3923
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3924
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
2888
3925
|
return records.map((record) => {
|
2889
3926
|
const { table = "orphan" } = record.xata;
|
2890
3927
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
2891
3928
|
});
|
2892
3929
|
},
|
2893
3930
|
byTable: async (query, options = {}) => {
|
2894
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
2895
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3931
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3932
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
2896
3933
|
return records.reduce((acc, record) => {
|
2897
3934
|
const { table = "orphan" } = record.xata;
|
2898
3935
|
const items = acc[table] ?? [];
|
@@ -2905,113 +3942,40 @@ class SearchPlugin extends XataPlugin {
|
|
2905
3942
|
}
|
2906
3943
|
_schemaTables = new WeakMap();
|
2907
3944
|
_search = new WeakSet();
|
2908
|
-
search_fn = async function(query, options,
|
2909
|
-
const
|
2910
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
3945
|
+
search_fn = async function(query, options, pluginOptions) {
|
3946
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
2911
3947
|
const { records } = await searchBranch({
|
2912
3948
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2913
|
-
|
2914
|
-
|
3949
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3950
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
3951
|
+
...pluginOptions
|
2915
3952
|
});
|
2916
3953
|
return records;
|
2917
3954
|
};
|
2918
3955
|
_getSchemaTables = new WeakSet();
|
2919
|
-
getSchemaTables_fn = async function(
|
3956
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
2920
3957
|
if (__privateGet$1(this, _schemaTables))
|
2921
3958
|
return __privateGet$1(this, _schemaTables);
|
2922
|
-
const fetchProps = await getFetchProps();
|
2923
3959
|
const { schema } = await getBranchDetails({
|
2924
3960
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2925
|
-
...
|
3961
|
+
...pluginOptions
|
2926
3962
|
});
|
2927
3963
|
__privateSet$1(this, _schemaTables, schema.tables);
|
2928
3964
|
return schema.tables;
|
2929
3965
|
};
|
2930
3966
|
|
2931
|
-
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
|
2943
|
-
const gitBranch = envBranch || await getGitBranch();
|
2944
|
-
return resolveXataBranch(gitBranch, options);
|
2945
|
-
}
|
2946
|
-
async function getCurrentBranchDetails(options) {
|
2947
|
-
const branch = await getCurrentBranchName(options);
|
2948
|
-
return getDatabaseBranch(branch, options);
|
2949
|
-
}
|
2950
|
-
async function resolveXataBranch(gitBranch, options) {
|
2951
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2952
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2953
|
-
if (!databaseURL)
|
2954
|
-
throw new Error(
|
2955
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2956
|
-
);
|
2957
|
-
if (!apiKey)
|
2958
|
-
throw new Error(
|
2959
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2960
|
-
);
|
2961
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
2962
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
2963
|
-
if (!urlParts)
|
2964
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
2965
|
-
const { workspace, region } = urlParts;
|
2966
|
-
const { fallbackBranch } = getEnvironment();
|
2967
|
-
const { branch } = await resolveBranch({
|
2968
|
-
apiKey,
|
2969
|
-
apiUrl: databaseURL,
|
2970
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2971
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
2972
|
-
pathParams: { dbName, workspace, region },
|
2973
|
-
queryParams: { gitBranch, fallbackBranch },
|
2974
|
-
trace: defaultTrace
|
2975
|
-
});
|
2976
|
-
return branch;
|
2977
|
-
}
|
2978
|
-
async function getDatabaseBranch(branch, options) {
|
2979
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2980
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2981
|
-
if (!databaseURL)
|
2982
|
-
throw new Error(
|
2983
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2984
|
-
);
|
2985
|
-
if (!apiKey)
|
2986
|
-
throw new Error(
|
2987
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2988
|
-
);
|
2989
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
2990
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
2991
|
-
if (!urlParts)
|
2992
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
2993
|
-
const { workspace, region } = urlParts;
|
2994
|
-
try {
|
2995
|
-
return await getBranchDetails({
|
2996
|
-
apiKey,
|
2997
|
-
apiUrl: databaseURL,
|
2998
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2999
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3000
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3001
|
-
trace: defaultTrace
|
3002
|
-
});
|
3003
|
-
} catch (err) {
|
3004
|
-
if (isObject(err) && err.status === 404)
|
3005
|
-
return null;
|
3006
|
-
throw err;
|
3007
|
-
}
|
3008
|
-
}
|
3009
|
-
function getDatabaseURL() {
|
3010
|
-
try {
|
3011
|
-
const { databaseURL } = getEnvironment();
|
3012
|
-
return databaseURL;
|
3013
|
-
} catch (err) {
|
3014
|
-
return void 0;
|
3967
|
+
class TransactionPlugin extends XataPlugin {
|
3968
|
+
build(pluginOptions) {
|
3969
|
+
return {
|
3970
|
+
run: async (operations) => {
|
3971
|
+
const response = await branchTransaction({
|
3972
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3973
|
+
body: { operations },
|
3974
|
+
...pluginOptions
|
3975
|
+
});
|
3976
|
+
return response;
|
3977
|
+
}
|
3978
|
+
};
|
3015
3979
|
}
|
3016
3980
|
}
|
3017
3981
|
|
@@ -3038,89 +4002,116 @@ var __privateMethod = (obj, member, method) => {
|
|
3038
4002
|
return method;
|
3039
4003
|
};
|
3040
4004
|
const buildClient = (plugins) => {
|
3041
|
-
var
|
4005
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3042
4006
|
return _a = class {
|
3043
4007
|
constructor(options = {}, schemaTables) {
|
3044
4008
|
__privateAdd(this, _parseOptions);
|
3045
4009
|
__privateAdd(this, _getFetchProps);
|
3046
|
-
__privateAdd(this, _evaluateBranch);
|
3047
|
-
__privateAdd(this, _branch, void 0);
|
3048
4010
|
__privateAdd(this, _options, void 0);
|
3049
4011
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3050
4012
|
__privateSet(this, _options, safeOptions);
|
3051
4013
|
const pluginOptions = {
|
3052
|
-
|
4014
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3053
4015
|
cache: safeOptions.cache,
|
3054
|
-
|
4016
|
+
host: safeOptions.host
|
3055
4017
|
};
|
3056
4018
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3057
4019
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4020
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
3058
4021
|
this.db = db;
|
3059
4022
|
this.search = search;
|
4023
|
+
this.transactions = transactions;
|
3060
4024
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3061
4025
|
if (namespace === void 0)
|
3062
4026
|
continue;
|
3063
|
-
|
3064
|
-
if (result instanceof Promise) {
|
3065
|
-
void result.then((namespace2) => {
|
3066
|
-
this[key] = namespace2;
|
3067
|
-
});
|
3068
|
-
} else {
|
3069
|
-
this[key] = result;
|
3070
|
-
}
|
4027
|
+
this[key] = namespace.build(pluginOptions);
|
3071
4028
|
}
|
3072
4029
|
}
|
3073
4030
|
async getConfig() {
|
3074
4031
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3075
|
-
const branch =
|
4032
|
+
const branch = __privateGet(this, _options).branch;
|
3076
4033
|
return { databaseURL, branch };
|
3077
4034
|
}
|
3078
|
-
},
|
4035
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
4036
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
4037
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
4038
|
+
if (isBrowser && !enableBrowser) {
|
4039
|
+
throw new Error(
|
4040
|
+
"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."
|
4041
|
+
);
|
4042
|
+
}
|
3079
4043
|
const fetch = getFetchImplementation(options?.fetch);
|
3080
4044
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3081
4045
|
const apiKey = options?.apiKey || getAPIKey();
|
3082
4046
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3083
4047
|
const trace = options?.trace ?? defaultTrace;
|
3084
|
-
const
|
4048
|
+
const clientName = options?.clientName;
|
4049
|
+
const host = options?.host ?? "production";
|
4050
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3085
4051
|
if (!apiKey) {
|
3086
4052
|
throw new Error("Option apiKey is required");
|
3087
4053
|
}
|
3088
4054
|
if (!databaseURL) {
|
3089
4055
|
throw new Error("Option databaseURL is required");
|
3090
4056
|
}
|
3091
|
-
|
3092
|
-
|
3093
|
-
const
|
3094
|
-
if (
|
3095
|
-
|
4057
|
+
const envBranch = getBranch();
|
4058
|
+
const previewBranch = getPreviewBranch();
|
4059
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4060
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4061
|
+
console.warn(
|
4062
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4063
|
+
);
|
4064
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4065
|
+
console.warn(
|
4066
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4067
|
+
);
|
4068
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4069
|
+
console.warn(
|
4070
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4071
|
+
);
|
4072
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4073
|
+
console.warn(
|
4074
|
+
`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.`
|
4075
|
+
);
|
4076
|
+
}
|
4077
|
+
return {
|
4078
|
+
fetch,
|
4079
|
+
databaseURL,
|
4080
|
+
apiKey,
|
4081
|
+
branch,
|
4082
|
+
cache,
|
4083
|
+
trace,
|
4084
|
+
host,
|
4085
|
+
clientID: generateUUID(),
|
4086
|
+
enableBrowser,
|
4087
|
+
clientName,
|
4088
|
+
xataAgentExtra
|
4089
|
+
};
|
4090
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4091
|
+
fetch,
|
4092
|
+
apiKey,
|
4093
|
+
databaseURL,
|
4094
|
+
branch,
|
4095
|
+
trace,
|
4096
|
+
clientID,
|
4097
|
+
clientName,
|
4098
|
+
xataAgentExtra
|
4099
|
+
}) {
|
3096
4100
|
return {
|
3097
|
-
|
4101
|
+
fetch,
|
3098
4102
|
apiKey,
|
3099
4103
|
apiUrl: "",
|
4104
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3100
4105
|
workspacesApiUrl: (path, params) => {
|
3101
4106
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3102
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4107
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3103
4108
|
return databaseURL + newPath;
|
3104
4109
|
},
|
3105
4110
|
trace,
|
3106
|
-
clientID
|
3107
|
-
|
3108
|
-
|
3109
|
-
if (__privateGet(this, _branch))
|
3110
|
-
return __privateGet(this, _branch);
|
3111
|
-
if (param === void 0)
|
3112
|
-
return void 0;
|
3113
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3114
|
-
const evaluateBranch = async (strategy) => {
|
3115
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
4111
|
+
clientID,
|
4112
|
+
clientName,
|
4113
|
+
xataAgentExtra
|
3116
4114
|
};
|
3117
|
-
for await (const strategy of strategies) {
|
3118
|
-
const branch = await evaluateBranch(strategy);
|
3119
|
-
if (branch) {
|
3120
|
-
__privateSet(this, _branch, branch);
|
3121
|
-
return branch;
|
3122
|
-
}
|
3123
|
-
}
|
3124
4115
|
}, _a;
|
3125
4116
|
};
|
3126
4117
|
class BaseClient extends buildClient() {
|
@@ -3194,7 +4185,7 @@ const deserialize = (json) => {
|
|
3194
4185
|
};
|
3195
4186
|
|
3196
4187
|
function buildWorkerRunner(config) {
|
3197
|
-
return function xataWorker(name,
|
4188
|
+
return function xataWorker(name, worker) {
|
3198
4189
|
return async (...args) => {
|
3199
4190
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3200
4191
|
const result = await fetch(url, {
|
@@ -3215,5 +4206,5 @@ class XataError extends Error {
|
|
3215
4206
|
}
|
3216
4207
|
}
|
3217
4208
|
|
3218
|
-
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, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace,
|
4209
|
+
export { BaseClient, FetcherError, 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, askTable, 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, 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, getWorkspace, getWorkspaceMembersList, getWorkspacesList, 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, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3219
4210
|
//# sourceMappingURL=index.mjs.map
|