@xata.io/client 0.0.0-alpha.vfe4a947 → 0.0.0-alpha.vfe896b3
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/.eslintrc.cjs +3 -2
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +298 -0
- package/README.md +3 -269
- package/dist/index.cjs +2389 -790
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5615 -1526
- package/dist/index.mjs +2353 -769
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -9
- package/rollup.config.mjs +44 -0
- package/Usage.md +0 -449
- package/rollup.config.js +0 -29
package/dist/index.cjs
CHANGED
@@ -1,36 +1,15 @@
|
|
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
|
-
},
|
28
|
-
onError: () => {
|
29
|
-
return;
|
30
8
|
}
|
31
9
|
});
|
32
10
|
};
|
33
11
|
const TraceAttributes = {
|
12
|
+
KIND: "xata.trace.kind",
|
34
13
|
VERSION: "xata.sdk.version",
|
35
14
|
TABLE: "xata.table",
|
36
15
|
HTTP_REQUEST_ID: "http.request_id",
|
@@ -62,6 +41,21 @@ function isString(value) {
|
|
62
41
|
function isStringArray(value) {
|
63
42
|
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
64
43
|
}
|
44
|
+
function isNumber(value) {
|
45
|
+
return isDefined(value) && typeof value === "number";
|
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
|
+
}
|
65
59
|
function toBase64(value) {
|
66
60
|
try {
|
67
61
|
return btoa(value);
|
@@ -70,16 +64,39 @@ function toBase64(value) {
|
|
70
64
|
return buf.from(value).toString("base64");
|
71
65
|
}
|
72
66
|
}
|
67
|
+
function deepMerge(a, b) {
|
68
|
+
const result = { ...a };
|
69
|
+
for (const [key, value] of Object.entries(b)) {
|
70
|
+
if (isObject(value) && isObject(result[key])) {
|
71
|
+
result[key] = deepMerge(result[key], value);
|
72
|
+
} else {
|
73
|
+
result[key] = value;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
return result;
|
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
|
+
}
|
73
88
|
|
74
89
|
function getEnvironment() {
|
75
90
|
try {
|
76
|
-
if (
|
91
|
+
if (isDefined(process) && isDefined(process.env)) {
|
77
92
|
return {
|
78
93
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
79
94
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
80
95
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
81
|
-
|
82
|
-
|
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
|
83
100
|
};
|
84
101
|
}
|
85
102
|
} catch (err) {
|
@@ -90,8 +107,10 @@ function getEnvironment() {
|
|
90
107
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
91
108
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
92
109
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
93
|
-
|
94
|
-
|
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")
|
95
114
|
};
|
96
115
|
}
|
97
116
|
} catch (err) {
|
@@ -100,10 +119,31 @@ function getEnvironment() {
|
|
100
119
|
apiKey: getGlobalApiKey(),
|
101
120
|
databaseURL: getGlobalDatabaseURL(),
|
102
121
|
branch: getGlobalBranch(),
|
103
|
-
|
104
|
-
|
122
|
+
deployPreview: void 0,
|
123
|
+
deployPreviewBranch: void 0,
|
124
|
+
vercelGitCommitRef: void 0,
|
125
|
+
vercelGitRepoOwner: void 0
|
105
126
|
};
|
106
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
|
+
}
|
107
147
|
function getGlobalApiKey() {
|
108
148
|
try {
|
109
149
|
return XATA_API_KEY;
|
@@ -125,56 +165,334 @@ function getGlobalBranch() {
|
|
125
165
|
return void 0;
|
126
166
|
}
|
127
167
|
}
|
128
|
-
function
|
168
|
+
function getDatabaseURL() {
|
129
169
|
try {
|
130
|
-
|
170
|
+
const { databaseURL } = getEnvironment();
|
171
|
+
return databaseURL;
|
131
172
|
} catch (err) {
|
132
173
|
return void 0;
|
133
174
|
}
|
134
175
|
}
|
135
|
-
|
136
|
-
const cmd = ["git", "branch", "--show-current"];
|
137
|
-
const fullCmd = cmd.join(" ");
|
138
|
-
const nodeModule = ["child", "process"].join("_");
|
139
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
176
|
+
function getAPIKey() {
|
140
177
|
try {
|
141
|
-
|
142
|
-
|
143
|
-
}
|
144
|
-
const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
|
145
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
178
|
+
const { apiKey } = getEnvironment();
|
179
|
+
return apiKey;
|
146
180
|
} catch (err) {
|
181
|
+
return void 0;
|
147
182
|
}
|
183
|
+
}
|
184
|
+
function getBranch() {
|
148
185
|
try {
|
149
|
-
|
150
|
-
|
151
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
152
|
-
}
|
186
|
+
const { branch } = getEnvironment();
|
187
|
+
return branch ?? "main";
|
153
188
|
} catch (err) {
|
189
|
+
return void 0;
|
154
190
|
}
|
155
191
|
}
|
156
|
-
|
157
|
-
|
192
|
+
function buildPreviewBranchName({ org, branch }) {
|
193
|
+
return `preview-${org}-${branch}`;
|
194
|
+
}
|
195
|
+
function getPreviewBranch() {
|
158
196
|
try {
|
159
|
-
const {
|
160
|
-
|
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;
|
161
210
|
} catch (err) {
|
162
211
|
return void 0;
|
163
212
|
}
|
164
213
|
}
|
165
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;
|
166
238
|
function getFetchImplementation(userFetch) {
|
167
239
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
168
240
|
const fetchImpl = userFetch ?? globalFetch;
|
169
241
|
if (!fetchImpl) {
|
170
242
|
throw new Error(
|
171
|
-
`
|
243
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
172
244
|
);
|
173
245
|
}
|
174
246
|
return fetchImpl;
|
175
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 = 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 = 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
|
+
};
|
176
314
|
|
177
|
-
|
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.23.3";
|
178
496
|
|
179
497
|
class ErrorWithCause extends Error {
|
180
498
|
constructor(message, options) {
|
@@ -185,7 +503,7 @@ class FetcherError extends ErrorWithCause {
|
|
185
503
|
constructor(status, data, requestId) {
|
186
504
|
super(getMessage(data));
|
187
505
|
this.status = status;
|
188
|
-
this.errors = isBulkError(data) ? data.errors :
|
506
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
189
507
|
this.requestId = requestId;
|
190
508
|
if (data instanceof Error) {
|
191
509
|
this.stack = data.stack;
|
@@ -217,6 +535,7 @@ function getMessage(data) {
|
|
217
535
|
}
|
218
536
|
}
|
219
537
|
|
538
|
+
const pool = new ApiRequestPool();
|
220
539
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
221
540
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
222
541
|
if (value === void 0 || value === null)
|
@@ -225,69 +544,100 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
225
544
|
}, {});
|
226
545
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
227
546
|
const queryString = query.length > 0 ? `?${query}` : "";
|
228
|
-
|
547
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
548
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
549
|
+
}, {});
|
550
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
229
551
|
};
|
230
552
|
function buildBaseUrl({
|
553
|
+
endpoint,
|
231
554
|
path,
|
232
555
|
workspacesApiUrl,
|
233
556
|
apiUrl,
|
234
|
-
pathParams
|
557
|
+
pathParams = {}
|
235
558
|
}) {
|
236
|
-
if (
|
237
|
-
|
238
|
-
|
239
|
-
|
559
|
+
if (endpoint === "dataPlane") {
|
560
|
+
const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
561
|
+
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
562
|
+
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
563
|
+
}
|
564
|
+
return `${apiUrl}${path}`;
|
240
565
|
}
|
241
566
|
function hostHeader(url) {
|
242
567
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
243
568
|
const { groups } = pattern.exec(url) ?? {};
|
244
569
|
return groups?.host ? { Host: groups.host } : {};
|
245
570
|
}
|
571
|
+
const defaultClientID = generateUUID();
|
246
572
|
async function fetch$1({
|
247
573
|
url: path,
|
248
574
|
method,
|
249
575
|
body,
|
250
|
-
headers,
|
576
|
+
headers: customHeaders,
|
251
577
|
pathParams,
|
252
578
|
queryParams,
|
253
|
-
|
579
|
+
fetch: fetch2,
|
254
580
|
apiKey,
|
581
|
+
endpoint,
|
255
582
|
apiUrl,
|
256
583
|
workspacesApiUrl,
|
257
|
-
trace
|
584
|
+
trace,
|
585
|
+
signal,
|
586
|
+
clientID,
|
587
|
+
sessionID,
|
588
|
+
clientName,
|
589
|
+
xataAgentExtra,
|
590
|
+
fetchOptions = {}
|
258
591
|
}) {
|
259
|
-
|
592
|
+
pool.setFetch(fetch2);
|
593
|
+
return await trace(
|
260
594
|
`${method.toUpperCase()} ${path}`,
|
261
|
-
async ({ setAttributes
|
262
|
-
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
595
|
+
async ({ setAttributes }) => {
|
596
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
263
597
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
264
598
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
265
599
|
setAttributes({
|
266
600
|
[TraceAttributes.HTTP_URL]: url,
|
267
601
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
268
602
|
});
|
269
|
-
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,
|
270
621
|
method: method.toUpperCase(),
|
271
622
|
body: body ? JSON.stringify(body) : void 0,
|
272
|
-
headers
|
273
|
-
|
274
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
275
|
-
...headers,
|
276
|
-
...hostHeader(fullUrl),
|
277
|
-
Authorization: `Bearer ${apiKey}`
|
278
|
-
}
|
623
|
+
headers,
|
624
|
+
signal
|
279
625
|
});
|
280
|
-
if (response.status === 204) {
|
281
|
-
return {};
|
282
|
-
}
|
283
626
|
const { host, protocol } = parseUrl(response.url);
|
284
627
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
285
628
|
setAttributes({
|
629
|
+
[TraceAttributes.KIND]: "http",
|
286
630
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
287
631
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
288
632
|
[TraceAttributes.HTTP_HOST]: host,
|
289
633
|
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
290
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
|
+
}
|
291
641
|
try {
|
292
642
|
const jsonResponse = await response.json();
|
293
643
|
if (response.ok) {
|
@@ -295,14 +645,65 @@ async function fetch$1({
|
|
295
645
|
}
|
296
646
|
throw new FetcherError(response.status, jsonResponse, requestId);
|
297
647
|
} catch (error) {
|
298
|
-
|
299
|
-
onError(fetcherError.message);
|
300
|
-
throw fetcherError;
|
648
|
+
throw new FetcherError(response.status, error, requestId);
|
301
649
|
}
|
302
650
|
},
|
303
651
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
304
652
|
);
|
305
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
|
+
}
|
306
707
|
function parseUrl(url) {
|
307
708
|
try {
|
308
709
|
const { host, protocol } = new URL(url);
|
@@ -312,257 +713,207 @@ function parseUrl(url) {
|
|
312
713
|
}
|
313
714
|
}
|
314
715
|
|
315
|
-
const
|
316
|
-
|
317
|
-
const
|
318
|
-
const getUserAPIKeys = (variables) => fetch$1({
|
319
|
-
url: "/user/keys",
|
320
|
-
method: "get",
|
321
|
-
...variables
|
322
|
-
});
|
323
|
-
const createUserAPIKey = (variables) => fetch$1({
|
324
|
-
url: "/user/keys/{keyName}",
|
325
|
-
method: "post",
|
326
|
-
...variables
|
327
|
-
});
|
328
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
329
|
-
url: "/user/keys/{keyName}",
|
330
|
-
method: "delete",
|
331
|
-
...variables
|
332
|
-
});
|
333
|
-
const createWorkspace = (variables) => fetch$1({
|
334
|
-
url: "/workspaces",
|
335
|
-
method: "post",
|
336
|
-
...variables
|
337
|
-
});
|
338
|
-
const getWorkspacesList = (variables) => fetch$1({
|
339
|
-
url: "/workspaces",
|
340
|
-
method: "get",
|
341
|
-
...variables
|
342
|
-
});
|
343
|
-
const getWorkspace = (variables) => fetch$1({
|
344
|
-
url: "/workspaces/{workspaceId}",
|
345
|
-
method: "get",
|
346
|
-
...variables
|
347
|
-
});
|
348
|
-
const updateWorkspace = (variables) => fetch$1({
|
349
|
-
url: "/workspaces/{workspaceId}",
|
350
|
-
method: "put",
|
351
|
-
...variables
|
352
|
-
});
|
353
|
-
const deleteWorkspace = (variables) => fetch$1({
|
354
|
-
url: "/workspaces/{workspaceId}",
|
355
|
-
method: "delete",
|
356
|
-
...variables
|
357
|
-
});
|
358
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
359
|
-
url: "/workspaces/{workspaceId}/members",
|
360
|
-
method: "get",
|
361
|
-
...variables
|
362
|
-
});
|
363
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
364
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
365
|
-
url: "/workspaces/{workspaceId}/members/{userId}",
|
366
|
-
method: "delete",
|
367
|
-
...variables
|
368
|
-
});
|
369
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
370
|
-
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
371
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
372
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
373
|
-
method: "delete",
|
374
|
-
...variables
|
375
|
-
});
|
376
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
377
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
378
|
-
method: "post",
|
379
|
-
...variables
|
380
|
-
});
|
381
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
382
|
-
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
383
|
-
method: "post",
|
384
|
-
...variables
|
385
|
-
});
|
386
|
-
const getDatabaseList = (variables) => fetch$1({
|
387
|
-
url: "/dbs",
|
388
|
-
method: "get",
|
389
|
-
...variables
|
390
|
-
});
|
391
|
-
const getBranchList = (variables) => fetch$1({
|
392
|
-
url: "/dbs/{dbName}",
|
393
|
-
method: "get",
|
394
|
-
...variables
|
395
|
-
});
|
396
|
-
const createDatabase = (variables) => fetch$1({
|
397
|
-
url: "/dbs/{dbName}",
|
398
|
-
method: "put",
|
399
|
-
...variables
|
400
|
-
});
|
401
|
-
const deleteDatabase = (variables) => fetch$1({
|
716
|
+
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
717
|
+
|
718
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
402
719
|
url: "/dbs/{dbName}",
|
403
|
-
method: "delete",
|
404
|
-
...variables
|
405
|
-
});
|
406
|
-
const getDatabaseMetadata = (variables) => fetch$1({
|
407
|
-
url: "/dbs/{dbName}/metadata",
|
408
|
-
method: "get",
|
409
|
-
...variables
|
410
|
-
});
|
411
|
-
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
412
|
-
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
413
|
-
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
414
|
-
const resolveBranch = (variables) => fetch$1({
|
415
|
-
url: "/dbs/{dbName}/resolveBranch",
|
416
720
|
method: "get",
|
417
|
-
...variables
|
721
|
+
...variables,
|
722
|
+
signal
|
418
723
|
});
|
419
|
-
const getBranchDetails = (variables) =>
|
724
|
+
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
420
725
|
url: "/db/{dbBranchName}",
|
421
726
|
method: "get",
|
422
|
-
...variables
|
727
|
+
...variables,
|
728
|
+
signal
|
423
729
|
});
|
424
|
-
const createBranch = (variables) =>
|
425
|
-
const deleteBranch = (variables) =>
|
730
|
+
const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
731
|
+
const deleteBranch = (variables, signal) => dataPlaneFetch({
|
426
732
|
url: "/db/{dbBranchName}",
|
427
733
|
method: "delete",
|
428
|
-
...variables
|
734
|
+
...variables,
|
735
|
+
signal
|
736
|
+
});
|
737
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
738
|
+
url: "/db/{dbBranchName}/copy",
|
739
|
+
method: "post",
|
740
|
+
...variables,
|
741
|
+
signal
|
429
742
|
});
|
430
|
-
const updateBranchMetadata = (variables) =>
|
743
|
+
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
431
744
|
url: "/db/{dbBranchName}/metadata",
|
432
745
|
method: "put",
|
433
|
-
...variables
|
746
|
+
...variables,
|
747
|
+
signal
|
434
748
|
});
|
435
|
-
const getBranchMetadata = (variables) =>
|
749
|
+
const getBranchMetadata = (variables, signal) => dataPlaneFetch({
|
436
750
|
url: "/db/{dbBranchName}/metadata",
|
437
751
|
method: "get",
|
438
|
-
...variables
|
752
|
+
...variables,
|
753
|
+
signal
|
439
754
|
});
|
440
|
-
const
|
441
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
442
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
443
|
-
const getBranchStats = (variables) => fetch$1({
|
755
|
+
const getBranchStats = (variables, signal) => dataPlaneFetch({
|
444
756
|
url: "/db/{dbBranchName}/stats",
|
445
757
|
method: "get",
|
446
|
-
...variables
|
758
|
+
...variables,
|
759
|
+
signal
|
760
|
+
});
|
761
|
+
const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
762
|
+
const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
763
|
+
const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
764
|
+
const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
|
765
|
+
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
766
|
+
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
767
|
+
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
768
|
+
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
769
|
+
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
770
|
+
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
771
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
772
|
+
method: "get",
|
773
|
+
...variables,
|
774
|
+
signal
|
775
|
+
});
|
776
|
+
const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
777
|
+
const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
778
|
+
const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
779
|
+
const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
780
|
+
const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
|
781
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
782
|
+
method: "post",
|
783
|
+
...variables,
|
784
|
+
signal
|
447
785
|
});
|
448
|
-
const
|
786
|
+
const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
787
|
+
const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
788
|
+
const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
789
|
+
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
790
|
+
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
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 });
|
793
|
+
const createTable = (variables, signal) => dataPlaneFetch({
|
449
794
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
450
795
|
method: "put",
|
451
|
-
...variables
|
796
|
+
...variables,
|
797
|
+
signal
|
452
798
|
});
|
453
|
-
const deleteTable = (variables) =>
|
799
|
+
const deleteTable = (variables, signal) => dataPlaneFetch({
|
454
800
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
455
801
|
method: "delete",
|
456
|
-
...variables
|
802
|
+
...variables,
|
803
|
+
signal
|
457
804
|
});
|
458
|
-
const updateTable = (variables) =>
|
459
|
-
|
460
|
-
method: "patch",
|
461
|
-
...variables
|
462
|
-
});
|
463
|
-
const getTableSchema = (variables) => fetch$1({
|
805
|
+
const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
|
806
|
+
const getTableSchema = (variables, signal) => dataPlaneFetch({
|
464
807
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
465
808
|
method: "get",
|
466
|
-
...variables
|
467
|
-
|
468
|
-
const setTableSchema = (variables) => fetch$1({
|
469
|
-
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
470
|
-
method: "put",
|
471
|
-
...variables
|
809
|
+
...variables,
|
810
|
+
signal
|
472
811
|
});
|
473
|
-
const
|
812
|
+
const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
|
813
|
+
const getTableColumns = (variables, signal) => dataPlaneFetch({
|
474
814
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
475
815
|
method: "get",
|
476
|
-
...variables
|
477
|
-
|
478
|
-
const addTableColumn = (variables) => fetch$1({
|
479
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
480
|
-
method: "post",
|
481
|
-
...variables
|
816
|
+
...variables,
|
817
|
+
signal
|
482
818
|
});
|
483
|
-
const
|
819
|
+
const addTableColumn = (variables, signal) => dataPlaneFetch(
|
820
|
+
{ url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
|
821
|
+
);
|
822
|
+
const getColumn = (variables, signal) => dataPlaneFetch({
|
484
823
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
485
824
|
method: "get",
|
486
|
-
...variables
|
825
|
+
...variables,
|
826
|
+
signal
|
487
827
|
});
|
488
|
-
const
|
828
|
+
const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
|
829
|
+
const deleteColumn = (variables, signal) => dataPlaneFetch({
|
489
830
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
490
831
|
method: "delete",
|
491
|
-
...variables
|
832
|
+
...variables,
|
833
|
+
signal
|
492
834
|
});
|
493
|
-
const
|
494
|
-
|
495
|
-
|
496
|
-
...variables
|
497
|
-
});
|
498
|
-
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
499
|
-
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
500
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
501
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
502
|
-
const deleteRecord = (variables) => fetch$1({
|
503
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
504
|
-
method: "delete",
|
505
|
-
...variables
|
506
|
-
});
|
507
|
-
const getRecord = (variables) => fetch$1({
|
835
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
836
|
+
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
837
|
+
const getRecord = (variables, signal) => dataPlaneFetch({
|
508
838
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
509
839
|
method: "get",
|
510
|
-
...variables
|
840
|
+
...variables,
|
841
|
+
signal
|
511
842
|
});
|
512
|
-
const
|
513
|
-
const
|
843
|
+
const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
844
|
+
const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
845
|
+
const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
846
|
+
const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
|
847
|
+
const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
848
|
+
const queryTable = (variables, signal) => dataPlaneFetch({
|
514
849
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
515
850
|
method: "post",
|
516
|
-
...variables
|
851
|
+
...variables,
|
852
|
+
signal
|
853
|
+
});
|
854
|
+
const searchBranch = (variables, signal) => dataPlaneFetch({
|
855
|
+
url: "/db/{dbBranchName}/search",
|
856
|
+
method: "post",
|
857
|
+
...variables,
|
858
|
+
signal
|
517
859
|
});
|
518
|
-
const searchTable = (variables) =>
|
860
|
+
const searchTable = (variables, signal) => dataPlaneFetch({
|
519
861
|
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
520
862
|
method: "post",
|
521
|
-
...variables
|
863
|
+
...variables,
|
864
|
+
signal
|
522
865
|
});
|
523
|
-
const
|
524
|
-
url: "/db/{dbBranchName}/
|
866
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
867
|
+
url: "/db/{dbBranchName}/sql",
|
525
868
|
method: "post",
|
526
|
-
...variables
|
869
|
+
...variables,
|
870
|
+
signal
|
527
871
|
});
|
528
|
-
const
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
removeWorkspaceMember,
|
539
|
-
inviteWorkspaceMember,
|
540
|
-
updateWorkspaceMemberInvite,
|
541
|
-
cancelWorkspaceMemberInvite,
|
542
|
-
resendWorkspaceMemberInvite,
|
543
|
-
acceptWorkspaceMemberInvite
|
544
|
-
},
|
545
|
-
database: {
|
546
|
-
getDatabaseList,
|
547
|
-
createDatabase,
|
548
|
-
deleteDatabase,
|
549
|
-
getDatabaseMetadata,
|
550
|
-
getGitBranchesMapping,
|
551
|
-
addGitBranchesEntry,
|
552
|
-
removeGitBranchesEntry,
|
553
|
-
resolveBranch
|
554
|
-
},
|
872
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
873
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
874
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
875
|
+
method: "post",
|
876
|
+
...variables,
|
877
|
+
signal
|
878
|
+
});
|
879
|
+
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
880
|
+
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
881
|
+
const operationsByTag$2 = {
|
555
882
|
branch: {
|
556
883
|
getBranchList,
|
557
884
|
getBranchDetails,
|
558
885
|
createBranch,
|
559
886
|
deleteBranch,
|
887
|
+
copyBranch,
|
560
888
|
updateBranchMetadata,
|
561
889
|
getBranchMetadata,
|
890
|
+
getBranchStats,
|
891
|
+
getGitBranchesMapping,
|
892
|
+
addGitBranchesEntry,
|
893
|
+
removeGitBranchesEntry,
|
894
|
+
resolveBranch
|
895
|
+
},
|
896
|
+
migrations: {
|
562
897
|
getBranchMigrationHistory,
|
563
|
-
executeBranchMigrationPlan,
|
564
898
|
getBranchMigrationPlan,
|
565
|
-
|
899
|
+
executeBranchMigrationPlan,
|
900
|
+
getBranchSchemaHistory,
|
901
|
+
compareBranchWithUserSchema,
|
902
|
+
compareBranchSchemas,
|
903
|
+
updateBranchSchema,
|
904
|
+
previewBranchSchemaEdit,
|
905
|
+
applyBranchSchemaEdit,
|
906
|
+
pushBranchMigrations
|
907
|
+
},
|
908
|
+
migrationRequests: {
|
909
|
+
queryMigrationRequests,
|
910
|
+
createMigrationRequest,
|
911
|
+
getMigrationRequest,
|
912
|
+
updateMigrationRequest,
|
913
|
+
listMigrationRequestsCommits,
|
914
|
+
compareMigrationRequest,
|
915
|
+
getMigrationRequestIsMerged,
|
916
|
+
mergeMigrationRequest
|
566
917
|
},
|
567
918
|
table: {
|
568
919
|
createTable,
|
@@ -573,27 +924,175 @@ const operationsByTag = {
|
|
573
924
|
getTableColumns,
|
574
925
|
addTableColumn,
|
575
926
|
getColumn,
|
576
|
-
|
577
|
-
|
927
|
+
updateColumn,
|
928
|
+
deleteColumn
|
578
929
|
},
|
579
930
|
records: {
|
931
|
+
branchTransaction,
|
580
932
|
insertRecord,
|
933
|
+
getRecord,
|
581
934
|
insertRecordWithID,
|
582
935
|
updateRecordWithID,
|
583
936
|
upsertRecordWithID,
|
584
937
|
deleteRecord,
|
585
|
-
|
586
|
-
|
938
|
+
bulkInsertTableRecords
|
939
|
+
},
|
940
|
+
searchAndFilter: {
|
587
941
|
queryTable,
|
942
|
+
searchBranch,
|
588
943
|
searchTable,
|
589
|
-
|
944
|
+
sqlQuery,
|
945
|
+
vectorSearchTable,
|
946
|
+
askTable,
|
947
|
+
summarizeTable,
|
948
|
+
aggregateTable
|
949
|
+
}
|
950
|
+
};
|
951
|
+
|
952
|
+
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
953
|
+
|
954
|
+
const getUser = (variables, signal) => controlPlaneFetch({
|
955
|
+
url: "/user",
|
956
|
+
method: "get",
|
957
|
+
...variables,
|
958
|
+
signal
|
959
|
+
});
|
960
|
+
const updateUser = (variables, signal) => controlPlaneFetch({
|
961
|
+
url: "/user",
|
962
|
+
method: "put",
|
963
|
+
...variables,
|
964
|
+
signal
|
965
|
+
});
|
966
|
+
const deleteUser = (variables, signal) => controlPlaneFetch({
|
967
|
+
url: "/user",
|
968
|
+
method: "delete",
|
969
|
+
...variables,
|
970
|
+
signal
|
971
|
+
});
|
972
|
+
const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
973
|
+
url: "/user/keys",
|
974
|
+
method: "get",
|
975
|
+
...variables,
|
976
|
+
signal
|
977
|
+
});
|
978
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
979
|
+
url: "/user/keys/{keyName}",
|
980
|
+
method: "post",
|
981
|
+
...variables,
|
982
|
+
signal
|
983
|
+
});
|
984
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
985
|
+
url: "/user/keys/{keyName}",
|
986
|
+
method: "delete",
|
987
|
+
...variables,
|
988
|
+
signal
|
989
|
+
});
|
990
|
+
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
991
|
+
url: "/workspaces",
|
992
|
+
method: "get",
|
993
|
+
...variables,
|
994
|
+
signal
|
995
|
+
});
|
996
|
+
const createWorkspace = (variables, signal) => controlPlaneFetch({
|
997
|
+
url: "/workspaces",
|
998
|
+
method: "post",
|
999
|
+
...variables,
|
1000
|
+
signal
|
1001
|
+
});
|
1002
|
+
const getWorkspace = (variables, signal) => controlPlaneFetch({
|
1003
|
+
url: "/workspaces/{workspaceId}",
|
1004
|
+
method: "get",
|
1005
|
+
...variables,
|
1006
|
+
signal
|
1007
|
+
});
|
1008
|
+
const updateWorkspace = (variables, signal) => controlPlaneFetch({
|
1009
|
+
url: "/workspaces/{workspaceId}",
|
1010
|
+
method: "put",
|
1011
|
+
...variables,
|
1012
|
+
signal
|
1013
|
+
});
|
1014
|
+
const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
1015
|
+
url: "/workspaces/{workspaceId}",
|
1016
|
+
method: "delete",
|
1017
|
+
...variables,
|
1018
|
+
signal
|
1019
|
+
});
|
1020
|
+
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
1021
|
+
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
1022
|
+
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
1023
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
1024
|
+
method: "delete",
|
1025
|
+
...variables,
|
1026
|
+
signal
|
1027
|
+
});
|
1028
|
+
const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
1029
|
+
const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
1030
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1031
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1032
|
+
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1033
|
+
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
1034
|
+
url: "/workspaces/{workspaceId}/dbs",
|
1035
|
+
method: "get",
|
1036
|
+
...variables,
|
1037
|
+
signal
|
1038
|
+
});
|
1039
|
+
const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
1040
|
+
const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
1041
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
1042
|
+
method: "delete",
|
1043
|
+
...variables,
|
1044
|
+
signal
|
1045
|
+
});
|
1046
|
+
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
1047
|
+
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1048
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1049
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1050
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
1051
|
+
const listRegions = (variables, signal) => controlPlaneFetch({
|
1052
|
+
url: "/workspaces/{workspaceId}/regions",
|
1053
|
+
method: "get",
|
1054
|
+
...variables,
|
1055
|
+
signal
|
1056
|
+
});
|
1057
|
+
const operationsByTag$1 = {
|
1058
|
+
users: { getUser, updateUser, deleteUser },
|
1059
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1060
|
+
workspaces: {
|
1061
|
+
getWorkspacesList,
|
1062
|
+
createWorkspace,
|
1063
|
+
getWorkspace,
|
1064
|
+
updateWorkspace,
|
1065
|
+
deleteWorkspace,
|
1066
|
+
getWorkspaceMembersList,
|
1067
|
+
updateWorkspaceMemberRole,
|
1068
|
+
removeWorkspaceMember
|
1069
|
+
},
|
1070
|
+
invites: {
|
1071
|
+
inviteWorkspaceMember,
|
1072
|
+
updateWorkspaceMemberInvite,
|
1073
|
+
cancelWorkspaceMemberInvite,
|
1074
|
+
acceptWorkspaceMemberInvite,
|
1075
|
+
resendWorkspaceMemberInvite
|
1076
|
+
},
|
1077
|
+
databases: {
|
1078
|
+
getDatabaseList,
|
1079
|
+
createDatabase,
|
1080
|
+
deleteDatabase,
|
1081
|
+
getDatabaseMetadata,
|
1082
|
+
updateDatabaseMetadata,
|
1083
|
+
getDatabaseGithubSettings,
|
1084
|
+
updateDatabaseGithubSettings,
|
1085
|
+
deleteDatabaseGithubSettings,
|
1086
|
+
listRegions
|
590
1087
|
}
|
591
1088
|
};
|
592
1089
|
|
1090
|
+
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1091
|
+
|
593
1092
|
function getHostUrl(provider, type) {
|
594
|
-
if (
|
1093
|
+
if (isHostProviderAlias(provider)) {
|
595
1094
|
return providers[provider][type];
|
596
|
-
} else if (
|
1095
|
+
} else if (isHostProviderBuilder(provider)) {
|
597
1096
|
return provider[type];
|
598
1097
|
}
|
599
1098
|
throw new Error("Invalid API provider");
|
@@ -601,19 +1100,49 @@ function getHostUrl(provider, type) {
|
|
601
1100
|
const providers = {
|
602
1101
|
production: {
|
603
1102
|
main: "https://api.xata.io",
|
604
|
-
workspaces: "https://{workspaceId}.xata.sh"
|
1103
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
605
1104
|
},
|
606
1105
|
staging: {
|
607
|
-
main: "https://staging.
|
608
|
-
workspaces: "https://{workspaceId}.staging.
|
1106
|
+
main: "https://api.staging-xata.dev",
|
1107
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1108
|
+
},
|
1109
|
+
dev: {
|
1110
|
+
main: "https://api.dev-xata.dev",
|
1111
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
609
1112
|
}
|
610
1113
|
};
|
611
|
-
function
|
1114
|
+
function isHostProviderAlias(alias) {
|
612
1115
|
return isString(alias) && Object.keys(providers).includes(alias);
|
613
1116
|
}
|
614
|
-
function
|
1117
|
+
function isHostProviderBuilder(builder) {
|
615
1118
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
616
1119
|
}
|
1120
|
+
function parseProviderString(provider = "production") {
|
1121
|
+
if (isHostProviderAlias(provider)) {
|
1122
|
+
return provider;
|
1123
|
+
}
|
1124
|
+
const [main, workspaces] = provider.split(",");
|
1125
|
+
if (!main || !workspaces)
|
1126
|
+
return null;
|
1127
|
+
return { main, workspaces };
|
1128
|
+
}
|
1129
|
+
function buildProviderString(provider) {
|
1130
|
+
if (isHostProviderAlias(provider))
|
1131
|
+
return provider;
|
1132
|
+
return `${provider.main},${provider.workspaces}`;
|
1133
|
+
}
|
1134
|
+
function parseWorkspacesUrlParts(url) {
|
1135
|
+
if (!isString(url))
|
1136
|
+
return null;
|
1137
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1138
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1139
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1140
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1141
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1142
|
+
if (!match)
|
1143
|
+
return null;
|
1144
|
+
return { workspace: match[1], region: match[2] };
|
1145
|
+
}
|
617
1146
|
|
618
1147
|
var __accessCheck$7 = (obj, member, msg) => {
|
619
1148
|
if (!member.has(obj))
|
@@ -641,15 +1170,19 @@ class XataApiClient {
|
|
641
1170
|
const provider = options.host ?? "production";
|
642
1171
|
const apiKey = options.apiKey ?? getAPIKey();
|
643
1172
|
const trace = options.trace ?? defaultTrace;
|
1173
|
+
const clientID = generateUUID();
|
644
1174
|
if (!apiKey) {
|
645
1175
|
throw new Error("Could not resolve a valid apiKey");
|
646
1176
|
}
|
647
1177
|
__privateSet$7(this, _extraProps, {
|
648
1178
|
apiUrl: getHostUrl(provider, "main"),
|
649
1179
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
650
|
-
|
1180
|
+
fetch: getFetchImplementation(options.fetch),
|
651
1181
|
apiKey,
|
652
|
-
trace
|
1182
|
+
trace,
|
1183
|
+
clientName: options.clientName,
|
1184
|
+
xataAgentExtra: options.xataAgentExtra,
|
1185
|
+
clientID
|
653
1186
|
});
|
654
1187
|
}
|
655
1188
|
get user() {
|
@@ -657,21 +1190,41 @@ class XataApiClient {
|
|
657
1190
|
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
658
1191
|
return __privateGet$7(this, _namespaces).user;
|
659
1192
|
}
|
1193
|
+
get authentication() {
|
1194
|
+
if (!__privateGet$7(this, _namespaces).authentication)
|
1195
|
+
__privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
|
1196
|
+
return __privateGet$7(this, _namespaces).authentication;
|
1197
|
+
}
|
660
1198
|
get workspaces() {
|
661
1199
|
if (!__privateGet$7(this, _namespaces).workspaces)
|
662
1200
|
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
663
1201
|
return __privateGet$7(this, _namespaces).workspaces;
|
664
1202
|
}
|
665
|
-
get
|
666
|
-
if (!__privateGet$7(this, _namespaces).
|
667
|
-
__privateGet$7(this, _namespaces).
|
668
|
-
return __privateGet$7(this, _namespaces).
|
1203
|
+
get invites() {
|
1204
|
+
if (!__privateGet$7(this, _namespaces).invites)
|
1205
|
+
__privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
|
1206
|
+
return __privateGet$7(this, _namespaces).invites;
|
1207
|
+
}
|
1208
|
+
get database() {
|
1209
|
+
if (!__privateGet$7(this, _namespaces).database)
|
1210
|
+
__privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
|
1211
|
+
return __privateGet$7(this, _namespaces).database;
|
669
1212
|
}
|
670
1213
|
get branches() {
|
671
1214
|
if (!__privateGet$7(this, _namespaces).branches)
|
672
1215
|
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
673
1216
|
return __privateGet$7(this, _namespaces).branches;
|
674
1217
|
}
|
1218
|
+
get migrations() {
|
1219
|
+
if (!__privateGet$7(this, _namespaces).migrations)
|
1220
|
+
__privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
|
1221
|
+
return __privateGet$7(this, _namespaces).migrations;
|
1222
|
+
}
|
1223
|
+
get migrationRequests() {
|
1224
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
1225
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
1226
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
1227
|
+
}
|
675
1228
|
get tables() {
|
676
1229
|
if (!__privateGet$7(this, _namespaces).tables)
|
677
1230
|
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
@@ -682,6 +1235,11 @@ class XataApiClient {
|
|
682
1235
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
683
1236
|
return __privateGet$7(this, _namespaces).records;
|
684
1237
|
}
|
1238
|
+
get searchAndFilter() {
|
1239
|
+
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
1240
|
+
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
1241
|
+
return __privateGet$7(this, _namespaces).searchAndFilter;
|
1242
|
+
}
|
685
1243
|
}
|
686
1244
|
_extraProps = new WeakMap();
|
687
1245
|
_namespaces = new WeakMap();
|
@@ -692,24 +1250,29 @@ class UserApi {
|
|
692
1250
|
getUser() {
|
693
1251
|
return operationsByTag.users.getUser({ ...this.extraProps });
|
694
1252
|
}
|
695
|
-
updateUser(user) {
|
1253
|
+
updateUser({ user }) {
|
696
1254
|
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
697
1255
|
}
|
698
1256
|
deleteUser() {
|
699
1257
|
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
700
1258
|
}
|
1259
|
+
}
|
1260
|
+
class AuthenticationApi {
|
1261
|
+
constructor(extraProps) {
|
1262
|
+
this.extraProps = extraProps;
|
1263
|
+
}
|
701
1264
|
getUserAPIKeys() {
|
702
|
-
return operationsByTag.
|
1265
|
+
return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
|
703
1266
|
}
|
704
|
-
createUserAPIKey(
|
705
|
-
return operationsByTag.
|
706
|
-
pathParams: { keyName },
|
1267
|
+
createUserAPIKey({ name }) {
|
1268
|
+
return operationsByTag.authentication.createUserAPIKey({
|
1269
|
+
pathParams: { keyName: name },
|
707
1270
|
...this.extraProps
|
708
1271
|
});
|
709
1272
|
}
|
710
|
-
deleteUserAPIKey(
|
711
|
-
return operationsByTag.
|
712
|
-
pathParams: { keyName },
|
1273
|
+
deleteUserAPIKey({ name }) {
|
1274
|
+
return operationsByTag.authentication.deleteUserAPIKey({
|
1275
|
+
pathParams: { keyName: name },
|
713
1276
|
...this.extraProps
|
714
1277
|
});
|
715
1278
|
}
|
@@ -718,374 +1281,1009 @@ class WorkspaceApi {
|
|
718
1281
|
constructor(extraProps) {
|
719
1282
|
this.extraProps = extraProps;
|
720
1283
|
}
|
721
|
-
|
1284
|
+
getWorkspacesList() {
|
1285
|
+
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
1286
|
+
}
|
1287
|
+
createWorkspace({ data }) {
|
722
1288
|
return operationsByTag.workspaces.createWorkspace({
|
723
|
-
body:
|
1289
|
+
body: data,
|
724
1290
|
...this.extraProps
|
725
1291
|
});
|
726
1292
|
}
|
727
|
-
|
728
|
-
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
729
|
-
}
|
730
|
-
getWorkspace(workspaceId) {
|
1293
|
+
getWorkspace({ workspace }) {
|
731
1294
|
return operationsByTag.workspaces.getWorkspace({
|
732
|
-
pathParams: { workspaceId },
|
1295
|
+
pathParams: { workspaceId: workspace },
|
733
1296
|
...this.extraProps
|
734
1297
|
});
|
735
1298
|
}
|
736
|
-
updateWorkspace(
|
1299
|
+
updateWorkspace({
|
1300
|
+
workspace,
|
1301
|
+
update
|
1302
|
+
}) {
|
737
1303
|
return operationsByTag.workspaces.updateWorkspace({
|
738
|
-
pathParams: { workspaceId },
|
739
|
-
body:
|
1304
|
+
pathParams: { workspaceId: workspace },
|
1305
|
+
body: update,
|
740
1306
|
...this.extraProps
|
741
1307
|
});
|
742
1308
|
}
|
743
|
-
deleteWorkspace(
|
1309
|
+
deleteWorkspace({ workspace }) {
|
744
1310
|
return operationsByTag.workspaces.deleteWorkspace({
|
745
|
-
pathParams: { workspaceId },
|
1311
|
+
pathParams: { workspaceId: workspace },
|
746
1312
|
...this.extraProps
|
747
1313
|
});
|
748
1314
|
}
|
749
|
-
getWorkspaceMembersList(
|
1315
|
+
getWorkspaceMembersList({ workspace }) {
|
750
1316
|
return operationsByTag.workspaces.getWorkspaceMembersList({
|
751
|
-
pathParams: { workspaceId },
|
1317
|
+
pathParams: { workspaceId: workspace },
|
752
1318
|
...this.extraProps
|
753
1319
|
});
|
754
1320
|
}
|
755
|
-
updateWorkspaceMemberRole(
|
1321
|
+
updateWorkspaceMemberRole({
|
1322
|
+
workspace,
|
1323
|
+
user,
|
1324
|
+
role
|
1325
|
+
}) {
|
756
1326
|
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
757
|
-
pathParams: { workspaceId, userId },
|
1327
|
+
pathParams: { workspaceId: workspace, userId: user },
|
758
1328
|
body: { role },
|
759
1329
|
...this.extraProps
|
760
1330
|
});
|
761
1331
|
}
|
762
|
-
removeWorkspaceMember(
|
1332
|
+
removeWorkspaceMember({
|
1333
|
+
workspace,
|
1334
|
+
user
|
1335
|
+
}) {
|
763
1336
|
return operationsByTag.workspaces.removeWorkspaceMember({
|
764
|
-
pathParams: { workspaceId, userId },
|
1337
|
+
pathParams: { workspaceId: workspace, userId: user },
|
765
1338
|
...this.extraProps
|
766
1339
|
});
|
767
1340
|
}
|
768
|
-
|
769
|
-
|
770
|
-
|
1341
|
+
}
|
1342
|
+
class InvitesApi {
|
1343
|
+
constructor(extraProps) {
|
1344
|
+
this.extraProps = extraProps;
|
1345
|
+
}
|
1346
|
+
inviteWorkspaceMember({
|
1347
|
+
workspace,
|
1348
|
+
email,
|
1349
|
+
role
|
1350
|
+
}) {
|
1351
|
+
return operationsByTag.invites.inviteWorkspaceMember({
|
1352
|
+
pathParams: { workspaceId: workspace },
|
771
1353
|
body: { email, role },
|
772
1354
|
...this.extraProps
|
773
1355
|
});
|
774
1356
|
}
|
775
|
-
updateWorkspaceMemberInvite(
|
776
|
-
|
777
|
-
|
1357
|
+
updateWorkspaceMemberInvite({
|
1358
|
+
workspace,
|
1359
|
+
invite,
|
1360
|
+
role
|
1361
|
+
}) {
|
1362
|
+
return operationsByTag.invites.updateWorkspaceMemberInvite({
|
1363
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
778
1364
|
body: { role },
|
779
1365
|
...this.extraProps
|
780
1366
|
});
|
781
1367
|
}
|
782
|
-
cancelWorkspaceMemberInvite(
|
783
|
-
|
784
|
-
|
1368
|
+
cancelWorkspaceMemberInvite({
|
1369
|
+
workspace,
|
1370
|
+
invite
|
1371
|
+
}) {
|
1372
|
+
return operationsByTag.invites.cancelWorkspaceMemberInvite({
|
1373
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
1374
|
+
...this.extraProps
|
1375
|
+
});
|
1376
|
+
}
|
1377
|
+
acceptWorkspaceMemberInvite({
|
1378
|
+
workspace,
|
1379
|
+
key
|
1380
|
+
}) {
|
1381
|
+
return operationsByTag.invites.acceptWorkspaceMemberInvite({
|
1382
|
+
pathParams: { workspaceId: workspace, inviteKey: key },
|
1383
|
+
...this.extraProps
|
1384
|
+
});
|
1385
|
+
}
|
1386
|
+
resendWorkspaceMemberInvite({
|
1387
|
+
workspace,
|
1388
|
+
invite
|
1389
|
+
}) {
|
1390
|
+
return operationsByTag.invites.resendWorkspaceMemberInvite({
|
1391
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
1392
|
+
...this.extraProps
|
1393
|
+
});
|
1394
|
+
}
|
1395
|
+
}
|
1396
|
+
class BranchApi {
|
1397
|
+
constructor(extraProps) {
|
1398
|
+
this.extraProps = extraProps;
|
1399
|
+
}
|
1400
|
+
getBranchList({
|
1401
|
+
workspace,
|
1402
|
+
region,
|
1403
|
+
database
|
1404
|
+
}) {
|
1405
|
+
return operationsByTag.branch.getBranchList({
|
1406
|
+
pathParams: { workspace, region, dbName: database },
|
1407
|
+
...this.extraProps
|
1408
|
+
});
|
1409
|
+
}
|
1410
|
+
getBranchDetails({
|
1411
|
+
workspace,
|
1412
|
+
region,
|
1413
|
+
database,
|
1414
|
+
branch
|
1415
|
+
}) {
|
1416
|
+
return operationsByTag.branch.getBranchDetails({
|
1417
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1418
|
+
...this.extraProps
|
1419
|
+
});
|
1420
|
+
}
|
1421
|
+
createBranch({
|
1422
|
+
workspace,
|
1423
|
+
region,
|
1424
|
+
database,
|
1425
|
+
branch,
|
1426
|
+
from,
|
1427
|
+
metadata
|
1428
|
+
}) {
|
1429
|
+
return operationsByTag.branch.createBranch({
|
1430
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1431
|
+
body: { from, metadata },
|
1432
|
+
...this.extraProps
|
1433
|
+
});
|
1434
|
+
}
|
1435
|
+
deleteBranch({
|
1436
|
+
workspace,
|
1437
|
+
region,
|
1438
|
+
database,
|
1439
|
+
branch
|
1440
|
+
}) {
|
1441
|
+
return operationsByTag.branch.deleteBranch({
|
1442
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1443
|
+
...this.extraProps
|
1444
|
+
});
|
1445
|
+
}
|
1446
|
+
copyBranch({
|
1447
|
+
workspace,
|
1448
|
+
region,
|
1449
|
+
database,
|
1450
|
+
branch,
|
1451
|
+
destinationBranch,
|
1452
|
+
limit
|
1453
|
+
}) {
|
1454
|
+
return operationsByTag.branch.copyBranch({
|
1455
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1456
|
+
body: { destinationBranch, limit },
|
1457
|
+
...this.extraProps
|
1458
|
+
});
|
1459
|
+
}
|
1460
|
+
updateBranchMetadata({
|
1461
|
+
workspace,
|
1462
|
+
region,
|
1463
|
+
database,
|
1464
|
+
branch,
|
1465
|
+
metadata
|
1466
|
+
}) {
|
1467
|
+
return operationsByTag.branch.updateBranchMetadata({
|
1468
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1469
|
+
body: metadata,
|
1470
|
+
...this.extraProps
|
1471
|
+
});
|
1472
|
+
}
|
1473
|
+
getBranchMetadata({
|
1474
|
+
workspace,
|
1475
|
+
region,
|
1476
|
+
database,
|
1477
|
+
branch
|
1478
|
+
}) {
|
1479
|
+
return operationsByTag.branch.getBranchMetadata({
|
1480
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1481
|
+
...this.extraProps
|
1482
|
+
});
|
1483
|
+
}
|
1484
|
+
getBranchStats({
|
1485
|
+
workspace,
|
1486
|
+
region,
|
1487
|
+
database,
|
1488
|
+
branch
|
1489
|
+
}) {
|
1490
|
+
return operationsByTag.branch.getBranchStats({
|
1491
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1492
|
+
...this.extraProps
|
1493
|
+
});
|
1494
|
+
}
|
1495
|
+
getGitBranchesMapping({
|
1496
|
+
workspace,
|
1497
|
+
region,
|
1498
|
+
database
|
1499
|
+
}) {
|
1500
|
+
return operationsByTag.branch.getGitBranchesMapping({
|
1501
|
+
pathParams: { workspace, region, dbName: database },
|
1502
|
+
...this.extraProps
|
1503
|
+
});
|
1504
|
+
}
|
1505
|
+
addGitBranchesEntry({
|
1506
|
+
workspace,
|
1507
|
+
region,
|
1508
|
+
database,
|
1509
|
+
gitBranch,
|
1510
|
+
xataBranch
|
1511
|
+
}) {
|
1512
|
+
return operationsByTag.branch.addGitBranchesEntry({
|
1513
|
+
pathParams: { workspace, region, dbName: database },
|
1514
|
+
body: { gitBranch, xataBranch },
|
1515
|
+
...this.extraProps
|
1516
|
+
});
|
1517
|
+
}
|
1518
|
+
removeGitBranchesEntry({
|
1519
|
+
workspace,
|
1520
|
+
region,
|
1521
|
+
database,
|
1522
|
+
gitBranch
|
1523
|
+
}) {
|
1524
|
+
return operationsByTag.branch.removeGitBranchesEntry({
|
1525
|
+
pathParams: { workspace, region, dbName: database },
|
1526
|
+
queryParams: { gitBranch },
|
1527
|
+
...this.extraProps
|
1528
|
+
});
|
1529
|
+
}
|
1530
|
+
resolveBranch({
|
1531
|
+
workspace,
|
1532
|
+
region,
|
1533
|
+
database,
|
1534
|
+
gitBranch,
|
1535
|
+
fallbackBranch
|
1536
|
+
}) {
|
1537
|
+
return operationsByTag.branch.resolveBranch({
|
1538
|
+
pathParams: { workspace, region, dbName: database },
|
1539
|
+
queryParams: { gitBranch, fallbackBranch },
|
1540
|
+
...this.extraProps
|
1541
|
+
});
|
1542
|
+
}
|
1543
|
+
}
|
1544
|
+
class TableApi {
|
1545
|
+
constructor(extraProps) {
|
1546
|
+
this.extraProps = extraProps;
|
1547
|
+
}
|
1548
|
+
createTable({
|
1549
|
+
workspace,
|
1550
|
+
region,
|
1551
|
+
database,
|
1552
|
+
branch,
|
1553
|
+
table
|
1554
|
+
}) {
|
1555
|
+
return operationsByTag.table.createTable({
|
1556
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1557
|
+
...this.extraProps
|
1558
|
+
});
|
1559
|
+
}
|
1560
|
+
deleteTable({
|
1561
|
+
workspace,
|
1562
|
+
region,
|
1563
|
+
database,
|
1564
|
+
branch,
|
1565
|
+
table
|
1566
|
+
}) {
|
1567
|
+
return operationsByTag.table.deleteTable({
|
1568
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1569
|
+
...this.extraProps
|
1570
|
+
});
|
1571
|
+
}
|
1572
|
+
updateTable({
|
1573
|
+
workspace,
|
1574
|
+
region,
|
1575
|
+
database,
|
1576
|
+
branch,
|
1577
|
+
table,
|
1578
|
+
update
|
1579
|
+
}) {
|
1580
|
+
return operationsByTag.table.updateTable({
|
1581
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1582
|
+
body: update,
|
1583
|
+
...this.extraProps
|
1584
|
+
});
|
1585
|
+
}
|
1586
|
+
getTableSchema({
|
1587
|
+
workspace,
|
1588
|
+
region,
|
1589
|
+
database,
|
1590
|
+
branch,
|
1591
|
+
table
|
1592
|
+
}) {
|
1593
|
+
return operationsByTag.table.getTableSchema({
|
1594
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1595
|
+
...this.extraProps
|
1596
|
+
});
|
1597
|
+
}
|
1598
|
+
setTableSchema({
|
1599
|
+
workspace,
|
1600
|
+
region,
|
1601
|
+
database,
|
1602
|
+
branch,
|
1603
|
+
table,
|
1604
|
+
schema
|
1605
|
+
}) {
|
1606
|
+
return operationsByTag.table.setTableSchema({
|
1607
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1608
|
+
body: schema,
|
1609
|
+
...this.extraProps
|
1610
|
+
});
|
1611
|
+
}
|
1612
|
+
getTableColumns({
|
1613
|
+
workspace,
|
1614
|
+
region,
|
1615
|
+
database,
|
1616
|
+
branch,
|
1617
|
+
table
|
1618
|
+
}) {
|
1619
|
+
return operationsByTag.table.getTableColumns({
|
1620
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1621
|
+
...this.extraProps
|
1622
|
+
});
|
1623
|
+
}
|
1624
|
+
addTableColumn({
|
1625
|
+
workspace,
|
1626
|
+
region,
|
1627
|
+
database,
|
1628
|
+
branch,
|
1629
|
+
table,
|
1630
|
+
column
|
1631
|
+
}) {
|
1632
|
+
return operationsByTag.table.addTableColumn({
|
1633
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1634
|
+
body: column,
|
1635
|
+
...this.extraProps
|
1636
|
+
});
|
1637
|
+
}
|
1638
|
+
getColumn({
|
1639
|
+
workspace,
|
1640
|
+
region,
|
1641
|
+
database,
|
1642
|
+
branch,
|
1643
|
+
table,
|
1644
|
+
column
|
1645
|
+
}) {
|
1646
|
+
return operationsByTag.table.getColumn({
|
1647
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1648
|
+
...this.extraProps
|
1649
|
+
});
|
1650
|
+
}
|
1651
|
+
updateColumn({
|
1652
|
+
workspace,
|
1653
|
+
region,
|
1654
|
+
database,
|
1655
|
+
branch,
|
1656
|
+
table,
|
1657
|
+
column,
|
1658
|
+
update
|
1659
|
+
}) {
|
1660
|
+
return operationsByTag.table.updateColumn({
|
1661
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1662
|
+
body: update,
|
1663
|
+
...this.extraProps
|
1664
|
+
});
|
1665
|
+
}
|
1666
|
+
deleteColumn({
|
1667
|
+
workspace,
|
1668
|
+
region,
|
1669
|
+
database,
|
1670
|
+
branch,
|
1671
|
+
table,
|
1672
|
+
column
|
1673
|
+
}) {
|
1674
|
+
return operationsByTag.table.deleteColumn({
|
1675
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1676
|
+
...this.extraProps
|
1677
|
+
});
|
1678
|
+
}
|
1679
|
+
}
|
1680
|
+
class RecordsApi {
|
1681
|
+
constructor(extraProps) {
|
1682
|
+
this.extraProps = extraProps;
|
1683
|
+
}
|
1684
|
+
insertRecord({
|
1685
|
+
workspace,
|
1686
|
+
region,
|
1687
|
+
database,
|
1688
|
+
branch,
|
1689
|
+
table,
|
1690
|
+
record,
|
1691
|
+
columns
|
1692
|
+
}) {
|
1693
|
+
return operationsByTag.records.insertRecord({
|
1694
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1695
|
+
queryParams: { columns },
|
1696
|
+
body: record,
|
1697
|
+
...this.extraProps
|
1698
|
+
});
|
1699
|
+
}
|
1700
|
+
getRecord({
|
1701
|
+
workspace,
|
1702
|
+
region,
|
1703
|
+
database,
|
1704
|
+
branch,
|
1705
|
+
table,
|
1706
|
+
id,
|
1707
|
+
columns
|
1708
|
+
}) {
|
1709
|
+
return operationsByTag.records.getRecord({
|
1710
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1711
|
+
queryParams: { columns },
|
1712
|
+
...this.extraProps
|
1713
|
+
});
|
1714
|
+
}
|
1715
|
+
insertRecordWithID({
|
1716
|
+
workspace,
|
1717
|
+
region,
|
1718
|
+
database,
|
1719
|
+
branch,
|
1720
|
+
table,
|
1721
|
+
id,
|
1722
|
+
record,
|
1723
|
+
columns,
|
1724
|
+
createOnly,
|
1725
|
+
ifVersion
|
1726
|
+
}) {
|
1727
|
+
return operationsByTag.records.insertRecordWithID({
|
1728
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1729
|
+
queryParams: { columns, createOnly, ifVersion },
|
1730
|
+
body: record,
|
1731
|
+
...this.extraProps
|
1732
|
+
});
|
1733
|
+
}
|
1734
|
+
updateRecordWithID({
|
1735
|
+
workspace,
|
1736
|
+
region,
|
1737
|
+
database,
|
1738
|
+
branch,
|
1739
|
+
table,
|
1740
|
+
id,
|
1741
|
+
record,
|
1742
|
+
columns,
|
1743
|
+
ifVersion
|
1744
|
+
}) {
|
1745
|
+
return operationsByTag.records.updateRecordWithID({
|
1746
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1747
|
+
queryParams: { columns, ifVersion },
|
1748
|
+
body: record,
|
1749
|
+
...this.extraProps
|
1750
|
+
});
|
1751
|
+
}
|
1752
|
+
upsertRecordWithID({
|
1753
|
+
workspace,
|
1754
|
+
region,
|
1755
|
+
database,
|
1756
|
+
branch,
|
1757
|
+
table,
|
1758
|
+
id,
|
1759
|
+
record,
|
1760
|
+
columns,
|
1761
|
+
ifVersion
|
1762
|
+
}) {
|
1763
|
+
return operationsByTag.records.upsertRecordWithID({
|
1764
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1765
|
+
queryParams: { columns, ifVersion },
|
1766
|
+
body: record,
|
1767
|
+
...this.extraProps
|
1768
|
+
});
|
1769
|
+
}
|
1770
|
+
deleteRecord({
|
1771
|
+
workspace,
|
1772
|
+
region,
|
1773
|
+
database,
|
1774
|
+
branch,
|
1775
|
+
table,
|
1776
|
+
id,
|
1777
|
+
columns
|
1778
|
+
}) {
|
1779
|
+
return operationsByTag.records.deleteRecord({
|
1780
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1781
|
+
queryParams: { columns },
|
785
1782
|
...this.extraProps
|
786
1783
|
});
|
787
1784
|
}
|
788
|
-
|
789
|
-
|
790
|
-
|
1785
|
+
bulkInsertTableRecords({
|
1786
|
+
workspace,
|
1787
|
+
region,
|
1788
|
+
database,
|
1789
|
+
branch,
|
1790
|
+
table,
|
1791
|
+
records,
|
1792
|
+
columns
|
1793
|
+
}) {
|
1794
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
1795
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1796
|
+
queryParams: { columns },
|
1797
|
+
body: { records },
|
791
1798
|
...this.extraProps
|
792
1799
|
});
|
793
1800
|
}
|
794
|
-
|
795
|
-
|
796
|
-
|
1801
|
+
branchTransaction({
|
1802
|
+
workspace,
|
1803
|
+
region,
|
1804
|
+
database,
|
1805
|
+
branch,
|
1806
|
+
operations
|
1807
|
+
}) {
|
1808
|
+
return operationsByTag.records.branchTransaction({
|
1809
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1810
|
+
body: { operations },
|
797
1811
|
...this.extraProps
|
798
1812
|
});
|
799
1813
|
}
|
800
1814
|
}
|
801
|
-
class
|
1815
|
+
class SearchAndFilterApi {
|
802
1816
|
constructor(extraProps) {
|
803
1817
|
this.extraProps = extraProps;
|
804
1818
|
}
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
1819
|
+
queryTable({
|
1820
|
+
workspace,
|
1821
|
+
region,
|
1822
|
+
database,
|
1823
|
+
branch,
|
1824
|
+
table,
|
1825
|
+
filter,
|
1826
|
+
sort,
|
1827
|
+
page,
|
1828
|
+
columns,
|
1829
|
+
consistency
|
1830
|
+
}) {
|
1831
|
+
return operationsByTag.searchAndFilter.queryTable({
|
1832
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1833
|
+
body: { filter, sort, page, columns, consistency },
|
815
1834
|
...this.extraProps
|
816
1835
|
});
|
817
1836
|
}
|
818
|
-
|
819
|
-
|
820
|
-
|
1837
|
+
searchTable({
|
1838
|
+
workspace,
|
1839
|
+
region,
|
1840
|
+
database,
|
1841
|
+
branch,
|
1842
|
+
table,
|
1843
|
+
query,
|
1844
|
+
fuzziness,
|
1845
|
+
target,
|
1846
|
+
prefix,
|
1847
|
+
filter,
|
1848
|
+
highlight,
|
1849
|
+
boosters
|
1850
|
+
}) {
|
1851
|
+
return operationsByTag.searchAndFilter.searchTable({
|
1852
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1853
|
+
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
821
1854
|
...this.extraProps
|
822
1855
|
});
|
823
1856
|
}
|
824
|
-
|
825
|
-
|
826
|
-
|
1857
|
+
searchBranch({
|
1858
|
+
workspace,
|
1859
|
+
region,
|
1860
|
+
database,
|
1861
|
+
branch,
|
1862
|
+
tables,
|
1863
|
+
query,
|
1864
|
+
fuzziness,
|
1865
|
+
prefix,
|
1866
|
+
highlight
|
1867
|
+
}) {
|
1868
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
1869
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1870
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
827
1871
|
...this.extraProps
|
828
1872
|
});
|
829
1873
|
}
|
830
|
-
|
831
|
-
|
832
|
-
|
1874
|
+
vectorSearchTable({
|
1875
|
+
workspace,
|
1876
|
+
region,
|
1877
|
+
database,
|
1878
|
+
branch,
|
1879
|
+
table,
|
1880
|
+
queryVector,
|
1881
|
+
column,
|
1882
|
+
similarityFunction,
|
1883
|
+
size,
|
1884
|
+
filter
|
1885
|
+
}) {
|
1886
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
1887
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1888
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
833
1889
|
...this.extraProps
|
834
1890
|
});
|
835
1891
|
}
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
1892
|
+
askTable({
|
1893
|
+
workspace,
|
1894
|
+
region,
|
1895
|
+
database,
|
1896
|
+
branch,
|
1897
|
+
table,
|
1898
|
+
options
|
1899
|
+
}) {
|
1900
|
+
return operationsByTag.searchAndFilter.askTable({
|
1901
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1902
|
+
body: { ...options },
|
840
1903
|
...this.extraProps
|
841
1904
|
});
|
842
1905
|
}
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
1906
|
+
summarizeTable({
|
1907
|
+
workspace,
|
1908
|
+
region,
|
1909
|
+
database,
|
1910
|
+
branch,
|
1911
|
+
table,
|
1912
|
+
filter,
|
1913
|
+
columns,
|
1914
|
+
summaries,
|
1915
|
+
sort,
|
1916
|
+
summariesFilter,
|
1917
|
+
page,
|
1918
|
+
consistency
|
1919
|
+
}) {
|
1920
|
+
return operationsByTag.searchAndFilter.summarizeTable({
|
1921
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1922
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
847
1923
|
...this.extraProps
|
848
1924
|
});
|
849
1925
|
}
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
1926
|
+
aggregateTable({
|
1927
|
+
workspace,
|
1928
|
+
region,
|
1929
|
+
database,
|
1930
|
+
branch,
|
1931
|
+
table,
|
1932
|
+
filter,
|
1933
|
+
aggs
|
1934
|
+
}) {
|
1935
|
+
return operationsByTag.searchAndFilter.aggregateTable({
|
1936
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1937
|
+
body: { filter, aggs },
|
854
1938
|
...this.extraProps
|
855
1939
|
});
|
856
1940
|
}
|
857
1941
|
}
|
858
|
-
class
|
1942
|
+
class MigrationRequestsApi {
|
859
1943
|
constructor(extraProps) {
|
860
1944
|
this.extraProps = extraProps;
|
861
1945
|
}
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
createBranch(workspace, database, branch, from, options = {}) {
|
875
|
-
return operationsByTag.branch.createBranch({
|
876
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
877
|
-
queryParams: isString(from) ? { from } : void 0,
|
878
|
-
body: options,
|
1946
|
+
queryMigrationRequests({
|
1947
|
+
workspace,
|
1948
|
+
region,
|
1949
|
+
database,
|
1950
|
+
filter,
|
1951
|
+
sort,
|
1952
|
+
page,
|
1953
|
+
columns
|
1954
|
+
}) {
|
1955
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
1956
|
+
pathParams: { workspace, region, dbName: database },
|
1957
|
+
body: { filter, sort, page, columns },
|
879
1958
|
...this.extraProps
|
880
1959
|
});
|
881
1960
|
}
|
882
|
-
|
883
|
-
|
884
|
-
|
1961
|
+
createMigrationRequest({
|
1962
|
+
workspace,
|
1963
|
+
region,
|
1964
|
+
database,
|
1965
|
+
migration
|
1966
|
+
}) {
|
1967
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1968
|
+
pathParams: { workspace, region, dbName: database },
|
1969
|
+
body: migration,
|
885
1970
|
...this.extraProps
|
886
1971
|
});
|
887
1972
|
}
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
1973
|
+
getMigrationRequest({
|
1974
|
+
workspace,
|
1975
|
+
region,
|
1976
|
+
database,
|
1977
|
+
migrationRequest
|
1978
|
+
}) {
|
1979
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1980
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
892
1981
|
...this.extraProps
|
893
1982
|
});
|
894
1983
|
}
|
895
|
-
|
896
|
-
|
897
|
-
|
1984
|
+
updateMigrationRequest({
|
1985
|
+
workspace,
|
1986
|
+
region,
|
1987
|
+
database,
|
1988
|
+
migrationRequest,
|
1989
|
+
update
|
1990
|
+
}) {
|
1991
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1992
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1993
|
+
body: update,
|
898
1994
|
...this.extraProps
|
899
1995
|
});
|
900
1996
|
}
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
1997
|
+
listMigrationRequestsCommits({
|
1998
|
+
workspace,
|
1999
|
+
region,
|
2000
|
+
database,
|
2001
|
+
migrationRequest,
|
2002
|
+
page
|
2003
|
+
}) {
|
2004
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
2005
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
2006
|
+
body: { page },
|
905
2007
|
...this.extraProps
|
906
2008
|
});
|
907
2009
|
}
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
2010
|
+
compareMigrationRequest({
|
2011
|
+
workspace,
|
2012
|
+
region,
|
2013
|
+
database,
|
2014
|
+
migrationRequest
|
2015
|
+
}) {
|
2016
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
2017
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
912
2018
|
...this.extraProps
|
913
2019
|
});
|
914
2020
|
}
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
2021
|
+
getMigrationRequestIsMerged({
|
2022
|
+
workspace,
|
2023
|
+
region,
|
2024
|
+
database,
|
2025
|
+
migrationRequest
|
2026
|
+
}) {
|
2027
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
2028
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
919
2029
|
...this.extraProps
|
920
2030
|
});
|
921
2031
|
}
|
922
|
-
|
923
|
-
|
924
|
-
|
2032
|
+
mergeMigrationRequest({
|
2033
|
+
workspace,
|
2034
|
+
region,
|
2035
|
+
database,
|
2036
|
+
migrationRequest
|
2037
|
+
}) {
|
2038
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
2039
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
925
2040
|
...this.extraProps
|
926
2041
|
});
|
927
2042
|
}
|
928
2043
|
}
|
929
|
-
class
|
2044
|
+
class MigrationsApi {
|
930
2045
|
constructor(extraProps) {
|
931
2046
|
this.extraProps = extraProps;
|
932
2047
|
}
|
933
|
-
|
934
|
-
|
935
|
-
|
2048
|
+
getBranchMigrationHistory({
|
2049
|
+
workspace,
|
2050
|
+
region,
|
2051
|
+
database,
|
2052
|
+
branch,
|
2053
|
+
limit,
|
2054
|
+
startFrom
|
2055
|
+
}) {
|
2056
|
+
return operationsByTag.migrations.getBranchMigrationHistory({
|
2057
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2058
|
+
body: { limit, startFrom },
|
936
2059
|
...this.extraProps
|
937
2060
|
});
|
938
2061
|
}
|
939
|
-
|
940
|
-
|
941
|
-
|
2062
|
+
getBranchMigrationPlan({
|
2063
|
+
workspace,
|
2064
|
+
region,
|
2065
|
+
database,
|
2066
|
+
branch,
|
2067
|
+
schema
|
2068
|
+
}) {
|
2069
|
+
return operationsByTag.migrations.getBranchMigrationPlan({
|
2070
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2071
|
+
body: schema,
|
942
2072
|
...this.extraProps
|
943
2073
|
});
|
944
2074
|
}
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
2075
|
+
executeBranchMigrationPlan({
|
2076
|
+
workspace,
|
2077
|
+
region,
|
2078
|
+
database,
|
2079
|
+
branch,
|
2080
|
+
plan
|
2081
|
+
}) {
|
2082
|
+
return operationsByTag.migrations.executeBranchMigrationPlan({
|
2083
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2084
|
+
body: plan,
|
949
2085
|
...this.extraProps
|
950
2086
|
});
|
951
2087
|
}
|
952
|
-
|
953
|
-
|
954
|
-
|
2088
|
+
getBranchSchemaHistory({
|
2089
|
+
workspace,
|
2090
|
+
region,
|
2091
|
+
database,
|
2092
|
+
branch,
|
2093
|
+
page
|
2094
|
+
}) {
|
2095
|
+
return operationsByTag.migrations.getBranchSchemaHistory({
|
2096
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2097
|
+
body: { page },
|
955
2098
|
...this.extraProps
|
956
2099
|
});
|
957
2100
|
}
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
2101
|
+
compareBranchWithUserSchema({
|
2102
|
+
workspace,
|
2103
|
+
region,
|
2104
|
+
database,
|
2105
|
+
branch,
|
2106
|
+
schema,
|
2107
|
+
schemaOperations,
|
2108
|
+
branchOperations
|
2109
|
+
}) {
|
2110
|
+
return operationsByTag.migrations.compareBranchWithUserSchema({
|
2111
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2112
|
+
body: { schema, schemaOperations, branchOperations },
|
962
2113
|
...this.extraProps
|
963
2114
|
});
|
964
2115
|
}
|
965
|
-
|
966
|
-
|
967
|
-
|
2116
|
+
compareBranchSchemas({
|
2117
|
+
workspace,
|
2118
|
+
region,
|
2119
|
+
database,
|
2120
|
+
branch,
|
2121
|
+
compare,
|
2122
|
+
sourceBranchOperations,
|
2123
|
+
targetBranchOperations
|
2124
|
+
}) {
|
2125
|
+
return operationsByTag.migrations.compareBranchSchemas({
|
2126
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
2127
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
968
2128
|
...this.extraProps
|
969
2129
|
});
|
970
2130
|
}
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
2131
|
+
updateBranchSchema({
|
2132
|
+
workspace,
|
2133
|
+
region,
|
2134
|
+
database,
|
2135
|
+
branch,
|
2136
|
+
migration
|
2137
|
+
}) {
|
2138
|
+
return operationsByTag.migrations.updateBranchSchema({
|
2139
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2140
|
+
body: migration,
|
975
2141
|
...this.extraProps
|
976
2142
|
});
|
977
2143
|
}
|
978
|
-
|
979
|
-
|
980
|
-
|
2144
|
+
previewBranchSchemaEdit({
|
2145
|
+
workspace,
|
2146
|
+
region,
|
2147
|
+
database,
|
2148
|
+
branch,
|
2149
|
+
data
|
2150
|
+
}) {
|
2151
|
+
return operationsByTag.migrations.previewBranchSchemaEdit({
|
2152
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2153
|
+
body: data,
|
981
2154
|
...this.extraProps
|
982
2155
|
});
|
983
2156
|
}
|
984
|
-
|
985
|
-
|
986
|
-
|
2157
|
+
applyBranchSchemaEdit({
|
2158
|
+
workspace,
|
2159
|
+
region,
|
2160
|
+
database,
|
2161
|
+
branch,
|
2162
|
+
edits
|
2163
|
+
}) {
|
2164
|
+
return operationsByTag.migrations.applyBranchSchemaEdit({
|
2165
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2166
|
+
body: { edits },
|
987
2167
|
...this.extraProps
|
988
2168
|
});
|
989
2169
|
}
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
2170
|
+
pushBranchMigrations({
|
2171
|
+
workspace,
|
2172
|
+
region,
|
2173
|
+
database,
|
2174
|
+
branch,
|
2175
|
+
migrations
|
2176
|
+
}) {
|
2177
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2178
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2179
|
+
body: { migrations },
|
994
2180
|
...this.extraProps
|
995
2181
|
});
|
996
2182
|
}
|
997
2183
|
}
|
998
|
-
class
|
2184
|
+
class DatabaseApi {
|
999
2185
|
constructor(extraProps) {
|
1000
2186
|
this.extraProps = extraProps;
|
1001
2187
|
}
|
1002
|
-
|
1003
|
-
return operationsByTag.
|
1004
|
-
pathParams: {
|
1005
|
-
queryParams: options,
|
1006
|
-
body: record,
|
1007
|
-
...this.extraProps
|
1008
|
-
});
|
1009
|
-
}
|
1010
|
-
insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
1011
|
-
return operationsByTag.records.insertRecordWithID({
|
1012
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1013
|
-
queryParams: options,
|
1014
|
-
body: record,
|
2188
|
+
getDatabaseList({ workspace }) {
|
2189
|
+
return operationsByTag.databases.getDatabaseList({
|
2190
|
+
pathParams: { workspaceId: workspace },
|
1015
2191
|
...this.extraProps
|
1016
2192
|
});
|
1017
2193
|
}
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
2194
|
+
createDatabase({
|
2195
|
+
workspace,
|
2196
|
+
database,
|
2197
|
+
data
|
2198
|
+
}) {
|
2199
|
+
return operationsByTag.databases.createDatabase({
|
2200
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2201
|
+
body: data,
|
1023
2202
|
...this.extraProps
|
1024
2203
|
});
|
1025
2204
|
}
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
2205
|
+
deleteDatabase({
|
2206
|
+
workspace,
|
2207
|
+
database
|
2208
|
+
}) {
|
2209
|
+
return operationsByTag.databases.deleteDatabase({
|
2210
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1031
2211
|
...this.extraProps
|
1032
2212
|
});
|
1033
2213
|
}
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
2214
|
+
getDatabaseMetadata({
|
2215
|
+
workspace,
|
2216
|
+
database
|
2217
|
+
}) {
|
2218
|
+
return operationsByTag.databases.getDatabaseMetadata({
|
2219
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1038
2220
|
...this.extraProps
|
1039
2221
|
});
|
1040
2222
|
}
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
2223
|
+
updateDatabaseMetadata({
|
2224
|
+
workspace,
|
2225
|
+
database,
|
2226
|
+
metadata
|
2227
|
+
}) {
|
2228
|
+
return operationsByTag.databases.updateDatabaseMetadata({
|
2229
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2230
|
+
body: metadata,
|
1045
2231
|
...this.extraProps
|
1046
2232
|
});
|
1047
2233
|
}
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
2234
|
+
getDatabaseGithubSettings({
|
2235
|
+
workspace,
|
2236
|
+
database
|
2237
|
+
}) {
|
2238
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2239
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1053
2240
|
...this.extraProps
|
1054
2241
|
});
|
1055
2242
|
}
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
2243
|
+
updateDatabaseGithubSettings({
|
2244
|
+
workspace,
|
2245
|
+
database,
|
2246
|
+
settings
|
2247
|
+
}) {
|
2248
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2249
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2250
|
+
body: settings,
|
1060
2251
|
...this.extraProps
|
1061
2252
|
});
|
1062
2253
|
}
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
2254
|
+
deleteDatabaseGithubSettings({
|
2255
|
+
workspace,
|
2256
|
+
database
|
2257
|
+
}) {
|
2258
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2259
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1067
2260
|
...this.extraProps
|
1068
2261
|
});
|
1069
2262
|
}
|
1070
|
-
|
1071
|
-
return operationsByTag.
|
1072
|
-
pathParams: {
|
1073
|
-
body: query,
|
2263
|
+
listRegions({ workspace }) {
|
2264
|
+
return operationsByTag.databases.listRegions({
|
2265
|
+
pathParams: { workspaceId: workspace },
|
1074
2266
|
...this.extraProps
|
1075
2267
|
});
|
1076
2268
|
}
|
1077
2269
|
}
|
1078
2270
|
|
1079
2271
|
class XataApiPlugin {
|
1080
|
-
|
1081
|
-
|
1082
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2272
|
+
build(options) {
|
2273
|
+
return new XataApiClient(options);
|
1083
2274
|
}
|
1084
2275
|
}
|
1085
2276
|
|
1086
2277
|
class XataPlugin {
|
1087
2278
|
}
|
1088
2279
|
|
2280
|
+
function cleanFilter(filter) {
|
2281
|
+
if (!filter)
|
2282
|
+
return void 0;
|
2283
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2284
|
+
return values.length > 0 ? filter : void 0;
|
2285
|
+
}
|
2286
|
+
|
1089
2287
|
var __accessCheck$6 = (obj, member, msg) => {
|
1090
2288
|
if (!member.has(obj))
|
1091
2289
|
throw TypeError("Cannot " + msg);
|
@@ -1118,11 +2316,11 @@ class Page {
|
|
1118
2316
|
async previousPage(size, offset) {
|
1119
2317
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1120
2318
|
}
|
1121
|
-
async
|
1122
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
2319
|
+
async startPage(size, offset) {
|
2320
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1123
2321
|
}
|
1124
|
-
async
|
1125
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
2322
|
+
async endPage(size, offset) {
|
2323
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1126
2324
|
}
|
1127
2325
|
hasNextPage() {
|
1128
2326
|
return this.meta.page.more;
|
@@ -1134,7 +2332,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
|
|
1134
2332
|
const PAGINATION_MAX_OFFSET = 800;
|
1135
2333
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1136
2334
|
function isCursorPaginationOptions(options) {
|
1137
|
-
return isDefined(options) && (isDefined(options.
|
2335
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1138
2336
|
}
|
1139
2337
|
const _RecordArray = class extends Array {
|
1140
2338
|
constructor(...args) {
|
@@ -1155,6 +2353,12 @@ const _RecordArray = class extends Array {
|
|
1155
2353
|
toArray() {
|
1156
2354
|
return new Array(...this);
|
1157
2355
|
}
|
2356
|
+
toSerializable() {
|
2357
|
+
return JSON.parse(this.toString());
|
2358
|
+
}
|
2359
|
+
toString() {
|
2360
|
+
return JSON.stringify(this.toArray());
|
2361
|
+
}
|
1158
2362
|
map(callbackfn, thisArg) {
|
1159
2363
|
return this.toArray().map(callbackfn, thisArg);
|
1160
2364
|
}
|
@@ -1166,12 +2370,12 @@ const _RecordArray = class extends Array {
|
|
1166
2370
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1167
2371
|
return new _RecordArray(newPage);
|
1168
2372
|
}
|
1169
|
-
async
|
1170
|
-
const newPage = await __privateGet$6(this, _page).
|
2373
|
+
async startPage(size, offset) {
|
2374
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1171
2375
|
return new _RecordArray(newPage);
|
1172
2376
|
}
|
1173
|
-
async
|
1174
|
-
const newPage = await __privateGet$6(this, _page).
|
2377
|
+
async endPage(size, offset) {
|
2378
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1175
2379
|
return new _RecordArray(newPage);
|
1176
2380
|
}
|
1177
2381
|
hasNextPage() {
|
@@ -1199,9 +2403,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1199
2403
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1200
2404
|
return value;
|
1201
2405
|
};
|
1202
|
-
var
|
2406
|
+
var __privateMethod$3 = (obj, member, method) => {
|
2407
|
+
__accessCheck$5(obj, member, "access private method");
|
2408
|
+
return method;
|
2409
|
+
};
|
2410
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1203
2411
|
const _Query = class {
|
1204
2412
|
constructor(repository, table, data, rawParent) {
|
2413
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1205
2414
|
__privateAdd$5(this, _table$1, void 0);
|
1206
2415
|
__privateAdd$5(this, _repository, void 0);
|
1207
2416
|
__privateAdd$5(this, _data, { filter: {} });
|
@@ -1220,9 +2429,11 @@ const _Query = class {
|
|
1220
2429
|
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1221
2430
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1222
2431
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1223
|
-
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns
|
2432
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
2433
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1224
2434
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1225
2435
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2436
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1226
2437
|
this.any = this.any.bind(this);
|
1227
2438
|
this.all = this.all.bind(this);
|
1228
2439
|
this.not = this.not.bind(this);
|
@@ -1258,11 +2469,14 @@ const _Query = class {
|
|
1258
2469
|
}
|
1259
2470
|
filter(a, b) {
|
1260
2471
|
if (arguments.length === 1) {
|
1261
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
2472
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
2473
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
2474
|
+
}));
|
1262
2475
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1263
2476
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1264
2477
|
} else {
|
1265
|
-
const
|
2478
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
2479
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1266
2480
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1267
2481
|
}
|
1268
2482
|
}
|
@@ -1300,11 +2514,20 @@ const _Query = class {
|
|
1300
2514
|
}
|
1301
2515
|
}
|
1302
2516
|
async getMany(options = {}) {
|
1303
|
-
const
|
2517
|
+
const { pagination = {}, ...rest } = options;
|
2518
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
2519
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
2520
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
2521
|
+
const results = [...page.records];
|
2522
|
+
while (page.hasNextPage() && results.length < size) {
|
2523
|
+
page = await page.nextPage();
|
2524
|
+
results.push(...page.records);
|
2525
|
+
}
|
1304
2526
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1305
2527
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1306
2528
|
}
|
1307
|
-
|
2529
|
+
const array = new RecordArray(page, results.slice(0, size));
|
2530
|
+
return array;
|
1308
2531
|
}
|
1309
2532
|
async getAll(options = {}) {
|
1310
2533
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1318,19 +2541,35 @@ const _Query = class {
|
|
1318
2541
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1319
2542
|
return records[0] ?? null;
|
1320
2543
|
}
|
2544
|
+
async getFirstOrThrow(options = {}) {
|
2545
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
2546
|
+
if (records[0] === void 0)
|
2547
|
+
throw new Error("No results found.");
|
2548
|
+
return records[0];
|
2549
|
+
}
|
2550
|
+
async summarize(params = {}) {
|
2551
|
+
const { summaries, summariesFilter, ...options } = params;
|
2552
|
+
const query = new _Query(
|
2553
|
+
__privateGet$5(this, _repository),
|
2554
|
+
__privateGet$5(this, _table$1),
|
2555
|
+
options,
|
2556
|
+
__privateGet$5(this, _data)
|
2557
|
+
);
|
2558
|
+
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2559
|
+
}
|
1321
2560
|
cache(ttl) {
|
1322
2561
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1323
2562
|
}
|
1324
2563
|
nextPage(size, offset) {
|
1325
|
-
return this.
|
2564
|
+
return this.startPage(size, offset);
|
1326
2565
|
}
|
1327
2566
|
previousPage(size, offset) {
|
1328
|
-
return this.
|
2567
|
+
return this.startPage(size, offset);
|
1329
2568
|
}
|
1330
|
-
|
2569
|
+
startPage(size, offset) {
|
1331
2570
|
return this.getPaginated({ pagination: { size, offset } });
|
1332
2571
|
}
|
1333
|
-
|
2572
|
+
endPage(size, offset) {
|
1334
2573
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
1335
2574
|
}
|
1336
2575
|
hasNextPage() {
|
@@ -1341,9 +2580,20 @@ let Query = _Query;
|
|
1341
2580
|
_table$1 = new WeakMap();
|
1342
2581
|
_repository = new WeakMap();
|
1343
2582
|
_data = new WeakMap();
|
2583
|
+
_cleanFilterConstraint = new WeakSet();
|
2584
|
+
cleanFilterConstraint_fn = function(column, value) {
|
2585
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
2586
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
2587
|
+
return { $includes: value };
|
2588
|
+
}
|
2589
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
2590
|
+
return value.id;
|
2591
|
+
}
|
2592
|
+
return value;
|
2593
|
+
};
|
1344
2594
|
function cleanParent(data, parent) {
|
1345
2595
|
if (isCursorPaginationOptions(data.pagination)) {
|
1346
|
-
return { ...parent,
|
2596
|
+
return { ...parent, sort: void 0, filter: void 0 };
|
1347
2597
|
}
|
1348
2598
|
return parent;
|
1349
2599
|
}
|
@@ -1402,18 +2652,25 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1402
2652
|
__accessCheck$4(obj, member, "access private method");
|
1403
2653
|
return method;
|
1404
2654
|
};
|
1405
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2655
|
+
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;
|
2656
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
1406
2657
|
class Repository extends Query {
|
1407
2658
|
}
|
1408
2659
|
class RestRepository extends Query {
|
1409
2660
|
constructor(options) {
|
1410
|
-
super(
|
2661
|
+
super(
|
2662
|
+
null,
|
2663
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
2664
|
+
{}
|
2665
|
+
);
|
1411
2666
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1412
2667
|
__privateAdd$4(this, _insertRecordWithId);
|
1413
|
-
__privateAdd$4(this,
|
2668
|
+
__privateAdd$4(this, _insertRecords);
|
1414
2669
|
__privateAdd$4(this, _updateRecordWithID);
|
2670
|
+
__privateAdd$4(this, _updateRecords);
|
1415
2671
|
__privateAdd$4(this, _upsertRecordWithID);
|
1416
2672
|
__privateAdd$4(this, _deleteRecord);
|
2673
|
+
__privateAdd$4(this, _deleteRecords);
|
1417
2674
|
__privateAdd$4(this, _setCacheQuery);
|
1418
2675
|
__privateAdd$4(this, _getCacheQuery);
|
1419
2676
|
__privateAdd$4(this, _getSchemaTables$1);
|
@@ -1424,38 +2681,42 @@ class RestRepository extends Query {
|
|
1424
2681
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1425
2682
|
__privateAdd$4(this, _trace, void 0);
|
1426
2683
|
__privateSet$4(this, _table, options.table);
|
1427
|
-
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1428
2684
|
__privateSet$4(this, _db, options.db);
|
1429
2685
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1430
2686
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2687
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
1431
2688
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1432
2689
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1433
2690
|
return trace(name, fn, {
|
1434
2691
|
...options2,
|
1435
2692
|
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
2693
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1436
2694
|
[TraceAttributes.VERSION]: VERSION
|
1437
2695
|
});
|
1438
2696
|
});
|
1439
2697
|
}
|
1440
|
-
async create(a, b, c) {
|
2698
|
+
async create(a, b, c, d) {
|
1441
2699
|
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
2700
|
+
const ifVersion = parseIfVersion(b, c, d);
|
1442
2701
|
if (Array.isArray(a)) {
|
1443
2702
|
if (a.length === 0)
|
1444
2703
|
return [];
|
1445
|
-
const
|
1446
|
-
|
2704
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2705
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2706
|
+
const result = await this.read(ids, columns);
|
2707
|
+
return result;
|
1447
2708
|
}
|
1448
2709
|
if (isString(a) && isObject(b)) {
|
1449
2710
|
if (a === "")
|
1450
2711
|
throw new Error("The id can't be empty");
|
1451
2712
|
const columns = isStringArray(c) ? c : void 0;
|
1452
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
2713
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
1453
2714
|
}
|
1454
2715
|
if (isObject(a) && isString(a.id)) {
|
1455
2716
|
if (a.id === "")
|
1456
2717
|
throw new Error("The id can't be empty");
|
1457
2718
|
const columns = isStringArray(b) ? b : void 0;
|
1458
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
2719
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
1459
2720
|
}
|
1460
2721
|
if (isObject(a)) {
|
1461
2722
|
const columns = isStringArray(b) ? b : void 0;
|
@@ -1470,30 +2731,30 @@ class RestRepository extends Query {
|
|
1470
2731
|
if (Array.isArray(a)) {
|
1471
2732
|
if (a.length === 0)
|
1472
2733
|
return [];
|
1473
|
-
const ids = a.map((item) =>
|
1474
|
-
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
2734
|
+
const ids = a.map((item) => extractId(item));
|
2735
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1475
2736
|
const dictionary = finalObjects.reduce((acc, object) => {
|
1476
2737
|
acc[object.id] = object;
|
1477
2738
|
return acc;
|
1478
2739
|
}, {});
|
1479
|
-
return ids.map((id2) => dictionary[id2] ?? null);
|
2740
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1480
2741
|
}
|
1481
|
-
const id =
|
1482
|
-
if (
|
1483
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2742
|
+
const id = extractId(a);
|
2743
|
+
if (id) {
|
1484
2744
|
try {
|
1485
2745
|
const response = await getRecord({
|
1486
2746
|
pathParams: {
|
1487
2747
|
workspace: "{workspaceId}",
|
1488
2748
|
dbBranchName: "{dbBranch}",
|
2749
|
+
region: "{region}",
|
1489
2750
|
tableName: __privateGet$4(this, _table),
|
1490
2751
|
recordId: id
|
1491
2752
|
},
|
1492
2753
|
queryParams: { columns },
|
1493
|
-
...
|
2754
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1494
2755
|
});
|
1495
2756
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1496
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2757
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1497
2758
|
} catch (e) {
|
1498
2759
|
if (isObject(e) && e.status === 404) {
|
1499
2760
|
return null;
|
@@ -1504,89 +2765,228 @@ class RestRepository extends Query {
|
|
1504
2765
|
return null;
|
1505
2766
|
});
|
1506
2767
|
}
|
1507
|
-
async
|
2768
|
+
async readOrThrow(a, b) {
|
2769
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
2770
|
+
const result = await this.read(a, b);
|
2771
|
+
if (Array.isArray(result)) {
|
2772
|
+
const missingIds = compact(
|
2773
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2774
|
+
);
|
2775
|
+
if (missingIds.length > 0) {
|
2776
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2777
|
+
}
|
2778
|
+
return result;
|
2779
|
+
}
|
2780
|
+
if (result === null) {
|
2781
|
+
const id = extractId(a) ?? "unknown";
|
2782
|
+
throw new Error(`Record with id ${id} not found`);
|
2783
|
+
}
|
2784
|
+
return result;
|
2785
|
+
});
|
2786
|
+
}
|
2787
|
+
async update(a, b, c, d) {
|
1508
2788
|
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
2789
|
+
const ifVersion = parseIfVersion(b, c, d);
|
1509
2790
|
if (Array.isArray(a)) {
|
1510
2791
|
if (a.length === 0)
|
1511
2792
|
return [];
|
1512
|
-
|
1513
|
-
|
2793
|
+
const existing = await this.read(a, ["id"]);
|
2794
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
2795
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2796
|
+
ifVersion,
|
2797
|
+
upsert: false
|
2798
|
+
});
|
2799
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2800
|
+
const result = await this.read(a, columns);
|
2801
|
+
return result;
|
2802
|
+
}
|
2803
|
+
try {
|
2804
|
+
if (isString(a) && isObject(b)) {
|
2805
|
+
const columns = isStringArray(c) ? c : void 0;
|
2806
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2807
|
+
}
|
2808
|
+
if (isObject(a) && isString(a.id)) {
|
2809
|
+
const columns = isStringArray(b) ? b : void 0;
|
2810
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2811
|
+
}
|
2812
|
+
} catch (error) {
|
2813
|
+
if (error.status === 422)
|
2814
|
+
return null;
|
2815
|
+
throw error;
|
2816
|
+
}
|
2817
|
+
throw new Error("Invalid arguments for update method");
|
2818
|
+
});
|
2819
|
+
}
|
2820
|
+
async updateOrThrow(a, b, c, d) {
|
2821
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
2822
|
+
const result = await this.update(a, b, c, d);
|
2823
|
+
if (Array.isArray(result)) {
|
2824
|
+
const missingIds = compact(
|
2825
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2826
|
+
);
|
2827
|
+
if (missingIds.length > 0) {
|
2828
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1514
2829
|
}
|
2830
|
+
return result;
|
2831
|
+
}
|
2832
|
+
if (result === null) {
|
2833
|
+
const id = extractId(a) ?? "unknown";
|
2834
|
+
throw new Error(`Record with id ${id} not found`);
|
2835
|
+
}
|
2836
|
+
return result;
|
2837
|
+
});
|
2838
|
+
}
|
2839
|
+
async createOrUpdate(a, b, c, d) {
|
2840
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
2841
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2842
|
+
if (Array.isArray(a)) {
|
2843
|
+
if (a.length === 0)
|
2844
|
+
return [];
|
2845
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
2846
|
+
ifVersion,
|
2847
|
+
upsert: true
|
2848
|
+
});
|
1515
2849
|
const columns = isStringArray(b) ? b : ["*"];
|
1516
|
-
|
2850
|
+
const result = await this.read(a, columns);
|
2851
|
+
return result;
|
1517
2852
|
}
|
1518
2853
|
if (isString(a) && isObject(b)) {
|
1519
2854
|
const columns = isStringArray(c) ? c : void 0;
|
1520
|
-
return __privateMethod$2(this,
|
2855
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
1521
2856
|
}
|
1522
2857
|
if (isObject(a) && isString(a.id)) {
|
1523
|
-
const columns = isStringArray(
|
1524
|
-
return __privateMethod$2(this,
|
2858
|
+
const columns = isStringArray(c) ? c : void 0;
|
2859
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
1525
2860
|
}
|
1526
|
-
throw new Error("Invalid arguments for
|
2861
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
1527
2862
|
});
|
1528
2863
|
}
|
1529
|
-
async
|
1530
|
-
return __privateGet$4(this, _trace).call(this, "
|
2864
|
+
async createOrReplace(a, b, c, d) {
|
2865
|
+
return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
|
2866
|
+
const ifVersion = parseIfVersion(b, c, d);
|
1531
2867
|
if (Array.isArray(a)) {
|
1532
2868
|
if (a.length === 0)
|
1533
2869
|
return [];
|
1534
|
-
|
1535
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
1536
|
-
}
|
2870
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
1537
2871
|
const columns = isStringArray(b) ? b : ["*"];
|
1538
|
-
|
2872
|
+
const result = await this.read(ids, columns);
|
2873
|
+
return result;
|
1539
2874
|
}
|
1540
2875
|
if (isString(a) && isObject(b)) {
|
1541
2876
|
const columns = isStringArray(c) ? c : void 0;
|
1542
|
-
return __privateMethod$2(this,
|
2877
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
1543
2878
|
}
|
1544
2879
|
if (isObject(a) && isString(a.id)) {
|
1545
2880
|
const columns = isStringArray(c) ? c : void 0;
|
1546
|
-
return __privateMethod$2(this,
|
2881
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
1547
2882
|
}
|
1548
|
-
throw new Error("Invalid arguments for
|
2883
|
+
throw new Error("Invalid arguments for createOrReplace method");
|
1549
2884
|
});
|
1550
2885
|
}
|
1551
|
-
async delete(a) {
|
2886
|
+
async delete(a, b) {
|
1552
2887
|
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1553
2888
|
if (Array.isArray(a)) {
|
1554
2889
|
if (a.length === 0)
|
1555
|
-
return;
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
2890
|
+
return [];
|
2891
|
+
const ids = a.map((o) => {
|
2892
|
+
if (isString(o))
|
2893
|
+
return o;
|
2894
|
+
if (isString(o.id))
|
2895
|
+
return o.id;
|
2896
|
+
throw new Error("Invalid arguments for delete method");
|
2897
|
+
});
|
2898
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2899
|
+
const result = await this.read(a, columns);
|
2900
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2901
|
+
return result;
|
1561
2902
|
}
|
1562
2903
|
if (isString(a)) {
|
1563
|
-
|
1564
|
-
return;
|
2904
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1565
2905
|
}
|
1566
2906
|
if (isObject(a) && isString(a.id)) {
|
1567
|
-
|
1568
|
-
return;
|
2907
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1569
2908
|
}
|
1570
2909
|
throw new Error("Invalid arguments for delete method");
|
1571
2910
|
});
|
1572
2911
|
}
|
2912
|
+
async deleteOrThrow(a, b) {
|
2913
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
2914
|
+
const result = await this.delete(a, b);
|
2915
|
+
if (Array.isArray(result)) {
|
2916
|
+
const missingIds = compact(
|
2917
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2918
|
+
);
|
2919
|
+
if (missingIds.length > 0) {
|
2920
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2921
|
+
}
|
2922
|
+
return result;
|
2923
|
+
} else if (result === null) {
|
2924
|
+
const id = extractId(a) ?? "unknown";
|
2925
|
+
throw new Error(`Record with id ${id} not found`);
|
2926
|
+
}
|
2927
|
+
return result;
|
2928
|
+
});
|
2929
|
+
}
|
1573
2930
|
async search(query, options = {}) {
|
1574
2931
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1575
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1576
2932
|
const { records } = await searchTable({
|
1577
|
-
pathParams: {
|
2933
|
+
pathParams: {
|
2934
|
+
workspace: "{workspaceId}",
|
2935
|
+
dbBranchName: "{dbBranch}",
|
2936
|
+
region: "{region}",
|
2937
|
+
tableName: __privateGet$4(this, _table)
|
2938
|
+
},
|
1578
2939
|
body: {
|
1579
2940
|
query,
|
1580
2941
|
fuzziness: options.fuzziness,
|
1581
2942
|
prefix: options.prefix,
|
1582
2943
|
highlight: options.highlight,
|
1583
2944
|
filter: options.filter,
|
1584
|
-
boosters: options.boosters
|
2945
|
+
boosters: options.boosters,
|
2946
|
+
page: options.page,
|
2947
|
+
target: options.target
|
2948
|
+
},
|
2949
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2950
|
+
});
|
2951
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2952
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
2953
|
+
});
|
2954
|
+
}
|
2955
|
+
async vectorSearch(column, query, options) {
|
2956
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
2957
|
+
const { records } = await vectorSearchTable({
|
2958
|
+
pathParams: {
|
2959
|
+
workspace: "{workspaceId}",
|
2960
|
+
dbBranchName: "{dbBranch}",
|
2961
|
+
region: "{region}",
|
2962
|
+
tableName: __privateGet$4(this, _table)
|
2963
|
+
},
|
2964
|
+
body: {
|
2965
|
+
column,
|
2966
|
+
queryVector: query,
|
2967
|
+
similarityFunction: options?.similarityFunction,
|
2968
|
+
size: options?.size,
|
2969
|
+
filter: options?.filter
|
1585
2970
|
},
|
1586
|
-
...
|
2971
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1587
2972
|
});
|
1588
2973
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1589
|
-
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
2974
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
2975
|
+
});
|
2976
|
+
}
|
2977
|
+
async aggregate(aggs, filter) {
|
2978
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2979
|
+
const result = await aggregateTable({
|
2980
|
+
pathParams: {
|
2981
|
+
workspace: "{workspaceId}",
|
2982
|
+
dbBranchName: "{dbBranch}",
|
2983
|
+
region: "{region}",
|
2984
|
+
tableName: __privateGet$4(this, _table)
|
2985
|
+
},
|
2986
|
+
body: { aggs, filter },
|
2987
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2988
|
+
});
|
2989
|
+
return result;
|
1590
2990
|
});
|
1591
2991
|
}
|
1592
2992
|
async query(query) {
|
@@ -1595,24 +2995,83 @@ class RestRepository extends Query {
|
|
1595
2995
|
if (cacheQuery)
|
1596
2996
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1597
2997
|
const data = query.getQueryOptions();
|
1598
|
-
const body = {
|
1599
|
-
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1600
|
-
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1601
|
-
page: data.pagination,
|
1602
|
-
columns: data.columns
|
1603
|
-
};
|
1604
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1605
2998
|
const { meta, records: objects } = await queryTable({
|
1606
|
-
pathParams: {
|
1607
|
-
|
1608
|
-
|
2999
|
+
pathParams: {
|
3000
|
+
workspace: "{workspaceId}",
|
3001
|
+
dbBranchName: "{dbBranch}",
|
3002
|
+
region: "{region}",
|
3003
|
+
tableName: __privateGet$4(this, _table)
|
3004
|
+
},
|
3005
|
+
body: {
|
3006
|
+
filter: cleanFilter(data.filter),
|
3007
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
3008
|
+
page: data.pagination,
|
3009
|
+
columns: data.columns ?? ["*"],
|
3010
|
+
consistency: data.consistency
|
3011
|
+
},
|
3012
|
+
fetchOptions: data.fetchOptions,
|
3013
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1609
3014
|
});
|
1610
3015
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1611
|
-
const records = objects.map(
|
3016
|
+
const records = objects.map(
|
3017
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
3018
|
+
);
|
1612
3019
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1613
3020
|
return new Page(query, meta, records);
|
1614
3021
|
});
|
1615
3022
|
}
|
3023
|
+
async summarizeTable(query, summaries, summariesFilter) {
|
3024
|
+
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
3025
|
+
const data = query.getQueryOptions();
|
3026
|
+
const result = await summarizeTable({
|
3027
|
+
pathParams: {
|
3028
|
+
workspace: "{workspaceId}",
|
3029
|
+
dbBranchName: "{dbBranch}",
|
3030
|
+
region: "{region}",
|
3031
|
+
tableName: __privateGet$4(this, _table)
|
3032
|
+
},
|
3033
|
+
body: {
|
3034
|
+
filter: cleanFilter(data.filter),
|
3035
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
3036
|
+
columns: data.columns,
|
3037
|
+
consistency: data.consistency,
|
3038
|
+
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
3039
|
+
summaries,
|
3040
|
+
summariesFilter
|
3041
|
+
},
|
3042
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3043
|
+
});
|
3044
|
+
return result;
|
3045
|
+
});
|
3046
|
+
}
|
3047
|
+
ask(question, options) {
|
3048
|
+
const params = {
|
3049
|
+
pathParams: {
|
3050
|
+
workspace: "{workspaceId}",
|
3051
|
+
dbBranchName: "{dbBranch}",
|
3052
|
+
region: "{region}",
|
3053
|
+
tableName: __privateGet$4(this, _table)
|
3054
|
+
},
|
3055
|
+
body: {
|
3056
|
+
question,
|
3057
|
+
...options
|
3058
|
+
},
|
3059
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3060
|
+
};
|
3061
|
+
if (options?.onMessage) {
|
3062
|
+
fetchSSERequest({
|
3063
|
+
endpoint: "dataPlane",
|
3064
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3065
|
+
method: "POST",
|
3066
|
+
onMessage: (message) => {
|
3067
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3068
|
+
},
|
3069
|
+
...params
|
3070
|
+
});
|
3071
|
+
} else {
|
3072
|
+
return askTable(params);
|
3073
|
+
}
|
3074
|
+
}
|
1616
3075
|
}
|
1617
3076
|
_table = new WeakMap();
|
1618
3077
|
_getFetchProps = new WeakMap();
|
@@ -1622,99 +3081,192 @@ _schemaTables$2 = new WeakMap();
|
|
1622
3081
|
_trace = new WeakMap();
|
1623
3082
|
_insertRecordWithoutId = new WeakSet();
|
1624
3083
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1625
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1626
3084
|
const record = transformObjectLinks(object);
|
1627
3085
|
const response = await insertRecord({
|
1628
3086
|
pathParams: {
|
1629
3087
|
workspace: "{workspaceId}",
|
1630
3088
|
dbBranchName: "{dbBranch}",
|
3089
|
+
region: "{region}",
|
1631
3090
|
tableName: __privateGet$4(this, _table)
|
1632
3091
|
},
|
1633
3092
|
queryParams: { columns },
|
1634
3093
|
body: record,
|
1635
|
-
...
|
3094
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1636
3095
|
});
|
1637
3096
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1638
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
3097
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1639
3098
|
};
|
1640
3099
|
_insertRecordWithId = new WeakSet();
|
1641
|
-
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1642
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
3100
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
1643
3101
|
const record = transformObjectLinks(object);
|
1644
3102
|
const response = await insertRecordWithID({
|
1645
3103
|
pathParams: {
|
1646
3104
|
workspace: "{workspaceId}",
|
1647
3105
|
dbBranchName: "{dbBranch}",
|
3106
|
+
region: "{region}",
|
1648
3107
|
tableName: __privateGet$4(this, _table),
|
1649
3108
|
recordId
|
1650
3109
|
},
|
1651
3110
|
body: record,
|
1652
|
-
queryParams: { createOnly
|
1653
|
-
...
|
3111
|
+
queryParams: { createOnly, columns, ifVersion },
|
3112
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1654
3113
|
});
|
1655
3114
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1656
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1657
|
-
};
|
1658
|
-
|
1659
|
-
|
1660
|
-
const
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
3115
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
3116
|
+
};
|
3117
|
+
_insertRecords = new WeakSet();
|
3118
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3119
|
+
const chunkedOperations = chunk(
|
3120
|
+
objects.map((object) => ({
|
3121
|
+
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
3122
|
+
})),
|
3123
|
+
BULK_OPERATION_MAX_SIZE
|
3124
|
+
);
|
3125
|
+
const ids = [];
|
3126
|
+
for (const operations of chunkedOperations) {
|
3127
|
+
const { results } = await branchTransaction({
|
3128
|
+
pathParams: {
|
3129
|
+
workspace: "{workspaceId}",
|
3130
|
+
dbBranchName: "{dbBranch}",
|
3131
|
+
region: "{region}"
|
3132
|
+
},
|
3133
|
+
body: { operations },
|
3134
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3135
|
+
});
|
3136
|
+
for (const result of results) {
|
3137
|
+
if (result.operation === "insert") {
|
3138
|
+
ids.push(result.id);
|
3139
|
+
} else {
|
3140
|
+
ids.push(null);
|
3141
|
+
}
|
3142
|
+
}
|
1670
3143
|
}
|
1671
|
-
|
1672
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
3144
|
+
return ids;
|
1673
3145
|
};
|
1674
3146
|
_updateRecordWithID = new WeakSet();
|
1675
|
-
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1676
|
-
const
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
3147
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
3148
|
+
const { id: _id, ...record } = transformObjectLinks(object);
|
3149
|
+
try {
|
3150
|
+
const response = await updateRecordWithID({
|
3151
|
+
pathParams: {
|
3152
|
+
workspace: "{workspaceId}",
|
3153
|
+
dbBranchName: "{dbBranch}",
|
3154
|
+
region: "{region}",
|
3155
|
+
tableName: __privateGet$4(this, _table),
|
3156
|
+
recordId
|
3157
|
+
},
|
3158
|
+
queryParams: { columns, ifVersion },
|
3159
|
+
body: record,
|
3160
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3161
|
+
});
|
3162
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3163
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
3164
|
+
} catch (e) {
|
3165
|
+
if (isObject(e) && e.status === 404) {
|
3166
|
+
return null;
|
3167
|
+
}
|
3168
|
+
throw e;
|
3169
|
+
}
|
3170
|
+
};
|
3171
|
+
_updateRecords = new WeakSet();
|
3172
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3173
|
+
const chunkedOperations = chunk(
|
3174
|
+
objects.map(({ id, ...object }) => ({
|
3175
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
3176
|
+
})),
|
3177
|
+
BULK_OPERATION_MAX_SIZE
|
3178
|
+
);
|
3179
|
+
const ids = [];
|
3180
|
+
for (const operations of chunkedOperations) {
|
3181
|
+
const { results } = await branchTransaction({
|
3182
|
+
pathParams: {
|
3183
|
+
workspace: "{workspaceId}",
|
3184
|
+
dbBranchName: "{dbBranch}",
|
3185
|
+
region: "{region}"
|
3186
|
+
},
|
3187
|
+
body: { operations },
|
3188
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3189
|
+
});
|
3190
|
+
for (const result of results) {
|
3191
|
+
if (result.operation === "update") {
|
3192
|
+
ids.push(result.id);
|
3193
|
+
} else {
|
3194
|
+
ids.push(null);
|
3195
|
+
}
|
3196
|
+
}
|
3197
|
+
}
|
3198
|
+
return ids;
|
1686
3199
|
};
|
1687
3200
|
_upsertRecordWithID = new WeakSet();
|
1688
|
-
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1689
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
3201
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
1690
3202
|
const response = await upsertRecordWithID({
|
1691
|
-
pathParams: {
|
1692
|
-
|
3203
|
+
pathParams: {
|
3204
|
+
workspace: "{workspaceId}",
|
3205
|
+
dbBranchName: "{dbBranch}",
|
3206
|
+
region: "{region}",
|
3207
|
+
tableName: __privateGet$4(this, _table),
|
3208
|
+
recordId
|
3209
|
+
},
|
3210
|
+
queryParams: { columns, ifVersion },
|
1693
3211
|
body: object,
|
1694
|
-
...
|
3212
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1695
3213
|
});
|
1696
3214
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1697
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
3215
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1698
3216
|
};
|
1699
3217
|
_deleteRecord = new WeakSet();
|
1700
|
-
deleteRecord_fn = async function(recordId) {
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
3218
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
3219
|
+
try {
|
3220
|
+
const response = await deleteRecord({
|
3221
|
+
pathParams: {
|
3222
|
+
workspace: "{workspaceId}",
|
3223
|
+
dbBranchName: "{dbBranch}",
|
3224
|
+
region: "{region}",
|
3225
|
+
tableName: __privateGet$4(this, _table),
|
3226
|
+
recordId
|
3227
|
+
},
|
3228
|
+
queryParams: { columns },
|
3229
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3230
|
+
});
|
3231
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3232
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
3233
|
+
} catch (e) {
|
3234
|
+
if (isObject(e) && e.status === 404) {
|
3235
|
+
return null;
|
3236
|
+
}
|
3237
|
+
throw e;
|
3238
|
+
}
|
3239
|
+
};
|
3240
|
+
_deleteRecords = new WeakSet();
|
3241
|
+
deleteRecords_fn = async function(recordIds) {
|
3242
|
+
const chunkedOperations = chunk(
|
3243
|
+
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3244
|
+
BULK_OPERATION_MAX_SIZE
|
3245
|
+
);
|
3246
|
+
for (const operations of chunkedOperations) {
|
3247
|
+
await branchTransaction({
|
3248
|
+
pathParams: {
|
3249
|
+
workspace: "{workspaceId}",
|
3250
|
+
dbBranchName: "{dbBranch}",
|
3251
|
+
region: "{region}"
|
3252
|
+
},
|
3253
|
+
body: { operations },
|
3254
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3255
|
+
});
|
3256
|
+
}
|
1706
3257
|
};
|
1707
3258
|
_setCacheQuery = new WeakSet();
|
1708
3259
|
setCacheQuery_fn = async function(query, meta, records) {
|
1709
|
-
await __privateGet$4(this, _cache)
|
3260
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
|
1710
3261
|
};
|
1711
3262
|
_getCacheQuery = new WeakSet();
|
1712
3263
|
getCacheQuery_fn = async function(query) {
|
1713
3264
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
1714
|
-
const result = await __privateGet$4(this, _cache)
|
3265
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
1715
3266
|
if (!result)
|
1716
3267
|
return null;
|
1717
|
-
const
|
3268
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3269
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
1718
3270
|
if (ttl < 0)
|
1719
3271
|
return null;
|
1720
3272
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -1724,10 +3276,9 @@ _getSchemaTables$1 = new WeakSet();
|
|
1724
3276
|
getSchemaTables_fn$1 = async function() {
|
1725
3277
|
if (__privateGet$4(this, _schemaTables$2))
|
1726
3278
|
return __privateGet$4(this, _schemaTables$2);
|
1727
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1728
3279
|
const { schema } = await getBranchDetails({
|
1729
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1730
|
-
...
|
3280
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3281
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1731
3282
|
});
|
1732
3283
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1733
3284
|
return schema.tables;
|
@@ -1739,22 +3290,24 @@ const transformObjectLinks = (object) => {
|
|
1739
3290
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1740
3291
|
}, {});
|
1741
3292
|
};
|
1742
|
-
const initObject = (db, schemaTables, table, object) => {
|
1743
|
-
const
|
3293
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
3294
|
+
const data = {};
|
1744
3295
|
const { xata, ...rest } = object ?? {};
|
1745
|
-
Object.assign(
|
3296
|
+
Object.assign(data, rest);
|
1746
3297
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1747
3298
|
if (!columns)
|
1748
3299
|
console.error(`Table ${table} not found in schema`);
|
1749
3300
|
for (const column of columns ?? []) {
|
1750
|
-
|
3301
|
+
if (!isValidColumn(selectedColumns, column))
|
3302
|
+
continue;
|
3303
|
+
const value = data[column.name];
|
1751
3304
|
switch (column.type) {
|
1752
3305
|
case "datetime": {
|
1753
|
-
const date = value !== void 0 ? new Date(value) :
|
1754
|
-
if (date && isNaN(date.getTime())) {
|
3306
|
+
const date = value !== void 0 ? new Date(value) : null;
|
3307
|
+
if (date !== null && isNaN(date.getTime())) {
|
1755
3308
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1756
|
-
} else
|
1757
|
-
|
3309
|
+
} else {
|
3310
|
+
data[column.name] = date;
|
1758
3311
|
}
|
1759
3312
|
break;
|
1760
3313
|
}
|
@@ -1763,32 +3316,85 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1763
3316
|
if (!linkTable) {
|
1764
3317
|
console.error(`Failed to parse link for field ${column.name}`);
|
1765
3318
|
} else if (isObject(value)) {
|
1766
|
-
|
3319
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
3320
|
+
if (item === column.name) {
|
3321
|
+
return [...acc, "*"];
|
3322
|
+
}
|
3323
|
+
if (item.startsWith(`${column.name}.`)) {
|
3324
|
+
const [, ...path] = item.split(".");
|
3325
|
+
return [...acc, path.join(".")];
|
3326
|
+
}
|
3327
|
+
return acc;
|
3328
|
+
}, []);
|
3329
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
3330
|
+
} else {
|
3331
|
+
data[column.name] = null;
|
1767
3332
|
}
|
1768
3333
|
break;
|
1769
3334
|
}
|
3335
|
+
default:
|
3336
|
+
data[column.name] = value ?? null;
|
3337
|
+
if (column.notNull === true && value === null) {
|
3338
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
3339
|
+
}
|
3340
|
+
break;
|
1770
3341
|
}
|
1771
3342
|
}
|
1772
|
-
|
1773
|
-
|
3343
|
+
const record = { ...data };
|
3344
|
+
record.read = function(columns2) {
|
3345
|
+
return db[table].read(record["id"], columns2);
|
1774
3346
|
};
|
1775
|
-
|
1776
|
-
|
3347
|
+
record.update = function(data2, b, c) {
|
3348
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
3349
|
+
const ifVersion = parseIfVersion(b, c);
|
3350
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
1777
3351
|
};
|
1778
|
-
|
1779
|
-
|
3352
|
+
record.replace = function(data2, b, c) {
|
3353
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
3354
|
+
const ifVersion = parseIfVersion(b, c);
|
3355
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
1780
3356
|
};
|
1781
|
-
|
3357
|
+
record.delete = function() {
|
3358
|
+
return db[table].delete(record["id"]);
|
3359
|
+
};
|
3360
|
+
record.getMetadata = function() {
|
1782
3361
|
return xata;
|
1783
3362
|
};
|
1784
|
-
|
1785
|
-
|
3363
|
+
record.toSerializable = function() {
|
3364
|
+
return JSON.parse(JSON.stringify(transformObjectLinks(data)));
|
3365
|
+
};
|
3366
|
+
record.toString = function() {
|
3367
|
+
return JSON.stringify(transformObjectLinks(data));
|
3368
|
+
};
|
3369
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3370
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
1786
3371
|
}
|
1787
|
-
Object.freeze(
|
1788
|
-
return
|
3372
|
+
Object.freeze(record);
|
3373
|
+
return record;
|
1789
3374
|
};
|
1790
|
-
function
|
1791
|
-
|
3375
|
+
function extractId(value) {
|
3376
|
+
if (isString(value))
|
3377
|
+
return value;
|
3378
|
+
if (isObject(value) && isString(value.id))
|
3379
|
+
return value.id;
|
3380
|
+
return void 0;
|
3381
|
+
}
|
3382
|
+
function isValidColumn(columns, column) {
|
3383
|
+
if (columns.includes("*"))
|
3384
|
+
return true;
|
3385
|
+
if (column.type === "link") {
|
3386
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
3387
|
+
return linkColumns.length > 0;
|
3388
|
+
}
|
3389
|
+
return columns.includes(column.name);
|
3390
|
+
}
|
3391
|
+
function parseIfVersion(...args) {
|
3392
|
+
for (const arg of args) {
|
3393
|
+
if (isObject(arg) && isNumber(arg.ifVersion)) {
|
3394
|
+
return arg.ifVersion;
|
3395
|
+
}
|
3396
|
+
}
|
3397
|
+
return void 0;
|
1792
3398
|
}
|
1793
3399
|
|
1794
3400
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1948,23 +3554,23 @@ class SearchPlugin extends XataPlugin {
|
|
1948
3554
|
__privateAdd$1(this, _schemaTables, void 0);
|
1949
3555
|
__privateSet$1(this, _schemaTables, schemaTables);
|
1950
3556
|
}
|
1951
|
-
build(
|
3557
|
+
build(pluginOptions) {
|
1952
3558
|
return {
|
1953
3559
|
all: async (query, options = {}) => {
|
1954
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
1955
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3560
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3561
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
1956
3562
|
return records.map((record) => {
|
1957
3563
|
const { table = "orphan" } = record.xata;
|
1958
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
3564
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
1959
3565
|
});
|
1960
3566
|
},
|
1961
3567
|
byTable: async (query, options = {}) => {
|
1962
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
1963
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3568
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3569
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
1964
3570
|
return records.reduce((acc, record) => {
|
1965
3571
|
const { table = "orphan" } = record.xata;
|
1966
3572
|
const items = acc[table] ?? [];
|
1967
|
-
const item = initObject(this.db, schemaTables, table, record);
|
3573
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1968
3574
|
return { ...acc, [table]: [...items, item] };
|
1969
3575
|
}, {});
|
1970
3576
|
}
|
@@ -1973,108 +3579,39 @@ class SearchPlugin extends XataPlugin {
|
|
1973
3579
|
}
|
1974
3580
|
_schemaTables = new WeakMap();
|
1975
3581
|
_search = new WeakSet();
|
1976
|
-
search_fn = async function(query, options,
|
1977
|
-
const
|
1978
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
3582
|
+
search_fn = async function(query, options, pluginOptions) {
|
3583
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
1979
3584
|
const { records } = await searchBranch({
|
1980
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1981
|
-
body: { tables, query, fuzziness, prefix, highlight },
|
1982
|
-
...
|
3585
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3586
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
3587
|
+
...pluginOptions
|
1983
3588
|
});
|
1984
3589
|
return records;
|
1985
3590
|
};
|
1986
3591
|
_getSchemaTables = new WeakSet();
|
1987
|
-
getSchemaTables_fn = async function(
|
3592
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
1988
3593
|
if (__privateGet$1(this, _schemaTables))
|
1989
3594
|
return __privateGet$1(this, _schemaTables);
|
1990
|
-
const fetchProps = await getFetchProps();
|
1991
3595
|
const { schema } = await getBranchDetails({
|
1992
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1993
|
-
...
|
3596
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3597
|
+
...pluginOptions
|
1994
3598
|
});
|
1995
3599
|
__privateSet$1(this, _schemaTables, schema.tables);
|
1996
3600
|
return schema.tables;
|
1997
3601
|
};
|
1998
3602
|
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
const gitBranch = envBranch || await getGitBranch();
|
2012
|
-
return resolveXataBranch(gitBranch, options);
|
2013
|
-
}
|
2014
|
-
async function getCurrentBranchDetails(options) {
|
2015
|
-
const branch = await getCurrentBranchName(options);
|
2016
|
-
return getDatabaseBranch(branch, options);
|
2017
|
-
}
|
2018
|
-
async function resolveXataBranch(gitBranch, options) {
|
2019
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2020
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2021
|
-
if (!databaseURL)
|
2022
|
-
throw new Error(
|
2023
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2024
|
-
);
|
2025
|
-
if (!apiKey)
|
2026
|
-
throw new Error(
|
2027
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2028
|
-
);
|
2029
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
2030
|
-
const [workspace] = host.split(".");
|
2031
|
-
const { fallbackBranch } = getEnvironment();
|
2032
|
-
const { branch } = await resolveBranch({
|
2033
|
-
apiKey,
|
2034
|
-
apiUrl: databaseURL,
|
2035
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2036
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
2037
|
-
pathParams: { dbName, workspace },
|
2038
|
-
queryParams: { gitBranch, fallbackBranch },
|
2039
|
-
trace: defaultTrace
|
2040
|
-
});
|
2041
|
-
return branch;
|
2042
|
-
}
|
2043
|
-
async function getDatabaseBranch(branch, options) {
|
2044
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2045
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2046
|
-
if (!databaseURL)
|
2047
|
-
throw new Error(
|
2048
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2049
|
-
);
|
2050
|
-
if (!apiKey)
|
2051
|
-
throw new Error(
|
2052
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2053
|
-
);
|
2054
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
2055
|
-
const [workspace] = host.split(".");
|
2056
|
-
const dbBranchName = `${database}:${branch}`;
|
2057
|
-
try {
|
2058
|
-
return await getBranchDetails({
|
2059
|
-
apiKey,
|
2060
|
-
apiUrl: databaseURL,
|
2061
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2062
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
2063
|
-
pathParams: { dbBranchName, workspace },
|
2064
|
-
trace: defaultTrace
|
2065
|
-
});
|
2066
|
-
} catch (err) {
|
2067
|
-
if (isObject(err) && err.status === 404)
|
2068
|
-
return null;
|
2069
|
-
throw err;
|
2070
|
-
}
|
2071
|
-
}
|
2072
|
-
function getDatabaseURL() {
|
2073
|
-
try {
|
2074
|
-
const { databaseURL } = getEnvironment();
|
2075
|
-
return databaseURL;
|
2076
|
-
} catch (err) {
|
2077
|
-
return void 0;
|
3603
|
+
class TransactionPlugin extends XataPlugin {
|
3604
|
+
build(pluginOptions) {
|
3605
|
+
return {
|
3606
|
+
run: async (operations) => {
|
3607
|
+
const response = await branchTransaction({
|
3608
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3609
|
+
body: { operations },
|
3610
|
+
...pluginOptions
|
3611
|
+
});
|
3612
|
+
return response;
|
3613
|
+
}
|
3614
|
+
};
|
2078
3615
|
}
|
2079
3616
|
}
|
2080
3617
|
|
@@ -2101,88 +3638,115 @@ var __privateMethod = (obj, member, method) => {
|
|
2101
3638
|
return method;
|
2102
3639
|
};
|
2103
3640
|
const buildClient = (plugins) => {
|
2104
|
-
var
|
3641
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
2105
3642
|
return _a = class {
|
2106
3643
|
constructor(options = {}, schemaTables) {
|
2107
3644
|
__privateAdd(this, _parseOptions);
|
2108
3645
|
__privateAdd(this, _getFetchProps);
|
2109
|
-
__privateAdd(this, _evaluateBranch);
|
2110
|
-
__privateAdd(this, _branch, void 0);
|
2111
3646
|
__privateAdd(this, _options, void 0);
|
2112
3647
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2113
3648
|
__privateSet(this, _options, safeOptions);
|
2114
3649
|
const pluginOptions = {
|
2115
|
-
|
3650
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2116
3651
|
cache: safeOptions.cache,
|
2117
|
-
|
3652
|
+
host: safeOptions.host
|
2118
3653
|
};
|
2119
3654
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2120
3655
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3656
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
2121
3657
|
this.db = db;
|
2122
3658
|
this.search = search;
|
3659
|
+
this.transactions = transactions;
|
2123
3660
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
2124
3661
|
if (namespace === void 0)
|
2125
3662
|
continue;
|
2126
|
-
|
2127
|
-
if (result instanceof Promise) {
|
2128
|
-
void result.then((namespace2) => {
|
2129
|
-
this[key] = namespace2;
|
2130
|
-
});
|
2131
|
-
} else {
|
2132
|
-
this[key] = result;
|
2133
|
-
}
|
3663
|
+
this[key] = namespace.build(pluginOptions);
|
2134
3664
|
}
|
2135
3665
|
}
|
2136
3666
|
async getConfig() {
|
2137
3667
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
2138
|
-
const branch =
|
3668
|
+
const branch = __privateGet(this, _options).branch;
|
2139
3669
|
return { databaseURL, branch };
|
2140
3670
|
}
|
2141
|
-
},
|
3671
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3672
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3673
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3674
|
+
if (isBrowser && !enableBrowser) {
|
3675
|
+
throw new Error(
|
3676
|
+
"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."
|
3677
|
+
);
|
3678
|
+
}
|
2142
3679
|
const fetch = getFetchImplementation(options?.fetch);
|
2143
3680
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2144
3681
|
const apiKey = options?.apiKey || getAPIKey();
|
2145
3682
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2146
3683
|
const trace = options?.trace ?? defaultTrace;
|
2147
|
-
const
|
3684
|
+
const clientName = options?.clientName;
|
3685
|
+
const host = options?.host ?? "production";
|
3686
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
2148
3687
|
if (!apiKey) {
|
2149
3688
|
throw new Error("Option apiKey is required");
|
2150
3689
|
}
|
2151
3690
|
if (!databaseURL) {
|
2152
3691
|
throw new Error("Option databaseURL is required");
|
2153
3692
|
}
|
2154
|
-
|
2155
|
-
|
2156
|
-
const
|
2157
|
-
if (
|
2158
|
-
|
3693
|
+
const envBranch = getBranch();
|
3694
|
+
const previewBranch = getPreviewBranch();
|
3695
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
3696
|
+
if (!!previewBranch && branch !== previewBranch) {
|
3697
|
+
console.warn(
|
3698
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
3699
|
+
);
|
3700
|
+
} else if (!!envBranch && branch !== envBranch) {
|
3701
|
+
console.warn(
|
3702
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
3703
|
+
);
|
3704
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
3705
|
+
console.warn(
|
3706
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
3707
|
+
);
|
3708
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
3709
|
+
console.warn(
|
3710
|
+
`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.`
|
3711
|
+
);
|
3712
|
+
}
|
3713
|
+
return {
|
3714
|
+
fetch,
|
3715
|
+
databaseURL,
|
3716
|
+
apiKey,
|
3717
|
+
branch,
|
3718
|
+
cache,
|
3719
|
+
trace,
|
3720
|
+
host,
|
3721
|
+
clientID: generateUUID(),
|
3722
|
+
enableBrowser,
|
3723
|
+
clientName,
|
3724
|
+
xataAgentExtra
|
3725
|
+
};
|
3726
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3727
|
+
fetch,
|
3728
|
+
apiKey,
|
3729
|
+
databaseURL,
|
3730
|
+
branch,
|
3731
|
+
trace,
|
3732
|
+
clientID,
|
3733
|
+
clientName,
|
3734
|
+
xataAgentExtra
|
3735
|
+
}) {
|
2159
3736
|
return {
|
2160
|
-
|
3737
|
+
fetch,
|
2161
3738
|
apiKey,
|
2162
3739
|
apiUrl: "",
|
2163
3740
|
workspacesApiUrl: (path, params) => {
|
2164
3741
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2165
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${
|
3742
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
2166
3743
|
return databaseURL + newPath;
|
2167
3744
|
},
|
2168
|
-
trace
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
return __privateGet(this, _branch);
|
2173
|
-
if (param === void 0)
|
2174
|
-
return void 0;
|
2175
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
2176
|
-
const evaluateBranch = async (strategy) => {
|
2177
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3745
|
+
trace,
|
3746
|
+
clientID,
|
3747
|
+
clientName,
|
3748
|
+
xataAgentExtra
|
2178
3749
|
};
|
2179
|
-
for await (const strategy of strategies) {
|
2180
|
-
const branch = await evaluateBranch(strategy);
|
2181
|
-
if (branch) {
|
2182
|
-
__privateSet(this, _branch, branch);
|
2183
|
-
return branch;
|
2184
|
-
}
|
2185
|
-
}
|
2186
3750
|
}, _a;
|
2187
3751
|
};
|
2188
3752
|
class BaseClient extends buildClient() {
|
@@ -2256,7 +3820,7 @@ const deserialize = (json) => {
|
|
2256
3820
|
};
|
2257
3821
|
|
2258
3822
|
function buildWorkerRunner(config) {
|
2259
|
-
return function xataWorker(name,
|
3823
|
+
return function xataWorker(name, worker) {
|
2260
3824
|
return async (...args) => {
|
2261
3825
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2262
3826
|
const result = await fetch(url, {
|
@@ -2278,6 +3842,7 @@ class XataError extends Error {
|
|
2278
3842
|
}
|
2279
3843
|
|
2280
3844
|
exports.BaseClient = BaseClient;
|
3845
|
+
exports.FetcherError = FetcherError;
|
2281
3846
|
exports.Operations = operationsByTag;
|
2282
3847
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
2283
3848
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -2299,19 +3864,31 @@ exports.XataPlugin = XataPlugin;
|
|
2299
3864
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
2300
3865
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2301
3866
|
exports.addTableColumn = addTableColumn;
|
3867
|
+
exports.aggregateTable = aggregateTable;
|
3868
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
3869
|
+
exports.askTable = askTable;
|
3870
|
+
exports.branchTransaction = branchTransaction;
|
2302
3871
|
exports.buildClient = buildClient;
|
3872
|
+
exports.buildPreviewBranchName = buildPreviewBranchName;
|
3873
|
+
exports.buildProviderString = buildProviderString;
|
2303
3874
|
exports.buildWorkerRunner = buildWorkerRunner;
|
2304
3875
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2305
3876
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
3877
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
3878
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
3879
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
2306
3880
|
exports.contains = contains;
|
3881
|
+
exports.copyBranch = copyBranch;
|
2307
3882
|
exports.createBranch = createBranch;
|
2308
3883
|
exports.createDatabase = createDatabase;
|
3884
|
+
exports.createMigrationRequest = createMigrationRequest;
|
2309
3885
|
exports.createTable = createTable;
|
2310
3886
|
exports.createUserAPIKey = createUserAPIKey;
|
2311
3887
|
exports.createWorkspace = createWorkspace;
|
2312
3888
|
exports.deleteBranch = deleteBranch;
|
2313
3889
|
exports.deleteColumn = deleteColumn;
|
2314
3890
|
exports.deleteDatabase = deleteDatabase;
|
3891
|
+
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
2315
3892
|
exports.deleteRecord = deleteRecord;
|
2316
3893
|
exports.deleteTable = deleteTable;
|
2317
3894
|
exports.deleteUser = deleteUser;
|
@@ -2324,19 +3901,24 @@ exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
|
2324
3901
|
exports.exists = exists;
|
2325
3902
|
exports.ge = ge;
|
2326
3903
|
exports.getAPIKey = getAPIKey;
|
3904
|
+
exports.getBranch = getBranch;
|
2327
3905
|
exports.getBranchDetails = getBranchDetails;
|
2328
3906
|
exports.getBranchList = getBranchList;
|
2329
3907
|
exports.getBranchMetadata = getBranchMetadata;
|
2330
3908
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
2331
3909
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
3910
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
2332
3911
|
exports.getBranchStats = getBranchStats;
|
2333
3912
|
exports.getColumn = getColumn;
|
2334
|
-
exports.
|
2335
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
3913
|
+
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
2336
3914
|
exports.getDatabaseList = getDatabaseList;
|
2337
3915
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2338
3916
|
exports.getDatabaseURL = getDatabaseURL;
|
2339
3917
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
3918
|
+
exports.getHostUrl = getHostUrl;
|
3919
|
+
exports.getMigrationRequest = getMigrationRequest;
|
3920
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
3921
|
+
exports.getPreviewBranch = getPreviewBranch;
|
2340
3922
|
exports.getRecord = getRecord;
|
2341
3923
|
exports.getTableColumns = getTableColumns;
|
2342
3924
|
exports.getTableSchema = getTableSchema;
|
@@ -2359,6 +3941,8 @@ exports.insertRecordWithID = insertRecordWithID;
|
|
2359
3941
|
exports.inviteWorkspaceMember = inviteWorkspaceMember;
|
2360
3942
|
exports.is = is;
|
2361
3943
|
exports.isCursorPaginationOptions = isCursorPaginationOptions;
|
3944
|
+
exports.isHostProviderAlias = isHostProviderAlias;
|
3945
|
+
exports.isHostProviderBuilder = isHostProviderBuilder;
|
2362
3946
|
exports.isIdentifiable = isIdentifiable;
|
2363
3947
|
exports.isNot = isNot;
|
2364
3948
|
exports.isXataRecord = isXataRecord;
|
@@ -2366,11 +3950,19 @@ exports.le = le;
|
|
2366
3950
|
exports.lessEquals = lessEquals;
|
2367
3951
|
exports.lessThan = lessThan;
|
2368
3952
|
exports.lessThanEquals = lessThanEquals;
|
3953
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
3954
|
+
exports.listRegions = listRegions;
|
2369
3955
|
exports.lt = lt;
|
2370
3956
|
exports.lte = lte;
|
3957
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
2371
3958
|
exports.notExists = notExists;
|
2372
3959
|
exports.operationsByTag = operationsByTag;
|
3960
|
+
exports.parseProviderString = parseProviderString;
|
3961
|
+
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
2373
3962
|
exports.pattern = pattern;
|
3963
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
3964
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
3965
|
+
exports.queryMigrationRequests = queryMigrationRequests;
|
2374
3966
|
exports.queryTable = queryTable;
|
2375
3967
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
2376
3968
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
@@ -2380,9 +3972,15 @@ exports.searchBranch = searchBranch;
|
|
2380
3972
|
exports.searchTable = searchTable;
|
2381
3973
|
exports.serialize = serialize;
|
2382
3974
|
exports.setTableSchema = setTableSchema;
|
3975
|
+
exports.sqlQuery = sqlQuery;
|
2383
3976
|
exports.startsWith = startsWith;
|
3977
|
+
exports.summarizeTable = summarizeTable;
|
2384
3978
|
exports.updateBranchMetadata = updateBranchMetadata;
|
3979
|
+
exports.updateBranchSchema = updateBranchSchema;
|
2385
3980
|
exports.updateColumn = updateColumn;
|
3981
|
+
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
3982
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
3983
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
2386
3984
|
exports.updateRecordWithID = updateRecordWithID;
|
2387
3985
|
exports.updateTable = updateTable;
|
2388
3986
|
exports.updateUser = updateUser;
|
@@ -2390,4 +3988,5 @@ exports.updateWorkspace = updateWorkspace;
|
|
2390
3988
|
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
2391
3989
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
2392
3990
|
exports.upsertRecordWithID = upsertRecordWithID;
|
3991
|
+
exports.vectorSearchTable = vectorSearchTable;
|
2393
3992
|
//# sourceMappingURL=index.cjs.map
|