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