@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.cjs
CHANGED
@@ -1,27 +1,8 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
function _interopNamespace(e) {
|
6
|
-
if (e && e.__esModule) return e;
|
7
|
-
var n = Object.create(null);
|
8
|
-
if (e) {
|
9
|
-
Object.keys(e).forEach(function (k) {
|
10
|
-
if (k !== 'default') {
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
13
|
-
enumerable: true,
|
14
|
-
get: function () { return e[k]; }
|
15
|
-
});
|
16
|
-
}
|
17
|
-
});
|
18
|
-
}
|
19
|
-
n["default"] = e;
|
20
|
-
return Object.freeze(n);
|
21
|
-
}
|
22
|
-
|
23
|
-
const defaultTrace = async (_name, fn, _options) => {
|
3
|
+
const defaultTrace = async (name, fn, _options) => {
|
24
4
|
return await fn({
|
5
|
+
name,
|
25
6
|
setAttributes: () => {
|
26
7
|
return;
|
27
8
|
}
|
@@ -63,6 +44,18 @@ function isStringArray(value) {
|
|
63
44
|
function isNumber(value) {
|
64
45
|
return isDefined(value) && typeof value === "number";
|
65
46
|
}
|
47
|
+
function parseNumber(value) {
|
48
|
+
if (isNumber(value)) {
|
49
|
+
return value;
|
50
|
+
}
|
51
|
+
if (isString(value)) {
|
52
|
+
const parsed = Number(value);
|
53
|
+
if (!Number.isNaN(parsed)) {
|
54
|
+
return parsed;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
return void 0;
|
58
|
+
}
|
66
59
|
function toBase64(value) {
|
67
60
|
try {
|
68
61
|
return btoa(value);
|
@@ -82,16 +75,28 @@ function deepMerge(a, b) {
|
|
82
75
|
}
|
83
76
|
return result;
|
84
77
|
}
|
78
|
+
function chunk(array, chunkSize) {
|
79
|
+
const result = [];
|
80
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
81
|
+
result.push(array.slice(i, i + chunkSize));
|
82
|
+
}
|
83
|
+
return result;
|
84
|
+
}
|
85
|
+
async function timeout(ms) {
|
86
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
87
|
+
}
|
85
88
|
|
86
89
|
function getEnvironment() {
|
87
90
|
try {
|
88
|
-
if (
|
91
|
+
if (isDefined(process) && isDefined(process.env)) {
|
89
92
|
return {
|
90
93
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
91
94
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
92
95
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
93
|
-
|
94
|
-
|
96
|
+
deployPreview: process.env.XATA_PREVIEW,
|
97
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
98
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
99
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
95
100
|
};
|
96
101
|
}
|
97
102
|
} catch (err) {
|
@@ -102,8 +107,10 @@ function getEnvironment() {
|
|
102
107
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
103
108
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
104
109
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
105
|
-
|
106
|
-
|
110
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
111
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
112
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
113
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
107
114
|
};
|
108
115
|
}
|
109
116
|
} catch (err) {
|
@@ -112,10 +119,31 @@ function getEnvironment() {
|
|
112
119
|
apiKey: getGlobalApiKey(),
|
113
120
|
databaseURL: getGlobalDatabaseURL(),
|
114
121
|
branch: getGlobalBranch(),
|
115
|
-
|
116
|
-
|
122
|
+
deployPreview: void 0,
|
123
|
+
deployPreviewBranch: void 0,
|
124
|
+
vercelGitCommitRef: void 0,
|
125
|
+
vercelGitRepoOwner: void 0
|
117
126
|
};
|
118
127
|
}
|
128
|
+
function getEnableBrowserVariable() {
|
129
|
+
try {
|
130
|
+
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
131
|
+
return process.env.XATA_ENABLE_BROWSER === "true";
|
132
|
+
}
|
133
|
+
} catch (err) {
|
134
|
+
}
|
135
|
+
try {
|
136
|
+
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
137
|
+
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
138
|
+
}
|
139
|
+
} catch (err) {
|
140
|
+
}
|
141
|
+
try {
|
142
|
+
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
143
|
+
} catch (err) {
|
144
|
+
return void 0;
|
145
|
+
}
|
146
|
+
}
|
119
147
|
function getGlobalApiKey() {
|
120
148
|
try {
|
121
149
|
return XATA_API_KEY;
|
@@ -137,44 +165,76 @@ function getGlobalBranch() {
|
|
137
165
|
return void 0;
|
138
166
|
}
|
139
167
|
}
|
140
|
-
function
|
168
|
+
function getDatabaseURL() {
|
141
169
|
try {
|
142
|
-
|
170
|
+
const { databaseURL } = getEnvironment();
|
171
|
+
return databaseURL;
|
143
172
|
} catch (err) {
|
144
173
|
return void 0;
|
145
174
|
}
|
146
175
|
}
|
147
|
-
|
148
|
-
const cmd = ["git", "branch", "--show-current"];
|
149
|
-
const fullCmd = cmd.join(" ");
|
150
|
-
const nodeModule = ["child", "process"].join("_");
|
151
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
176
|
+
function getAPIKey() {
|
152
177
|
try {
|
153
|
-
|
154
|
-
|
155
|
-
}
|
156
|
-
const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
|
157
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
178
|
+
const { apiKey } = getEnvironment();
|
179
|
+
return apiKey;
|
158
180
|
} catch (err) {
|
181
|
+
return void 0;
|
159
182
|
}
|
183
|
+
}
|
184
|
+
function getBranch() {
|
160
185
|
try {
|
161
|
-
|
162
|
-
|
163
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
164
|
-
}
|
186
|
+
const { branch } = getEnvironment();
|
187
|
+
return branch ?? "main";
|
165
188
|
} catch (err) {
|
189
|
+
return void 0;
|
166
190
|
}
|
167
191
|
}
|
168
|
-
|
169
|
-
|
192
|
+
function buildPreviewBranchName({ org, branch }) {
|
193
|
+
return `preview-${org}-${branch}`;
|
194
|
+
}
|
195
|
+
function getPreviewBranch() {
|
170
196
|
try {
|
171
|
-
const {
|
172
|
-
|
197
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
198
|
+
if (deployPreviewBranch)
|
199
|
+
return deployPreviewBranch;
|
200
|
+
switch (deployPreview) {
|
201
|
+
case "vercel": {
|
202
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
203
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
204
|
+
return void 0;
|
205
|
+
}
|
206
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
207
|
+
}
|
208
|
+
}
|
209
|
+
return void 0;
|
173
210
|
} catch (err) {
|
174
211
|
return void 0;
|
175
212
|
}
|
176
213
|
}
|
177
214
|
|
215
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
216
|
+
if (!member.has(obj))
|
217
|
+
throw TypeError("Cannot " + msg);
|
218
|
+
};
|
219
|
+
var __privateGet$8 = (obj, member, getter) => {
|
220
|
+
__accessCheck$8(obj, member, "read from private field");
|
221
|
+
return getter ? getter.call(obj) : member.get(obj);
|
222
|
+
};
|
223
|
+
var __privateAdd$8 = (obj, member, value) => {
|
224
|
+
if (member.has(obj))
|
225
|
+
throw TypeError("Cannot add the same private member more than once");
|
226
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
227
|
+
};
|
228
|
+
var __privateSet$8 = (obj, member, value, setter) => {
|
229
|
+
__accessCheck$8(obj, member, "write to private field");
|
230
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
231
|
+
return value;
|
232
|
+
};
|
233
|
+
var __privateMethod$4 = (obj, member, method) => {
|
234
|
+
__accessCheck$8(obj, member, "access private method");
|
235
|
+
return method;
|
236
|
+
};
|
237
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
178
238
|
function getFetchImplementation(userFetch) {
|
179
239
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
180
240
|
const fetchImpl = userFetch ?? globalFetch;
|
@@ -185,8 +245,254 @@ function getFetchImplementation(userFetch) {
|
|
185
245
|
}
|
186
246
|
return fetchImpl;
|
187
247
|
}
|
248
|
+
class ApiRequestPool {
|
249
|
+
constructor(concurrency = 10) {
|
250
|
+
__privateAdd$8(this, _enqueue);
|
251
|
+
__privateAdd$8(this, _fetch, void 0);
|
252
|
+
__privateAdd$8(this, _queue, void 0);
|
253
|
+
__privateAdd$8(this, _concurrency, void 0);
|
254
|
+
__privateSet$8(this, _queue, []);
|
255
|
+
__privateSet$8(this, _concurrency, concurrency);
|
256
|
+
this.running = 0;
|
257
|
+
this.started = 0;
|
258
|
+
}
|
259
|
+
setFetch(fetch2) {
|
260
|
+
__privateSet$8(this, _fetch, fetch2);
|
261
|
+
}
|
262
|
+
getFetch() {
|
263
|
+
if (!__privateGet$8(this, _fetch)) {
|
264
|
+
throw new Error("Fetch not set");
|
265
|
+
}
|
266
|
+
return __privateGet$8(this, _fetch);
|
267
|
+
}
|
268
|
+
request(url, options) {
|
269
|
+
const start = /* @__PURE__ */ new Date();
|
270
|
+
const fetch2 = this.getFetch();
|
271
|
+
const runRequest = async (stalled = false) => {
|
272
|
+
const response = await fetch2(url, options);
|
273
|
+
if (response.status === 429) {
|
274
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
275
|
+
await timeout(rateLimitReset * 1e3);
|
276
|
+
return await runRequest(true);
|
277
|
+
}
|
278
|
+
if (stalled) {
|
279
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
280
|
+
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
281
|
+
}
|
282
|
+
return response;
|
283
|
+
};
|
284
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
285
|
+
return await runRequest();
|
286
|
+
});
|
287
|
+
}
|
288
|
+
}
|
289
|
+
_fetch = new WeakMap();
|
290
|
+
_queue = new WeakMap();
|
291
|
+
_concurrency = new WeakMap();
|
292
|
+
_enqueue = new WeakSet();
|
293
|
+
enqueue_fn = function(task) {
|
294
|
+
const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
|
295
|
+
this.started--;
|
296
|
+
this.running++;
|
297
|
+
}).then(() => task()).finally(() => {
|
298
|
+
this.running--;
|
299
|
+
const next = __privateGet$8(this, _queue).shift();
|
300
|
+
if (next !== void 0) {
|
301
|
+
this.started++;
|
302
|
+
next();
|
303
|
+
}
|
304
|
+
});
|
305
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
306
|
+
const next = __privateGet$8(this, _queue).shift();
|
307
|
+
if (next !== void 0) {
|
308
|
+
this.started++;
|
309
|
+
next();
|
310
|
+
}
|
311
|
+
}
|
312
|
+
return promise;
|
313
|
+
};
|
188
314
|
|
189
|
-
|
315
|
+
function generateUUID() {
|
316
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
317
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
318
|
+
return v.toString(16);
|
319
|
+
});
|
320
|
+
}
|
321
|
+
|
322
|
+
async function getBytes(stream, onChunk) {
|
323
|
+
const reader = stream.getReader();
|
324
|
+
let result;
|
325
|
+
while (!(result = await reader.read()).done) {
|
326
|
+
onChunk(result.value);
|
327
|
+
}
|
328
|
+
}
|
329
|
+
function getLines(onLine) {
|
330
|
+
let buffer;
|
331
|
+
let position;
|
332
|
+
let fieldLength;
|
333
|
+
let discardTrailingNewline = false;
|
334
|
+
return function onChunk(arr) {
|
335
|
+
if (buffer === void 0) {
|
336
|
+
buffer = arr;
|
337
|
+
position = 0;
|
338
|
+
fieldLength = -1;
|
339
|
+
} else {
|
340
|
+
buffer = concat(buffer, arr);
|
341
|
+
}
|
342
|
+
const bufLength = buffer.length;
|
343
|
+
let lineStart = 0;
|
344
|
+
while (position < bufLength) {
|
345
|
+
if (discardTrailingNewline) {
|
346
|
+
if (buffer[position] === 10 /* NewLine */) {
|
347
|
+
lineStart = ++position;
|
348
|
+
}
|
349
|
+
discardTrailingNewline = false;
|
350
|
+
}
|
351
|
+
let lineEnd = -1;
|
352
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
353
|
+
switch (buffer[position]) {
|
354
|
+
case 58 /* Colon */:
|
355
|
+
if (fieldLength === -1) {
|
356
|
+
fieldLength = position - lineStart;
|
357
|
+
}
|
358
|
+
break;
|
359
|
+
case 13 /* CarriageReturn */:
|
360
|
+
discardTrailingNewline = true;
|
361
|
+
case 10 /* NewLine */:
|
362
|
+
lineEnd = position;
|
363
|
+
break;
|
364
|
+
}
|
365
|
+
}
|
366
|
+
if (lineEnd === -1) {
|
367
|
+
break;
|
368
|
+
}
|
369
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
370
|
+
lineStart = position;
|
371
|
+
fieldLength = -1;
|
372
|
+
}
|
373
|
+
if (lineStart === bufLength) {
|
374
|
+
buffer = void 0;
|
375
|
+
} else if (lineStart !== 0) {
|
376
|
+
buffer = buffer.subarray(lineStart);
|
377
|
+
position -= lineStart;
|
378
|
+
}
|
379
|
+
};
|
380
|
+
}
|
381
|
+
function getMessages(onId, onRetry, onMessage) {
|
382
|
+
let message = newMessage();
|
383
|
+
const decoder = new TextDecoder();
|
384
|
+
return function onLine(line, fieldLength) {
|
385
|
+
if (line.length === 0) {
|
386
|
+
onMessage?.(message);
|
387
|
+
message = newMessage();
|
388
|
+
} else if (fieldLength > 0) {
|
389
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
390
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
391
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
392
|
+
switch (field) {
|
393
|
+
case "data":
|
394
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
395
|
+
break;
|
396
|
+
case "event":
|
397
|
+
message.event = value;
|
398
|
+
break;
|
399
|
+
case "id":
|
400
|
+
onId(message.id = value);
|
401
|
+
break;
|
402
|
+
case "retry":
|
403
|
+
const retry = parseInt(value, 10);
|
404
|
+
if (!isNaN(retry)) {
|
405
|
+
onRetry(message.retry = retry);
|
406
|
+
}
|
407
|
+
break;
|
408
|
+
}
|
409
|
+
}
|
410
|
+
};
|
411
|
+
}
|
412
|
+
function concat(a, b) {
|
413
|
+
const res = new Uint8Array(a.length + b.length);
|
414
|
+
res.set(a);
|
415
|
+
res.set(b, a.length);
|
416
|
+
return res;
|
417
|
+
}
|
418
|
+
function newMessage() {
|
419
|
+
return {
|
420
|
+
data: "",
|
421
|
+
event: "",
|
422
|
+
id: "",
|
423
|
+
retry: void 0
|
424
|
+
};
|
425
|
+
}
|
426
|
+
const EventStreamContentType = "text/event-stream";
|
427
|
+
const LastEventId = "last-event-id";
|
428
|
+
function fetchEventSource(input, {
|
429
|
+
signal: inputSignal,
|
430
|
+
headers: inputHeaders,
|
431
|
+
onopen: inputOnOpen,
|
432
|
+
onmessage,
|
433
|
+
onclose,
|
434
|
+
onerror,
|
435
|
+
fetch: inputFetch,
|
436
|
+
...rest
|
437
|
+
}) {
|
438
|
+
return new Promise((resolve, reject) => {
|
439
|
+
const headers = { ...inputHeaders };
|
440
|
+
if (!headers.accept) {
|
441
|
+
headers.accept = EventStreamContentType;
|
442
|
+
}
|
443
|
+
let curRequestController;
|
444
|
+
function dispose() {
|
445
|
+
curRequestController.abort();
|
446
|
+
}
|
447
|
+
inputSignal?.addEventListener("abort", () => {
|
448
|
+
dispose();
|
449
|
+
resolve();
|
450
|
+
});
|
451
|
+
const fetchImpl = inputFetch ?? fetch;
|
452
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
453
|
+
async function create() {
|
454
|
+
curRequestController = new AbortController();
|
455
|
+
try {
|
456
|
+
const response = await fetchImpl(input, {
|
457
|
+
...rest,
|
458
|
+
headers,
|
459
|
+
signal: curRequestController.signal
|
460
|
+
});
|
461
|
+
await onopen(response);
|
462
|
+
await getBytes(
|
463
|
+
response.body,
|
464
|
+
getLines(
|
465
|
+
getMessages(
|
466
|
+
(id) => {
|
467
|
+
if (id) {
|
468
|
+
headers[LastEventId] = id;
|
469
|
+
} else {
|
470
|
+
delete headers[LastEventId];
|
471
|
+
}
|
472
|
+
},
|
473
|
+
(_retry) => {
|
474
|
+
},
|
475
|
+
onmessage
|
476
|
+
)
|
477
|
+
)
|
478
|
+
);
|
479
|
+
onclose?.();
|
480
|
+
dispose();
|
481
|
+
resolve();
|
482
|
+
} catch (err) {
|
483
|
+
}
|
484
|
+
}
|
485
|
+
create();
|
486
|
+
});
|
487
|
+
}
|
488
|
+
function defaultOnOpen(response) {
|
489
|
+
const contentType = response.headers?.get("content-type");
|
490
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
491
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
492
|
+
}
|
493
|
+
}
|
494
|
+
|
495
|
+
const VERSION = "0.24.2";
|
190
496
|
|
191
497
|
class ErrorWithCause extends Error {
|
192
498
|
constructor(message, options) {
|
@@ -197,7 +503,7 @@ class FetcherError extends ErrorWithCause {
|
|
197
503
|
constructor(status, data, requestId) {
|
198
504
|
super(getMessage(data));
|
199
505
|
this.status = status;
|
200
|
-
this.errors = isBulkError(data) ? data.errors :
|
506
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
201
507
|
this.requestId = requestId;
|
202
508
|
if (data instanceof Error) {
|
203
509
|
this.stack = data.stack;
|
@@ -229,6 +535,7 @@ function getMessage(data) {
|
|
229
535
|
}
|
230
536
|
}
|
231
537
|
|
538
|
+
const pool = new ApiRequestPool();
|
232
539
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
233
540
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
234
541
|
if (value === void 0 || value === null)
|
@@ -261,14 +568,15 @@ function hostHeader(url) {
|
|
261
568
|
const { groups } = pattern.exec(url) ?? {};
|
262
569
|
return groups?.host ? { Host: groups.host } : {};
|
263
570
|
}
|
571
|
+
const defaultClientID = generateUUID();
|
264
572
|
async function fetch$1({
|
265
573
|
url: path,
|
266
574
|
method,
|
267
575
|
body,
|
268
|
-
headers,
|
576
|
+
headers: customHeaders,
|
269
577
|
pathParams,
|
270
578
|
queryParams,
|
271
|
-
|
579
|
+
fetch: fetch2,
|
272
580
|
apiKey,
|
273
581
|
endpoint,
|
274
582
|
apiUrl,
|
@@ -276,9 +584,13 @@ async function fetch$1({
|
|
276
584
|
trace,
|
277
585
|
signal,
|
278
586
|
clientID,
|
279
|
-
sessionID
|
587
|
+
sessionID,
|
588
|
+
clientName,
|
589
|
+
xataAgentExtra,
|
590
|
+
fetchOptions = {}
|
280
591
|
}) {
|
281
|
-
|
592
|
+
pool.setFetch(fetch2);
|
593
|
+
return await trace(
|
282
594
|
`${method.toUpperCase()} ${path}`,
|
283
595
|
async ({ setAttributes }) => {
|
284
596
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
@@ -288,23 +600,29 @@ async function fetch$1({
|
|
288
600
|
[TraceAttributes.HTTP_URL]: url,
|
289
601
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
290
602
|
});
|
291
|
-
const
|
603
|
+
const xataAgent = compact([
|
604
|
+
["client", "TS_SDK"],
|
605
|
+
["version", VERSION],
|
606
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
607
|
+
...Object.entries(xataAgentExtra ?? {})
|
608
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
609
|
+
const headers = {
|
610
|
+
"Accept-Encoding": "identity",
|
611
|
+
"Content-Type": "application/json",
|
612
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
613
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
614
|
+
"X-Xata-Agent": xataAgent,
|
615
|
+
...customHeaders,
|
616
|
+
...hostHeader(fullUrl),
|
617
|
+
Authorization: `Bearer ${apiKey}`
|
618
|
+
};
|
619
|
+
const response = await pool.request(url, {
|
620
|
+
...fetchOptions,
|
292
621
|
method: method.toUpperCase(),
|
293
622
|
body: body ? JSON.stringify(body) : void 0,
|
294
|
-
headers
|
295
|
-
"Content-Type": "application/json",
|
296
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
297
|
-
"X-Xata-Client-ID": clientID ?? "",
|
298
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
299
|
-
...headers,
|
300
|
-
...hostHeader(fullUrl),
|
301
|
-
Authorization: `Bearer ${apiKey}`
|
302
|
-
},
|
623
|
+
headers,
|
303
624
|
signal
|
304
625
|
});
|
305
|
-
if (response.status === 204) {
|
306
|
-
return {};
|
307
|
-
}
|
308
626
|
const { host, protocol } = parseUrl(response.url);
|
309
627
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
310
628
|
setAttributes({
|
@@ -314,6 +632,12 @@ async function fetch$1({
|
|
314
632
|
[TraceAttributes.HTTP_HOST]: host,
|
315
633
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
316
634
|
});
|
635
|
+
if (response.status === 204) {
|
636
|
+
return {};
|
637
|
+
}
|
638
|
+
if (response.status === 429) {
|
639
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
640
|
+
}
|
317
641
|
try {
|
318
642
|
const jsonResponse = await response.json();
|
319
643
|
if (response.ok) {
|
@@ -327,6 +651,59 @@ async function fetch$1({
|
|
327
651
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
328
652
|
);
|
329
653
|
}
|
654
|
+
function fetchSSERequest({
|
655
|
+
url: path,
|
656
|
+
method,
|
657
|
+
body,
|
658
|
+
headers: customHeaders,
|
659
|
+
pathParams,
|
660
|
+
queryParams,
|
661
|
+
fetch: fetch2,
|
662
|
+
apiKey,
|
663
|
+
endpoint,
|
664
|
+
apiUrl,
|
665
|
+
workspacesApiUrl,
|
666
|
+
onMessage,
|
667
|
+
onError,
|
668
|
+
onClose,
|
669
|
+
signal,
|
670
|
+
clientID,
|
671
|
+
sessionID,
|
672
|
+
clientName,
|
673
|
+
xataAgentExtra
|
674
|
+
}) {
|
675
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
676
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
677
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
678
|
+
void fetchEventSource(url, {
|
679
|
+
method,
|
680
|
+
body: JSON.stringify(body),
|
681
|
+
fetch: fetch2,
|
682
|
+
signal,
|
683
|
+
headers: {
|
684
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
685
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
686
|
+
"X-Xata-Agent": compact([
|
687
|
+
["client", "TS_SDK"],
|
688
|
+
["version", VERSION],
|
689
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
690
|
+
...Object.entries(xataAgentExtra ?? {})
|
691
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
692
|
+
...customHeaders,
|
693
|
+
Authorization: `Bearer ${apiKey}`,
|
694
|
+
"Content-Type": "application/json"
|
695
|
+
},
|
696
|
+
onmessage(ev) {
|
697
|
+
onMessage?.(JSON.parse(ev.data));
|
698
|
+
},
|
699
|
+
onerror(ev) {
|
700
|
+
onError?.(JSON.parse(ev.data));
|
701
|
+
},
|
702
|
+
onclose() {
|
703
|
+
onClose?.();
|
704
|
+
}
|
705
|
+
});
|
706
|
+
}
|
330
707
|
function parseUrl(url) {
|
331
708
|
try {
|
332
709
|
const { host, protocol } = new URL(url);
|
@@ -338,17 +715,12 @@ function parseUrl(url) {
|
|
338
715
|
|
339
716
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
340
717
|
|
341
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
342
718
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
343
719
|
url: "/dbs/{dbName}",
|
344
720
|
method: "get",
|
345
721
|
...variables,
|
346
722
|
signal
|
347
723
|
});
|
348
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
349
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
350
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
351
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
352
724
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
353
725
|
url: "/db/{dbBranchName}",
|
354
726
|
method: "get",
|
@@ -362,6 +734,12 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
362
734
|
...variables,
|
363
735
|
signal
|
364
736
|
});
|
737
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
738
|
+
url: "/db/{dbBranchName}/copy",
|
739
|
+
method: "post",
|
740
|
+
...variables,
|
741
|
+
signal
|
742
|
+
});
|
365
743
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
366
744
|
url: "/db/{dbBranchName}/metadata",
|
367
745
|
method: "put",
|
@@ -411,6 +789,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
411
789
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
412
790
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
413
791
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
792
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
414
793
|
const createTable = (variables, signal) => dataPlaneFetch({
|
415
794
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
416
795
|
method: "put",
|
@@ -453,7 +832,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
453
832
|
...variables,
|
454
833
|
signal
|
455
834
|
});
|
835
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
456
836
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
837
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
838
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
839
|
+
method: "get",
|
840
|
+
...variables,
|
841
|
+
signal
|
842
|
+
});
|
843
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
844
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
845
|
+
method: "put",
|
846
|
+
...variables,
|
847
|
+
signal
|
848
|
+
});
|
849
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
850
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
851
|
+
method: "delete",
|
852
|
+
...variables,
|
853
|
+
signal
|
854
|
+
});
|
855
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
856
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
857
|
+
method: "get",
|
858
|
+
...variables,
|
859
|
+
signal
|
860
|
+
});
|
861
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
862
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
863
|
+
method: "put",
|
864
|
+
...variables,
|
865
|
+
signal
|
866
|
+
});
|
867
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
868
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
869
|
+
method: "delete",
|
870
|
+
...variables,
|
871
|
+
signal
|
872
|
+
});
|
457
873
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
458
874
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
459
875
|
method: "get",
|
@@ -483,21 +899,34 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
483
899
|
...variables,
|
484
900
|
signal
|
485
901
|
});
|
902
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
903
|
+
url: "/db/{dbBranchName}/sql",
|
904
|
+
method: "post",
|
905
|
+
...variables,
|
906
|
+
signal
|
907
|
+
});
|
908
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
909
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
910
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
911
|
+
method: "post",
|
912
|
+
...variables,
|
913
|
+
signal
|
914
|
+
});
|
486
915
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
487
916
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
917
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
918
|
+
url: "/file/{fileId}",
|
919
|
+
method: "get",
|
920
|
+
...variables,
|
921
|
+
signal
|
922
|
+
});
|
488
923
|
const operationsByTag$2 = {
|
489
|
-
database: {
|
490
|
-
dEPRECATEDgetDatabaseList,
|
491
|
-
dEPRECATEDcreateDatabase,
|
492
|
-
dEPRECATEDdeleteDatabase,
|
493
|
-
dEPRECATEDgetDatabaseMetadata,
|
494
|
-
dEPRECATEDupdateDatabaseMetadata
|
495
|
-
},
|
496
924
|
branch: {
|
497
925
|
getBranchList,
|
498
926
|
getBranchDetails,
|
499
927
|
createBranch,
|
500
928
|
deleteBranch,
|
929
|
+
copyBranch,
|
501
930
|
updateBranchMetadata,
|
502
931
|
getBranchMetadata,
|
503
932
|
getBranchStats,
|
@@ -515,7 +944,8 @@ const operationsByTag$2 = {
|
|
515
944
|
compareBranchSchemas,
|
516
945
|
updateBranchSchema,
|
517
946
|
previewBranchSchemaEdit,
|
518
|
-
applyBranchSchemaEdit
|
947
|
+
applyBranchSchemaEdit,
|
948
|
+
pushBranchMigrations
|
519
949
|
},
|
520
950
|
migrationRequests: {
|
521
951
|
queryMigrationRequests,
|
@@ -540,6 +970,7 @@ const operationsByTag$2 = {
|
|
540
970
|
deleteColumn
|
541
971
|
},
|
542
972
|
records: {
|
973
|
+
branchTransaction,
|
543
974
|
insertRecord,
|
544
975
|
getRecord,
|
545
976
|
insertRecordWithID,
|
@@ -548,7 +979,17 @@ const operationsByTag$2 = {
|
|
548
979
|
deleteRecord,
|
549
980
|
bulkInsertTableRecords
|
550
981
|
},
|
551
|
-
|
982
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
983
|
+
searchAndFilter: {
|
984
|
+
queryTable,
|
985
|
+
searchBranch,
|
986
|
+
searchTable,
|
987
|
+
sqlQuery,
|
988
|
+
vectorSearchTable,
|
989
|
+
askTable,
|
990
|
+
summarizeTable,
|
991
|
+
aggregateTable
|
992
|
+
}
|
552
993
|
};
|
553
994
|
|
554
995
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
@@ -647,6 +1088,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
647
1088
|
});
|
648
1089
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
649
1090
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1091
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1092
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1093
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1094
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
650
1095
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
651
1096
|
url: "/workspaces/{workspaceId}/regions",
|
652
1097
|
method: "get",
|
@@ -679,6 +1124,10 @@ const operationsByTag$1 = {
|
|
679
1124
|
deleteDatabase,
|
680
1125
|
getDatabaseMetadata,
|
681
1126
|
updateDatabaseMetadata,
|
1127
|
+
renameDatabase,
|
1128
|
+
getDatabaseGithubSettings,
|
1129
|
+
updateDatabaseGithubSettings,
|
1130
|
+
deleteDatabaseGithubSettings,
|
682
1131
|
listRegions
|
683
1132
|
}
|
684
1133
|
};
|
@@ -699,8 +1148,12 @@ const providers = {
|
|
699
1148
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
700
1149
|
},
|
701
1150
|
staging: {
|
702
|
-
main: "https://staging.
|
703
|
-
workspaces: "https://{workspaceId}.
|
1151
|
+
main: "https://api.staging-xata.dev",
|
1152
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1153
|
+
},
|
1154
|
+
dev: {
|
1155
|
+
main: "https://api.dev-xata.dev",
|
1156
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
704
1157
|
}
|
705
1158
|
};
|
706
1159
|
function isHostProviderAlias(alias) {
|
@@ -718,15 +1171,22 @@ function parseProviderString(provider = "production") {
|
|
718
1171
|
return null;
|
719
1172
|
return { main, workspaces };
|
720
1173
|
}
|
1174
|
+
function buildProviderString(provider) {
|
1175
|
+
if (isHostProviderAlias(provider))
|
1176
|
+
return provider;
|
1177
|
+
return `${provider.main},${provider.workspaces}`;
|
1178
|
+
}
|
721
1179
|
function parseWorkspacesUrlParts(url) {
|
722
1180
|
if (!isString(url))
|
723
1181
|
return null;
|
724
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
725
|
-
const
|
726
|
-
const
|
1182
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1183
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1184
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1185
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1186
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
727
1187
|
if (!match)
|
728
1188
|
return null;
|
729
|
-
return { workspace: match[1], region: match[2]
|
1189
|
+
return { workspace: match[1], region: match[2] };
|
730
1190
|
}
|
731
1191
|
|
732
1192
|
var __accessCheck$7 = (obj, member, msg) => {
|
@@ -755,15 +1215,19 @@ class XataApiClient {
|
|
755
1215
|
const provider = options.host ?? "production";
|
756
1216
|
const apiKey = options.apiKey ?? getAPIKey();
|
757
1217
|
const trace = options.trace ?? defaultTrace;
|
1218
|
+
const clientID = generateUUID();
|
758
1219
|
if (!apiKey) {
|
759
1220
|
throw new Error("Could not resolve a valid apiKey");
|
760
1221
|
}
|
761
1222
|
__privateSet$7(this, _extraProps, {
|
762
1223
|
apiUrl: getHostUrl(provider, "main"),
|
763
1224
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
764
|
-
|
1225
|
+
fetch: getFetchImplementation(options.fetch),
|
765
1226
|
apiKey,
|
766
|
-
trace
|
1227
|
+
trace,
|
1228
|
+
clientName: options.clientName,
|
1229
|
+
xataAgentExtra: options.xataAgentExtra,
|
1230
|
+
clientID
|
767
1231
|
});
|
768
1232
|
}
|
769
1233
|
get user() {
|
@@ -816,6 +1280,11 @@ class XataApiClient {
|
|
816
1280
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
817
1281
|
return __privateGet$7(this, _namespaces).records;
|
818
1282
|
}
|
1283
|
+
get files() {
|
1284
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1285
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1286
|
+
return __privateGet$7(this, _namespaces).files;
|
1287
|
+
}
|
819
1288
|
get searchAndFilter() {
|
820
1289
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
821
1290
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1024,6 +1493,20 @@ class BranchApi {
|
|
1024
1493
|
...this.extraProps
|
1025
1494
|
});
|
1026
1495
|
}
|
1496
|
+
copyBranch({
|
1497
|
+
workspace,
|
1498
|
+
region,
|
1499
|
+
database,
|
1500
|
+
branch,
|
1501
|
+
destinationBranch,
|
1502
|
+
limit
|
1503
|
+
}) {
|
1504
|
+
return operationsByTag.branch.copyBranch({
|
1505
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1506
|
+
body: { destinationBranch, limit },
|
1507
|
+
...this.extraProps
|
1508
|
+
});
|
1509
|
+
}
|
1027
1510
|
updateBranchMetadata({
|
1028
1511
|
workspace,
|
1029
1512
|
region,
|
@@ -1343,25 +1826,196 @@ class RecordsApi {
|
|
1343
1826
|
id,
|
1344
1827
|
columns
|
1345
1828
|
}) {
|
1346
|
-
return operationsByTag.records.deleteRecord({
|
1347
|
-
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1348
|
-
queryParams: { columns },
|
1829
|
+
return operationsByTag.records.deleteRecord({
|
1830
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1831
|
+
queryParams: { columns },
|
1832
|
+
...this.extraProps
|
1833
|
+
});
|
1834
|
+
}
|
1835
|
+
bulkInsertTableRecords({
|
1836
|
+
workspace,
|
1837
|
+
region,
|
1838
|
+
database,
|
1839
|
+
branch,
|
1840
|
+
table,
|
1841
|
+
records,
|
1842
|
+
columns
|
1843
|
+
}) {
|
1844
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
1845
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1846
|
+
queryParams: { columns },
|
1847
|
+
body: { records },
|
1848
|
+
...this.extraProps
|
1849
|
+
});
|
1850
|
+
}
|
1851
|
+
branchTransaction({
|
1852
|
+
workspace,
|
1853
|
+
region,
|
1854
|
+
database,
|
1855
|
+
branch,
|
1856
|
+
operations
|
1857
|
+
}) {
|
1858
|
+
return operationsByTag.records.branchTransaction({
|
1859
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1860
|
+
body: { operations },
|
1861
|
+
...this.extraProps
|
1862
|
+
});
|
1863
|
+
}
|
1864
|
+
}
|
1865
|
+
class FilesApi {
|
1866
|
+
constructor(extraProps) {
|
1867
|
+
this.extraProps = extraProps;
|
1868
|
+
}
|
1869
|
+
getFileItem({
|
1870
|
+
workspace,
|
1871
|
+
region,
|
1872
|
+
database,
|
1873
|
+
branch,
|
1874
|
+
table,
|
1875
|
+
record,
|
1876
|
+
column,
|
1877
|
+
fileId
|
1878
|
+
}) {
|
1879
|
+
return operationsByTag.files.getFileItem({
|
1880
|
+
pathParams: {
|
1881
|
+
workspace,
|
1882
|
+
region,
|
1883
|
+
dbBranchName: `${database}:${branch}`,
|
1884
|
+
tableName: table,
|
1885
|
+
recordId: record,
|
1886
|
+
columnName: column,
|
1887
|
+
fileId
|
1888
|
+
},
|
1889
|
+
...this.extraProps
|
1890
|
+
});
|
1891
|
+
}
|
1892
|
+
putFileItem({
|
1893
|
+
workspace,
|
1894
|
+
region,
|
1895
|
+
database,
|
1896
|
+
branch,
|
1897
|
+
table,
|
1898
|
+
record,
|
1899
|
+
column,
|
1900
|
+
fileId,
|
1901
|
+
file
|
1902
|
+
}) {
|
1903
|
+
return operationsByTag.files.putFileItem({
|
1904
|
+
pathParams: {
|
1905
|
+
workspace,
|
1906
|
+
region,
|
1907
|
+
dbBranchName: `${database}:${branch}`,
|
1908
|
+
tableName: table,
|
1909
|
+
recordId: record,
|
1910
|
+
columnName: column,
|
1911
|
+
fileId
|
1912
|
+
},
|
1913
|
+
// @ts-ignore
|
1914
|
+
body: file,
|
1915
|
+
...this.extraProps
|
1916
|
+
});
|
1917
|
+
}
|
1918
|
+
deleteFileItem({
|
1919
|
+
workspace,
|
1920
|
+
region,
|
1921
|
+
database,
|
1922
|
+
branch,
|
1923
|
+
table,
|
1924
|
+
record,
|
1925
|
+
column,
|
1926
|
+
fileId
|
1927
|
+
}) {
|
1928
|
+
return operationsByTag.files.deleteFileItem({
|
1929
|
+
pathParams: {
|
1930
|
+
workspace,
|
1931
|
+
region,
|
1932
|
+
dbBranchName: `${database}:${branch}`,
|
1933
|
+
tableName: table,
|
1934
|
+
recordId: record,
|
1935
|
+
columnName: column,
|
1936
|
+
fileId
|
1937
|
+
},
|
1938
|
+
...this.extraProps
|
1939
|
+
});
|
1940
|
+
}
|
1941
|
+
getFile({
|
1942
|
+
workspace,
|
1943
|
+
region,
|
1944
|
+
database,
|
1945
|
+
branch,
|
1946
|
+
table,
|
1947
|
+
record,
|
1948
|
+
column
|
1949
|
+
}) {
|
1950
|
+
return operationsByTag.files.getFile({
|
1951
|
+
pathParams: {
|
1952
|
+
workspace,
|
1953
|
+
region,
|
1954
|
+
dbBranchName: `${database}:${branch}`,
|
1955
|
+
tableName: table,
|
1956
|
+
recordId: record,
|
1957
|
+
columnName: column
|
1958
|
+
},
|
1959
|
+
...this.extraProps
|
1960
|
+
});
|
1961
|
+
}
|
1962
|
+
putFile({
|
1963
|
+
workspace,
|
1964
|
+
region,
|
1965
|
+
database,
|
1966
|
+
branch,
|
1967
|
+
table,
|
1968
|
+
record,
|
1969
|
+
column,
|
1970
|
+
file
|
1971
|
+
}) {
|
1972
|
+
return operationsByTag.files.putFile({
|
1973
|
+
pathParams: {
|
1974
|
+
workspace,
|
1975
|
+
region,
|
1976
|
+
dbBranchName: `${database}:${branch}`,
|
1977
|
+
tableName: table,
|
1978
|
+
recordId: record,
|
1979
|
+
columnName: column
|
1980
|
+
},
|
1981
|
+
body: file,
|
1982
|
+
...this.extraProps
|
1983
|
+
});
|
1984
|
+
}
|
1985
|
+
deleteFile({
|
1986
|
+
workspace,
|
1987
|
+
region,
|
1988
|
+
database,
|
1989
|
+
branch,
|
1990
|
+
table,
|
1991
|
+
record,
|
1992
|
+
column
|
1993
|
+
}) {
|
1994
|
+
return operationsByTag.files.deleteFile({
|
1995
|
+
pathParams: {
|
1996
|
+
workspace,
|
1997
|
+
region,
|
1998
|
+
dbBranchName: `${database}:${branch}`,
|
1999
|
+
tableName: table,
|
2000
|
+
recordId: record,
|
2001
|
+
columnName: column
|
2002
|
+
},
|
1349
2003
|
...this.extraProps
|
1350
2004
|
});
|
1351
2005
|
}
|
1352
|
-
|
2006
|
+
fileAccess({
|
1353
2007
|
workspace,
|
1354
2008
|
region,
|
1355
|
-
|
1356
|
-
|
1357
|
-
table,
|
1358
|
-
records,
|
1359
|
-
columns
|
2009
|
+
fileId,
|
2010
|
+
verify
|
1360
2011
|
}) {
|
1361
|
-
return operationsByTag.
|
1362
|
-
pathParams: {
|
1363
|
-
|
1364
|
-
|
2012
|
+
return operationsByTag.files.fileAccess({
|
2013
|
+
pathParams: {
|
2014
|
+
workspace,
|
2015
|
+
region,
|
2016
|
+
fileId
|
2017
|
+
},
|
2018
|
+
queryParams: { verify },
|
1365
2019
|
...this.extraProps
|
1366
2020
|
});
|
1367
2021
|
}
|
@@ -1379,11 +2033,12 @@ class SearchAndFilterApi {
|
|
1379
2033
|
filter,
|
1380
2034
|
sort,
|
1381
2035
|
page,
|
1382
|
-
columns
|
2036
|
+
columns,
|
2037
|
+
consistency
|
1383
2038
|
}) {
|
1384
2039
|
return operationsByTag.searchAndFilter.queryTable({
|
1385
2040
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1386
|
-
body: { filter, sort, page, columns },
|
2041
|
+
body: { filter, sort, page, columns, consistency },
|
1387
2042
|
...this.extraProps
|
1388
2043
|
});
|
1389
2044
|
}
|
@@ -1424,6 +2079,38 @@ class SearchAndFilterApi {
|
|
1424
2079
|
...this.extraProps
|
1425
2080
|
});
|
1426
2081
|
}
|
2082
|
+
vectorSearchTable({
|
2083
|
+
workspace,
|
2084
|
+
region,
|
2085
|
+
database,
|
2086
|
+
branch,
|
2087
|
+
table,
|
2088
|
+
queryVector,
|
2089
|
+
column,
|
2090
|
+
similarityFunction,
|
2091
|
+
size,
|
2092
|
+
filter
|
2093
|
+
}) {
|
2094
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2095
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2096
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2097
|
+
...this.extraProps
|
2098
|
+
});
|
2099
|
+
}
|
2100
|
+
askTable({
|
2101
|
+
workspace,
|
2102
|
+
region,
|
2103
|
+
database,
|
2104
|
+
branch,
|
2105
|
+
table,
|
2106
|
+
options
|
2107
|
+
}) {
|
2108
|
+
return operationsByTag.searchAndFilter.askTable({
|
2109
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2110
|
+
body: { ...options },
|
2111
|
+
...this.extraProps
|
2112
|
+
});
|
2113
|
+
}
|
1427
2114
|
summarizeTable({
|
1428
2115
|
workspace,
|
1429
2116
|
region,
|
@@ -1435,11 +2122,12 @@ class SearchAndFilterApi {
|
|
1435
2122
|
summaries,
|
1436
2123
|
sort,
|
1437
2124
|
summariesFilter,
|
1438
|
-
page
|
2125
|
+
page,
|
2126
|
+
consistency
|
1439
2127
|
}) {
|
1440
2128
|
return operationsByTag.searchAndFilter.summarizeTable({
|
1441
2129
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1442
|
-
body: { filter, columns, summaries, sort, summariesFilter, page },
|
2130
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
1443
2131
|
...this.extraProps
|
1444
2132
|
});
|
1445
2133
|
}
|
@@ -1623,11 +2311,13 @@ class MigrationsApi {
|
|
1623
2311
|
region,
|
1624
2312
|
database,
|
1625
2313
|
branch,
|
1626
|
-
schema
|
2314
|
+
schema,
|
2315
|
+
schemaOperations,
|
2316
|
+
branchOperations
|
1627
2317
|
}) {
|
1628
2318
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1629
2319
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1630
|
-
body: { schema },
|
2320
|
+
body: { schema, schemaOperations, branchOperations },
|
1631
2321
|
...this.extraProps
|
1632
2322
|
});
|
1633
2323
|
}
|
@@ -1637,11 +2327,12 @@ class MigrationsApi {
|
|
1637
2327
|
database,
|
1638
2328
|
branch,
|
1639
2329
|
compare,
|
1640
|
-
|
2330
|
+
sourceBranchOperations,
|
2331
|
+
targetBranchOperations
|
1641
2332
|
}) {
|
1642
2333
|
return operationsByTag.migrations.compareBranchSchemas({
|
1643
2334
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1644
|
-
body: {
|
2335
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
1645
2336
|
...this.extraProps
|
1646
2337
|
});
|
1647
2338
|
}
|
@@ -1684,6 +2375,19 @@ class MigrationsApi {
|
|
1684
2375
|
...this.extraProps
|
1685
2376
|
});
|
1686
2377
|
}
|
2378
|
+
pushBranchMigrations({
|
2379
|
+
workspace,
|
2380
|
+
region,
|
2381
|
+
database,
|
2382
|
+
branch,
|
2383
|
+
migrations
|
2384
|
+
}) {
|
2385
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2386
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2387
|
+
body: { migrations },
|
2388
|
+
...this.extraProps
|
2389
|
+
});
|
2390
|
+
}
|
1687
2391
|
}
|
1688
2392
|
class DatabaseApi {
|
1689
2393
|
constructor(extraProps) {
|
@@ -1735,6 +2439,46 @@ class DatabaseApi {
|
|
1735
2439
|
...this.extraProps
|
1736
2440
|
});
|
1737
2441
|
}
|
2442
|
+
renameDatabase({
|
2443
|
+
workspace,
|
2444
|
+
database,
|
2445
|
+
newName
|
2446
|
+
}) {
|
2447
|
+
return operationsByTag.databases.renameDatabase({
|
2448
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2449
|
+
body: { newName },
|
2450
|
+
...this.extraProps
|
2451
|
+
});
|
2452
|
+
}
|
2453
|
+
getDatabaseGithubSettings({
|
2454
|
+
workspace,
|
2455
|
+
database
|
2456
|
+
}) {
|
2457
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2458
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2459
|
+
...this.extraProps
|
2460
|
+
});
|
2461
|
+
}
|
2462
|
+
updateDatabaseGithubSettings({
|
2463
|
+
workspace,
|
2464
|
+
database,
|
2465
|
+
settings
|
2466
|
+
}) {
|
2467
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2468
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2469
|
+
body: settings,
|
2470
|
+
...this.extraProps
|
2471
|
+
});
|
2472
|
+
}
|
2473
|
+
deleteDatabaseGithubSettings({
|
2474
|
+
workspace,
|
2475
|
+
database
|
2476
|
+
}) {
|
2477
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2478
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2479
|
+
...this.extraProps
|
2480
|
+
});
|
2481
|
+
}
|
1738
2482
|
listRegions({ workspace }) {
|
1739
2483
|
return operationsByTag.databases.listRegions({
|
1740
2484
|
pathParams: { workspaceId: workspace },
|
@@ -1744,22 +2488,14 @@ class DatabaseApi {
|
|
1744
2488
|
}
|
1745
2489
|
|
1746
2490
|
class XataApiPlugin {
|
1747
|
-
|
1748
|
-
|
1749
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2491
|
+
build(options) {
|
2492
|
+
return new XataApiClient(options);
|
1750
2493
|
}
|
1751
2494
|
}
|
1752
2495
|
|
1753
2496
|
class XataPlugin {
|
1754
2497
|
}
|
1755
2498
|
|
1756
|
-
function generateUUID() {
|
1757
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1758
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1759
|
-
return v.toString(16);
|
1760
|
-
});
|
1761
|
-
}
|
1762
|
-
|
1763
2499
|
function cleanFilter(filter) {
|
1764
2500
|
if (!filter)
|
1765
2501
|
return void 0;
|
@@ -1793,18 +2529,46 @@ class Page {
|
|
1793
2529
|
this.meta = meta;
|
1794
2530
|
this.records = new RecordArray(this, records);
|
1795
2531
|
}
|
2532
|
+
/**
|
2533
|
+
* Retrieves the next page of results.
|
2534
|
+
* @param size Maximum number of results to be retrieved.
|
2535
|
+
* @param offset Number of results to skip when retrieving the results.
|
2536
|
+
* @returns The next page or results.
|
2537
|
+
*/
|
1796
2538
|
async nextPage(size, offset) {
|
1797
2539
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1798
2540
|
}
|
2541
|
+
/**
|
2542
|
+
* Retrieves the previous page of results.
|
2543
|
+
* @param size Maximum number of results to be retrieved.
|
2544
|
+
* @param offset Number of results to skip when retrieving the results.
|
2545
|
+
* @returns The previous page or results.
|
2546
|
+
*/
|
1799
2547
|
async previousPage(size, offset) {
|
1800
2548
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1801
2549
|
}
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
2550
|
+
/**
|
2551
|
+
* Retrieves the start page of results.
|
2552
|
+
* @param size Maximum number of results to be retrieved.
|
2553
|
+
* @param offset Number of results to skip when retrieving the results.
|
2554
|
+
* @returns The start page or results.
|
2555
|
+
*/
|
2556
|
+
async startPage(size, offset) {
|
2557
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
2558
|
+
}
|
2559
|
+
/**
|
2560
|
+
* Retrieves the end page of results.
|
2561
|
+
* @param size Maximum number of results to be retrieved.
|
2562
|
+
* @param offset Number of results to skip when retrieving the results.
|
2563
|
+
* @returns The end page or results.
|
2564
|
+
*/
|
2565
|
+
async endPage(size, offset) {
|
2566
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
2567
|
+
}
|
2568
|
+
/**
|
2569
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2570
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2571
|
+
*/
|
1808
2572
|
hasNextPage() {
|
1809
2573
|
return this.meta.page.more;
|
1810
2574
|
}
|
@@ -1815,7 +2579,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
|
|
1815
2579
|
const PAGINATION_MAX_OFFSET = 800;
|
1816
2580
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1817
2581
|
function isCursorPaginationOptions(options) {
|
1818
|
-
return isDefined(options) && (isDefined(options.
|
2582
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1819
2583
|
}
|
1820
2584
|
const _RecordArray = class extends Array {
|
1821
2585
|
constructor(...args) {
|
@@ -1836,25 +2600,54 @@ const _RecordArray = class extends Array {
|
|
1836
2600
|
toArray() {
|
1837
2601
|
return new Array(...this);
|
1838
2602
|
}
|
2603
|
+
toSerializable() {
|
2604
|
+
return JSON.parse(this.toString());
|
2605
|
+
}
|
2606
|
+
toString() {
|
2607
|
+
return JSON.stringify(this.toArray());
|
2608
|
+
}
|
1839
2609
|
map(callbackfn, thisArg) {
|
1840
2610
|
return this.toArray().map(callbackfn, thisArg);
|
1841
2611
|
}
|
2612
|
+
/**
|
2613
|
+
* Retrieve next page of records
|
2614
|
+
*
|
2615
|
+
* @returns A new array of objects
|
2616
|
+
*/
|
1842
2617
|
async nextPage(size, offset) {
|
1843
2618
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1844
2619
|
return new _RecordArray(newPage);
|
1845
2620
|
}
|
2621
|
+
/**
|
2622
|
+
* Retrieve previous page of records
|
2623
|
+
*
|
2624
|
+
* @returns A new array of objects
|
2625
|
+
*/
|
1846
2626
|
async previousPage(size, offset) {
|
1847
2627
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1848
2628
|
return new _RecordArray(newPage);
|
1849
2629
|
}
|
1850
|
-
|
1851
|
-
|
2630
|
+
/**
|
2631
|
+
* Retrieve start page of records
|
2632
|
+
*
|
2633
|
+
* @returns A new array of objects
|
2634
|
+
*/
|
2635
|
+
async startPage(size, offset) {
|
2636
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1852
2637
|
return new _RecordArray(newPage);
|
1853
2638
|
}
|
1854
|
-
|
1855
|
-
|
2639
|
+
/**
|
2640
|
+
* Retrieve end page of records
|
2641
|
+
*
|
2642
|
+
* @returns A new array of objects
|
2643
|
+
*/
|
2644
|
+
async endPage(size, offset) {
|
2645
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1856
2646
|
return new _RecordArray(newPage);
|
1857
2647
|
}
|
2648
|
+
/**
|
2649
|
+
* @returns Boolean indicating if there is a next page
|
2650
|
+
*/
|
1858
2651
|
hasNextPage() {
|
1859
2652
|
return __privateGet$6(this, _page).meta.page.more;
|
1860
2653
|
}
|
@@ -1891,7 +2684,8 @@ const _Query = class {
|
|
1891
2684
|
__privateAdd$5(this, _table$1, void 0);
|
1892
2685
|
__privateAdd$5(this, _repository, void 0);
|
1893
2686
|
__privateAdd$5(this, _data, { filter: {} });
|
1894
|
-
|
2687
|
+
// Implements pagination
|
2688
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1895
2689
|
this.records = new RecordArray(this, []);
|
1896
2690
|
__privateSet$5(this, _table$1, table);
|
1897
2691
|
if (repository) {
|
@@ -1907,8 +2701,10 @@ const _Query = class {
|
|
1907
2701
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1908
2702
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1909
2703
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
2704
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1910
2705
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1911
2706
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2707
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1912
2708
|
this.any = this.any.bind(this);
|
1913
2709
|
this.all = this.all.bind(this);
|
1914
2710
|
this.not = this.not.bind(this);
|
@@ -1926,18 +2722,38 @@ const _Query = class {
|
|
1926
2722
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1927
2723
|
return toBase64(key);
|
1928
2724
|
}
|
2725
|
+
/**
|
2726
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
2727
|
+
* @param queries An array of subqueries.
|
2728
|
+
* @returns A new Query object.
|
2729
|
+
*/
|
1929
2730
|
any(...queries) {
|
1930
2731
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1931
2732
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
1932
2733
|
}
|
2734
|
+
/**
|
2735
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
2736
|
+
* @param queries An array of subqueries.
|
2737
|
+
* @returns A new Query object.
|
2738
|
+
*/
|
1933
2739
|
all(...queries) {
|
1934
2740
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1935
2741
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1936
2742
|
}
|
2743
|
+
/**
|
2744
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
2745
|
+
* @param queries An array of subqueries.
|
2746
|
+
* @returns A new Query object.
|
2747
|
+
*/
|
1937
2748
|
not(...queries) {
|
1938
2749
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1939
2750
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
1940
2751
|
}
|
2752
|
+
/**
|
2753
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
2754
|
+
* @param queries An array of subqueries.
|
2755
|
+
* @returns A new Query object.
|
2756
|
+
*/
|
1941
2757
|
none(...queries) {
|
1942
2758
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1943
2759
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -1960,6 +2776,11 @@ const _Query = class {
|
|
1960
2776
|
const sort = [...originalSort, { column, direction }];
|
1961
2777
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1962
2778
|
}
|
2779
|
+
/**
|
2780
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
2781
|
+
* @param columns Array of column names to be returned by the query.
|
2782
|
+
* @returns A new Query object.
|
2783
|
+
*/
|
1963
2784
|
select(columns) {
|
1964
2785
|
return new _Query(
|
1965
2786
|
__privateGet$5(this, _repository),
|
@@ -1972,6 +2793,12 @@ const _Query = class {
|
|
1972
2793
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1973
2794
|
return __privateGet$5(this, _repository).query(query);
|
1974
2795
|
}
|
2796
|
+
/**
|
2797
|
+
* Get results in an iterator
|
2798
|
+
*
|
2799
|
+
* @async
|
2800
|
+
* @returns Async interable of results
|
2801
|
+
*/
|
1975
2802
|
async *[Symbol.asyncIterator]() {
|
1976
2803
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1977
2804
|
yield record;
|
@@ -2032,21 +2859,49 @@ const _Query = class {
|
|
2032
2859
|
);
|
2033
2860
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2034
2861
|
}
|
2862
|
+
/**
|
2863
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
2864
|
+
* @param ttl The cache TTL in milliseconds.
|
2865
|
+
* @returns A new Query object.
|
2866
|
+
*/
|
2035
2867
|
cache(ttl) {
|
2036
2868
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2037
2869
|
}
|
2870
|
+
/**
|
2871
|
+
* Retrieve next page of records
|
2872
|
+
*
|
2873
|
+
* @returns A new page object.
|
2874
|
+
*/
|
2038
2875
|
nextPage(size, offset) {
|
2039
|
-
return this.
|
2876
|
+
return this.startPage(size, offset);
|
2040
2877
|
}
|
2878
|
+
/**
|
2879
|
+
* Retrieve previous page of records
|
2880
|
+
*
|
2881
|
+
* @returns A new page object
|
2882
|
+
*/
|
2041
2883
|
previousPage(size, offset) {
|
2042
|
-
return this.
|
2043
|
-
}
|
2044
|
-
|
2884
|
+
return this.startPage(size, offset);
|
2885
|
+
}
|
2886
|
+
/**
|
2887
|
+
* Retrieve start page of records
|
2888
|
+
*
|
2889
|
+
* @returns A new page object
|
2890
|
+
*/
|
2891
|
+
startPage(size, offset) {
|
2045
2892
|
return this.getPaginated({ pagination: { size, offset } });
|
2046
2893
|
}
|
2047
|
-
|
2894
|
+
/**
|
2895
|
+
* Retrieve last page of records
|
2896
|
+
*
|
2897
|
+
* @returns A new page object
|
2898
|
+
*/
|
2899
|
+
endPage(size, offset) {
|
2048
2900
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2049
2901
|
}
|
2902
|
+
/**
|
2903
|
+
* @returns Boolean indicating if there is a next page
|
2904
|
+
*/
|
2050
2905
|
hasNextPage() {
|
2051
2906
|
return this.meta.page.more;
|
2052
2907
|
}
|
@@ -2086,7 +2941,11 @@ function isSortFilterString(value) {
|
|
2086
2941
|
return isString(value);
|
2087
2942
|
}
|
2088
2943
|
function isSortFilterBase(filter) {
|
2089
|
-
return isObject(filter) && Object.
|
2944
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
2945
|
+
if (key === "*")
|
2946
|
+
return value === "random";
|
2947
|
+
return value === "asc" || value === "desc";
|
2948
|
+
});
|
2090
2949
|
}
|
2091
2950
|
function isSortFilterObject(filter) {
|
2092
2951
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2127,7 +2986,8 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2127
2986
|
__accessCheck$4(obj, member, "access private method");
|
2128
2987
|
return method;
|
2129
2988
|
};
|
2130
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2989
|
+
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;
|
2990
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2131
2991
|
class Repository extends Query {
|
2132
2992
|
}
|
2133
2993
|
class RestRepository extends Query {
|
@@ -2139,10 +2999,12 @@ class RestRepository extends Query {
|
|
2139
2999
|
);
|
2140
3000
|
__privateAdd$4(this, _insertRecordWithoutId);
|
2141
3001
|
__privateAdd$4(this, _insertRecordWithId);
|
2142
|
-
__privateAdd$4(this,
|
3002
|
+
__privateAdd$4(this, _insertRecords);
|
2143
3003
|
__privateAdd$4(this, _updateRecordWithID);
|
3004
|
+
__privateAdd$4(this, _updateRecords);
|
2144
3005
|
__privateAdd$4(this, _upsertRecordWithID);
|
2145
3006
|
__privateAdd$4(this, _deleteRecord);
|
3007
|
+
__privateAdd$4(this, _deleteRecords);
|
2146
3008
|
__privateAdd$4(this, _setCacheQuery);
|
2147
3009
|
__privateAdd$4(this, _getCacheQuery);
|
2148
3010
|
__privateAdd$4(this, _getSchemaTables$1);
|
@@ -2156,10 +3018,7 @@ class RestRepository extends Query {
|
|
2156
3018
|
__privateSet$4(this, _db, options.db);
|
2157
3019
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2158
3020
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2159
|
-
__privateSet$4(this, _getFetchProps,
|
2160
|
-
const props = await options.pluginOptions.getFetchProps();
|
2161
|
-
return { ...props, sessionID: generateUUID() };
|
2162
|
-
});
|
3021
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2163
3022
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2164
3023
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2165
3024
|
return trace(name, fn, {
|
@@ -2176,20 +3035,22 @@ class RestRepository extends Query {
|
|
2176
3035
|
if (Array.isArray(a)) {
|
2177
3036
|
if (a.length === 0)
|
2178
3037
|
return [];
|
2179
|
-
const
|
2180
|
-
|
3038
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3039
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3040
|
+
const result = await this.read(ids, columns);
|
3041
|
+
return result;
|
2181
3042
|
}
|
2182
3043
|
if (isString(a) && isObject(b)) {
|
2183
3044
|
if (a === "")
|
2184
3045
|
throw new Error("The id can't be empty");
|
2185
3046
|
const columns = isStringArray(c) ? c : void 0;
|
2186
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3047
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2187
3048
|
}
|
2188
3049
|
if (isObject(a) && isString(a.id)) {
|
2189
3050
|
if (a.id === "")
|
2190
3051
|
throw new Error("The id can't be empty");
|
2191
3052
|
const columns = isStringArray(b) ? b : void 0;
|
2192
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3053
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2193
3054
|
}
|
2194
3055
|
if (isObject(a)) {
|
2195
3056
|
const columns = isStringArray(b) ? b : void 0;
|
@@ -2214,7 +3075,6 @@ class RestRepository extends Query {
|
|
2214
3075
|
}
|
2215
3076
|
const id = extractId(a);
|
2216
3077
|
if (id) {
|
2217
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2218
3078
|
try {
|
2219
3079
|
const response = await getRecord({
|
2220
3080
|
pathParams: {
|
@@ -2225,7 +3085,7 @@ class RestRepository extends Query {
|
|
2225
3085
|
recordId: id
|
2226
3086
|
},
|
2227
3087
|
queryParams: { columns },
|
2228
|
-
...
|
3088
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2229
3089
|
});
|
2230
3090
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2231
3091
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2264,19 +3124,29 @@ class RestRepository extends Query {
|
|
2264
3124
|
if (Array.isArray(a)) {
|
2265
3125
|
if (a.length === 0)
|
2266
3126
|
return [];
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
3127
|
+
const existing = await this.read(a, ["id"]);
|
3128
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
3129
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
3130
|
+
ifVersion,
|
3131
|
+
upsert: false
|
3132
|
+
});
|
2270
3133
|
const columns = isStringArray(b) ? b : ["*"];
|
2271
|
-
|
2272
|
-
|
2273
|
-
if (isString(a) && isObject(b)) {
|
2274
|
-
const columns = isStringArray(c) ? c : void 0;
|
2275
|
-
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3134
|
+
const result = await this.read(a, columns);
|
3135
|
+
return result;
|
2276
3136
|
}
|
2277
|
-
|
2278
|
-
|
2279
|
-
|
3137
|
+
try {
|
3138
|
+
if (isString(a) && isObject(b)) {
|
3139
|
+
const columns = isStringArray(c) ? c : void 0;
|
3140
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3141
|
+
}
|
3142
|
+
if (isObject(a) && isString(a.id)) {
|
3143
|
+
const columns = isStringArray(b) ? b : void 0;
|
3144
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3145
|
+
}
|
3146
|
+
} catch (error) {
|
3147
|
+
if (error.status === 422)
|
3148
|
+
return null;
|
3149
|
+
throw error;
|
2280
3150
|
}
|
2281
3151
|
throw new Error("Invalid arguments for update method");
|
2282
3152
|
});
|
@@ -2306,19 +3176,31 @@ class RestRepository extends Query {
|
|
2306
3176
|
if (Array.isArray(a)) {
|
2307
3177
|
if (a.length === 0)
|
2308
3178
|
return [];
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
3179
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
3180
|
+
ifVersion,
|
3181
|
+
upsert: true
|
3182
|
+
});
|
2312
3183
|
const columns = isStringArray(b) ? b : ["*"];
|
2313
|
-
|
3184
|
+
const result = await this.read(a, columns);
|
3185
|
+
return result;
|
2314
3186
|
}
|
2315
3187
|
if (isString(a) && isObject(b)) {
|
3188
|
+
if (a === "")
|
3189
|
+
throw new Error("The id can't be empty");
|
2316
3190
|
const columns = isStringArray(c) ? c : void 0;
|
2317
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3191
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2318
3192
|
}
|
2319
3193
|
if (isObject(a) && isString(a.id)) {
|
3194
|
+
if (a.id === "")
|
3195
|
+
throw new Error("The id can't be empty");
|
2320
3196
|
const columns = isStringArray(c) ? c : void 0;
|
2321
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3197
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3198
|
+
}
|
3199
|
+
if (!isDefined(a) && isObject(b)) {
|
3200
|
+
return await this.create(b, c);
|
3201
|
+
}
|
3202
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3203
|
+
return await this.create(a, b);
|
2322
3204
|
}
|
2323
3205
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2324
3206
|
});
|
@@ -2329,16 +3211,28 @@ class RestRepository extends Query {
|
|
2329
3211
|
if (Array.isArray(a)) {
|
2330
3212
|
if (a.length === 0)
|
2331
3213
|
return [];
|
3214
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2332
3215
|
const columns = isStringArray(b) ? b : ["*"];
|
2333
|
-
|
3216
|
+
const result = await this.read(ids, columns);
|
3217
|
+
return result;
|
2334
3218
|
}
|
2335
3219
|
if (isString(a) && isObject(b)) {
|
3220
|
+
if (a === "")
|
3221
|
+
throw new Error("The id can't be empty");
|
2336
3222
|
const columns = isStringArray(c) ? c : void 0;
|
2337
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3223
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2338
3224
|
}
|
2339
3225
|
if (isObject(a) && isString(a.id)) {
|
3226
|
+
if (a.id === "")
|
3227
|
+
throw new Error("The id can't be empty");
|
2340
3228
|
const columns = isStringArray(c) ? c : void 0;
|
2341
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3229
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3230
|
+
}
|
3231
|
+
if (!isDefined(a) && isObject(b)) {
|
3232
|
+
return await this.create(b, c);
|
3233
|
+
}
|
3234
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3235
|
+
return await this.create(a, b);
|
2342
3236
|
}
|
2343
3237
|
throw new Error("Invalid arguments for createOrReplace method");
|
2344
3238
|
});
|
@@ -2348,10 +3242,17 @@ class RestRepository extends Query {
|
|
2348
3242
|
if (Array.isArray(a)) {
|
2349
3243
|
if (a.length === 0)
|
2350
3244
|
return [];
|
2351
|
-
|
2352
|
-
|
2353
|
-
|
2354
|
-
|
3245
|
+
const ids = a.map((o) => {
|
3246
|
+
if (isString(o))
|
3247
|
+
return o;
|
3248
|
+
if (isString(o.id))
|
3249
|
+
return o.id;
|
3250
|
+
throw new Error("Invalid arguments for delete method");
|
3251
|
+
});
|
3252
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3253
|
+
const result = await this.read(a, columns);
|
3254
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3255
|
+
return result;
|
2355
3256
|
}
|
2356
3257
|
if (isString(a)) {
|
2357
3258
|
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
@@ -2382,7 +3283,6 @@ class RestRepository extends Query {
|
|
2382
3283
|
}
|
2383
3284
|
async search(query, options = {}) {
|
2384
3285
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2385
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2386
3286
|
const { records } = await searchTable({
|
2387
3287
|
pathParams: {
|
2388
3288
|
workspace: "{workspaceId}",
|
@@ -2396,9 +3296,33 @@ class RestRepository extends Query {
|
|
2396
3296
|
prefix: options.prefix,
|
2397
3297
|
highlight: options.highlight,
|
2398
3298
|
filter: options.filter,
|
2399
|
-
boosters: options.boosters
|
3299
|
+
boosters: options.boosters,
|
3300
|
+
page: options.page,
|
3301
|
+
target: options.target
|
3302
|
+
},
|
3303
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3304
|
+
});
|
3305
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3306
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3307
|
+
});
|
3308
|
+
}
|
3309
|
+
async vectorSearch(column, query, options) {
|
3310
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3311
|
+
const { records } = await vectorSearchTable({
|
3312
|
+
pathParams: {
|
3313
|
+
workspace: "{workspaceId}",
|
3314
|
+
dbBranchName: "{dbBranch}",
|
3315
|
+
region: "{region}",
|
3316
|
+
tableName: __privateGet$4(this, _table)
|
3317
|
+
},
|
3318
|
+
body: {
|
3319
|
+
column,
|
3320
|
+
queryVector: query,
|
3321
|
+
similarityFunction: options?.similarityFunction,
|
3322
|
+
size: options?.size,
|
3323
|
+
filter: options?.filter
|
2400
3324
|
},
|
2401
|
-
...
|
3325
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2402
3326
|
});
|
2403
3327
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2404
3328
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
@@ -2406,7 +3330,6 @@ class RestRepository extends Query {
|
|
2406
3330
|
}
|
2407
3331
|
async aggregate(aggs, filter) {
|
2408
3332
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2409
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2410
3333
|
const result = await aggregateTable({
|
2411
3334
|
pathParams: {
|
2412
3335
|
workspace: "{workspaceId}",
|
@@ -2415,7 +3338,7 @@ class RestRepository extends Query {
|
|
2415
3338
|
tableName: __privateGet$4(this, _table)
|
2416
3339
|
},
|
2417
3340
|
body: { aggs, filter },
|
2418
|
-
...
|
3341
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2419
3342
|
});
|
2420
3343
|
return result;
|
2421
3344
|
});
|
@@ -2426,7 +3349,6 @@ class RestRepository extends Query {
|
|
2426
3349
|
if (cacheQuery)
|
2427
3350
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2428
3351
|
const data = query.getQueryOptions();
|
2429
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2430
3352
|
const { meta, records: objects } = await queryTable({
|
2431
3353
|
pathParams: {
|
2432
3354
|
workspace: "{workspaceId}",
|
@@ -2438,9 +3360,11 @@ class RestRepository extends Query {
|
|
2438
3360
|
filter: cleanFilter(data.filter),
|
2439
3361
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2440
3362
|
page: data.pagination,
|
2441
|
-
columns: data.columns ?? ["*"]
|
3363
|
+
columns: data.columns ?? ["*"],
|
3364
|
+
consistency: data.consistency
|
2442
3365
|
},
|
2443
|
-
|
3366
|
+
fetchOptions: data.fetchOptions,
|
3367
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2444
3368
|
});
|
2445
3369
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2446
3370
|
const records = objects.map(
|
@@ -2453,7 +3377,6 @@ class RestRepository extends Query {
|
|
2453
3377
|
async summarizeTable(query, summaries, summariesFilter) {
|
2454
3378
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2455
3379
|
const data = query.getQueryOptions();
|
2456
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2457
3380
|
const result = await summarizeTable({
|
2458
3381
|
pathParams: {
|
2459
3382
|
workspace: "{workspaceId}",
|
@@ -2465,15 +3388,44 @@ class RestRepository extends Query {
|
|
2465
3388
|
filter: cleanFilter(data.filter),
|
2466
3389
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2467
3390
|
columns: data.columns,
|
3391
|
+
consistency: data.consistency,
|
2468
3392
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2469
3393
|
summaries,
|
2470
3394
|
summariesFilter
|
2471
3395
|
},
|
2472
|
-
...
|
3396
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2473
3397
|
});
|
2474
3398
|
return result;
|
2475
3399
|
});
|
2476
3400
|
}
|
3401
|
+
ask(question, options) {
|
3402
|
+
const params = {
|
3403
|
+
pathParams: {
|
3404
|
+
workspace: "{workspaceId}",
|
3405
|
+
dbBranchName: "{dbBranch}",
|
3406
|
+
region: "{region}",
|
3407
|
+
tableName: __privateGet$4(this, _table)
|
3408
|
+
},
|
3409
|
+
body: {
|
3410
|
+
question,
|
3411
|
+
...options
|
3412
|
+
},
|
3413
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3414
|
+
};
|
3415
|
+
if (options?.onMessage) {
|
3416
|
+
fetchSSERequest({
|
3417
|
+
endpoint: "dataPlane",
|
3418
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3419
|
+
method: "POST",
|
3420
|
+
onMessage: (message) => {
|
3421
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3422
|
+
},
|
3423
|
+
...params
|
3424
|
+
});
|
3425
|
+
} else {
|
3426
|
+
return askTable(params);
|
3427
|
+
}
|
3428
|
+
}
|
2477
3429
|
}
|
2478
3430
|
_table = new WeakMap();
|
2479
3431
|
_getFetchProps = new WeakMap();
|
@@ -2483,7 +3435,6 @@ _schemaTables$2 = new WeakMap();
|
|
2483
3435
|
_trace = new WeakMap();
|
2484
3436
|
_insertRecordWithoutId = new WeakSet();
|
2485
3437
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2486
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2487
3438
|
const record = transformObjectLinks(object);
|
2488
3439
|
const response = await insertRecord({
|
2489
3440
|
pathParams: {
|
@@ -2494,14 +3445,15 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2494
3445
|
},
|
2495
3446
|
queryParams: { columns },
|
2496
3447
|
body: record,
|
2497
|
-
...
|
3448
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2498
3449
|
});
|
2499
3450
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2500
3451
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2501
3452
|
};
|
2502
3453
|
_insertRecordWithId = new WeakSet();
|
2503
3454
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2504
|
-
|
3455
|
+
if (!recordId)
|
3456
|
+
return null;
|
2505
3457
|
const record = transformObjectLinks(object);
|
2506
3458
|
const response = await insertRecordWithID({
|
2507
3459
|
pathParams: {
|
@@ -2513,36 +3465,45 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2513
3465
|
},
|
2514
3466
|
body: record,
|
2515
3467
|
queryParams: { createOnly, columns, ifVersion },
|
2516
|
-
...
|
3468
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2517
3469
|
});
|
2518
3470
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2519
3471
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2520
3472
|
};
|
2521
|
-
|
2522
|
-
|
2523
|
-
const
|
2524
|
-
|
2525
|
-
|
2526
|
-
|
2527
|
-
|
2528
|
-
|
2529
|
-
|
2530
|
-
|
2531
|
-
}
|
2532
|
-
|
2533
|
-
|
2534
|
-
|
2535
|
-
|
2536
|
-
|
2537
|
-
|
3473
|
+
_insertRecords = new WeakSet();
|
3474
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3475
|
+
const chunkedOperations = chunk(
|
3476
|
+
objects.map((object) => ({
|
3477
|
+
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
3478
|
+
})),
|
3479
|
+
BULK_OPERATION_MAX_SIZE
|
3480
|
+
);
|
3481
|
+
const ids = [];
|
3482
|
+
for (const operations of chunkedOperations) {
|
3483
|
+
const { results } = await branchTransaction({
|
3484
|
+
pathParams: {
|
3485
|
+
workspace: "{workspaceId}",
|
3486
|
+
dbBranchName: "{dbBranch}",
|
3487
|
+
region: "{region}"
|
3488
|
+
},
|
3489
|
+
body: { operations },
|
3490
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3491
|
+
});
|
3492
|
+
for (const result of results) {
|
3493
|
+
if (result.operation === "insert") {
|
3494
|
+
ids.push(result.id);
|
3495
|
+
} else {
|
3496
|
+
ids.push(null);
|
3497
|
+
}
|
3498
|
+
}
|
2538
3499
|
}
|
2539
|
-
|
2540
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
3500
|
+
return ids;
|
2541
3501
|
};
|
2542
3502
|
_updateRecordWithID = new WeakSet();
|
2543
3503
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2544
|
-
|
2545
|
-
|
3504
|
+
if (!recordId)
|
3505
|
+
return null;
|
3506
|
+
const { id: _id, ...record } = transformObjectLinks(object);
|
2546
3507
|
try {
|
2547
3508
|
const response = await updateRecordWithID({
|
2548
3509
|
pathParams: {
|
@@ -2554,7 +3515,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2554
3515
|
},
|
2555
3516
|
queryParams: { columns, ifVersion },
|
2556
3517
|
body: record,
|
2557
|
-
...
|
3518
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2558
3519
|
});
|
2559
3520
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2560
3521
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2565,9 +3526,39 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2565
3526
|
throw e;
|
2566
3527
|
}
|
2567
3528
|
};
|
3529
|
+
_updateRecords = new WeakSet();
|
3530
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3531
|
+
const chunkedOperations = chunk(
|
3532
|
+
objects.map(({ id, ...object }) => ({
|
3533
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
3534
|
+
})),
|
3535
|
+
BULK_OPERATION_MAX_SIZE
|
3536
|
+
);
|
3537
|
+
const ids = [];
|
3538
|
+
for (const operations of chunkedOperations) {
|
3539
|
+
const { results } = await branchTransaction({
|
3540
|
+
pathParams: {
|
3541
|
+
workspace: "{workspaceId}",
|
3542
|
+
dbBranchName: "{dbBranch}",
|
3543
|
+
region: "{region}"
|
3544
|
+
},
|
3545
|
+
body: { operations },
|
3546
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3547
|
+
});
|
3548
|
+
for (const result of results) {
|
3549
|
+
if (result.operation === "update") {
|
3550
|
+
ids.push(result.id);
|
3551
|
+
} else {
|
3552
|
+
ids.push(null);
|
3553
|
+
}
|
3554
|
+
}
|
3555
|
+
}
|
3556
|
+
return ids;
|
3557
|
+
};
|
2568
3558
|
_upsertRecordWithID = new WeakSet();
|
2569
3559
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2570
|
-
|
3560
|
+
if (!recordId)
|
3561
|
+
return null;
|
2571
3562
|
const response = await upsertRecordWithID({
|
2572
3563
|
pathParams: {
|
2573
3564
|
workspace: "{workspaceId}",
|
@@ -2578,14 +3569,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2578
3569
|
},
|
2579
3570
|
queryParams: { columns, ifVersion },
|
2580
3571
|
body: object,
|
2581
|
-
...
|
3572
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2582
3573
|
});
|
2583
3574
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2584
3575
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2585
3576
|
};
|
2586
3577
|
_deleteRecord = new WeakSet();
|
2587
3578
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2588
|
-
|
3579
|
+
if (!recordId)
|
3580
|
+
return null;
|
2589
3581
|
try {
|
2590
3582
|
const response = await deleteRecord({
|
2591
3583
|
pathParams: {
|
@@ -2596,7 +3588,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2596
3588
|
recordId
|
2597
3589
|
},
|
2598
3590
|
queryParams: { columns },
|
2599
|
-
...
|
3591
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2600
3592
|
});
|
2601
3593
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2602
3594
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2607,17 +3599,36 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2607
3599
|
throw e;
|
2608
3600
|
}
|
2609
3601
|
};
|
3602
|
+
_deleteRecords = new WeakSet();
|
3603
|
+
deleteRecords_fn = async function(recordIds) {
|
3604
|
+
const chunkedOperations = chunk(
|
3605
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3606
|
+
BULK_OPERATION_MAX_SIZE
|
3607
|
+
);
|
3608
|
+
for (const operations of chunkedOperations) {
|
3609
|
+
await branchTransaction({
|
3610
|
+
pathParams: {
|
3611
|
+
workspace: "{workspaceId}",
|
3612
|
+
dbBranchName: "{dbBranch}",
|
3613
|
+
region: "{region}"
|
3614
|
+
},
|
3615
|
+
body: { operations },
|
3616
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3617
|
+
});
|
3618
|
+
}
|
3619
|
+
};
|
2610
3620
|
_setCacheQuery = new WeakSet();
|
2611
3621
|
setCacheQuery_fn = async function(query, meta, records) {
|
2612
|
-
await __privateGet$4(this, _cache)
|
3622
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2613
3623
|
};
|
2614
3624
|
_getCacheQuery = new WeakSet();
|
2615
3625
|
getCacheQuery_fn = async function(query) {
|
2616
3626
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2617
|
-
const result = await __privateGet$4(this, _cache)
|
3627
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2618
3628
|
if (!result)
|
2619
3629
|
return null;
|
2620
|
-
const
|
3630
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3631
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2621
3632
|
if (ttl < 0)
|
2622
3633
|
return null;
|
2623
3634
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2627,10 +3638,9 @@ _getSchemaTables$1 = new WeakSet();
|
|
2627
3638
|
getSchemaTables_fn$1 = async function() {
|
2628
3639
|
if (__privateGet$4(this, _schemaTables$2))
|
2629
3640
|
return __privateGet$4(this, _schemaTables$2);
|
2630
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2631
3641
|
const { schema } = await getBranchDetails({
|
2632
3642
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2633
|
-
...
|
3643
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2634
3644
|
});
|
2635
3645
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2636
3646
|
return schema.tables;
|
@@ -2643,23 +3653,23 @@ const transformObjectLinks = (object) => {
|
|
2643
3653
|
}, {});
|
2644
3654
|
};
|
2645
3655
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2646
|
-
const
|
3656
|
+
const data = {};
|
2647
3657
|
const { xata, ...rest } = object ?? {};
|
2648
|
-
Object.assign(
|
3658
|
+
Object.assign(data, rest);
|
2649
3659
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
2650
3660
|
if (!columns)
|
2651
3661
|
console.error(`Table ${table} not found in schema`);
|
2652
3662
|
for (const column of columns ?? []) {
|
2653
3663
|
if (!isValidColumn(selectedColumns, column))
|
2654
3664
|
continue;
|
2655
|
-
const value =
|
3665
|
+
const value = data[column.name];
|
2656
3666
|
switch (column.type) {
|
2657
3667
|
case "datetime": {
|
2658
|
-
const date = value !== void 0 ? new Date(value) :
|
2659
|
-
if (date && isNaN(date.getTime())) {
|
3668
|
+
const date = value !== void 0 ? new Date(value) : null;
|
3669
|
+
if (date !== null && isNaN(date.getTime())) {
|
2660
3670
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
2661
|
-
} else
|
2662
|
-
|
3671
|
+
} else {
|
3672
|
+
data[column.name] = date;
|
2663
3673
|
}
|
2664
3674
|
break;
|
2665
3675
|
}
|
@@ -2678,48 +3688,55 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2678
3688
|
}
|
2679
3689
|
return acc;
|
2680
3690
|
}, []);
|
2681
|
-
|
3691
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2682
3692
|
} else {
|
2683
|
-
|
3693
|
+
data[column.name] = null;
|
2684
3694
|
}
|
2685
3695
|
break;
|
2686
3696
|
}
|
2687
3697
|
default:
|
2688
|
-
|
3698
|
+
data[column.name] = value ?? null;
|
2689
3699
|
if (column.notNull === true && value === null) {
|
2690
3700
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2691
3701
|
}
|
2692
3702
|
break;
|
2693
3703
|
}
|
2694
3704
|
}
|
2695
|
-
|
2696
|
-
|
3705
|
+
const record = { ...data };
|
3706
|
+
const serializable = { xata, ...transformObjectLinks(data) };
|
3707
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
3708
|
+
record.read = function(columns2) {
|
3709
|
+
return db[table].read(record["id"], columns2);
|
2697
3710
|
};
|
2698
|
-
|
3711
|
+
record.update = function(data2, b, c) {
|
2699
3712
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2700
3713
|
const ifVersion = parseIfVersion(b, c);
|
2701
|
-
return db[table].update(
|
3714
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2702
3715
|
};
|
2703
|
-
|
3716
|
+
record.replace = function(data2, b, c) {
|
2704
3717
|
const columns2 = isStringArray(b) ? b : ["*"];
|
2705
3718
|
const ifVersion = parseIfVersion(b, c);
|
2706
|
-
return db[table].createOrReplace(
|
3719
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
3720
|
+
};
|
3721
|
+
record.delete = function() {
|
3722
|
+
return db[table].delete(record["id"]);
|
2707
3723
|
};
|
2708
|
-
|
2709
|
-
|
3724
|
+
record.xata = Object.freeze(metadata);
|
3725
|
+
record.getMetadata = function() {
|
3726
|
+
return record.xata;
|
2710
3727
|
};
|
2711
|
-
|
2712
|
-
return
|
3728
|
+
record.toSerializable = function() {
|
3729
|
+
return JSON.parse(JSON.stringify(serializable));
|
2713
3730
|
};
|
2714
|
-
|
2715
|
-
|
3731
|
+
record.toString = function() {
|
3732
|
+
return JSON.stringify(transformObjectLinks(serializable));
|
3733
|
+
};
|
3734
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3735
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2716
3736
|
}
|
2717
|
-
Object.freeze(
|
2718
|
-
return
|
3737
|
+
Object.freeze(record);
|
3738
|
+
return record;
|
2719
3739
|
};
|
2720
|
-
function isResponseWithRecords(value) {
|
2721
|
-
return isObject(value) && Array.isArray(value.records);
|
2722
|
-
}
|
2723
3740
|
function extractId(value) {
|
2724
3741
|
if (isString(value))
|
2725
3742
|
return value;
|
@@ -2902,19 +3919,19 @@ class SearchPlugin extends XataPlugin {
|
|
2902
3919
|
__privateAdd$1(this, _schemaTables, void 0);
|
2903
3920
|
__privateSet$1(this, _schemaTables, schemaTables);
|
2904
3921
|
}
|
2905
|
-
build(
|
3922
|
+
build(pluginOptions) {
|
2906
3923
|
return {
|
2907
3924
|
all: async (query, options = {}) => {
|
2908
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
2909
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3925
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3926
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
2910
3927
|
return records.map((record) => {
|
2911
3928
|
const { table = "orphan" } = record.xata;
|
2912
3929
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
2913
3930
|
});
|
2914
3931
|
},
|
2915
3932
|
byTable: async (query, options = {}) => {
|
2916
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
2917
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3933
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3934
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
2918
3935
|
return records.reduce((acc, record) => {
|
2919
3936
|
const { table = "orphan" } = record.xata;
|
2920
3937
|
const items = acc[table] ?? [];
|
@@ -2927,113 +3944,40 @@ class SearchPlugin extends XataPlugin {
|
|
2927
3944
|
}
|
2928
3945
|
_schemaTables = new WeakMap();
|
2929
3946
|
_search = new WeakSet();
|
2930
|
-
search_fn = async function(query, options,
|
2931
|
-
const
|
2932
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
3947
|
+
search_fn = async function(query, options, pluginOptions) {
|
3948
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
2933
3949
|
const { records } = await searchBranch({
|
2934
3950
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2935
|
-
|
2936
|
-
|
3951
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3952
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
3953
|
+
...pluginOptions
|
2937
3954
|
});
|
2938
3955
|
return records;
|
2939
3956
|
};
|
2940
3957
|
_getSchemaTables = new WeakSet();
|
2941
|
-
getSchemaTables_fn = async function(
|
3958
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
2942
3959
|
if (__privateGet$1(this, _schemaTables))
|
2943
3960
|
return __privateGet$1(this, _schemaTables);
|
2944
|
-
const fetchProps = await getFetchProps();
|
2945
3961
|
const { schema } = await getBranchDetails({
|
2946
3962
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2947
|
-
...
|
3963
|
+
...pluginOptions
|
2948
3964
|
});
|
2949
3965
|
__privateSet$1(this, _schemaTables, schema.tables);
|
2950
3966
|
return schema.tables;
|
2951
3967
|
};
|
2952
3968
|
|
2953
|
-
|
2954
|
-
|
2955
|
-
|
2956
|
-
|
2957
|
-
|
2958
|
-
|
2959
|
-
|
2960
|
-
|
2961
|
-
|
2962
|
-
|
2963
|
-
|
2964
|
-
|
2965
|
-
const gitBranch = envBranch || await getGitBranch();
|
2966
|
-
return resolveXataBranch(gitBranch, options);
|
2967
|
-
}
|
2968
|
-
async function getCurrentBranchDetails(options) {
|
2969
|
-
const branch = await getCurrentBranchName(options);
|
2970
|
-
return getDatabaseBranch(branch, options);
|
2971
|
-
}
|
2972
|
-
async function resolveXataBranch(gitBranch, options) {
|
2973
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2974
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2975
|
-
if (!databaseURL)
|
2976
|
-
throw new Error(
|
2977
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2978
|
-
);
|
2979
|
-
if (!apiKey)
|
2980
|
-
throw new Error(
|
2981
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2982
|
-
);
|
2983
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
2984
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
2985
|
-
if (!urlParts)
|
2986
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
2987
|
-
const { workspace, region } = urlParts;
|
2988
|
-
const { fallbackBranch } = getEnvironment();
|
2989
|
-
const { branch } = await resolveBranch({
|
2990
|
-
apiKey,
|
2991
|
-
apiUrl: databaseURL,
|
2992
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2993
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
2994
|
-
pathParams: { dbName, workspace, region },
|
2995
|
-
queryParams: { gitBranch, fallbackBranch },
|
2996
|
-
trace: defaultTrace
|
2997
|
-
});
|
2998
|
-
return branch;
|
2999
|
-
}
|
3000
|
-
async function getDatabaseBranch(branch, options) {
|
3001
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3002
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3003
|
-
if (!databaseURL)
|
3004
|
-
throw new Error(
|
3005
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3006
|
-
);
|
3007
|
-
if (!apiKey)
|
3008
|
-
throw new Error(
|
3009
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3010
|
-
);
|
3011
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3012
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3013
|
-
if (!urlParts)
|
3014
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3015
|
-
const { workspace, region } = urlParts;
|
3016
|
-
try {
|
3017
|
-
return await getBranchDetails({
|
3018
|
-
apiKey,
|
3019
|
-
apiUrl: databaseURL,
|
3020
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3021
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3022
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3023
|
-
trace: defaultTrace
|
3024
|
-
});
|
3025
|
-
} catch (err) {
|
3026
|
-
if (isObject(err) && err.status === 404)
|
3027
|
-
return null;
|
3028
|
-
throw err;
|
3029
|
-
}
|
3030
|
-
}
|
3031
|
-
function getDatabaseURL() {
|
3032
|
-
try {
|
3033
|
-
const { databaseURL } = getEnvironment();
|
3034
|
-
return databaseURL;
|
3035
|
-
} catch (err) {
|
3036
|
-
return void 0;
|
3969
|
+
class TransactionPlugin extends XataPlugin {
|
3970
|
+
build(pluginOptions) {
|
3971
|
+
return {
|
3972
|
+
run: async (operations) => {
|
3973
|
+
const response = await branchTransaction({
|
3974
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3975
|
+
body: { operations },
|
3976
|
+
...pluginOptions
|
3977
|
+
});
|
3978
|
+
return response;
|
3979
|
+
}
|
3980
|
+
};
|
3037
3981
|
}
|
3038
3982
|
}
|
3039
3983
|
|
@@ -3060,89 +4004,116 @@ var __privateMethod = (obj, member, method) => {
|
|
3060
4004
|
return method;
|
3061
4005
|
};
|
3062
4006
|
const buildClient = (plugins) => {
|
3063
|
-
var
|
4007
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3064
4008
|
return _a = class {
|
3065
4009
|
constructor(options = {}, schemaTables) {
|
3066
4010
|
__privateAdd(this, _parseOptions);
|
3067
4011
|
__privateAdd(this, _getFetchProps);
|
3068
|
-
__privateAdd(this, _evaluateBranch);
|
3069
|
-
__privateAdd(this, _branch, void 0);
|
3070
4012
|
__privateAdd(this, _options, void 0);
|
3071
4013
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3072
4014
|
__privateSet(this, _options, safeOptions);
|
3073
4015
|
const pluginOptions = {
|
3074
|
-
|
4016
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3075
4017
|
cache: safeOptions.cache,
|
3076
|
-
|
4018
|
+
host: safeOptions.host
|
3077
4019
|
};
|
3078
4020
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3079
4021
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
4022
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
3080
4023
|
this.db = db;
|
3081
4024
|
this.search = search;
|
4025
|
+
this.transactions = transactions;
|
3082
4026
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3083
4027
|
if (namespace === void 0)
|
3084
4028
|
continue;
|
3085
|
-
|
3086
|
-
if (result instanceof Promise) {
|
3087
|
-
void result.then((namespace2) => {
|
3088
|
-
this[key] = namespace2;
|
3089
|
-
});
|
3090
|
-
} else {
|
3091
|
-
this[key] = result;
|
3092
|
-
}
|
4029
|
+
this[key] = namespace.build(pluginOptions);
|
3093
4030
|
}
|
3094
4031
|
}
|
3095
4032
|
async getConfig() {
|
3096
4033
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3097
|
-
const branch =
|
4034
|
+
const branch = __privateGet(this, _options).branch;
|
3098
4035
|
return { databaseURL, branch };
|
3099
4036
|
}
|
3100
|
-
},
|
4037
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
4038
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
4039
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
4040
|
+
if (isBrowser && !enableBrowser) {
|
4041
|
+
throw new Error(
|
4042
|
+
"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."
|
4043
|
+
);
|
4044
|
+
}
|
3101
4045
|
const fetch = getFetchImplementation(options?.fetch);
|
3102
4046
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3103
4047
|
const apiKey = options?.apiKey || getAPIKey();
|
3104
4048
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3105
4049
|
const trace = options?.trace ?? defaultTrace;
|
3106
|
-
const
|
4050
|
+
const clientName = options?.clientName;
|
4051
|
+
const host = options?.host ?? "production";
|
4052
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
3107
4053
|
if (!apiKey) {
|
3108
4054
|
throw new Error("Option apiKey is required");
|
3109
4055
|
}
|
3110
4056
|
if (!databaseURL) {
|
3111
4057
|
throw new Error("Option databaseURL is required");
|
3112
4058
|
}
|
3113
|
-
|
3114
|
-
|
3115
|
-
const
|
3116
|
-
if (
|
3117
|
-
|
4059
|
+
const envBranch = getBranch();
|
4060
|
+
const previewBranch = getPreviewBranch();
|
4061
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4062
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4063
|
+
console.warn(
|
4064
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4065
|
+
);
|
4066
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4067
|
+
console.warn(
|
4068
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4069
|
+
);
|
4070
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4071
|
+
console.warn(
|
4072
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4073
|
+
);
|
4074
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4075
|
+
console.warn(
|
4076
|
+
`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.`
|
4077
|
+
);
|
4078
|
+
}
|
4079
|
+
return {
|
4080
|
+
fetch,
|
4081
|
+
databaseURL,
|
4082
|
+
apiKey,
|
4083
|
+
branch,
|
4084
|
+
cache,
|
4085
|
+
trace,
|
4086
|
+
host,
|
4087
|
+
clientID: generateUUID(),
|
4088
|
+
enableBrowser,
|
4089
|
+
clientName,
|
4090
|
+
xataAgentExtra
|
4091
|
+
};
|
4092
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
4093
|
+
fetch,
|
4094
|
+
apiKey,
|
4095
|
+
databaseURL,
|
4096
|
+
branch,
|
4097
|
+
trace,
|
4098
|
+
clientID,
|
4099
|
+
clientName,
|
4100
|
+
xataAgentExtra
|
4101
|
+
}) {
|
3118
4102
|
return {
|
3119
|
-
|
4103
|
+
fetch,
|
3120
4104
|
apiKey,
|
3121
4105
|
apiUrl: "",
|
4106
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3122
4107
|
workspacesApiUrl: (path, params) => {
|
3123
4108
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3124
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4109
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3125
4110
|
return databaseURL + newPath;
|
3126
4111
|
},
|
3127
4112
|
trace,
|
3128
|
-
clientID
|
3129
|
-
|
3130
|
-
|
3131
|
-
if (__privateGet(this, _branch))
|
3132
|
-
return __privateGet(this, _branch);
|
3133
|
-
if (param === void 0)
|
3134
|
-
return void 0;
|
3135
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3136
|
-
const evaluateBranch = async (strategy) => {
|
3137
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
4113
|
+
clientID,
|
4114
|
+
clientName,
|
4115
|
+
xataAgentExtra
|
3138
4116
|
};
|
3139
|
-
for await (const strategy of strategies) {
|
3140
|
-
const branch = await evaluateBranch(strategy);
|
3141
|
-
if (branch) {
|
3142
|
-
__privateSet(this, _branch, branch);
|
3143
|
-
return branch;
|
3144
|
-
}
|
3145
|
-
}
|
3146
4117
|
}, _a;
|
3147
4118
|
};
|
3148
4119
|
class BaseClient extends buildClient() {
|
@@ -3216,7 +4187,7 @@ const deserialize = (json) => {
|
|
3216
4187
|
};
|
3217
4188
|
|
3218
4189
|
function buildWorkerRunner(config) {
|
3219
|
-
return function xataWorker(name,
|
4190
|
+
return function xataWorker(name, worker) {
|
3220
4191
|
return async (...args) => {
|
3221
4192
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3222
4193
|
const result = await fetch(url, {
|
@@ -3238,6 +4209,7 @@ class XataError extends Error {
|
|
3238
4209
|
}
|
3239
4210
|
|
3240
4211
|
exports.BaseClient = BaseClient;
|
4212
|
+
exports.FetcherError = FetcherError;
|
3241
4213
|
exports.Operations = operationsByTag;
|
3242
4214
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
3243
4215
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -3261,7 +4233,11 @@ exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
3261
4233
|
exports.addTableColumn = addTableColumn;
|
3262
4234
|
exports.aggregateTable = aggregateTable;
|
3263
4235
|
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4236
|
+
exports.askTable = askTable;
|
4237
|
+
exports.branchTransaction = branchTransaction;
|
3264
4238
|
exports.buildClient = buildClient;
|
4239
|
+
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4240
|
+
exports.buildProviderString = buildProviderString;
|
3265
4241
|
exports.buildWorkerRunner = buildWorkerRunner;
|
3266
4242
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
3267
4243
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
@@ -3269,20 +4245,19 @@ exports.compareBranchSchemas = compareBranchSchemas;
|
|
3269
4245
|
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3270
4246
|
exports.compareMigrationRequest = compareMigrationRequest;
|
3271
4247
|
exports.contains = contains;
|
4248
|
+
exports.copyBranch = copyBranch;
|
3272
4249
|
exports.createBranch = createBranch;
|
3273
4250
|
exports.createDatabase = createDatabase;
|
3274
4251
|
exports.createMigrationRequest = createMigrationRequest;
|
3275
4252
|
exports.createTable = createTable;
|
3276
4253
|
exports.createUserAPIKey = createUserAPIKey;
|
3277
4254
|
exports.createWorkspace = createWorkspace;
|
3278
|
-
exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
|
3279
|
-
exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
|
3280
|
-
exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
|
3281
|
-
exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
|
3282
|
-
exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
|
3283
4255
|
exports.deleteBranch = deleteBranch;
|
3284
4256
|
exports.deleteColumn = deleteColumn;
|
3285
4257
|
exports.deleteDatabase = deleteDatabase;
|
4258
|
+
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
4259
|
+
exports.deleteFile = deleteFile;
|
4260
|
+
exports.deleteFileItem = deleteFileItem;
|
3286
4261
|
exports.deleteRecord = deleteRecord;
|
3287
4262
|
exports.deleteTable = deleteTable;
|
3288
4263
|
exports.deleteUser = deleteUser;
|
@@ -3293,8 +4268,10 @@ exports.endsWith = endsWith;
|
|
3293
4268
|
exports.equals = equals;
|
3294
4269
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
3295
4270
|
exports.exists = exists;
|
4271
|
+
exports.fileAccess = fileAccess;
|
3296
4272
|
exports.ge = ge;
|
3297
4273
|
exports.getAPIKey = getAPIKey;
|
4274
|
+
exports.getBranch = getBranch;
|
3298
4275
|
exports.getBranchDetails = getBranchDetails;
|
3299
4276
|
exports.getBranchList = getBranchList;
|
3300
4277
|
exports.getBranchMetadata = getBranchMetadata;
|
@@ -3303,15 +4280,17 @@ exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
|
3303
4280
|
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
3304
4281
|
exports.getBranchStats = getBranchStats;
|
3305
4282
|
exports.getColumn = getColumn;
|
3306
|
-
exports.
|
3307
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
4283
|
+
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
3308
4284
|
exports.getDatabaseList = getDatabaseList;
|
3309
4285
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
3310
4286
|
exports.getDatabaseURL = getDatabaseURL;
|
4287
|
+
exports.getFile = getFile;
|
4288
|
+
exports.getFileItem = getFileItem;
|
3311
4289
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3312
4290
|
exports.getHostUrl = getHostUrl;
|
3313
4291
|
exports.getMigrationRequest = getMigrationRequest;
|
3314
4292
|
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4293
|
+
exports.getPreviewBranch = getPreviewBranch;
|
3315
4294
|
exports.getRecord = getRecord;
|
3316
4295
|
exports.getTableColumns = getTableColumns;
|
3317
4296
|
exports.getTableSchema = getTableSchema;
|
@@ -3354,21 +4333,27 @@ exports.parseProviderString = parseProviderString;
|
|
3354
4333
|
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
3355
4334
|
exports.pattern = pattern;
|
3356
4335
|
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4336
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
4337
|
+
exports.putFile = putFile;
|
4338
|
+
exports.putFileItem = putFileItem;
|
3357
4339
|
exports.queryMigrationRequests = queryMigrationRequests;
|
3358
4340
|
exports.queryTable = queryTable;
|
3359
4341
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
3360
4342
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
4343
|
+
exports.renameDatabase = renameDatabase;
|
3361
4344
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
3362
4345
|
exports.resolveBranch = resolveBranch;
|
3363
4346
|
exports.searchBranch = searchBranch;
|
3364
4347
|
exports.searchTable = searchTable;
|
3365
4348
|
exports.serialize = serialize;
|
3366
4349
|
exports.setTableSchema = setTableSchema;
|
4350
|
+
exports.sqlQuery = sqlQuery;
|
3367
4351
|
exports.startsWith = startsWith;
|
3368
4352
|
exports.summarizeTable = summarizeTable;
|
3369
4353
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3370
4354
|
exports.updateBranchSchema = updateBranchSchema;
|
3371
4355
|
exports.updateColumn = updateColumn;
|
4356
|
+
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3372
4357
|
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3373
4358
|
exports.updateMigrationRequest = updateMigrationRequest;
|
3374
4359
|
exports.updateRecordWithID = updateRecordWithID;
|
@@ -3378,4 +4363,5 @@ exports.updateWorkspace = updateWorkspace;
|
|
3378
4363
|
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
3379
4364
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
3380
4365
|
exports.upsertRecordWithID = upsertRecordWithID;
|
4366
|
+
exports.vectorSearchTable = vectorSearchTable;
|
3381
4367
|
//# sourceMappingURL=index.cjs.map
|