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