@xata.io/client 0.0.0-alpha.vf28813b → 0.0.0-alpha.vf2f26ae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +344 -0
- package/README.md +3 -267
- package/dist/index.cjs +3014 -867
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6392 -1548
- package/dist/index.mjs +2957 -844
- package/dist/index.mjs.map +1 -1
- package/package.json +13 -11
- package/.eslintrc.cjs +0 -12
- package/Usage.md +0 -428
- package/rollup.config.js +0 -29
- package/tsconfig.json +0 -23
package/dist/index.cjs
CHANGED
@@ -1,24 +1,27 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
3
|
+
const defaultTrace = async (name, fn, _options) => {
|
4
|
+
return await fn({
|
5
|
+
name,
|
6
|
+
setAttributes: () => {
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
});
|
10
|
+
};
|
11
|
+
const TraceAttributes = {
|
12
|
+
KIND: "xata.trace.kind",
|
13
|
+
VERSION: "xata.sdk.version",
|
14
|
+
TABLE: "xata.table",
|
15
|
+
HTTP_REQUEST_ID: "http.request_id",
|
16
|
+
HTTP_STATUS_CODE: "http.status_code",
|
17
|
+
HTTP_HOST: "http.host",
|
18
|
+
HTTP_SCHEME: "http.scheme",
|
19
|
+
HTTP_USER_AGENT: "http.user_agent",
|
20
|
+
HTTP_METHOD: "http.method",
|
21
|
+
HTTP_URL: "http.url",
|
22
|
+
HTTP_ROUTE: "http.route",
|
23
|
+
HTTP_TARGET: "http.target"
|
24
|
+
};
|
22
25
|
|
23
26
|
function notEmpty(value) {
|
24
27
|
return value !== null && value !== void 0;
|
@@ -38,6 +41,21 @@ function isString(value) {
|
|
38
41
|
function isStringArray(value) {
|
39
42
|
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
40
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
|
+
}
|
41
59
|
function toBase64(value) {
|
42
60
|
try {
|
43
61
|
return btoa(value);
|
@@ -46,16 +64,39 @@ function toBase64(value) {
|
|
46
64
|
return buf.from(value).toString("base64");
|
47
65
|
}
|
48
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
|
+
}
|
49
88
|
|
50
89
|
function getEnvironment() {
|
51
90
|
try {
|
52
|
-
if (
|
91
|
+
if (isDefined(process) && isDefined(process.env)) {
|
53
92
|
return {
|
54
93
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
55
94
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
56
95
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
57
|
-
|
58
|
-
|
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
|
59
100
|
};
|
60
101
|
}
|
61
102
|
} catch (err) {
|
@@ -66,8 +107,10 @@ function getEnvironment() {
|
|
66
107
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
67
108
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
68
109
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
69
|
-
|
70
|
-
|
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")
|
71
114
|
};
|
72
115
|
}
|
73
116
|
} catch (err) {
|
@@ -76,10 +119,31 @@ function getEnvironment() {
|
|
76
119
|
apiKey: getGlobalApiKey(),
|
77
120
|
databaseURL: getGlobalDatabaseURL(),
|
78
121
|
branch: getGlobalBranch(),
|
79
|
-
|
80
|
-
|
122
|
+
deployPreview: void 0,
|
123
|
+
deployPreviewBranch: void 0,
|
124
|
+
vercelGitCommitRef: void 0,
|
125
|
+
vercelGitRepoOwner: void 0
|
81
126
|
};
|
82
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
|
+
}
|
83
147
|
function getGlobalApiKey() {
|
84
148
|
try {
|
85
149
|
return XATA_API_KEY;
|
@@ -101,56 +165,334 @@ function getGlobalBranch() {
|
|
101
165
|
return void 0;
|
102
166
|
}
|
103
167
|
}
|
104
|
-
function
|
168
|
+
function getDatabaseURL() {
|
105
169
|
try {
|
106
|
-
|
170
|
+
const { databaseURL } = getEnvironment();
|
171
|
+
return databaseURL;
|
107
172
|
} catch (err) {
|
108
173
|
return void 0;
|
109
174
|
}
|
110
175
|
}
|
111
|
-
|
112
|
-
const cmd = ["git", "branch", "--show-current"];
|
113
|
-
const fullCmd = cmd.join(" ");
|
114
|
-
const nodeModule = ["child", "process"].join("_");
|
115
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
176
|
+
function getAPIKey() {
|
116
177
|
try {
|
117
|
-
|
118
|
-
|
119
|
-
}
|
120
|
-
const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
|
121
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
178
|
+
const { apiKey } = getEnvironment();
|
179
|
+
return apiKey;
|
122
180
|
} catch (err) {
|
181
|
+
return void 0;
|
123
182
|
}
|
183
|
+
}
|
184
|
+
function getBranch() {
|
124
185
|
try {
|
125
|
-
|
126
|
-
|
127
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
128
|
-
}
|
186
|
+
const { branch } = getEnvironment();
|
187
|
+
return branch ?? "main";
|
129
188
|
} catch (err) {
|
189
|
+
return void 0;
|
130
190
|
}
|
131
191
|
}
|
132
|
-
|
133
|
-
|
192
|
+
function buildPreviewBranchName({ org, branch }) {
|
193
|
+
return `preview-${org}-${branch}`;
|
194
|
+
}
|
195
|
+
function getPreviewBranch() {
|
134
196
|
try {
|
135
|
-
const {
|
136
|
-
|
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;
|
137
210
|
} catch (err) {
|
138
211
|
return void 0;
|
139
212
|
}
|
140
213
|
}
|
141
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;
|
142
238
|
function getFetchImplementation(userFetch) {
|
143
239
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
144
240
|
const fetchImpl = userFetch ?? globalFetch;
|
145
241
|
if (!fetchImpl) {
|
146
242
|
throw new Error(
|
147
|
-
`
|
243
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
148
244
|
);
|
149
245
|
}
|
150
246
|
return fetchImpl;
|
151
247
|
}
|
248
|
+
class ApiRequestPool {
|
249
|
+
constructor(concurrency = 10) {
|
250
|
+
__privateAdd$8(this, _enqueue);
|
251
|
+
__privateAdd$8(this, _fetch, void 0);
|
252
|
+
__privateAdd$8(this, _queue, void 0);
|
253
|
+
__privateAdd$8(this, _concurrency, void 0);
|
254
|
+
__privateSet$8(this, _queue, []);
|
255
|
+
__privateSet$8(this, _concurrency, concurrency);
|
256
|
+
this.running = 0;
|
257
|
+
this.started = 0;
|
258
|
+
}
|
259
|
+
setFetch(fetch2) {
|
260
|
+
__privateSet$8(this, _fetch, fetch2);
|
261
|
+
}
|
262
|
+
getFetch() {
|
263
|
+
if (!__privateGet$8(this, _fetch)) {
|
264
|
+
throw new Error("Fetch not set");
|
265
|
+
}
|
266
|
+
return __privateGet$8(this, _fetch);
|
267
|
+
}
|
268
|
+
request(url, options) {
|
269
|
+
const start = /* @__PURE__ */ new Date();
|
270
|
+
const fetch2 = this.getFetch();
|
271
|
+
const runRequest = async (stalled = false) => {
|
272
|
+
const response = await fetch2(url, options);
|
273
|
+
if (response.status === 429) {
|
274
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
275
|
+
await timeout(rateLimitReset * 1e3);
|
276
|
+
return await runRequest(true);
|
277
|
+
}
|
278
|
+
if (stalled) {
|
279
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
280
|
+
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
281
|
+
}
|
282
|
+
return response;
|
283
|
+
};
|
284
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
285
|
+
return await runRequest();
|
286
|
+
});
|
287
|
+
}
|
288
|
+
}
|
289
|
+
_fetch = new WeakMap();
|
290
|
+
_queue = new WeakMap();
|
291
|
+
_concurrency = new WeakMap();
|
292
|
+
_enqueue = new WeakSet();
|
293
|
+
enqueue_fn = function(task) {
|
294
|
+
const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
|
295
|
+
this.started--;
|
296
|
+
this.running++;
|
297
|
+
}).then(() => task()).finally(() => {
|
298
|
+
this.running--;
|
299
|
+
const next = __privateGet$8(this, _queue).shift();
|
300
|
+
if (next !== void 0) {
|
301
|
+
this.started++;
|
302
|
+
next();
|
303
|
+
}
|
304
|
+
});
|
305
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
306
|
+
const next = __privateGet$8(this, _queue).shift();
|
307
|
+
if (next !== void 0) {
|
308
|
+
this.started++;
|
309
|
+
next();
|
310
|
+
}
|
311
|
+
}
|
312
|
+
return promise;
|
313
|
+
};
|
314
|
+
|
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
|
+
}
|
152
494
|
|
153
|
-
const VERSION = "0.
|
495
|
+
const VERSION = "0.24.0";
|
154
496
|
|
155
497
|
class ErrorWithCause extends Error {
|
156
498
|
constructor(message, options) {
|
@@ -161,7 +503,7 @@ class FetcherError extends ErrorWithCause {
|
|
161
503
|
constructor(status, data, requestId) {
|
162
504
|
super(getMessage(data));
|
163
505
|
this.status = status;
|
164
|
-
this.errors = isBulkError(data) ? data.errors :
|
506
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
165
507
|
this.requestId = requestId;
|
166
508
|
if (data instanceof Error) {
|
167
509
|
this.stack = data.stack;
|
@@ -193,6 +535,7 @@ function getMessage(data) {
|
|
193
535
|
}
|
194
536
|
}
|
195
537
|
|
538
|
+
const pool = new ApiRequestPool();
|
196
539
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
197
540
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
198
541
|
if (value === void 0 || value === null)
|
@@ -201,317 +544,419 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
201
544
|
}, {});
|
202
545
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
203
546
|
const queryString = query.length > 0 ? `?${query}` : "";
|
204
|
-
|
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;
|
205
551
|
};
|
206
552
|
function buildBaseUrl({
|
553
|
+
endpoint,
|
207
554
|
path,
|
208
555
|
workspacesApiUrl,
|
209
556
|
apiUrl,
|
210
|
-
pathParams
|
557
|
+
pathParams = {}
|
211
558
|
}) {
|
212
|
-
if (
|
213
|
-
|
214
|
-
|
215
|
-
|
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}`;
|
216
565
|
}
|
217
566
|
function hostHeader(url) {
|
218
567
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
219
568
|
const { groups } = pattern.exec(url) ?? {};
|
220
569
|
return groups?.host ? { Host: groups.host } : {};
|
221
570
|
}
|
571
|
+
const defaultClientID = generateUUID();
|
222
572
|
async function fetch$1({
|
223
573
|
url: path,
|
224
574
|
method,
|
225
575
|
body,
|
226
|
-
headers,
|
576
|
+
headers: customHeaders,
|
577
|
+
pathParams,
|
578
|
+
queryParams,
|
579
|
+
fetch: fetch2,
|
580
|
+
apiKey,
|
581
|
+
endpoint,
|
582
|
+
apiUrl,
|
583
|
+
workspacesApiUrl,
|
584
|
+
trace,
|
585
|
+
signal,
|
586
|
+
clientID,
|
587
|
+
sessionID,
|
588
|
+
clientName,
|
589
|
+
xataAgentExtra,
|
590
|
+
fetchOptions = {}
|
591
|
+
}) {
|
592
|
+
pool.setFetch(fetch2);
|
593
|
+
return await trace(
|
594
|
+
`${method.toUpperCase()} ${path}`,
|
595
|
+
async ({ setAttributes }) => {
|
596
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
597
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
598
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
599
|
+
setAttributes({
|
600
|
+
[TraceAttributes.HTTP_URL]: url,
|
601
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
602
|
+
});
|
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,
|
621
|
+
method: method.toUpperCase(),
|
622
|
+
body: body ? JSON.stringify(body) : void 0,
|
623
|
+
headers,
|
624
|
+
signal
|
625
|
+
});
|
626
|
+
const { host, protocol } = parseUrl(response.url);
|
627
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
628
|
+
setAttributes({
|
629
|
+
[TraceAttributes.KIND]: "http",
|
630
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
631
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
632
|
+
[TraceAttributes.HTTP_HOST]: host,
|
633
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
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
|
+
}
|
641
|
+
try {
|
642
|
+
const jsonResponse = await response.json();
|
643
|
+
if (response.ok) {
|
644
|
+
return jsonResponse;
|
645
|
+
}
|
646
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
647
|
+
} catch (error) {
|
648
|
+
throw new FetcherError(response.status, error, requestId);
|
649
|
+
}
|
650
|
+
},
|
651
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
652
|
+
);
|
653
|
+
}
|
654
|
+
function fetchSSERequest({
|
655
|
+
url: path,
|
656
|
+
method,
|
657
|
+
body,
|
658
|
+
headers: customHeaders,
|
227
659
|
pathParams,
|
228
660
|
queryParams,
|
229
|
-
|
661
|
+
fetch: fetch2,
|
230
662
|
apiKey,
|
663
|
+
endpoint,
|
231
664
|
apiUrl,
|
232
|
-
workspacesApiUrl
|
665
|
+
workspacesApiUrl,
|
666
|
+
onMessage,
|
667
|
+
onError,
|
668
|
+
onClose,
|
669
|
+
signal,
|
670
|
+
clientID,
|
671
|
+
sessionID,
|
672
|
+
clientName,
|
673
|
+
xataAgentExtra
|
233
674
|
}) {
|
234
|
-
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
675
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
235
676
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
236
677
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
237
|
-
|
238
|
-
method
|
239
|
-
body:
|
678
|
+
void fetchEventSource(url, {
|
679
|
+
method,
|
680
|
+
body: JSON.stringify(body),
|
681
|
+
fetch: fetch2,
|
682
|
+
signal,
|
240
683
|
headers: {
|
241
|
-
"
|
242
|
-
"
|
243
|
-
|
244
|
-
|
245
|
-
|
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?.();
|
246
704
|
}
|
247
705
|
});
|
248
|
-
|
249
|
-
|
250
|
-
}
|
251
|
-
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
706
|
+
}
|
707
|
+
function parseUrl(url) {
|
252
708
|
try {
|
253
|
-
const
|
254
|
-
|
255
|
-
return jsonResponse;
|
256
|
-
}
|
257
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
709
|
+
const { host, protocol } = new URL(url);
|
710
|
+
return { host, protocol };
|
258
711
|
} catch (error) {
|
259
|
-
|
712
|
+
return {};
|
260
713
|
}
|
261
714
|
}
|
262
715
|
|
263
|
-
const
|
264
|
-
|
265
|
-
const
|
266
|
-
const getUserAPIKeys = (variables) => fetch$1({
|
267
|
-
url: "/user/keys",
|
268
|
-
method: "get",
|
269
|
-
...variables
|
270
|
-
});
|
271
|
-
const createUserAPIKey = (variables) => fetch$1({
|
272
|
-
url: "/user/keys/{keyName}",
|
273
|
-
method: "post",
|
274
|
-
...variables
|
275
|
-
});
|
276
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
277
|
-
url: "/user/keys/{keyName}",
|
278
|
-
method: "delete",
|
279
|
-
...variables
|
280
|
-
});
|
281
|
-
const createWorkspace = (variables) => fetch$1({
|
282
|
-
url: "/workspaces",
|
283
|
-
method: "post",
|
284
|
-
...variables
|
285
|
-
});
|
286
|
-
const getWorkspacesList = (variables) => fetch$1({
|
287
|
-
url: "/workspaces",
|
288
|
-
method: "get",
|
289
|
-
...variables
|
290
|
-
});
|
291
|
-
const getWorkspace = (variables) => fetch$1({
|
292
|
-
url: "/workspaces/{workspaceId}",
|
293
|
-
method: "get",
|
294
|
-
...variables
|
295
|
-
});
|
296
|
-
const updateWorkspace = (variables) => fetch$1({
|
297
|
-
url: "/workspaces/{workspaceId}",
|
298
|
-
method: "put",
|
299
|
-
...variables
|
300
|
-
});
|
301
|
-
const deleteWorkspace = (variables) => fetch$1({
|
302
|
-
url: "/workspaces/{workspaceId}",
|
303
|
-
method: "delete",
|
304
|
-
...variables
|
305
|
-
});
|
306
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
307
|
-
url: "/workspaces/{workspaceId}/members",
|
308
|
-
method: "get",
|
309
|
-
...variables
|
310
|
-
});
|
311
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
312
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
313
|
-
url: "/workspaces/{workspaceId}/members/{userId}",
|
314
|
-
method: "delete",
|
315
|
-
...variables
|
316
|
-
});
|
317
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
318
|
-
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
319
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
320
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
321
|
-
method: "delete",
|
322
|
-
...variables
|
323
|
-
});
|
324
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
325
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
326
|
-
method: "post",
|
327
|
-
...variables
|
328
|
-
});
|
329
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
330
|
-
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
331
|
-
method: "post",
|
332
|
-
...variables
|
333
|
-
});
|
334
|
-
const getDatabaseList = (variables) => fetch$1({
|
335
|
-
url: "/dbs",
|
336
|
-
method: "get",
|
337
|
-
...variables
|
338
|
-
});
|
339
|
-
const getBranchList = (variables) => fetch$1({
|
340
|
-
url: "/dbs/{dbName}",
|
341
|
-
method: "get",
|
342
|
-
...variables
|
343
|
-
});
|
344
|
-
const createDatabase = (variables) => fetch$1({
|
345
|
-
url: "/dbs/{dbName}",
|
346
|
-
method: "put",
|
347
|
-
...variables
|
348
|
-
});
|
349
|
-
const deleteDatabase = (variables) => fetch$1({
|
716
|
+
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
717
|
+
|
718
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
350
719
|
url: "/dbs/{dbName}",
|
351
|
-
method: "delete",
|
352
|
-
...variables
|
353
|
-
});
|
354
|
-
const getDatabaseMetadata = (variables) => fetch$1({
|
355
|
-
url: "/dbs/{dbName}/metadata",
|
356
720
|
method: "get",
|
357
|
-
...variables
|
721
|
+
...variables,
|
722
|
+
signal
|
358
723
|
});
|
359
|
-
const
|
360
|
-
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
361
|
-
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
362
|
-
const resolveBranch = (variables) => fetch$1({
|
363
|
-
url: "/dbs/{dbName}/resolveBranch",
|
364
|
-
method: "get",
|
365
|
-
...variables
|
366
|
-
});
|
367
|
-
const getBranchDetails = (variables) => fetch$1({
|
724
|
+
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
368
725
|
url: "/db/{dbBranchName}",
|
369
726
|
method: "get",
|
370
|
-
...variables
|
727
|
+
...variables,
|
728
|
+
signal
|
371
729
|
});
|
372
|
-
const createBranch = (variables) =>
|
373
|
-
const deleteBranch = (variables) =>
|
730
|
+
const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
731
|
+
const deleteBranch = (variables, signal) => dataPlaneFetch({
|
374
732
|
url: "/db/{dbBranchName}",
|
375
733
|
method: "delete",
|
376
|
-
...variables
|
734
|
+
...variables,
|
735
|
+
signal
|
736
|
+
});
|
737
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
738
|
+
url: "/db/{dbBranchName}/copy",
|
739
|
+
method: "post",
|
740
|
+
...variables,
|
741
|
+
signal
|
377
742
|
});
|
378
|
-
const updateBranchMetadata = (variables) =>
|
743
|
+
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
379
744
|
url: "/db/{dbBranchName}/metadata",
|
380
745
|
method: "put",
|
381
|
-
...variables
|
746
|
+
...variables,
|
747
|
+
signal
|
382
748
|
});
|
383
|
-
const getBranchMetadata = (variables) =>
|
749
|
+
const getBranchMetadata = (variables, signal) => dataPlaneFetch({
|
384
750
|
url: "/db/{dbBranchName}/metadata",
|
385
751
|
method: "get",
|
386
|
-
...variables
|
752
|
+
...variables,
|
753
|
+
signal
|
387
754
|
});
|
388
|
-
const
|
389
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
390
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
391
|
-
const getBranchStats = (variables) => fetch$1({
|
755
|
+
const getBranchStats = (variables, signal) => dataPlaneFetch({
|
392
756
|
url: "/db/{dbBranchName}/stats",
|
393
757
|
method: "get",
|
394
|
-
...variables
|
758
|
+
...variables,
|
759
|
+
signal
|
395
760
|
});
|
396
|
-
const
|
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
|
785
|
+
});
|
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({
|
397
794
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
398
795
|
method: "put",
|
399
|
-
...variables
|
796
|
+
...variables,
|
797
|
+
signal
|
400
798
|
});
|
401
|
-
const deleteTable = (variables) =>
|
799
|
+
const deleteTable = (variables, signal) => dataPlaneFetch({
|
402
800
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
403
801
|
method: "delete",
|
404
|
-
...variables
|
802
|
+
...variables,
|
803
|
+
signal
|
405
804
|
});
|
406
|
-
const updateTable = (variables) =>
|
407
|
-
|
408
|
-
method: "patch",
|
409
|
-
...variables
|
410
|
-
});
|
411
|
-
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({
|
412
807
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
413
808
|
method: "get",
|
414
|
-
...variables
|
415
|
-
|
416
|
-
const setTableSchema = (variables) => fetch$1({
|
417
|
-
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
418
|
-
method: "put",
|
419
|
-
...variables
|
809
|
+
...variables,
|
810
|
+
signal
|
420
811
|
});
|
421
|
-
const
|
812
|
+
const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
|
813
|
+
const getTableColumns = (variables, signal) => dataPlaneFetch({
|
422
814
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
423
815
|
method: "get",
|
424
|
-
...variables
|
425
|
-
|
426
|
-
const addTableColumn = (variables) => fetch$1({
|
427
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
428
|
-
method: "post",
|
429
|
-
...variables
|
816
|
+
...variables,
|
817
|
+
signal
|
430
818
|
});
|
431
|
-
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({
|
432
823
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
433
824
|
method: "get",
|
434
|
-
...variables
|
825
|
+
...variables,
|
826
|
+
signal
|
435
827
|
});
|
436
|
-
const
|
828
|
+
const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
|
829
|
+
const deleteColumn = (variables, signal) => dataPlaneFetch({
|
437
830
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
438
831
|
method: "delete",
|
439
|
-
...variables
|
832
|
+
...variables,
|
833
|
+
signal
|
440
834
|
});
|
441
|
-
const
|
442
|
-
|
443
|
-
|
444
|
-
|
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 getFileItem = (variables, signal) => dataPlaneFetch({
|
838
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
839
|
+
method: "get",
|
840
|
+
...variables,
|
841
|
+
signal
|
445
842
|
});
|
446
|
-
const
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
843
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
844
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
845
|
+
method: "put",
|
846
|
+
...variables,
|
847
|
+
signal
|
848
|
+
});
|
849
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
850
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
851
|
+
method: "delete",
|
852
|
+
...variables,
|
853
|
+
signal
|
854
|
+
});
|
855
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
856
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
857
|
+
method: "get",
|
858
|
+
...variables,
|
859
|
+
signal
|
860
|
+
});
|
861
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
862
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
863
|
+
method: "put",
|
864
|
+
...variables,
|
865
|
+
signal
|
866
|
+
});
|
867
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
868
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
452
869
|
method: "delete",
|
453
|
-
...variables
|
870
|
+
...variables,
|
871
|
+
signal
|
454
872
|
});
|
455
|
-
const getRecord = (variables) =>
|
873
|
+
const getRecord = (variables, signal) => dataPlaneFetch({
|
456
874
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
457
875
|
method: "get",
|
458
|
-
...variables
|
876
|
+
...variables,
|
877
|
+
signal
|
459
878
|
});
|
460
|
-
const
|
461
|
-
const
|
879
|
+
const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
880
|
+
const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
881
|
+
const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
882
|
+
const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
|
883
|
+
const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
884
|
+
const queryTable = (variables, signal) => dataPlaneFetch({
|
462
885
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
463
886
|
method: "post",
|
464
|
-
...variables
|
887
|
+
...variables,
|
888
|
+
signal
|
889
|
+
});
|
890
|
+
const searchBranch = (variables, signal) => dataPlaneFetch({
|
891
|
+
url: "/db/{dbBranchName}/search",
|
892
|
+
method: "post",
|
893
|
+
...variables,
|
894
|
+
signal
|
465
895
|
});
|
466
|
-
const searchTable = (variables) =>
|
896
|
+
const searchTable = (variables, signal) => dataPlaneFetch({
|
467
897
|
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
468
898
|
method: "post",
|
469
|
-
...variables
|
899
|
+
...variables,
|
900
|
+
signal
|
470
901
|
});
|
471
|
-
const
|
472
|
-
url: "/db/{dbBranchName}/
|
902
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
903
|
+
url: "/db/{dbBranchName}/sql",
|
473
904
|
method: "post",
|
474
|
-
...variables
|
905
|
+
...variables,
|
906
|
+
signal
|
475
907
|
});
|
476
|
-
const
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
},
|
493
|
-
database: {
|
494
|
-
getDatabaseList,
|
495
|
-
createDatabase,
|
496
|
-
deleteDatabase,
|
497
|
-
getGitBranchesMapping,
|
498
|
-
addGitBranchesEntry,
|
499
|
-
removeGitBranchesEntry,
|
500
|
-
resolveBranch
|
501
|
-
},
|
908
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
909
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
910
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
911
|
+
method: "post",
|
912
|
+
...variables,
|
913
|
+
signal
|
914
|
+
});
|
915
|
+
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
916
|
+
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
917
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
918
|
+
url: "/file/{fileId}",
|
919
|
+
method: "get",
|
920
|
+
...variables,
|
921
|
+
signal
|
922
|
+
});
|
923
|
+
const operationsByTag$2 = {
|
502
924
|
branch: {
|
503
925
|
getBranchList,
|
504
|
-
getDatabaseMetadata,
|
505
926
|
getBranchDetails,
|
506
927
|
createBranch,
|
507
928
|
deleteBranch,
|
929
|
+
copyBranch,
|
508
930
|
updateBranchMetadata,
|
509
931
|
getBranchMetadata,
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
932
|
+
getBranchStats,
|
933
|
+
getGitBranchesMapping,
|
934
|
+
addGitBranchesEntry,
|
935
|
+
removeGitBranchesEntry,
|
936
|
+
resolveBranch
|
937
|
+
},
|
938
|
+
migrations: {
|
939
|
+
getBranchMigrationHistory,
|
940
|
+
getBranchMigrationPlan,
|
941
|
+
executeBranchMigrationPlan,
|
942
|
+
getBranchSchemaHistory,
|
943
|
+
compareBranchWithUserSchema,
|
944
|
+
compareBranchSchemas,
|
945
|
+
updateBranchSchema,
|
946
|
+
previewBranchSchemaEdit,
|
947
|
+
applyBranchSchemaEdit,
|
948
|
+
pushBranchMigrations
|
949
|
+
},
|
950
|
+
migrationRequests: {
|
951
|
+
queryMigrationRequests,
|
952
|
+
createMigrationRequest,
|
953
|
+
getMigrationRequest,
|
954
|
+
updateMigrationRequest,
|
955
|
+
listMigrationRequestsCommits,
|
956
|
+
compareMigrationRequest,
|
957
|
+
getMigrationRequestIsMerged,
|
958
|
+
mergeMigrationRequest
|
959
|
+
},
|
515
960
|
table: {
|
516
961
|
createTable,
|
517
962
|
deleteTable,
|
@@ -521,27 +966,178 @@ const operationsByTag = {
|
|
521
966
|
getTableColumns,
|
522
967
|
addTableColumn,
|
523
968
|
getColumn,
|
524
|
-
|
525
|
-
|
969
|
+
updateColumn,
|
970
|
+
deleteColumn
|
526
971
|
},
|
527
972
|
records: {
|
973
|
+
branchTransaction,
|
528
974
|
insertRecord,
|
975
|
+
getRecord,
|
529
976
|
insertRecordWithID,
|
530
977
|
updateRecordWithID,
|
531
978
|
upsertRecordWithID,
|
532
979
|
deleteRecord,
|
533
|
-
|
534
|
-
|
980
|
+
bulkInsertTableRecords
|
981
|
+
},
|
982
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
983
|
+
searchAndFilter: {
|
535
984
|
queryTable,
|
985
|
+
searchBranch,
|
536
986
|
searchTable,
|
537
|
-
|
987
|
+
sqlQuery,
|
988
|
+
vectorSearchTable,
|
989
|
+
askTable,
|
990
|
+
summarizeTable,
|
991
|
+
aggregateTable
|
992
|
+
}
|
993
|
+
};
|
994
|
+
|
995
|
+
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
996
|
+
|
997
|
+
const getUser = (variables, signal) => controlPlaneFetch({
|
998
|
+
url: "/user",
|
999
|
+
method: "get",
|
1000
|
+
...variables,
|
1001
|
+
signal
|
1002
|
+
});
|
1003
|
+
const updateUser = (variables, signal) => controlPlaneFetch({
|
1004
|
+
url: "/user",
|
1005
|
+
method: "put",
|
1006
|
+
...variables,
|
1007
|
+
signal
|
1008
|
+
});
|
1009
|
+
const deleteUser = (variables, signal) => controlPlaneFetch({
|
1010
|
+
url: "/user",
|
1011
|
+
method: "delete",
|
1012
|
+
...variables,
|
1013
|
+
signal
|
1014
|
+
});
|
1015
|
+
const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
1016
|
+
url: "/user/keys",
|
1017
|
+
method: "get",
|
1018
|
+
...variables,
|
1019
|
+
signal
|
1020
|
+
});
|
1021
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
1022
|
+
url: "/user/keys/{keyName}",
|
1023
|
+
method: "post",
|
1024
|
+
...variables,
|
1025
|
+
signal
|
1026
|
+
});
|
1027
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
1028
|
+
url: "/user/keys/{keyName}",
|
1029
|
+
method: "delete",
|
1030
|
+
...variables,
|
1031
|
+
signal
|
1032
|
+
});
|
1033
|
+
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
1034
|
+
url: "/workspaces",
|
1035
|
+
method: "get",
|
1036
|
+
...variables,
|
1037
|
+
signal
|
1038
|
+
});
|
1039
|
+
const createWorkspace = (variables, signal) => controlPlaneFetch({
|
1040
|
+
url: "/workspaces",
|
1041
|
+
method: "post",
|
1042
|
+
...variables,
|
1043
|
+
signal
|
1044
|
+
});
|
1045
|
+
const getWorkspace = (variables, signal) => controlPlaneFetch({
|
1046
|
+
url: "/workspaces/{workspaceId}",
|
1047
|
+
method: "get",
|
1048
|
+
...variables,
|
1049
|
+
signal
|
1050
|
+
});
|
1051
|
+
const updateWorkspace = (variables, signal) => controlPlaneFetch({
|
1052
|
+
url: "/workspaces/{workspaceId}",
|
1053
|
+
method: "put",
|
1054
|
+
...variables,
|
1055
|
+
signal
|
1056
|
+
});
|
1057
|
+
const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
1058
|
+
url: "/workspaces/{workspaceId}",
|
1059
|
+
method: "delete",
|
1060
|
+
...variables,
|
1061
|
+
signal
|
1062
|
+
});
|
1063
|
+
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
1064
|
+
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
1065
|
+
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
1066
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
1067
|
+
method: "delete",
|
1068
|
+
...variables,
|
1069
|
+
signal
|
1070
|
+
});
|
1071
|
+
const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
1072
|
+
const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
1073
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1074
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1075
|
+
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1076
|
+
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
1077
|
+
url: "/workspaces/{workspaceId}/dbs",
|
1078
|
+
method: "get",
|
1079
|
+
...variables,
|
1080
|
+
signal
|
1081
|
+
});
|
1082
|
+
const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
1083
|
+
const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
1084
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
1085
|
+
method: "delete",
|
1086
|
+
...variables,
|
1087
|
+
signal
|
1088
|
+
});
|
1089
|
+
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
1090
|
+
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1091
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1092
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1093
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1094
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
1095
|
+
const listRegions = (variables, signal) => controlPlaneFetch({
|
1096
|
+
url: "/workspaces/{workspaceId}/regions",
|
1097
|
+
method: "get",
|
1098
|
+
...variables,
|
1099
|
+
signal
|
1100
|
+
});
|
1101
|
+
const operationsByTag$1 = {
|
1102
|
+
users: { getUser, updateUser, deleteUser },
|
1103
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
1104
|
+
workspaces: {
|
1105
|
+
getWorkspacesList,
|
1106
|
+
createWorkspace,
|
1107
|
+
getWorkspace,
|
1108
|
+
updateWorkspace,
|
1109
|
+
deleteWorkspace,
|
1110
|
+
getWorkspaceMembersList,
|
1111
|
+
updateWorkspaceMemberRole,
|
1112
|
+
removeWorkspaceMember
|
1113
|
+
},
|
1114
|
+
invites: {
|
1115
|
+
inviteWorkspaceMember,
|
1116
|
+
updateWorkspaceMemberInvite,
|
1117
|
+
cancelWorkspaceMemberInvite,
|
1118
|
+
acceptWorkspaceMemberInvite,
|
1119
|
+
resendWorkspaceMemberInvite
|
1120
|
+
},
|
1121
|
+
databases: {
|
1122
|
+
getDatabaseList,
|
1123
|
+
createDatabase,
|
1124
|
+
deleteDatabase,
|
1125
|
+
getDatabaseMetadata,
|
1126
|
+
updateDatabaseMetadata,
|
1127
|
+
renameDatabase,
|
1128
|
+
getDatabaseGithubSettings,
|
1129
|
+
updateDatabaseGithubSettings,
|
1130
|
+
deleteDatabaseGithubSettings,
|
1131
|
+
listRegions
|
538
1132
|
}
|
539
1133
|
};
|
540
1134
|
|
1135
|
+
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
1136
|
+
|
541
1137
|
function getHostUrl(provider, type) {
|
542
|
-
if (
|
1138
|
+
if (isHostProviderAlias(provider)) {
|
543
1139
|
return providers[provider][type];
|
544
|
-
} else if (
|
1140
|
+
} else if (isHostProviderBuilder(provider)) {
|
545
1141
|
return provider[type];
|
546
1142
|
}
|
547
1143
|
throw new Error("Invalid API provider");
|
@@ -549,19 +1145,49 @@ function getHostUrl(provider, type) {
|
|
549
1145
|
const providers = {
|
550
1146
|
production: {
|
551
1147
|
main: "https://api.xata.io",
|
552
|
-
workspaces: "https://{workspaceId}.xata.sh"
|
1148
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
553
1149
|
},
|
554
1150
|
staging: {
|
555
|
-
main: "https://staging.
|
556
|
-
workspaces: "https://{workspaceId}.staging.
|
1151
|
+
main: "https://api.staging-xata.dev",
|
1152
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
1153
|
+
},
|
1154
|
+
dev: {
|
1155
|
+
main: "https://api.dev-xata.dev",
|
1156
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
557
1157
|
}
|
558
1158
|
};
|
559
|
-
function
|
1159
|
+
function isHostProviderAlias(alias) {
|
560
1160
|
return isString(alias) && Object.keys(providers).includes(alias);
|
561
1161
|
}
|
562
|
-
function
|
1162
|
+
function isHostProviderBuilder(builder) {
|
563
1163
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
564
1164
|
}
|
1165
|
+
function parseProviderString(provider = "production") {
|
1166
|
+
if (isHostProviderAlias(provider)) {
|
1167
|
+
return provider;
|
1168
|
+
}
|
1169
|
+
const [main, workspaces] = provider.split(",");
|
1170
|
+
if (!main || !workspaces)
|
1171
|
+
return null;
|
1172
|
+
return { main, workspaces };
|
1173
|
+
}
|
1174
|
+
function buildProviderString(provider) {
|
1175
|
+
if (isHostProviderAlias(provider))
|
1176
|
+
return provider;
|
1177
|
+
return `${provider.main},${provider.workspaces}`;
|
1178
|
+
}
|
1179
|
+
function parseWorkspacesUrlParts(url) {
|
1180
|
+
if (!isString(url))
|
1181
|
+
return null;
|
1182
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
1183
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
1184
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
1185
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
1186
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
1187
|
+
if (!match)
|
1188
|
+
return null;
|
1189
|
+
return { workspace: match[1], region: match[2] };
|
1190
|
+
}
|
565
1191
|
|
566
1192
|
var __accessCheck$7 = (obj, member, msg) => {
|
567
1193
|
if (!member.has(obj))
|
@@ -587,15 +1213,21 @@ class XataApiClient {
|
|
587
1213
|
__privateAdd$7(this, _extraProps, void 0);
|
588
1214
|
__privateAdd$7(this, _namespaces, {});
|
589
1215
|
const provider = options.host ?? "production";
|
590
|
-
const apiKey = options
|
1216
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
1217
|
+
const trace = options.trace ?? defaultTrace;
|
1218
|
+
const clientID = generateUUID();
|
591
1219
|
if (!apiKey) {
|
592
1220
|
throw new Error("Could not resolve a valid apiKey");
|
593
1221
|
}
|
594
1222
|
__privateSet$7(this, _extraProps, {
|
595
1223
|
apiUrl: getHostUrl(provider, "main"),
|
596
1224
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
597
|
-
|
598
|
-
apiKey
|
1225
|
+
fetch: getFetchImplementation(options.fetch),
|
1226
|
+
apiKey,
|
1227
|
+
trace,
|
1228
|
+
clientName: options.clientName,
|
1229
|
+
xataAgentExtra: options.xataAgentExtra,
|
1230
|
+
clientID
|
599
1231
|
});
|
600
1232
|
}
|
601
1233
|
get user() {
|
@@ -603,21 +1235,41 @@ class XataApiClient {
|
|
603
1235
|
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
604
1236
|
return __privateGet$7(this, _namespaces).user;
|
605
1237
|
}
|
1238
|
+
get authentication() {
|
1239
|
+
if (!__privateGet$7(this, _namespaces).authentication)
|
1240
|
+
__privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
|
1241
|
+
return __privateGet$7(this, _namespaces).authentication;
|
1242
|
+
}
|
606
1243
|
get workspaces() {
|
607
1244
|
if (!__privateGet$7(this, _namespaces).workspaces)
|
608
1245
|
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
609
1246
|
return __privateGet$7(this, _namespaces).workspaces;
|
610
1247
|
}
|
611
|
-
get
|
612
|
-
if (!__privateGet$7(this, _namespaces).
|
613
|
-
__privateGet$7(this, _namespaces).
|
614
|
-
return __privateGet$7(this, _namespaces).
|
1248
|
+
get invites() {
|
1249
|
+
if (!__privateGet$7(this, _namespaces).invites)
|
1250
|
+
__privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
|
1251
|
+
return __privateGet$7(this, _namespaces).invites;
|
1252
|
+
}
|
1253
|
+
get database() {
|
1254
|
+
if (!__privateGet$7(this, _namespaces).database)
|
1255
|
+
__privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
|
1256
|
+
return __privateGet$7(this, _namespaces).database;
|
615
1257
|
}
|
616
1258
|
get branches() {
|
617
1259
|
if (!__privateGet$7(this, _namespaces).branches)
|
618
1260
|
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
619
1261
|
return __privateGet$7(this, _namespaces).branches;
|
620
1262
|
}
|
1263
|
+
get migrations() {
|
1264
|
+
if (!__privateGet$7(this, _namespaces).migrations)
|
1265
|
+
__privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
|
1266
|
+
return __privateGet$7(this, _namespaces).migrations;
|
1267
|
+
}
|
1268
|
+
get migrationRequests() {
|
1269
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
1270
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
1271
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
1272
|
+
}
|
621
1273
|
get tables() {
|
622
1274
|
if (!__privateGet$7(this, _namespaces).tables)
|
623
1275
|
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
@@ -628,6 +1280,16 @@ class XataApiClient {
|
|
628
1280
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
629
1281
|
return __privateGet$7(this, _namespaces).records;
|
630
1282
|
}
|
1283
|
+
get files() {
|
1284
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1285
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1286
|
+
return __privateGet$7(this, _namespaces).files;
|
1287
|
+
}
|
1288
|
+
get searchAndFilter() {
|
1289
|
+
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
1290
|
+
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
1291
|
+
return __privateGet$7(this, _namespaces).searchAndFilter;
|
1292
|
+
}
|
631
1293
|
}
|
632
1294
|
_extraProps = new WeakMap();
|
633
1295
|
_namespaces = new WeakMap();
|
@@ -638,24 +1300,29 @@ class UserApi {
|
|
638
1300
|
getUser() {
|
639
1301
|
return operationsByTag.users.getUser({ ...this.extraProps });
|
640
1302
|
}
|
641
|
-
updateUser(user) {
|
1303
|
+
updateUser({ user }) {
|
642
1304
|
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
643
1305
|
}
|
644
1306
|
deleteUser() {
|
645
1307
|
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
646
1308
|
}
|
1309
|
+
}
|
1310
|
+
class AuthenticationApi {
|
1311
|
+
constructor(extraProps) {
|
1312
|
+
this.extraProps = extraProps;
|
1313
|
+
}
|
647
1314
|
getUserAPIKeys() {
|
648
|
-
return operationsByTag.
|
1315
|
+
return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
|
649
1316
|
}
|
650
|
-
createUserAPIKey(
|
651
|
-
return operationsByTag.
|
652
|
-
pathParams: { keyName },
|
1317
|
+
createUserAPIKey({ name }) {
|
1318
|
+
return operationsByTag.authentication.createUserAPIKey({
|
1319
|
+
pathParams: { keyName: name },
|
653
1320
|
...this.extraProps
|
654
1321
|
});
|
655
1322
|
}
|
656
|
-
deleteUserAPIKey(
|
657
|
-
return operationsByTag.
|
658
|
-
pathParams: { keyName },
|
1323
|
+
deleteUserAPIKey({ name }) {
|
1324
|
+
return operationsByTag.authentication.deleteUserAPIKey({
|
1325
|
+
pathParams: { keyName: name },
|
659
1326
|
...this.extraProps
|
660
1327
|
});
|
661
1328
|
}
|
@@ -664,368 +1331,1178 @@ class WorkspaceApi {
|
|
664
1331
|
constructor(extraProps) {
|
665
1332
|
this.extraProps = extraProps;
|
666
1333
|
}
|
667
|
-
|
1334
|
+
getWorkspacesList() {
|
1335
|
+
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
1336
|
+
}
|
1337
|
+
createWorkspace({ data }) {
|
668
1338
|
return operationsByTag.workspaces.createWorkspace({
|
669
|
-
body:
|
1339
|
+
body: data,
|
670
1340
|
...this.extraProps
|
671
1341
|
});
|
672
1342
|
}
|
673
|
-
|
674
|
-
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
675
|
-
}
|
676
|
-
getWorkspace(workspaceId) {
|
1343
|
+
getWorkspace({ workspace }) {
|
677
1344
|
return operationsByTag.workspaces.getWorkspace({
|
678
|
-
pathParams: { workspaceId },
|
1345
|
+
pathParams: { workspaceId: workspace },
|
679
1346
|
...this.extraProps
|
680
1347
|
});
|
681
1348
|
}
|
682
|
-
updateWorkspace(
|
1349
|
+
updateWorkspace({
|
1350
|
+
workspace,
|
1351
|
+
update
|
1352
|
+
}) {
|
683
1353
|
return operationsByTag.workspaces.updateWorkspace({
|
684
|
-
pathParams: { workspaceId },
|
685
|
-
body:
|
1354
|
+
pathParams: { workspaceId: workspace },
|
1355
|
+
body: update,
|
686
1356
|
...this.extraProps
|
687
1357
|
});
|
688
1358
|
}
|
689
|
-
deleteWorkspace(
|
1359
|
+
deleteWorkspace({ workspace }) {
|
690
1360
|
return operationsByTag.workspaces.deleteWorkspace({
|
691
|
-
pathParams: { workspaceId },
|
1361
|
+
pathParams: { workspaceId: workspace },
|
692
1362
|
...this.extraProps
|
693
1363
|
});
|
694
1364
|
}
|
695
|
-
getWorkspaceMembersList(
|
1365
|
+
getWorkspaceMembersList({ workspace }) {
|
696
1366
|
return operationsByTag.workspaces.getWorkspaceMembersList({
|
697
|
-
pathParams: { workspaceId },
|
1367
|
+
pathParams: { workspaceId: workspace },
|
698
1368
|
...this.extraProps
|
699
1369
|
});
|
700
1370
|
}
|
701
|
-
updateWorkspaceMemberRole(
|
1371
|
+
updateWorkspaceMemberRole({
|
1372
|
+
workspace,
|
1373
|
+
user,
|
1374
|
+
role
|
1375
|
+
}) {
|
702
1376
|
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
703
|
-
pathParams: { workspaceId, userId },
|
1377
|
+
pathParams: { workspaceId: workspace, userId: user },
|
704
1378
|
body: { role },
|
705
1379
|
...this.extraProps
|
706
1380
|
});
|
707
1381
|
}
|
708
|
-
removeWorkspaceMember(
|
1382
|
+
removeWorkspaceMember({
|
1383
|
+
workspace,
|
1384
|
+
user
|
1385
|
+
}) {
|
709
1386
|
return operationsByTag.workspaces.removeWorkspaceMember({
|
710
|
-
pathParams: { workspaceId, userId },
|
1387
|
+
pathParams: { workspaceId: workspace, userId: user },
|
711
1388
|
...this.extraProps
|
712
1389
|
});
|
713
1390
|
}
|
714
|
-
|
715
|
-
|
716
|
-
|
1391
|
+
}
|
1392
|
+
class InvitesApi {
|
1393
|
+
constructor(extraProps) {
|
1394
|
+
this.extraProps = extraProps;
|
1395
|
+
}
|
1396
|
+
inviteWorkspaceMember({
|
1397
|
+
workspace,
|
1398
|
+
email,
|
1399
|
+
role
|
1400
|
+
}) {
|
1401
|
+
return operationsByTag.invites.inviteWorkspaceMember({
|
1402
|
+
pathParams: { workspaceId: workspace },
|
717
1403
|
body: { email, role },
|
718
1404
|
...this.extraProps
|
719
1405
|
});
|
720
1406
|
}
|
721
|
-
updateWorkspaceMemberInvite(
|
722
|
-
|
723
|
-
|
1407
|
+
updateWorkspaceMemberInvite({
|
1408
|
+
workspace,
|
1409
|
+
invite,
|
1410
|
+
role
|
1411
|
+
}) {
|
1412
|
+
return operationsByTag.invites.updateWorkspaceMemberInvite({
|
1413
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
724
1414
|
body: { role },
|
725
1415
|
...this.extraProps
|
726
1416
|
});
|
727
1417
|
}
|
728
|
-
cancelWorkspaceMemberInvite(
|
729
|
-
|
730
|
-
|
1418
|
+
cancelWorkspaceMemberInvite({
|
1419
|
+
workspace,
|
1420
|
+
invite
|
1421
|
+
}) {
|
1422
|
+
return operationsByTag.invites.cancelWorkspaceMemberInvite({
|
1423
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
731
1424
|
...this.extraProps
|
732
1425
|
});
|
733
1426
|
}
|
734
|
-
|
735
|
-
|
736
|
-
|
1427
|
+
acceptWorkspaceMemberInvite({
|
1428
|
+
workspace,
|
1429
|
+
key
|
1430
|
+
}) {
|
1431
|
+
return operationsByTag.invites.acceptWorkspaceMemberInvite({
|
1432
|
+
pathParams: { workspaceId: workspace, inviteKey: key },
|
737
1433
|
...this.extraProps
|
738
1434
|
});
|
739
1435
|
}
|
740
|
-
|
741
|
-
|
742
|
-
|
1436
|
+
resendWorkspaceMemberInvite({
|
1437
|
+
workspace,
|
1438
|
+
invite
|
1439
|
+
}) {
|
1440
|
+
return operationsByTag.invites.resendWorkspaceMemberInvite({
|
1441
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
743
1442
|
...this.extraProps
|
744
1443
|
});
|
745
1444
|
}
|
746
1445
|
}
|
747
|
-
class
|
1446
|
+
class BranchApi {
|
748
1447
|
constructor(extraProps) {
|
749
1448
|
this.extraProps = extraProps;
|
750
1449
|
}
|
751
|
-
|
752
|
-
|
753
|
-
|
1450
|
+
getBranchList({
|
1451
|
+
workspace,
|
1452
|
+
region,
|
1453
|
+
database
|
1454
|
+
}) {
|
1455
|
+
return operationsByTag.branch.getBranchList({
|
1456
|
+
pathParams: { workspace, region, dbName: database },
|
1457
|
+
...this.extraProps
|
1458
|
+
});
|
1459
|
+
}
|
1460
|
+
getBranchDetails({
|
1461
|
+
workspace,
|
1462
|
+
region,
|
1463
|
+
database,
|
1464
|
+
branch
|
1465
|
+
}) {
|
1466
|
+
return operationsByTag.branch.getBranchDetails({
|
1467
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
754
1468
|
...this.extraProps
|
755
1469
|
});
|
756
1470
|
}
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
1471
|
+
createBranch({
|
1472
|
+
workspace,
|
1473
|
+
region,
|
1474
|
+
database,
|
1475
|
+
branch,
|
1476
|
+
from,
|
1477
|
+
metadata
|
1478
|
+
}) {
|
1479
|
+
return operationsByTag.branch.createBranch({
|
1480
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1481
|
+
body: { from, metadata },
|
761
1482
|
...this.extraProps
|
762
1483
|
});
|
763
1484
|
}
|
764
|
-
|
765
|
-
|
766
|
-
|
1485
|
+
deleteBranch({
|
1486
|
+
workspace,
|
1487
|
+
region,
|
1488
|
+
database,
|
1489
|
+
branch
|
1490
|
+
}) {
|
1491
|
+
return operationsByTag.branch.deleteBranch({
|
1492
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
767
1493
|
...this.extraProps
|
768
1494
|
});
|
769
1495
|
}
|
770
|
-
|
771
|
-
|
772
|
-
|
1496
|
+
copyBranch({
|
1497
|
+
workspace,
|
1498
|
+
region,
|
1499
|
+
database,
|
1500
|
+
branch,
|
1501
|
+
destinationBranch,
|
1502
|
+
limit
|
1503
|
+
}) {
|
1504
|
+
return operationsByTag.branch.copyBranch({
|
1505
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1506
|
+
body: { destinationBranch, limit },
|
773
1507
|
...this.extraProps
|
774
1508
|
});
|
775
1509
|
}
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
1510
|
+
updateBranchMetadata({
|
1511
|
+
workspace,
|
1512
|
+
region,
|
1513
|
+
database,
|
1514
|
+
branch,
|
1515
|
+
metadata
|
1516
|
+
}) {
|
1517
|
+
return operationsByTag.branch.updateBranchMetadata({
|
1518
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1519
|
+
body: metadata,
|
780
1520
|
...this.extraProps
|
781
1521
|
});
|
782
1522
|
}
|
783
|
-
|
784
|
-
|
785
|
-
|
1523
|
+
getBranchMetadata({
|
1524
|
+
workspace,
|
1525
|
+
region,
|
1526
|
+
database,
|
1527
|
+
branch
|
1528
|
+
}) {
|
1529
|
+
return operationsByTag.branch.getBranchMetadata({
|
1530
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1531
|
+
...this.extraProps
|
1532
|
+
});
|
1533
|
+
}
|
1534
|
+
getBranchStats({
|
1535
|
+
workspace,
|
1536
|
+
region,
|
1537
|
+
database,
|
1538
|
+
branch
|
1539
|
+
}) {
|
1540
|
+
return operationsByTag.branch.getBranchStats({
|
1541
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1542
|
+
...this.extraProps
|
1543
|
+
});
|
1544
|
+
}
|
1545
|
+
getGitBranchesMapping({
|
1546
|
+
workspace,
|
1547
|
+
region,
|
1548
|
+
database
|
1549
|
+
}) {
|
1550
|
+
return operationsByTag.branch.getGitBranchesMapping({
|
1551
|
+
pathParams: { workspace, region, dbName: database },
|
1552
|
+
...this.extraProps
|
1553
|
+
});
|
1554
|
+
}
|
1555
|
+
addGitBranchesEntry({
|
1556
|
+
workspace,
|
1557
|
+
region,
|
1558
|
+
database,
|
1559
|
+
gitBranch,
|
1560
|
+
xataBranch
|
1561
|
+
}) {
|
1562
|
+
return operationsByTag.branch.addGitBranchesEntry({
|
1563
|
+
pathParams: { workspace, region, dbName: database },
|
1564
|
+
body: { gitBranch, xataBranch },
|
1565
|
+
...this.extraProps
|
1566
|
+
});
|
1567
|
+
}
|
1568
|
+
removeGitBranchesEntry({
|
1569
|
+
workspace,
|
1570
|
+
region,
|
1571
|
+
database,
|
1572
|
+
gitBranch
|
1573
|
+
}) {
|
1574
|
+
return operationsByTag.branch.removeGitBranchesEntry({
|
1575
|
+
pathParams: { workspace, region, dbName: database },
|
786
1576
|
queryParams: { gitBranch },
|
787
1577
|
...this.extraProps
|
788
1578
|
});
|
789
1579
|
}
|
790
|
-
resolveBranch(
|
791
|
-
|
792
|
-
|
1580
|
+
resolveBranch({
|
1581
|
+
workspace,
|
1582
|
+
region,
|
1583
|
+
database,
|
1584
|
+
gitBranch,
|
1585
|
+
fallbackBranch
|
1586
|
+
}) {
|
1587
|
+
return operationsByTag.branch.resolveBranch({
|
1588
|
+
pathParams: { workspace, region, dbName: database },
|
793
1589
|
queryParams: { gitBranch, fallbackBranch },
|
794
1590
|
...this.extraProps
|
795
1591
|
});
|
796
1592
|
}
|
797
1593
|
}
|
798
|
-
class
|
1594
|
+
class TableApi {
|
799
1595
|
constructor(extraProps) {
|
800
1596
|
this.extraProps = extraProps;
|
801
1597
|
}
|
802
|
-
|
803
|
-
|
804
|
-
|
1598
|
+
createTable({
|
1599
|
+
workspace,
|
1600
|
+
region,
|
1601
|
+
database,
|
1602
|
+
branch,
|
1603
|
+
table
|
1604
|
+
}) {
|
1605
|
+
return operationsByTag.table.createTable({
|
1606
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
805
1607
|
...this.extraProps
|
806
1608
|
});
|
807
1609
|
}
|
808
|
-
|
809
|
-
|
810
|
-
|
1610
|
+
deleteTable({
|
1611
|
+
workspace,
|
1612
|
+
region,
|
1613
|
+
database,
|
1614
|
+
branch,
|
1615
|
+
table
|
1616
|
+
}) {
|
1617
|
+
return operationsByTag.table.deleteTable({
|
1618
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
811
1619
|
...this.extraProps
|
812
1620
|
});
|
813
1621
|
}
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
1622
|
+
updateTable({
|
1623
|
+
workspace,
|
1624
|
+
region,
|
1625
|
+
database,
|
1626
|
+
branch,
|
1627
|
+
table,
|
1628
|
+
update
|
1629
|
+
}) {
|
1630
|
+
return operationsByTag.table.updateTable({
|
1631
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1632
|
+
body: update,
|
819
1633
|
...this.extraProps
|
820
1634
|
});
|
821
1635
|
}
|
822
|
-
|
823
|
-
|
824
|
-
|
1636
|
+
getTableSchema({
|
1637
|
+
workspace,
|
1638
|
+
region,
|
1639
|
+
database,
|
1640
|
+
branch,
|
1641
|
+
table
|
1642
|
+
}) {
|
1643
|
+
return operationsByTag.table.getTableSchema({
|
1644
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
825
1645
|
...this.extraProps
|
826
1646
|
});
|
827
1647
|
}
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
1648
|
+
setTableSchema({
|
1649
|
+
workspace,
|
1650
|
+
region,
|
1651
|
+
database,
|
1652
|
+
branch,
|
1653
|
+
table,
|
1654
|
+
schema
|
1655
|
+
}) {
|
1656
|
+
return operationsByTag.table.setTableSchema({
|
1657
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1658
|
+
body: schema,
|
832
1659
|
...this.extraProps
|
833
1660
|
});
|
834
1661
|
}
|
835
|
-
|
836
|
-
|
837
|
-
|
1662
|
+
getTableColumns({
|
1663
|
+
workspace,
|
1664
|
+
region,
|
1665
|
+
database,
|
1666
|
+
branch,
|
1667
|
+
table
|
1668
|
+
}) {
|
1669
|
+
return operationsByTag.table.getTableColumns({
|
1670
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
838
1671
|
...this.extraProps
|
839
1672
|
});
|
840
1673
|
}
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
1674
|
+
addTableColumn({
|
1675
|
+
workspace,
|
1676
|
+
region,
|
1677
|
+
database,
|
1678
|
+
branch,
|
1679
|
+
table,
|
1680
|
+
column
|
1681
|
+
}) {
|
1682
|
+
return operationsByTag.table.addTableColumn({
|
1683
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1684
|
+
body: column,
|
845
1685
|
...this.extraProps
|
846
1686
|
});
|
847
1687
|
}
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
1688
|
+
getColumn({
|
1689
|
+
workspace,
|
1690
|
+
region,
|
1691
|
+
database,
|
1692
|
+
branch,
|
1693
|
+
table,
|
1694
|
+
column
|
1695
|
+
}) {
|
1696
|
+
return operationsByTag.table.getColumn({
|
1697
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
852
1698
|
...this.extraProps
|
853
1699
|
});
|
854
1700
|
}
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
1701
|
+
updateColumn({
|
1702
|
+
workspace,
|
1703
|
+
region,
|
1704
|
+
database,
|
1705
|
+
branch,
|
1706
|
+
table,
|
1707
|
+
column,
|
1708
|
+
update
|
1709
|
+
}) {
|
1710
|
+
return operationsByTag.table.updateColumn({
|
1711
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1712
|
+
body: update,
|
859
1713
|
...this.extraProps
|
860
1714
|
});
|
861
1715
|
}
|
862
|
-
|
863
|
-
|
864
|
-
|
1716
|
+
deleteColumn({
|
1717
|
+
workspace,
|
1718
|
+
region,
|
1719
|
+
database,
|
1720
|
+
branch,
|
1721
|
+
table,
|
1722
|
+
column
|
1723
|
+
}) {
|
1724
|
+
return operationsByTag.table.deleteColumn({
|
1725
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
865
1726
|
...this.extraProps
|
866
1727
|
});
|
867
1728
|
}
|
868
1729
|
}
|
869
|
-
class
|
1730
|
+
class RecordsApi {
|
870
1731
|
constructor(extraProps) {
|
871
1732
|
this.extraProps = extraProps;
|
872
1733
|
}
|
873
|
-
|
874
|
-
|
875
|
-
|
1734
|
+
insertRecord({
|
1735
|
+
workspace,
|
1736
|
+
region,
|
1737
|
+
database,
|
1738
|
+
branch,
|
1739
|
+
table,
|
1740
|
+
record,
|
1741
|
+
columns
|
1742
|
+
}) {
|
1743
|
+
return operationsByTag.records.insertRecord({
|
1744
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1745
|
+
queryParams: { columns },
|
1746
|
+
body: record,
|
876
1747
|
...this.extraProps
|
877
1748
|
});
|
878
1749
|
}
|
879
|
-
|
880
|
-
|
881
|
-
|
1750
|
+
getRecord({
|
1751
|
+
workspace,
|
1752
|
+
region,
|
1753
|
+
database,
|
1754
|
+
branch,
|
1755
|
+
table,
|
1756
|
+
id,
|
1757
|
+
columns
|
1758
|
+
}) {
|
1759
|
+
return operationsByTag.records.getRecord({
|
1760
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1761
|
+
queryParams: { columns },
|
882
1762
|
...this.extraProps
|
883
1763
|
});
|
884
1764
|
}
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
1765
|
+
insertRecordWithID({
|
1766
|
+
workspace,
|
1767
|
+
region,
|
1768
|
+
database,
|
1769
|
+
branch,
|
1770
|
+
table,
|
1771
|
+
id,
|
1772
|
+
record,
|
1773
|
+
columns,
|
1774
|
+
createOnly,
|
1775
|
+
ifVersion
|
1776
|
+
}) {
|
1777
|
+
return operationsByTag.records.insertRecordWithID({
|
1778
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1779
|
+
queryParams: { columns, createOnly, ifVersion },
|
1780
|
+
body: record,
|
889
1781
|
...this.extraProps
|
890
1782
|
});
|
891
1783
|
}
|
892
|
-
|
893
|
-
|
894
|
-
|
1784
|
+
updateRecordWithID({
|
1785
|
+
workspace,
|
1786
|
+
region,
|
1787
|
+
database,
|
1788
|
+
branch,
|
1789
|
+
table,
|
1790
|
+
id,
|
1791
|
+
record,
|
1792
|
+
columns,
|
1793
|
+
ifVersion
|
1794
|
+
}) {
|
1795
|
+
return operationsByTag.records.updateRecordWithID({
|
1796
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1797
|
+
queryParams: { columns, ifVersion },
|
1798
|
+
body: record,
|
895
1799
|
...this.extraProps
|
896
1800
|
});
|
897
1801
|
}
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
1802
|
+
upsertRecordWithID({
|
1803
|
+
workspace,
|
1804
|
+
region,
|
1805
|
+
database,
|
1806
|
+
branch,
|
1807
|
+
table,
|
1808
|
+
id,
|
1809
|
+
record,
|
1810
|
+
columns,
|
1811
|
+
ifVersion
|
1812
|
+
}) {
|
1813
|
+
return operationsByTag.records.upsertRecordWithID({
|
1814
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1815
|
+
queryParams: { columns, ifVersion },
|
1816
|
+
body: record,
|
902
1817
|
...this.extraProps
|
903
1818
|
});
|
904
1819
|
}
|
905
|
-
|
906
|
-
|
907
|
-
|
1820
|
+
deleteRecord({
|
1821
|
+
workspace,
|
1822
|
+
region,
|
1823
|
+
database,
|
1824
|
+
branch,
|
1825
|
+
table,
|
1826
|
+
id,
|
1827
|
+
columns
|
1828
|
+
}) {
|
1829
|
+
return operationsByTag.records.deleteRecord({
|
1830
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1831
|
+
queryParams: { columns },
|
908
1832
|
...this.extraProps
|
909
1833
|
});
|
910
1834
|
}
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
1835
|
+
bulkInsertTableRecords({
|
1836
|
+
workspace,
|
1837
|
+
region,
|
1838
|
+
database,
|
1839
|
+
branch,
|
1840
|
+
table,
|
1841
|
+
records,
|
1842
|
+
columns
|
1843
|
+
}) {
|
1844
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
1845
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1846
|
+
queryParams: { columns },
|
1847
|
+
body: { records },
|
915
1848
|
...this.extraProps
|
916
1849
|
});
|
917
1850
|
}
|
918
|
-
|
919
|
-
|
920
|
-
|
1851
|
+
branchTransaction({
|
1852
|
+
workspace,
|
1853
|
+
region,
|
1854
|
+
database,
|
1855
|
+
branch,
|
1856
|
+
operations
|
1857
|
+
}) {
|
1858
|
+
return operationsByTag.records.branchTransaction({
|
1859
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1860
|
+
body: { operations },
|
921
1861
|
...this.extraProps
|
922
1862
|
});
|
923
1863
|
}
|
924
|
-
|
925
|
-
|
926
|
-
|
1864
|
+
}
|
1865
|
+
class FilesApi {
|
1866
|
+
constructor(extraProps) {
|
1867
|
+
this.extraProps = extraProps;
|
1868
|
+
}
|
1869
|
+
getFileItem({
|
1870
|
+
workspace,
|
1871
|
+
region,
|
1872
|
+
database,
|
1873
|
+
branch,
|
1874
|
+
table,
|
1875
|
+
record,
|
1876
|
+
column,
|
1877
|
+
fileId
|
1878
|
+
}) {
|
1879
|
+
return operationsByTag.files.getFileItem({
|
1880
|
+
pathParams: {
|
1881
|
+
workspace,
|
1882
|
+
region,
|
1883
|
+
dbBranchName: `${database}:${branch}`,
|
1884
|
+
tableName: table,
|
1885
|
+
recordId: record,
|
1886
|
+
columnName: column,
|
1887
|
+
fileId
|
1888
|
+
},
|
927
1889
|
...this.extraProps
|
928
1890
|
});
|
929
1891
|
}
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
1892
|
+
putFileItem({
|
1893
|
+
workspace,
|
1894
|
+
region,
|
1895
|
+
database,
|
1896
|
+
branch,
|
1897
|
+
table,
|
1898
|
+
record,
|
1899
|
+
column,
|
1900
|
+
fileId,
|
1901
|
+
file
|
1902
|
+
}) {
|
1903
|
+
return operationsByTag.files.putFileItem({
|
1904
|
+
pathParams: {
|
1905
|
+
workspace,
|
1906
|
+
region,
|
1907
|
+
dbBranchName: `${database}:${branch}`,
|
1908
|
+
tableName: table,
|
1909
|
+
recordId: record,
|
1910
|
+
columnName: column,
|
1911
|
+
fileId
|
1912
|
+
},
|
1913
|
+
// @ts-ignore
|
1914
|
+
body: file,
|
1915
|
+
...this.extraProps
|
1916
|
+
});
|
1917
|
+
}
|
1918
|
+
deleteFileItem({
|
1919
|
+
workspace,
|
1920
|
+
region,
|
1921
|
+
database,
|
1922
|
+
branch,
|
1923
|
+
table,
|
1924
|
+
record,
|
1925
|
+
column,
|
1926
|
+
fileId
|
1927
|
+
}) {
|
1928
|
+
return operationsByTag.files.deleteFileItem({
|
1929
|
+
pathParams: {
|
1930
|
+
workspace,
|
1931
|
+
region,
|
1932
|
+
dbBranchName: `${database}:${branch}`,
|
1933
|
+
tableName: table,
|
1934
|
+
recordId: record,
|
1935
|
+
columnName: column,
|
1936
|
+
fileId
|
1937
|
+
},
|
1938
|
+
...this.extraProps
|
1939
|
+
});
|
1940
|
+
}
|
1941
|
+
getFile({
|
1942
|
+
workspace,
|
1943
|
+
region,
|
1944
|
+
database,
|
1945
|
+
branch,
|
1946
|
+
table,
|
1947
|
+
record,
|
1948
|
+
column
|
1949
|
+
}) {
|
1950
|
+
return operationsByTag.files.getFile({
|
1951
|
+
pathParams: {
|
1952
|
+
workspace,
|
1953
|
+
region,
|
1954
|
+
dbBranchName: `${database}:${branch}`,
|
1955
|
+
tableName: table,
|
1956
|
+
recordId: record,
|
1957
|
+
columnName: column
|
1958
|
+
},
|
1959
|
+
...this.extraProps
|
1960
|
+
});
|
1961
|
+
}
|
1962
|
+
putFile({
|
1963
|
+
workspace,
|
1964
|
+
region,
|
1965
|
+
database,
|
1966
|
+
branch,
|
1967
|
+
table,
|
1968
|
+
record,
|
1969
|
+
column,
|
1970
|
+
file
|
1971
|
+
}) {
|
1972
|
+
return operationsByTag.files.putFile({
|
1973
|
+
pathParams: {
|
1974
|
+
workspace,
|
1975
|
+
region,
|
1976
|
+
dbBranchName: `${database}:${branch}`,
|
1977
|
+
tableName: table,
|
1978
|
+
recordId: record,
|
1979
|
+
columnName: column
|
1980
|
+
},
|
1981
|
+
body: file,
|
1982
|
+
...this.extraProps
|
1983
|
+
});
|
1984
|
+
}
|
1985
|
+
deleteFile({
|
1986
|
+
workspace,
|
1987
|
+
region,
|
1988
|
+
database,
|
1989
|
+
branch,
|
1990
|
+
table,
|
1991
|
+
record,
|
1992
|
+
column
|
1993
|
+
}) {
|
1994
|
+
return operationsByTag.files.deleteFile({
|
1995
|
+
pathParams: {
|
1996
|
+
workspace,
|
1997
|
+
region,
|
1998
|
+
dbBranchName: `${database}:${branch}`,
|
1999
|
+
tableName: table,
|
2000
|
+
recordId: record,
|
2001
|
+
columnName: column
|
2002
|
+
},
|
2003
|
+
...this.extraProps
|
2004
|
+
});
|
2005
|
+
}
|
2006
|
+
fileAccess({
|
2007
|
+
workspace,
|
2008
|
+
region,
|
2009
|
+
fileId,
|
2010
|
+
verify
|
2011
|
+
}) {
|
2012
|
+
return operationsByTag.files.fileAccess({
|
2013
|
+
pathParams: {
|
2014
|
+
workspace,
|
2015
|
+
region,
|
2016
|
+
fileId
|
2017
|
+
},
|
2018
|
+
queryParams: { verify },
|
934
2019
|
...this.extraProps
|
935
2020
|
});
|
936
2021
|
}
|
937
2022
|
}
|
938
|
-
class
|
2023
|
+
class SearchAndFilterApi {
|
2024
|
+
constructor(extraProps) {
|
2025
|
+
this.extraProps = extraProps;
|
2026
|
+
}
|
2027
|
+
queryTable({
|
2028
|
+
workspace,
|
2029
|
+
region,
|
2030
|
+
database,
|
2031
|
+
branch,
|
2032
|
+
table,
|
2033
|
+
filter,
|
2034
|
+
sort,
|
2035
|
+
page,
|
2036
|
+
columns,
|
2037
|
+
consistency
|
2038
|
+
}) {
|
2039
|
+
return operationsByTag.searchAndFilter.queryTable({
|
2040
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2041
|
+
body: { filter, sort, page, columns, consistency },
|
2042
|
+
...this.extraProps
|
2043
|
+
});
|
2044
|
+
}
|
2045
|
+
searchTable({
|
2046
|
+
workspace,
|
2047
|
+
region,
|
2048
|
+
database,
|
2049
|
+
branch,
|
2050
|
+
table,
|
2051
|
+
query,
|
2052
|
+
fuzziness,
|
2053
|
+
target,
|
2054
|
+
prefix,
|
2055
|
+
filter,
|
2056
|
+
highlight,
|
2057
|
+
boosters
|
2058
|
+
}) {
|
2059
|
+
return operationsByTag.searchAndFilter.searchTable({
|
2060
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2061
|
+
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
2062
|
+
...this.extraProps
|
2063
|
+
});
|
2064
|
+
}
|
2065
|
+
searchBranch({
|
2066
|
+
workspace,
|
2067
|
+
region,
|
2068
|
+
database,
|
2069
|
+
branch,
|
2070
|
+
tables,
|
2071
|
+
query,
|
2072
|
+
fuzziness,
|
2073
|
+
prefix,
|
2074
|
+
highlight
|
2075
|
+
}) {
|
2076
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
2077
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2078
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
2079
|
+
...this.extraProps
|
2080
|
+
});
|
2081
|
+
}
|
2082
|
+
vectorSearchTable({
|
2083
|
+
workspace,
|
2084
|
+
region,
|
2085
|
+
database,
|
2086
|
+
branch,
|
2087
|
+
table,
|
2088
|
+
queryVector,
|
2089
|
+
column,
|
2090
|
+
similarityFunction,
|
2091
|
+
size,
|
2092
|
+
filter
|
2093
|
+
}) {
|
2094
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2095
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2096
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2097
|
+
...this.extraProps
|
2098
|
+
});
|
2099
|
+
}
|
2100
|
+
askTable({
|
2101
|
+
workspace,
|
2102
|
+
region,
|
2103
|
+
database,
|
2104
|
+
branch,
|
2105
|
+
table,
|
2106
|
+
options
|
2107
|
+
}) {
|
2108
|
+
return operationsByTag.searchAndFilter.askTable({
|
2109
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2110
|
+
body: { ...options },
|
2111
|
+
...this.extraProps
|
2112
|
+
});
|
2113
|
+
}
|
2114
|
+
summarizeTable({
|
2115
|
+
workspace,
|
2116
|
+
region,
|
2117
|
+
database,
|
2118
|
+
branch,
|
2119
|
+
table,
|
2120
|
+
filter,
|
2121
|
+
columns,
|
2122
|
+
summaries,
|
2123
|
+
sort,
|
2124
|
+
summariesFilter,
|
2125
|
+
page,
|
2126
|
+
consistency
|
2127
|
+
}) {
|
2128
|
+
return operationsByTag.searchAndFilter.summarizeTable({
|
2129
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2130
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
2131
|
+
...this.extraProps
|
2132
|
+
});
|
2133
|
+
}
|
2134
|
+
aggregateTable({
|
2135
|
+
workspace,
|
2136
|
+
region,
|
2137
|
+
database,
|
2138
|
+
branch,
|
2139
|
+
table,
|
2140
|
+
filter,
|
2141
|
+
aggs
|
2142
|
+
}) {
|
2143
|
+
return operationsByTag.searchAndFilter.aggregateTable({
|
2144
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2145
|
+
body: { filter, aggs },
|
2146
|
+
...this.extraProps
|
2147
|
+
});
|
2148
|
+
}
|
2149
|
+
}
|
2150
|
+
class MigrationRequestsApi {
|
2151
|
+
constructor(extraProps) {
|
2152
|
+
this.extraProps = extraProps;
|
2153
|
+
}
|
2154
|
+
queryMigrationRequests({
|
2155
|
+
workspace,
|
2156
|
+
region,
|
2157
|
+
database,
|
2158
|
+
filter,
|
2159
|
+
sort,
|
2160
|
+
page,
|
2161
|
+
columns
|
2162
|
+
}) {
|
2163
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
2164
|
+
pathParams: { workspace, region, dbName: database },
|
2165
|
+
body: { filter, sort, page, columns },
|
2166
|
+
...this.extraProps
|
2167
|
+
});
|
2168
|
+
}
|
2169
|
+
createMigrationRequest({
|
2170
|
+
workspace,
|
2171
|
+
region,
|
2172
|
+
database,
|
2173
|
+
migration
|
2174
|
+
}) {
|
2175
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
2176
|
+
pathParams: { workspace, region, dbName: database },
|
2177
|
+
body: migration,
|
2178
|
+
...this.extraProps
|
2179
|
+
});
|
2180
|
+
}
|
2181
|
+
getMigrationRequest({
|
2182
|
+
workspace,
|
2183
|
+
region,
|
2184
|
+
database,
|
2185
|
+
migrationRequest
|
2186
|
+
}) {
|
2187
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
2188
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
2189
|
+
...this.extraProps
|
2190
|
+
});
|
2191
|
+
}
|
2192
|
+
updateMigrationRequest({
|
2193
|
+
workspace,
|
2194
|
+
region,
|
2195
|
+
database,
|
2196
|
+
migrationRequest,
|
2197
|
+
update
|
2198
|
+
}) {
|
2199
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
2200
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
2201
|
+
body: update,
|
2202
|
+
...this.extraProps
|
2203
|
+
});
|
2204
|
+
}
|
2205
|
+
listMigrationRequestsCommits({
|
2206
|
+
workspace,
|
2207
|
+
region,
|
2208
|
+
database,
|
2209
|
+
migrationRequest,
|
2210
|
+
page
|
2211
|
+
}) {
|
2212
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
2213
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
2214
|
+
body: { page },
|
2215
|
+
...this.extraProps
|
2216
|
+
});
|
2217
|
+
}
|
2218
|
+
compareMigrationRequest({
|
2219
|
+
workspace,
|
2220
|
+
region,
|
2221
|
+
database,
|
2222
|
+
migrationRequest
|
2223
|
+
}) {
|
2224
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
2225
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
2226
|
+
...this.extraProps
|
2227
|
+
});
|
2228
|
+
}
|
2229
|
+
getMigrationRequestIsMerged({
|
2230
|
+
workspace,
|
2231
|
+
region,
|
2232
|
+
database,
|
2233
|
+
migrationRequest
|
2234
|
+
}) {
|
2235
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
2236
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
2237
|
+
...this.extraProps
|
2238
|
+
});
|
2239
|
+
}
|
2240
|
+
mergeMigrationRequest({
|
2241
|
+
workspace,
|
2242
|
+
region,
|
2243
|
+
database,
|
2244
|
+
migrationRequest
|
2245
|
+
}) {
|
2246
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
2247
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
2248
|
+
...this.extraProps
|
2249
|
+
});
|
2250
|
+
}
|
2251
|
+
}
|
2252
|
+
class MigrationsApi {
|
2253
|
+
constructor(extraProps) {
|
2254
|
+
this.extraProps = extraProps;
|
2255
|
+
}
|
2256
|
+
getBranchMigrationHistory({
|
2257
|
+
workspace,
|
2258
|
+
region,
|
2259
|
+
database,
|
2260
|
+
branch,
|
2261
|
+
limit,
|
2262
|
+
startFrom
|
2263
|
+
}) {
|
2264
|
+
return operationsByTag.migrations.getBranchMigrationHistory({
|
2265
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2266
|
+
body: { limit, startFrom },
|
2267
|
+
...this.extraProps
|
2268
|
+
});
|
2269
|
+
}
|
2270
|
+
getBranchMigrationPlan({
|
2271
|
+
workspace,
|
2272
|
+
region,
|
2273
|
+
database,
|
2274
|
+
branch,
|
2275
|
+
schema
|
2276
|
+
}) {
|
2277
|
+
return operationsByTag.migrations.getBranchMigrationPlan({
|
2278
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2279
|
+
body: schema,
|
2280
|
+
...this.extraProps
|
2281
|
+
});
|
2282
|
+
}
|
2283
|
+
executeBranchMigrationPlan({
|
2284
|
+
workspace,
|
2285
|
+
region,
|
2286
|
+
database,
|
2287
|
+
branch,
|
2288
|
+
plan
|
2289
|
+
}) {
|
2290
|
+
return operationsByTag.migrations.executeBranchMigrationPlan({
|
2291
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2292
|
+
body: plan,
|
2293
|
+
...this.extraProps
|
2294
|
+
});
|
2295
|
+
}
|
2296
|
+
getBranchSchemaHistory({
|
2297
|
+
workspace,
|
2298
|
+
region,
|
2299
|
+
database,
|
2300
|
+
branch,
|
2301
|
+
page
|
2302
|
+
}) {
|
2303
|
+
return operationsByTag.migrations.getBranchSchemaHistory({
|
2304
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2305
|
+
body: { page },
|
2306
|
+
...this.extraProps
|
2307
|
+
});
|
2308
|
+
}
|
2309
|
+
compareBranchWithUserSchema({
|
2310
|
+
workspace,
|
2311
|
+
region,
|
2312
|
+
database,
|
2313
|
+
branch,
|
2314
|
+
schema,
|
2315
|
+
schemaOperations,
|
2316
|
+
branchOperations
|
2317
|
+
}) {
|
2318
|
+
return operationsByTag.migrations.compareBranchWithUserSchema({
|
2319
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2320
|
+
body: { schema, schemaOperations, branchOperations },
|
2321
|
+
...this.extraProps
|
2322
|
+
});
|
2323
|
+
}
|
2324
|
+
compareBranchSchemas({
|
2325
|
+
workspace,
|
2326
|
+
region,
|
2327
|
+
database,
|
2328
|
+
branch,
|
2329
|
+
compare,
|
2330
|
+
sourceBranchOperations,
|
2331
|
+
targetBranchOperations
|
2332
|
+
}) {
|
2333
|
+
return operationsByTag.migrations.compareBranchSchemas({
|
2334
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
2335
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
2336
|
+
...this.extraProps
|
2337
|
+
});
|
2338
|
+
}
|
2339
|
+
updateBranchSchema({
|
2340
|
+
workspace,
|
2341
|
+
region,
|
2342
|
+
database,
|
2343
|
+
branch,
|
2344
|
+
migration
|
2345
|
+
}) {
|
2346
|
+
return operationsByTag.migrations.updateBranchSchema({
|
2347
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2348
|
+
body: migration,
|
2349
|
+
...this.extraProps
|
2350
|
+
});
|
2351
|
+
}
|
2352
|
+
previewBranchSchemaEdit({
|
2353
|
+
workspace,
|
2354
|
+
region,
|
2355
|
+
database,
|
2356
|
+
branch,
|
2357
|
+
data
|
2358
|
+
}) {
|
2359
|
+
return operationsByTag.migrations.previewBranchSchemaEdit({
|
2360
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2361
|
+
body: data,
|
2362
|
+
...this.extraProps
|
2363
|
+
});
|
2364
|
+
}
|
2365
|
+
applyBranchSchemaEdit({
|
2366
|
+
workspace,
|
2367
|
+
region,
|
2368
|
+
database,
|
2369
|
+
branch,
|
2370
|
+
edits
|
2371
|
+
}) {
|
2372
|
+
return operationsByTag.migrations.applyBranchSchemaEdit({
|
2373
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2374
|
+
body: { edits },
|
2375
|
+
...this.extraProps
|
2376
|
+
});
|
2377
|
+
}
|
2378
|
+
pushBranchMigrations({
|
2379
|
+
workspace,
|
2380
|
+
region,
|
2381
|
+
database,
|
2382
|
+
branch,
|
2383
|
+
migrations
|
2384
|
+
}) {
|
2385
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2386
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2387
|
+
body: { migrations },
|
2388
|
+
...this.extraProps
|
2389
|
+
});
|
2390
|
+
}
|
2391
|
+
}
|
2392
|
+
class DatabaseApi {
|
939
2393
|
constructor(extraProps) {
|
940
2394
|
this.extraProps = extraProps;
|
941
2395
|
}
|
942
|
-
|
943
|
-
return operationsByTag.
|
944
|
-
pathParams: {
|
945
|
-
queryParams: options,
|
946
|
-
body: record,
|
2396
|
+
getDatabaseList({ workspace }) {
|
2397
|
+
return operationsByTag.databases.getDatabaseList({
|
2398
|
+
pathParams: { workspaceId: workspace },
|
947
2399
|
...this.extraProps
|
948
2400
|
});
|
949
2401
|
}
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
2402
|
+
createDatabase({
|
2403
|
+
workspace,
|
2404
|
+
database,
|
2405
|
+
data
|
2406
|
+
}) {
|
2407
|
+
return operationsByTag.databases.createDatabase({
|
2408
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2409
|
+
body: data,
|
955
2410
|
...this.extraProps
|
956
2411
|
});
|
957
2412
|
}
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
2413
|
+
deleteDatabase({
|
2414
|
+
workspace,
|
2415
|
+
database
|
2416
|
+
}) {
|
2417
|
+
return operationsByTag.databases.deleteDatabase({
|
2418
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
963
2419
|
...this.extraProps
|
964
2420
|
});
|
965
2421
|
}
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
2422
|
+
getDatabaseMetadata({
|
2423
|
+
workspace,
|
2424
|
+
database
|
2425
|
+
}) {
|
2426
|
+
return operationsByTag.databases.getDatabaseMetadata({
|
2427
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
971
2428
|
...this.extraProps
|
972
2429
|
});
|
973
2430
|
}
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
2431
|
+
updateDatabaseMetadata({
|
2432
|
+
workspace,
|
2433
|
+
database,
|
2434
|
+
metadata
|
2435
|
+
}) {
|
2436
|
+
return operationsByTag.databases.updateDatabaseMetadata({
|
2437
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2438
|
+
body: metadata,
|
978
2439
|
...this.extraProps
|
979
2440
|
});
|
980
2441
|
}
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
2442
|
+
renameDatabase({
|
2443
|
+
workspace,
|
2444
|
+
database,
|
2445
|
+
newName
|
2446
|
+
}) {
|
2447
|
+
return operationsByTag.databases.renameDatabase({
|
2448
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2449
|
+
body: { newName },
|
985
2450
|
...this.extraProps
|
986
2451
|
});
|
987
2452
|
}
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
2453
|
+
getDatabaseGithubSettings({
|
2454
|
+
workspace,
|
2455
|
+
database
|
2456
|
+
}) {
|
2457
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
2458
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
993
2459
|
...this.extraProps
|
994
2460
|
});
|
995
2461
|
}
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
2462
|
+
updateDatabaseGithubSettings({
|
2463
|
+
workspace,
|
2464
|
+
database,
|
2465
|
+
settings
|
2466
|
+
}) {
|
2467
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
2468
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2469
|
+
body: settings,
|
1000
2470
|
...this.extraProps
|
1001
2471
|
});
|
1002
2472
|
}
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
2473
|
+
deleteDatabaseGithubSettings({
|
2474
|
+
workspace,
|
2475
|
+
database
|
2476
|
+
}) {
|
2477
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
2478
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1007
2479
|
...this.extraProps
|
1008
2480
|
});
|
1009
2481
|
}
|
1010
|
-
|
1011
|
-
return operationsByTag.
|
1012
|
-
pathParams: {
|
1013
|
-
body: query,
|
2482
|
+
listRegions({ workspace }) {
|
2483
|
+
return operationsByTag.databases.listRegions({
|
2484
|
+
pathParams: { workspaceId: workspace },
|
1014
2485
|
...this.extraProps
|
1015
2486
|
});
|
1016
2487
|
}
|
1017
2488
|
}
|
1018
2489
|
|
1019
2490
|
class XataApiPlugin {
|
1020
|
-
|
1021
|
-
|
1022
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2491
|
+
build(options) {
|
2492
|
+
return new XataApiClient(options);
|
1023
2493
|
}
|
1024
2494
|
}
|
1025
2495
|
|
1026
2496
|
class XataPlugin {
|
1027
2497
|
}
|
1028
2498
|
|
2499
|
+
function cleanFilter(filter) {
|
2500
|
+
if (!filter)
|
2501
|
+
return void 0;
|
2502
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2503
|
+
return values.length > 0 ? filter : void 0;
|
2504
|
+
}
|
2505
|
+
|
1029
2506
|
var __accessCheck$6 = (obj, member, msg) => {
|
1030
2507
|
if (!member.has(obj))
|
1031
2508
|
throw TypeError("Cannot " + msg);
|
@@ -1052,18 +2529,46 @@ class Page {
|
|
1052
2529
|
this.meta = meta;
|
1053
2530
|
this.records = new RecordArray(this, records);
|
1054
2531
|
}
|
2532
|
+
/**
|
2533
|
+
* Retrieves the next page of results.
|
2534
|
+
* @param size Maximum number of results to be retrieved.
|
2535
|
+
* @param offset Number of results to skip when retrieving the results.
|
2536
|
+
* @returns The next page or results.
|
2537
|
+
*/
|
1055
2538
|
async nextPage(size, offset) {
|
1056
2539
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1057
2540
|
}
|
2541
|
+
/**
|
2542
|
+
* Retrieves the previous page of results.
|
2543
|
+
* @param size Maximum number of results to be retrieved.
|
2544
|
+
* @param offset Number of results to skip when retrieving the results.
|
2545
|
+
* @returns The previous page or results.
|
2546
|
+
*/
|
1058
2547
|
async previousPage(size, offset) {
|
1059
2548
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1060
2549
|
}
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
2550
|
+
/**
|
2551
|
+
* Retrieves the start page of results.
|
2552
|
+
* @param size Maximum number of results to be retrieved.
|
2553
|
+
* @param offset Number of results to skip when retrieving the results.
|
2554
|
+
* @returns The start page or results.
|
2555
|
+
*/
|
2556
|
+
async startPage(size, offset) {
|
2557
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
2558
|
+
}
|
2559
|
+
/**
|
2560
|
+
* Retrieves the end page of results.
|
2561
|
+
* @param size Maximum number of results to be retrieved.
|
2562
|
+
* @param offset Number of results to skip when retrieving the results.
|
2563
|
+
* @returns The end page or results.
|
2564
|
+
*/
|
2565
|
+
async endPage(size, offset) {
|
2566
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
2567
|
+
}
|
2568
|
+
/**
|
2569
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2570
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2571
|
+
*/
|
1067
2572
|
hasNextPage() {
|
1068
2573
|
return this.meta.page.more;
|
1069
2574
|
}
|
@@ -1074,7 +2579,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
|
|
1074
2579
|
const PAGINATION_MAX_OFFSET = 800;
|
1075
2580
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1076
2581
|
function isCursorPaginationOptions(options) {
|
1077
|
-
return isDefined(options) && (isDefined(options.
|
2582
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1078
2583
|
}
|
1079
2584
|
const _RecordArray = class extends Array {
|
1080
2585
|
constructor(...args) {
|
@@ -1095,25 +2600,54 @@ const _RecordArray = class extends Array {
|
|
1095
2600
|
toArray() {
|
1096
2601
|
return new Array(...this);
|
1097
2602
|
}
|
2603
|
+
toSerializable() {
|
2604
|
+
return JSON.parse(this.toString());
|
2605
|
+
}
|
2606
|
+
toString() {
|
2607
|
+
return JSON.stringify(this.toArray());
|
2608
|
+
}
|
1098
2609
|
map(callbackfn, thisArg) {
|
1099
2610
|
return this.toArray().map(callbackfn, thisArg);
|
1100
2611
|
}
|
2612
|
+
/**
|
2613
|
+
* Retrieve next page of records
|
2614
|
+
*
|
2615
|
+
* @returns A new array of objects
|
2616
|
+
*/
|
1101
2617
|
async nextPage(size, offset) {
|
1102
2618
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1103
2619
|
return new _RecordArray(newPage);
|
1104
2620
|
}
|
2621
|
+
/**
|
2622
|
+
* Retrieve previous page of records
|
2623
|
+
*
|
2624
|
+
* @returns A new array of objects
|
2625
|
+
*/
|
1105
2626
|
async previousPage(size, offset) {
|
1106
2627
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1107
2628
|
return new _RecordArray(newPage);
|
1108
2629
|
}
|
1109
|
-
|
1110
|
-
|
2630
|
+
/**
|
2631
|
+
* Retrieve start page of records
|
2632
|
+
*
|
2633
|
+
* @returns A new array of objects
|
2634
|
+
*/
|
2635
|
+
async startPage(size, offset) {
|
2636
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1111
2637
|
return new _RecordArray(newPage);
|
1112
2638
|
}
|
1113
|
-
|
1114
|
-
|
2639
|
+
/**
|
2640
|
+
* Retrieve end page of records
|
2641
|
+
*
|
2642
|
+
* @returns A new array of objects
|
2643
|
+
*/
|
2644
|
+
async endPage(size, offset) {
|
2645
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1115
2646
|
return new _RecordArray(newPage);
|
1116
2647
|
}
|
2648
|
+
/**
|
2649
|
+
* @returns Boolean indicating if there is a next page
|
2650
|
+
*/
|
1117
2651
|
hasNextPage() {
|
1118
2652
|
return __privateGet$6(this, _page).meta.page.more;
|
1119
2653
|
}
|
@@ -1139,13 +2673,19 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1139
2673
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1140
2674
|
return value;
|
1141
2675
|
};
|
1142
|
-
var
|
2676
|
+
var __privateMethod$3 = (obj, member, method) => {
|
2677
|
+
__accessCheck$5(obj, member, "access private method");
|
2678
|
+
return method;
|
2679
|
+
};
|
2680
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1143
2681
|
const _Query = class {
|
1144
2682
|
constructor(repository, table, data, rawParent) {
|
2683
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1145
2684
|
__privateAdd$5(this, _table$1, void 0);
|
1146
2685
|
__privateAdd$5(this, _repository, void 0);
|
1147
2686
|
__privateAdd$5(this, _data, { filter: {} });
|
1148
|
-
|
2687
|
+
// Implements pagination
|
2688
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1149
2689
|
this.records = new RecordArray(this, []);
|
1150
2690
|
__privateSet$5(this, _table$1, table);
|
1151
2691
|
if (repository) {
|
@@ -1160,9 +2700,11 @@ const _Query = class {
|
|
1160
2700
|
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1161
2701
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1162
2702
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1163
|
-
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns
|
2703
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
2704
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1164
2705
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1165
2706
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2707
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1166
2708
|
this.any = this.any.bind(this);
|
1167
2709
|
this.all = this.all.bind(this);
|
1168
2710
|
this.not = this.not.bind(this);
|
@@ -1180,37 +2722,65 @@ const _Query = class {
|
|
1180
2722
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1181
2723
|
return toBase64(key);
|
1182
2724
|
}
|
2725
|
+
/**
|
2726
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
2727
|
+
* @param queries An array of subqueries.
|
2728
|
+
* @returns A new Query object.
|
2729
|
+
*/
|
1183
2730
|
any(...queries) {
|
1184
2731
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1185
2732
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
1186
2733
|
}
|
2734
|
+
/**
|
2735
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
2736
|
+
* @param queries An array of subqueries.
|
2737
|
+
* @returns A new Query object.
|
2738
|
+
*/
|
1187
2739
|
all(...queries) {
|
1188
2740
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1189
2741
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1190
2742
|
}
|
2743
|
+
/**
|
2744
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
2745
|
+
* @param queries An array of subqueries.
|
2746
|
+
* @returns A new Query object.
|
2747
|
+
*/
|
1191
2748
|
not(...queries) {
|
1192
2749
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1193
2750
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
1194
2751
|
}
|
2752
|
+
/**
|
2753
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
2754
|
+
* @param queries An array of subqueries.
|
2755
|
+
* @returns A new Query object.
|
2756
|
+
*/
|
1195
2757
|
none(...queries) {
|
1196
2758
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1197
2759
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
1198
2760
|
}
|
1199
2761
|
filter(a, b) {
|
1200
2762
|
if (arguments.length === 1) {
|
1201
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
2763
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
2764
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
2765
|
+
}));
|
1202
2766
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1203
2767
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1204
2768
|
} else {
|
1205
|
-
const
|
2769
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
2770
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1206
2771
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1207
2772
|
}
|
1208
2773
|
}
|
1209
|
-
sort(column, direction) {
|
2774
|
+
sort(column, direction = "asc") {
|
1210
2775
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1211
2776
|
const sort = [...originalSort, { column, direction }];
|
1212
2777
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1213
2778
|
}
|
2779
|
+
/**
|
2780
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
2781
|
+
* @param columns Array of column names to be returned by the query.
|
2782
|
+
* @returns A new Query object.
|
2783
|
+
*/
|
1214
2784
|
select(columns) {
|
1215
2785
|
return new _Query(
|
1216
2786
|
__privateGet$5(this, _repository),
|
@@ -1223,6 +2793,12 @@ const _Query = class {
|
|
1223
2793
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1224
2794
|
return __privateGet$5(this, _repository).query(query);
|
1225
2795
|
}
|
2796
|
+
/**
|
2797
|
+
* Get results in an iterator
|
2798
|
+
*
|
2799
|
+
* @async
|
2800
|
+
* @returns Async interable of results
|
2801
|
+
*/
|
1226
2802
|
async *[Symbol.asyncIterator]() {
|
1227
2803
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1228
2804
|
yield record;
|
@@ -1240,11 +2816,20 @@ const _Query = class {
|
|
1240
2816
|
}
|
1241
2817
|
}
|
1242
2818
|
async getMany(options = {}) {
|
1243
|
-
const
|
2819
|
+
const { pagination = {}, ...rest } = options;
|
2820
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
2821
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
2822
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
2823
|
+
const results = [...page.records];
|
2824
|
+
while (page.hasNextPage() && results.length < size) {
|
2825
|
+
page = await page.nextPage();
|
2826
|
+
results.push(...page.records);
|
2827
|
+
}
|
1244
2828
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1245
2829
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1246
2830
|
}
|
1247
|
-
|
2831
|
+
const array = new RecordArray(page, results.slice(0, size));
|
2832
|
+
return array;
|
1248
2833
|
}
|
1249
2834
|
async getAll(options = {}) {
|
1250
2835
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1258,21 +2843,65 @@ const _Query = class {
|
|
1258
2843
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1259
2844
|
return records[0] ?? null;
|
1260
2845
|
}
|
2846
|
+
async getFirstOrThrow(options = {}) {
|
2847
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
2848
|
+
if (records[0] === void 0)
|
2849
|
+
throw new Error("No results found.");
|
2850
|
+
return records[0];
|
2851
|
+
}
|
2852
|
+
async summarize(params = {}) {
|
2853
|
+
const { summaries, summariesFilter, ...options } = params;
|
2854
|
+
const query = new _Query(
|
2855
|
+
__privateGet$5(this, _repository),
|
2856
|
+
__privateGet$5(this, _table$1),
|
2857
|
+
options,
|
2858
|
+
__privateGet$5(this, _data)
|
2859
|
+
);
|
2860
|
+
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2861
|
+
}
|
2862
|
+
/**
|
2863
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
2864
|
+
* @param ttl The cache TTL in milliseconds.
|
2865
|
+
* @returns A new Query object.
|
2866
|
+
*/
|
1261
2867
|
cache(ttl) {
|
1262
2868
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1263
2869
|
}
|
2870
|
+
/**
|
2871
|
+
* Retrieve next page of records
|
2872
|
+
*
|
2873
|
+
* @returns A new page object.
|
2874
|
+
*/
|
1264
2875
|
nextPage(size, offset) {
|
1265
|
-
return this.
|
2876
|
+
return this.startPage(size, offset);
|
1266
2877
|
}
|
2878
|
+
/**
|
2879
|
+
* Retrieve previous page of records
|
2880
|
+
*
|
2881
|
+
* @returns A new page object
|
2882
|
+
*/
|
1267
2883
|
previousPage(size, offset) {
|
1268
|
-
return this.
|
1269
|
-
}
|
1270
|
-
|
2884
|
+
return this.startPage(size, offset);
|
2885
|
+
}
|
2886
|
+
/**
|
2887
|
+
* Retrieve start page of records
|
2888
|
+
*
|
2889
|
+
* @returns A new page object
|
2890
|
+
*/
|
2891
|
+
startPage(size, offset) {
|
1271
2892
|
return this.getPaginated({ pagination: { size, offset } });
|
1272
2893
|
}
|
1273
|
-
|
2894
|
+
/**
|
2895
|
+
* Retrieve last page of records
|
2896
|
+
*
|
2897
|
+
* @returns A new page object
|
2898
|
+
*/
|
2899
|
+
endPage(size, offset) {
|
1274
2900
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
1275
2901
|
}
|
2902
|
+
/**
|
2903
|
+
* @returns Boolean indicating if there is a next page
|
2904
|
+
*/
|
1276
2905
|
hasNextPage() {
|
1277
2906
|
return this.meta.page.more;
|
1278
2907
|
}
|
@@ -1281,9 +2910,20 @@ let Query = _Query;
|
|
1281
2910
|
_table$1 = new WeakMap();
|
1282
2911
|
_repository = new WeakMap();
|
1283
2912
|
_data = new WeakMap();
|
2913
|
+
_cleanFilterConstraint = new WeakSet();
|
2914
|
+
cleanFilterConstraint_fn = function(column, value) {
|
2915
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
2916
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
2917
|
+
return { $includes: value };
|
2918
|
+
}
|
2919
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
2920
|
+
return value.id;
|
2921
|
+
}
|
2922
|
+
return value;
|
2923
|
+
};
|
1284
2924
|
function cleanParent(data, parent) {
|
1285
2925
|
if (isCursorPaginationOptions(data.pagination)) {
|
1286
|
-
return { ...parent,
|
2926
|
+
return { ...parent, sort: void 0, filter: void 0 };
|
1287
2927
|
}
|
1288
2928
|
return parent;
|
1289
2929
|
}
|
@@ -1301,7 +2941,11 @@ function isSortFilterString(value) {
|
|
1301
2941
|
return isString(value);
|
1302
2942
|
}
|
1303
2943
|
function isSortFilterBase(filter) {
|
1304
|
-
return isObject(filter) && Object.
|
2944
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
2945
|
+
if (key === "*")
|
2946
|
+
return value === "random";
|
2947
|
+
return value === "asc" || value === "desc";
|
2948
|
+
});
|
1305
2949
|
}
|
1306
2950
|
function isSortFilterObject(filter) {
|
1307
2951
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -1342,288 +2986,621 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1342
2986
|
__accessCheck$4(obj, member, "access private method");
|
1343
2987
|
return method;
|
1344
2988
|
};
|
1345
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2989
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
2990
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
1346
2991
|
class Repository extends Query {
|
1347
2992
|
}
|
1348
2993
|
class RestRepository extends Query {
|
1349
2994
|
constructor(options) {
|
1350
|
-
super(
|
2995
|
+
super(
|
2996
|
+
null,
|
2997
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
2998
|
+
{}
|
2999
|
+
);
|
1351
3000
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1352
3001
|
__privateAdd$4(this, _insertRecordWithId);
|
1353
|
-
__privateAdd$4(this,
|
3002
|
+
__privateAdd$4(this, _insertRecords);
|
1354
3003
|
__privateAdd$4(this, _updateRecordWithID);
|
3004
|
+
__privateAdd$4(this, _updateRecords);
|
1355
3005
|
__privateAdd$4(this, _upsertRecordWithID);
|
1356
3006
|
__privateAdd$4(this, _deleteRecord);
|
3007
|
+
__privateAdd$4(this, _deleteRecords);
|
1357
3008
|
__privateAdd$4(this, _setCacheQuery);
|
1358
3009
|
__privateAdd$4(this, _getCacheQuery);
|
1359
3010
|
__privateAdd$4(this, _getSchemaTables$1);
|
1360
3011
|
__privateAdd$4(this, _table, void 0);
|
1361
3012
|
__privateAdd$4(this, _getFetchProps, void 0);
|
3013
|
+
__privateAdd$4(this, _db, void 0);
|
1362
3014
|
__privateAdd$4(this, _cache, void 0);
|
1363
3015
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
3016
|
+
__privateAdd$4(this, _trace, void 0);
|
1364
3017
|
__privateSet$4(this, _table, options.table);
|
1365
|
-
__privateSet$4(this,
|
1366
|
-
this.db = options.db;
|
3018
|
+
__privateSet$4(this, _db, options.db);
|
1367
3019
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1368
3020
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
3021
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
3022
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
3023
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
3024
|
+
return trace(name, fn, {
|
3025
|
+
...options2,
|
3026
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
3027
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
3028
|
+
[TraceAttributes.VERSION]: VERSION
|
3029
|
+
});
|
3030
|
+
});
|
1369
3031
|
}
|
1370
|
-
async create(a, b, c) {
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
3032
|
+
async create(a, b, c, d) {
|
3033
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
3034
|
+
const ifVersion = parseIfVersion(b, c, d);
|
3035
|
+
if (Array.isArray(a)) {
|
3036
|
+
if (a.length === 0)
|
3037
|
+
return [];
|
3038
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
3039
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3040
|
+
const result = await this.read(ids, columns);
|
3041
|
+
return result;
|
3042
|
+
}
|
3043
|
+
if (isString(a) && isObject(b)) {
|
3044
|
+
if (a === "")
|
3045
|
+
throw new Error("The id can't be empty");
|
3046
|
+
const columns = isStringArray(c) ? c : void 0;
|
3047
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
3048
|
+
}
|
3049
|
+
if (isObject(a) && isString(a.id)) {
|
3050
|
+
if (a.id === "")
|
3051
|
+
throw new Error("The id can't be empty");
|
3052
|
+
const columns = isStringArray(b) ? b : void 0;
|
3053
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
3054
|
+
}
|
3055
|
+
if (isObject(a)) {
|
3056
|
+
const columns = isStringArray(b) ? b : void 0;
|
3057
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
3058
|
+
}
|
3059
|
+
throw new Error("Invalid arguments for create method");
|
3060
|
+
});
|
1394
3061
|
}
|
1395
3062
|
async read(a, b) {
|
1396
|
-
|
1397
|
-
|
1398
|
-
if (a
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
acc
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
3063
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
3064
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3065
|
+
if (Array.isArray(a)) {
|
3066
|
+
if (a.length === 0)
|
3067
|
+
return [];
|
3068
|
+
const ids = a.map((item) => extractId(item));
|
3069
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
3070
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
3071
|
+
acc[object.id] = object;
|
3072
|
+
return acc;
|
3073
|
+
}, {});
|
3074
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
3075
|
+
}
|
3076
|
+
const id = extractId(a);
|
3077
|
+
if (id) {
|
3078
|
+
try {
|
3079
|
+
const response = await getRecord({
|
3080
|
+
pathParams: {
|
3081
|
+
workspace: "{workspaceId}",
|
3082
|
+
dbBranchName: "{dbBranch}",
|
3083
|
+
region: "{region}",
|
3084
|
+
tableName: __privateGet$4(this, _table),
|
3085
|
+
recordId: id
|
3086
|
+
},
|
3087
|
+
queryParams: { columns },
|
3088
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3089
|
+
});
|
3090
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3091
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
3092
|
+
} catch (e) {
|
3093
|
+
if (isObject(e) && e.status === 404) {
|
3094
|
+
return null;
|
3095
|
+
}
|
3096
|
+
throw e;
|
3097
|
+
}
|
3098
|
+
}
|
3099
|
+
return null;
|
3100
|
+
});
|
3101
|
+
}
|
3102
|
+
async readOrThrow(a, b) {
|
3103
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
3104
|
+
const result = await this.read(a, b);
|
3105
|
+
if (Array.isArray(result)) {
|
3106
|
+
const missingIds = compact(
|
3107
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
3108
|
+
);
|
3109
|
+
if (missingIds.length > 0) {
|
3110
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
3111
|
+
}
|
3112
|
+
return result;
|
3113
|
+
}
|
3114
|
+
if (result === null) {
|
3115
|
+
const id = extractId(a) ?? "unknown";
|
3116
|
+
throw new Error(`Record with id ${id} not found`);
|
3117
|
+
}
|
3118
|
+
return result;
|
3119
|
+
});
|
3120
|
+
}
|
3121
|
+
async update(a, b, c, d) {
|
3122
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
3123
|
+
const ifVersion = parseIfVersion(b, c, d);
|
3124
|
+
if (Array.isArray(a)) {
|
3125
|
+
if (a.length === 0)
|
3126
|
+
return [];
|
3127
|
+
const existing = await this.read(a, ["id"]);
|
3128
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
3129
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
3130
|
+
ifVersion,
|
3131
|
+
upsert: false
|
1416
3132
|
});
|
1417
|
-
const
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
3133
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3134
|
+
const result = await this.read(a, columns);
|
3135
|
+
return result;
|
3136
|
+
}
|
3137
|
+
try {
|
3138
|
+
if (isString(a) && isObject(b)) {
|
3139
|
+
const columns = isStringArray(c) ? c : void 0;
|
3140
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
3141
|
+
}
|
3142
|
+
if (isObject(a) && isString(a.id)) {
|
3143
|
+
const columns = isStringArray(b) ? b : void 0;
|
3144
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3145
|
+
}
|
3146
|
+
} catch (error) {
|
3147
|
+
if (error.status === 422)
|
1421
3148
|
return null;
|
3149
|
+
throw error;
|
3150
|
+
}
|
3151
|
+
throw new Error("Invalid arguments for update method");
|
3152
|
+
});
|
3153
|
+
}
|
3154
|
+
async updateOrThrow(a, b, c, d) {
|
3155
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
3156
|
+
const result = await this.update(a, b, c, d);
|
3157
|
+
if (Array.isArray(result)) {
|
3158
|
+
const missingIds = compact(
|
3159
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
3160
|
+
);
|
3161
|
+
if (missingIds.length > 0) {
|
3162
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1422
3163
|
}
|
1423
|
-
|
3164
|
+
return result;
|
1424
3165
|
}
|
1425
|
-
|
1426
|
-
|
3166
|
+
if (result === null) {
|
3167
|
+
const id = extractId(a) ?? "unknown";
|
3168
|
+
throw new Error(`Record with id ${id} not found`);
|
3169
|
+
}
|
3170
|
+
return result;
|
3171
|
+
});
|
1427
3172
|
}
|
1428
|
-
async
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
3173
|
+
async createOrUpdate(a, b, c, d) {
|
3174
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
3175
|
+
const ifVersion = parseIfVersion(b, c, d);
|
3176
|
+
if (Array.isArray(a)) {
|
3177
|
+
if (a.length === 0)
|
3178
|
+
return [];
|
3179
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
3180
|
+
ifVersion,
|
3181
|
+
upsert: true
|
3182
|
+
});
|
3183
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3184
|
+
const result = await this.read(a, columns);
|
3185
|
+
return result;
|
1434
3186
|
}
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
if (isString(a) && isObject(b)) {
|
1439
|
-
const columns = isStringArray(c) ? c : void 0;
|
1440
|
-
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1441
|
-
}
|
1442
|
-
if (isObject(a) && isString(a.id)) {
|
1443
|
-
const columns = isStringArray(b) ? b : void 0;
|
1444
|
-
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1445
|
-
}
|
1446
|
-
throw new Error("Invalid arguments for update method");
|
1447
|
-
}
|
1448
|
-
async createOrUpdate(a, b, c) {
|
1449
|
-
if (Array.isArray(a)) {
|
1450
|
-
if (a.length === 0)
|
1451
|
-
return [];
|
1452
|
-
if (a.length > 100) {
|
1453
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
3187
|
+
if (isString(a) && isObject(b)) {
|
3188
|
+
const columns = isStringArray(c) ? c : void 0;
|
3189
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
1454
3190
|
}
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
if (isString(a) && isObject(b)) {
|
1459
|
-
const columns = isStringArray(c) ? c : void 0;
|
1460
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1461
|
-
}
|
1462
|
-
if (isObject(a) && isString(a.id)) {
|
1463
|
-
const columns = isStringArray(c) ? c : void 0;
|
1464
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1465
|
-
}
|
1466
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1467
|
-
}
|
1468
|
-
async delete(a) {
|
1469
|
-
if (Array.isArray(a)) {
|
1470
|
-
if (a.length === 0)
|
1471
|
-
return;
|
1472
|
-
if (a.length > 100) {
|
1473
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
3191
|
+
if (isObject(a) && isString(a.id)) {
|
3192
|
+
const columns = isStringArray(c) ? c : void 0;
|
3193
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
1474
3194
|
}
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
3195
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
3196
|
+
});
|
3197
|
+
}
|
3198
|
+
async createOrReplace(a, b, c, d) {
|
3199
|
+
return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
|
3200
|
+
const ifVersion = parseIfVersion(b, c, d);
|
3201
|
+
if (Array.isArray(a)) {
|
3202
|
+
if (a.length === 0)
|
3203
|
+
return [];
|
3204
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
3205
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3206
|
+
const result = await this.read(ids, columns);
|
3207
|
+
return result;
|
3208
|
+
}
|
3209
|
+
if (isString(a) && isObject(b)) {
|
3210
|
+
const columns = isStringArray(c) ? c : void 0;
|
3211
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
3212
|
+
}
|
3213
|
+
if (isObject(a) && isString(a.id)) {
|
3214
|
+
const columns = isStringArray(c) ? c : void 0;
|
3215
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3216
|
+
}
|
3217
|
+
throw new Error("Invalid arguments for createOrReplace method");
|
3218
|
+
});
|
3219
|
+
}
|
3220
|
+
async delete(a, b) {
|
3221
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
3222
|
+
if (Array.isArray(a)) {
|
3223
|
+
if (a.length === 0)
|
3224
|
+
return [];
|
3225
|
+
const ids = a.map((o) => {
|
3226
|
+
if (isString(o))
|
3227
|
+
return o;
|
3228
|
+
if (isString(o.id))
|
3229
|
+
return o.id;
|
3230
|
+
throw new Error("Invalid arguments for delete method");
|
3231
|
+
});
|
3232
|
+
const columns = isStringArray(b) ? b : ["*"];
|
3233
|
+
const result = await this.read(a, columns);
|
3234
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
3235
|
+
return result;
|
3236
|
+
}
|
3237
|
+
if (isString(a)) {
|
3238
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
3239
|
+
}
|
3240
|
+
if (isObject(a) && isString(a.id)) {
|
3241
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
3242
|
+
}
|
3243
|
+
throw new Error("Invalid arguments for delete method");
|
3244
|
+
});
|
3245
|
+
}
|
3246
|
+
async deleteOrThrow(a, b) {
|
3247
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
3248
|
+
const result = await this.delete(a, b);
|
3249
|
+
if (Array.isArray(result)) {
|
3250
|
+
const missingIds = compact(
|
3251
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
3252
|
+
);
|
3253
|
+
if (missingIds.length > 0) {
|
3254
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
3255
|
+
}
|
3256
|
+
return result;
|
3257
|
+
} else if (result === null) {
|
3258
|
+
const id = extractId(a) ?? "unknown";
|
3259
|
+
throw new Error(`Record with id ${id} not found`);
|
3260
|
+
}
|
3261
|
+
return result;
|
3262
|
+
});
|
1487
3263
|
}
|
1488
3264
|
async search(query, options = {}) {
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
3265
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
3266
|
+
const { records } = await searchTable({
|
3267
|
+
pathParams: {
|
3268
|
+
workspace: "{workspaceId}",
|
3269
|
+
dbBranchName: "{dbBranch}",
|
3270
|
+
region: "{region}",
|
3271
|
+
tableName: __privateGet$4(this, _table)
|
3272
|
+
},
|
3273
|
+
body: {
|
3274
|
+
query,
|
3275
|
+
fuzziness: options.fuzziness,
|
3276
|
+
prefix: options.prefix,
|
3277
|
+
highlight: options.highlight,
|
3278
|
+
filter: options.filter,
|
3279
|
+
boosters: options.boosters,
|
3280
|
+
page: options.page,
|
3281
|
+
target: options.target
|
3282
|
+
},
|
3283
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3284
|
+
});
|
3285
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3286
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3287
|
+
});
|
3288
|
+
}
|
3289
|
+
async vectorSearch(column, query, options) {
|
3290
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3291
|
+
const { records } = await vectorSearchTable({
|
3292
|
+
pathParams: {
|
3293
|
+
workspace: "{workspaceId}",
|
3294
|
+
dbBranchName: "{dbBranch}",
|
3295
|
+
region: "{region}",
|
3296
|
+
tableName: __privateGet$4(this, _table)
|
3297
|
+
},
|
3298
|
+
body: {
|
3299
|
+
column,
|
3300
|
+
queryVector: query,
|
3301
|
+
similarityFunction: options?.similarityFunction,
|
3302
|
+
size: options?.size,
|
3303
|
+
filter: options?.filter
|
3304
|
+
},
|
3305
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3306
|
+
});
|
3307
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3308
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
3309
|
+
});
|
3310
|
+
}
|
3311
|
+
async aggregate(aggs, filter) {
|
3312
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
3313
|
+
const result = await aggregateTable({
|
3314
|
+
pathParams: {
|
3315
|
+
workspace: "{workspaceId}",
|
3316
|
+
dbBranchName: "{dbBranch}",
|
3317
|
+
region: "{region}",
|
3318
|
+
tableName: __privateGet$4(this, _table)
|
3319
|
+
},
|
3320
|
+
body: { aggs, filter },
|
3321
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3322
|
+
});
|
3323
|
+
return result;
|
1501
3324
|
});
|
1502
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1503
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1504
3325
|
}
|
1505
3326
|
async query(query) {
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
3327
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
3328
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
3329
|
+
if (cacheQuery)
|
3330
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
3331
|
+
const data = query.getQueryOptions();
|
3332
|
+
const { meta, records: objects } = await queryTable({
|
3333
|
+
pathParams: {
|
3334
|
+
workspace: "{workspaceId}",
|
3335
|
+
dbBranchName: "{dbBranch}",
|
3336
|
+
region: "{region}",
|
3337
|
+
tableName: __privateGet$4(this, _table)
|
3338
|
+
},
|
3339
|
+
body: {
|
3340
|
+
filter: cleanFilter(data.filter),
|
3341
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
3342
|
+
page: data.pagination,
|
3343
|
+
columns: data.columns ?? ["*"],
|
3344
|
+
consistency: data.consistency
|
3345
|
+
},
|
3346
|
+
fetchOptions: data.fetchOptions,
|
3347
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3348
|
+
});
|
3349
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3350
|
+
const records = objects.map(
|
3351
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
3352
|
+
);
|
3353
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
3354
|
+
return new Page(query, meta, records);
|
3355
|
+
});
|
3356
|
+
}
|
3357
|
+
async summarizeTable(query, summaries, summariesFilter) {
|
3358
|
+
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
3359
|
+
const data = query.getQueryOptions();
|
3360
|
+
const result = await summarizeTable({
|
3361
|
+
pathParams: {
|
3362
|
+
workspace: "{workspaceId}",
|
3363
|
+
dbBranchName: "{dbBranch}",
|
3364
|
+
region: "{region}",
|
3365
|
+
tableName: __privateGet$4(this, _table)
|
3366
|
+
},
|
3367
|
+
body: {
|
3368
|
+
filter: cleanFilter(data.filter),
|
3369
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
3370
|
+
columns: data.columns,
|
3371
|
+
consistency: data.consistency,
|
3372
|
+
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
3373
|
+
summaries,
|
3374
|
+
summariesFilter
|
3375
|
+
},
|
3376
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3377
|
+
});
|
3378
|
+
return result;
|
1521
3379
|
});
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
3380
|
+
}
|
3381
|
+
ask(question, options) {
|
3382
|
+
const params = {
|
3383
|
+
pathParams: {
|
3384
|
+
workspace: "{workspaceId}",
|
3385
|
+
dbBranchName: "{dbBranch}",
|
3386
|
+
region: "{region}",
|
3387
|
+
tableName: __privateGet$4(this, _table)
|
3388
|
+
},
|
3389
|
+
body: {
|
3390
|
+
question,
|
3391
|
+
...options
|
3392
|
+
},
|
3393
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3394
|
+
};
|
3395
|
+
if (options?.onMessage) {
|
3396
|
+
fetchSSERequest({
|
3397
|
+
endpoint: "dataPlane",
|
3398
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
3399
|
+
method: "POST",
|
3400
|
+
onMessage: (message) => {
|
3401
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3402
|
+
},
|
3403
|
+
...params
|
3404
|
+
});
|
3405
|
+
} else {
|
3406
|
+
return askTable(params);
|
3407
|
+
}
|
1526
3408
|
}
|
1527
3409
|
}
|
1528
3410
|
_table = new WeakMap();
|
1529
3411
|
_getFetchProps = new WeakMap();
|
3412
|
+
_db = new WeakMap();
|
1530
3413
|
_cache = new WeakMap();
|
1531
3414
|
_schemaTables$2 = new WeakMap();
|
3415
|
+
_trace = new WeakMap();
|
1532
3416
|
_insertRecordWithoutId = new WeakSet();
|
1533
3417
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1534
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1535
3418
|
const record = transformObjectLinks(object);
|
1536
3419
|
const response = await insertRecord({
|
1537
3420
|
pathParams: {
|
1538
3421
|
workspace: "{workspaceId}",
|
1539
3422
|
dbBranchName: "{dbBranch}",
|
3423
|
+
region: "{region}",
|
1540
3424
|
tableName: __privateGet$4(this, _table)
|
1541
3425
|
},
|
1542
3426
|
queryParams: { columns },
|
1543
3427
|
body: record,
|
1544
|
-
...
|
3428
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1545
3429
|
});
|
1546
3430
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1547
|
-
return initObject(this
|
3431
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1548
3432
|
};
|
1549
3433
|
_insertRecordWithId = new WeakSet();
|
1550
|
-
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1551
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
3434
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
1552
3435
|
const record = transformObjectLinks(object);
|
1553
3436
|
const response = await insertRecordWithID({
|
1554
3437
|
pathParams: {
|
1555
3438
|
workspace: "{workspaceId}",
|
1556
3439
|
dbBranchName: "{dbBranch}",
|
3440
|
+
region: "{region}",
|
1557
3441
|
tableName: __privateGet$4(this, _table),
|
1558
3442
|
recordId
|
1559
3443
|
},
|
1560
3444
|
body: record,
|
1561
|
-
queryParams: { createOnly
|
1562
|
-
...
|
3445
|
+
queryParams: { createOnly, columns, ifVersion },
|
3446
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1563
3447
|
});
|
1564
3448
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1565
|
-
return initObject(this
|
1566
|
-
};
|
1567
|
-
|
1568
|
-
|
1569
|
-
const
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
3449
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
3450
|
+
};
|
3451
|
+
_insertRecords = new WeakSet();
|
3452
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
3453
|
+
const chunkedOperations = chunk(
|
3454
|
+
objects.map((object) => ({
|
3455
|
+
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
3456
|
+
})),
|
3457
|
+
BULK_OPERATION_MAX_SIZE
|
3458
|
+
);
|
3459
|
+
const ids = [];
|
3460
|
+
for (const operations of chunkedOperations) {
|
3461
|
+
const { results } = await branchTransaction({
|
3462
|
+
pathParams: {
|
3463
|
+
workspace: "{workspaceId}",
|
3464
|
+
dbBranchName: "{dbBranch}",
|
3465
|
+
region: "{region}"
|
3466
|
+
},
|
3467
|
+
body: { operations },
|
3468
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3469
|
+
});
|
3470
|
+
for (const result of results) {
|
3471
|
+
if (result.operation === "insert") {
|
3472
|
+
ids.push(result.id);
|
3473
|
+
} else {
|
3474
|
+
ids.push(null);
|
3475
|
+
}
|
3476
|
+
}
|
1579
3477
|
}
|
1580
|
-
|
1581
|
-
return response.records?.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
3478
|
+
return ids;
|
1582
3479
|
};
|
1583
3480
|
_updateRecordWithID = new WeakSet();
|
1584
|
-
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1585
|
-
const
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
3481
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
3482
|
+
const { id: _id, ...record } = transformObjectLinks(object);
|
3483
|
+
try {
|
3484
|
+
const response = await updateRecordWithID({
|
3485
|
+
pathParams: {
|
3486
|
+
workspace: "{workspaceId}",
|
3487
|
+
dbBranchName: "{dbBranch}",
|
3488
|
+
region: "{region}",
|
3489
|
+
tableName: __privateGet$4(this, _table),
|
3490
|
+
recordId
|
3491
|
+
},
|
3492
|
+
queryParams: { columns, ifVersion },
|
3493
|
+
body: record,
|
3494
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3495
|
+
});
|
3496
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3497
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
3498
|
+
} catch (e) {
|
3499
|
+
if (isObject(e) && e.status === 404) {
|
3500
|
+
return null;
|
3501
|
+
}
|
3502
|
+
throw e;
|
3503
|
+
}
|
3504
|
+
};
|
3505
|
+
_updateRecords = new WeakSet();
|
3506
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
3507
|
+
const chunkedOperations = chunk(
|
3508
|
+
objects.map(({ id, ...object }) => ({
|
3509
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
3510
|
+
})),
|
3511
|
+
BULK_OPERATION_MAX_SIZE
|
3512
|
+
);
|
3513
|
+
const ids = [];
|
3514
|
+
for (const operations of chunkedOperations) {
|
3515
|
+
const { results } = await branchTransaction({
|
3516
|
+
pathParams: {
|
3517
|
+
workspace: "{workspaceId}",
|
3518
|
+
dbBranchName: "{dbBranch}",
|
3519
|
+
region: "{region}"
|
3520
|
+
},
|
3521
|
+
body: { operations },
|
3522
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3523
|
+
});
|
3524
|
+
for (const result of results) {
|
3525
|
+
if (result.operation === "update") {
|
3526
|
+
ids.push(result.id);
|
3527
|
+
} else {
|
3528
|
+
ids.push(null);
|
3529
|
+
}
|
3530
|
+
}
|
3531
|
+
}
|
3532
|
+
return ids;
|
1595
3533
|
};
|
1596
3534
|
_upsertRecordWithID = new WeakSet();
|
1597
|
-
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1598
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
3535
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
1599
3536
|
const response = await upsertRecordWithID({
|
1600
|
-
pathParams: {
|
1601
|
-
|
3537
|
+
pathParams: {
|
3538
|
+
workspace: "{workspaceId}",
|
3539
|
+
dbBranchName: "{dbBranch}",
|
3540
|
+
region: "{region}",
|
3541
|
+
tableName: __privateGet$4(this, _table),
|
3542
|
+
recordId
|
3543
|
+
},
|
3544
|
+
queryParams: { columns, ifVersion },
|
1602
3545
|
body: object,
|
1603
|
-
...
|
3546
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1604
3547
|
});
|
1605
3548
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1606
|
-
return initObject(this
|
3549
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1607
3550
|
};
|
1608
3551
|
_deleteRecord = new WeakSet();
|
1609
|
-
deleteRecord_fn = async function(recordId) {
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
3552
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
3553
|
+
try {
|
3554
|
+
const response = await deleteRecord({
|
3555
|
+
pathParams: {
|
3556
|
+
workspace: "{workspaceId}",
|
3557
|
+
dbBranchName: "{dbBranch}",
|
3558
|
+
region: "{region}",
|
3559
|
+
tableName: __privateGet$4(this, _table),
|
3560
|
+
recordId
|
3561
|
+
},
|
3562
|
+
queryParams: { columns },
|
3563
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3564
|
+
});
|
3565
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3566
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
3567
|
+
} catch (e) {
|
3568
|
+
if (isObject(e) && e.status === 404) {
|
3569
|
+
return null;
|
3570
|
+
}
|
3571
|
+
throw e;
|
3572
|
+
}
|
3573
|
+
};
|
3574
|
+
_deleteRecords = new WeakSet();
|
3575
|
+
deleteRecords_fn = async function(recordIds) {
|
3576
|
+
const chunkedOperations = chunk(
|
3577
|
+
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
3578
|
+
BULK_OPERATION_MAX_SIZE
|
3579
|
+
);
|
3580
|
+
for (const operations of chunkedOperations) {
|
3581
|
+
await branchTransaction({
|
3582
|
+
pathParams: {
|
3583
|
+
workspace: "{workspaceId}",
|
3584
|
+
dbBranchName: "{dbBranch}",
|
3585
|
+
region: "{region}"
|
3586
|
+
},
|
3587
|
+
body: { operations },
|
3588
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3589
|
+
});
|
3590
|
+
}
|
1615
3591
|
};
|
1616
3592
|
_setCacheQuery = new WeakSet();
|
1617
3593
|
setCacheQuery_fn = async function(query, meta, records) {
|
1618
|
-
await __privateGet$4(this, _cache)
|
3594
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
1619
3595
|
};
|
1620
3596
|
_getCacheQuery = new WeakSet();
|
1621
3597
|
getCacheQuery_fn = async function(query) {
|
1622
3598
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
1623
|
-
const result = await __privateGet$4(this, _cache)
|
3599
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
1624
3600
|
if (!result)
|
1625
3601
|
return null;
|
1626
|
-
const
|
3602
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
3603
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
1627
3604
|
if (ttl < 0)
|
1628
3605
|
return null;
|
1629
3606
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -1633,10 +3610,9 @@ _getSchemaTables$1 = new WeakSet();
|
|
1633
3610
|
getSchemaTables_fn$1 = async function() {
|
1634
3611
|
if (__privateGet$4(this, _schemaTables$2))
|
1635
3612
|
return __privateGet$4(this, _schemaTables$2);
|
1636
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1637
3613
|
const { schema } = await getBranchDetails({
|
1638
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1639
|
-
...
|
3614
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3615
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1640
3616
|
});
|
1641
3617
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1642
3618
|
return schema.tables;
|
@@ -1648,22 +3624,24 @@ const transformObjectLinks = (object) => {
|
|
1648
3624
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1649
3625
|
}, {});
|
1650
3626
|
};
|
1651
|
-
const initObject = (db, schemaTables, table, object) => {
|
1652
|
-
const
|
3627
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
3628
|
+
const data = {};
|
1653
3629
|
const { xata, ...rest } = object ?? {};
|
1654
|
-
Object.assign(
|
3630
|
+
Object.assign(data, rest);
|
1655
3631
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1656
3632
|
if (!columns)
|
1657
3633
|
console.error(`Table ${table} not found in schema`);
|
1658
3634
|
for (const column of columns ?? []) {
|
1659
|
-
|
3635
|
+
if (!isValidColumn(selectedColumns, column))
|
3636
|
+
continue;
|
3637
|
+
const value = data[column.name];
|
1660
3638
|
switch (column.type) {
|
1661
3639
|
case "datetime": {
|
1662
|
-
const date = value !== void 0 ? new Date(value) :
|
1663
|
-
if (date && isNaN(date.getTime())) {
|
3640
|
+
const date = value !== void 0 ? new Date(value) : null;
|
3641
|
+
if (date !== null && isNaN(date.getTime())) {
|
1664
3642
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1665
|
-
} else
|
1666
|
-
|
3643
|
+
} else {
|
3644
|
+
data[column.name] = date;
|
1667
3645
|
}
|
1668
3646
|
break;
|
1669
3647
|
}
|
@@ -1672,32 +3650,88 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1672
3650
|
if (!linkTable) {
|
1673
3651
|
console.error(`Failed to parse link for field ${column.name}`);
|
1674
3652
|
} else if (isObject(value)) {
|
1675
|
-
|
3653
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
3654
|
+
if (item === column.name) {
|
3655
|
+
return [...acc, "*"];
|
3656
|
+
}
|
3657
|
+
if (item.startsWith(`${column.name}.`)) {
|
3658
|
+
const [, ...path] = item.split(".");
|
3659
|
+
return [...acc, path.join(".")];
|
3660
|
+
}
|
3661
|
+
return acc;
|
3662
|
+
}, []);
|
3663
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
3664
|
+
} else {
|
3665
|
+
data[column.name] = null;
|
1676
3666
|
}
|
1677
3667
|
break;
|
1678
3668
|
}
|
3669
|
+
default:
|
3670
|
+
data[column.name] = value ?? null;
|
3671
|
+
if (column.notNull === true && value === null) {
|
3672
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
3673
|
+
}
|
3674
|
+
break;
|
1679
3675
|
}
|
1680
3676
|
}
|
1681
|
-
|
1682
|
-
|
3677
|
+
const record = { ...data };
|
3678
|
+
const serializable = { xata, ...transformObjectLinks(data) };
|
3679
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
3680
|
+
record.read = function(columns2) {
|
3681
|
+
return db[table].read(record["id"], columns2);
|
3682
|
+
};
|
3683
|
+
record.update = function(data2, b, c) {
|
3684
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
3685
|
+
const ifVersion = parseIfVersion(b, c);
|
3686
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
3687
|
+
};
|
3688
|
+
record.replace = function(data2, b, c) {
|
3689
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
3690
|
+
const ifVersion = parseIfVersion(b, c);
|
3691
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
3692
|
+
};
|
3693
|
+
record.delete = function() {
|
3694
|
+
return db[table].delete(record["id"]);
|
1683
3695
|
};
|
1684
|
-
|
1685
|
-
|
3696
|
+
record.xata = Object.freeze(metadata);
|
3697
|
+
record.getMetadata = function() {
|
3698
|
+
return record.xata;
|
1686
3699
|
};
|
1687
|
-
|
1688
|
-
return
|
3700
|
+
record.toSerializable = function() {
|
3701
|
+
return JSON.parse(JSON.stringify(serializable));
|
1689
3702
|
};
|
1690
|
-
|
1691
|
-
return
|
3703
|
+
record.toString = function() {
|
3704
|
+
return JSON.stringify(transformObjectLinks(serializable));
|
1692
3705
|
};
|
1693
|
-
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
1694
|
-
Object.defineProperty(
|
3706
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
3707
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
1695
3708
|
}
|
1696
|
-
Object.freeze(
|
1697
|
-
return
|
3709
|
+
Object.freeze(record);
|
3710
|
+
return record;
|
1698
3711
|
};
|
1699
|
-
function
|
1700
|
-
|
3712
|
+
function extractId(value) {
|
3713
|
+
if (isString(value))
|
3714
|
+
return value;
|
3715
|
+
if (isObject(value) && isString(value.id))
|
3716
|
+
return value.id;
|
3717
|
+
return void 0;
|
3718
|
+
}
|
3719
|
+
function isValidColumn(columns, column) {
|
3720
|
+
if (columns.includes("*"))
|
3721
|
+
return true;
|
3722
|
+
if (column.type === "link") {
|
3723
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
3724
|
+
return linkColumns.length > 0;
|
3725
|
+
}
|
3726
|
+
return columns.includes(column.name);
|
3727
|
+
}
|
3728
|
+
function parseIfVersion(...args) {
|
3729
|
+
for (const arg of args) {
|
3730
|
+
if (isObject(arg) && isNumber(arg.ifVersion)) {
|
3731
|
+
return arg.ifVersion;
|
3732
|
+
}
|
3733
|
+
}
|
3734
|
+
return void 0;
|
1701
3735
|
}
|
1702
3736
|
|
1703
3737
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1749,18 +3783,25 @@ class SimpleCache {
|
|
1749
3783
|
}
|
1750
3784
|
_map = new WeakMap();
|
1751
3785
|
|
1752
|
-
const
|
1753
|
-
const
|
1754
|
-
const
|
1755
|
-
const
|
1756
|
-
const
|
1757
|
-
const
|
3786
|
+
const greaterThan = (value) => ({ $gt: value });
|
3787
|
+
const gt = greaterThan;
|
3788
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
3789
|
+
const greaterEquals = greaterThanEquals;
|
3790
|
+
const gte = greaterThanEquals;
|
3791
|
+
const ge = greaterThanEquals;
|
3792
|
+
const lessThan = (value) => ({ $lt: value });
|
3793
|
+
const lt = lessThan;
|
3794
|
+
const lessThanEquals = (value) => ({ $le: value });
|
3795
|
+
const lessEquals = lessThanEquals;
|
3796
|
+
const lte = lessThanEquals;
|
3797
|
+
const le = lessThanEquals;
|
1758
3798
|
const exists = (column) => ({ $exists: column });
|
1759
3799
|
const notExists = (column) => ({ $notExists: column });
|
1760
3800
|
const startsWith = (value) => ({ $startsWith: value });
|
1761
3801
|
const endsWith = (value) => ({ $endsWith: value });
|
1762
3802
|
const pattern = (value) => ({ $pattern: value });
|
1763
3803
|
const is = (value) => ({ $is: value });
|
3804
|
+
const equals = is;
|
1764
3805
|
const isNot = (value) => ({ $isNot: value });
|
1765
3806
|
const contains = (value) => ({ $contains: value });
|
1766
3807
|
const includes = (value) => ({ $includes: value });
|
@@ -1850,23 +3891,23 @@ class SearchPlugin extends XataPlugin {
|
|
1850
3891
|
__privateAdd$1(this, _schemaTables, void 0);
|
1851
3892
|
__privateSet$1(this, _schemaTables, schemaTables);
|
1852
3893
|
}
|
1853
|
-
build(
|
3894
|
+
build(pluginOptions) {
|
1854
3895
|
return {
|
1855
3896
|
all: async (query, options = {}) => {
|
1856
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
1857
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3897
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3898
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
1858
3899
|
return records.map((record) => {
|
1859
3900
|
const { table = "orphan" } = record.xata;
|
1860
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
3901
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
1861
3902
|
});
|
1862
3903
|
},
|
1863
3904
|
byTable: async (query, options = {}) => {
|
1864
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
1865
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3905
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3906
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
1866
3907
|
return records.reduce((acc, record) => {
|
1867
3908
|
const { table = "orphan" } = record.xata;
|
1868
3909
|
const items = acc[table] ?? [];
|
1869
|
-
const item = initObject(this.db, schemaTables, table, record);
|
3910
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1870
3911
|
return { ...acc, [table]: [...items, item] };
|
1871
3912
|
}, {});
|
1872
3913
|
}
|
@@ -1875,106 +3916,40 @@ class SearchPlugin extends XataPlugin {
|
|
1875
3916
|
}
|
1876
3917
|
_schemaTables = new WeakMap();
|
1877
3918
|
_search = new WeakSet();
|
1878
|
-
search_fn = async function(query, options,
|
1879
|
-
const
|
1880
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
3919
|
+
search_fn = async function(query, options, pluginOptions) {
|
3920
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
1881
3921
|
const { records } = await searchBranch({
|
1882
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1883
|
-
|
1884
|
-
|
3922
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3923
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3924
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
3925
|
+
...pluginOptions
|
1885
3926
|
});
|
1886
3927
|
return records;
|
1887
3928
|
};
|
1888
3929
|
_getSchemaTables = new WeakSet();
|
1889
|
-
getSchemaTables_fn = async function(
|
3930
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
1890
3931
|
if (__privateGet$1(this, _schemaTables))
|
1891
3932
|
return __privateGet$1(this, _schemaTables);
|
1892
|
-
const fetchProps = await getFetchProps();
|
1893
3933
|
const { schema } = await getBranchDetails({
|
1894
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1895
|
-
...
|
3934
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3935
|
+
...pluginOptions
|
1896
3936
|
});
|
1897
3937
|
__privateSet$1(this, _schemaTables, schema.tables);
|
1898
3938
|
return schema.tables;
|
1899
3939
|
};
|
1900
3940
|
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
const gitBranch = envBranch || await getGitBranch();
|
1914
|
-
return resolveXataBranch(gitBranch, options);
|
1915
|
-
}
|
1916
|
-
async function getCurrentBranchDetails(options) {
|
1917
|
-
const branch = await getCurrentBranchName(options);
|
1918
|
-
return getDatabaseBranch(branch, options);
|
1919
|
-
}
|
1920
|
-
async function resolveXataBranch(gitBranch, options) {
|
1921
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1922
|
-
const apiKey = options?.apiKey || getAPIKey();
|
1923
|
-
if (!databaseURL)
|
1924
|
-
throw new Error(
|
1925
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1926
|
-
);
|
1927
|
-
if (!apiKey)
|
1928
|
-
throw new Error(
|
1929
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1930
|
-
);
|
1931
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1932
|
-
const [workspace] = host.split(".");
|
1933
|
-
const { fallbackBranch } = getEnvironment();
|
1934
|
-
const { branch } = await resolveBranch({
|
1935
|
-
apiKey,
|
1936
|
-
apiUrl: databaseURL,
|
1937
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1938
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
1939
|
-
pathParams: { dbName, workspace },
|
1940
|
-
queryParams: { gitBranch, fallbackBranch }
|
1941
|
-
});
|
1942
|
-
return branch;
|
1943
|
-
}
|
1944
|
-
async function getDatabaseBranch(branch, options) {
|
1945
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1946
|
-
const apiKey = options?.apiKey || getAPIKey();
|
1947
|
-
if (!databaseURL)
|
1948
|
-
throw new Error(
|
1949
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
1950
|
-
);
|
1951
|
-
if (!apiKey)
|
1952
|
-
throw new Error(
|
1953
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1954
|
-
);
|
1955
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
1956
|
-
const [workspace] = host.split(".");
|
1957
|
-
const dbBranchName = `${database}:${branch}`;
|
1958
|
-
try {
|
1959
|
-
return await getBranchDetails({
|
1960
|
-
apiKey,
|
1961
|
-
apiUrl: databaseURL,
|
1962
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1963
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
1964
|
-
pathParams: { dbBranchName, workspace }
|
1965
|
-
});
|
1966
|
-
} catch (err) {
|
1967
|
-
if (isObject(err) && err.status === 404)
|
1968
|
-
return null;
|
1969
|
-
throw err;
|
1970
|
-
}
|
1971
|
-
}
|
1972
|
-
function getDatabaseURL() {
|
1973
|
-
try {
|
1974
|
-
const { databaseURL } = getEnvironment();
|
1975
|
-
return databaseURL;
|
1976
|
-
} catch (err) {
|
1977
|
-
return void 0;
|
3941
|
+
class TransactionPlugin extends XataPlugin {
|
3942
|
+
build(pluginOptions) {
|
3943
|
+
return {
|
3944
|
+
run: async (operations) => {
|
3945
|
+
const response = await branchTransaction({
|
3946
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3947
|
+
body: { operations },
|
3948
|
+
...pluginOptions
|
3949
|
+
});
|
3950
|
+
return response;
|
3951
|
+
}
|
3952
|
+
};
|
1978
3953
|
}
|
1979
3954
|
}
|
1980
3955
|
|
@@ -2001,85 +3976,203 @@ var __privateMethod = (obj, member, method) => {
|
|
2001
3976
|
return method;
|
2002
3977
|
};
|
2003
3978
|
const buildClient = (plugins) => {
|
2004
|
-
var
|
3979
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
2005
3980
|
return _a = class {
|
2006
3981
|
constructor(options = {}, schemaTables) {
|
2007
3982
|
__privateAdd(this, _parseOptions);
|
2008
3983
|
__privateAdd(this, _getFetchProps);
|
2009
|
-
__privateAdd(this,
|
2010
|
-
__privateAdd(this, _branch, void 0);
|
3984
|
+
__privateAdd(this, _options, void 0);
|
2011
3985
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3986
|
+
__privateSet(this, _options, safeOptions);
|
2012
3987
|
const pluginOptions = {
|
2013
|
-
|
2014
|
-
cache: safeOptions.cache
|
3988
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3989
|
+
cache: safeOptions.cache,
|
3990
|
+
host: safeOptions.host
|
2015
3991
|
};
|
2016
3992
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2017
3993
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3994
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
2018
3995
|
this.db = db;
|
2019
3996
|
this.search = search;
|
3997
|
+
this.transactions = transactions;
|
2020
3998
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
2021
3999
|
if (namespace === void 0)
|
2022
4000
|
continue;
|
2023
|
-
|
2024
|
-
if (result instanceof Promise) {
|
2025
|
-
void result.then((namespace2) => {
|
2026
|
-
this[key] = namespace2;
|
2027
|
-
});
|
2028
|
-
} else {
|
2029
|
-
this[key] = result;
|
2030
|
-
}
|
4001
|
+
this[key] = namespace.build(pluginOptions);
|
2031
4002
|
}
|
2032
4003
|
}
|
2033
|
-
|
4004
|
+
async getConfig() {
|
4005
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
4006
|
+
const branch = __privateGet(this, _options).branch;
|
4007
|
+
return { databaseURL, branch };
|
4008
|
+
}
|
4009
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
4010
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
4011
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
4012
|
+
if (isBrowser && !enableBrowser) {
|
4013
|
+
throw new Error(
|
4014
|
+
"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."
|
4015
|
+
);
|
4016
|
+
}
|
2034
4017
|
const fetch = getFetchImplementation(options?.fetch);
|
2035
4018
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2036
4019
|
const apiKey = options?.apiKey || getAPIKey();
|
2037
4020
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2038
|
-
const
|
2039
|
-
|
2040
|
-
|
4021
|
+
const trace = options?.trace ?? defaultTrace;
|
4022
|
+
const clientName = options?.clientName;
|
4023
|
+
const host = options?.host ?? "production";
|
4024
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
4025
|
+
if (!apiKey) {
|
4026
|
+
throw new Error("Option apiKey is required");
|
4027
|
+
}
|
4028
|
+
if (!databaseURL) {
|
4029
|
+
throw new Error("Option databaseURL is required");
|
2041
4030
|
}
|
2042
|
-
|
2043
|
-
|
4031
|
+
const envBranch = getBranch();
|
4032
|
+
const previewBranch = getPreviewBranch();
|
4033
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4034
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4035
|
+
console.warn(
|
4036
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4037
|
+
);
|
4038
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4039
|
+
console.warn(
|
4040
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4041
|
+
);
|
4042
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4043
|
+
console.warn(
|
4044
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4045
|
+
);
|
4046
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4047
|
+
console.warn(
|
4048
|
+
`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.`
|
4049
|
+
);
|
4050
|
+
}
|
4051
|
+
return {
|
4052
|
+
fetch,
|
4053
|
+
databaseURL,
|
4054
|
+
apiKey,
|
4055
|
+
branch,
|
4056
|
+
cache,
|
4057
|
+
trace,
|
4058
|
+
host,
|
4059
|
+
clientID: generateUUID(),
|
4060
|
+
enableBrowser,
|
4061
|
+
clientName,
|
4062
|
+
xataAgentExtra
|
4063
|
+
};
|
4064
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
2044
4065
|
fetch,
|
2045
4066
|
apiKey,
|
2046
4067
|
databaseURL,
|
2047
|
-
branch
|
4068
|
+
branch,
|
4069
|
+
trace,
|
4070
|
+
clientID,
|
4071
|
+
clientName,
|
4072
|
+
xataAgentExtra
|
2048
4073
|
}) {
|
2049
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2050
|
-
if (!branchValue)
|
2051
|
-
throw new Error("Unable to resolve branch value");
|
2052
4074
|
return {
|
2053
|
-
|
4075
|
+
fetch,
|
2054
4076
|
apiKey,
|
2055
4077
|
apiUrl: "",
|
4078
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
2056
4079
|
workspacesApiUrl: (path, params) => {
|
2057
4080
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2058
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${
|
4081
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
2059
4082
|
return databaseURL + newPath;
|
2060
|
-
}
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
if (param === void 0)
|
2066
|
-
return void 0;
|
2067
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
2068
|
-
const evaluateBranch = async (strategy) => {
|
2069
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
4083
|
+
},
|
4084
|
+
trace,
|
4085
|
+
clientID,
|
4086
|
+
clientName,
|
4087
|
+
xataAgentExtra
|
2070
4088
|
};
|
2071
|
-
for await (const strategy of strategies) {
|
2072
|
-
const branch = await evaluateBranch(strategy);
|
2073
|
-
if (branch) {
|
2074
|
-
__privateSet(this, _branch, branch);
|
2075
|
-
return branch;
|
2076
|
-
}
|
2077
|
-
}
|
2078
4089
|
}, _a;
|
2079
4090
|
};
|
2080
4091
|
class BaseClient extends buildClient() {
|
2081
4092
|
}
|
2082
4093
|
|
4094
|
+
const META = "__";
|
4095
|
+
const VALUE = "___";
|
4096
|
+
class Serializer {
|
4097
|
+
constructor() {
|
4098
|
+
this.classes = {};
|
4099
|
+
}
|
4100
|
+
add(clazz) {
|
4101
|
+
this.classes[clazz.name] = clazz;
|
4102
|
+
}
|
4103
|
+
toJSON(data) {
|
4104
|
+
function visit(obj) {
|
4105
|
+
if (Array.isArray(obj))
|
4106
|
+
return obj.map(visit);
|
4107
|
+
const type = typeof obj;
|
4108
|
+
if (type === "undefined")
|
4109
|
+
return { [META]: "undefined" };
|
4110
|
+
if (type === "bigint")
|
4111
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
4112
|
+
if (obj === null || type !== "object")
|
4113
|
+
return obj;
|
4114
|
+
const constructor = obj.constructor;
|
4115
|
+
const o = { [META]: constructor.name };
|
4116
|
+
for (const [key, value] of Object.entries(obj)) {
|
4117
|
+
o[key] = visit(value);
|
4118
|
+
}
|
4119
|
+
if (constructor === Date)
|
4120
|
+
o[VALUE] = obj.toISOString();
|
4121
|
+
if (constructor === Map)
|
4122
|
+
o[VALUE] = Object.fromEntries(obj);
|
4123
|
+
if (constructor === Set)
|
4124
|
+
o[VALUE] = [...obj];
|
4125
|
+
return o;
|
4126
|
+
}
|
4127
|
+
return JSON.stringify(visit(data));
|
4128
|
+
}
|
4129
|
+
fromJSON(json) {
|
4130
|
+
return JSON.parse(json, (key, value) => {
|
4131
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
4132
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
4133
|
+
const constructor = this.classes[clazz];
|
4134
|
+
if (constructor) {
|
4135
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
4136
|
+
}
|
4137
|
+
if (clazz === "Date")
|
4138
|
+
return new Date(val);
|
4139
|
+
if (clazz === "Set")
|
4140
|
+
return new Set(val);
|
4141
|
+
if (clazz === "Map")
|
4142
|
+
return new Map(Object.entries(val));
|
4143
|
+
if (clazz === "bigint")
|
4144
|
+
return BigInt(val);
|
4145
|
+
if (clazz === "undefined")
|
4146
|
+
return void 0;
|
4147
|
+
return rest;
|
4148
|
+
}
|
4149
|
+
return value;
|
4150
|
+
});
|
4151
|
+
}
|
4152
|
+
}
|
4153
|
+
const defaultSerializer = new Serializer();
|
4154
|
+
const serialize = (data) => {
|
4155
|
+
return defaultSerializer.toJSON(data);
|
4156
|
+
};
|
4157
|
+
const deserialize = (json) => {
|
4158
|
+
return defaultSerializer.fromJSON(json);
|
4159
|
+
};
|
4160
|
+
|
4161
|
+
function buildWorkerRunner(config) {
|
4162
|
+
return function xataWorker(name, worker) {
|
4163
|
+
return async (...args) => {
|
4164
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
4165
|
+
const result = await fetch(url, {
|
4166
|
+
method: "POST",
|
4167
|
+
headers: { "Content-Type": "application/json" },
|
4168
|
+
body: serialize({ args })
|
4169
|
+
});
|
4170
|
+
const text = await result.text();
|
4171
|
+
return deserialize(text);
|
4172
|
+
};
|
4173
|
+
};
|
4174
|
+
}
|
4175
|
+
|
2083
4176
|
class XataError extends Error {
|
2084
4177
|
constructor(message, status) {
|
2085
4178
|
super(message);
|
@@ -2088,6 +4181,7 @@ class XataError extends Error {
|
|
2088
4181
|
}
|
2089
4182
|
|
2090
4183
|
exports.BaseClient = BaseClient;
|
4184
|
+
exports.FetcherError = FetcherError;
|
2091
4185
|
exports.Operations = operationsByTag;
|
2092
4186
|
exports.PAGINATION_DEFAULT_OFFSET = PAGINATION_DEFAULT_OFFSET;
|
2093
4187
|
exports.PAGINATION_DEFAULT_SIZE = PAGINATION_DEFAULT_SIZE;
|
@@ -2100,6 +4194,7 @@ exports.Repository = Repository;
|
|
2100
4194
|
exports.RestRepository = RestRepository;
|
2101
4195
|
exports.SchemaPlugin = SchemaPlugin;
|
2102
4196
|
exports.SearchPlugin = SearchPlugin;
|
4197
|
+
exports.Serializer = Serializer;
|
2103
4198
|
exports.SimpleCache = SimpleCache;
|
2104
4199
|
exports.XataApiClient = XataApiClient;
|
2105
4200
|
exports.XataApiPlugin = XataApiPlugin;
|
@@ -2108,41 +4203,66 @@ exports.XataPlugin = XataPlugin;
|
|
2108
4203
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
2109
4204
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2110
4205
|
exports.addTableColumn = addTableColumn;
|
4206
|
+
exports.aggregateTable = aggregateTable;
|
4207
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
4208
|
+
exports.askTable = askTable;
|
4209
|
+
exports.branchTransaction = branchTransaction;
|
2111
4210
|
exports.buildClient = buildClient;
|
4211
|
+
exports.buildPreviewBranchName = buildPreviewBranchName;
|
4212
|
+
exports.buildProviderString = buildProviderString;
|
4213
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
2112
4214
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2113
4215
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
4216
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
4217
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
4218
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
2114
4219
|
exports.contains = contains;
|
4220
|
+
exports.copyBranch = copyBranch;
|
2115
4221
|
exports.createBranch = createBranch;
|
2116
4222
|
exports.createDatabase = createDatabase;
|
4223
|
+
exports.createMigrationRequest = createMigrationRequest;
|
2117
4224
|
exports.createTable = createTable;
|
2118
4225
|
exports.createUserAPIKey = createUserAPIKey;
|
2119
4226
|
exports.createWorkspace = createWorkspace;
|
2120
4227
|
exports.deleteBranch = deleteBranch;
|
2121
4228
|
exports.deleteColumn = deleteColumn;
|
2122
4229
|
exports.deleteDatabase = deleteDatabase;
|
4230
|
+
exports.deleteDatabaseGithubSettings = deleteDatabaseGithubSettings;
|
4231
|
+
exports.deleteFile = deleteFile;
|
4232
|
+
exports.deleteFileItem = deleteFileItem;
|
2123
4233
|
exports.deleteRecord = deleteRecord;
|
2124
4234
|
exports.deleteTable = deleteTable;
|
2125
4235
|
exports.deleteUser = deleteUser;
|
2126
4236
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
2127
4237
|
exports.deleteWorkspace = deleteWorkspace;
|
4238
|
+
exports.deserialize = deserialize;
|
2128
4239
|
exports.endsWith = endsWith;
|
4240
|
+
exports.equals = equals;
|
2129
4241
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
2130
4242
|
exports.exists = exists;
|
4243
|
+
exports.fileAccess = fileAccess;
|
2131
4244
|
exports.ge = ge;
|
2132
4245
|
exports.getAPIKey = getAPIKey;
|
4246
|
+
exports.getBranch = getBranch;
|
2133
4247
|
exports.getBranchDetails = getBranchDetails;
|
2134
4248
|
exports.getBranchList = getBranchList;
|
2135
4249
|
exports.getBranchMetadata = getBranchMetadata;
|
2136
4250
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
2137
4251
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
4252
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
2138
4253
|
exports.getBranchStats = getBranchStats;
|
2139
4254
|
exports.getColumn = getColumn;
|
2140
|
-
exports.
|
2141
|
-
exports.getCurrentBranchName = getCurrentBranchName;
|
4255
|
+
exports.getDatabaseGithubSettings = getDatabaseGithubSettings;
|
2142
4256
|
exports.getDatabaseList = getDatabaseList;
|
2143
4257
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2144
4258
|
exports.getDatabaseURL = getDatabaseURL;
|
4259
|
+
exports.getFile = getFile;
|
4260
|
+
exports.getFileItem = getFileItem;
|
2145
4261
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
4262
|
+
exports.getHostUrl = getHostUrl;
|
4263
|
+
exports.getMigrationRequest = getMigrationRequest;
|
4264
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
4265
|
+
exports.getPreviewBranch = getPreviewBranch;
|
2146
4266
|
exports.getRecord = getRecord;
|
2147
4267
|
exports.getTableColumns = getTableColumns;
|
2148
4268
|
exports.getTableSchema = getTableSchema;
|
@@ -2151,6 +4271,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
2151
4271
|
exports.getWorkspace = getWorkspace;
|
2152
4272
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
2153
4273
|
exports.getWorkspacesList = getWorkspacesList;
|
4274
|
+
exports.greaterEquals = greaterEquals;
|
4275
|
+
exports.greaterThan = greaterThan;
|
4276
|
+
exports.greaterThanEquals = greaterThanEquals;
|
2154
4277
|
exports.gt = gt;
|
2155
4278
|
exports.gte = gte;
|
2156
4279
|
exports.includes = includes;
|
@@ -2162,26 +4285,49 @@ exports.insertRecordWithID = insertRecordWithID;
|
|
2162
4285
|
exports.inviteWorkspaceMember = inviteWorkspaceMember;
|
2163
4286
|
exports.is = is;
|
2164
4287
|
exports.isCursorPaginationOptions = isCursorPaginationOptions;
|
4288
|
+
exports.isHostProviderAlias = isHostProviderAlias;
|
4289
|
+
exports.isHostProviderBuilder = isHostProviderBuilder;
|
2165
4290
|
exports.isIdentifiable = isIdentifiable;
|
2166
4291
|
exports.isNot = isNot;
|
2167
4292
|
exports.isXataRecord = isXataRecord;
|
2168
4293
|
exports.le = le;
|
4294
|
+
exports.lessEquals = lessEquals;
|
4295
|
+
exports.lessThan = lessThan;
|
4296
|
+
exports.lessThanEquals = lessThanEquals;
|
4297
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
4298
|
+
exports.listRegions = listRegions;
|
2169
4299
|
exports.lt = lt;
|
2170
4300
|
exports.lte = lte;
|
4301
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
2171
4302
|
exports.notExists = notExists;
|
2172
4303
|
exports.operationsByTag = operationsByTag;
|
4304
|
+
exports.parseProviderString = parseProviderString;
|
4305
|
+
exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
|
2173
4306
|
exports.pattern = pattern;
|
4307
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
4308
|
+
exports.pushBranchMigrations = pushBranchMigrations;
|
4309
|
+
exports.putFile = putFile;
|
4310
|
+
exports.putFileItem = putFileItem;
|
4311
|
+
exports.queryMigrationRequests = queryMigrationRequests;
|
2174
4312
|
exports.queryTable = queryTable;
|
2175
4313
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
2176
4314
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
4315
|
+
exports.renameDatabase = renameDatabase;
|
2177
4316
|
exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
2178
4317
|
exports.resolveBranch = resolveBranch;
|
2179
4318
|
exports.searchBranch = searchBranch;
|
2180
4319
|
exports.searchTable = searchTable;
|
4320
|
+
exports.serialize = serialize;
|
2181
4321
|
exports.setTableSchema = setTableSchema;
|
4322
|
+
exports.sqlQuery = sqlQuery;
|
2182
4323
|
exports.startsWith = startsWith;
|
4324
|
+
exports.summarizeTable = summarizeTable;
|
2183
4325
|
exports.updateBranchMetadata = updateBranchMetadata;
|
4326
|
+
exports.updateBranchSchema = updateBranchSchema;
|
2184
4327
|
exports.updateColumn = updateColumn;
|
4328
|
+
exports.updateDatabaseGithubSettings = updateDatabaseGithubSettings;
|
4329
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
4330
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
2185
4331
|
exports.updateRecordWithID = updateRecordWithID;
|
2186
4332
|
exports.updateTable = updateTable;
|
2187
4333
|
exports.updateUser = updateUser;
|
@@ -2189,4 +4335,5 @@ exports.updateWorkspace = updateWorkspace;
|
|
2189
4335
|
exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
|
2190
4336
|
exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
|
2191
4337
|
exports.upsertRecordWithID = upsertRecordWithID;
|
4338
|
+
exports.vectorSearchTable = vectorSearchTable;
|
2192
4339
|
//# sourceMappingURL=index.cjs.map
|