@xata.io/client 0.0.0-alpha.ve8aa5fb → 0.0.0-alpha.ve8d38ea
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 +318 -0
- package/README.md +3 -269
- package/dist/index.cjs +1954 -399
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3965 -1677
- package/dist/index.mjs +1911 -393
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -10
- package/.eslintrc.cjs +0 -12
- package/Usage.md +0 -451
- package/rollup.config.mjs +0 -29
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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
|
}
|
|
@@ -17,7 +18,8 @@ const TraceAttributes = {
|
|
|
17
18
|
HTTP_METHOD: "http.method",
|
|
18
19
|
HTTP_URL: "http.url",
|
|
19
20
|
HTTP_ROUTE: "http.route",
|
|
20
|
-
HTTP_TARGET: "http.target"
|
|
21
|
+
HTTP_TARGET: "http.target",
|
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
function notEmpty(value) {
|
|
@@ -26,8 +28,18 @@ function notEmpty(value) {
|
|
|
26
28
|
function compact(arr) {
|
|
27
29
|
return arr.filter(notEmpty);
|
|
28
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
|
+
}
|
|
29
41
|
function isObject(value) {
|
|
30
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
|
31
43
|
}
|
|
32
44
|
function isDefined(value) {
|
|
33
45
|
return value !== null && value !== void 0;
|
|
@@ -41,6 +53,18 @@ function isStringArray(value) {
|
|
|
41
53
|
function isNumber(value) {
|
|
42
54
|
return isDefined(value) && typeof value === "number";
|
|
43
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
|
+
}
|
|
44
68
|
function toBase64(value) {
|
|
45
69
|
try {
|
|
46
70
|
return btoa(value);
|
|
@@ -60,16 +84,49 @@ function deepMerge(a, b) {
|
|
|
60
84
|
}
|
|
61
85
|
return result;
|
|
62
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
|
+
}
|
|
63
118
|
|
|
64
119
|
function getEnvironment() {
|
|
65
120
|
try {
|
|
66
|
-
if (
|
|
121
|
+
if (isDefined(process) && isDefined(process.env)) {
|
|
67
122
|
return {
|
|
68
123
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
|
69
124
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
|
70
125
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
73
130
|
};
|
|
74
131
|
}
|
|
75
132
|
} catch (err) {
|
|
@@ -80,8 +137,10 @@ function getEnvironment() {
|
|
|
80
137
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
|
81
138
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
|
82
139
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
|
83
|
-
|
|
84
|
-
|
|
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")
|
|
85
144
|
};
|
|
86
145
|
}
|
|
87
146
|
} catch (err) {
|
|
@@ -90,8 +149,10 @@ function getEnvironment() {
|
|
|
90
149
|
apiKey: getGlobalApiKey(),
|
|
91
150
|
databaseURL: getGlobalDatabaseURL(),
|
|
92
151
|
branch: getGlobalBranch(),
|
|
93
|
-
|
|
94
|
-
|
|
152
|
+
deployPreview: void 0,
|
|
153
|
+
deployPreviewBranch: void 0,
|
|
154
|
+
vercelGitCommitRef: void 0,
|
|
155
|
+
vercelGitRepoOwner: void 0
|
|
95
156
|
};
|
|
96
157
|
}
|
|
97
158
|
function getEnableBrowserVariable() {
|
|
@@ -134,56 +195,338 @@ function getGlobalBranch() {
|
|
|
134
195
|
return void 0;
|
|
135
196
|
}
|
|
136
197
|
}
|
|
137
|
-
function
|
|
198
|
+
function getDatabaseURL() {
|
|
138
199
|
try {
|
|
139
|
-
|
|
200
|
+
const { databaseURL } = getEnvironment();
|
|
201
|
+
return databaseURL;
|
|
140
202
|
} catch (err) {
|
|
141
203
|
return void 0;
|
|
142
204
|
}
|
|
143
205
|
}
|
|
144
|
-
|
|
145
|
-
const cmd = ["git", "branch", "--show-current"];
|
|
146
|
-
const fullCmd = cmd.join(" ");
|
|
147
|
-
const nodeModule = ["child", "process"].join("_");
|
|
148
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
|
206
|
+
function getAPIKey() {
|
|
149
207
|
try {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
const { execSync } = await import(nodeModule);
|
|
154
|
-
return execSync(fullCmd, execOptions).toString().trim();
|
|
208
|
+
const { apiKey } = getEnvironment();
|
|
209
|
+
return apiKey;
|
|
155
210
|
} catch (err) {
|
|
211
|
+
return void 0;
|
|
156
212
|
}
|
|
213
|
+
}
|
|
214
|
+
function getBranch() {
|
|
157
215
|
try {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
|
161
|
-
}
|
|
216
|
+
const { branch } = getEnvironment();
|
|
217
|
+
return branch;
|
|
162
218
|
} catch (err) {
|
|
219
|
+
return void 0;
|
|
163
220
|
}
|
|
164
221
|
}
|
|
165
|
-
|
|
166
|
-
|
|
222
|
+
function buildPreviewBranchName({ org, branch }) {
|
|
223
|
+
return `preview-${org}-${branch}`;
|
|
224
|
+
}
|
|
225
|
+
function getPreviewBranch() {
|
|
167
226
|
try {
|
|
168
|
-
const {
|
|
169
|
-
|
|
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;
|
|
170
240
|
} catch (err) {
|
|
171
241
|
return void 0;
|
|
172
242
|
}
|
|
173
243
|
}
|
|
174
244
|
|
|
245
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
|
246
|
+
if (!member.has(obj))
|
|
247
|
+
throw TypeError("Cannot " + msg);
|
|
248
|
+
};
|
|
249
|
+
var __privateGet$8 = (obj, member, getter) => {
|
|
250
|
+
__accessCheck$8(obj, member, "read from private field");
|
|
251
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
252
|
+
};
|
|
253
|
+
var __privateAdd$8 = (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$8 = (obj, member, value, setter) => {
|
|
259
|
+
__accessCheck$8(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$8(obj, member, "access private method");
|
|
265
|
+
return method;
|
|
266
|
+
};
|
|
267
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
|
268
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
|
175
269
|
function getFetchImplementation(userFetch) {
|
|
176
270
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
|
177
|
-
const
|
|
271
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
|
272
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
|
178
273
|
if (!fetchImpl) {
|
|
179
|
-
throw new Error(
|
|
180
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
|
181
|
-
);
|
|
274
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
|
182
275
|
}
|
|
183
276
|
return fetchImpl;
|
|
184
277
|
}
|
|
278
|
+
class ApiRequestPool {
|
|
279
|
+
constructor(concurrency = 10) {
|
|
280
|
+
__privateAdd$8(this, _enqueue);
|
|
281
|
+
__privateAdd$8(this, _fetch, void 0);
|
|
282
|
+
__privateAdd$8(this, _queue, void 0);
|
|
283
|
+
__privateAdd$8(this, _concurrency, void 0);
|
|
284
|
+
__privateSet$8(this, _queue, []);
|
|
285
|
+
__privateSet$8(this, _concurrency, concurrency);
|
|
286
|
+
this.running = 0;
|
|
287
|
+
this.started = 0;
|
|
288
|
+
}
|
|
289
|
+
setFetch(fetch2) {
|
|
290
|
+
__privateSet$8(this, _fetch, fetch2);
|
|
291
|
+
}
|
|
292
|
+
getFetch() {
|
|
293
|
+
if (!__privateGet$8(this, _fetch)) {
|
|
294
|
+
throw new Error("Fetch not set");
|
|
295
|
+
}
|
|
296
|
+
return __privateGet$8(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$8(this, _queue).push(resolve)).finally(() => {
|
|
329
|
+
this.started--;
|
|
330
|
+
this.running++;
|
|
331
|
+
}).then(() => task()).finally(() => {
|
|
332
|
+
this.running--;
|
|
333
|
+
const next = __privateGet$8(this, _queue).shift();
|
|
334
|
+
if (next !== void 0) {
|
|
335
|
+
this.started++;
|
|
336
|
+
next();
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
|
340
|
+
const next = __privateGet$8(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
|
+
}
|
|
185
528
|
|
|
186
|
-
const VERSION = "0.
|
|
529
|
+
const VERSION = "0.26.9";
|
|
187
530
|
|
|
188
531
|
class ErrorWithCause extends Error {
|
|
189
532
|
constructor(message, options) {
|
|
@@ -194,7 +537,7 @@ class FetcherError extends ErrorWithCause {
|
|
|
194
537
|
constructor(status, data, requestId) {
|
|
195
538
|
super(getMessage(data));
|
|
196
539
|
this.status = status;
|
|
197
|
-
this.errors = isBulkError(data) ? data.errors :
|
|
540
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
|
198
541
|
this.requestId = requestId;
|
|
199
542
|
if (data instanceof Error) {
|
|
200
543
|
this.stack = data.stack;
|
|
@@ -226,6 +569,7 @@ function getMessage(data) {
|
|
|
226
569
|
}
|
|
227
570
|
}
|
|
228
571
|
|
|
572
|
+
const pool = new ApiRequestPool();
|
|
229
573
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
230
574
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
|
231
575
|
if (value === void 0 || value === null)
|
|
@@ -258,14 +602,27 @@ function hostHeader(url) {
|
|
|
258
602
|
const { groups } = pattern.exec(url) ?? {};
|
|
259
603
|
return groups?.host ? { Host: groups.host } : {};
|
|
260
604
|
}
|
|
605
|
+
async function parseBody(body, headers) {
|
|
606
|
+
if (!isDefined(body))
|
|
607
|
+
return void 0;
|
|
608
|
+
if (isBlob(body) || typeof body.text === "function") {
|
|
609
|
+
return body;
|
|
610
|
+
}
|
|
611
|
+
const { "Content-Type": contentType } = headers ?? {};
|
|
612
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
|
613
|
+
return JSON.stringify(body);
|
|
614
|
+
}
|
|
615
|
+
return body;
|
|
616
|
+
}
|
|
617
|
+
const defaultClientID = generateUUID();
|
|
261
618
|
async function fetch$1({
|
|
262
619
|
url: path,
|
|
263
620
|
method,
|
|
264
621
|
body,
|
|
265
|
-
headers,
|
|
622
|
+
headers: customHeaders,
|
|
266
623
|
pathParams,
|
|
267
624
|
queryParams,
|
|
268
|
-
|
|
625
|
+
fetch: fetch2,
|
|
269
626
|
apiKey,
|
|
270
627
|
endpoint,
|
|
271
628
|
apiUrl,
|
|
@@ -274,9 +631,13 @@ async function fetch$1({
|
|
|
274
631
|
signal,
|
|
275
632
|
clientID,
|
|
276
633
|
sessionID,
|
|
277
|
-
|
|
634
|
+
clientName,
|
|
635
|
+
xataAgentExtra,
|
|
636
|
+
fetchOptions = {},
|
|
637
|
+
rawResponse = false
|
|
278
638
|
}) {
|
|
279
|
-
|
|
639
|
+
pool.setFetch(fetch2);
|
|
640
|
+
return await trace(
|
|
280
641
|
`${method.toUpperCase()} ${path}`,
|
|
281
642
|
async ({ setAttributes }) => {
|
|
282
643
|
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
|
@@ -286,24 +647,29 @@ async function fetch$1({
|
|
|
286
647
|
[TraceAttributes.HTTP_URL]: url,
|
|
287
648
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
|
288
649
|
});
|
|
289
|
-
const
|
|
650
|
+
const xataAgent = compact([
|
|
651
|
+
["client", "TS_SDK"],
|
|
652
|
+
["version", VERSION],
|
|
653
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
|
654
|
+
...Object.entries(xataAgentExtra ?? {})
|
|
655
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
|
656
|
+
const headers = compactObject({
|
|
657
|
+
"Accept-Encoding": "identity",
|
|
658
|
+
"Content-Type": "application/json",
|
|
659
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
|
660
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
|
661
|
+
"X-Xata-Agent": xataAgent,
|
|
662
|
+
...customHeaders,
|
|
663
|
+
...hostHeader(fullUrl),
|
|
664
|
+
Authorization: `Bearer ${apiKey}`
|
|
665
|
+
});
|
|
666
|
+
const response = await pool.request(url, {
|
|
290
667
|
...fetchOptions,
|
|
291
668
|
method: method.toUpperCase(),
|
|
292
|
-
body:
|
|
293
|
-
headers
|
|
294
|
-
"Content-Type": "application/json",
|
|
295
|
-
"User-Agent": `Xata client-ts/${VERSION}`,
|
|
296
|
-
"X-Xata-Client-ID": clientID ?? "",
|
|
297
|
-
"X-Xata-Session-ID": sessionID ?? "",
|
|
298
|
-
...headers,
|
|
299
|
-
...hostHeader(fullUrl),
|
|
300
|
-
Authorization: `Bearer ${apiKey}`
|
|
301
|
-
},
|
|
669
|
+
body: await parseBody(body, headers),
|
|
670
|
+
headers,
|
|
302
671
|
signal
|
|
303
672
|
});
|
|
304
|
-
if (response.status === 204) {
|
|
305
|
-
return {};
|
|
306
|
-
}
|
|
307
673
|
const { host, protocol } = parseUrl(response.url);
|
|
308
674
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
|
309
675
|
setAttributes({
|
|
@@ -311,10 +677,20 @@ async function fetch$1({
|
|
|
311
677
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
|
312
678
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
|
313
679
|
[TraceAttributes.HTTP_HOST]: host,
|
|
314
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
|
680
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
|
681
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
|
315
682
|
});
|
|
683
|
+
const message = response.headers?.get("x-xata-message");
|
|
684
|
+
if (message)
|
|
685
|
+
console.warn(message);
|
|
686
|
+
if (response.status === 204) {
|
|
687
|
+
return {};
|
|
688
|
+
}
|
|
689
|
+
if (response.status === 429) {
|
|
690
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
|
691
|
+
}
|
|
316
692
|
try {
|
|
317
|
-
const jsonResponse = await response.json();
|
|
693
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
|
318
694
|
if (response.ok) {
|
|
319
695
|
return jsonResponse;
|
|
320
696
|
}
|
|
@@ -326,6 +702,59 @@ async function fetch$1({
|
|
|
326
702
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
|
327
703
|
);
|
|
328
704
|
}
|
|
705
|
+
function fetchSSERequest({
|
|
706
|
+
url: path,
|
|
707
|
+
method,
|
|
708
|
+
body,
|
|
709
|
+
headers: customHeaders,
|
|
710
|
+
pathParams,
|
|
711
|
+
queryParams,
|
|
712
|
+
fetch: fetch2,
|
|
713
|
+
apiKey,
|
|
714
|
+
endpoint,
|
|
715
|
+
apiUrl,
|
|
716
|
+
workspacesApiUrl,
|
|
717
|
+
onMessage,
|
|
718
|
+
onError,
|
|
719
|
+
onClose,
|
|
720
|
+
signal,
|
|
721
|
+
clientID,
|
|
722
|
+
sessionID,
|
|
723
|
+
clientName,
|
|
724
|
+
xataAgentExtra
|
|
725
|
+
}) {
|
|
726
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
|
727
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
|
728
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
|
729
|
+
void fetchEventSource(url, {
|
|
730
|
+
method,
|
|
731
|
+
body: JSON.stringify(body),
|
|
732
|
+
fetch: fetch2,
|
|
733
|
+
signal,
|
|
734
|
+
headers: {
|
|
735
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
|
736
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
|
737
|
+
"X-Xata-Agent": compact([
|
|
738
|
+
["client", "TS_SDK"],
|
|
739
|
+
["version", VERSION],
|
|
740
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
|
741
|
+
...Object.entries(xataAgentExtra ?? {})
|
|
742
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
|
743
|
+
...customHeaders,
|
|
744
|
+
Authorization: `Bearer ${apiKey}`,
|
|
745
|
+
"Content-Type": "application/json"
|
|
746
|
+
},
|
|
747
|
+
onmessage(ev) {
|
|
748
|
+
onMessage?.(JSON.parse(ev.data));
|
|
749
|
+
},
|
|
750
|
+
onerror(ev) {
|
|
751
|
+
onError?.(JSON.parse(ev.data));
|
|
752
|
+
},
|
|
753
|
+
onclose() {
|
|
754
|
+
onClose?.();
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
}
|
|
329
758
|
function parseUrl(url) {
|
|
330
759
|
try {
|
|
331
760
|
const { host, protocol } = new URL(url);
|
|
@@ -337,17 +766,12 @@ function parseUrl(url) {
|
|
|
337
766
|
|
|
338
767
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
|
339
768
|
|
|
340
|
-
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
|
341
769
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
|
342
770
|
url: "/dbs/{dbName}",
|
|
343
771
|
method: "get",
|
|
344
772
|
...variables,
|
|
345
773
|
signal
|
|
346
774
|
});
|
|
347
|
-
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
|
348
|
-
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
|
349
|
-
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
|
350
|
-
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
|
351
775
|
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
|
352
776
|
url: "/db/{dbBranchName}",
|
|
353
777
|
method: "get",
|
|
@@ -361,6 +785,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
|
361
785
|
...variables,
|
|
362
786
|
signal
|
|
363
787
|
});
|
|
788
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
|
789
|
+
url: "/db/{dbBranchName}/schema",
|
|
790
|
+
method: "get",
|
|
791
|
+
...variables,
|
|
792
|
+
signal
|
|
793
|
+
});
|
|
794
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
|
795
|
+
url: "/db/{dbBranchName}/copy",
|
|
796
|
+
method: "post",
|
|
797
|
+
...variables,
|
|
798
|
+
signal
|
|
799
|
+
});
|
|
364
800
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
|
365
801
|
url: "/db/{dbBranchName}/metadata",
|
|
366
802
|
method: "put",
|
|
@@ -386,7 +822,6 @@ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName
|
|
|
386
822
|
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
|
387
823
|
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
|
388
824
|
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
|
389
|
-
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
|
390
825
|
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
|
391
826
|
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
|
392
827
|
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
|
@@ -411,6 +846,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
|
411
846
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
|
412
847
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
|
413
848
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
|
849
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
|
414
850
|
const createTable = (variables, signal) => dataPlaneFetch({
|
|
415
851
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
|
416
852
|
method: "put",
|
|
@@ -453,7 +889,44 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
|
453
889
|
...variables,
|
|
454
890
|
signal
|
|
455
891
|
});
|
|
892
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
|
456
893
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
|
894
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
|
895
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
|
896
|
+
method: "get",
|
|
897
|
+
...variables,
|
|
898
|
+
signal
|
|
899
|
+
});
|
|
900
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
|
901
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
|
902
|
+
method: "put",
|
|
903
|
+
...variables,
|
|
904
|
+
signal
|
|
905
|
+
});
|
|
906
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
|
907
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
|
908
|
+
method: "delete",
|
|
909
|
+
...variables,
|
|
910
|
+
signal
|
|
911
|
+
});
|
|
912
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
|
913
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
|
914
|
+
method: "get",
|
|
915
|
+
...variables,
|
|
916
|
+
signal
|
|
917
|
+
});
|
|
918
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
|
919
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
|
920
|
+
method: "put",
|
|
921
|
+
...variables,
|
|
922
|
+
signal
|
|
923
|
+
});
|
|
924
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
|
925
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
|
926
|
+
method: "delete",
|
|
927
|
+
...variables,
|
|
928
|
+
signal
|
|
929
|
+
});
|
|
457
930
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
|
458
931
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
|
459
932
|
method: "get",
|
|
@@ -483,21 +956,35 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
|
483
956
|
...variables,
|
|
484
957
|
signal
|
|
485
958
|
});
|
|
959
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
|
960
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
|
961
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
|
962
|
+
method: "post",
|
|
963
|
+
...variables,
|
|
964
|
+
signal
|
|
965
|
+
});
|
|
966
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
|
486
967
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
|
487
968
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
|
969
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
|
970
|
+
url: "/file/{fileId}",
|
|
971
|
+
method: "get",
|
|
972
|
+
...variables,
|
|
973
|
+
signal
|
|
974
|
+
});
|
|
975
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
|
976
|
+
url: "/db/{dbBranchName}/sql",
|
|
977
|
+
method: "post",
|
|
978
|
+
...variables,
|
|
979
|
+
signal
|
|
980
|
+
});
|
|
488
981
|
const operationsByTag$2 = {
|
|
489
|
-
database: {
|
|
490
|
-
dEPRECATEDgetDatabaseList,
|
|
491
|
-
dEPRECATEDcreateDatabase,
|
|
492
|
-
dEPRECATEDdeleteDatabase,
|
|
493
|
-
dEPRECATEDgetDatabaseMetadata,
|
|
494
|
-
dEPRECATEDupdateDatabaseMetadata
|
|
495
|
-
},
|
|
496
982
|
branch: {
|
|
497
983
|
getBranchList,
|
|
498
984
|
getBranchDetails,
|
|
499
985
|
createBranch,
|
|
500
986
|
deleteBranch,
|
|
987
|
+
copyBranch,
|
|
501
988
|
updateBranchMetadata,
|
|
502
989
|
getBranchMetadata,
|
|
503
990
|
getBranchStats,
|
|
@@ -507,6 +994,7 @@ const operationsByTag$2 = {
|
|
|
507
994
|
resolveBranch
|
|
508
995
|
},
|
|
509
996
|
migrations: {
|
|
997
|
+
getSchema,
|
|
510
998
|
getBranchMigrationHistory,
|
|
511
999
|
getBranchMigrationPlan,
|
|
512
1000
|
executeBranchMigrationPlan,
|
|
@@ -515,17 +1003,8 @@ const operationsByTag$2 = {
|
|
|
515
1003
|
compareBranchSchemas,
|
|
516
1004
|
updateBranchSchema,
|
|
517
1005
|
previewBranchSchemaEdit,
|
|
518
|
-
applyBranchSchemaEdit
|
|
519
|
-
|
|
520
|
-
records: {
|
|
521
|
-
branchTransaction,
|
|
522
|
-
insertRecord,
|
|
523
|
-
getRecord,
|
|
524
|
-
insertRecordWithID,
|
|
525
|
-
updateRecordWithID,
|
|
526
|
-
upsertRecordWithID,
|
|
527
|
-
deleteRecord,
|
|
528
|
-
bulkInsertTableRecords
|
|
1006
|
+
applyBranchSchemaEdit,
|
|
1007
|
+
pushBranchMigrations
|
|
529
1008
|
},
|
|
530
1009
|
migrationRequests: {
|
|
531
1010
|
queryMigrationRequests,
|
|
@@ -549,11 +1028,34 @@ const operationsByTag$2 = {
|
|
|
549
1028
|
updateColumn,
|
|
550
1029
|
deleteColumn
|
|
551
1030
|
},
|
|
552
|
-
|
|
1031
|
+
records: {
|
|
1032
|
+
branchTransaction,
|
|
1033
|
+
insertRecord,
|
|
1034
|
+
getRecord,
|
|
1035
|
+
insertRecordWithID,
|
|
1036
|
+
updateRecordWithID,
|
|
1037
|
+
upsertRecordWithID,
|
|
1038
|
+
deleteRecord,
|
|
1039
|
+
bulkInsertTableRecords
|
|
1040
|
+
},
|
|
1041
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess },
|
|
1042
|
+
searchAndFilter: {
|
|
1043
|
+
queryTable,
|
|
1044
|
+
searchBranch,
|
|
1045
|
+
searchTable,
|
|
1046
|
+
vectorSearchTable,
|
|
1047
|
+
askTable,
|
|
1048
|
+
askTableSession,
|
|
1049
|
+
summarizeTable,
|
|
1050
|
+
aggregateTable
|
|
1051
|
+
},
|
|
1052
|
+
sql: { sqlQuery }
|
|
553
1053
|
};
|
|
554
1054
|
|
|
555
1055
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
|
556
1056
|
|
|
1057
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
|
1058
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
|
557
1059
|
const getUser = (variables, signal) => controlPlaneFetch({
|
|
558
1060
|
url: "/user",
|
|
559
1061
|
method: "get",
|
|
@@ -590,6 +1092,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
|
590
1092
|
...variables,
|
|
591
1093
|
signal
|
|
592
1094
|
});
|
|
1095
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
|
1096
|
+
url: "/user/oauth/clients",
|
|
1097
|
+
method: "get",
|
|
1098
|
+
...variables,
|
|
1099
|
+
signal
|
|
1100
|
+
});
|
|
1101
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
|
1102
|
+
url: "/user/oauth/clients/{clientId}",
|
|
1103
|
+
method: "delete",
|
|
1104
|
+
...variables,
|
|
1105
|
+
signal
|
|
1106
|
+
});
|
|
1107
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
|
1108
|
+
url: "/user/oauth/tokens",
|
|
1109
|
+
method: "get",
|
|
1110
|
+
...variables,
|
|
1111
|
+
signal
|
|
1112
|
+
});
|
|
1113
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
|
1114
|
+
url: "/user/oauth/tokens/{token}",
|
|
1115
|
+
method: "delete",
|
|
1116
|
+
...variables,
|
|
1117
|
+
signal
|
|
1118
|
+
});
|
|
1119
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
|
593
1120
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
|
594
1121
|
url: "/workspaces",
|
|
595
1122
|
method: "get",
|
|
@@ -633,6 +1160,20 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
|
633
1160
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
|
634
1161
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
|
635
1162
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
|
1163
|
+
const listClusters = (variables, signal) => controlPlaneFetch({
|
|
1164
|
+
url: "/workspaces/{workspaceId}/clusters",
|
|
1165
|
+
method: "get",
|
|
1166
|
+
...variables,
|
|
1167
|
+
signal
|
|
1168
|
+
});
|
|
1169
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
|
1170
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
|
1171
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
|
1172
|
+
method: "get",
|
|
1173
|
+
...variables,
|
|
1174
|
+
signal
|
|
1175
|
+
});
|
|
1176
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
|
636
1177
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
|
637
1178
|
url: "/workspaces/{workspaceId}/dbs",
|
|
638
1179
|
method: "get",
|
|
@@ -648,6 +1189,10 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
|
648
1189
|
});
|
|
649
1190
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
|
650
1191
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
|
1192
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
|
1193
|
+
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
|
1194
|
+
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
|
1195
|
+
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
|
651
1196
|
const listRegions = (variables, signal) => controlPlaneFetch({
|
|
652
1197
|
url: "/workspaces/{workspaceId}/regions",
|
|
653
1198
|
method: "get",
|
|
@@ -655,6 +1200,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
|
655
1200
|
signal
|
|
656
1201
|
});
|
|
657
1202
|
const operationsByTag$1 = {
|
|
1203
|
+
oAuth: {
|
|
1204
|
+
getAuthorizationCode,
|
|
1205
|
+
grantAuthorizationCode,
|
|
1206
|
+
getUserOAuthClients,
|
|
1207
|
+
deleteUserOAuthClient,
|
|
1208
|
+
getUserOAuthAccessTokens,
|
|
1209
|
+
deleteOAuthAccessToken,
|
|
1210
|
+
updateOAuthAccessToken
|
|
1211
|
+
},
|
|
658
1212
|
users: { getUser, updateUser, deleteUser },
|
|
659
1213
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
|
660
1214
|
workspaces: {
|
|
@@ -674,12 +1228,17 @@ const operationsByTag$1 = {
|
|
|
674
1228
|
acceptWorkspaceMemberInvite,
|
|
675
1229
|
resendWorkspaceMemberInvite
|
|
676
1230
|
},
|
|
1231
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
|
677
1232
|
databases: {
|
|
678
1233
|
getDatabaseList,
|
|
679
1234
|
createDatabase,
|
|
680
1235
|
deleteDatabase,
|
|
681
1236
|
getDatabaseMetadata,
|
|
682
1237
|
updateDatabaseMetadata,
|
|
1238
|
+
renameDatabase,
|
|
1239
|
+
getDatabaseGithubSettings,
|
|
1240
|
+
updateDatabaseGithubSettings,
|
|
1241
|
+
deleteDatabaseGithubSettings,
|
|
683
1242
|
listRegions
|
|
684
1243
|
}
|
|
685
1244
|
};
|
|
@@ -700,8 +1259,12 @@ const providers = {
|
|
|
700
1259
|
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
|
701
1260
|
},
|
|
702
1261
|
staging: {
|
|
703
|
-
main: "https://staging.
|
|
704
|
-
workspaces: "https://{workspaceId}.
|
|
1262
|
+
main: "https://api.staging-xata.dev",
|
|
1263
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
|
1264
|
+
},
|
|
1265
|
+
dev: {
|
|
1266
|
+
main: "https://api.dev-xata.dev",
|
|
1267
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
|
705
1268
|
}
|
|
706
1269
|
};
|
|
707
1270
|
function isHostProviderAlias(alias) {
|
|
@@ -719,15 +1282,22 @@ function parseProviderString(provider = "production") {
|
|
|
719
1282
|
return null;
|
|
720
1283
|
return { main, workspaces };
|
|
721
1284
|
}
|
|
1285
|
+
function buildProviderString(provider) {
|
|
1286
|
+
if (isHostProviderAlias(provider))
|
|
1287
|
+
return provider;
|
|
1288
|
+
return `${provider.main},${provider.workspaces}`;
|
|
1289
|
+
}
|
|
722
1290
|
function parseWorkspacesUrlParts(url) {
|
|
723
1291
|
if (!isString(url))
|
|
724
1292
|
return null;
|
|
725
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))
|
|
726
|
-
const
|
|
727
|
-
const
|
|
1293
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
|
1294
|
+
const regexDev = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/;
|
|
1295
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/;
|
|
1296
|
+
const regexProdTesting = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.tech.*/;
|
|
1297
|
+
const match = url.match(regex) || url.match(regexDev) || url.match(regexStaging) || url.match(regexProdTesting);
|
|
728
1298
|
if (!match)
|
|
729
1299
|
return null;
|
|
730
|
-
return { workspace: match[1], region: match[2]
|
|
1300
|
+
return { workspace: match[1], region: match[2] };
|
|
731
1301
|
}
|
|
732
1302
|
|
|
733
1303
|
var __accessCheck$7 = (obj, member, msg) => {
|
|
@@ -756,15 +1326,19 @@ class XataApiClient {
|
|
|
756
1326
|
const provider = options.host ?? "production";
|
|
757
1327
|
const apiKey = options.apiKey ?? getAPIKey();
|
|
758
1328
|
const trace = options.trace ?? defaultTrace;
|
|
1329
|
+
const clientID = generateUUID();
|
|
759
1330
|
if (!apiKey) {
|
|
760
1331
|
throw new Error("Could not resolve a valid apiKey");
|
|
761
1332
|
}
|
|
762
1333
|
__privateSet$7(this, _extraProps, {
|
|
763
1334
|
apiUrl: getHostUrl(provider, "main"),
|
|
764
1335
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
|
765
|
-
|
|
1336
|
+
fetch: getFetchImplementation(options.fetch),
|
|
766
1337
|
apiKey,
|
|
767
|
-
trace
|
|
1338
|
+
trace,
|
|
1339
|
+
clientName: options.clientName,
|
|
1340
|
+
xataAgentExtra: options.xataAgentExtra,
|
|
1341
|
+
clientID
|
|
768
1342
|
});
|
|
769
1343
|
}
|
|
770
1344
|
get user() {
|
|
@@ -817,6 +1391,11 @@ class XataApiClient {
|
|
|
817
1391
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
|
818
1392
|
return __privateGet$7(this, _namespaces).records;
|
|
819
1393
|
}
|
|
1394
|
+
get files() {
|
|
1395
|
+
if (!__privateGet$7(this, _namespaces).files)
|
|
1396
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
|
1397
|
+
return __privateGet$7(this, _namespaces).files;
|
|
1398
|
+
}
|
|
820
1399
|
get searchAndFilter() {
|
|
821
1400
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
|
822
1401
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
|
@@ -1025,6 +1604,20 @@ class BranchApi {
|
|
|
1025
1604
|
...this.extraProps
|
|
1026
1605
|
});
|
|
1027
1606
|
}
|
|
1607
|
+
copyBranch({
|
|
1608
|
+
workspace,
|
|
1609
|
+
region,
|
|
1610
|
+
database,
|
|
1611
|
+
branch,
|
|
1612
|
+
destinationBranch,
|
|
1613
|
+
limit
|
|
1614
|
+
}) {
|
|
1615
|
+
return operationsByTag.branch.copyBranch({
|
|
1616
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1617
|
+
body: { destinationBranch, limit },
|
|
1618
|
+
...this.extraProps
|
|
1619
|
+
});
|
|
1620
|
+
}
|
|
1028
1621
|
updateBranchMetadata({
|
|
1029
1622
|
workspace,
|
|
1030
1623
|
region,
|
|
@@ -1366,6 +1959,177 @@ class RecordsApi {
|
|
|
1366
1959
|
...this.extraProps
|
|
1367
1960
|
});
|
|
1368
1961
|
}
|
|
1962
|
+
branchTransaction({
|
|
1963
|
+
workspace,
|
|
1964
|
+
region,
|
|
1965
|
+
database,
|
|
1966
|
+
branch,
|
|
1967
|
+
operations
|
|
1968
|
+
}) {
|
|
1969
|
+
return operationsByTag.records.branchTransaction({
|
|
1970
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1971
|
+
body: { operations },
|
|
1972
|
+
...this.extraProps
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
class FilesApi {
|
|
1977
|
+
constructor(extraProps) {
|
|
1978
|
+
this.extraProps = extraProps;
|
|
1979
|
+
}
|
|
1980
|
+
getFileItem({
|
|
1981
|
+
workspace,
|
|
1982
|
+
region,
|
|
1983
|
+
database,
|
|
1984
|
+
branch,
|
|
1985
|
+
table,
|
|
1986
|
+
record,
|
|
1987
|
+
column,
|
|
1988
|
+
fileId
|
|
1989
|
+
}) {
|
|
1990
|
+
return operationsByTag.files.getFileItem({
|
|
1991
|
+
pathParams: {
|
|
1992
|
+
workspace,
|
|
1993
|
+
region,
|
|
1994
|
+
dbBranchName: `${database}:${branch}`,
|
|
1995
|
+
tableName: table,
|
|
1996
|
+
recordId: record,
|
|
1997
|
+
columnName: column,
|
|
1998
|
+
fileId
|
|
1999
|
+
},
|
|
2000
|
+
...this.extraProps
|
|
2001
|
+
});
|
|
2002
|
+
}
|
|
2003
|
+
putFileItem({
|
|
2004
|
+
workspace,
|
|
2005
|
+
region,
|
|
2006
|
+
database,
|
|
2007
|
+
branch,
|
|
2008
|
+
table,
|
|
2009
|
+
record,
|
|
2010
|
+
column,
|
|
2011
|
+
fileId,
|
|
2012
|
+
file
|
|
2013
|
+
}) {
|
|
2014
|
+
return operationsByTag.files.putFileItem({
|
|
2015
|
+
pathParams: {
|
|
2016
|
+
workspace,
|
|
2017
|
+
region,
|
|
2018
|
+
dbBranchName: `${database}:${branch}`,
|
|
2019
|
+
tableName: table,
|
|
2020
|
+
recordId: record,
|
|
2021
|
+
columnName: column,
|
|
2022
|
+
fileId
|
|
2023
|
+
},
|
|
2024
|
+
// @ts-ignore
|
|
2025
|
+
body: file,
|
|
2026
|
+
...this.extraProps
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
deleteFileItem({
|
|
2030
|
+
workspace,
|
|
2031
|
+
region,
|
|
2032
|
+
database,
|
|
2033
|
+
branch,
|
|
2034
|
+
table,
|
|
2035
|
+
record,
|
|
2036
|
+
column,
|
|
2037
|
+
fileId
|
|
2038
|
+
}) {
|
|
2039
|
+
return operationsByTag.files.deleteFileItem({
|
|
2040
|
+
pathParams: {
|
|
2041
|
+
workspace,
|
|
2042
|
+
region,
|
|
2043
|
+
dbBranchName: `${database}:${branch}`,
|
|
2044
|
+
tableName: table,
|
|
2045
|
+
recordId: record,
|
|
2046
|
+
columnName: column,
|
|
2047
|
+
fileId
|
|
2048
|
+
},
|
|
2049
|
+
...this.extraProps
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
getFile({
|
|
2053
|
+
workspace,
|
|
2054
|
+
region,
|
|
2055
|
+
database,
|
|
2056
|
+
branch,
|
|
2057
|
+
table,
|
|
2058
|
+
record,
|
|
2059
|
+
column
|
|
2060
|
+
}) {
|
|
2061
|
+
return operationsByTag.files.getFile({
|
|
2062
|
+
pathParams: {
|
|
2063
|
+
workspace,
|
|
2064
|
+
region,
|
|
2065
|
+
dbBranchName: `${database}:${branch}`,
|
|
2066
|
+
tableName: table,
|
|
2067
|
+
recordId: record,
|
|
2068
|
+
columnName: column
|
|
2069
|
+
},
|
|
2070
|
+
...this.extraProps
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
putFile({
|
|
2074
|
+
workspace,
|
|
2075
|
+
region,
|
|
2076
|
+
database,
|
|
2077
|
+
branch,
|
|
2078
|
+
table,
|
|
2079
|
+
record,
|
|
2080
|
+
column,
|
|
2081
|
+
file
|
|
2082
|
+
}) {
|
|
2083
|
+
return operationsByTag.files.putFile({
|
|
2084
|
+
pathParams: {
|
|
2085
|
+
workspace,
|
|
2086
|
+
region,
|
|
2087
|
+
dbBranchName: `${database}:${branch}`,
|
|
2088
|
+
tableName: table,
|
|
2089
|
+
recordId: record,
|
|
2090
|
+
columnName: column
|
|
2091
|
+
},
|
|
2092
|
+
body: file,
|
|
2093
|
+
...this.extraProps
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
deleteFile({
|
|
2097
|
+
workspace,
|
|
2098
|
+
region,
|
|
2099
|
+
database,
|
|
2100
|
+
branch,
|
|
2101
|
+
table,
|
|
2102
|
+
record,
|
|
2103
|
+
column
|
|
2104
|
+
}) {
|
|
2105
|
+
return operationsByTag.files.deleteFile({
|
|
2106
|
+
pathParams: {
|
|
2107
|
+
workspace,
|
|
2108
|
+
region,
|
|
2109
|
+
dbBranchName: `${database}:${branch}`,
|
|
2110
|
+
tableName: table,
|
|
2111
|
+
recordId: record,
|
|
2112
|
+
columnName: column
|
|
2113
|
+
},
|
|
2114
|
+
...this.extraProps
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
fileAccess({
|
|
2118
|
+
workspace,
|
|
2119
|
+
region,
|
|
2120
|
+
fileId,
|
|
2121
|
+
verify
|
|
2122
|
+
}) {
|
|
2123
|
+
return operationsByTag.files.fileAccess({
|
|
2124
|
+
pathParams: {
|
|
2125
|
+
workspace,
|
|
2126
|
+
region,
|
|
2127
|
+
fileId
|
|
2128
|
+
},
|
|
2129
|
+
queryParams: { verify },
|
|
2130
|
+
...this.extraProps
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
1369
2133
|
}
|
|
1370
2134
|
class SearchAndFilterApi {
|
|
1371
2135
|
constructor(extraProps) {
|
|
@@ -1426,6 +2190,53 @@ class SearchAndFilterApi {
|
|
|
1426
2190
|
...this.extraProps
|
|
1427
2191
|
});
|
|
1428
2192
|
}
|
|
2193
|
+
vectorSearchTable({
|
|
2194
|
+
workspace,
|
|
2195
|
+
region,
|
|
2196
|
+
database,
|
|
2197
|
+
branch,
|
|
2198
|
+
table,
|
|
2199
|
+
queryVector,
|
|
2200
|
+
column,
|
|
2201
|
+
similarityFunction,
|
|
2202
|
+
size,
|
|
2203
|
+
filter
|
|
2204
|
+
}) {
|
|
2205
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
|
2206
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
2207
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
|
2208
|
+
...this.extraProps
|
|
2209
|
+
});
|
|
2210
|
+
}
|
|
2211
|
+
askTable({
|
|
2212
|
+
workspace,
|
|
2213
|
+
region,
|
|
2214
|
+
database,
|
|
2215
|
+
branch,
|
|
2216
|
+
table,
|
|
2217
|
+
options
|
|
2218
|
+
}) {
|
|
2219
|
+
return operationsByTag.searchAndFilter.askTable({
|
|
2220
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
|
2221
|
+
body: { ...options },
|
|
2222
|
+
...this.extraProps
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2225
|
+
askTableSession({
|
|
2226
|
+
workspace,
|
|
2227
|
+
region,
|
|
2228
|
+
database,
|
|
2229
|
+
branch,
|
|
2230
|
+
table,
|
|
2231
|
+
sessionId,
|
|
2232
|
+
message
|
|
2233
|
+
}) {
|
|
2234
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
|
2235
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
|
2236
|
+
body: { message },
|
|
2237
|
+
...this.extraProps
|
|
2238
|
+
});
|
|
2239
|
+
}
|
|
1429
2240
|
summarizeTable({
|
|
1430
2241
|
workspace,
|
|
1431
2242
|
region,
|
|
@@ -1626,11 +2437,13 @@ class MigrationsApi {
|
|
|
1626
2437
|
region,
|
|
1627
2438
|
database,
|
|
1628
2439
|
branch,
|
|
1629
|
-
schema
|
|
2440
|
+
schema,
|
|
2441
|
+
schemaOperations,
|
|
2442
|
+
branchOperations
|
|
1630
2443
|
}) {
|
|
1631
2444
|
return operationsByTag.migrations.compareBranchWithUserSchema({
|
|
1632
2445
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
1633
|
-
body: { schema },
|
|
2446
|
+
body: { schema, schemaOperations, branchOperations },
|
|
1634
2447
|
...this.extraProps
|
|
1635
2448
|
});
|
|
1636
2449
|
}
|
|
@@ -1640,11 +2453,12 @@ class MigrationsApi {
|
|
|
1640
2453
|
database,
|
|
1641
2454
|
branch,
|
|
1642
2455
|
compare,
|
|
1643
|
-
|
|
2456
|
+
sourceBranchOperations,
|
|
2457
|
+
targetBranchOperations
|
|
1644
2458
|
}) {
|
|
1645
2459
|
return operationsByTag.migrations.compareBranchSchemas({
|
|
1646
2460
|
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
|
1647
|
-
body: {
|
|
2461
|
+
body: { sourceBranchOperations, targetBranchOperations },
|
|
1648
2462
|
...this.extraProps
|
|
1649
2463
|
});
|
|
1650
2464
|
}
|
|
@@ -1687,6 +2501,19 @@ class MigrationsApi {
|
|
|
1687
2501
|
...this.extraProps
|
|
1688
2502
|
});
|
|
1689
2503
|
}
|
|
2504
|
+
pushBranchMigrations({
|
|
2505
|
+
workspace,
|
|
2506
|
+
region,
|
|
2507
|
+
database,
|
|
2508
|
+
branch,
|
|
2509
|
+
migrations
|
|
2510
|
+
}) {
|
|
2511
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
|
2512
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
|
2513
|
+
body: { migrations },
|
|
2514
|
+
...this.extraProps
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
1690
2517
|
}
|
|
1691
2518
|
class DatabaseApi {
|
|
1692
2519
|
constructor(extraProps) {
|
|
@@ -1701,11 +2528,13 @@ class DatabaseApi {
|
|
|
1701
2528
|
createDatabase({
|
|
1702
2529
|
workspace,
|
|
1703
2530
|
database,
|
|
1704
|
-
data
|
|
2531
|
+
data,
|
|
2532
|
+
headers
|
|
1705
2533
|
}) {
|
|
1706
2534
|
return operationsByTag.databases.createDatabase({
|
|
1707
2535
|
pathParams: { workspaceId: workspace, dbName: database },
|
|
1708
2536
|
body: data,
|
|
2537
|
+
headers,
|
|
1709
2538
|
...this.extraProps
|
|
1710
2539
|
});
|
|
1711
2540
|
}
|
|
@@ -1738,6 +2567,46 @@ class DatabaseApi {
|
|
|
1738
2567
|
...this.extraProps
|
|
1739
2568
|
});
|
|
1740
2569
|
}
|
|
2570
|
+
renameDatabase({
|
|
2571
|
+
workspace,
|
|
2572
|
+
database,
|
|
2573
|
+
newName
|
|
2574
|
+
}) {
|
|
2575
|
+
return operationsByTag.databases.renameDatabase({
|
|
2576
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
2577
|
+
body: { newName },
|
|
2578
|
+
...this.extraProps
|
|
2579
|
+
});
|
|
2580
|
+
}
|
|
2581
|
+
getDatabaseGithubSettings({
|
|
2582
|
+
workspace,
|
|
2583
|
+
database
|
|
2584
|
+
}) {
|
|
2585
|
+
return operationsByTag.databases.getDatabaseGithubSettings({
|
|
2586
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
2587
|
+
...this.extraProps
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
updateDatabaseGithubSettings({
|
|
2591
|
+
workspace,
|
|
2592
|
+
database,
|
|
2593
|
+
settings
|
|
2594
|
+
}) {
|
|
2595
|
+
return operationsByTag.databases.updateDatabaseGithubSettings({
|
|
2596
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
2597
|
+
body: settings,
|
|
2598
|
+
...this.extraProps
|
|
2599
|
+
});
|
|
2600
|
+
}
|
|
2601
|
+
deleteDatabaseGithubSettings({
|
|
2602
|
+
workspace,
|
|
2603
|
+
database
|
|
2604
|
+
}) {
|
|
2605
|
+
return operationsByTag.databases.deleteDatabaseGithubSettings({
|
|
2606
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
|
2607
|
+
...this.extraProps
|
|
2608
|
+
});
|
|
2609
|
+
}
|
|
1741
2610
|
listRegions({ workspace }) {
|
|
1742
2611
|
return operationsByTag.databases.listRegions({
|
|
1743
2612
|
pathParams: { workspaceId: workspace },
|
|
@@ -1747,27 +2616,200 @@ class DatabaseApi {
|
|
|
1747
2616
|
}
|
|
1748
2617
|
|
|
1749
2618
|
class XataApiPlugin {
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
|
2619
|
+
build(options) {
|
|
2620
|
+
return new XataApiClient(options);
|
|
1753
2621
|
}
|
|
1754
2622
|
}
|
|
1755
2623
|
|
|
1756
2624
|
class XataPlugin {
|
|
1757
2625
|
}
|
|
1758
2626
|
|
|
1759
|
-
function
|
|
1760
|
-
return
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
2627
|
+
function buildTransformString(transformations) {
|
|
2628
|
+
return transformations.flatMap(
|
|
2629
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
|
2630
|
+
if (key === "trim") {
|
|
2631
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
|
2632
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
|
2633
|
+
}
|
|
2634
|
+
if (key === "gravity" && typeof value === "object") {
|
|
2635
|
+
const { x = 0.5, y = 0.5 } = value;
|
|
2636
|
+
return `${key}=${[x, y].join("x")}`;
|
|
2637
|
+
}
|
|
2638
|
+
return `${key}=${value}`;
|
|
2639
|
+
})
|
|
2640
|
+
).join(",");
|
|
2641
|
+
}
|
|
2642
|
+
function transformImage(url, ...transformations) {
|
|
2643
|
+
if (!isDefined(url))
|
|
2644
|
+
return void 0;
|
|
2645
|
+
const newTransformations = buildTransformString(transformations);
|
|
2646
|
+
const { hostname, pathname, search } = new URL(url);
|
|
2647
|
+
const pathParts = pathname.split("/");
|
|
2648
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
|
2649
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
|
2650
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
|
2651
|
+
const path = pathParts.join("/");
|
|
2652
|
+
return `https://${hostname}${transform}${path}${search}`;
|
|
1764
2653
|
}
|
|
1765
2654
|
|
|
2655
|
+
class XataFile {
|
|
2656
|
+
constructor(file) {
|
|
2657
|
+
this.id = file.id;
|
|
2658
|
+
this.name = file.name || "";
|
|
2659
|
+
this.mediaType = file.mediaType || "application/octet-stream";
|
|
2660
|
+
this.base64Content = file.base64Content;
|
|
2661
|
+
this.enablePublicUrl = file.enablePublicUrl ?? false;
|
|
2662
|
+
this.signedUrlTimeout = file.signedUrlTimeout ?? 300;
|
|
2663
|
+
this.size = file.size ?? 0;
|
|
2664
|
+
this.version = file.version ?? 1;
|
|
2665
|
+
this.url = file.url || "";
|
|
2666
|
+
this.signedUrl = file.signedUrl;
|
|
2667
|
+
this.attributes = file.attributes || {};
|
|
2668
|
+
}
|
|
2669
|
+
static fromBuffer(buffer, options = {}) {
|
|
2670
|
+
const base64Content = buffer.toString("base64");
|
|
2671
|
+
return new XataFile({ ...options, base64Content });
|
|
2672
|
+
}
|
|
2673
|
+
toBuffer() {
|
|
2674
|
+
if (!this.base64Content) {
|
|
2675
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2676
|
+
}
|
|
2677
|
+
return Buffer.from(this.base64Content, "base64");
|
|
2678
|
+
}
|
|
2679
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
|
2680
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
2681
|
+
return this.fromUint8Array(uint8Array, options);
|
|
2682
|
+
}
|
|
2683
|
+
toArrayBuffer() {
|
|
2684
|
+
if (!this.base64Content) {
|
|
2685
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2686
|
+
}
|
|
2687
|
+
const binary = atob(this.base64Content);
|
|
2688
|
+
return new ArrayBuffer(binary.length);
|
|
2689
|
+
}
|
|
2690
|
+
static fromUint8Array(uint8Array, options = {}) {
|
|
2691
|
+
let binary = "";
|
|
2692
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
|
2693
|
+
binary += String.fromCharCode(uint8Array[i]);
|
|
2694
|
+
}
|
|
2695
|
+
const base64Content = btoa(binary);
|
|
2696
|
+
return new XataFile({ ...options, base64Content });
|
|
2697
|
+
}
|
|
2698
|
+
toUint8Array() {
|
|
2699
|
+
if (!this.base64Content) {
|
|
2700
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2701
|
+
}
|
|
2702
|
+
const binary = atob(this.base64Content);
|
|
2703
|
+
const uint8Array = new Uint8Array(binary.length);
|
|
2704
|
+
for (let i = 0; i < binary.length; i++) {
|
|
2705
|
+
uint8Array[i] = binary.charCodeAt(i);
|
|
2706
|
+
}
|
|
2707
|
+
return uint8Array;
|
|
2708
|
+
}
|
|
2709
|
+
static async fromBlob(file, options = {}) {
|
|
2710
|
+
const name = options.name ?? file.name;
|
|
2711
|
+
const mediaType = file.type;
|
|
2712
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
2713
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
|
2714
|
+
}
|
|
2715
|
+
toBlob() {
|
|
2716
|
+
if (!this.base64Content) {
|
|
2717
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2718
|
+
}
|
|
2719
|
+
const binary = atob(this.base64Content);
|
|
2720
|
+
const uint8Array = new Uint8Array(binary.length);
|
|
2721
|
+
for (let i = 0; i < binary.length; i++) {
|
|
2722
|
+
uint8Array[i] = binary.charCodeAt(i);
|
|
2723
|
+
}
|
|
2724
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
|
2725
|
+
}
|
|
2726
|
+
static fromString(string, options = {}) {
|
|
2727
|
+
const base64Content = btoa(string);
|
|
2728
|
+
return new XataFile({ ...options, base64Content });
|
|
2729
|
+
}
|
|
2730
|
+
toString() {
|
|
2731
|
+
if (!this.base64Content) {
|
|
2732
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2733
|
+
}
|
|
2734
|
+
return atob(this.base64Content);
|
|
2735
|
+
}
|
|
2736
|
+
static fromBase64(base64Content, options = {}) {
|
|
2737
|
+
return new XataFile({ ...options, base64Content });
|
|
2738
|
+
}
|
|
2739
|
+
toBase64() {
|
|
2740
|
+
if (!this.base64Content) {
|
|
2741
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
|
2742
|
+
}
|
|
2743
|
+
return this.base64Content;
|
|
2744
|
+
}
|
|
2745
|
+
transform(...options) {
|
|
2746
|
+
return {
|
|
2747
|
+
url: transformImage(this.url, ...options),
|
|
2748
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
|
2749
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
|
2750
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
|
2751
|
+
};
|
|
2752
|
+
}
|
|
2753
|
+
}
|
|
2754
|
+
const parseInputFileEntry = async (entry) => {
|
|
2755
|
+
if (!isDefined(entry))
|
|
2756
|
+
return null;
|
|
2757
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout } = await entry;
|
|
2758
|
+
return compactObject({
|
|
2759
|
+
id,
|
|
2760
|
+
// Name cannot be an empty string in our API
|
|
2761
|
+
name: name ? name : void 0,
|
|
2762
|
+
mediaType,
|
|
2763
|
+
base64Content,
|
|
2764
|
+
enablePublicUrl,
|
|
2765
|
+
signedUrlTimeout
|
|
2766
|
+
});
|
|
2767
|
+
};
|
|
2768
|
+
|
|
1766
2769
|
function cleanFilter(filter) {
|
|
1767
|
-
if (!filter)
|
|
2770
|
+
if (!isDefined(filter))
|
|
1768
2771
|
return void 0;
|
|
1769
|
-
|
|
1770
|
-
|
|
2772
|
+
if (!isObject(filter))
|
|
2773
|
+
return filter;
|
|
2774
|
+
const values = Object.fromEntries(
|
|
2775
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
|
2776
|
+
if (!isDefined(value))
|
|
2777
|
+
return acc;
|
|
2778
|
+
if (Array.isArray(value)) {
|
|
2779
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
|
2780
|
+
if (clean.length === 0)
|
|
2781
|
+
return acc;
|
|
2782
|
+
return [...acc, [key, clean]];
|
|
2783
|
+
}
|
|
2784
|
+
if (isObject(value)) {
|
|
2785
|
+
const clean = cleanFilter(value);
|
|
2786
|
+
if (!isDefined(clean))
|
|
2787
|
+
return acc;
|
|
2788
|
+
return [...acc, [key, clean]];
|
|
2789
|
+
}
|
|
2790
|
+
return [...acc, [key, value]];
|
|
2791
|
+
}, [])
|
|
2792
|
+
);
|
|
2793
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
function stringifyJson(value) {
|
|
2797
|
+
if (!isDefined(value))
|
|
2798
|
+
return value;
|
|
2799
|
+
if (isString(value))
|
|
2800
|
+
return value;
|
|
2801
|
+
try {
|
|
2802
|
+
return JSON.stringify(value);
|
|
2803
|
+
} catch (e) {
|
|
2804
|
+
return value;
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
function parseJson(value) {
|
|
2808
|
+
try {
|
|
2809
|
+
return JSON.parse(value);
|
|
2810
|
+
} catch (e) {
|
|
2811
|
+
return value;
|
|
2812
|
+
}
|
|
1771
2813
|
}
|
|
1772
2814
|
|
|
1773
2815
|
var __accessCheck$6 = (obj, member, msg) => {
|
|
@@ -1796,31 +2838,59 @@ class Page {
|
|
|
1796
2838
|
this.meta = meta;
|
|
1797
2839
|
this.records = new RecordArray(this, records);
|
|
1798
2840
|
}
|
|
2841
|
+
/**
|
|
2842
|
+
* Retrieves the next page of results.
|
|
2843
|
+
* @param size Maximum number of results to be retrieved.
|
|
2844
|
+
* @param offset Number of results to skip when retrieving the results.
|
|
2845
|
+
* @returns The next page or results.
|
|
2846
|
+
*/
|
|
1799
2847
|
async nextPage(size, offset) {
|
|
1800
2848
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
|
1801
2849
|
}
|
|
2850
|
+
/**
|
|
2851
|
+
* Retrieves the previous page of results.
|
|
2852
|
+
* @param size Maximum number of results to be retrieved.
|
|
2853
|
+
* @param offset Number of results to skip when retrieving the results.
|
|
2854
|
+
* @returns The previous page or results.
|
|
2855
|
+
*/
|
|
1802
2856
|
async previousPage(size, offset) {
|
|
1803
2857
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
|
1804
2858
|
}
|
|
2859
|
+
/**
|
|
2860
|
+
* Retrieves the start page of results.
|
|
2861
|
+
* @param size Maximum number of results to be retrieved.
|
|
2862
|
+
* @param offset Number of results to skip when retrieving the results.
|
|
2863
|
+
* @returns The start page or results.
|
|
2864
|
+
*/
|
|
1805
2865
|
async startPage(size, offset) {
|
|
1806
2866
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
|
1807
2867
|
}
|
|
2868
|
+
/**
|
|
2869
|
+
* Retrieves the end page of results.
|
|
2870
|
+
* @param size Maximum number of results to be retrieved.
|
|
2871
|
+
* @param offset Number of results to skip when retrieving the results.
|
|
2872
|
+
* @returns The end page or results.
|
|
2873
|
+
*/
|
|
1808
2874
|
async endPage(size, offset) {
|
|
1809
2875
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
|
1810
2876
|
}
|
|
2877
|
+
/**
|
|
2878
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
|
2879
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
|
2880
|
+
*/
|
|
1811
2881
|
hasNextPage() {
|
|
1812
2882
|
return this.meta.page.more;
|
|
1813
2883
|
}
|
|
1814
2884
|
}
|
|
1815
2885
|
_query = new WeakMap();
|
|
1816
|
-
const PAGINATION_MAX_SIZE =
|
|
2886
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
|
1817
2887
|
const PAGINATION_DEFAULT_SIZE = 20;
|
|
1818
|
-
const PAGINATION_MAX_OFFSET =
|
|
2888
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
|
1819
2889
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
|
1820
2890
|
function isCursorPaginationOptions(options) {
|
|
1821
2891
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
|
1822
2892
|
}
|
|
1823
|
-
const _RecordArray = class extends Array {
|
|
2893
|
+
const _RecordArray = class _RecordArray extends Array {
|
|
1824
2894
|
constructor(...args) {
|
|
1825
2895
|
super(..._RecordArray.parseConstructorParams(...args));
|
|
1826
2896
|
__privateAdd$6(this, _page, void 0);
|
|
@@ -1839,31 +2909,60 @@ const _RecordArray = class extends Array {
|
|
|
1839
2909
|
toArray() {
|
|
1840
2910
|
return new Array(...this);
|
|
1841
2911
|
}
|
|
2912
|
+
toSerializable() {
|
|
2913
|
+
return JSON.parse(this.toString());
|
|
2914
|
+
}
|
|
2915
|
+
toString() {
|
|
2916
|
+
return JSON.stringify(this.toArray());
|
|
2917
|
+
}
|
|
1842
2918
|
map(callbackfn, thisArg) {
|
|
1843
2919
|
return this.toArray().map(callbackfn, thisArg);
|
|
1844
2920
|
}
|
|
2921
|
+
/**
|
|
2922
|
+
* Retrieve next page of records
|
|
2923
|
+
*
|
|
2924
|
+
* @returns A new array of objects
|
|
2925
|
+
*/
|
|
1845
2926
|
async nextPage(size, offset) {
|
|
1846
2927
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
|
1847
2928
|
return new _RecordArray(newPage);
|
|
1848
2929
|
}
|
|
2930
|
+
/**
|
|
2931
|
+
* Retrieve previous page of records
|
|
2932
|
+
*
|
|
2933
|
+
* @returns A new array of objects
|
|
2934
|
+
*/
|
|
1849
2935
|
async previousPage(size, offset) {
|
|
1850
2936
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
|
1851
2937
|
return new _RecordArray(newPage);
|
|
1852
2938
|
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Retrieve start page of records
|
|
2941
|
+
*
|
|
2942
|
+
* @returns A new array of objects
|
|
2943
|
+
*/
|
|
1853
2944
|
async startPage(size, offset) {
|
|
1854
2945
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
|
1855
2946
|
return new _RecordArray(newPage);
|
|
1856
2947
|
}
|
|
2948
|
+
/**
|
|
2949
|
+
* Retrieve end page of records
|
|
2950
|
+
*
|
|
2951
|
+
* @returns A new array of objects
|
|
2952
|
+
*/
|
|
1857
2953
|
async endPage(size, offset) {
|
|
1858
2954
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
|
1859
2955
|
return new _RecordArray(newPage);
|
|
1860
2956
|
}
|
|
2957
|
+
/**
|
|
2958
|
+
* @returns Boolean indicating if there is a next page
|
|
2959
|
+
*/
|
|
1861
2960
|
hasNextPage() {
|
|
1862
2961
|
return __privateGet$6(this, _page).meta.page.more;
|
|
1863
2962
|
}
|
|
1864
2963
|
};
|
|
1865
|
-
let RecordArray = _RecordArray;
|
|
1866
2964
|
_page = new WeakMap();
|
|
2965
|
+
let RecordArray = _RecordArray;
|
|
1867
2966
|
|
|
1868
2967
|
var __accessCheck$5 = (obj, member, msg) => {
|
|
1869
2968
|
if (!member.has(obj))
|
|
@@ -1888,13 +2987,14 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
|
1888
2987
|
return method;
|
|
1889
2988
|
};
|
|
1890
2989
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
|
1891
|
-
const _Query = class {
|
|
2990
|
+
const _Query = class _Query {
|
|
1892
2991
|
constructor(repository, table, data, rawParent) {
|
|
1893
2992
|
__privateAdd$5(this, _cleanFilterConstraint);
|
|
1894
2993
|
__privateAdd$5(this, _table$1, void 0);
|
|
1895
2994
|
__privateAdd$5(this, _repository, void 0);
|
|
1896
2995
|
__privateAdd$5(this, _data, { filter: {} });
|
|
1897
|
-
|
|
2996
|
+
// Implements pagination
|
|
2997
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
|
1898
2998
|
this.records = new RecordArray(this, []);
|
|
1899
2999
|
__privateSet$5(this, _table$1, table);
|
|
1900
3000
|
if (repository) {
|
|
@@ -1910,6 +3010,7 @@ const _Query = class {
|
|
|
1910
3010
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
|
1911
3011
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
|
1912
3012
|
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
|
3013
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
|
1913
3014
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
|
1914
3015
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
|
1915
3016
|
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
|
@@ -1930,18 +3031,38 @@ const _Query = class {
|
|
|
1930
3031
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
|
1931
3032
|
return toBase64(key);
|
|
1932
3033
|
}
|
|
3034
|
+
/**
|
|
3035
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
|
3036
|
+
* @param queries An array of subqueries.
|
|
3037
|
+
* @returns A new Query object.
|
|
3038
|
+
*/
|
|
1933
3039
|
any(...queries) {
|
|
1934
3040
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
|
1935
3041
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
|
1936
3042
|
}
|
|
3043
|
+
/**
|
|
3044
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
|
3045
|
+
* @param queries An array of subqueries.
|
|
3046
|
+
* @returns A new Query object.
|
|
3047
|
+
*/
|
|
1937
3048
|
all(...queries) {
|
|
1938
3049
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
|
1939
3050
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1940
3051
|
}
|
|
3052
|
+
/**
|
|
3053
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
|
3054
|
+
* @param queries An array of subqueries.
|
|
3055
|
+
* @returns A new Query object.
|
|
3056
|
+
*/
|
|
1941
3057
|
not(...queries) {
|
|
1942
3058
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
|
1943
3059
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
|
1944
3060
|
}
|
|
3061
|
+
/**
|
|
3062
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
|
3063
|
+
* @param queries An array of subqueries.
|
|
3064
|
+
* @returns A new Query object.
|
|
3065
|
+
*/
|
|
1945
3066
|
none(...queries) {
|
|
1946
3067
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
|
1947
3068
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
|
@@ -1964,6 +3085,11 @@ const _Query = class {
|
|
|
1964
3085
|
const sort = [...originalSort, { column, direction }];
|
|
1965
3086
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
|
1966
3087
|
}
|
|
3088
|
+
/**
|
|
3089
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
|
3090
|
+
* @param columns Array of column names to be returned by the query.
|
|
3091
|
+
* @returns A new Query object.
|
|
3092
|
+
*/
|
|
1967
3093
|
select(columns) {
|
|
1968
3094
|
return new _Query(
|
|
1969
3095
|
__privateGet$5(this, _repository),
|
|
@@ -1976,6 +3102,12 @@ const _Query = class {
|
|
|
1976
3102
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
|
1977
3103
|
return __privateGet$5(this, _repository).query(query);
|
|
1978
3104
|
}
|
|
3105
|
+
/**
|
|
3106
|
+
* Get results in an iterator
|
|
3107
|
+
*
|
|
3108
|
+
* @async
|
|
3109
|
+
* @returns Async interable of results
|
|
3110
|
+
*/
|
|
1979
3111
|
async *[Symbol.asyncIterator]() {
|
|
1980
3112
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
|
1981
3113
|
yield record;
|
|
@@ -2036,26 +3168,53 @@ const _Query = class {
|
|
|
2036
3168
|
);
|
|
2037
3169
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
|
2038
3170
|
}
|
|
3171
|
+
/**
|
|
3172
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
|
3173
|
+
* @param ttl The cache TTL in milliseconds.
|
|
3174
|
+
* @returns A new Query object.
|
|
3175
|
+
*/
|
|
2039
3176
|
cache(ttl) {
|
|
2040
3177
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
|
2041
3178
|
}
|
|
3179
|
+
/**
|
|
3180
|
+
* Retrieve next page of records
|
|
3181
|
+
*
|
|
3182
|
+
* @returns A new page object.
|
|
3183
|
+
*/
|
|
2042
3184
|
nextPage(size, offset) {
|
|
2043
3185
|
return this.startPage(size, offset);
|
|
2044
3186
|
}
|
|
3187
|
+
/**
|
|
3188
|
+
* Retrieve previous page of records
|
|
3189
|
+
*
|
|
3190
|
+
* @returns A new page object
|
|
3191
|
+
*/
|
|
2045
3192
|
previousPage(size, offset) {
|
|
2046
3193
|
return this.startPage(size, offset);
|
|
2047
3194
|
}
|
|
3195
|
+
/**
|
|
3196
|
+
* Retrieve start page of records
|
|
3197
|
+
*
|
|
3198
|
+
* @returns A new page object
|
|
3199
|
+
*/
|
|
2048
3200
|
startPage(size, offset) {
|
|
2049
3201
|
return this.getPaginated({ pagination: { size, offset } });
|
|
2050
3202
|
}
|
|
3203
|
+
/**
|
|
3204
|
+
* Retrieve last page of records
|
|
3205
|
+
*
|
|
3206
|
+
* @returns A new page object
|
|
3207
|
+
*/
|
|
2051
3208
|
endPage(size, offset) {
|
|
2052
3209
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
|
2053
3210
|
}
|
|
3211
|
+
/**
|
|
3212
|
+
* @returns Boolean indicating if there is a next page
|
|
3213
|
+
*/
|
|
2054
3214
|
hasNextPage() {
|
|
2055
3215
|
return this.meta.page.more;
|
|
2056
3216
|
}
|
|
2057
3217
|
};
|
|
2058
|
-
let Query = _Query;
|
|
2059
3218
|
_table$1 = new WeakMap();
|
|
2060
3219
|
_repository = new WeakMap();
|
|
2061
3220
|
_data = new WeakMap();
|
|
@@ -2070,6 +3229,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
|
2070
3229
|
}
|
|
2071
3230
|
return value;
|
|
2072
3231
|
};
|
|
3232
|
+
let Query = _Query;
|
|
2073
3233
|
function cleanParent(data, parent) {
|
|
2074
3234
|
if (isCursorPaginationOptions(data.pagination)) {
|
|
2075
3235
|
return { ...parent, sort: void 0, filter: void 0 };
|
|
@@ -2077,6 +3237,22 @@ function cleanParent(data, parent) {
|
|
|
2077
3237
|
return parent;
|
|
2078
3238
|
}
|
|
2079
3239
|
|
|
3240
|
+
const RecordColumnTypes = [
|
|
3241
|
+
"bool",
|
|
3242
|
+
"int",
|
|
3243
|
+
"float",
|
|
3244
|
+
"string",
|
|
3245
|
+
"text",
|
|
3246
|
+
"email",
|
|
3247
|
+
"multiple",
|
|
3248
|
+
"link",
|
|
3249
|
+
"object",
|
|
3250
|
+
"datetime",
|
|
3251
|
+
"vector",
|
|
3252
|
+
"file[]",
|
|
3253
|
+
"file",
|
|
3254
|
+
"json"
|
|
3255
|
+
];
|
|
2080
3256
|
function isIdentifiable(x) {
|
|
2081
3257
|
return isObject(x) && isString(x?.id);
|
|
2082
3258
|
}
|
|
@@ -2086,11 +3262,33 @@ function isXataRecord(x) {
|
|
|
2086
3262
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
|
2087
3263
|
}
|
|
2088
3264
|
|
|
3265
|
+
function isValidExpandedColumn(column) {
|
|
3266
|
+
return isObject(column) && isString(column.name);
|
|
3267
|
+
}
|
|
3268
|
+
function isValidSelectableColumns(columns) {
|
|
3269
|
+
if (!Array.isArray(columns)) {
|
|
3270
|
+
return false;
|
|
3271
|
+
}
|
|
3272
|
+
return columns.every((column) => {
|
|
3273
|
+
if (typeof column === "string") {
|
|
3274
|
+
return true;
|
|
3275
|
+
}
|
|
3276
|
+
if (typeof column === "object") {
|
|
3277
|
+
return isValidExpandedColumn(column);
|
|
3278
|
+
}
|
|
3279
|
+
return false;
|
|
3280
|
+
});
|
|
3281
|
+
}
|
|
3282
|
+
|
|
2089
3283
|
function isSortFilterString(value) {
|
|
2090
3284
|
return isString(value);
|
|
2091
3285
|
}
|
|
2092
3286
|
function isSortFilterBase(filter) {
|
|
2093
|
-
return isObject(filter) && Object.
|
|
3287
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
|
3288
|
+
if (key === "*")
|
|
3289
|
+
return value === "random";
|
|
3290
|
+
return value === "asc" || value === "desc";
|
|
3291
|
+
});
|
|
2094
3292
|
}
|
|
2095
3293
|
function isSortFilterObject(filter) {
|
|
2096
3294
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
|
@@ -2131,7 +3329,8 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
|
2131
3329
|
__accessCheck$4(obj, member, "access private method");
|
|
2132
3330
|
return method;
|
|
2133
3331
|
};
|
|
2134
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
|
3332
|
+
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;
|
|
3333
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
|
2135
3334
|
class Repository extends Query {
|
|
2136
3335
|
}
|
|
2137
3336
|
class RestRepository extends Query {
|
|
@@ -2143,13 +3342,16 @@ class RestRepository extends Query {
|
|
|
2143
3342
|
);
|
|
2144
3343
|
__privateAdd$4(this, _insertRecordWithoutId);
|
|
2145
3344
|
__privateAdd$4(this, _insertRecordWithId);
|
|
2146
|
-
__privateAdd$4(this,
|
|
3345
|
+
__privateAdd$4(this, _insertRecords);
|
|
2147
3346
|
__privateAdd$4(this, _updateRecordWithID);
|
|
3347
|
+
__privateAdd$4(this, _updateRecords);
|
|
2148
3348
|
__privateAdd$4(this, _upsertRecordWithID);
|
|
2149
3349
|
__privateAdd$4(this, _deleteRecord);
|
|
3350
|
+
__privateAdd$4(this, _deleteRecords);
|
|
2150
3351
|
__privateAdd$4(this, _setCacheQuery);
|
|
2151
3352
|
__privateAdd$4(this, _getCacheQuery);
|
|
2152
3353
|
__privateAdd$4(this, _getSchemaTables$1);
|
|
3354
|
+
__privateAdd$4(this, _transformObjectToApi);
|
|
2153
3355
|
__privateAdd$4(this, _table, void 0);
|
|
2154
3356
|
__privateAdd$4(this, _getFetchProps, void 0);
|
|
2155
3357
|
__privateAdd$4(this, _db, void 0);
|
|
@@ -2160,10 +3362,7 @@ class RestRepository extends Query {
|
|
|
2160
3362
|
__privateSet$4(this, _db, options.db);
|
|
2161
3363
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
|
2162
3364
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
|
2163
|
-
__privateSet$4(this, _getFetchProps,
|
|
2164
|
-
const props = await options.pluginOptions.getFetchProps();
|
|
2165
|
-
return { ...props, sessionID: generateUUID() };
|
|
2166
|
-
});
|
|
3365
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
|
2167
3366
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
|
2168
3367
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
|
2169
3368
|
return trace(name, fn, {
|
|
@@ -2180,23 +3379,25 @@ class RestRepository extends Query {
|
|
|
2180
3379
|
if (Array.isArray(a)) {
|
|
2181
3380
|
if (a.length === 0)
|
|
2182
3381
|
return [];
|
|
2183
|
-
const
|
|
2184
|
-
|
|
3382
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
|
3383
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
3384
|
+
const result = await this.read(ids, columns);
|
|
3385
|
+
return result;
|
|
2185
3386
|
}
|
|
2186
3387
|
if (isString(a) && isObject(b)) {
|
|
2187
3388
|
if (a === "")
|
|
2188
3389
|
throw new Error("The id can't be empty");
|
|
2189
|
-
const columns =
|
|
2190
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
|
3390
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3391
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
|
2191
3392
|
}
|
|
2192
3393
|
if (isObject(a) && isString(a.id)) {
|
|
2193
3394
|
if (a.id === "")
|
|
2194
3395
|
throw new Error("The id can't be empty");
|
|
2195
|
-
const columns =
|
|
2196
|
-
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
|
3396
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
|
3397
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
|
2197
3398
|
}
|
|
2198
3399
|
if (isObject(a)) {
|
|
2199
|
-
const columns =
|
|
3400
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
|
2200
3401
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
|
2201
3402
|
}
|
|
2202
3403
|
throw new Error("Invalid arguments for create method");
|
|
@@ -2204,7 +3405,7 @@ class RestRepository extends Query {
|
|
|
2204
3405
|
}
|
|
2205
3406
|
async read(a, b) {
|
|
2206
3407
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
|
2207
|
-
const columns =
|
|
3408
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
2208
3409
|
if (Array.isArray(a)) {
|
|
2209
3410
|
if (a.length === 0)
|
|
2210
3411
|
return [];
|
|
@@ -2218,7 +3419,6 @@ class RestRepository extends Query {
|
|
|
2218
3419
|
}
|
|
2219
3420
|
const id = extractId(a);
|
|
2220
3421
|
if (id) {
|
|
2221
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2222
3422
|
try {
|
|
2223
3423
|
const response = await getRecord({
|
|
2224
3424
|
pathParams: {
|
|
@@ -2229,10 +3429,16 @@ class RestRepository extends Query {
|
|
|
2229
3429
|
recordId: id
|
|
2230
3430
|
},
|
|
2231
3431
|
queryParams: { columns },
|
|
2232
|
-
...
|
|
3432
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2233
3433
|
});
|
|
2234
3434
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2235
|
-
return initObject(
|
|
3435
|
+
return initObject(
|
|
3436
|
+
__privateGet$4(this, _db),
|
|
3437
|
+
schemaTables,
|
|
3438
|
+
__privateGet$4(this, _table),
|
|
3439
|
+
response,
|
|
3440
|
+
columns
|
|
3441
|
+
);
|
|
2236
3442
|
} catch (e) {
|
|
2237
3443
|
if (isObject(e) && e.status === 404) {
|
|
2238
3444
|
return null;
|
|
@@ -2268,19 +3474,29 @@ class RestRepository extends Query {
|
|
|
2268
3474
|
if (Array.isArray(a)) {
|
|
2269
3475
|
if (a.length === 0)
|
|
2270
3476
|
return [];
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
const
|
|
2279
|
-
return
|
|
3477
|
+
const existing = await this.read(a, ["id"]);
|
|
3478
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
|
3479
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
|
3480
|
+
ifVersion,
|
|
3481
|
+
upsert: false
|
|
3482
|
+
});
|
|
3483
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
3484
|
+
const result = await this.read(a, columns);
|
|
3485
|
+
return result;
|
|
2280
3486
|
}
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
3487
|
+
try {
|
|
3488
|
+
if (isString(a) && isObject(b)) {
|
|
3489
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3490
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
|
3491
|
+
}
|
|
3492
|
+
if (isObject(a) && isString(a.id)) {
|
|
3493
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
|
3494
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
|
3495
|
+
}
|
|
3496
|
+
} catch (error) {
|
|
3497
|
+
if (error.status === 422)
|
|
3498
|
+
return null;
|
|
3499
|
+
throw error;
|
|
2284
3500
|
}
|
|
2285
3501
|
throw new Error("Invalid arguments for update method");
|
|
2286
3502
|
});
|
|
@@ -2310,19 +3526,31 @@ class RestRepository extends Query {
|
|
|
2310
3526
|
if (Array.isArray(a)) {
|
|
2311
3527
|
if (a.length === 0)
|
|
2312
3528
|
return [];
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
3529
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
|
3530
|
+
ifVersion,
|
|
3531
|
+
upsert: true
|
|
3532
|
+
});
|
|
3533
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
3534
|
+
const result = await this.read(a, columns);
|
|
3535
|
+
return result;
|
|
2318
3536
|
}
|
|
2319
3537
|
if (isString(a) && isObject(b)) {
|
|
2320
|
-
|
|
2321
|
-
|
|
3538
|
+
if (a === "")
|
|
3539
|
+
throw new Error("The id can't be empty");
|
|
3540
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3541
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
|
2322
3542
|
}
|
|
2323
3543
|
if (isObject(a) && isString(a.id)) {
|
|
2324
|
-
|
|
2325
|
-
|
|
3544
|
+
if (a.id === "")
|
|
3545
|
+
throw new Error("The id can't be empty");
|
|
3546
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3547
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
|
3548
|
+
}
|
|
3549
|
+
if (!isDefined(a) && isObject(b)) {
|
|
3550
|
+
return await this.create(b, c);
|
|
3551
|
+
}
|
|
3552
|
+
if (isObject(a) && !isDefined(a.id)) {
|
|
3553
|
+
return await this.create(a, b);
|
|
2326
3554
|
}
|
|
2327
3555
|
throw new Error("Invalid arguments for createOrUpdate method");
|
|
2328
3556
|
});
|
|
@@ -2333,16 +3561,28 @@ class RestRepository extends Query {
|
|
|
2333
3561
|
if (Array.isArray(a)) {
|
|
2334
3562
|
if (a.length === 0)
|
|
2335
3563
|
return [];
|
|
2336
|
-
const
|
|
2337
|
-
|
|
3564
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
|
3565
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
3566
|
+
const result = await this.read(ids, columns);
|
|
3567
|
+
return result;
|
|
2338
3568
|
}
|
|
2339
3569
|
if (isString(a) && isObject(b)) {
|
|
2340
|
-
|
|
2341
|
-
|
|
3570
|
+
if (a === "")
|
|
3571
|
+
throw new Error("The id can't be empty");
|
|
3572
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3573
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
|
2342
3574
|
}
|
|
2343
3575
|
if (isObject(a) && isString(a.id)) {
|
|
2344
|
-
|
|
2345
|
-
|
|
3576
|
+
if (a.id === "")
|
|
3577
|
+
throw new Error("The id can't be empty");
|
|
3578
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
|
3579
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
|
3580
|
+
}
|
|
3581
|
+
if (!isDefined(a) && isObject(b)) {
|
|
3582
|
+
return await this.create(b, c);
|
|
3583
|
+
}
|
|
3584
|
+
if (isObject(a) && !isDefined(a.id)) {
|
|
3585
|
+
return await this.create(a, b);
|
|
2346
3586
|
}
|
|
2347
3587
|
throw new Error("Invalid arguments for createOrReplace method");
|
|
2348
3588
|
});
|
|
@@ -2352,10 +3592,17 @@ class RestRepository extends Query {
|
|
|
2352
3592
|
if (Array.isArray(a)) {
|
|
2353
3593
|
if (a.length === 0)
|
|
2354
3594
|
return [];
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
3595
|
+
const ids = a.map((o) => {
|
|
3596
|
+
if (isString(o))
|
|
3597
|
+
return o;
|
|
3598
|
+
if (isString(o.id))
|
|
3599
|
+
return o.id;
|
|
3600
|
+
throw new Error("Invalid arguments for delete method");
|
|
3601
|
+
});
|
|
3602
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
|
3603
|
+
const result = await this.read(a, columns);
|
|
3604
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
|
3605
|
+
return result;
|
|
2359
3606
|
}
|
|
2360
3607
|
if (isString(a)) {
|
|
2361
3608
|
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
|
@@ -2386,7 +3633,6 @@ class RestRepository extends Query {
|
|
|
2386
3633
|
}
|
|
2387
3634
|
async search(query, options = {}) {
|
|
2388
3635
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
|
2389
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2390
3636
|
const { records } = await searchTable({
|
|
2391
3637
|
pathParams: {
|
|
2392
3638
|
workspace: "{workspaceId}",
|
|
@@ -2400,9 +3646,33 @@ class RestRepository extends Query {
|
|
|
2400
3646
|
prefix: options.prefix,
|
|
2401
3647
|
highlight: options.highlight,
|
|
2402
3648
|
filter: options.filter,
|
|
2403
|
-
boosters: options.boosters
|
|
3649
|
+
boosters: options.boosters,
|
|
3650
|
+
page: options.page,
|
|
3651
|
+
target: options.target
|
|
3652
|
+
},
|
|
3653
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3654
|
+
});
|
|
3655
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
3656
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
|
3657
|
+
});
|
|
3658
|
+
}
|
|
3659
|
+
async vectorSearch(column, query, options) {
|
|
3660
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
|
3661
|
+
const { records } = await vectorSearchTable({
|
|
3662
|
+
pathParams: {
|
|
3663
|
+
workspace: "{workspaceId}",
|
|
3664
|
+
dbBranchName: "{dbBranch}",
|
|
3665
|
+
region: "{region}",
|
|
3666
|
+
tableName: __privateGet$4(this, _table)
|
|
3667
|
+
},
|
|
3668
|
+
body: {
|
|
3669
|
+
column,
|
|
3670
|
+
queryVector: query,
|
|
3671
|
+
similarityFunction: options?.similarityFunction,
|
|
3672
|
+
size: options?.size,
|
|
3673
|
+
filter: options?.filter
|
|
2404
3674
|
},
|
|
2405
|
-
...
|
|
3675
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2406
3676
|
});
|
|
2407
3677
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2408
3678
|
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
|
@@ -2410,7 +3680,6 @@ class RestRepository extends Query {
|
|
|
2410
3680
|
}
|
|
2411
3681
|
async aggregate(aggs, filter) {
|
|
2412
3682
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
|
2413
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2414
3683
|
const result = await aggregateTable({
|
|
2415
3684
|
pathParams: {
|
|
2416
3685
|
workspace: "{workspaceId}",
|
|
@@ -2419,7 +3688,7 @@ class RestRepository extends Query {
|
|
|
2419
3688
|
tableName: __privateGet$4(this, _table)
|
|
2420
3689
|
},
|
|
2421
3690
|
body: { aggs, filter },
|
|
2422
|
-
...
|
|
3691
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2423
3692
|
});
|
|
2424
3693
|
return result;
|
|
2425
3694
|
});
|
|
@@ -2430,7 +3699,6 @@ class RestRepository extends Query {
|
|
|
2430
3699
|
if (cacheQuery)
|
|
2431
3700
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
|
2432
3701
|
const data = query.getQueryOptions();
|
|
2433
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2434
3702
|
const { meta, records: objects } = await queryTable({
|
|
2435
3703
|
pathParams: {
|
|
2436
3704
|
workspace: "{workspaceId}",
|
|
@@ -2442,14 +3710,21 @@ class RestRepository extends Query {
|
|
|
2442
3710
|
filter: cleanFilter(data.filter),
|
|
2443
3711
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
|
2444
3712
|
page: data.pagination,
|
|
2445
|
-
columns: data.columns ?? ["*"]
|
|
3713
|
+
columns: data.columns ?? ["*"],
|
|
3714
|
+
consistency: data.consistency
|
|
2446
3715
|
},
|
|
2447
3716
|
fetchOptions: data.fetchOptions,
|
|
2448
|
-
...
|
|
3717
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2449
3718
|
});
|
|
2450
3719
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2451
3720
|
const records = objects.map(
|
|
2452
|
-
(record) => initObject(
|
|
3721
|
+
(record) => initObject(
|
|
3722
|
+
__privateGet$4(this, _db),
|
|
3723
|
+
schemaTables,
|
|
3724
|
+
__privateGet$4(this, _table),
|
|
3725
|
+
record,
|
|
3726
|
+
data.columns ?? ["*"]
|
|
3727
|
+
)
|
|
2453
3728
|
);
|
|
2454
3729
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
2455
3730
|
return new Page(query, meta, records);
|
|
@@ -2458,7 +3733,6 @@ class RestRepository extends Query {
|
|
|
2458
3733
|
async summarizeTable(query, summaries, summariesFilter) {
|
|
2459
3734
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
|
2460
3735
|
const data = query.getQueryOptions();
|
|
2461
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2462
3736
|
const result = await summarizeTable({
|
|
2463
3737
|
pathParams: {
|
|
2464
3738
|
workspace: "{workspaceId}",
|
|
@@ -2470,15 +3744,55 @@ class RestRepository extends Query {
|
|
|
2470
3744
|
filter: cleanFilter(data.filter),
|
|
2471
3745
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
|
2472
3746
|
columns: data.columns,
|
|
3747
|
+
consistency: data.consistency,
|
|
2473
3748
|
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
|
2474
3749
|
summaries,
|
|
2475
3750
|
summariesFilter
|
|
2476
3751
|
},
|
|
2477
|
-
...
|
|
3752
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2478
3753
|
});
|
|
2479
|
-
|
|
3754
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
3755
|
+
return {
|
|
3756
|
+
...result,
|
|
3757
|
+
summaries: result.summaries.map(
|
|
3758
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
|
3759
|
+
)
|
|
3760
|
+
};
|
|
2480
3761
|
});
|
|
2481
3762
|
}
|
|
3763
|
+
ask(question, options) {
|
|
3764
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
|
3765
|
+
const params = {
|
|
3766
|
+
pathParams: {
|
|
3767
|
+
workspace: "{workspaceId}",
|
|
3768
|
+
dbBranchName: "{dbBranch}",
|
|
3769
|
+
region: "{region}",
|
|
3770
|
+
tableName: __privateGet$4(this, _table),
|
|
3771
|
+
sessionId: options?.sessionId
|
|
3772
|
+
},
|
|
3773
|
+
body: {
|
|
3774
|
+
...questionParam,
|
|
3775
|
+
rules: options?.rules,
|
|
3776
|
+
searchType: options?.searchType,
|
|
3777
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
|
3778
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
|
3779
|
+
},
|
|
3780
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3781
|
+
};
|
|
3782
|
+
if (options?.onMessage) {
|
|
3783
|
+
fetchSSERequest({
|
|
3784
|
+
endpoint: "dataPlane",
|
|
3785
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
|
3786
|
+
method: "POST",
|
|
3787
|
+
onMessage: (message) => {
|
|
3788
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
|
3789
|
+
},
|
|
3790
|
+
...params
|
|
3791
|
+
});
|
|
3792
|
+
} else {
|
|
3793
|
+
return askTableSession(params);
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
2482
3796
|
}
|
|
2483
3797
|
_table = new WeakMap();
|
|
2484
3798
|
_getFetchProps = new WeakMap();
|
|
@@ -2488,8 +3802,7 @@ _schemaTables$2 = new WeakMap();
|
|
|
2488
3802
|
_trace = new WeakMap();
|
|
2489
3803
|
_insertRecordWithoutId = new WeakSet();
|
|
2490
3804
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2491
|
-
const
|
|
2492
|
-
const record = transformObjectLinks(object);
|
|
3805
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
2493
3806
|
const response = await insertRecord({
|
|
2494
3807
|
pathParams: {
|
|
2495
3808
|
workspace: "{workspaceId}",
|
|
@@ -2499,15 +3812,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
|
2499
3812
|
},
|
|
2500
3813
|
queryParams: { columns },
|
|
2501
3814
|
body: record,
|
|
2502
|
-
...
|
|
3815
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2503
3816
|
});
|
|
2504
3817
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2505
3818
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2506
3819
|
};
|
|
2507
3820
|
_insertRecordWithId = new WeakSet();
|
|
2508
3821
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
|
2509
|
-
|
|
2510
|
-
|
|
3822
|
+
if (!recordId)
|
|
3823
|
+
return null;
|
|
3824
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
2511
3825
|
const response = await insertRecordWithID({
|
|
2512
3826
|
pathParams: {
|
|
2513
3827
|
workspace: "{workspaceId}",
|
|
@@ -2518,36 +3832,44 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
|
2518
3832
|
},
|
|
2519
3833
|
body: record,
|
|
2520
3834
|
queryParams: { createOnly, columns, ifVersion },
|
|
2521
|
-
...
|
|
3835
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2522
3836
|
});
|
|
2523
3837
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2524
3838
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2525
3839
|
};
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
const
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
pathParams: {
|
|
2532
|
-
workspace: "{workspaceId}",
|
|
2533
|
-
dbBranchName: "{dbBranch}",
|
|
2534
|
-
region: "{region}",
|
|
2535
|
-
tableName: __privateGet$4(this, _table)
|
|
2536
|
-
},
|
|
2537
|
-
queryParams: { columns },
|
|
2538
|
-
body: { records },
|
|
2539
|
-
...fetchProps
|
|
3840
|
+
_insertRecords = new WeakSet();
|
|
3841
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
3842
|
+
const operations = await promiseMap(objects, async (object) => {
|
|
3843
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
3844
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
|
2540
3845
|
});
|
|
2541
|
-
|
|
2542
|
-
|
|
3846
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
|
3847
|
+
const ids = [];
|
|
3848
|
+
for (const operations2 of chunkedOperations) {
|
|
3849
|
+
const { results } = await branchTransaction({
|
|
3850
|
+
pathParams: {
|
|
3851
|
+
workspace: "{workspaceId}",
|
|
3852
|
+
dbBranchName: "{dbBranch}",
|
|
3853
|
+
region: "{region}"
|
|
3854
|
+
},
|
|
3855
|
+
body: { operations: operations2 },
|
|
3856
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3857
|
+
});
|
|
3858
|
+
for (const result of results) {
|
|
3859
|
+
if (result.operation === "insert") {
|
|
3860
|
+
ids.push(result.id);
|
|
3861
|
+
} else {
|
|
3862
|
+
ids.push(null);
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
2543
3865
|
}
|
|
2544
|
-
|
|
2545
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
|
3866
|
+
return ids;
|
|
2546
3867
|
};
|
|
2547
3868
|
_updateRecordWithID = new WeakSet();
|
|
2548
3869
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
|
2549
|
-
|
|
2550
|
-
|
|
3870
|
+
if (!recordId)
|
|
3871
|
+
return null;
|
|
3872
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
2551
3873
|
try {
|
|
2552
3874
|
const response = await updateRecordWithID({
|
|
2553
3875
|
pathParams: {
|
|
@@ -2559,7 +3881,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
|
2559
3881
|
},
|
|
2560
3882
|
queryParams: { columns, ifVersion },
|
|
2561
3883
|
body: record,
|
|
2562
|
-
...
|
|
3884
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2563
3885
|
});
|
|
2564
3886
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2565
3887
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
@@ -2570,9 +3892,38 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
|
2570
3892
|
throw e;
|
|
2571
3893
|
}
|
|
2572
3894
|
};
|
|
3895
|
+
_updateRecords = new WeakSet();
|
|
3896
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
3897
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
|
3898
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
|
3899
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
|
3900
|
+
});
|
|
3901
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
|
3902
|
+
const ids = [];
|
|
3903
|
+
for (const operations2 of chunkedOperations) {
|
|
3904
|
+
const { results } = await branchTransaction({
|
|
3905
|
+
pathParams: {
|
|
3906
|
+
workspace: "{workspaceId}",
|
|
3907
|
+
dbBranchName: "{dbBranch}",
|
|
3908
|
+
region: "{region}"
|
|
3909
|
+
},
|
|
3910
|
+
body: { operations: operations2 },
|
|
3911
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3912
|
+
});
|
|
3913
|
+
for (const result of results) {
|
|
3914
|
+
if (result.operation === "update") {
|
|
3915
|
+
ids.push(result.id);
|
|
3916
|
+
} else {
|
|
3917
|
+
ids.push(null);
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
return ids;
|
|
3922
|
+
};
|
|
2573
3923
|
_upsertRecordWithID = new WeakSet();
|
|
2574
3924
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
|
2575
|
-
|
|
3925
|
+
if (!recordId)
|
|
3926
|
+
return null;
|
|
2576
3927
|
const response = await upsertRecordWithID({
|
|
2577
3928
|
pathParams: {
|
|
2578
3929
|
workspace: "{workspaceId}",
|
|
@@ -2583,14 +3934,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
|
2583
3934
|
},
|
|
2584
3935
|
queryParams: { columns, ifVersion },
|
|
2585
3936
|
body: object,
|
|
2586
|
-
...
|
|
3937
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2587
3938
|
});
|
|
2588
3939
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2589
3940
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2590
3941
|
};
|
|
2591
3942
|
_deleteRecord = new WeakSet();
|
|
2592
3943
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2593
|
-
|
|
3944
|
+
if (!recordId)
|
|
3945
|
+
return null;
|
|
2594
3946
|
try {
|
|
2595
3947
|
const response = await deleteRecord({
|
|
2596
3948
|
pathParams: {
|
|
@@ -2601,7 +3953,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
|
2601
3953
|
recordId
|
|
2602
3954
|
},
|
|
2603
3955
|
queryParams: { columns },
|
|
2604
|
-
...
|
|
3956
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2605
3957
|
});
|
|
2606
3958
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2607
3959
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
@@ -2612,17 +3964,36 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
|
2612
3964
|
throw e;
|
|
2613
3965
|
}
|
|
2614
3966
|
};
|
|
3967
|
+
_deleteRecords = new WeakSet();
|
|
3968
|
+
deleteRecords_fn = async function(recordIds) {
|
|
3969
|
+
const chunkedOperations = chunk(
|
|
3970
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
|
3971
|
+
BULK_OPERATION_MAX_SIZE
|
|
3972
|
+
);
|
|
3973
|
+
for (const operations of chunkedOperations) {
|
|
3974
|
+
await branchTransaction({
|
|
3975
|
+
pathParams: {
|
|
3976
|
+
workspace: "{workspaceId}",
|
|
3977
|
+
dbBranchName: "{dbBranch}",
|
|
3978
|
+
region: "{region}"
|
|
3979
|
+
},
|
|
3980
|
+
body: { operations },
|
|
3981
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
3982
|
+
});
|
|
3983
|
+
}
|
|
3984
|
+
};
|
|
2615
3985
|
_setCacheQuery = new WeakSet();
|
|
2616
3986
|
setCacheQuery_fn = async function(query, meta, records) {
|
|
2617
|
-
await __privateGet$4(this, _cache)
|
|
3987
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
|
2618
3988
|
};
|
|
2619
3989
|
_getCacheQuery = new WeakSet();
|
|
2620
3990
|
getCacheQuery_fn = async function(query) {
|
|
2621
3991
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
|
2622
|
-
const result = await __privateGet$4(this, _cache)
|
|
3992
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
|
2623
3993
|
if (!result)
|
|
2624
3994
|
return null;
|
|
2625
|
-
const
|
|
3995
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
|
3996
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
|
2626
3997
|
if (ttl < 0)
|
|
2627
3998
|
return null;
|
|
2628
3999
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
|
@@ -2632,39 +4003,66 @@ _getSchemaTables$1 = new WeakSet();
|
|
|
2632
4003
|
getSchemaTables_fn$1 = async function() {
|
|
2633
4004
|
if (__privateGet$4(this, _schemaTables$2))
|
|
2634
4005
|
return __privateGet$4(this, _schemaTables$2);
|
|
2635
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
2636
4006
|
const { schema } = await getBranchDetails({
|
|
2637
4007
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
2638
|
-
...
|
|
4008
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
|
2639
4009
|
});
|
|
2640
4010
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
|
2641
4011
|
return schema.tables;
|
|
2642
4012
|
};
|
|
2643
|
-
|
|
2644
|
-
|
|
4013
|
+
_transformObjectToApi = new WeakSet();
|
|
4014
|
+
transformObjectToApi_fn = async function(object) {
|
|
4015
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
4016
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
|
4017
|
+
if (!schema)
|
|
4018
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
|
4019
|
+
const result = {};
|
|
4020
|
+
for (const [key, value] of Object.entries(object)) {
|
|
2645
4021
|
if (key === "xata")
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
4022
|
+
continue;
|
|
4023
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
|
4024
|
+
switch (type) {
|
|
4025
|
+
case "link": {
|
|
4026
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
|
4027
|
+
break;
|
|
4028
|
+
}
|
|
4029
|
+
case "datetime": {
|
|
4030
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
|
4031
|
+
break;
|
|
4032
|
+
}
|
|
4033
|
+
case `file`:
|
|
4034
|
+
result[key] = await parseInputFileEntry(value);
|
|
4035
|
+
break;
|
|
4036
|
+
case "file[]":
|
|
4037
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
|
4038
|
+
break;
|
|
4039
|
+
case "json":
|
|
4040
|
+
result[key] = stringifyJson(value);
|
|
4041
|
+
break;
|
|
4042
|
+
default:
|
|
4043
|
+
result[key] = value;
|
|
4044
|
+
}
|
|
4045
|
+
}
|
|
4046
|
+
return result;
|
|
2649
4047
|
};
|
|
2650
4048
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2651
|
-
const
|
|
4049
|
+
const data = {};
|
|
2652
4050
|
const { xata, ...rest } = object ?? {};
|
|
2653
|
-
Object.assign(
|
|
4051
|
+
Object.assign(data, rest);
|
|
2654
4052
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
|
2655
4053
|
if (!columns)
|
|
2656
4054
|
console.error(`Table ${table} not found in schema`);
|
|
2657
4055
|
for (const column of columns ?? []) {
|
|
2658
4056
|
if (!isValidColumn(selectedColumns, column))
|
|
2659
4057
|
continue;
|
|
2660
|
-
const value =
|
|
4058
|
+
const value = data[column.name];
|
|
2661
4059
|
switch (column.type) {
|
|
2662
4060
|
case "datetime": {
|
|
2663
|
-
const date = value !== void 0 ? new Date(value) :
|
|
2664
|
-
if (date && isNaN(date.getTime())) {
|
|
4061
|
+
const date = value !== void 0 ? new Date(value) : null;
|
|
4062
|
+
if (date !== null && isNaN(date.getTime())) {
|
|
2665
4063
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
|
2666
|
-
} else
|
|
2667
|
-
|
|
4064
|
+
} else {
|
|
4065
|
+
data[column.name] = date;
|
|
2668
4066
|
}
|
|
2669
4067
|
break;
|
|
2670
4068
|
}
|
|
@@ -2677,54 +4075,77 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
|
2677
4075
|
if (item === column.name) {
|
|
2678
4076
|
return [...acc, "*"];
|
|
2679
4077
|
}
|
|
2680
|
-
if (item.startsWith(`${column.name}.`)) {
|
|
4078
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
|
2681
4079
|
const [, ...path] = item.split(".");
|
|
2682
4080
|
return [...acc, path.join(".")];
|
|
2683
4081
|
}
|
|
2684
4082
|
return acc;
|
|
2685
4083
|
}, []);
|
|
2686
|
-
|
|
4084
|
+
data[column.name] = initObject(
|
|
4085
|
+
db,
|
|
4086
|
+
schemaTables,
|
|
4087
|
+
linkTable,
|
|
4088
|
+
value,
|
|
4089
|
+
selectedLinkColumns
|
|
4090
|
+
);
|
|
2687
4091
|
} else {
|
|
2688
|
-
|
|
4092
|
+
data[column.name] = null;
|
|
2689
4093
|
}
|
|
2690
4094
|
break;
|
|
2691
4095
|
}
|
|
4096
|
+
case "file":
|
|
4097
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
|
4098
|
+
break;
|
|
4099
|
+
case "file[]":
|
|
4100
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
|
4101
|
+
break;
|
|
4102
|
+
case "json":
|
|
4103
|
+
data[column.name] = parseJson(value);
|
|
4104
|
+
break;
|
|
2692
4105
|
default:
|
|
2693
|
-
|
|
4106
|
+
data[column.name] = value ?? null;
|
|
2694
4107
|
if (column.notNull === true && value === null) {
|
|
2695
4108
|
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
|
2696
4109
|
}
|
|
2697
4110
|
break;
|
|
2698
4111
|
}
|
|
2699
4112
|
}
|
|
2700
|
-
|
|
2701
|
-
|
|
4113
|
+
const record = { ...data };
|
|
4114
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
|
4115
|
+
record.read = function(columns2) {
|
|
4116
|
+
return db[table].read(record["id"], columns2);
|
|
2702
4117
|
};
|
|
2703
|
-
|
|
2704
|
-
const columns2 =
|
|
4118
|
+
record.update = function(data2, b, c) {
|
|
4119
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
|
2705
4120
|
const ifVersion = parseIfVersion(b, c);
|
|
2706
|
-
return db[table].update(
|
|
4121
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
|
2707
4122
|
};
|
|
2708
|
-
|
|
2709
|
-
const columns2 =
|
|
4123
|
+
record.replace = function(data2, b, c) {
|
|
4124
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
|
2710
4125
|
const ifVersion = parseIfVersion(b, c);
|
|
2711
|
-
return db[table].createOrReplace(
|
|
4126
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
|
4127
|
+
};
|
|
4128
|
+
record.delete = function() {
|
|
4129
|
+
return db[table].delete(record["id"]);
|
|
2712
4130
|
};
|
|
2713
|
-
|
|
2714
|
-
|
|
4131
|
+
if (metadata !== void 0) {
|
|
4132
|
+
record.xata = Object.freeze(metadata);
|
|
4133
|
+
}
|
|
4134
|
+
record.getMetadata = function() {
|
|
4135
|
+
return record.xata;
|
|
4136
|
+
};
|
|
4137
|
+
record.toSerializable = function() {
|
|
4138
|
+
return JSON.parse(JSON.stringify(record));
|
|
2715
4139
|
};
|
|
2716
|
-
|
|
2717
|
-
return
|
|
4140
|
+
record.toString = function() {
|
|
4141
|
+
return JSON.stringify(record);
|
|
2718
4142
|
};
|
|
2719
|
-
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
|
2720
|
-
Object.defineProperty(
|
|
4143
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
|
4144
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
|
2721
4145
|
}
|
|
2722
|
-
Object.freeze(
|
|
2723
|
-
return
|
|
4146
|
+
Object.freeze(record);
|
|
4147
|
+
return record;
|
|
2724
4148
|
};
|
|
2725
|
-
function isResponseWithRecords(value) {
|
|
2726
|
-
return isObject(value) && Array.isArray(value.records);
|
|
2727
|
-
}
|
|
2728
4149
|
function extractId(value) {
|
|
2729
4150
|
if (isString(value))
|
|
2730
4151
|
return value;
|
|
@@ -2735,11 +4156,7 @@ function extractId(value) {
|
|
|
2735
4156
|
function isValidColumn(columns, column) {
|
|
2736
4157
|
if (columns.includes("*"))
|
|
2737
4158
|
return true;
|
|
2738
|
-
|
|
2739
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
|
2740
|
-
return linkColumns.length > 0;
|
|
2741
|
-
}
|
|
2742
|
-
return columns.includes(column.name);
|
|
4159
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
|
2743
4160
|
}
|
|
2744
4161
|
function parseIfVersion(...args) {
|
|
2745
4162
|
for (const arg of args) {
|
|
@@ -2816,10 +4233,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
|
2816
4233
|
const startsWith = (value) => ({ $startsWith: value });
|
|
2817
4234
|
const endsWith = (value) => ({ $endsWith: value });
|
|
2818
4235
|
const pattern = (value) => ({ $pattern: value });
|
|
4236
|
+
const iPattern = (value) => ({ $iPattern: value });
|
|
2819
4237
|
const is = (value) => ({ $is: value });
|
|
2820
4238
|
const equals = is;
|
|
2821
4239
|
const isNot = (value) => ({ $isNot: value });
|
|
2822
4240
|
const contains = (value) => ({ $contains: value });
|
|
4241
|
+
const iContains = (value) => ({ $iContains: value });
|
|
2823
4242
|
const includes = (value) => ({ $includes: value });
|
|
2824
4243
|
const includesAll = (value) => ({ $includesAll: value });
|
|
2825
4244
|
const includesNone = (value) => ({ $includesNone: value });
|
|
@@ -2845,13 +4264,13 @@ var __privateSet$2 = (obj, member, value, setter) => {
|
|
|
2845
4264
|
};
|
|
2846
4265
|
var _tables, _schemaTables$1;
|
|
2847
4266
|
class SchemaPlugin extends XataPlugin {
|
|
2848
|
-
constructor(
|
|
4267
|
+
constructor() {
|
|
2849
4268
|
super();
|
|
2850
4269
|
__privateAdd$2(this, _tables, {});
|
|
2851
4270
|
__privateAdd$2(this, _schemaTables$1, void 0);
|
|
2852
|
-
__privateSet$2(this, _schemaTables$1, schemaTables);
|
|
2853
4271
|
}
|
|
2854
4272
|
build(pluginOptions) {
|
|
4273
|
+
__privateSet$2(this, _schemaTables$1, pluginOptions.tables);
|
|
2855
4274
|
const db = new Proxy(
|
|
2856
4275
|
{},
|
|
2857
4276
|
{
|
|
@@ -2875,6 +4294,80 @@ class SchemaPlugin extends XataPlugin {
|
|
|
2875
4294
|
_tables = new WeakMap();
|
|
2876
4295
|
_schemaTables$1 = new WeakMap();
|
|
2877
4296
|
|
|
4297
|
+
class FilesPlugin extends XataPlugin {
|
|
4298
|
+
build(pluginOptions) {
|
|
4299
|
+
return {
|
|
4300
|
+
download: async (location) => {
|
|
4301
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
|
4302
|
+
return await getFileItem({
|
|
4303
|
+
pathParams: {
|
|
4304
|
+
workspace: "{workspaceId}",
|
|
4305
|
+
dbBranchName: "{dbBranch}",
|
|
4306
|
+
region: "{region}",
|
|
4307
|
+
tableName: table ?? "",
|
|
4308
|
+
recordId: record ?? "",
|
|
4309
|
+
columnName: column ?? "",
|
|
4310
|
+
fileId
|
|
4311
|
+
},
|
|
4312
|
+
...pluginOptions,
|
|
4313
|
+
rawResponse: true
|
|
4314
|
+
});
|
|
4315
|
+
},
|
|
4316
|
+
upload: async (location, file, options) => {
|
|
4317
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
|
4318
|
+
const resolvedFile = await file;
|
|
4319
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
|
4320
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
|
4321
|
+
return await putFileItem({
|
|
4322
|
+
...pluginOptions,
|
|
4323
|
+
pathParams: {
|
|
4324
|
+
workspace: "{workspaceId}",
|
|
4325
|
+
dbBranchName: "{dbBranch}",
|
|
4326
|
+
region: "{region}",
|
|
4327
|
+
tableName: table ?? "",
|
|
4328
|
+
recordId: record ?? "",
|
|
4329
|
+
columnName: column ?? "",
|
|
4330
|
+
fileId
|
|
4331
|
+
},
|
|
4332
|
+
body,
|
|
4333
|
+
headers: { "Content-Type": contentType }
|
|
4334
|
+
});
|
|
4335
|
+
},
|
|
4336
|
+
delete: async (location) => {
|
|
4337
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
|
4338
|
+
return await deleteFileItem({
|
|
4339
|
+
pathParams: {
|
|
4340
|
+
workspace: "{workspaceId}",
|
|
4341
|
+
dbBranchName: "{dbBranch}",
|
|
4342
|
+
region: "{region}",
|
|
4343
|
+
tableName: table ?? "",
|
|
4344
|
+
recordId: record ?? "",
|
|
4345
|
+
columnName: column ?? "",
|
|
4346
|
+
fileId
|
|
4347
|
+
},
|
|
4348
|
+
...pluginOptions
|
|
4349
|
+
});
|
|
4350
|
+
}
|
|
4351
|
+
};
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
function getContentType(file) {
|
|
4355
|
+
if (typeof file === "string") {
|
|
4356
|
+
return "text/plain";
|
|
4357
|
+
}
|
|
4358
|
+
if ("mediaType" in file) {
|
|
4359
|
+
return file.mediaType;
|
|
4360
|
+
}
|
|
4361
|
+
if (isBlob(file)) {
|
|
4362
|
+
return file.type;
|
|
4363
|
+
}
|
|
4364
|
+
try {
|
|
4365
|
+
return file.type;
|
|
4366
|
+
} catch (e) {
|
|
4367
|
+
}
|
|
4368
|
+
return "application/octet-stream";
|
|
4369
|
+
}
|
|
4370
|
+
|
|
2878
4371
|
var __accessCheck$1 = (obj, member, msg) => {
|
|
2879
4372
|
if (!member.has(obj))
|
|
2880
4373
|
throw TypeError("Cannot " + msg);
|
|
@@ -2899,27 +4392,27 @@ var __privateMethod$1 = (obj, member, method) => {
|
|
|
2899
4392
|
};
|
|
2900
4393
|
var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
|
|
2901
4394
|
class SearchPlugin extends XataPlugin {
|
|
2902
|
-
constructor(db
|
|
4395
|
+
constructor(db) {
|
|
2903
4396
|
super();
|
|
2904
4397
|
this.db = db;
|
|
2905
4398
|
__privateAdd$1(this, _search);
|
|
2906
4399
|
__privateAdd$1(this, _getSchemaTables);
|
|
2907
4400
|
__privateAdd$1(this, _schemaTables, void 0);
|
|
2908
|
-
__privateSet$1(this, _schemaTables, schemaTables);
|
|
2909
4401
|
}
|
|
2910
|
-
build(
|
|
4402
|
+
build(pluginOptions) {
|
|
4403
|
+
__privateSet$1(this, _schemaTables, pluginOptions.tables);
|
|
2911
4404
|
return {
|
|
2912
4405
|
all: async (query, options = {}) => {
|
|
2913
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
|
2914
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
|
4406
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
|
4407
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
|
2915
4408
|
return records.map((record) => {
|
|
2916
4409
|
const { table = "orphan" } = record.xata;
|
|
2917
4410
|
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
|
2918
4411
|
});
|
|
2919
4412
|
},
|
|
2920
4413
|
byTable: async (query, options = {}) => {
|
|
2921
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
|
2922
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
|
4414
|
+
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
|
4415
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
|
2923
4416
|
return records.reduce((acc, record) => {
|
|
2924
4417
|
const { table = "orphan" } = record.xata;
|
|
2925
4418
|
const items = acc[table] ?? [];
|
|
@@ -2932,113 +4425,112 @@ class SearchPlugin extends XataPlugin {
|
|
|
2932
4425
|
}
|
|
2933
4426
|
_schemaTables = new WeakMap();
|
|
2934
4427
|
_search = new WeakSet();
|
|
2935
|
-
search_fn = async function(query, options,
|
|
2936
|
-
const
|
|
2937
|
-
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
|
4428
|
+
search_fn = async function(query, options, pluginOptions) {
|
|
4429
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
|
2938
4430
|
const { records } = await searchBranch({
|
|
2939
4431
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
2940
|
-
|
|
2941
|
-
|
|
4432
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
|
4433
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
|
4434
|
+
...pluginOptions
|
|
2942
4435
|
});
|
|
2943
4436
|
return records;
|
|
2944
4437
|
};
|
|
2945
4438
|
_getSchemaTables = new WeakSet();
|
|
2946
|
-
getSchemaTables_fn = async function(
|
|
4439
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
|
2947
4440
|
if (__privateGet$1(this, _schemaTables))
|
|
2948
4441
|
return __privateGet$1(this, _schemaTables);
|
|
2949
|
-
const fetchProps = await getFetchProps();
|
|
2950
4442
|
const { schema } = await getBranchDetails({
|
|
2951
4443
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
2952
|
-
...
|
|
4444
|
+
...pluginOptions
|
|
2953
4445
|
});
|
|
2954
4446
|
__privateSet$1(this, _schemaTables, schema.tables);
|
|
2955
4447
|
return schema.tables;
|
|
2956
4448
|
};
|
|
2957
4449
|
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
}
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
}
|
|
2977
|
-
async function resolveXataBranch(gitBranch, options) {
|
|
2978
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
2979
|
-
const apiKey = options?.apiKey || getAPIKey();
|
|
2980
|
-
if (!databaseURL)
|
|
2981
|
-
throw new Error(
|
|
2982
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
2983
|
-
);
|
|
2984
|
-
if (!apiKey)
|
|
2985
|
-
throw new Error(
|
|
2986
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
2987
|
-
);
|
|
2988
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
|
2989
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
|
2990
|
-
if (!urlParts)
|
|
2991
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
|
2992
|
-
const { workspace, region } = urlParts;
|
|
2993
|
-
const { fallbackBranch } = getEnvironment();
|
|
2994
|
-
const { branch } = await resolveBranch({
|
|
2995
|
-
apiKey,
|
|
2996
|
-
apiUrl: databaseURL,
|
|
2997
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
2998
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
|
2999
|
-
pathParams: { dbName, workspace, region },
|
|
3000
|
-
queryParams: { gitBranch, fallbackBranch },
|
|
3001
|
-
trace: defaultTrace
|
|
3002
|
-
});
|
|
3003
|
-
return branch;
|
|
3004
|
-
}
|
|
3005
|
-
async function getDatabaseBranch(branch, options) {
|
|
3006
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
3007
|
-
const apiKey = options?.apiKey || getAPIKey();
|
|
3008
|
-
if (!databaseURL)
|
|
3009
|
-
throw new Error(
|
|
3010
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
|
3011
|
-
);
|
|
3012
|
-
if (!apiKey)
|
|
3013
|
-
throw new Error(
|
|
3014
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
|
3015
|
-
);
|
|
3016
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
|
3017
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
|
3018
|
-
if (!urlParts)
|
|
3019
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
|
3020
|
-
const { workspace, region } = urlParts;
|
|
3021
|
-
try {
|
|
3022
|
-
return await getBranchDetails({
|
|
3023
|
-
apiKey,
|
|
3024
|
-
apiUrl: databaseURL,
|
|
3025
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
3026
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
|
3027
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
|
3028
|
-
trace: defaultTrace
|
|
3029
|
-
});
|
|
3030
|
-
} catch (err) {
|
|
3031
|
-
if (isObject(err) && err.status === 404)
|
|
3032
|
-
return null;
|
|
3033
|
-
throw err;
|
|
4450
|
+
function escapeElement(elementRepresentation) {
|
|
4451
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
4452
|
+
return '"' + escaped + '"';
|
|
4453
|
+
}
|
|
4454
|
+
function arrayString(val) {
|
|
4455
|
+
let result = "{";
|
|
4456
|
+
for (let i = 0; i < val.length; i++) {
|
|
4457
|
+
if (i > 0) {
|
|
4458
|
+
result = result + ",";
|
|
4459
|
+
}
|
|
4460
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
|
4461
|
+
result = result + "NULL";
|
|
4462
|
+
} else if (Array.isArray(val[i])) {
|
|
4463
|
+
result = result + arrayString(val[i]);
|
|
4464
|
+
} else if (val[i] instanceof Buffer) {
|
|
4465
|
+
result += "\\\\x" + val[i].toString("hex");
|
|
4466
|
+
} else {
|
|
4467
|
+
result += escapeElement(prepareValue(val[i]));
|
|
4468
|
+
}
|
|
3034
4469
|
}
|
|
4470
|
+
result = result + "}";
|
|
4471
|
+
return result;
|
|
3035
4472
|
}
|
|
3036
|
-
function
|
|
4473
|
+
function prepareValue(value) {
|
|
4474
|
+
if (!isDefined(value))
|
|
4475
|
+
return null;
|
|
4476
|
+
if (value instanceof Date) {
|
|
4477
|
+
return value.toISOString();
|
|
4478
|
+
}
|
|
4479
|
+
if (Array.isArray(value)) {
|
|
4480
|
+
return arrayString(value);
|
|
4481
|
+
}
|
|
4482
|
+
if (isObject(value)) {
|
|
4483
|
+
return JSON.stringify(value);
|
|
4484
|
+
}
|
|
3037
4485
|
try {
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
4486
|
+
return value.toString();
|
|
4487
|
+
} catch (e) {
|
|
4488
|
+
return value;
|
|
4489
|
+
}
|
|
4490
|
+
}
|
|
4491
|
+
function prepareParams(param1, param2) {
|
|
4492
|
+
if (isString(param1)) {
|
|
4493
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
|
4494
|
+
}
|
|
4495
|
+
if (isStringArray(param1)) {
|
|
4496
|
+
const statement = param1.reduce((acc, curr, index) => {
|
|
4497
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
|
4498
|
+
}, "");
|
|
4499
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
|
4500
|
+
}
|
|
4501
|
+
if (isObject(param1)) {
|
|
4502
|
+
const { statement, params, consistency } = param1;
|
|
4503
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
|
4504
|
+
}
|
|
4505
|
+
throw new Error("Invalid query");
|
|
4506
|
+
}
|
|
4507
|
+
|
|
4508
|
+
class SQLPlugin extends XataPlugin {
|
|
4509
|
+
build(pluginOptions) {
|
|
4510
|
+
return async (param1, ...param2) => {
|
|
4511
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
|
4512
|
+
const { records, warning } = await sqlQuery({
|
|
4513
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
4514
|
+
body: { statement, params, consistency },
|
|
4515
|
+
...pluginOptions
|
|
4516
|
+
});
|
|
4517
|
+
return { records, warning };
|
|
4518
|
+
};
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
|
|
4522
|
+
class TransactionPlugin extends XataPlugin {
|
|
4523
|
+
build(pluginOptions) {
|
|
4524
|
+
return {
|
|
4525
|
+
run: async (operations) => {
|
|
4526
|
+
const response = await branchTransaction({
|
|
4527
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
|
4528
|
+
body: { operations },
|
|
4529
|
+
...pluginOptions
|
|
4530
|
+
});
|
|
4531
|
+
return response;
|
|
4532
|
+
}
|
|
4533
|
+
};
|
|
3042
4534
|
}
|
|
3043
4535
|
}
|
|
3044
4536
|
|
|
@@ -3065,46 +4557,45 @@ var __privateMethod = (obj, member, method) => {
|
|
|
3065
4557
|
return method;
|
|
3066
4558
|
};
|
|
3067
4559
|
const buildClient = (plugins) => {
|
|
3068
|
-
var
|
|
4560
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
|
3069
4561
|
return _a = class {
|
|
3070
|
-
constructor(options = {},
|
|
4562
|
+
constructor(options = {}, tables) {
|
|
3071
4563
|
__privateAdd(this, _parseOptions);
|
|
3072
4564
|
__privateAdd(this, _getFetchProps);
|
|
3073
|
-
__privateAdd(this, _evaluateBranch);
|
|
3074
|
-
__privateAdd(this, _branch, void 0);
|
|
3075
4565
|
__privateAdd(this, _options, void 0);
|
|
3076
4566
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
|
3077
4567
|
__privateSet(this, _options, safeOptions);
|
|
3078
4568
|
const pluginOptions = {
|
|
3079
|
-
|
|
4569
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
|
3080
4570
|
cache: safeOptions.cache,
|
|
3081
|
-
|
|
4571
|
+
host: safeOptions.host,
|
|
4572
|
+
tables
|
|
3082
4573
|
};
|
|
3083
|
-
const db = new SchemaPlugin(
|
|
3084
|
-
const search = new SearchPlugin(db
|
|
4574
|
+
const db = new SchemaPlugin().build(pluginOptions);
|
|
4575
|
+
const search = new SearchPlugin(db).build(pluginOptions);
|
|
4576
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
|
4577
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
|
4578
|
+
const files = new FilesPlugin().build(pluginOptions);
|
|
4579
|
+
this.schema = { tables };
|
|
3085
4580
|
this.db = db;
|
|
3086
4581
|
this.search = search;
|
|
4582
|
+
this.transactions = transactions;
|
|
4583
|
+
this.sql = sql;
|
|
4584
|
+
this.files = files;
|
|
3087
4585
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
|
3088
4586
|
if (namespace === void 0)
|
|
3089
4587
|
continue;
|
|
3090
|
-
|
|
3091
|
-
if (result instanceof Promise) {
|
|
3092
|
-
void result.then((namespace2) => {
|
|
3093
|
-
this[key] = namespace2;
|
|
3094
|
-
});
|
|
3095
|
-
} else {
|
|
3096
|
-
this[key] = result;
|
|
3097
|
-
}
|
|
4588
|
+
this[key] = namespace.build(pluginOptions);
|
|
3098
4589
|
}
|
|
3099
4590
|
}
|
|
3100
4591
|
async getConfig() {
|
|
3101
4592
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
|
3102
|
-
const branch =
|
|
4593
|
+
const branch = __privateGet(this, _options).branch;
|
|
3103
4594
|
return { databaseURL, branch };
|
|
3104
4595
|
}
|
|
3105
|
-
},
|
|
4596
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
|
3106
4597
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
|
3107
|
-
const isBrowser = typeof window !== "undefined";
|
|
4598
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
|
3108
4599
|
if (isBrowser && !enableBrowser) {
|
|
3109
4600
|
throw new Error(
|
|
3110
4601
|
"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."
|
|
@@ -3115,46 +4606,73 @@ const buildClient = (plugins) => {
|
|
|
3115
4606
|
const apiKey = options?.apiKey || getAPIKey();
|
|
3116
4607
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
|
3117
4608
|
const trace = options?.trace ?? defaultTrace;
|
|
3118
|
-
const
|
|
4609
|
+
const clientName = options?.clientName;
|
|
4610
|
+
const host = options?.host ?? "production";
|
|
4611
|
+
const xataAgentExtra = options?.xataAgentExtra;
|
|
3119
4612
|
if (!apiKey) {
|
|
3120
4613
|
throw new Error("Option apiKey is required");
|
|
3121
4614
|
}
|
|
3122
4615
|
if (!databaseURL) {
|
|
3123
4616
|
throw new Error("Option databaseURL is required");
|
|
3124
4617
|
}
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
const
|
|
3128
|
-
if (
|
|
3129
|
-
|
|
4618
|
+
const envBranch = getBranch();
|
|
4619
|
+
const previewBranch = getPreviewBranch();
|
|
4620
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
|
4621
|
+
if (!!previewBranch && branch !== previewBranch) {
|
|
4622
|
+
console.warn(
|
|
4623
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
|
4624
|
+
);
|
|
4625
|
+
} else if (!!envBranch && branch !== envBranch) {
|
|
4626
|
+
console.warn(
|
|
4627
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
|
4628
|
+
);
|
|
4629
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
|
4630
|
+
console.warn(
|
|
4631
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
|
4632
|
+
);
|
|
4633
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
|
4634
|
+
console.warn(
|
|
4635
|
+
`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.`
|
|
4636
|
+
);
|
|
4637
|
+
}
|
|
4638
|
+
return {
|
|
4639
|
+
fetch,
|
|
4640
|
+
databaseURL,
|
|
4641
|
+
apiKey,
|
|
4642
|
+
branch,
|
|
4643
|
+
cache,
|
|
4644
|
+
trace,
|
|
4645
|
+
host,
|
|
4646
|
+
clientID: generateUUID(),
|
|
4647
|
+
enableBrowser,
|
|
4648
|
+
clientName,
|
|
4649
|
+
xataAgentExtra
|
|
4650
|
+
};
|
|
4651
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
|
4652
|
+
fetch,
|
|
4653
|
+
apiKey,
|
|
4654
|
+
databaseURL,
|
|
4655
|
+
branch,
|
|
4656
|
+
trace,
|
|
4657
|
+
clientID,
|
|
4658
|
+
clientName,
|
|
4659
|
+
xataAgentExtra
|
|
4660
|
+
}) {
|
|
3130
4661
|
return {
|
|
3131
|
-
|
|
4662
|
+
fetch,
|
|
3132
4663
|
apiKey,
|
|
3133
4664
|
apiUrl: "",
|
|
4665
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
|
3134
4666
|
workspacesApiUrl: (path, params) => {
|
|
3135
4667
|
const hasBranch = params.dbBranchName ?? params.branch;
|
|
3136
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
|
4668
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
|
3137
4669
|
return databaseURL + newPath;
|
|
3138
4670
|
},
|
|
3139
4671
|
trace,
|
|
3140
|
-
clientID
|
|
4672
|
+
clientID,
|
|
4673
|
+
clientName,
|
|
4674
|
+
xataAgentExtra
|
|
3141
4675
|
};
|
|
3142
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
|
3143
|
-
if (__privateGet(this, _branch))
|
|
3144
|
-
return __privateGet(this, _branch);
|
|
3145
|
-
if (param === void 0)
|
|
3146
|
-
return void 0;
|
|
3147
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
|
3148
|
-
const evaluateBranch = async (strategy) => {
|
|
3149
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
|
3150
|
-
};
|
|
3151
|
-
for await (const strategy of strategies) {
|
|
3152
|
-
const branch = await evaluateBranch(strategy);
|
|
3153
|
-
if (branch) {
|
|
3154
|
-
__privateSet(this, _branch, branch);
|
|
3155
|
-
return branch;
|
|
3156
|
-
}
|
|
3157
|
-
}
|
|
3158
4676
|
}, _a;
|
|
3159
4677
|
};
|
|
3160
4678
|
class BaseClient extends buildClient() {
|
|
@@ -3228,7 +4746,7 @@ const deserialize = (json) => {
|
|
|
3228
4746
|
};
|
|
3229
4747
|
|
|
3230
4748
|
function buildWorkerRunner(config) {
|
|
3231
|
-
return function xataWorker(name,
|
|
4749
|
+
return function xataWorker(name, worker) {
|
|
3232
4750
|
return async (...args) => {
|
|
3233
4751
|
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
|
3234
4752
|
const result = await fetch(url, {
|
|
@@ -3249,5 +4767,5 @@ class XataError extends Error {
|
|
|
3249
4767
|
}
|
|
3250
4768
|
}
|
|
3251
4769
|
|
|
3252
|
-
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, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace,
|
|
4770
|
+
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, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, buildWorkerRunner, 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, 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, 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 };
|
|
3253
4771
|
//# sourceMappingURL=index.mjs.map
|