@xata.io/client 0.0.0-alpha.vfdcf483 → 0.0.0-alpha.vfdd8c9fa700ee4d676771b5b8b8052b7734cb8c4
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 +488 -0
- package/README.md +3 -269
- package/dist/index.cjs +2379 -1069
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6989 -1861
- package/dist/index.mjs +2307 -1047
- 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",
|
@@ -19,7 +18,8 @@ const TraceAttributes = {
|
|
19
18
|
HTTP_METHOD: "http.method",
|
20
19
|
HTTP_URL: "http.url",
|
21
20
|
HTTP_ROUTE: "http.route",
|
22
|
-
HTTP_TARGET: "http.target"
|
21
|
+
HTTP_TARGET: "http.target",
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
23
23
|
};
|
24
24
|
|
25
25
|
function notEmpty(value) {
|
@@ -28,8 +28,18 @@ function notEmpty(value) {
|
|
28
28
|
function compact(arr) {
|
29
29
|
return arr.filter(notEmpty);
|
30
30
|
}
|
31
|
+
function compactObject(obj) {
|
32
|
+
return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
|
33
|
+
}
|
34
|
+
function isBlob(value) {
|
35
|
+
try {
|
36
|
+
return value instanceof Blob;
|
37
|
+
} catch (error) {
|
38
|
+
return false;
|
39
|
+
}
|
40
|
+
}
|
31
41
|
function isObject(value) {
|
32
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
33
43
|
}
|
34
44
|
function isDefined(value) {
|
35
45
|
return value !== null && value !== void 0;
|
@@ -40,6 +50,21 @@ function isString(value) {
|
|
40
50
|
function isStringArray(value) {
|
41
51
|
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
42
52
|
}
|
53
|
+
function isNumber(value) {
|
54
|
+
return isDefined(value) && typeof value === "number";
|
55
|
+
}
|
56
|
+
function parseNumber(value) {
|
57
|
+
if (isNumber(value)) {
|
58
|
+
return value;
|
59
|
+
}
|
60
|
+
if (isString(value)) {
|
61
|
+
const parsed = Number(value);
|
62
|
+
if (!Number.isNaN(parsed)) {
|
63
|
+
return parsed;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return void 0;
|
67
|
+
}
|
43
68
|
function toBase64(value) {
|
44
69
|
try {
|
45
70
|
return btoa(value);
|
@@ -48,16 +73,60 @@ function toBase64(value) {
|
|
48
73
|
return buf.from(value).toString("base64");
|
49
74
|
}
|
50
75
|
}
|
76
|
+
function deepMerge(a, b) {
|
77
|
+
const result = { ...a };
|
78
|
+
for (const [key, value] of Object.entries(b)) {
|
79
|
+
if (isObject(value) && isObject(result[key])) {
|
80
|
+
result[key] = deepMerge(result[key], value);
|
81
|
+
} else {
|
82
|
+
result[key] = value;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
return result;
|
86
|
+
}
|
87
|
+
function chunk(array, chunkSize) {
|
88
|
+
const result = [];
|
89
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
90
|
+
result.push(array.slice(i, i + chunkSize));
|
91
|
+
}
|
92
|
+
return result;
|
93
|
+
}
|
94
|
+
async function timeout(ms) {
|
95
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
96
|
+
}
|
97
|
+
function timeoutWithCancel(ms) {
|
98
|
+
let timeoutId;
|
99
|
+
const promise = new Promise((resolve) => {
|
100
|
+
timeoutId = setTimeout(() => {
|
101
|
+
resolve();
|
102
|
+
}, ms);
|
103
|
+
});
|
104
|
+
return {
|
105
|
+
cancel: () => clearTimeout(timeoutId),
|
106
|
+
promise
|
107
|
+
};
|
108
|
+
}
|
109
|
+
function promiseMap(inputValues, mapper) {
|
110
|
+
const reducer = (acc$, inputValue) => acc$.then(
|
111
|
+
(acc) => mapper(inputValue).then((result) => {
|
112
|
+
acc.push(result);
|
113
|
+
return acc;
|
114
|
+
})
|
115
|
+
);
|
116
|
+
return inputValues.reduce(reducer, Promise.resolve([]));
|
117
|
+
}
|
51
118
|
|
52
119
|
function getEnvironment() {
|
53
120
|
try {
|
54
|
-
if (
|
121
|
+
if (isDefined(process) && isDefined(process.env)) {
|
55
122
|
return {
|
56
123
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
57
124
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
58
125
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
59
|
-
|
60
|
-
|
126
|
+
deployPreview: process.env.XATA_PREVIEW,
|
127
|
+
deployPreviewBranch: process.env.XATA_PREVIEW_BRANCH,
|
128
|
+
vercelGitCommitRef: process.env.VERCEL_GIT_COMMIT_REF,
|
129
|
+
vercelGitRepoOwner: process.env.VERCEL_GIT_REPO_OWNER
|
61
130
|
};
|
62
131
|
}
|
63
132
|
} catch (err) {
|
@@ -68,8 +137,10 @@ function getEnvironment() {
|
|
68
137
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
69
138
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
70
139
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
71
|
-
|
72
|
-
|
140
|
+
deployPreview: Deno.env.get("XATA_PREVIEW"),
|
141
|
+
deployPreviewBranch: Deno.env.get("XATA_PREVIEW_BRANCH"),
|
142
|
+
vercelGitCommitRef: Deno.env.get("VERCEL_GIT_COMMIT_REF"),
|
143
|
+
vercelGitRepoOwner: Deno.env.get("VERCEL_GIT_REPO_OWNER")
|
73
144
|
};
|
74
145
|
}
|
75
146
|
} catch (err) {
|
@@ -78,10 +149,31 @@ function getEnvironment() {
|
|
78
149
|
apiKey: getGlobalApiKey(),
|
79
150
|
databaseURL: getGlobalDatabaseURL(),
|
80
151
|
branch: getGlobalBranch(),
|
81
|
-
|
82
|
-
|
152
|
+
deployPreview: void 0,
|
153
|
+
deployPreviewBranch: void 0,
|
154
|
+
vercelGitCommitRef: void 0,
|
155
|
+
vercelGitRepoOwner: void 0
|
83
156
|
};
|
84
157
|
}
|
158
|
+
function getEnableBrowserVariable() {
|
159
|
+
try {
|
160
|
+
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
161
|
+
return process.env.XATA_ENABLE_BROWSER === "true";
|
162
|
+
}
|
163
|
+
} catch (err) {
|
164
|
+
}
|
165
|
+
try {
|
166
|
+
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
167
|
+
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
168
|
+
}
|
169
|
+
} catch (err) {
|
170
|
+
}
|
171
|
+
try {
|
172
|
+
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
173
|
+
} catch (err) {
|
174
|
+
return void 0;
|
175
|
+
}
|
176
|
+
}
|
85
177
|
function getGlobalApiKey() {
|
86
178
|
try {
|
87
179
|
return XATA_API_KEY;
|
@@ -103,56 +195,338 @@ function getGlobalBranch() {
|
|
103
195
|
return void 0;
|
104
196
|
}
|
105
197
|
}
|
106
|
-
function
|
198
|
+
function getDatabaseURL() {
|
107
199
|
try {
|
108
|
-
|
200
|
+
const { databaseURL } = getEnvironment();
|
201
|
+
return databaseURL;
|
109
202
|
} catch (err) {
|
110
203
|
return void 0;
|
111
204
|
}
|
112
205
|
}
|
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"] };
|
206
|
+
function getAPIKey() {
|
118
207
|
try {
|
119
|
-
|
120
|
-
|
121
|
-
}
|
122
|
-
const { execSync } = await import(nodeModule);
|
123
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
208
|
+
const { apiKey } = getEnvironment();
|
209
|
+
return apiKey;
|
124
210
|
} catch (err) {
|
211
|
+
return void 0;
|
125
212
|
}
|
213
|
+
}
|
214
|
+
function getBranch() {
|
126
215
|
try {
|
127
|
-
|
128
|
-
|
129
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
130
|
-
}
|
216
|
+
const { branch } = getEnvironment();
|
217
|
+
return branch;
|
131
218
|
} catch (err) {
|
219
|
+
return void 0;
|
132
220
|
}
|
133
221
|
}
|
134
|
-
|
135
|
-
|
222
|
+
function buildPreviewBranchName({ org, branch }) {
|
223
|
+
return `preview-${org}-${branch}`;
|
224
|
+
}
|
225
|
+
function getPreviewBranch() {
|
136
226
|
try {
|
137
|
-
const {
|
138
|
-
|
227
|
+
const { deployPreview, deployPreviewBranch, vercelGitCommitRef, vercelGitRepoOwner } = getEnvironment();
|
228
|
+
if (deployPreviewBranch)
|
229
|
+
return deployPreviewBranch;
|
230
|
+
switch (deployPreview) {
|
231
|
+
case "vercel": {
|
232
|
+
if (!vercelGitCommitRef || !vercelGitRepoOwner) {
|
233
|
+
console.warn("XATA_PREVIEW=vercel but VERCEL_GIT_COMMIT_REF or VERCEL_GIT_REPO_OWNER is not valid");
|
234
|
+
return void 0;
|
235
|
+
}
|
236
|
+
return buildPreviewBranchName({ org: vercelGitRepoOwner, branch: vercelGitCommitRef });
|
237
|
+
}
|
238
|
+
}
|
239
|
+
return void 0;
|
139
240
|
} catch (err) {
|
140
241
|
return void 0;
|
141
242
|
}
|
142
243
|
}
|
143
244
|
|
245
|
+
var __accessCheck$7 = (obj, member, msg) => {
|
246
|
+
if (!member.has(obj))
|
247
|
+
throw TypeError("Cannot " + msg);
|
248
|
+
};
|
249
|
+
var __privateGet$7 = (obj, member, getter) => {
|
250
|
+
__accessCheck$7(obj, member, "read from private field");
|
251
|
+
return getter ? getter.call(obj) : member.get(obj);
|
252
|
+
};
|
253
|
+
var __privateAdd$7 = (obj, member, value) => {
|
254
|
+
if (member.has(obj))
|
255
|
+
throw TypeError("Cannot add the same private member more than once");
|
256
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
257
|
+
};
|
258
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
259
|
+
__accessCheck$7(obj, member, "write to private field");
|
260
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
261
|
+
return value;
|
262
|
+
};
|
263
|
+
var __privateMethod$4 = (obj, member, method) => {
|
264
|
+
__accessCheck$7(obj, member, "access private method");
|
265
|
+
return method;
|
266
|
+
};
|
267
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
144
269
|
function getFetchImplementation(userFetch) {
|
145
270
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
146
|
-
const
|
271
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
272
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
147
273
|
if (!fetchImpl) {
|
148
|
-
throw new Error(
|
149
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
150
|
-
);
|
274
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
151
275
|
}
|
152
276
|
return fetchImpl;
|
153
277
|
}
|
278
|
+
class ApiRequestPool {
|
279
|
+
constructor(concurrency = 10) {
|
280
|
+
__privateAdd$7(this, _enqueue);
|
281
|
+
__privateAdd$7(this, _fetch, void 0);
|
282
|
+
__privateAdd$7(this, _queue, void 0);
|
283
|
+
__privateAdd$7(this, _concurrency, void 0);
|
284
|
+
__privateSet$7(this, _queue, []);
|
285
|
+
__privateSet$7(this, _concurrency, concurrency);
|
286
|
+
this.running = 0;
|
287
|
+
this.started = 0;
|
288
|
+
}
|
289
|
+
setFetch(fetch2) {
|
290
|
+
__privateSet$7(this, _fetch, fetch2);
|
291
|
+
}
|
292
|
+
getFetch() {
|
293
|
+
if (!__privateGet$7(this, _fetch)) {
|
294
|
+
throw new Error("Fetch not set");
|
295
|
+
}
|
296
|
+
return __privateGet$7(this, _fetch);
|
297
|
+
}
|
298
|
+
request(url, options) {
|
299
|
+
const start = /* @__PURE__ */ new Date();
|
300
|
+
const fetchImpl = this.getFetch();
|
301
|
+
const runRequest = async (stalled = false) => {
|
302
|
+
const { promise, cancel } = timeoutWithCancel(REQUEST_TIMEOUT);
|
303
|
+
const response = await Promise.race([fetchImpl(url, options), promise.then(() => null)]).finally(cancel);
|
304
|
+
if (!response) {
|
305
|
+
throw new Error("Request timed out");
|
306
|
+
}
|
307
|
+
if (response.status === 429) {
|
308
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
309
|
+
await timeout(rateLimitReset * 1e3);
|
310
|
+
return await runRequest(true);
|
311
|
+
}
|
312
|
+
if (stalled) {
|
313
|
+
const stalledTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
314
|
+
console.warn(`A request to Xata hit branch rate limits, was retried and stalled for ${stalledTime}ms`);
|
315
|
+
}
|
316
|
+
return response;
|
317
|
+
};
|
318
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
319
|
+
return await runRequest();
|
320
|
+
});
|
321
|
+
}
|
322
|
+
}
|
323
|
+
_fetch = new WeakMap();
|
324
|
+
_queue = new WeakMap();
|
325
|
+
_concurrency = new WeakMap();
|
326
|
+
_enqueue = new WeakSet();
|
327
|
+
enqueue_fn = function(task) {
|
328
|
+
const promise = new Promise((resolve) => __privateGet$7(this, _queue).push(resolve)).finally(() => {
|
329
|
+
this.started--;
|
330
|
+
this.running++;
|
331
|
+
}).then(() => task()).finally(() => {
|
332
|
+
this.running--;
|
333
|
+
const next = __privateGet$7(this, _queue).shift();
|
334
|
+
if (next !== void 0) {
|
335
|
+
this.started++;
|
336
|
+
next();
|
337
|
+
}
|
338
|
+
});
|
339
|
+
if (this.running + this.started < __privateGet$7(this, _concurrency)) {
|
340
|
+
const next = __privateGet$7(this, _queue).shift();
|
341
|
+
if (next !== void 0) {
|
342
|
+
this.started++;
|
343
|
+
next();
|
344
|
+
}
|
345
|
+
}
|
346
|
+
return promise;
|
347
|
+
};
|
348
|
+
|
349
|
+
function generateUUID() {
|
350
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
351
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
352
|
+
return v.toString(16);
|
353
|
+
});
|
354
|
+
}
|
355
|
+
|
356
|
+
async function getBytes(stream, onChunk) {
|
357
|
+
const reader = stream.getReader();
|
358
|
+
let result;
|
359
|
+
while (!(result = await reader.read()).done) {
|
360
|
+
onChunk(result.value);
|
361
|
+
}
|
362
|
+
}
|
363
|
+
function getLines(onLine) {
|
364
|
+
let buffer;
|
365
|
+
let position;
|
366
|
+
let fieldLength;
|
367
|
+
let discardTrailingNewline = false;
|
368
|
+
return function onChunk(arr) {
|
369
|
+
if (buffer === void 0) {
|
370
|
+
buffer = arr;
|
371
|
+
position = 0;
|
372
|
+
fieldLength = -1;
|
373
|
+
} else {
|
374
|
+
buffer = concat(buffer, arr);
|
375
|
+
}
|
376
|
+
const bufLength = buffer.length;
|
377
|
+
let lineStart = 0;
|
378
|
+
while (position < bufLength) {
|
379
|
+
if (discardTrailingNewline) {
|
380
|
+
if (buffer[position] === 10 /* NewLine */) {
|
381
|
+
lineStart = ++position;
|
382
|
+
}
|
383
|
+
discardTrailingNewline = false;
|
384
|
+
}
|
385
|
+
let lineEnd = -1;
|
386
|
+
for (; position < bufLength && lineEnd === -1; ++position) {
|
387
|
+
switch (buffer[position]) {
|
388
|
+
case 58 /* Colon */:
|
389
|
+
if (fieldLength === -1) {
|
390
|
+
fieldLength = position - lineStart;
|
391
|
+
}
|
392
|
+
break;
|
393
|
+
case 13 /* CarriageReturn */:
|
394
|
+
discardTrailingNewline = true;
|
395
|
+
case 10 /* NewLine */:
|
396
|
+
lineEnd = position;
|
397
|
+
break;
|
398
|
+
}
|
399
|
+
}
|
400
|
+
if (lineEnd === -1) {
|
401
|
+
break;
|
402
|
+
}
|
403
|
+
onLine(buffer.subarray(lineStart, lineEnd), fieldLength);
|
404
|
+
lineStart = position;
|
405
|
+
fieldLength = -1;
|
406
|
+
}
|
407
|
+
if (lineStart === bufLength) {
|
408
|
+
buffer = void 0;
|
409
|
+
} else if (lineStart !== 0) {
|
410
|
+
buffer = buffer.subarray(lineStart);
|
411
|
+
position -= lineStart;
|
412
|
+
}
|
413
|
+
};
|
414
|
+
}
|
415
|
+
function getMessages(onId, onRetry, onMessage) {
|
416
|
+
let message = newMessage();
|
417
|
+
const decoder = new TextDecoder();
|
418
|
+
return function onLine(line, fieldLength) {
|
419
|
+
if (line.length === 0) {
|
420
|
+
onMessage?.(message);
|
421
|
+
message = newMessage();
|
422
|
+
} else if (fieldLength > 0) {
|
423
|
+
const field = decoder.decode(line.subarray(0, fieldLength));
|
424
|
+
const valueOffset = fieldLength + (line[fieldLength + 1] === 32 /* Space */ ? 2 : 1);
|
425
|
+
const value = decoder.decode(line.subarray(valueOffset));
|
426
|
+
switch (field) {
|
427
|
+
case "data":
|
428
|
+
message.data = message.data ? message.data + "\n" + value : value;
|
429
|
+
break;
|
430
|
+
case "event":
|
431
|
+
message.event = value;
|
432
|
+
break;
|
433
|
+
case "id":
|
434
|
+
onId(message.id = value);
|
435
|
+
break;
|
436
|
+
case "retry":
|
437
|
+
const retry = parseInt(value, 10);
|
438
|
+
if (!isNaN(retry)) {
|
439
|
+
onRetry(message.retry = retry);
|
440
|
+
}
|
441
|
+
break;
|
442
|
+
}
|
443
|
+
}
|
444
|
+
};
|
445
|
+
}
|
446
|
+
function concat(a, b) {
|
447
|
+
const res = new Uint8Array(a.length + b.length);
|
448
|
+
res.set(a);
|
449
|
+
res.set(b, a.length);
|
450
|
+
return res;
|
451
|
+
}
|
452
|
+
function newMessage() {
|
453
|
+
return {
|
454
|
+
data: "",
|
455
|
+
event: "",
|
456
|
+
id: "",
|
457
|
+
retry: void 0
|
458
|
+
};
|
459
|
+
}
|
460
|
+
const EventStreamContentType = "text/event-stream";
|
461
|
+
const LastEventId = "last-event-id";
|
462
|
+
function fetchEventSource(input, {
|
463
|
+
signal: inputSignal,
|
464
|
+
headers: inputHeaders,
|
465
|
+
onopen: inputOnOpen,
|
466
|
+
onmessage,
|
467
|
+
onclose,
|
468
|
+
onerror,
|
469
|
+
fetch: inputFetch,
|
470
|
+
...rest
|
471
|
+
}) {
|
472
|
+
return new Promise((resolve, reject) => {
|
473
|
+
const headers = { ...inputHeaders };
|
474
|
+
if (!headers.accept) {
|
475
|
+
headers.accept = EventStreamContentType;
|
476
|
+
}
|
477
|
+
let curRequestController;
|
478
|
+
function dispose() {
|
479
|
+
curRequestController.abort();
|
480
|
+
}
|
481
|
+
inputSignal?.addEventListener("abort", () => {
|
482
|
+
dispose();
|
483
|
+
resolve();
|
484
|
+
});
|
485
|
+
const fetchImpl = inputFetch ?? fetch;
|
486
|
+
const onopen = inputOnOpen ?? defaultOnOpen;
|
487
|
+
async function create() {
|
488
|
+
curRequestController = new AbortController();
|
489
|
+
try {
|
490
|
+
const response = await fetchImpl(input, {
|
491
|
+
...rest,
|
492
|
+
headers,
|
493
|
+
signal: curRequestController.signal
|
494
|
+
});
|
495
|
+
await onopen(response);
|
496
|
+
await getBytes(
|
497
|
+
response.body,
|
498
|
+
getLines(
|
499
|
+
getMessages(
|
500
|
+
(id) => {
|
501
|
+
if (id) {
|
502
|
+
headers[LastEventId] = id;
|
503
|
+
} else {
|
504
|
+
delete headers[LastEventId];
|
505
|
+
}
|
506
|
+
},
|
507
|
+
(_retry) => {
|
508
|
+
},
|
509
|
+
onmessage
|
510
|
+
)
|
511
|
+
)
|
512
|
+
);
|
513
|
+
onclose?.();
|
514
|
+
dispose();
|
515
|
+
resolve();
|
516
|
+
} catch (err) {
|
517
|
+
}
|
518
|
+
}
|
519
|
+
create();
|
520
|
+
});
|
521
|
+
}
|
522
|
+
function defaultOnOpen(response) {
|
523
|
+
const contentType = response.headers?.get("content-type");
|
524
|
+
if (!contentType?.startsWith(EventStreamContentType)) {
|
525
|
+
throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${contentType}`);
|
526
|
+
}
|
527
|
+
}
|
154
528
|
|
155
|
-
const VERSION = "0.
|
529
|
+
const VERSION = "0.28.3";
|
156
530
|
|
157
531
|
class ErrorWithCause extends Error {
|
158
532
|
constructor(message, options) {
|
@@ -163,7 +537,7 @@ class FetcherError extends ErrorWithCause {
|
|
163
537
|
constructor(status, data, requestId) {
|
164
538
|
super(getMessage(data));
|
165
539
|
this.status = status;
|
166
|
-
this.errors = isBulkError(data) ? data.errors :
|
540
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
167
541
|
this.requestId = requestId;
|
168
542
|
if (data instanceof Error) {
|
169
543
|
this.stack = data.stack;
|
@@ -195,6 +569,68 @@ function getMessage(data) {
|
|
195
569
|
}
|
196
570
|
}
|
197
571
|
|
572
|
+
function getHostUrl(provider, type) {
|
573
|
+
if (isHostProviderAlias(provider)) {
|
574
|
+
return providers[provider][type];
|
575
|
+
} else if (isHostProviderBuilder(provider)) {
|
576
|
+
return provider[type];
|
577
|
+
}
|
578
|
+
throw new Error("Invalid API provider");
|
579
|
+
}
|
580
|
+
const providers = {
|
581
|
+
production: {
|
582
|
+
main: "https://api.xata.io",
|
583
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
584
|
+
},
|
585
|
+
staging: {
|
586
|
+
main: "https://api.staging-xata.dev",
|
587
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
588
|
+
},
|
589
|
+
dev: {
|
590
|
+
main: "https://api.dev-xata.dev",
|
591
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
592
|
+
},
|
593
|
+
local: {
|
594
|
+
main: "http://localhost:6001",
|
595
|
+
workspaces: "http://{workspaceId}.{region}.localhost:6001"
|
596
|
+
}
|
597
|
+
};
|
598
|
+
function isHostProviderAlias(alias) {
|
599
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
600
|
+
}
|
601
|
+
function isHostProviderBuilder(builder) {
|
602
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
603
|
+
}
|
604
|
+
function parseProviderString(provider = "production") {
|
605
|
+
if (isHostProviderAlias(provider)) {
|
606
|
+
return provider;
|
607
|
+
}
|
608
|
+
const [main, workspaces] = provider.split(",");
|
609
|
+
if (!main || !workspaces)
|
610
|
+
return null;
|
611
|
+
return { main, workspaces };
|
612
|
+
}
|
613
|
+
function buildProviderString(provider) {
|
614
|
+
if (isHostProviderAlias(provider))
|
615
|
+
return provider;
|
616
|
+
return `${provider.main},${provider.workspaces}`;
|
617
|
+
}
|
618
|
+
function parseWorkspacesUrlParts(url) {
|
619
|
+
if (!isString(url))
|
620
|
+
return null;
|
621
|
+
const matches = {
|
622
|
+
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
|
623
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
624
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
625
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
626
|
+
};
|
627
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
628
|
+
if (!isHostProviderAlias(host) || !match)
|
629
|
+
return null;
|
630
|
+
return { workspace: match[1], region: match[2], host };
|
631
|
+
}
|
632
|
+
|
633
|
+
const pool = new ApiRequestPool();
|
198
634
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
199
635
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
200
636
|
if (value === void 0 || value === null)
|
@@ -203,84 +639,201 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
203
639
|
}, {});
|
204
640
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
205
641
|
const queryString = query.length > 0 ? `?${query}` : "";
|
206
|
-
|
642
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
643
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
644
|
+
}, {});
|
645
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
207
646
|
};
|
208
647
|
function buildBaseUrl({
|
648
|
+
method,
|
649
|
+
endpoint,
|
209
650
|
path,
|
210
651
|
workspacesApiUrl,
|
211
652
|
apiUrl,
|
212
|
-
pathParams
|
653
|
+
pathParams = {}
|
213
654
|
}) {
|
214
|
-
if (
|
215
|
-
|
216
|
-
|
217
|
-
|
655
|
+
if (endpoint === "dataPlane") {
|
656
|
+
let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
657
|
+
if (method.toUpperCase() === "PUT" && [
|
658
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
659
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
|
660
|
+
].includes(path)) {
|
661
|
+
const { host } = parseWorkspacesUrlParts(url) ?? {};
|
662
|
+
switch (host) {
|
663
|
+
case "production":
|
664
|
+
url = url.replace("xata.sh", "upload.xata.sh");
|
665
|
+
break;
|
666
|
+
case "staging":
|
667
|
+
url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
|
668
|
+
break;
|
669
|
+
case "dev":
|
670
|
+
url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
|
671
|
+
break;
|
672
|
+
}
|
673
|
+
}
|
674
|
+
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
675
|
+
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
676
|
+
}
|
677
|
+
return `${apiUrl}${path}`;
|
218
678
|
}
|
219
679
|
function hostHeader(url) {
|
220
680
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
221
681
|
const { groups } = pattern.exec(url) ?? {};
|
222
682
|
return groups?.host ? { Host: groups.host } : {};
|
223
683
|
}
|
684
|
+
async function parseBody(body, headers) {
|
685
|
+
if (!isDefined(body))
|
686
|
+
return void 0;
|
687
|
+
if (isBlob(body) || typeof body.text === "function") {
|
688
|
+
return body;
|
689
|
+
}
|
690
|
+
const { "Content-Type": contentType } = headers ?? {};
|
691
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
692
|
+
return JSON.stringify(body);
|
693
|
+
}
|
694
|
+
return body;
|
695
|
+
}
|
696
|
+
const defaultClientID = generateUUID();
|
224
697
|
async function fetch$1({
|
225
698
|
url: path,
|
226
699
|
method,
|
227
700
|
body,
|
228
|
-
headers,
|
701
|
+
headers: customHeaders,
|
229
702
|
pathParams,
|
230
703
|
queryParams,
|
231
|
-
|
704
|
+
fetch: fetch2,
|
232
705
|
apiKey,
|
706
|
+
endpoint,
|
233
707
|
apiUrl,
|
234
708
|
workspacesApiUrl,
|
235
|
-
trace
|
709
|
+
trace,
|
710
|
+
signal,
|
711
|
+
clientID,
|
712
|
+
sessionID,
|
713
|
+
clientName,
|
714
|
+
xataAgentExtra,
|
715
|
+
fetchOptions = {},
|
716
|
+
rawResponse = false
|
236
717
|
}) {
|
237
|
-
|
718
|
+
pool.setFetch(fetch2);
|
719
|
+
return await trace(
|
238
720
|
`${method.toUpperCase()} ${path}`,
|
239
|
-
async ({ setAttributes
|
240
|
-
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
721
|
+
async ({ setAttributes }) => {
|
722
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
241
723
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
242
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
724
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
243
725
|
setAttributes({
|
244
726
|
[TraceAttributes.HTTP_URL]: url,
|
245
727
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
246
728
|
});
|
247
|
-
const
|
729
|
+
const xataAgent = compact([
|
730
|
+
["client", "TS_SDK"],
|
731
|
+
["version", VERSION],
|
732
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
733
|
+
...Object.entries(xataAgentExtra ?? {})
|
734
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
735
|
+
const headers = compactObject({
|
736
|
+
"Accept-Encoding": "identity",
|
737
|
+
"Content-Type": "application/json",
|
738
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
739
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
740
|
+
"X-Xata-Agent": xataAgent,
|
741
|
+
...customHeaders,
|
742
|
+
...hostHeader(fullUrl),
|
743
|
+
Authorization: `Bearer ${apiKey}`
|
744
|
+
});
|
745
|
+
const response = await pool.request(url, {
|
746
|
+
...fetchOptions,
|
248
747
|
method: method.toUpperCase(),
|
249
|
-
body:
|
250
|
-
headers
|
251
|
-
|
252
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
253
|
-
...headers,
|
254
|
-
...hostHeader(fullUrl),
|
255
|
-
Authorization: `Bearer ${apiKey}`
|
256
|
-
}
|
748
|
+
body: await parseBody(body, headers),
|
749
|
+
headers,
|
750
|
+
signal
|
257
751
|
});
|
258
|
-
if (response.status === 204) {
|
259
|
-
return {};
|
260
|
-
}
|
261
752
|
const { host, protocol } = parseUrl(response.url);
|
262
753
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
263
754
|
setAttributes({
|
755
|
+
[TraceAttributes.KIND]: "http",
|
264
756
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
265
757
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
266
758
|
[TraceAttributes.HTTP_HOST]: host,
|
267
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
759
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
760
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
268
761
|
});
|
762
|
+
const message = response.headers?.get("x-xata-message");
|
763
|
+
if (message)
|
764
|
+
console.warn(message);
|
765
|
+
if (response.status === 204) {
|
766
|
+
return {};
|
767
|
+
}
|
768
|
+
if (response.status === 429) {
|
769
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
770
|
+
}
|
269
771
|
try {
|
270
|
-
const jsonResponse = await response.json();
|
772
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
271
773
|
if (response.ok) {
|
272
774
|
return jsonResponse;
|
273
775
|
}
|
274
776
|
throw new FetcherError(response.status, jsonResponse, requestId);
|
275
777
|
} catch (error) {
|
276
|
-
|
277
|
-
onError(fetcherError.message);
|
278
|
-
throw fetcherError;
|
778
|
+
throw new FetcherError(response.status, error, requestId);
|
279
779
|
}
|
280
780
|
},
|
281
781
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
282
782
|
);
|
283
783
|
}
|
784
|
+
function fetchSSERequest({
|
785
|
+
url: path,
|
786
|
+
method,
|
787
|
+
body,
|
788
|
+
headers: customHeaders,
|
789
|
+
pathParams,
|
790
|
+
queryParams,
|
791
|
+
fetch: fetch2,
|
792
|
+
apiKey,
|
793
|
+
endpoint,
|
794
|
+
apiUrl,
|
795
|
+
workspacesApiUrl,
|
796
|
+
onMessage,
|
797
|
+
onError,
|
798
|
+
onClose,
|
799
|
+
signal,
|
800
|
+
clientID,
|
801
|
+
sessionID,
|
802
|
+
clientName,
|
803
|
+
xataAgentExtra
|
804
|
+
}) {
|
805
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
806
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
807
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
808
|
+
void fetchEventSource(url, {
|
809
|
+
method,
|
810
|
+
body: JSON.stringify(body),
|
811
|
+
fetch: fetch2,
|
812
|
+
signal,
|
813
|
+
headers: {
|
814
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
815
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
816
|
+
"X-Xata-Agent": compact([
|
817
|
+
["client", "TS_SDK"],
|
818
|
+
["version", VERSION],
|
819
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
820
|
+
...Object.entries(xataAgentExtra ?? {})
|
821
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
822
|
+
...customHeaders,
|
823
|
+
Authorization: `Bearer ${apiKey}`,
|
824
|
+
"Content-Type": "application/json"
|
825
|
+
},
|
826
|
+
onmessage(ev) {
|
827
|
+
onMessage?.(JSON.parse(ev.data));
|
828
|
+
},
|
829
|
+
onerror(ev) {
|
830
|
+
onError?.(JSON.parse(ev.data));
|
831
|
+
},
|
832
|
+
onclose() {
|
833
|
+
onClose?.();
|
834
|
+
}
|
835
|
+
});
|
836
|
+
}
|
284
837
|
function parseUrl(url) {
|
285
838
|
try {
|
286
839
|
const { host, protocol } = new URL(url);
|
@@ -290,778 +843,749 @@ function parseUrl(url) {
|
|
290
843
|
}
|
291
844
|
}
|
292
845
|
|
293
|
-
const
|
294
|
-
|
295
|
-
const
|
296
|
-
const
|
297
|
-
url: "/
|
846
|
+
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
847
|
+
|
848
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
849
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
850
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
298
851
|
method: "get",
|
299
|
-
...variables
|
852
|
+
...variables,
|
853
|
+
signal
|
300
854
|
});
|
301
|
-
const
|
302
|
-
url: "/
|
303
|
-
method: "
|
304
|
-
...variables
|
855
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
856
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
857
|
+
method: "get",
|
858
|
+
...variables,
|
859
|
+
signal
|
305
860
|
});
|
306
|
-
const
|
307
|
-
|
861
|
+
const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
|
862
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
863
|
+
url: "/dbs/{dbName}",
|
864
|
+
method: "get",
|
865
|
+
...variables,
|
866
|
+
signal
|
867
|
+
});
|
868
|
+
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
869
|
+
url: "/db/{dbBranchName}",
|
870
|
+
method: "get",
|
871
|
+
...variables,
|
872
|
+
signal
|
873
|
+
});
|
874
|
+
const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
875
|
+
const deleteBranch = (variables, signal) => dataPlaneFetch({
|
876
|
+
url: "/db/{dbBranchName}",
|
308
877
|
method: "delete",
|
309
|
-
...variables
|
878
|
+
...variables,
|
879
|
+
signal
|
310
880
|
});
|
311
|
-
const
|
312
|
-
url: "/
|
881
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
882
|
+
url: "/db/{dbBranchName}/schema",
|
883
|
+
method: "get",
|
884
|
+
...variables,
|
885
|
+
signal
|
886
|
+
});
|
887
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
888
|
+
url: "/db/{dbBranchName}/copy",
|
313
889
|
method: "post",
|
314
|
-
...variables
|
890
|
+
...variables,
|
891
|
+
signal
|
315
892
|
});
|
316
|
-
const
|
317
|
-
url: "/
|
893
|
+
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
894
|
+
url: "/db/{dbBranchName}/metadata",
|
895
|
+
method: "put",
|
896
|
+
...variables,
|
897
|
+
signal
|
898
|
+
});
|
899
|
+
const getBranchMetadata = (variables, signal) => dataPlaneFetch({
|
900
|
+
url: "/db/{dbBranchName}/metadata",
|
318
901
|
method: "get",
|
319
|
-
...variables
|
902
|
+
...variables,
|
903
|
+
signal
|
320
904
|
});
|
321
|
-
const
|
322
|
-
url: "/
|
905
|
+
const getBranchStats = (variables, signal) => dataPlaneFetch({
|
906
|
+
url: "/db/{dbBranchName}/stats",
|
323
907
|
method: "get",
|
324
|
-
...variables
|
908
|
+
...variables,
|
909
|
+
signal
|
325
910
|
});
|
326
|
-
const
|
327
|
-
|
911
|
+
const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
912
|
+
const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
913
|
+
const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
914
|
+
const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
|
915
|
+
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
916
|
+
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
917
|
+
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
918
|
+
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
919
|
+
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
920
|
+
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
921
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
922
|
+
method: "get",
|
923
|
+
...variables,
|
924
|
+
signal
|
925
|
+
});
|
926
|
+
const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
927
|
+
const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
928
|
+
const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
929
|
+
const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
930
|
+
const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
|
931
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
932
|
+
method: "post",
|
933
|
+
...variables,
|
934
|
+
signal
|
935
|
+
});
|
936
|
+
const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
937
|
+
const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
938
|
+
const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
939
|
+
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
940
|
+
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
941
|
+
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
942
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
943
|
+
const createTable = (variables, signal) => dataPlaneFetch({
|
944
|
+
url: "/db/{dbBranchName}/tables/{tableName}",
|
328
945
|
method: "put",
|
329
|
-
...variables
|
946
|
+
...variables,
|
947
|
+
signal
|
330
948
|
});
|
331
|
-
const
|
332
|
-
url: "/
|
949
|
+
const deleteTable = (variables, signal) => dataPlaneFetch({
|
950
|
+
url: "/db/{dbBranchName}/tables/{tableName}",
|
333
951
|
method: "delete",
|
334
|
-
...variables
|
952
|
+
...variables,
|
953
|
+
signal
|
335
954
|
});
|
336
|
-
const
|
337
|
-
|
955
|
+
const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
|
956
|
+
const getTableSchema = (variables, signal) => dataPlaneFetch({
|
957
|
+
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
338
958
|
method: "get",
|
339
|
-
...variables
|
959
|
+
...variables,
|
960
|
+
signal
|
340
961
|
});
|
341
|
-
const
|
342
|
-
const
|
343
|
-
url: "/
|
344
|
-
method: "
|
345
|
-
...variables
|
962
|
+
const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
|
963
|
+
const getTableColumns = (variables, signal) => dataPlaneFetch({
|
964
|
+
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
965
|
+
method: "get",
|
966
|
+
...variables,
|
967
|
+
signal
|
346
968
|
});
|
347
|
-
const
|
348
|
-
|
349
|
-
|
350
|
-
|
969
|
+
const addTableColumn = (variables, signal) => dataPlaneFetch(
|
970
|
+
{ url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
|
971
|
+
);
|
972
|
+
const getColumn = (variables, signal) => dataPlaneFetch({
|
973
|
+
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
974
|
+
method: "get",
|
975
|
+
...variables,
|
976
|
+
signal
|
977
|
+
});
|
978
|
+
const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
|
979
|
+
const deleteColumn = (variables, signal) => dataPlaneFetch({
|
980
|
+
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
351
981
|
method: "delete",
|
352
|
-
...variables
|
982
|
+
...variables,
|
983
|
+
signal
|
353
984
|
});
|
354
|
-
const
|
355
|
-
|
356
|
-
|
357
|
-
|
985
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
986
|
+
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
987
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
988
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
989
|
+
method: "get",
|
990
|
+
...variables,
|
991
|
+
signal
|
358
992
|
});
|
359
|
-
const
|
360
|
-
url: "/
|
361
|
-
method: "
|
362
|
-
...variables
|
993
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
994
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
995
|
+
method: "put",
|
996
|
+
...variables,
|
997
|
+
signal
|
363
998
|
});
|
364
|
-
const
|
365
|
-
url: "/
|
366
|
-
method: "
|
367
|
-
...variables
|
999
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
1000
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
1001
|
+
method: "delete",
|
1002
|
+
...variables,
|
1003
|
+
signal
|
368
1004
|
});
|
369
|
-
const
|
370
|
-
url: "/
|
1005
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
1006
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
371
1007
|
method: "get",
|
372
|
-
...variables
|
1008
|
+
...variables,
|
1009
|
+
signal
|
373
1010
|
});
|
374
|
-
const
|
375
|
-
url: "/
|
1011
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
1012
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
376
1013
|
method: "put",
|
377
|
-
...variables
|
1014
|
+
...variables,
|
1015
|
+
signal
|
378
1016
|
});
|
379
|
-
const
|
380
|
-
url: "/
|
1017
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
1018
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
381
1019
|
method: "delete",
|
382
|
-
...variables
|
1020
|
+
...variables,
|
1021
|
+
signal
|
383
1022
|
});
|
384
|
-
const
|
385
|
-
url: "/
|
1023
|
+
const getRecord = (variables, signal) => dataPlaneFetch({
|
1024
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
386
1025
|
method: "get",
|
387
|
-
...variables
|
1026
|
+
...variables,
|
1027
|
+
signal
|
388
1028
|
});
|
389
|
-
const
|
390
|
-
const
|
391
|
-
const
|
392
|
-
const
|
393
|
-
|
394
|
-
|
395
|
-
|
1029
|
+
const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
1030
|
+
const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
1031
|
+
const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
1032
|
+
const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
|
1033
|
+
const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
1034
|
+
const queryTable = (variables, signal) => dataPlaneFetch({
|
1035
|
+
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
1036
|
+
method: "post",
|
1037
|
+
...variables,
|
1038
|
+
signal
|
396
1039
|
});
|
397
|
-
const
|
398
|
-
url: "/db/{dbBranchName}",
|
399
|
-
method: "
|
400
|
-
...variables
|
1040
|
+
const searchBranch = (variables, signal) => dataPlaneFetch({
|
1041
|
+
url: "/db/{dbBranchName}/search",
|
1042
|
+
method: "post",
|
1043
|
+
...variables,
|
1044
|
+
signal
|
401
1045
|
});
|
402
|
-
const
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
1046
|
+
const searchTable = (variables, signal) => dataPlaneFetch({
|
1047
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
1048
|
+
method: "post",
|
1049
|
+
...variables,
|
1050
|
+
signal
|
407
1051
|
});
|
408
|
-
const
|
409
|
-
|
410
|
-
|
411
|
-
|
1052
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
1053
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
1054
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
1055
|
+
method: "post",
|
1056
|
+
...variables,
|
1057
|
+
signal
|
412
1058
|
});
|
413
|
-
const
|
414
|
-
|
1059
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
1060
|
+
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
1061
|
+
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
1062
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
1063
|
+
url: "/file/{fileId}",
|
415
1064
|
method: "get",
|
416
|
-
...variables
|
1065
|
+
...variables,
|
1066
|
+
signal
|
417
1067
|
});
|
418
|
-
const
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
1068
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1069
|
+
url: "/file/{fileId}",
|
1070
|
+
method: "put",
|
1071
|
+
...variables,
|
1072
|
+
signal
|
1073
|
+
});
|
1074
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
1075
|
+
url: "/db/{dbBranchName}/sql",
|
1076
|
+
method: "post",
|
1077
|
+
...variables,
|
1078
|
+
signal
|
1079
|
+
});
|
1080
|
+
const operationsByTag$2 = {
|
1081
|
+
branch: {
|
1082
|
+
applyMigration,
|
1083
|
+
pgRollStatus,
|
1084
|
+
pgRollJobStatus,
|
1085
|
+
pgRollMigrationHistory,
|
1086
|
+
getBranchList,
|
1087
|
+
getBranchDetails,
|
1088
|
+
createBranch,
|
1089
|
+
deleteBranch,
|
1090
|
+
copyBranch,
|
1091
|
+
updateBranchMetadata,
|
1092
|
+
getBranchMetadata,
|
1093
|
+
getBranchStats,
|
1094
|
+
getGitBranchesMapping,
|
1095
|
+
addGitBranchesEntry,
|
1096
|
+
removeGitBranchesEntry,
|
1097
|
+
resolveBranch
|
1098
|
+
},
|
1099
|
+
migrations: {
|
1100
|
+
getSchema,
|
1101
|
+
getBranchMigrationHistory,
|
1102
|
+
getBranchMigrationPlan,
|
1103
|
+
executeBranchMigrationPlan,
|
1104
|
+
getBranchSchemaHistory,
|
1105
|
+
compareBranchWithUserSchema,
|
1106
|
+
compareBranchSchemas,
|
1107
|
+
updateBranchSchema,
|
1108
|
+
previewBranchSchemaEdit,
|
1109
|
+
applyBranchSchemaEdit,
|
1110
|
+
pushBranchMigrations
|
1111
|
+
},
|
1112
|
+
migrationRequests: {
|
1113
|
+
queryMigrationRequests,
|
1114
|
+
createMigrationRequest,
|
1115
|
+
getMigrationRequest,
|
1116
|
+
updateMigrationRequest,
|
1117
|
+
listMigrationRequestsCommits,
|
1118
|
+
compareMigrationRequest,
|
1119
|
+
getMigrationRequestIsMerged,
|
1120
|
+
mergeMigrationRequest
|
1121
|
+
},
|
1122
|
+
table: {
|
1123
|
+
createTable,
|
1124
|
+
deleteTable,
|
1125
|
+
updateTable,
|
1126
|
+
getTableSchema,
|
1127
|
+
setTableSchema,
|
1128
|
+
getTableColumns,
|
1129
|
+
addTableColumn,
|
1130
|
+
getColumn,
|
1131
|
+
updateColumn,
|
1132
|
+
deleteColumn
|
1133
|
+
},
|
1134
|
+
records: {
|
1135
|
+
branchTransaction,
|
1136
|
+
insertRecord,
|
1137
|
+
getRecord,
|
1138
|
+
insertRecordWithID,
|
1139
|
+
updateRecordWithID,
|
1140
|
+
upsertRecordWithID,
|
1141
|
+
deleteRecord,
|
1142
|
+
bulkInsertTableRecords
|
1143
|
+
},
|
1144
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1145
|
+
searchAndFilter: {
|
1146
|
+
queryTable,
|
1147
|
+
searchBranch,
|
1148
|
+
searchTable,
|
1149
|
+
vectorSearchTable,
|
1150
|
+
askTable,
|
1151
|
+
askTableSession,
|
1152
|
+
summarizeTable,
|
1153
|
+
aggregateTable
|
1154
|
+
},
|
1155
|
+
sql: { sqlQuery }
|
1156
|
+
};
|
1157
|
+
|
1158
|
+
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
1159
|
+
|
1160
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1161
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
1162
|
+
const getUser = (variables, signal) => controlPlaneFetch({
|
1163
|
+
url: "/user",
|
423
1164
|
method: "get",
|
424
|
-
...variables
|
1165
|
+
...variables,
|
1166
|
+
signal
|
425
1167
|
});
|
426
|
-
const
|
427
|
-
url: "/
|
1168
|
+
const updateUser = (variables, signal) => controlPlaneFetch({
|
1169
|
+
url: "/user",
|
428
1170
|
method: "put",
|
429
|
-
...variables
|
1171
|
+
...variables,
|
1172
|
+
signal
|
430
1173
|
});
|
431
|
-
const
|
432
|
-
url: "/
|
1174
|
+
const deleteUser = (variables, signal) => controlPlaneFetch({
|
1175
|
+
url: "/user",
|
433
1176
|
method: "delete",
|
434
|
-
...variables
|
1177
|
+
...variables,
|
1178
|
+
signal
|
435
1179
|
});
|
436
|
-
const
|
437
|
-
url: "/
|
438
|
-
method: "
|
439
|
-
...variables
|
1180
|
+
const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
1181
|
+
url: "/user/keys",
|
1182
|
+
method: "get",
|
1183
|
+
...variables,
|
1184
|
+
signal
|
440
1185
|
});
|
441
|
-
const
|
442
|
-
url: "/
|
1186
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
1187
|
+
url: "/user/keys/{keyName}",
|
1188
|
+
method: "post",
|
1189
|
+
...variables,
|
1190
|
+
signal
|
1191
|
+
});
|
1192
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
1193
|
+
url: "/user/keys/{keyName}",
|
1194
|
+
method: "delete",
|
1195
|
+
...variables,
|
1196
|
+
signal
|
1197
|
+
});
|
1198
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1199
|
+
url: "/user/oauth/clients",
|
443
1200
|
method: "get",
|
444
|
-
...variables
|
1201
|
+
...variables,
|
1202
|
+
signal
|
445
1203
|
});
|
446
|
-
const
|
447
|
-
url: "/
|
448
|
-
method: "
|
449
|
-
...variables
|
1204
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1205
|
+
url: "/user/oauth/clients/{clientId}",
|
1206
|
+
method: "delete",
|
1207
|
+
...variables,
|
1208
|
+
signal
|
450
1209
|
});
|
451
|
-
const
|
452
|
-
url: "/
|
1210
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1211
|
+
url: "/user/oauth/tokens",
|
453
1212
|
method: "get",
|
454
|
-
...variables
|
1213
|
+
...variables,
|
1214
|
+
signal
|
455
1215
|
});
|
456
|
-
const
|
457
|
-
url: "/
|
1216
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1217
|
+
url: "/user/oauth/tokens/{token}",
|
1218
|
+
method: "delete",
|
1219
|
+
...variables,
|
1220
|
+
signal
|
1221
|
+
});
|
1222
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
1223
|
+
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
1224
|
+
url: "/workspaces",
|
1225
|
+
method: "get",
|
1226
|
+
...variables,
|
1227
|
+
signal
|
1228
|
+
});
|
1229
|
+
const createWorkspace = (variables, signal) => controlPlaneFetch({
|
1230
|
+
url: "/workspaces",
|
458
1231
|
method: "post",
|
459
|
-
...variables
|
1232
|
+
...variables,
|
1233
|
+
signal
|
460
1234
|
});
|
461
|
-
const
|
462
|
-
url: "/
|
1235
|
+
const getWorkspace = (variables, signal) => controlPlaneFetch({
|
1236
|
+
url: "/workspaces/{workspaceId}",
|
463
1237
|
method: "get",
|
464
|
-
...variables
|
1238
|
+
...variables,
|
1239
|
+
signal
|
465
1240
|
});
|
466
|
-
const
|
467
|
-
url: "/
|
468
|
-
method: "
|
469
|
-
...variables
|
1241
|
+
const updateWorkspace = (variables, signal) => controlPlaneFetch({
|
1242
|
+
url: "/workspaces/{workspaceId}",
|
1243
|
+
method: "put",
|
1244
|
+
...variables,
|
1245
|
+
signal
|
470
1246
|
});
|
471
|
-
const
|
472
|
-
url: "/
|
473
|
-
method: "
|
474
|
-
...variables
|
1247
|
+
const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
1248
|
+
url: "/workspaces/{workspaceId}",
|
1249
|
+
method: "delete",
|
1250
|
+
...variables,
|
1251
|
+
signal
|
475
1252
|
});
|
476
|
-
const
|
477
|
-
const
|
478
|
-
const
|
479
|
-
|
480
|
-
const deleteRecord = (variables) => fetch$1({
|
481
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
1253
|
+
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
1254
|
+
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
1255
|
+
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
1256
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
482
1257
|
method: "delete",
|
483
|
-
...variables
|
1258
|
+
...variables,
|
1259
|
+
signal
|
484
1260
|
});
|
485
|
-
const
|
486
|
-
|
1261
|
+
const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
1262
|
+
const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
1263
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
1264
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
1265
|
+
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1266
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1267
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1268
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1269
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
487
1270
|
method: "get",
|
488
|
-
...variables
|
1271
|
+
...variables,
|
1272
|
+
signal
|
489
1273
|
});
|
490
|
-
const
|
491
|
-
const
|
492
|
-
url: "/
|
493
|
-
method: "
|
494
|
-
...variables
|
1274
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
1275
|
+
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
1276
|
+
url: "/workspaces/{workspaceId}/dbs",
|
1277
|
+
method: "get",
|
1278
|
+
...variables,
|
1279
|
+
signal
|
495
1280
|
});
|
496
|
-
const
|
497
|
-
|
498
|
-
|
499
|
-
|
1281
|
+
const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
1282
|
+
const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
1283
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
1284
|
+
method: "delete",
|
1285
|
+
...variables,
|
1286
|
+
signal
|
500
1287
|
});
|
501
|
-
const
|
502
|
-
|
503
|
-
|
504
|
-
|
1288
|
+
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
1289
|
+
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1290
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
1291
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
1292
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
1293
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
1294
|
+
const listRegions = (variables, signal) => controlPlaneFetch({
|
1295
|
+
url: "/workspaces/{workspaceId}/regions",
|
1296
|
+
method: "get",
|
1297
|
+
...variables,
|
1298
|
+
signal
|
505
1299
|
});
|
506
|
-
const operationsByTag = {
|
507
|
-
|
1300
|
+
const operationsByTag$1 = {
|
1301
|
+
oAuth: {
|
1302
|
+
getAuthorizationCode,
|
1303
|
+
grantAuthorizationCode,
|
1304
|
+
getUserOAuthClients,
|
1305
|
+
deleteUserOAuthClient,
|
1306
|
+
getUserOAuthAccessTokens,
|
1307
|
+
deleteOAuthAccessToken,
|
1308
|
+
updateOAuthAccessToken
|
1309
|
+
},
|
1310
|
+
users: { getUser, updateUser, deleteUser },
|
1311
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
508
1312
|
workspaces: {
|
509
|
-
createWorkspace,
|
510
1313
|
getWorkspacesList,
|
1314
|
+
createWorkspace,
|
511
1315
|
getWorkspace,
|
512
1316
|
updateWorkspace,
|
513
1317
|
deleteWorkspace,
|
514
1318
|
getWorkspaceMembersList,
|
515
1319
|
updateWorkspaceMemberRole,
|
516
|
-
removeWorkspaceMember
|
1320
|
+
removeWorkspaceMember
|
1321
|
+
},
|
1322
|
+
invites: {
|
517
1323
|
inviteWorkspaceMember,
|
518
1324
|
updateWorkspaceMemberInvite,
|
519
1325
|
cancelWorkspaceMemberInvite,
|
520
|
-
|
521
|
-
|
1326
|
+
acceptWorkspaceMemberInvite,
|
1327
|
+
resendWorkspaceMemberInvite
|
522
1328
|
},
|
523
|
-
|
1329
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
1330
|
+
databases: {
|
524
1331
|
getDatabaseList,
|
525
1332
|
createDatabase,
|
526
1333
|
deleteDatabase,
|
527
1334
|
getDatabaseMetadata,
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
getBranchList,
|
535
|
-
getBranchDetails,
|
536
|
-
createBranch,
|
537
|
-
deleteBranch,
|
538
|
-
updateBranchMetadata,
|
539
|
-
getBranchMetadata,
|
540
|
-
getBranchMigrationHistory,
|
541
|
-
executeBranchMigrationPlan,
|
542
|
-
getBranchMigrationPlan,
|
543
|
-
getBranchStats
|
544
|
-
},
|
545
|
-
table: {
|
546
|
-
createTable,
|
547
|
-
deleteTable,
|
548
|
-
updateTable,
|
549
|
-
getTableSchema,
|
550
|
-
setTableSchema,
|
551
|
-
getTableColumns,
|
552
|
-
addTableColumn,
|
553
|
-
getColumn,
|
554
|
-
deleteColumn,
|
555
|
-
updateColumn
|
556
|
-
},
|
557
|
-
records: {
|
558
|
-
insertRecord,
|
559
|
-
insertRecordWithID,
|
560
|
-
updateRecordWithID,
|
561
|
-
upsertRecordWithID,
|
562
|
-
deleteRecord,
|
563
|
-
getRecord,
|
564
|
-
bulkInsertTableRecords,
|
565
|
-
queryTable,
|
566
|
-
searchTable,
|
567
|
-
searchBranch
|
1335
|
+
updateDatabaseMetadata,
|
1336
|
+
renameDatabase,
|
1337
|
+
getDatabaseGithubSettings,
|
1338
|
+
updateDatabaseGithubSettings,
|
1339
|
+
deleteDatabaseGithubSettings,
|
1340
|
+
listRegions
|
568
1341
|
}
|
569
1342
|
};
|
570
1343
|
|
571
|
-
|
572
|
-
if (isValidAlias(provider)) {
|
573
|
-
return providers[provider][type];
|
574
|
-
} else if (isValidBuilder(provider)) {
|
575
|
-
return provider[type];
|
576
|
-
}
|
577
|
-
throw new Error("Invalid API provider");
|
578
|
-
}
|
579
|
-
const providers = {
|
580
|
-
production: {
|
581
|
-
main: "https://api.xata.io",
|
582
|
-
workspaces: "https://{workspaceId}.xata.sh"
|
583
|
-
},
|
584
|
-
staging: {
|
585
|
-
main: "https://staging.xatabase.co",
|
586
|
-
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
587
|
-
}
|
588
|
-
};
|
589
|
-
function isValidAlias(alias) {
|
590
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
591
|
-
}
|
592
|
-
function isValidBuilder(builder) {
|
593
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
594
|
-
}
|
1344
|
+
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
595
1345
|
|
596
|
-
|
597
|
-
if (!member.has(obj))
|
598
|
-
throw TypeError("Cannot " + msg);
|
599
|
-
};
|
600
|
-
var __privateGet$7 = (obj, member, getter) => {
|
601
|
-
__accessCheck$7(obj, member, "read from private field");
|
602
|
-
return getter ? getter.call(obj) : member.get(obj);
|
603
|
-
};
|
604
|
-
var __privateAdd$7 = (obj, member, value) => {
|
605
|
-
if (member.has(obj))
|
606
|
-
throw TypeError("Cannot add the same private member more than once");
|
607
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
608
|
-
};
|
609
|
-
var __privateSet$7 = (obj, member, value, setter) => {
|
610
|
-
__accessCheck$7(obj, member, "write to private field");
|
611
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
612
|
-
return value;
|
613
|
-
};
|
614
|
-
var _extraProps, _namespaces;
|
615
|
-
class XataApiClient {
|
1346
|
+
const buildApiClient = () => class {
|
616
1347
|
constructor(options = {}) {
|
617
|
-
__privateAdd$7(this, _extraProps, void 0);
|
618
|
-
__privateAdd$7(this, _namespaces, {});
|
619
1348
|
const provider = options.host ?? "production";
|
620
1349
|
const apiKey = options.apiKey ?? getAPIKey();
|
621
1350
|
const trace = options.trace ?? defaultTrace;
|
1351
|
+
const clientID = generateUUID();
|
622
1352
|
if (!apiKey) {
|
623
1353
|
throw new Error("Could not resolve a valid apiKey");
|
624
1354
|
}
|
625
|
-
|
1355
|
+
const extraProps = {
|
626
1356
|
apiUrl: getHostUrl(provider, "main"),
|
627
1357
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
628
|
-
|
1358
|
+
fetch: getFetchImplementation(options.fetch),
|
629
1359
|
apiKey,
|
630
|
-
trace
|
1360
|
+
trace,
|
1361
|
+
clientName: options.clientName,
|
1362
|
+
xataAgentExtra: options.xataAgentExtra,
|
1363
|
+
clientID
|
1364
|
+
};
|
1365
|
+
return new Proxy(this, {
|
1366
|
+
get: (_target, namespace) => {
|
1367
|
+
if (operationsByTag[namespace] === void 0) {
|
1368
|
+
return void 0;
|
1369
|
+
}
|
1370
|
+
return new Proxy(
|
1371
|
+
{},
|
1372
|
+
{
|
1373
|
+
get: (_target2, operation) => {
|
1374
|
+
if (operationsByTag[namespace][operation] === void 0) {
|
1375
|
+
return void 0;
|
1376
|
+
}
|
1377
|
+
const method = operationsByTag[namespace][operation];
|
1378
|
+
return async (params) => {
|
1379
|
+
return await method({ ...params, ...extraProps });
|
1380
|
+
};
|
1381
|
+
}
|
1382
|
+
}
|
1383
|
+
);
|
1384
|
+
}
|
631
1385
|
});
|
632
1386
|
}
|
633
|
-
|
634
|
-
|
635
|
-
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
636
|
-
return __privateGet$7(this, _namespaces).user;
|
637
|
-
}
|
638
|
-
get workspaces() {
|
639
|
-
if (!__privateGet$7(this, _namespaces).workspaces)
|
640
|
-
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
641
|
-
return __privateGet$7(this, _namespaces).workspaces;
|
642
|
-
}
|
643
|
-
get databases() {
|
644
|
-
if (!__privateGet$7(this, _namespaces).databases)
|
645
|
-
__privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
|
646
|
-
return __privateGet$7(this, _namespaces).databases;
|
647
|
-
}
|
648
|
-
get branches() {
|
649
|
-
if (!__privateGet$7(this, _namespaces).branches)
|
650
|
-
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
651
|
-
return __privateGet$7(this, _namespaces).branches;
|
652
|
-
}
|
653
|
-
get tables() {
|
654
|
-
if (!__privateGet$7(this, _namespaces).tables)
|
655
|
-
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
656
|
-
return __privateGet$7(this, _namespaces).tables;
|
657
|
-
}
|
658
|
-
get records() {
|
659
|
-
if (!__privateGet$7(this, _namespaces).records)
|
660
|
-
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
661
|
-
return __privateGet$7(this, _namespaces).records;
|
662
|
-
}
|
1387
|
+
};
|
1388
|
+
class XataApiClient extends buildApiClient() {
|
663
1389
|
}
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
this.extraProps = extraProps;
|
669
|
-
}
|
670
|
-
getUser() {
|
671
|
-
return operationsByTag.users.getUser({ ...this.extraProps });
|
672
|
-
}
|
673
|
-
updateUser(user) {
|
674
|
-
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
675
|
-
}
|
676
|
-
deleteUser() {
|
677
|
-
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
678
|
-
}
|
679
|
-
getUserAPIKeys() {
|
680
|
-
return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
|
681
|
-
}
|
682
|
-
createUserAPIKey(keyName) {
|
683
|
-
return operationsByTag.users.createUserAPIKey({
|
684
|
-
pathParams: { keyName },
|
685
|
-
...this.extraProps
|
686
|
-
});
|
687
|
-
}
|
688
|
-
deleteUserAPIKey(keyName) {
|
689
|
-
return operationsByTag.users.deleteUserAPIKey({
|
690
|
-
pathParams: { keyName },
|
691
|
-
...this.extraProps
|
692
|
-
});
|
1390
|
+
|
1391
|
+
class XataApiPlugin {
|
1392
|
+
build(options) {
|
1393
|
+
return new XataApiClient(options);
|
693
1394
|
}
|
694
1395
|
}
|
695
|
-
|
696
|
-
|
697
|
-
this.extraProps = extraProps;
|
698
|
-
}
|
699
|
-
createWorkspace(workspaceMeta) {
|
700
|
-
return operationsByTag.workspaces.createWorkspace({
|
701
|
-
body: workspaceMeta,
|
702
|
-
...this.extraProps
|
703
|
-
});
|
704
|
-
}
|
705
|
-
getWorkspacesList() {
|
706
|
-
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
707
|
-
}
|
708
|
-
getWorkspace(workspaceId) {
|
709
|
-
return operationsByTag.workspaces.getWorkspace({
|
710
|
-
pathParams: { workspaceId },
|
711
|
-
...this.extraProps
|
712
|
-
});
|
713
|
-
}
|
714
|
-
updateWorkspace(workspaceId, workspaceMeta) {
|
715
|
-
return operationsByTag.workspaces.updateWorkspace({
|
716
|
-
pathParams: { workspaceId },
|
717
|
-
body: workspaceMeta,
|
718
|
-
...this.extraProps
|
719
|
-
});
|
720
|
-
}
|
721
|
-
deleteWorkspace(workspaceId) {
|
722
|
-
return operationsByTag.workspaces.deleteWorkspace({
|
723
|
-
pathParams: { workspaceId },
|
724
|
-
...this.extraProps
|
725
|
-
});
|
726
|
-
}
|
727
|
-
getWorkspaceMembersList(workspaceId) {
|
728
|
-
return operationsByTag.workspaces.getWorkspaceMembersList({
|
729
|
-
pathParams: { workspaceId },
|
730
|
-
...this.extraProps
|
731
|
-
});
|
732
|
-
}
|
733
|
-
updateWorkspaceMemberRole(workspaceId, userId, role) {
|
734
|
-
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
735
|
-
pathParams: { workspaceId, userId },
|
736
|
-
body: { role },
|
737
|
-
...this.extraProps
|
738
|
-
});
|
739
|
-
}
|
740
|
-
removeWorkspaceMember(workspaceId, userId) {
|
741
|
-
return operationsByTag.workspaces.removeWorkspaceMember({
|
742
|
-
pathParams: { workspaceId, userId },
|
743
|
-
...this.extraProps
|
744
|
-
});
|
745
|
-
}
|
746
|
-
inviteWorkspaceMember(workspaceId, email, role) {
|
747
|
-
return operationsByTag.workspaces.inviteWorkspaceMember({
|
748
|
-
pathParams: { workspaceId },
|
749
|
-
body: { email, role },
|
750
|
-
...this.extraProps
|
751
|
-
});
|
752
|
-
}
|
753
|
-
updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
|
754
|
-
return operationsByTag.workspaces.updateWorkspaceMemberInvite({
|
755
|
-
pathParams: { workspaceId, inviteId },
|
756
|
-
body: { role },
|
757
|
-
...this.extraProps
|
758
|
-
});
|
759
|
-
}
|
760
|
-
cancelWorkspaceMemberInvite(workspaceId, inviteId) {
|
761
|
-
return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
|
762
|
-
pathParams: { workspaceId, inviteId },
|
763
|
-
...this.extraProps
|
764
|
-
});
|
765
|
-
}
|
766
|
-
resendWorkspaceMemberInvite(workspaceId, inviteId) {
|
767
|
-
return operationsByTag.workspaces.resendWorkspaceMemberInvite({
|
768
|
-
pathParams: { workspaceId, inviteId },
|
769
|
-
...this.extraProps
|
770
|
-
});
|
771
|
-
}
|
772
|
-
acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
|
773
|
-
return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
|
774
|
-
pathParams: { workspaceId, inviteKey },
|
775
|
-
...this.extraProps
|
776
|
-
});
|
777
|
-
}
|
1396
|
+
|
1397
|
+
class XataPlugin {
|
778
1398
|
}
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
});
|
795
|
-
}
|
796
|
-
deleteDatabase(workspace, dbName) {
|
797
|
-
return operationsByTag.database.deleteDatabase({
|
798
|
-
pathParams: { workspace, dbName },
|
799
|
-
...this.extraProps
|
800
|
-
});
|
801
|
-
}
|
802
|
-
getDatabaseMetadata(workspace, dbName) {
|
803
|
-
return operationsByTag.database.getDatabaseMetadata({
|
804
|
-
pathParams: { workspace, dbName },
|
805
|
-
...this.extraProps
|
806
|
-
});
|
807
|
-
}
|
808
|
-
getGitBranchesMapping(workspace, dbName) {
|
809
|
-
return operationsByTag.database.getGitBranchesMapping({
|
810
|
-
pathParams: { workspace, dbName },
|
811
|
-
...this.extraProps
|
812
|
-
});
|
813
|
-
}
|
814
|
-
addGitBranchesEntry(workspace, dbName, body) {
|
815
|
-
return operationsByTag.database.addGitBranchesEntry({
|
816
|
-
pathParams: { workspace, dbName },
|
817
|
-
body,
|
818
|
-
...this.extraProps
|
819
|
-
});
|
820
|
-
}
|
821
|
-
removeGitBranchesEntry(workspace, dbName, gitBranch) {
|
822
|
-
return operationsByTag.database.removeGitBranchesEntry({
|
823
|
-
pathParams: { workspace, dbName },
|
824
|
-
queryParams: { gitBranch },
|
825
|
-
...this.extraProps
|
826
|
-
});
|
827
|
-
}
|
828
|
-
resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
|
829
|
-
return operationsByTag.database.resolveBranch({
|
830
|
-
pathParams: { workspace, dbName },
|
831
|
-
queryParams: { gitBranch, fallbackBranch },
|
832
|
-
...this.extraProps
|
833
|
-
});
|
834
|
-
}
|
1399
|
+
|
1400
|
+
function buildTransformString(transformations) {
|
1401
|
+
return transformations.flatMap(
|
1402
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
1403
|
+
if (key === "trim") {
|
1404
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
1405
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
1406
|
+
}
|
1407
|
+
if (key === "gravity" && typeof value === "object") {
|
1408
|
+
const { x = 0.5, y = 0.5 } = value;
|
1409
|
+
return `${key}=${[x, y].join("x")}`;
|
1410
|
+
}
|
1411
|
+
return `${key}=${value}`;
|
1412
|
+
})
|
1413
|
+
).join(",");
|
835
1414
|
}
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
return operationsByTag.branch.getBranchDetails({
|
848
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
849
|
-
...this.extraProps
|
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,
|
857
|
-
...this.extraProps
|
858
|
-
});
|
859
|
-
}
|
860
|
-
deleteBranch(workspace, database, branch) {
|
861
|
-
return operationsByTag.branch.deleteBranch({
|
862
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
863
|
-
...this.extraProps
|
864
|
-
});
|
865
|
-
}
|
866
|
-
updateBranchMetadata(workspace, database, branch, metadata = {}) {
|
867
|
-
return operationsByTag.branch.updateBranchMetadata({
|
868
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
869
|
-
body: metadata,
|
870
|
-
...this.extraProps
|
871
|
-
});
|
872
|
-
}
|
873
|
-
getBranchMetadata(workspace, database, branch) {
|
874
|
-
return operationsByTag.branch.getBranchMetadata({
|
875
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
876
|
-
...this.extraProps
|
877
|
-
});
|
878
|
-
}
|
879
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
880
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
881
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
882
|
-
body: options,
|
883
|
-
...this.extraProps
|
884
|
-
});
|
885
|
-
}
|
886
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
887
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
888
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
889
|
-
body: migrationPlan,
|
890
|
-
...this.extraProps
|
891
|
-
});
|
892
|
-
}
|
893
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
894
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
895
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
896
|
-
body: schema,
|
897
|
-
...this.extraProps
|
898
|
-
});
|
899
|
-
}
|
900
|
-
getBranchStats(workspace, database, branch) {
|
901
|
-
return operationsByTag.branch.getBranchStats({
|
902
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
903
|
-
...this.extraProps
|
904
|
-
});
|
905
|
-
}
|
1415
|
+
function transformImage(url, ...transformations) {
|
1416
|
+
if (!isDefined(url))
|
1417
|
+
return void 0;
|
1418
|
+
const newTransformations = buildTransformString(transformations);
|
1419
|
+
const { hostname, pathname, search } = new URL(url);
|
1420
|
+
const pathParts = pathname.split("/");
|
1421
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
1422
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
1423
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
1424
|
+
const path = pathParts.join("/");
|
1425
|
+
return `https://${hostname}${transform}${path}${search}`;
|
906
1426
|
}
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
...this.extraProps
|
934
|
-
});
|
935
|
-
}
|
936
|
-
setTableSchema(workspace, database, branch, tableName, options) {
|
937
|
-
return operationsByTag.table.setTableSchema({
|
938
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
939
|
-
body: options,
|
940
|
-
...this.extraProps
|
941
|
-
});
|
942
|
-
}
|
943
|
-
getTableColumns(workspace, database, branch, tableName) {
|
944
|
-
return operationsByTag.table.getTableColumns({
|
945
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
946
|
-
...this.extraProps
|
947
|
-
});
|
948
|
-
}
|
949
|
-
addTableColumn(workspace, database, branch, tableName, column) {
|
950
|
-
return operationsByTag.table.addTableColumn({
|
951
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
952
|
-
body: column,
|
953
|
-
...this.extraProps
|
954
|
-
});
|
955
|
-
}
|
956
|
-
getColumn(workspace, database, branch, tableName, columnName) {
|
957
|
-
return operationsByTag.table.getColumn({
|
958
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
|
959
|
-
...this.extraProps
|
960
|
-
});
|
961
|
-
}
|
962
|
-
deleteColumn(workspace, database, branch, tableName, columnName) {
|
963
|
-
return operationsByTag.table.deleteColumn({
|
964
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
|
965
|
-
...this.extraProps
|
966
|
-
});
|
967
|
-
}
|
968
|
-
updateColumn(workspace, database, branch, tableName, columnName, options) {
|
969
|
-
return operationsByTag.table.updateColumn({
|
970
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
|
971
|
-
body: options,
|
972
|
-
...this.extraProps
|
973
|
-
});
|
1427
|
+
|
1428
|
+
class XataFile {
|
1429
|
+
constructor(file) {
|
1430
|
+
this.id = file.id;
|
1431
|
+
this.name = file.name;
|
1432
|
+
this.mediaType = file.mediaType;
|
1433
|
+
this.base64Content = file.base64Content;
|
1434
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
1435
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
1436
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
1437
|
+
this.size = file.size;
|
1438
|
+
this.version = file.version;
|
1439
|
+
this.url = file.url;
|
1440
|
+
this.signedUrl = file.signedUrl;
|
1441
|
+
this.uploadUrl = file.uploadUrl;
|
1442
|
+
this.attributes = file.attributes;
|
1443
|
+
}
|
1444
|
+
static fromBuffer(buffer, options = {}) {
|
1445
|
+
const base64Content = buffer.toString("base64");
|
1446
|
+
return new XataFile({ ...options, base64Content });
|
1447
|
+
}
|
1448
|
+
toBuffer() {
|
1449
|
+
if (!this.base64Content) {
|
1450
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1451
|
+
}
|
1452
|
+
return Buffer.from(this.base64Content, "base64");
|
974
1453
|
}
|
975
|
-
}
|
976
|
-
|
977
|
-
|
978
|
-
this.extraProps = extraProps;
|
1454
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
1455
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
1456
|
+
return this.fromUint8Array(uint8Array, options);
|
979
1457
|
}
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
});
|
1458
|
+
toArrayBuffer() {
|
1459
|
+
if (!this.base64Content) {
|
1460
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1461
|
+
}
|
1462
|
+
const binary = atob(this.base64Content);
|
1463
|
+
return new ArrayBuffer(binary.length);
|
987
1464
|
}
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
});
|
1465
|
+
static fromUint8Array(uint8Array, options = {}) {
|
1466
|
+
let binary = "";
|
1467
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
1468
|
+
binary += String.fromCharCode(uint8Array[i]);
|
1469
|
+
}
|
1470
|
+
const base64Content = btoa(binary);
|
1471
|
+
return new XataFile({ ...options, base64Content });
|
995
1472
|
}
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1473
|
+
toUint8Array() {
|
1474
|
+
if (!this.base64Content) {
|
1475
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1476
|
+
}
|
1477
|
+
const binary = atob(this.base64Content);
|
1478
|
+
const uint8Array = new Uint8Array(binary.length);
|
1479
|
+
for (let i = 0; i < binary.length; i++) {
|
1480
|
+
uint8Array[i] = binary.charCodeAt(i);
|
1481
|
+
}
|
1482
|
+
return uint8Array;
|
1003
1483
|
}
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
...this.extraProps
|
1010
|
-
});
|
1484
|
+
static async fromBlob(file, options = {}) {
|
1485
|
+
const name = options.name ?? file.name;
|
1486
|
+
const mediaType = file.type;
|
1487
|
+
const arrayBuffer = await file.arrayBuffer();
|
1488
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
1011
1489
|
}
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1490
|
+
toBlob() {
|
1491
|
+
if (!this.base64Content) {
|
1492
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1493
|
+
}
|
1494
|
+
const binary = atob(this.base64Content);
|
1495
|
+
const uint8Array = new Uint8Array(binary.length);
|
1496
|
+
for (let i = 0; i < binary.length; i++) {
|
1497
|
+
uint8Array[i] = binary.charCodeAt(i);
|
1498
|
+
}
|
1499
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
1018
1500
|
}
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
queryParams: options,
|
1023
|
-
...this.extraProps
|
1024
|
-
});
|
1501
|
+
static fromString(string, options = {}) {
|
1502
|
+
const base64Content = btoa(string);
|
1503
|
+
return new XataFile({ ...options, base64Content });
|
1025
1504
|
}
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
...this.extraProps
|
1032
|
-
});
|
1505
|
+
toString() {
|
1506
|
+
if (!this.base64Content) {
|
1507
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1508
|
+
}
|
1509
|
+
return atob(this.base64Content);
|
1033
1510
|
}
|
1034
|
-
|
1035
|
-
return
|
1036
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1037
|
-
body: query,
|
1038
|
-
...this.extraProps
|
1039
|
-
});
|
1511
|
+
static fromBase64(base64Content, options = {}) {
|
1512
|
+
return new XataFile({ ...options, base64Content });
|
1040
1513
|
}
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
});
|
1514
|
+
toBase64() {
|
1515
|
+
if (!this.base64Content) {
|
1516
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
1517
|
+
}
|
1518
|
+
return this.base64Content;
|
1047
1519
|
}
|
1048
|
-
|
1049
|
-
return
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1520
|
+
transform(...options) {
|
1521
|
+
return {
|
1522
|
+
url: transformImage(this.url, ...options),
|
1523
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
1524
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
1525
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
1526
|
+
};
|
1054
1527
|
}
|
1055
1528
|
}
|
1529
|
+
const parseInputFileEntry = async (entry) => {
|
1530
|
+
if (!isDefined(entry))
|
1531
|
+
return null;
|
1532
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
1533
|
+
return compactObject({
|
1534
|
+
id,
|
1535
|
+
// Name cannot be an empty string in our API
|
1536
|
+
name: name ? name : void 0,
|
1537
|
+
mediaType,
|
1538
|
+
base64Content,
|
1539
|
+
enablePublicUrl,
|
1540
|
+
signedUrlTimeout,
|
1541
|
+
uploadUrlTimeout
|
1542
|
+
});
|
1543
|
+
};
|
1056
1544
|
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1545
|
+
function cleanFilter(filter) {
|
1546
|
+
if (!isDefined(filter))
|
1547
|
+
return void 0;
|
1548
|
+
if (!isObject(filter))
|
1549
|
+
return filter;
|
1550
|
+
const values = Object.fromEntries(
|
1551
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
1552
|
+
if (!isDefined(value))
|
1553
|
+
return acc;
|
1554
|
+
if (Array.isArray(value)) {
|
1555
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
1556
|
+
if (clean.length === 0)
|
1557
|
+
return acc;
|
1558
|
+
return [...acc, [key, clean]];
|
1559
|
+
}
|
1560
|
+
if (isObject(value)) {
|
1561
|
+
const clean = cleanFilter(value);
|
1562
|
+
if (!isDefined(clean))
|
1563
|
+
return acc;
|
1564
|
+
return [...acc, [key, clean]];
|
1565
|
+
}
|
1566
|
+
return [...acc, [key, value]];
|
1567
|
+
}, [])
|
1568
|
+
);
|
1569
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
1062
1570
|
}
|
1063
1571
|
|
1064
|
-
|
1572
|
+
function stringifyJson(value) {
|
1573
|
+
if (!isDefined(value))
|
1574
|
+
return value;
|
1575
|
+
if (isString(value))
|
1576
|
+
return value;
|
1577
|
+
try {
|
1578
|
+
return JSON.stringify(value);
|
1579
|
+
} catch (e) {
|
1580
|
+
return value;
|
1581
|
+
}
|
1582
|
+
}
|
1583
|
+
function parseJson(value) {
|
1584
|
+
try {
|
1585
|
+
return JSON.parse(value);
|
1586
|
+
} catch (e) {
|
1587
|
+
return value;
|
1588
|
+
}
|
1065
1589
|
}
|
1066
1590
|
|
1067
1591
|
var __accessCheck$6 = (obj, member, msg) => {
|
@@ -1090,31 +1614,59 @@ class Page {
|
|
1090
1614
|
this.meta = meta;
|
1091
1615
|
this.records = new RecordArray(this, records);
|
1092
1616
|
}
|
1617
|
+
/**
|
1618
|
+
* Retrieves the next page of results.
|
1619
|
+
* @param size Maximum number of results to be retrieved.
|
1620
|
+
* @param offset Number of results to skip when retrieving the results.
|
1621
|
+
* @returns The next page or results.
|
1622
|
+
*/
|
1093
1623
|
async nextPage(size, offset) {
|
1094
1624
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1095
1625
|
}
|
1626
|
+
/**
|
1627
|
+
* Retrieves the previous page of results.
|
1628
|
+
* @param size Maximum number of results to be retrieved.
|
1629
|
+
* @param offset Number of results to skip when retrieving the results.
|
1630
|
+
* @returns The previous page or results.
|
1631
|
+
*/
|
1096
1632
|
async previousPage(size, offset) {
|
1097
1633
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1098
1634
|
}
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1635
|
+
/**
|
1636
|
+
* Retrieves the start page of results.
|
1637
|
+
* @param size Maximum number of results to be retrieved.
|
1638
|
+
* @param offset Number of results to skip when retrieving the results.
|
1639
|
+
* @returns The start page or results.
|
1640
|
+
*/
|
1641
|
+
async startPage(size, offset) {
|
1642
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1643
|
+
}
|
1644
|
+
/**
|
1645
|
+
* Retrieves the end page of results.
|
1646
|
+
* @param size Maximum number of results to be retrieved.
|
1647
|
+
* @param offset Number of results to skip when retrieving the results.
|
1648
|
+
* @returns The end page or results.
|
1649
|
+
*/
|
1650
|
+
async endPage(size, offset) {
|
1651
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1652
|
+
}
|
1653
|
+
/**
|
1654
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
1655
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
1656
|
+
*/
|
1105
1657
|
hasNextPage() {
|
1106
1658
|
return this.meta.page.more;
|
1107
1659
|
}
|
1108
1660
|
}
|
1109
1661
|
_query = new WeakMap();
|
1110
|
-
const PAGINATION_MAX_SIZE =
|
1662
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
1111
1663
|
const PAGINATION_DEFAULT_SIZE = 20;
|
1112
|
-
const PAGINATION_MAX_OFFSET =
|
1664
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
1113
1665
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1114
1666
|
function isCursorPaginationOptions(options) {
|
1115
|
-
return isDefined(options) && (isDefined(options.
|
1667
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1116
1668
|
}
|
1117
|
-
const _RecordArray = class extends Array {
|
1669
|
+
const _RecordArray = class _RecordArray extends Array {
|
1118
1670
|
constructor(...args) {
|
1119
1671
|
super(..._RecordArray.parseConstructorParams(...args));
|
1120
1672
|
__privateAdd$6(this, _page, void 0);
|
@@ -1133,31 +1685,60 @@ const _RecordArray = class extends Array {
|
|
1133
1685
|
toArray() {
|
1134
1686
|
return new Array(...this);
|
1135
1687
|
}
|
1688
|
+
toSerializable() {
|
1689
|
+
return JSON.parse(this.toString());
|
1690
|
+
}
|
1691
|
+
toString() {
|
1692
|
+
return JSON.stringify(this.toArray());
|
1693
|
+
}
|
1136
1694
|
map(callbackfn, thisArg) {
|
1137
1695
|
return this.toArray().map(callbackfn, thisArg);
|
1138
1696
|
}
|
1697
|
+
/**
|
1698
|
+
* Retrieve next page of records
|
1699
|
+
*
|
1700
|
+
* @returns A new array of objects
|
1701
|
+
*/
|
1139
1702
|
async nextPage(size, offset) {
|
1140
1703
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
1141
1704
|
return new _RecordArray(newPage);
|
1142
1705
|
}
|
1706
|
+
/**
|
1707
|
+
* Retrieve previous page of records
|
1708
|
+
*
|
1709
|
+
* @returns A new array of objects
|
1710
|
+
*/
|
1143
1711
|
async previousPage(size, offset) {
|
1144
1712
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1145
1713
|
return new _RecordArray(newPage);
|
1146
1714
|
}
|
1147
|
-
|
1148
|
-
|
1715
|
+
/**
|
1716
|
+
* Retrieve start page of records
|
1717
|
+
*
|
1718
|
+
* @returns A new array of objects
|
1719
|
+
*/
|
1720
|
+
async startPage(size, offset) {
|
1721
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1149
1722
|
return new _RecordArray(newPage);
|
1150
1723
|
}
|
1151
|
-
|
1152
|
-
|
1724
|
+
/**
|
1725
|
+
* Retrieve end page of records
|
1726
|
+
*
|
1727
|
+
* @returns A new array of objects
|
1728
|
+
*/
|
1729
|
+
async endPage(size, offset) {
|
1730
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1153
1731
|
return new _RecordArray(newPage);
|
1154
1732
|
}
|
1733
|
+
/**
|
1734
|
+
* @returns Boolean indicating if there is a next page
|
1735
|
+
*/
|
1155
1736
|
hasNextPage() {
|
1156
1737
|
return __privateGet$6(this, _page).meta.page.more;
|
1157
1738
|
}
|
1158
1739
|
};
|
1159
|
-
let RecordArray = _RecordArray;
|
1160
1740
|
_page = new WeakMap();
|
1741
|
+
let RecordArray = _RecordArray;
|
1161
1742
|
|
1162
1743
|
var __accessCheck$5 = (obj, member, msg) => {
|
1163
1744
|
if (!member.has(obj))
|
@@ -1177,13 +1758,19 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1177
1758
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1178
1759
|
return value;
|
1179
1760
|
};
|
1180
|
-
var
|
1181
|
-
|
1761
|
+
var __privateMethod$3 = (obj, member, method) => {
|
1762
|
+
__accessCheck$5(obj, member, "access private method");
|
1763
|
+
return method;
|
1764
|
+
};
|
1765
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1766
|
+
const _Query = class _Query {
|
1182
1767
|
constructor(repository, table, data, rawParent) {
|
1768
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1183
1769
|
__privateAdd$5(this, _table$1, void 0);
|
1184
1770
|
__privateAdd$5(this, _repository, void 0);
|
1185
1771
|
__privateAdd$5(this, _data, { filter: {} });
|
1186
|
-
|
1772
|
+
// Implements pagination
|
1773
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
1187
1774
|
this.records = new RecordArray(this, []);
|
1188
1775
|
__privateSet$5(this, _table$1, table);
|
1189
1776
|
if (repository) {
|
@@ -1198,9 +1785,11 @@ const _Query = class {
|
|
1198
1785
|
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1199
1786
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1200
1787
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1201
|
-
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns
|
1788
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
1789
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1202
1790
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1203
1791
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
1792
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1204
1793
|
this.any = this.any.bind(this);
|
1205
1794
|
this.all = this.all.bind(this);
|
1206
1795
|
this.not = this.not.bind(this);
|
@@ -1218,29 +1807,52 @@ const _Query = class {
|
|
1218
1807
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
1219
1808
|
return toBase64(key);
|
1220
1809
|
}
|
1810
|
+
/**
|
1811
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
1812
|
+
* @param queries An array of subqueries.
|
1813
|
+
* @returns A new Query object.
|
1814
|
+
*/
|
1221
1815
|
any(...queries) {
|
1222
1816
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1223
1817
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
1224
1818
|
}
|
1819
|
+
/**
|
1820
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
1821
|
+
* @param queries An array of subqueries.
|
1822
|
+
* @returns A new Query object.
|
1823
|
+
*/
|
1225
1824
|
all(...queries) {
|
1226
1825
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1227
1826
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1228
1827
|
}
|
1828
|
+
/**
|
1829
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
1830
|
+
* @param queries An array of subqueries.
|
1831
|
+
* @returns A new Query object.
|
1832
|
+
*/
|
1229
1833
|
not(...queries) {
|
1230
1834
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1231
1835
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
1232
1836
|
}
|
1837
|
+
/**
|
1838
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
1839
|
+
* @param queries An array of subqueries.
|
1840
|
+
* @returns A new Query object.
|
1841
|
+
*/
|
1233
1842
|
none(...queries) {
|
1234
1843
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
1235
1844
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
1236
1845
|
}
|
1237
1846
|
filter(a, b) {
|
1238
1847
|
if (arguments.length === 1) {
|
1239
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
1848
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
1849
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
1850
|
+
}));
|
1240
1851
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1241
1852
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1242
1853
|
} else {
|
1243
|
-
const
|
1854
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
1855
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1244
1856
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1245
1857
|
}
|
1246
1858
|
}
|
@@ -1249,6 +1861,11 @@ const _Query = class {
|
|
1249
1861
|
const sort = [...originalSort, { column, direction }];
|
1250
1862
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1251
1863
|
}
|
1864
|
+
/**
|
1865
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
1866
|
+
* @param columns Array of column names to be returned by the query.
|
1867
|
+
* @returns A new Query object.
|
1868
|
+
*/
|
1252
1869
|
select(columns) {
|
1253
1870
|
return new _Query(
|
1254
1871
|
__privateGet$5(this, _repository),
|
@@ -1261,6 +1878,12 @@ const _Query = class {
|
|
1261
1878
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
1262
1879
|
return __privateGet$5(this, _repository).query(query);
|
1263
1880
|
}
|
1881
|
+
/**
|
1882
|
+
* Get results in an iterator
|
1883
|
+
*
|
1884
|
+
* @async
|
1885
|
+
* @returns Async interable of results
|
1886
|
+
*/
|
1264
1887
|
async *[Symbol.asyncIterator]() {
|
1265
1888
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
1266
1889
|
yield record;
|
@@ -1278,11 +1901,20 @@ const _Query = class {
|
|
1278
1901
|
}
|
1279
1902
|
}
|
1280
1903
|
async getMany(options = {}) {
|
1281
|
-
const
|
1904
|
+
const { pagination = {}, ...rest } = options;
|
1905
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1906
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1907
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1908
|
+
const results = [...page.records];
|
1909
|
+
while (page.hasNextPage() && results.length < size) {
|
1910
|
+
page = await page.nextPage();
|
1911
|
+
results.push(...page.records);
|
1912
|
+
}
|
1282
1913
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1283
1914
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1284
1915
|
}
|
1285
|
-
|
1916
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1917
|
+
return array;
|
1286
1918
|
}
|
1287
1919
|
async getAll(options = {}) {
|
1288
1920
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1296,36 +1928,107 @@ const _Query = class {
|
|
1296
1928
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1297
1929
|
return records[0] ?? null;
|
1298
1930
|
}
|
1931
|
+
async getFirstOrThrow(options = {}) {
|
1932
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1933
|
+
if (records[0] === void 0)
|
1934
|
+
throw new Error("No results found.");
|
1935
|
+
return records[0];
|
1936
|
+
}
|
1937
|
+
async summarize(params = {}) {
|
1938
|
+
const { summaries, summariesFilter, ...options } = params;
|
1939
|
+
const query = new _Query(
|
1940
|
+
__privateGet$5(this, _repository),
|
1941
|
+
__privateGet$5(this, _table$1),
|
1942
|
+
options,
|
1943
|
+
__privateGet$5(this, _data)
|
1944
|
+
);
|
1945
|
+
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
1946
|
+
}
|
1947
|
+
/**
|
1948
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
1949
|
+
* @param ttl The cache TTL in milliseconds.
|
1950
|
+
* @returns A new Query object.
|
1951
|
+
*/
|
1299
1952
|
cache(ttl) {
|
1300
1953
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1301
1954
|
}
|
1955
|
+
/**
|
1956
|
+
* Retrieve next page of records
|
1957
|
+
*
|
1958
|
+
* @returns A new page object.
|
1959
|
+
*/
|
1302
1960
|
nextPage(size, offset) {
|
1303
|
-
return this.
|
1961
|
+
return this.startPage(size, offset);
|
1304
1962
|
}
|
1963
|
+
/**
|
1964
|
+
* Retrieve previous page of records
|
1965
|
+
*
|
1966
|
+
* @returns A new page object
|
1967
|
+
*/
|
1305
1968
|
previousPage(size, offset) {
|
1306
|
-
return this.
|
1307
|
-
}
|
1308
|
-
|
1969
|
+
return this.startPage(size, offset);
|
1970
|
+
}
|
1971
|
+
/**
|
1972
|
+
* Retrieve start page of records
|
1973
|
+
*
|
1974
|
+
* @returns A new page object
|
1975
|
+
*/
|
1976
|
+
startPage(size, offset) {
|
1309
1977
|
return this.getPaginated({ pagination: { size, offset } });
|
1310
1978
|
}
|
1311
|
-
|
1979
|
+
/**
|
1980
|
+
* Retrieve last page of records
|
1981
|
+
*
|
1982
|
+
* @returns A new page object
|
1983
|
+
*/
|
1984
|
+
endPage(size, offset) {
|
1312
1985
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
1313
1986
|
}
|
1987
|
+
/**
|
1988
|
+
* @returns Boolean indicating if there is a next page
|
1989
|
+
*/
|
1314
1990
|
hasNextPage() {
|
1315
1991
|
return this.meta.page.more;
|
1316
1992
|
}
|
1317
1993
|
};
|
1318
|
-
let Query = _Query;
|
1319
1994
|
_table$1 = new WeakMap();
|
1320
1995
|
_repository = new WeakMap();
|
1321
1996
|
_data = new WeakMap();
|
1997
|
+
_cleanFilterConstraint = new WeakSet();
|
1998
|
+
cleanFilterConstraint_fn = function(column, value) {
|
1999
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
2000
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
2001
|
+
return { $includes: value };
|
2002
|
+
}
|
2003
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
2004
|
+
return value.id;
|
2005
|
+
}
|
2006
|
+
return value;
|
2007
|
+
};
|
2008
|
+
let Query = _Query;
|
1322
2009
|
function cleanParent(data, parent) {
|
1323
2010
|
if (isCursorPaginationOptions(data.pagination)) {
|
1324
|
-
return { ...parent,
|
2011
|
+
return { ...parent, sort: void 0, filter: void 0 };
|
1325
2012
|
}
|
1326
2013
|
return parent;
|
1327
2014
|
}
|
1328
2015
|
|
2016
|
+
const RecordColumnTypes = [
|
2017
|
+
"bool",
|
2018
|
+
"int",
|
2019
|
+
"float",
|
2020
|
+
"string",
|
2021
|
+
"text",
|
2022
|
+
"email",
|
2023
|
+
"multiple",
|
2024
|
+
"link",
|
2025
|
+
"object",
|
2026
|
+
"datetime",
|
2027
|
+
"vector",
|
2028
|
+
"file[]",
|
2029
|
+
"file",
|
2030
|
+
"json"
|
2031
|
+
];
|
1329
2032
|
function isIdentifiable(x) {
|
1330
2033
|
return isObject(x) && isString(x?.id);
|
1331
2034
|
}
|
@@ -1335,11 +2038,33 @@ function isXataRecord(x) {
|
|
1335
2038
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
1336
2039
|
}
|
1337
2040
|
|
2041
|
+
function isValidExpandedColumn(column) {
|
2042
|
+
return isObject(column) && isString(column.name);
|
2043
|
+
}
|
2044
|
+
function isValidSelectableColumns(columns) {
|
2045
|
+
if (!Array.isArray(columns)) {
|
2046
|
+
return false;
|
2047
|
+
}
|
2048
|
+
return columns.every((column) => {
|
2049
|
+
if (typeof column === "string") {
|
2050
|
+
return true;
|
2051
|
+
}
|
2052
|
+
if (typeof column === "object") {
|
2053
|
+
return isValidExpandedColumn(column);
|
2054
|
+
}
|
2055
|
+
return false;
|
2056
|
+
});
|
2057
|
+
}
|
2058
|
+
|
1338
2059
|
function isSortFilterString(value) {
|
1339
2060
|
return isString(value);
|
1340
2061
|
}
|
1341
2062
|
function isSortFilterBase(filter) {
|
1342
|
-
return isObject(filter) && Object.
|
2063
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
2064
|
+
if (key === "*")
|
2065
|
+
return value === "random";
|
2066
|
+
return value === "asc" || value === "desc";
|
2067
|
+
});
|
1343
2068
|
}
|
1344
2069
|
function isSortFilterObject(filter) {
|
1345
2070
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -1380,21 +2105,29 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1380
2105
|
__accessCheck$4(obj, member, "access private method");
|
1381
2106
|
return method;
|
1382
2107
|
};
|
1383
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2108
|
+
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, _transformObjectToApi, transformObjectToApi_fn;
|
2109
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
1384
2110
|
class Repository extends Query {
|
1385
2111
|
}
|
1386
2112
|
class RestRepository extends Query {
|
1387
2113
|
constructor(options) {
|
1388
|
-
super(
|
2114
|
+
super(
|
2115
|
+
null,
|
2116
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
2117
|
+
{}
|
2118
|
+
);
|
1389
2119
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1390
2120
|
__privateAdd$4(this, _insertRecordWithId);
|
1391
|
-
__privateAdd$4(this,
|
2121
|
+
__privateAdd$4(this, _insertRecords);
|
1392
2122
|
__privateAdd$4(this, _updateRecordWithID);
|
2123
|
+
__privateAdd$4(this, _updateRecords);
|
1393
2124
|
__privateAdd$4(this, _upsertRecordWithID);
|
1394
2125
|
__privateAdd$4(this, _deleteRecord);
|
2126
|
+
__privateAdd$4(this, _deleteRecords);
|
1395
2127
|
__privateAdd$4(this, _setCacheQuery);
|
1396
2128
|
__privateAdd$4(this, _getCacheQuery);
|
1397
2129
|
__privateAdd$4(this, _getSchemaTables$1);
|
2130
|
+
__privateAdd$4(this, _transformObjectToApi);
|
1398
2131
|
__privateAdd$4(this, _table, void 0);
|
1399
2132
|
__privateAdd$4(this, _getFetchProps, void 0);
|
1400
2133
|
__privateAdd$4(this, _db, void 0);
|
@@ -1402,41 +2135,45 @@ class RestRepository extends Query {
|
|
1402
2135
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
1403
2136
|
__privateAdd$4(this, _trace, void 0);
|
1404
2137
|
__privateSet$4(this, _table, options.table);
|
1405
|
-
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1406
2138
|
__privateSet$4(this, _db, options.db);
|
1407
2139
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1408
2140
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2141
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
1409
2142
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
1410
2143
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
1411
2144
|
return trace(name, fn, {
|
1412
2145
|
...options2,
|
1413
2146
|
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
2147
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1414
2148
|
[TraceAttributes.VERSION]: VERSION
|
1415
2149
|
});
|
1416
2150
|
});
|
1417
2151
|
}
|
1418
|
-
async create(a, b, c) {
|
2152
|
+
async create(a, b, c, d) {
|
1419
2153
|
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
2154
|
+
const ifVersion = parseIfVersion(b, c, d);
|
1420
2155
|
if (Array.isArray(a)) {
|
1421
2156
|
if (a.length === 0)
|
1422
2157
|
return [];
|
1423
|
-
const
|
1424
|
-
|
2158
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2159
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2160
|
+
const result = await this.read(ids, columns);
|
2161
|
+
return result;
|
1425
2162
|
}
|
1426
2163
|
if (isString(a) && isObject(b)) {
|
1427
2164
|
if (a === "")
|
1428
2165
|
throw new Error("The id can't be empty");
|
1429
|
-
const columns =
|
1430
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
2166
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2167
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
1431
2168
|
}
|
1432
2169
|
if (isObject(a) && isString(a.id)) {
|
1433
2170
|
if (a.id === "")
|
1434
2171
|
throw new Error("The id can't be empty");
|
1435
|
-
const columns =
|
1436
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
2172
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2173
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
1437
2174
|
}
|
1438
2175
|
if (isObject(a)) {
|
1439
|
-
const columns =
|
2176
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
1440
2177
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
1441
2178
|
}
|
1442
2179
|
throw new Error("Invalid arguments for create method");
|
@@ -1444,7 +2181,7 @@ class RestRepository extends Query {
|
|
1444
2181
|
}
|
1445
2182
|
async read(a, b) {
|
1446
2183
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
1447
|
-
const columns =
|
2184
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
1448
2185
|
if (Array.isArray(a)) {
|
1449
2186
|
if (a.length === 0)
|
1450
2187
|
return [];
|
@@ -1458,20 +2195,26 @@ class RestRepository extends Query {
|
|
1458
2195
|
}
|
1459
2196
|
const id = extractId(a);
|
1460
2197
|
if (id) {
|
1461
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1462
2198
|
try {
|
1463
2199
|
const response = await getRecord({
|
1464
2200
|
pathParams: {
|
1465
2201
|
workspace: "{workspaceId}",
|
1466
2202
|
dbBranchName: "{dbBranch}",
|
2203
|
+
region: "{region}",
|
1467
2204
|
tableName: __privateGet$4(this, _table),
|
1468
2205
|
recordId: id
|
1469
2206
|
},
|
1470
2207
|
queryParams: { columns },
|
1471
|
-
...
|
2208
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1472
2209
|
});
|
1473
2210
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1474
|
-
return initObject(
|
2211
|
+
return initObject(
|
2212
|
+
__privateGet$4(this, _db),
|
2213
|
+
schemaTables,
|
2214
|
+
__privateGet$4(this, _table),
|
2215
|
+
response,
|
2216
|
+
columns
|
2217
|
+
);
|
1475
2218
|
} catch (e) {
|
1476
2219
|
if (isObject(e) && e.status === 404) {
|
1477
2220
|
return null;
|
@@ -1482,59 +2225,160 @@ class RestRepository extends Query {
|
|
1482
2225
|
return null;
|
1483
2226
|
});
|
1484
2227
|
}
|
1485
|
-
async
|
2228
|
+
async readOrThrow(a, b) {
|
2229
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
2230
|
+
const result = await this.read(a, b);
|
2231
|
+
if (Array.isArray(result)) {
|
2232
|
+
const missingIds = compact(
|
2233
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2234
|
+
);
|
2235
|
+
if (missingIds.length > 0) {
|
2236
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2237
|
+
}
|
2238
|
+
return result;
|
2239
|
+
}
|
2240
|
+
if (result === null) {
|
2241
|
+
const id = extractId(a) ?? "unknown";
|
2242
|
+
throw new Error(`Record with id ${id} not found`);
|
2243
|
+
}
|
2244
|
+
return result;
|
2245
|
+
});
|
2246
|
+
}
|
2247
|
+
async update(a, b, c, d) {
|
1486
2248
|
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
2249
|
+
const ifVersion = parseIfVersion(b, c, d);
|
1487
2250
|
if (Array.isArray(a)) {
|
1488
2251
|
if (a.length === 0)
|
1489
2252
|
return [];
|
1490
|
-
|
1491
|
-
|
2253
|
+
const existing = await this.read(a, ["id"]);
|
2254
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
2255
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2256
|
+
ifVersion,
|
2257
|
+
upsert: false
|
2258
|
+
});
|
2259
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2260
|
+
const result = await this.read(a, columns);
|
2261
|
+
return result;
|
2262
|
+
}
|
2263
|
+
try {
|
2264
|
+
if (isString(a) && isObject(b)) {
|
2265
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2266
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2267
|
+
}
|
2268
|
+
if (isObject(a) && isString(a.id)) {
|
2269
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2270
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
1492
2271
|
}
|
1493
|
-
|
1494
|
-
|
2272
|
+
} catch (error) {
|
2273
|
+
if (error.status === 422)
|
2274
|
+
return null;
|
2275
|
+
throw error;
|
1495
2276
|
}
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
2277
|
+
throw new Error("Invalid arguments for update method");
|
2278
|
+
});
|
2279
|
+
}
|
2280
|
+
async updateOrThrow(a, b, c, d) {
|
2281
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
2282
|
+
const result = await this.update(a, b, c, d);
|
2283
|
+
if (Array.isArray(result)) {
|
2284
|
+
const missingIds = compact(
|
2285
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2286
|
+
);
|
2287
|
+
if (missingIds.length > 0) {
|
2288
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2289
|
+
}
|
2290
|
+
return result;
|
1499
2291
|
}
|
1500
|
-
if (
|
1501
|
-
const
|
1502
|
-
|
2292
|
+
if (result === null) {
|
2293
|
+
const id = extractId(a) ?? "unknown";
|
2294
|
+
throw new Error(`Record with id ${id} not found`);
|
1503
2295
|
}
|
1504
|
-
|
2296
|
+
return result;
|
1505
2297
|
});
|
1506
2298
|
}
|
1507
|
-
async createOrUpdate(a, b, c) {
|
2299
|
+
async createOrUpdate(a, b, c, d) {
|
1508
2300
|
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
2301
|
+
const ifVersion = parseIfVersion(b, c, d);
|
1509
2302
|
if (Array.isArray(a)) {
|
1510
2303
|
if (a.length === 0)
|
1511
2304
|
return [];
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
2305
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
2306
|
+
ifVersion,
|
2307
|
+
upsert: true
|
2308
|
+
});
|
2309
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2310
|
+
const result = await this.read(a, columns);
|
2311
|
+
return result;
|
1517
2312
|
}
|
1518
2313
|
if (isString(a) && isObject(b)) {
|
1519
|
-
|
1520
|
-
|
2314
|
+
if (a === "")
|
2315
|
+
throw new Error("The id can't be empty");
|
2316
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2317
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
1521
2318
|
}
|
1522
2319
|
if (isObject(a) && isString(a.id)) {
|
1523
|
-
|
1524
|
-
|
2320
|
+
if (a.id === "")
|
2321
|
+
throw new Error("The id can't be empty");
|
2322
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2323
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2324
|
+
}
|
2325
|
+
if (!isDefined(a) && isObject(b)) {
|
2326
|
+
return await this.create(b, c);
|
2327
|
+
}
|
2328
|
+
if (isObject(a) && !isDefined(a.id)) {
|
2329
|
+
return await this.create(a, b);
|
1525
2330
|
}
|
1526
2331
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1527
2332
|
});
|
1528
2333
|
}
|
2334
|
+
async createOrReplace(a, b, c, d) {
|
2335
|
+
return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
|
2336
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2337
|
+
if (Array.isArray(a)) {
|
2338
|
+
if (a.length === 0)
|
2339
|
+
return [];
|
2340
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2341
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2342
|
+
const result = await this.read(ids, columns);
|
2343
|
+
return result;
|
2344
|
+
}
|
2345
|
+
if (isString(a) && isObject(b)) {
|
2346
|
+
if (a === "")
|
2347
|
+
throw new Error("The id can't be empty");
|
2348
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2349
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2350
|
+
}
|
2351
|
+
if (isObject(a) && isString(a.id)) {
|
2352
|
+
if (a.id === "")
|
2353
|
+
throw new Error("The id can't be empty");
|
2354
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2355
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
2356
|
+
}
|
2357
|
+
if (!isDefined(a) && isObject(b)) {
|
2358
|
+
return await this.create(b, c);
|
2359
|
+
}
|
2360
|
+
if (isObject(a) && !isDefined(a.id)) {
|
2361
|
+
return await this.create(a, b);
|
2362
|
+
}
|
2363
|
+
throw new Error("Invalid arguments for createOrReplace method");
|
2364
|
+
});
|
2365
|
+
}
|
1529
2366
|
async delete(a, b) {
|
1530
2367
|
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1531
2368
|
if (Array.isArray(a)) {
|
1532
2369
|
if (a.length === 0)
|
1533
2370
|
return [];
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
2371
|
+
const ids = a.map((o) => {
|
2372
|
+
if (isString(o))
|
2373
|
+
return o;
|
2374
|
+
if (isString(o.id))
|
2375
|
+
return o.id;
|
2376
|
+
throw new Error("Invalid arguments for delete method");
|
2377
|
+
});
|
2378
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2379
|
+
const result = await this.read(a, columns);
|
2380
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2381
|
+
return result;
|
1538
2382
|
}
|
1539
2383
|
if (isString(a)) {
|
1540
2384
|
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
@@ -1545,23 +2389,90 @@ class RestRepository extends Query {
|
|
1545
2389
|
throw new Error("Invalid arguments for delete method");
|
1546
2390
|
});
|
1547
2391
|
}
|
2392
|
+
async deleteOrThrow(a, b) {
|
2393
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
2394
|
+
const result = await this.delete(a, b);
|
2395
|
+
if (Array.isArray(result)) {
|
2396
|
+
const missingIds = compact(
|
2397
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2398
|
+
);
|
2399
|
+
if (missingIds.length > 0) {
|
2400
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2401
|
+
}
|
2402
|
+
return result;
|
2403
|
+
} else if (result === null) {
|
2404
|
+
const id = extractId(a) ?? "unknown";
|
2405
|
+
throw new Error(`Record with id ${id} not found`);
|
2406
|
+
}
|
2407
|
+
return result;
|
2408
|
+
});
|
2409
|
+
}
|
1548
2410
|
async search(query, options = {}) {
|
1549
2411
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1550
|
-
const
|
1551
|
-
|
1552
|
-
|
2412
|
+
const { records, totalCount } = await searchTable({
|
2413
|
+
pathParams: {
|
2414
|
+
workspace: "{workspaceId}",
|
2415
|
+
dbBranchName: "{dbBranch}",
|
2416
|
+
region: "{region}",
|
2417
|
+
tableName: __privateGet$4(this, _table)
|
2418
|
+
},
|
1553
2419
|
body: {
|
1554
2420
|
query,
|
1555
2421
|
fuzziness: options.fuzziness,
|
1556
2422
|
prefix: options.prefix,
|
1557
2423
|
highlight: options.highlight,
|
1558
2424
|
filter: options.filter,
|
1559
|
-
boosters: options.boosters
|
2425
|
+
boosters: options.boosters,
|
2426
|
+
page: options.page,
|
2427
|
+
target: options.target
|
2428
|
+
},
|
2429
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2430
|
+
});
|
2431
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2432
|
+
return {
|
2433
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
2434
|
+
totalCount
|
2435
|
+
};
|
2436
|
+
});
|
2437
|
+
}
|
2438
|
+
async vectorSearch(column, query, options) {
|
2439
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
2440
|
+
const { records, totalCount } = await vectorSearchTable({
|
2441
|
+
pathParams: {
|
2442
|
+
workspace: "{workspaceId}",
|
2443
|
+
dbBranchName: "{dbBranch}",
|
2444
|
+
region: "{region}",
|
2445
|
+
tableName: __privateGet$4(this, _table)
|
1560
2446
|
},
|
1561
|
-
|
2447
|
+
body: {
|
2448
|
+
column,
|
2449
|
+
queryVector: query,
|
2450
|
+
similarityFunction: options?.similarityFunction,
|
2451
|
+
size: options?.size,
|
2452
|
+
filter: options?.filter
|
2453
|
+
},
|
2454
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1562
2455
|
});
|
1563
2456
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1564
|
-
return
|
2457
|
+
return {
|
2458
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
2459
|
+
totalCount
|
2460
|
+
};
|
2461
|
+
});
|
2462
|
+
}
|
2463
|
+
async aggregate(aggs, filter) {
|
2464
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2465
|
+
const result = await aggregateTable({
|
2466
|
+
pathParams: {
|
2467
|
+
workspace: "{workspaceId}",
|
2468
|
+
dbBranchName: "{dbBranch}",
|
2469
|
+
region: "{region}",
|
2470
|
+
tableName: __privateGet$4(this, _table)
|
2471
|
+
},
|
2472
|
+
body: { aggs, filter },
|
2473
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2474
|
+
});
|
2475
|
+
return result;
|
1565
2476
|
});
|
1566
2477
|
}
|
1567
2478
|
async query(query) {
|
@@ -1570,24 +2481,100 @@ class RestRepository extends Query {
|
|
1570
2481
|
if (cacheQuery)
|
1571
2482
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1572
2483
|
const data = query.getQueryOptions();
|
1573
|
-
const body = {
|
1574
|
-
filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
|
1575
|
-
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1576
|
-
page: data.pagination,
|
1577
|
-
columns: data.columns
|
1578
|
-
};
|
1579
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1580
2484
|
const { meta, records: objects } = await queryTable({
|
1581
|
-
pathParams: {
|
1582
|
-
|
1583
|
-
|
2485
|
+
pathParams: {
|
2486
|
+
workspace: "{workspaceId}",
|
2487
|
+
dbBranchName: "{dbBranch}",
|
2488
|
+
region: "{region}",
|
2489
|
+
tableName: __privateGet$4(this, _table)
|
2490
|
+
},
|
2491
|
+
body: {
|
2492
|
+
filter: cleanFilter(data.filter),
|
2493
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2494
|
+
page: data.pagination,
|
2495
|
+
columns: data.columns ?? ["*"],
|
2496
|
+
consistency: data.consistency
|
2497
|
+
},
|
2498
|
+
fetchOptions: data.fetchOptions,
|
2499
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1584
2500
|
});
|
1585
2501
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1586
|
-
const records = objects.map(
|
2502
|
+
const records = objects.map(
|
2503
|
+
(record) => initObject(
|
2504
|
+
__privateGet$4(this, _db),
|
2505
|
+
schemaTables,
|
2506
|
+
__privateGet$4(this, _table),
|
2507
|
+
record,
|
2508
|
+
data.columns ?? ["*"]
|
2509
|
+
)
|
2510
|
+
);
|
1587
2511
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1588
2512
|
return new Page(query, meta, records);
|
1589
2513
|
});
|
1590
2514
|
}
|
2515
|
+
async summarizeTable(query, summaries, summariesFilter) {
|
2516
|
+
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2517
|
+
const data = query.getQueryOptions();
|
2518
|
+
const result = await summarizeTable({
|
2519
|
+
pathParams: {
|
2520
|
+
workspace: "{workspaceId}",
|
2521
|
+
dbBranchName: "{dbBranch}",
|
2522
|
+
region: "{region}",
|
2523
|
+
tableName: __privateGet$4(this, _table)
|
2524
|
+
},
|
2525
|
+
body: {
|
2526
|
+
filter: cleanFilter(data.filter),
|
2527
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2528
|
+
columns: data.columns,
|
2529
|
+
consistency: data.consistency,
|
2530
|
+
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2531
|
+
summaries,
|
2532
|
+
summariesFilter
|
2533
|
+
},
|
2534
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2535
|
+
});
|
2536
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2537
|
+
return {
|
2538
|
+
...result,
|
2539
|
+
summaries: result.summaries.map(
|
2540
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
2541
|
+
)
|
2542
|
+
};
|
2543
|
+
});
|
2544
|
+
}
|
2545
|
+
ask(question, options) {
|
2546
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
2547
|
+
const params = {
|
2548
|
+
pathParams: {
|
2549
|
+
workspace: "{workspaceId}",
|
2550
|
+
dbBranchName: "{dbBranch}",
|
2551
|
+
region: "{region}",
|
2552
|
+
tableName: __privateGet$4(this, _table),
|
2553
|
+
sessionId: options?.sessionId
|
2554
|
+
},
|
2555
|
+
body: {
|
2556
|
+
...questionParam,
|
2557
|
+
rules: options?.rules,
|
2558
|
+
searchType: options?.searchType,
|
2559
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
2560
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
2561
|
+
},
|
2562
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2563
|
+
};
|
2564
|
+
if (options?.onMessage) {
|
2565
|
+
fetchSSERequest({
|
2566
|
+
endpoint: "dataPlane",
|
2567
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
2568
|
+
method: "POST",
|
2569
|
+
onMessage: (message) => {
|
2570
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
2571
|
+
},
|
2572
|
+
...params
|
2573
|
+
});
|
2574
|
+
} else {
|
2575
|
+
return askTableSession(params);
|
2576
|
+
}
|
2577
|
+
}
|
1591
2578
|
}
|
1592
2579
|
_table = new WeakMap();
|
1593
2580
|
_getFetchProps = new WeakMap();
|
@@ -1597,68 +2584,89 @@ _schemaTables$2 = new WeakMap();
|
|
1597
2584
|
_trace = new WeakMap();
|
1598
2585
|
_insertRecordWithoutId = new WeakSet();
|
1599
2586
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1600
|
-
const
|
1601
|
-
const record = transformObjectLinks(object);
|
2587
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
1602
2588
|
const response = await insertRecord({
|
1603
2589
|
pathParams: {
|
1604
2590
|
workspace: "{workspaceId}",
|
1605
2591
|
dbBranchName: "{dbBranch}",
|
2592
|
+
region: "{region}",
|
1606
2593
|
tableName: __privateGet$4(this, _table)
|
1607
2594
|
},
|
1608
2595
|
queryParams: { columns },
|
1609
2596
|
body: record,
|
1610
|
-
...
|
2597
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1611
2598
|
});
|
1612
2599
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1613
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2600
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1614
2601
|
};
|
1615
2602
|
_insertRecordWithId = new WeakSet();
|
1616
|
-
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
1617
|
-
|
1618
|
-
|
2603
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2604
|
+
if (!recordId)
|
2605
|
+
return null;
|
2606
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
1619
2607
|
const response = await insertRecordWithID({
|
1620
2608
|
pathParams: {
|
1621
2609
|
workspace: "{workspaceId}",
|
1622
2610
|
dbBranchName: "{dbBranch}",
|
2611
|
+
region: "{region}",
|
1623
2612
|
tableName: __privateGet$4(this, _table),
|
1624
2613
|
recordId
|
1625
2614
|
},
|
1626
2615
|
body: record,
|
1627
|
-
queryParams: { createOnly
|
1628
|
-
...
|
2616
|
+
queryParams: { createOnly, columns, ifVersion },
|
2617
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1629
2618
|
});
|
1630
2619
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1631
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1632
|
-
};
|
1633
|
-
|
1634
|
-
|
1635
|
-
const
|
1636
|
-
|
1637
|
-
|
1638
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1639
|
-
queryParams: { columns },
|
1640
|
-
body: { records },
|
1641
|
-
...fetchProps
|
2620
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2621
|
+
};
|
2622
|
+
_insertRecords = new WeakSet();
|
2623
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2624
|
+
const operations = await promiseMap(objects, async (object) => {
|
2625
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2626
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
1642
2627
|
});
|
1643
|
-
|
1644
|
-
|
2628
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2629
|
+
const ids = [];
|
2630
|
+
for (const operations2 of chunkedOperations) {
|
2631
|
+
const { results } = await branchTransaction({
|
2632
|
+
pathParams: {
|
2633
|
+
workspace: "{workspaceId}",
|
2634
|
+
dbBranchName: "{dbBranch}",
|
2635
|
+
region: "{region}"
|
2636
|
+
},
|
2637
|
+
body: { operations: operations2 },
|
2638
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2639
|
+
});
|
2640
|
+
for (const result of results) {
|
2641
|
+
if (result.operation === "insert") {
|
2642
|
+
ids.push(result.id);
|
2643
|
+
} else {
|
2644
|
+
ids.push(null);
|
2645
|
+
}
|
2646
|
+
}
|
1645
2647
|
}
|
1646
|
-
|
1647
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
2648
|
+
return ids;
|
1648
2649
|
};
|
1649
2650
|
_updateRecordWithID = new WeakSet();
|
1650
|
-
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1651
|
-
|
1652
|
-
|
2651
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2652
|
+
if (!recordId)
|
2653
|
+
return null;
|
2654
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
1653
2655
|
try {
|
1654
2656
|
const response = await updateRecordWithID({
|
1655
|
-
pathParams: {
|
1656
|
-
|
2657
|
+
pathParams: {
|
2658
|
+
workspace: "{workspaceId}",
|
2659
|
+
dbBranchName: "{dbBranch}",
|
2660
|
+
region: "{region}",
|
2661
|
+
tableName: __privateGet$4(this, _table),
|
2662
|
+
recordId
|
2663
|
+
},
|
2664
|
+
queryParams: { columns, ifVersion },
|
1657
2665
|
body: record,
|
1658
|
-
...
|
2666
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1659
2667
|
});
|
1660
2668
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1661
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2669
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1662
2670
|
} catch (e) {
|
1663
2671
|
if (isObject(e) && e.status === 404) {
|
1664
2672
|
return null;
|
@@ -1666,29 +2674,71 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1666
2674
|
throw e;
|
1667
2675
|
}
|
1668
2676
|
};
|
2677
|
+
_updateRecords = new WeakSet();
|
2678
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2679
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
2680
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2681
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
2682
|
+
});
|
2683
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2684
|
+
const ids = [];
|
2685
|
+
for (const operations2 of chunkedOperations) {
|
2686
|
+
const { results } = await branchTransaction({
|
2687
|
+
pathParams: {
|
2688
|
+
workspace: "{workspaceId}",
|
2689
|
+
dbBranchName: "{dbBranch}",
|
2690
|
+
region: "{region}"
|
2691
|
+
},
|
2692
|
+
body: { operations: operations2 },
|
2693
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2694
|
+
});
|
2695
|
+
for (const result of results) {
|
2696
|
+
if (result.operation === "update") {
|
2697
|
+
ids.push(result.id);
|
2698
|
+
} else {
|
2699
|
+
ids.push(null);
|
2700
|
+
}
|
2701
|
+
}
|
2702
|
+
}
|
2703
|
+
return ids;
|
2704
|
+
};
|
1669
2705
|
_upsertRecordWithID = new WeakSet();
|
1670
|
-
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1671
|
-
|
2706
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2707
|
+
if (!recordId)
|
2708
|
+
return null;
|
1672
2709
|
const response = await upsertRecordWithID({
|
1673
|
-
pathParams: {
|
1674
|
-
|
2710
|
+
pathParams: {
|
2711
|
+
workspace: "{workspaceId}",
|
2712
|
+
dbBranchName: "{dbBranch}",
|
2713
|
+
region: "{region}",
|
2714
|
+
tableName: __privateGet$4(this, _table),
|
2715
|
+
recordId
|
2716
|
+
},
|
2717
|
+
queryParams: { columns, ifVersion },
|
1675
2718
|
body: object,
|
1676
|
-
...
|
2719
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1677
2720
|
});
|
1678
2721
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1679
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2722
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1680
2723
|
};
|
1681
2724
|
_deleteRecord = new WeakSet();
|
1682
2725
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1683
|
-
|
2726
|
+
if (!recordId)
|
2727
|
+
return null;
|
1684
2728
|
try {
|
1685
2729
|
const response = await deleteRecord({
|
1686
|
-
pathParams: {
|
2730
|
+
pathParams: {
|
2731
|
+
workspace: "{workspaceId}",
|
2732
|
+
dbBranchName: "{dbBranch}",
|
2733
|
+
region: "{region}",
|
2734
|
+
tableName: __privateGet$4(this, _table),
|
2735
|
+
recordId
|
2736
|
+
},
|
1687
2737
|
queryParams: { columns },
|
1688
|
-
...
|
2738
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1689
2739
|
});
|
1690
2740
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1691
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2741
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1692
2742
|
} catch (e) {
|
1693
2743
|
if (isObject(e) && e.status === 404) {
|
1694
2744
|
return null;
|
@@ -1696,17 +2746,36 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
1696
2746
|
throw e;
|
1697
2747
|
}
|
1698
2748
|
};
|
2749
|
+
_deleteRecords = new WeakSet();
|
2750
|
+
deleteRecords_fn = async function(recordIds) {
|
2751
|
+
const chunkedOperations = chunk(
|
2752
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2753
|
+
BULK_OPERATION_MAX_SIZE
|
2754
|
+
);
|
2755
|
+
for (const operations of chunkedOperations) {
|
2756
|
+
await branchTransaction({
|
2757
|
+
pathParams: {
|
2758
|
+
workspace: "{workspaceId}",
|
2759
|
+
dbBranchName: "{dbBranch}",
|
2760
|
+
region: "{region}"
|
2761
|
+
},
|
2762
|
+
body: { operations },
|
2763
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2764
|
+
});
|
2765
|
+
}
|
2766
|
+
};
|
1699
2767
|
_setCacheQuery = new WeakSet();
|
1700
2768
|
setCacheQuery_fn = async function(query, meta, records) {
|
1701
|
-
await __privateGet$4(this, _cache)
|
2769
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
1702
2770
|
};
|
1703
2771
|
_getCacheQuery = new WeakSet();
|
1704
2772
|
getCacheQuery_fn = async function(query) {
|
1705
2773
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
1706
|
-
const result = await __privateGet$4(this, _cache)
|
2774
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
1707
2775
|
if (!result)
|
1708
2776
|
return null;
|
1709
|
-
const
|
2777
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
2778
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
1710
2779
|
if (ttl < 0)
|
1711
2780
|
return null;
|
1712
2781
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -1716,37 +2785,66 @@ _getSchemaTables$1 = new WeakSet();
|
|
1716
2785
|
getSchemaTables_fn$1 = async function() {
|
1717
2786
|
if (__privateGet$4(this, _schemaTables$2))
|
1718
2787
|
return __privateGet$4(this, _schemaTables$2);
|
1719
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1720
2788
|
const { schema } = await getBranchDetails({
|
1721
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1722
|
-
...
|
2789
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2790
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
1723
2791
|
});
|
1724
2792
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
1725
2793
|
return schema.tables;
|
1726
2794
|
};
|
1727
|
-
|
1728
|
-
|
2795
|
+
_transformObjectToApi = new WeakSet();
|
2796
|
+
transformObjectToApi_fn = async function(object) {
|
2797
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2798
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
2799
|
+
if (!schema)
|
2800
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
2801
|
+
const result = {};
|
2802
|
+
for (const [key, value] of Object.entries(object)) {
|
1729
2803
|
if (key === "xata")
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
2804
|
+
continue;
|
2805
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
2806
|
+
switch (type) {
|
2807
|
+
case "link": {
|
2808
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
2809
|
+
break;
|
2810
|
+
}
|
2811
|
+
case "datetime": {
|
2812
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
2813
|
+
break;
|
2814
|
+
}
|
2815
|
+
case `file`:
|
2816
|
+
result[key] = await parseInputFileEntry(value);
|
2817
|
+
break;
|
2818
|
+
case "file[]":
|
2819
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
2820
|
+
break;
|
2821
|
+
case "json":
|
2822
|
+
result[key] = stringifyJson(value);
|
2823
|
+
break;
|
2824
|
+
default:
|
2825
|
+
result[key] = value;
|
2826
|
+
}
|
2827
|
+
}
|
2828
|
+
return result;
|
1733
2829
|
};
|
1734
|
-
const initObject = (db, schemaTables, table, object) => {
|
1735
|
-
const
|
2830
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2831
|
+
const data = {};
|
1736
2832
|
const { xata, ...rest } = object ?? {};
|
1737
|
-
Object.assign(
|
2833
|
+
Object.assign(data, rest);
|
1738
2834
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1739
2835
|
if (!columns)
|
1740
2836
|
console.error(`Table ${table} not found in schema`);
|
1741
2837
|
for (const column of columns ?? []) {
|
1742
|
-
|
2838
|
+
if (!isValidColumn(selectedColumns, column))
|
2839
|
+
continue;
|
2840
|
+
const value = data[column.name];
|
1743
2841
|
switch (column.type) {
|
1744
2842
|
case "datetime": {
|
1745
|
-
const date = value !== void 0 ? new Date(value) :
|
1746
|
-
if (date && isNaN(date.getTime())) {
|
2843
|
+
const date = value !== void 0 ? new Date(value) : null;
|
2844
|
+
if (date !== null && isNaN(date.getTime())) {
|
1747
2845
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1748
|
-
} else
|
1749
|
-
|
2846
|
+
} else {
|
2847
|
+
data[column.name] = date;
|
1750
2848
|
}
|
1751
2849
|
break;
|
1752
2850
|
}
|
@@ -1755,33 +2853,81 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1755
2853
|
if (!linkTable) {
|
1756
2854
|
console.error(`Failed to parse link for field ${column.name}`);
|
1757
2855
|
} else if (isObject(value)) {
|
1758
|
-
|
2856
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2857
|
+
if (item === column.name) {
|
2858
|
+
return [...acc, "*"];
|
2859
|
+
}
|
2860
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2861
|
+
const [, ...path] = item.split(".");
|
2862
|
+
return [...acc, path.join(".")];
|
2863
|
+
}
|
2864
|
+
return acc;
|
2865
|
+
}, []);
|
2866
|
+
data[column.name] = initObject(
|
2867
|
+
db,
|
2868
|
+
schemaTables,
|
2869
|
+
linkTable,
|
2870
|
+
value,
|
2871
|
+
selectedLinkColumns
|
2872
|
+
);
|
2873
|
+
} else {
|
2874
|
+
data[column.name] = null;
|
1759
2875
|
}
|
1760
2876
|
break;
|
1761
2877
|
}
|
2878
|
+
case "file":
|
2879
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
2880
|
+
break;
|
2881
|
+
case "file[]":
|
2882
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
2883
|
+
break;
|
2884
|
+
case "json":
|
2885
|
+
data[column.name] = parseJson(value);
|
2886
|
+
break;
|
2887
|
+
default:
|
2888
|
+
data[column.name] = value ?? null;
|
2889
|
+
if (column.notNull === true && value === null) {
|
2890
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2891
|
+
}
|
2892
|
+
break;
|
1762
2893
|
}
|
1763
2894
|
}
|
1764
|
-
|
1765
|
-
|
2895
|
+
const record = { ...data };
|
2896
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2897
|
+
record.read = function(columns2) {
|
2898
|
+
return db[table].read(record["id"], columns2);
|
1766
2899
|
};
|
1767
|
-
|
1768
|
-
|
2900
|
+
record.update = function(data2, b, c) {
|
2901
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2902
|
+
const ifVersion = parseIfVersion(b, c);
|
2903
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
1769
2904
|
};
|
1770
|
-
|
1771
|
-
|
2905
|
+
record.replace = function(data2, b, c) {
|
2906
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2907
|
+
const ifVersion = parseIfVersion(b, c);
|
2908
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
1772
2909
|
};
|
1773
|
-
|
1774
|
-
return
|
2910
|
+
record.delete = function() {
|
2911
|
+
return db[table].delete(record["id"]);
|
1775
2912
|
};
|
1776
|
-
|
1777
|
-
Object.
|
2913
|
+
if (metadata !== void 0) {
|
2914
|
+
record.xata = Object.freeze(metadata);
|
1778
2915
|
}
|
1779
|
-
|
1780
|
-
|
2916
|
+
record.getMetadata = function() {
|
2917
|
+
return record.xata;
|
2918
|
+
};
|
2919
|
+
record.toSerializable = function() {
|
2920
|
+
return JSON.parse(JSON.stringify(record));
|
2921
|
+
};
|
2922
|
+
record.toString = function() {
|
2923
|
+
return JSON.stringify(record);
|
2924
|
+
};
|
2925
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2926
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
2927
|
+
}
|
2928
|
+
Object.freeze(record);
|
2929
|
+
return record;
|
1781
2930
|
};
|
1782
|
-
function isResponseWithRecords(value) {
|
1783
|
-
return isObject(value) && Array.isArray(value.records);
|
1784
|
-
}
|
1785
2931
|
function extractId(value) {
|
1786
2932
|
if (isString(value))
|
1787
2933
|
return value;
|
@@ -1789,6 +2935,19 @@ function extractId(value) {
|
|
1789
2935
|
return value.id;
|
1790
2936
|
return void 0;
|
1791
2937
|
}
|
2938
|
+
function isValidColumn(columns, column) {
|
2939
|
+
if (columns.includes("*"))
|
2940
|
+
return true;
|
2941
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
2942
|
+
}
|
2943
|
+
function parseIfVersion(...args) {
|
2944
|
+
for (const arg of args) {
|
2945
|
+
if (isObject(arg) && isNumber(arg.ifVersion)) {
|
2946
|
+
return arg.ifVersion;
|
2947
|
+
}
|
2948
|
+
}
|
2949
|
+
return void 0;
|
2950
|
+
}
|
1792
2951
|
|
1793
2952
|
var __accessCheck$3 = (obj, member, msg) => {
|
1794
2953
|
if (!member.has(obj))
|
@@ -1856,10 +3015,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
1856
3015
|
const startsWith = (value) => ({ $startsWith: value });
|
1857
3016
|
const endsWith = (value) => ({ $endsWith: value });
|
1858
3017
|
const pattern = (value) => ({ $pattern: value });
|
3018
|
+
const iPattern = (value) => ({ $iPattern: value });
|
1859
3019
|
const is = (value) => ({ $is: value });
|
1860
3020
|
const equals = is;
|
1861
3021
|
const isNot = (value) => ({ $isNot: value });
|
1862
3022
|
const contains = (value) => ({ $contains: value });
|
3023
|
+
const iContains = (value) => ({ $iContains: value });
|
1863
3024
|
const includes = (value) => ({ $includes: value });
|
1864
3025
|
const includesAll = (value) => ({ $includesAll: value });
|
1865
3026
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -1915,6 +3076,80 @@ class SchemaPlugin extends XataPlugin {
|
|
1915
3076
|
_tables = new WeakMap();
|
1916
3077
|
_schemaTables$1 = new WeakMap();
|
1917
3078
|
|
3079
|
+
class FilesPlugin extends XataPlugin {
|
3080
|
+
build(pluginOptions) {
|
3081
|
+
return {
|
3082
|
+
download: async (location) => {
|
3083
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3084
|
+
return await getFileItem({
|
3085
|
+
pathParams: {
|
3086
|
+
workspace: "{workspaceId}",
|
3087
|
+
dbBranchName: "{dbBranch}",
|
3088
|
+
region: "{region}",
|
3089
|
+
tableName: table ?? "",
|
3090
|
+
recordId: record ?? "",
|
3091
|
+
columnName: column ?? "",
|
3092
|
+
fileId
|
3093
|
+
},
|
3094
|
+
...pluginOptions,
|
3095
|
+
rawResponse: true
|
3096
|
+
});
|
3097
|
+
},
|
3098
|
+
upload: async (location, file, options) => {
|
3099
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3100
|
+
const resolvedFile = await file;
|
3101
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
3102
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
3103
|
+
return await putFileItem({
|
3104
|
+
...pluginOptions,
|
3105
|
+
pathParams: {
|
3106
|
+
workspace: "{workspaceId}",
|
3107
|
+
dbBranchName: "{dbBranch}",
|
3108
|
+
region: "{region}",
|
3109
|
+
tableName: table ?? "",
|
3110
|
+
recordId: record ?? "",
|
3111
|
+
columnName: column ?? "",
|
3112
|
+
fileId
|
3113
|
+
},
|
3114
|
+
body,
|
3115
|
+
headers: { "Content-Type": contentType }
|
3116
|
+
});
|
3117
|
+
},
|
3118
|
+
delete: async (location) => {
|
3119
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
3120
|
+
return await deleteFileItem({
|
3121
|
+
pathParams: {
|
3122
|
+
workspace: "{workspaceId}",
|
3123
|
+
dbBranchName: "{dbBranch}",
|
3124
|
+
region: "{region}",
|
3125
|
+
tableName: table ?? "",
|
3126
|
+
recordId: record ?? "",
|
3127
|
+
columnName: column ?? "",
|
3128
|
+
fileId
|
3129
|
+
},
|
3130
|
+
...pluginOptions
|
3131
|
+
});
|
3132
|
+
}
|
3133
|
+
};
|
3134
|
+
}
|
3135
|
+
}
|
3136
|
+
function getContentType(file) {
|
3137
|
+
if (typeof file === "string") {
|
3138
|
+
return "text/plain";
|
3139
|
+
}
|
3140
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
3141
|
+
return file.mediaType;
|
3142
|
+
}
|
3143
|
+
if (isBlob(file)) {
|
3144
|
+
return file.type;
|
3145
|
+
}
|
3146
|
+
try {
|
3147
|
+
return file.type;
|
3148
|
+
} catch (e) {
|
3149
|
+
}
|
3150
|
+
return "application/octet-stream";
|
3151
|
+
}
|
3152
|
+
|
1918
3153
|
var __accessCheck$1 = (obj, member, msg) => {
|
1919
3154
|
if (!member.has(obj))
|
1920
3155
|
throw TypeError("Cannot " + msg);
|
@@ -1947,133 +3182,141 @@ class SearchPlugin extends XataPlugin {
|
|
1947
3182
|
__privateAdd$1(this, _schemaTables, void 0);
|
1948
3183
|
__privateSet$1(this, _schemaTables, schemaTables);
|
1949
3184
|
}
|
1950
|
-
build(
|
3185
|
+
build(pluginOptions) {
|
1951
3186
|
return {
|
1952
3187
|
all: async (query, options = {}) => {
|
1953
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
1954
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
1955
|
-
return
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
3188
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3189
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3190
|
+
return {
|
3191
|
+
totalCount,
|
3192
|
+
records: records.map((record) => {
|
3193
|
+
const { table = "orphan" } = record.xata;
|
3194
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
3195
|
+
})
|
3196
|
+
};
|
1959
3197
|
},
|
1960
3198
|
byTable: async (query, options = {}) => {
|
1961
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
1962
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
1963
|
-
|
3199
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
3200
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
3201
|
+
const records = rawRecords.reduce((acc, record) => {
|
1964
3202
|
const { table = "orphan" } = record.xata;
|
1965
3203
|
const items = acc[table] ?? [];
|
1966
|
-
const item = initObject(this.db, schemaTables, table, record);
|
3204
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1967
3205
|
return { ...acc, [table]: [...items, item] };
|
1968
3206
|
}, {});
|
3207
|
+
return { totalCount, records };
|
1969
3208
|
}
|
1970
3209
|
};
|
1971
3210
|
}
|
1972
3211
|
}
|
1973
3212
|
_schemaTables = new WeakMap();
|
1974
3213
|
_search = new WeakSet();
|
1975
|
-
search_fn = async function(query, options,
|
1976
|
-
const
|
1977
|
-
const {
|
1978
|
-
|
1979
|
-
|
1980
|
-
body: { tables, query, fuzziness, prefix, highlight },
|
1981
|
-
...
|
3214
|
+
search_fn = async function(query, options, pluginOptions) {
|
3215
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3216
|
+
const { records, totalCount } = await searchBranch({
|
3217
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3218
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3219
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
3220
|
+
...pluginOptions
|
1982
3221
|
});
|
1983
|
-
return records;
|
3222
|
+
return { records, totalCount };
|
1984
3223
|
};
|
1985
3224
|
_getSchemaTables = new WeakSet();
|
1986
|
-
getSchemaTables_fn = async function(
|
3225
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
1987
3226
|
if (__privateGet$1(this, _schemaTables))
|
1988
3227
|
return __privateGet$1(this, _schemaTables);
|
1989
|
-
const fetchProps = await getFetchProps();
|
1990
3228
|
const { schema } = await getBranchDetails({
|
1991
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1992
|
-
...
|
3229
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3230
|
+
...pluginOptions
|
1993
3231
|
});
|
1994
3232
|
__privateSet$1(this, _schemaTables, schema.tables);
|
1995
3233
|
return schema.tables;
|
1996
3234
|
};
|
1997
3235
|
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
}
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
}
|
2017
|
-
async function resolveXataBranch(gitBranch, options) {
|
2018
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2019
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2020
|
-
if (!databaseURL)
|
2021
|
-
throw new Error(
|
2022
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2023
|
-
);
|
2024
|
-
if (!apiKey)
|
2025
|
-
throw new Error(
|
2026
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2027
|
-
);
|
2028
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
2029
|
-
const [workspace] = host.split(".");
|
2030
|
-
const { fallbackBranch } = getEnvironment();
|
2031
|
-
const { branch } = await resolveBranch({
|
2032
|
-
apiKey,
|
2033
|
-
apiUrl: databaseURL,
|
2034
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2035
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
2036
|
-
pathParams: { dbName, workspace },
|
2037
|
-
queryParams: { gitBranch, fallbackBranch },
|
2038
|
-
trace: defaultTrace
|
2039
|
-
});
|
2040
|
-
return branch;
|
2041
|
-
}
|
2042
|
-
async function getDatabaseBranch(branch, options) {
|
2043
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2044
|
-
const apiKey = options?.apiKey || getAPIKey();
|
2045
|
-
if (!databaseURL)
|
2046
|
-
throw new Error(
|
2047
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
2048
|
-
);
|
2049
|
-
if (!apiKey)
|
2050
|
-
throw new Error(
|
2051
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
2052
|
-
);
|
2053
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
2054
|
-
const [workspace] = host.split(".");
|
2055
|
-
const dbBranchName = `${database}:${branch}`;
|
2056
|
-
try {
|
2057
|
-
return await getBranchDetails({
|
2058
|
-
apiKey,
|
2059
|
-
apiUrl: databaseURL,
|
2060
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
2061
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
2062
|
-
pathParams: { dbBranchName, workspace },
|
2063
|
-
trace: defaultTrace
|
2064
|
-
});
|
2065
|
-
} catch (err) {
|
2066
|
-
if (isObject(err) && err.status === 404)
|
2067
|
-
return null;
|
2068
|
-
throw err;
|
3236
|
+
function escapeElement(elementRepresentation) {
|
3237
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
3238
|
+
return '"' + escaped + '"';
|
3239
|
+
}
|
3240
|
+
function arrayString(val) {
|
3241
|
+
let result = "{";
|
3242
|
+
for (let i = 0; i < val.length; i++) {
|
3243
|
+
if (i > 0) {
|
3244
|
+
result = result + ",";
|
3245
|
+
}
|
3246
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
3247
|
+
result = result + "NULL";
|
3248
|
+
} else if (Array.isArray(val[i])) {
|
3249
|
+
result = result + arrayString(val[i]);
|
3250
|
+
} else if (val[i] instanceof Buffer) {
|
3251
|
+
result += "\\\\x" + val[i].toString("hex");
|
3252
|
+
} else {
|
3253
|
+
result += escapeElement(prepareValue(val[i]));
|
3254
|
+
}
|
2069
3255
|
}
|
3256
|
+
result = result + "}";
|
3257
|
+
return result;
|
2070
3258
|
}
|
2071
|
-
function
|
3259
|
+
function prepareValue(value) {
|
3260
|
+
if (!isDefined(value))
|
3261
|
+
return null;
|
3262
|
+
if (value instanceof Date) {
|
3263
|
+
return value.toISOString();
|
3264
|
+
}
|
3265
|
+
if (Array.isArray(value)) {
|
3266
|
+
return arrayString(value);
|
3267
|
+
}
|
3268
|
+
if (isObject(value)) {
|
3269
|
+
return JSON.stringify(value);
|
3270
|
+
}
|
2072
3271
|
try {
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
3272
|
+
return value.toString();
|
3273
|
+
} catch (e) {
|
3274
|
+
return value;
|
3275
|
+
}
|
3276
|
+
}
|
3277
|
+
function prepareParams(param1, param2) {
|
3278
|
+
if (isString(param1)) {
|
3279
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
3280
|
+
}
|
3281
|
+
if (isStringArray(param1)) {
|
3282
|
+
const statement = param1.reduce((acc, curr, index) => {
|
3283
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
3284
|
+
}, "");
|
3285
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
3286
|
+
}
|
3287
|
+
if (isObject(param1)) {
|
3288
|
+
const { statement, params, consistency } = param1;
|
3289
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
3290
|
+
}
|
3291
|
+
throw new Error("Invalid query");
|
3292
|
+
}
|
3293
|
+
|
3294
|
+
class SQLPlugin extends XataPlugin {
|
3295
|
+
build(pluginOptions) {
|
3296
|
+
return async (param1, ...param2) => {
|
3297
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
3298
|
+
const { records, warning } = await sqlQuery({
|
3299
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3300
|
+
body: { statement, params, consistency },
|
3301
|
+
...pluginOptions
|
3302
|
+
});
|
3303
|
+
return { records, warning };
|
3304
|
+
};
|
3305
|
+
}
|
3306
|
+
}
|
3307
|
+
|
3308
|
+
class TransactionPlugin extends XataPlugin {
|
3309
|
+
build(pluginOptions) {
|
3310
|
+
return {
|
3311
|
+
run: async (operations) => {
|
3312
|
+
const response = await branchTransaction({
|
3313
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3314
|
+
body: { operations },
|
3315
|
+
...pluginOptions
|
3316
|
+
});
|
3317
|
+
return response;
|
3318
|
+
}
|
3319
|
+
};
|
2077
3320
|
}
|
2078
3321
|
}
|
2079
3322
|
|
@@ -2100,88 +3343,120 @@ var __privateMethod = (obj, member, method) => {
|
|
2100
3343
|
return method;
|
2101
3344
|
};
|
2102
3345
|
const buildClient = (plugins) => {
|
2103
|
-
var
|
3346
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
2104
3347
|
return _a = class {
|
2105
3348
|
constructor(options = {}, schemaTables) {
|
2106
3349
|
__privateAdd(this, _parseOptions);
|
2107
3350
|
__privateAdd(this, _getFetchProps);
|
2108
|
-
__privateAdd(this, _evaluateBranch);
|
2109
|
-
__privateAdd(this, _branch, void 0);
|
2110
3351
|
__privateAdd(this, _options, void 0);
|
2111
3352
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
2112
3353
|
__privateSet(this, _options, safeOptions);
|
2113
3354
|
const pluginOptions = {
|
2114
|
-
|
3355
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2115
3356
|
cache: safeOptions.cache,
|
2116
|
-
|
3357
|
+
host: safeOptions.host
|
2117
3358
|
};
|
2118
3359
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2119
3360
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3361
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
3362
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
3363
|
+
const files = new FilesPlugin().build(pluginOptions);
|
2120
3364
|
this.db = db;
|
2121
3365
|
this.search = search;
|
3366
|
+
this.transactions = transactions;
|
3367
|
+
this.sql = sql;
|
3368
|
+
this.files = files;
|
2122
3369
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
2123
3370
|
if (namespace === void 0)
|
2124
3371
|
continue;
|
2125
|
-
|
2126
|
-
if (result instanceof Promise) {
|
2127
|
-
void result.then((namespace2) => {
|
2128
|
-
this[key] = namespace2;
|
2129
|
-
});
|
2130
|
-
} else {
|
2131
|
-
this[key] = result;
|
2132
|
-
}
|
3372
|
+
this[key] = namespace.build(pluginOptions);
|
2133
3373
|
}
|
2134
3374
|
}
|
2135
3375
|
async getConfig() {
|
2136
3376
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
2137
|
-
const branch =
|
3377
|
+
const branch = __privateGet(this, _options).branch;
|
2138
3378
|
return { databaseURL, branch };
|
2139
3379
|
}
|
2140
|
-
},
|
3380
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3381
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3382
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3383
|
+
if (isBrowser && !enableBrowser) {
|
3384
|
+
throw new Error(
|
3385
|
+
"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."
|
3386
|
+
);
|
3387
|
+
}
|
2141
3388
|
const fetch = getFetchImplementation(options?.fetch);
|
2142
3389
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2143
3390
|
const apiKey = options?.apiKey || getAPIKey();
|
2144
3391
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
2145
3392
|
const trace = options?.trace ?? defaultTrace;
|
2146
|
-
const
|
3393
|
+
const clientName = options?.clientName;
|
3394
|
+
const host = options?.host ?? "production";
|
3395
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
2147
3396
|
if (!apiKey) {
|
2148
3397
|
throw new Error("Option apiKey is required");
|
2149
3398
|
}
|
2150
3399
|
if (!databaseURL) {
|
2151
3400
|
throw new Error("Option databaseURL is required");
|
2152
3401
|
}
|
2153
|
-
|
2154
|
-
|
2155
|
-
const
|
2156
|
-
if (
|
2157
|
-
|
3402
|
+
const envBranch = getBranch();
|
3403
|
+
const previewBranch = getPreviewBranch();
|
3404
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
3405
|
+
if (!!previewBranch && branch !== previewBranch) {
|
3406
|
+
console.warn(
|
3407
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
3408
|
+
);
|
3409
|
+
} else if (!!envBranch && branch !== envBranch) {
|
3410
|
+
console.warn(
|
3411
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
3412
|
+
);
|
3413
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
3414
|
+
console.warn(
|
3415
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
3416
|
+
);
|
3417
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
3418
|
+
console.warn(
|
3419
|
+
`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.`
|
3420
|
+
);
|
3421
|
+
}
|
3422
|
+
return {
|
3423
|
+
fetch,
|
3424
|
+
databaseURL,
|
3425
|
+
apiKey,
|
3426
|
+
branch,
|
3427
|
+
cache,
|
3428
|
+
trace,
|
3429
|
+
host,
|
3430
|
+
clientID: generateUUID(),
|
3431
|
+
enableBrowser,
|
3432
|
+
clientName,
|
3433
|
+
xataAgentExtra
|
3434
|
+
};
|
3435
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3436
|
+
fetch,
|
3437
|
+
apiKey,
|
3438
|
+
databaseURL,
|
3439
|
+
branch,
|
3440
|
+
trace,
|
3441
|
+
clientID,
|
3442
|
+
clientName,
|
3443
|
+
xataAgentExtra
|
3444
|
+
}) {
|
2158
3445
|
return {
|
2159
|
-
|
3446
|
+
fetch,
|
2160
3447
|
apiKey,
|
2161
3448
|
apiUrl: "",
|
3449
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
2162
3450
|
workspacesApiUrl: (path, params) => {
|
2163
3451
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2164
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${
|
3452
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
2165
3453
|
return databaseURL + newPath;
|
2166
3454
|
},
|
2167
|
-
trace
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
return __privateGet(this, _branch);
|
2172
|
-
if (param === void 0)
|
2173
|
-
return void 0;
|
2174
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
2175
|
-
const evaluateBranch = async (strategy) => {
|
2176
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3455
|
+
trace,
|
3456
|
+
clientID,
|
3457
|
+
clientName,
|
3458
|
+
xataAgentExtra
|
2177
3459
|
};
|
2178
|
-
for await (const strategy of strategies) {
|
2179
|
-
const branch = await evaluateBranch(strategy);
|
2180
|
-
if (branch) {
|
2181
|
-
__privateSet(this, _branch, branch);
|
2182
|
-
return branch;
|
2183
|
-
}
|
2184
|
-
}
|
2185
3460
|
}, _a;
|
2186
3461
|
};
|
2187
3462
|
class BaseClient extends buildClient() {
|
@@ -2254,21 +3529,6 @@ const deserialize = (json) => {
|
|
2254
3529
|
return defaultSerializer.fromJSON(json);
|
2255
3530
|
};
|
2256
3531
|
|
2257
|
-
function buildWorkerRunner(config) {
|
2258
|
-
return function xataWorker(name, _worker) {
|
2259
|
-
return async (...args) => {
|
2260
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
2261
|
-
const result = await fetch(url, {
|
2262
|
-
method: "POST",
|
2263
|
-
headers: { "Content-Type": "application/json" },
|
2264
|
-
body: serialize({ args })
|
2265
|
-
});
|
2266
|
-
const text = await result.text();
|
2267
|
-
return deserialize(text);
|
2268
|
-
};
|
2269
|
-
};
|
2270
|
-
}
|
2271
|
-
|
2272
3532
|
class XataError extends Error {
|
2273
3533
|
constructor(message, status) {
|
2274
3534
|
super(message);
|
@@ -2276,5 +3536,5 @@ class XataError extends Error {
|
|
2276
3536
|
}
|
2277
3537
|
}
|
2278
3538
|
|
2279
|
-
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,
|
3539
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, pgRollMigrationHistory, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
2280
3540
|
//# sourceMappingURL=index.mjs.map
|