@xata.io/client 0.0.0-alpha.vfe07d64 → 0.0.0-alpha.vfe1509c97472488e5d1b48df0fac2546209a2944
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 +1 -1
- package/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +257 -1
- package/dist/index.cjs +1663 -379
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4618 -2335
- package/dist/index.mjs +1619 -376
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -3
- package/.eslintrc.cjs +0 -13
- package/rollup.config.mjs +0 -44
- package/tsconfig.json +0 -23
package/dist/index.mjs
CHANGED
@@ -18,7 +18,8 @@ const TraceAttributes = {
|
|
18
18
|
HTTP_METHOD: "http.method",
|
19
19
|
HTTP_URL: "http.url",
|
20
20
|
HTTP_ROUTE: "http.route",
|
21
|
-
HTTP_TARGET: "http.target"
|
21
|
+
HTTP_TARGET: "http.target",
|
22
|
+
CLOUDFLARE_RAY_ID: "cf.ray"
|
22
23
|
};
|
23
24
|
|
24
25
|
function notEmpty(value) {
|
@@ -27,8 +28,18 @@ function notEmpty(value) {
|
|
27
28
|
function compact(arr) {
|
28
29
|
return arr.filter(notEmpty);
|
29
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
|
+
}
|
30
41
|
function isObject(value) {
|
31
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
42
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !isBlob(value);
|
32
43
|
}
|
33
44
|
function isDefined(value) {
|
34
45
|
return value !== null && value !== void 0;
|
@@ -83,6 +94,27 @@ function chunk(array, chunkSize) {
|
|
83
94
|
async function timeout(ms) {
|
84
95
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
85
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
|
+
}
|
86
118
|
|
87
119
|
function getEnvironment() {
|
88
120
|
try {
|
@@ -91,8 +123,10 @@ function getEnvironment() {
|
|
91
123
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
92
124
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
93
125
|
branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
|
94
|
-
|
95
|
-
|
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
|
96
130
|
};
|
97
131
|
}
|
98
132
|
} catch (err) {
|
@@ -103,8 +137,10 @@ function getEnvironment() {
|
|
103
137
|
apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
|
104
138
|
databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
|
105
139
|
branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
|
106
|
-
|
107
|
-
|
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")
|
108
144
|
};
|
109
145
|
}
|
110
146
|
} catch (err) {
|
@@ -113,8 +149,10 @@ function getEnvironment() {
|
|
113
149
|
apiKey: getGlobalApiKey(),
|
114
150
|
databaseURL: getGlobalDatabaseURL(),
|
115
151
|
branch: getGlobalBranch(),
|
116
|
-
|
117
|
-
|
152
|
+
deployPreview: void 0,
|
153
|
+
deployPreviewBranch: void 0,
|
154
|
+
vercelGitCommitRef: void 0,
|
155
|
+
vercelGitRepoOwner: void 0
|
118
156
|
};
|
119
157
|
}
|
120
158
|
function getEnableBrowserVariable() {
|
@@ -157,36 +195,48 @@ function getGlobalBranch() {
|
|
157
195
|
return void 0;
|
158
196
|
}
|
159
197
|
}
|
160
|
-
function
|
198
|
+
function getDatabaseURL() {
|
161
199
|
try {
|
162
|
-
|
200
|
+
const { databaseURL } = getEnvironment();
|
201
|
+
return databaseURL;
|
163
202
|
} catch (err) {
|
164
203
|
return void 0;
|
165
204
|
}
|
166
205
|
}
|
167
|
-
|
168
|
-
const cmd = ["git", "branch", "--show-current"];
|
169
|
-
const fullCmd = cmd.join(" ");
|
170
|
-
const nodeModule = ["child", "process"].join("_");
|
171
|
-
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
206
|
+
function getAPIKey() {
|
172
207
|
try {
|
173
|
-
const {
|
174
|
-
return
|
208
|
+
const { apiKey } = getEnvironment();
|
209
|
+
return apiKey;
|
175
210
|
} catch (err) {
|
211
|
+
return void 0;
|
176
212
|
}
|
213
|
+
}
|
214
|
+
function getBranch() {
|
177
215
|
try {
|
178
|
-
|
179
|
-
|
180
|
-
return new TextDecoder().decode(await process2.output()).trim();
|
181
|
-
}
|
216
|
+
const { branch } = getEnvironment();
|
217
|
+
return branch;
|
182
218
|
} catch (err) {
|
219
|
+
return void 0;
|
183
220
|
}
|
184
221
|
}
|
185
|
-
|
186
|
-
|
222
|
+
function buildPreviewBranchName({ org, branch }) {
|
223
|
+
return `preview-${org}-${branch}`;
|
224
|
+
}
|
225
|
+
function getPreviewBranch() {
|
187
226
|
try {
|
188
|
-
const {
|
189
|
-
|
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;
|
190
240
|
} catch (err) {
|
191
241
|
return void 0;
|
192
242
|
}
|
@@ -215,13 +265,13 @@ var __privateMethod$4 = (obj, member, method) => {
|
|
215
265
|
return method;
|
216
266
|
};
|
217
267
|
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
268
|
+
const REQUEST_TIMEOUT = 5 * 60 * 1e3;
|
218
269
|
function getFetchImplementation(userFetch) {
|
219
270
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
220
|
-
const
|
271
|
+
const globalThisFetch = typeof globalThis !== "undefined" ? globalThis.fetch : void 0;
|
272
|
+
const fetchImpl = userFetch ?? globalFetch ?? globalThisFetch;
|
221
273
|
if (!fetchImpl) {
|
222
|
-
throw new Error(
|
223
|
-
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
224
|
-
);
|
274
|
+
throw new Error(`Couldn't find a global \`fetch\`. Pass a fetch implementation explicitly.`);
|
225
275
|
}
|
226
276
|
return fetchImpl;
|
227
277
|
}
|
@@ -246,18 +296,22 @@ class ApiRequestPool {
|
|
246
296
|
return __privateGet$8(this, _fetch);
|
247
297
|
}
|
248
298
|
request(url, options) {
|
249
|
-
const start = new Date();
|
250
|
-
const
|
299
|
+
const start = /* @__PURE__ */ new Date();
|
300
|
+
const fetchImpl = this.getFetch();
|
251
301
|
const runRequest = async (stalled = false) => {
|
252
|
-
const
|
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
|
+
}
|
253
307
|
if (response.status === 429) {
|
254
308
|
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
255
309
|
await timeout(rateLimitReset * 1e3);
|
256
310
|
return await runRequest(true);
|
257
311
|
}
|
258
312
|
if (stalled) {
|
259
|
-
const stalledTime = new Date().getTime() - start.getTime();
|
260
|
-
console.warn(`A request to Xata hit
|
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`);
|
261
315
|
}
|
262
316
|
return response;
|
263
317
|
};
|
@@ -299,7 +353,180 @@ function generateUUID() {
|
|
299
353
|
});
|
300
354
|
}
|
301
355
|
|
302
|
-
|
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
|
+
}
|
528
|
+
|
529
|
+
const VERSION = "0.28.3";
|
303
530
|
|
304
531
|
class ErrorWithCause extends Error {
|
305
532
|
constructor(message, options) {
|
@@ -342,6 +569,67 @@ function getMessage(data) {
|
|
342
569
|
}
|
343
570
|
}
|
344
571
|
|
572
|
+
function getHostUrl(provider, type) {
|
573
|
+
if (isHostProviderAlias(provider)) {
|
574
|
+
return providers[provider][type];
|
575
|
+
} else if (isHostProviderBuilder(provider)) {
|
576
|
+
return provider[type];
|
577
|
+
}
|
578
|
+
throw new Error("Invalid API provider");
|
579
|
+
}
|
580
|
+
const providers = {
|
581
|
+
production: {
|
582
|
+
main: "https://api.xata.io",
|
583
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
584
|
+
},
|
585
|
+
staging: {
|
586
|
+
main: "https://api.staging-xata.dev",
|
587
|
+
workspaces: "https://{workspaceId}.{region}.staging-xata.dev"
|
588
|
+
},
|
589
|
+
dev: {
|
590
|
+
main: "https://api.dev-xata.dev",
|
591
|
+
workspaces: "https://{workspaceId}.{region}.dev-xata.dev"
|
592
|
+
},
|
593
|
+
local: {
|
594
|
+
main: "http://localhost:6001",
|
595
|
+
workspaces: "http://{workspaceId}.{region}.localhost:6001"
|
596
|
+
}
|
597
|
+
};
|
598
|
+
function isHostProviderAlias(alias) {
|
599
|
+
return isString(alias) && Object.keys(providers).includes(alias);
|
600
|
+
}
|
601
|
+
function isHostProviderBuilder(builder) {
|
602
|
+
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
603
|
+
}
|
604
|
+
function parseProviderString(provider = "production") {
|
605
|
+
if (isHostProviderAlias(provider)) {
|
606
|
+
return provider;
|
607
|
+
}
|
608
|
+
const [main, workspaces] = provider.split(",");
|
609
|
+
if (!main || !workspaces)
|
610
|
+
return null;
|
611
|
+
return { main, workspaces };
|
612
|
+
}
|
613
|
+
function buildProviderString(provider) {
|
614
|
+
if (isHostProviderAlias(provider))
|
615
|
+
return provider;
|
616
|
+
return `${provider.main},${provider.workspaces}`;
|
617
|
+
}
|
618
|
+
function parseWorkspacesUrlParts(url) {
|
619
|
+
if (!isString(url))
|
620
|
+
return null;
|
621
|
+
const matches = {
|
622
|
+
production: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/),
|
623
|
+
staging: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.staging-xata\.dev.*/),
|
624
|
+
dev: url.match(/(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.dev-xata\.dev.*/),
|
625
|
+
local: url.match(/(?:https?:\/\/)?([^.]+)(?:\.([^.]+))\.localhost:(\d+)/)
|
626
|
+
};
|
627
|
+
const [host, match] = Object.entries(matches).find(([, match2]) => match2 !== null) ?? [];
|
628
|
+
if (!isHostProviderAlias(host) || !match)
|
629
|
+
return null;
|
630
|
+
return { workspace: match[1], region: match[2], host };
|
631
|
+
}
|
632
|
+
|
345
633
|
const pool = new ApiRequestPool();
|
346
634
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
347
635
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
@@ -357,6 +645,7 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
357
645
|
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
358
646
|
};
|
359
647
|
function buildBaseUrl({
|
648
|
+
method,
|
360
649
|
endpoint,
|
361
650
|
path,
|
362
651
|
workspacesApiUrl,
|
@@ -364,7 +653,24 @@ function buildBaseUrl({
|
|
364
653
|
pathParams = {}
|
365
654
|
}) {
|
366
655
|
if (endpoint === "dataPlane") {
|
367
|
-
|
656
|
+
let url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
657
|
+
if (method.toUpperCase() === "PUT" && [
|
658
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
659
|
+
"/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}"
|
660
|
+
].includes(path)) {
|
661
|
+
const { host } = parseWorkspacesUrlParts(url) ?? {};
|
662
|
+
switch (host) {
|
663
|
+
case "production":
|
664
|
+
url = url.replace("xata.sh", "upload.xata.sh");
|
665
|
+
break;
|
666
|
+
case "staging":
|
667
|
+
url = url.replace("staging-xata.dev", "upload.staging-xata.dev");
|
668
|
+
break;
|
669
|
+
case "dev":
|
670
|
+
url = url.replace("dev-xata.dev", "upload.dev-xata.dev");
|
671
|
+
break;
|
672
|
+
}
|
673
|
+
}
|
368
674
|
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
369
675
|
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
370
676
|
}
|
@@ -375,6 +681,18 @@ function hostHeader(url) {
|
|
375
681
|
const { groups } = pattern.exec(url) ?? {};
|
376
682
|
return groups?.host ? { Host: groups.host } : {};
|
377
683
|
}
|
684
|
+
async function parseBody(body, headers) {
|
685
|
+
if (!isDefined(body))
|
686
|
+
return void 0;
|
687
|
+
if (isBlob(body) || typeof body.text === "function") {
|
688
|
+
return body;
|
689
|
+
}
|
690
|
+
const { "Content-Type": contentType } = headers ?? {};
|
691
|
+
if (String(contentType).toLowerCase() === "application/json" && isObject(body)) {
|
692
|
+
return JSON.stringify(body);
|
693
|
+
}
|
694
|
+
return body;
|
695
|
+
}
|
378
696
|
const defaultClientID = generateUUID();
|
379
697
|
async function fetch$1({
|
380
698
|
url: path,
|
@@ -383,7 +701,7 @@ async function fetch$1({
|
|
383
701
|
headers: customHeaders,
|
384
702
|
pathParams,
|
385
703
|
queryParams,
|
386
|
-
|
704
|
+
fetch: fetch2,
|
387
705
|
apiKey,
|
388
706
|
endpoint,
|
389
707
|
apiUrl,
|
@@ -394,15 +712,16 @@ async function fetch$1({
|
|
394
712
|
sessionID,
|
395
713
|
clientName,
|
396
714
|
xataAgentExtra,
|
397
|
-
fetchOptions = {}
|
715
|
+
fetchOptions = {},
|
716
|
+
rawResponse = false
|
398
717
|
}) {
|
399
|
-
pool.setFetch(
|
718
|
+
pool.setFetch(fetch2);
|
400
719
|
return await trace(
|
401
720
|
`${method.toUpperCase()} ${path}`,
|
402
721
|
async ({ setAttributes }) => {
|
403
|
-
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
722
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
404
723
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
405
|
-
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
724
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\.[^.]+\./, "http://") : fullUrl;
|
406
725
|
setAttributes({
|
407
726
|
[TraceAttributes.HTTP_URL]: url,
|
408
727
|
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
@@ -413,7 +732,7 @@ async function fetch$1({
|
|
413
732
|
isDefined(clientName) ? ["service", clientName] : void 0,
|
414
733
|
...Object.entries(xataAgentExtra ?? {})
|
415
734
|
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
416
|
-
const headers = {
|
735
|
+
const headers = compactObject({
|
417
736
|
"Accept-Encoding": "identity",
|
418
737
|
"Content-Type": "application/json",
|
419
738
|
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
@@ -422,11 +741,11 @@ async function fetch$1({
|
|
422
741
|
...customHeaders,
|
423
742
|
...hostHeader(fullUrl),
|
424
743
|
Authorization: `Bearer ${apiKey}`
|
425
|
-
};
|
744
|
+
});
|
426
745
|
const response = await pool.request(url, {
|
427
746
|
...fetchOptions,
|
428
747
|
method: method.toUpperCase(),
|
429
|
-
body:
|
748
|
+
body: await parseBody(body, headers),
|
430
749
|
headers,
|
431
750
|
signal
|
432
751
|
});
|
@@ -437,8 +756,12 @@ async function fetch$1({
|
|
437
756
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
438
757
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
439
758
|
[TraceAttributes.HTTP_HOST]: host,
|
440
|
-
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
759
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", ""),
|
760
|
+
[TraceAttributes.CLOUDFLARE_RAY_ID]: response.headers?.get("cf-ray") ?? void 0
|
441
761
|
});
|
762
|
+
const message = response.headers?.get("x-xata-message");
|
763
|
+
if (message)
|
764
|
+
console.warn(message);
|
442
765
|
if (response.status === 204) {
|
443
766
|
return {};
|
444
767
|
}
|
@@ -446,7 +769,7 @@ async function fetch$1({
|
|
446
769
|
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
447
770
|
}
|
448
771
|
try {
|
449
|
-
const jsonResponse = await response.json();
|
772
|
+
const jsonResponse = rawResponse ? await response.blob() : await response.json();
|
450
773
|
if (response.ok) {
|
451
774
|
return jsonResponse;
|
452
775
|
}
|
@@ -458,6 +781,59 @@ async function fetch$1({
|
|
458
781
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
459
782
|
);
|
460
783
|
}
|
784
|
+
function fetchSSERequest({
|
785
|
+
url: path,
|
786
|
+
method,
|
787
|
+
body,
|
788
|
+
headers: customHeaders,
|
789
|
+
pathParams,
|
790
|
+
queryParams,
|
791
|
+
fetch: fetch2,
|
792
|
+
apiKey,
|
793
|
+
endpoint,
|
794
|
+
apiUrl,
|
795
|
+
workspacesApiUrl,
|
796
|
+
onMessage,
|
797
|
+
onError,
|
798
|
+
onClose,
|
799
|
+
signal,
|
800
|
+
clientID,
|
801
|
+
sessionID,
|
802
|
+
clientName,
|
803
|
+
xataAgentExtra
|
804
|
+
}) {
|
805
|
+
const baseUrl = buildBaseUrl({ method, endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
806
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
807
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
808
|
+
void fetchEventSource(url, {
|
809
|
+
method,
|
810
|
+
body: JSON.stringify(body),
|
811
|
+
fetch: fetch2,
|
812
|
+
signal,
|
813
|
+
headers: {
|
814
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
815
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
816
|
+
"X-Xata-Agent": compact([
|
817
|
+
["client", "TS_SDK"],
|
818
|
+
["version", VERSION],
|
819
|
+
isDefined(clientName) ? ["service", clientName] : void 0,
|
820
|
+
...Object.entries(xataAgentExtra ?? {})
|
821
|
+
]).map(([key, value]) => `${key}=${value}`).join("; "),
|
822
|
+
...customHeaders,
|
823
|
+
Authorization: `Bearer ${apiKey}`,
|
824
|
+
"Content-Type": "application/json"
|
825
|
+
},
|
826
|
+
onmessage(ev) {
|
827
|
+
onMessage?.(JSON.parse(ev.data));
|
828
|
+
},
|
829
|
+
onerror(ev) {
|
830
|
+
onError?.(JSON.parse(ev.data));
|
831
|
+
},
|
832
|
+
onclose() {
|
833
|
+
onClose?.();
|
834
|
+
}
|
835
|
+
});
|
836
|
+
}
|
461
837
|
function parseUrl(url) {
|
462
838
|
try {
|
463
839
|
const { host, protocol } = new URL(url);
|
@@ -469,6 +845,20 @@ function parseUrl(url) {
|
|
469
845
|
|
470
846
|
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
471
847
|
|
848
|
+
const applyMigration = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/apply", method: "post", ...variables, signal });
|
849
|
+
const pgRollStatus = (variables, signal) => dataPlaneFetch({
|
850
|
+
url: "/db/{dbBranchName}/pgroll/status",
|
851
|
+
method: "get",
|
852
|
+
...variables,
|
853
|
+
signal
|
854
|
+
});
|
855
|
+
const pgRollJobStatus = (variables, signal) => dataPlaneFetch({
|
856
|
+
url: "/db/{dbBranchName}/pgroll/jobs/{jobId}",
|
857
|
+
method: "get",
|
858
|
+
...variables,
|
859
|
+
signal
|
860
|
+
});
|
861
|
+
const pgRollMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/pgroll/migrations", method: "get", ...variables, signal });
|
472
862
|
const getBranchList = (variables, signal) => dataPlaneFetch({
|
473
863
|
url: "/dbs/{dbName}",
|
474
864
|
method: "get",
|
@@ -488,6 +878,18 @@ const deleteBranch = (variables, signal) => dataPlaneFetch({
|
|
488
878
|
...variables,
|
489
879
|
signal
|
490
880
|
});
|
881
|
+
const getSchema = (variables, signal) => dataPlaneFetch({
|
882
|
+
url: "/db/{dbBranchName}/schema",
|
883
|
+
method: "get",
|
884
|
+
...variables,
|
885
|
+
signal
|
886
|
+
});
|
887
|
+
const copyBranch = (variables, signal) => dataPlaneFetch({
|
888
|
+
url: "/db/{dbBranchName}/copy",
|
889
|
+
method: "post",
|
890
|
+
...variables,
|
891
|
+
signal
|
892
|
+
});
|
491
893
|
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
492
894
|
url: "/db/{dbBranchName}/metadata",
|
493
895
|
method: "put",
|
@@ -537,6 +939,7 @@ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{
|
|
537
939
|
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
538
940
|
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
539
941
|
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
942
|
+
const pushBranchMigrations = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/push", method: "post", ...variables, signal });
|
540
943
|
const createTable = (variables, signal) => dataPlaneFetch({
|
541
944
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
542
945
|
method: "put",
|
@@ -581,6 +984,42 @@ const deleteColumn = (variables, signal) => dataPlaneFetch({
|
|
581
984
|
});
|
582
985
|
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
583
986
|
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
987
|
+
const getFileItem = (variables, signal) => dataPlaneFetch({
|
988
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
989
|
+
method: "get",
|
990
|
+
...variables,
|
991
|
+
signal
|
992
|
+
});
|
993
|
+
const putFileItem = (variables, signal) => dataPlaneFetch({
|
994
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
995
|
+
method: "put",
|
996
|
+
...variables,
|
997
|
+
signal
|
998
|
+
});
|
999
|
+
const deleteFileItem = (variables, signal) => dataPlaneFetch({
|
1000
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file/{fileId}",
|
1001
|
+
method: "delete",
|
1002
|
+
...variables,
|
1003
|
+
signal
|
1004
|
+
});
|
1005
|
+
const getFile = (variables, signal) => dataPlaneFetch({
|
1006
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1007
|
+
method: "get",
|
1008
|
+
...variables,
|
1009
|
+
signal
|
1010
|
+
});
|
1011
|
+
const putFile = (variables, signal) => dataPlaneFetch({
|
1012
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1013
|
+
method: "put",
|
1014
|
+
...variables,
|
1015
|
+
signal
|
1016
|
+
});
|
1017
|
+
const deleteFile = (variables, signal) => dataPlaneFetch({
|
1018
|
+
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}/column/{columnName}/file",
|
1019
|
+
method: "delete",
|
1020
|
+
...variables,
|
1021
|
+
signal
|
1022
|
+
});
|
584
1023
|
const getRecord = (variables, signal) => dataPlaneFetch({
|
585
1024
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
586
1025
|
method: "get",
|
@@ -610,14 +1049,45 @@ const searchTable = (variables, signal) => dataPlaneFetch({
|
|
610
1049
|
...variables,
|
611
1050
|
signal
|
612
1051
|
});
|
1052
|
+
const vectorSearchTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/vectorSearch", method: "post", ...variables, signal });
|
1053
|
+
const askTable = (variables, signal) => dataPlaneFetch({
|
1054
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask",
|
1055
|
+
method: "post",
|
1056
|
+
...variables,
|
1057
|
+
signal
|
1058
|
+
});
|
1059
|
+
const askTableSession = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}", method: "post", ...variables, signal });
|
613
1060
|
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
614
1061
|
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
1062
|
+
const fileAccess = (variables, signal) => dataPlaneFetch({
|
1063
|
+
url: "/file/{fileId}",
|
1064
|
+
method: "get",
|
1065
|
+
...variables,
|
1066
|
+
signal
|
1067
|
+
});
|
1068
|
+
const fileUpload = (variables, signal) => dataPlaneFetch({
|
1069
|
+
url: "/file/{fileId}",
|
1070
|
+
method: "put",
|
1071
|
+
...variables,
|
1072
|
+
signal
|
1073
|
+
});
|
1074
|
+
const sqlQuery = (variables, signal) => dataPlaneFetch({
|
1075
|
+
url: "/db/{dbBranchName}/sql",
|
1076
|
+
method: "post",
|
1077
|
+
...variables,
|
1078
|
+
signal
|
1079
|
+
});
|
615
1080
|
const operationsByTag$2 = {
|
616
1081
|
branch: {
|
1082
|
+
applyMigration,
|
1083
|
+
pgRollStatus,
|
1084
|
+
pgRollJobStatus,
|
1085
|
+
pgRollMigrationHistory,
|
617
1086
|
getBranchList,
|
618
1087
|
getBranchDetails,
|
619
1088
|
createBranch,
|
620
1089
|
deleteBranch,
|
1090
|
+
copyBranch,
|
621
1091
|
updateBranchMetadata,
|
622
1092
|
getBranchMetadata,
|
623
1093
|
getBranchStats,
|
@@ -627,6 +1097,7 @@ const operationsByTag$2 = {
|
|
627
1097
|
resolveBranch
|
628
1098
|
},
|
629
1099
|
migrations: {
|
1100
|
+
getSchema,
|
630
1101
|
getBranchMigrationHistory,
|
631
1102
|
getBranchMigrationPlan,
|
632
1103
|
executeBranchMigrationPlan,
|
@@ -635,7 +1106,8 @@ const operationsByTag$2 = {
|
|
635
1106
|
compareBranchSchemas,
|
636
1107
|
updateBranchSchema,
|
637
1108
|
previewBranchSchemaEdit,
|
638
|
-
applyBranchSchemaEdit
|
1109
|
+
applyBranchSchemaEdit,
|
1110
|
+
pushBranchMigrations
|
639
1111
|
},
|
640
1112
|
migrationRequests: {
|
641
1113
|
queryMigrationRequests,
|
@@ -669,11 +1141,24 @@ const operationsByTag$2 = {
|
|
669
1141
|
deleteRecord,
|
670
1142
|
bulkInsertTableRecords
|
671
1143
|
},
|
672
|
-
|
1144
|
+
files: { getFileItem, putFileItem, deleteFileItem, getFile, putFile, deleteFile, fileAccess, fileUpload },
|
1145
|
+
searchAndFilter: {
|
1146
|
+
queryTable,
|
1147
|
+
searchBranch,
|
1148
|
+
searchTable,
|
1149
|
+
vectorSearchTable,
|
1150
|
+
askTable,
|
1151
|
+
askTableSession,
|
1152
|
+
summarizeTable,
|
1153
|
+
aggregateTable
|
1154
|
+
},
|
1155
|
+
sql: { sqlQuery }
|
673
1156
|
};
|
674
1157
|
|
675
1158
|
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
676
1159
|
|
1160
|
+
const getAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "get", ...variables, signal });
|
1161
|
+
const grantAuthorizationCode = (variables, signal) => controlPlaneFetch({ url: "/oauth/authorize", method: "post", ...variables, signal });
|
677
1162
|
const getUser = (variables, signal) => controlPlaneFetch({
|
678
1163
|
url: "/user",
|
679
1164
|
method: "get",
|
@@ -710,6 +1195,31 @@ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
|
710
1195
|
...variables,
|
711
1196
|
signal
|
712
1197
|
});
|
1198
|
+
const getUserOAuthClients = (variables, signal) => controlPlaneFetch({
|
1199
|
+
url: "/user/oauth/clients",
|
1200
|
+
method: "get",
|
1201
|
+
...variables,
|
1202
|
+
signal
|
1203
|
+
});
|
1204
|
+
const deleteUserOAuthClient = (variables, signal) => controlPlaneFetch({
|
1205
|
+
url: "/user/oauth/clients/{clientId}",
|
1206
|
+
method: "delete",
|
1207
|
+
...variables,
|
1208
|
+
signal
|
1209
|
+
});
|
1210
|
+
const getUserOAuthAccessTokens = (variables, signal) => controlPlaneFetch({
|
1211
|
+
url: "/user/oauth/tokens",
|
1212
|
+
method: "get",
|
1213
|
+
...variables,
|
1214
|
+
signal
|
1215
|
+
});
|
1216
|
+
const deleteOAuthAccessToken = (variables, signal) => controlPlaneFetch({
|
1217
|
+
url: "/user/oauth/tokens/{token}",
|
1218
|
+
method: "delete",
|
1219
|
+
...variables,
|
1220
|
+
signal
|
1221
|
+
});
|
1222
|
+
const updateOAuthAccessToken = (variables, signal) => controlPlaneFetch({ url: "/user/oauth/tokens/{token}", method: "patch", ...variables, signal });
|
713
1223
|
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
714
1224
|
url: "/workspaces",
|
715
1225
|
method: "get",
|
@@ -753,6 +1263,15 @@ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ u
|
|
753
1263
|
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
754
1264
|
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
755
1265
|
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
1266
|
+
const listClusters = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "get", ...variables, signal });
|
1267
|
+
const createCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters", method: "post", ...variables, signal });
|
1268
|
+
const getCluster = (variables, signal) => controlPlaneFetch({
|
1269
|
+
url: "/workspaces/{workspaceId}/clusters/{clusterId}",
|
1270
|
+
method: "get",
|
1271
|
+
...variables,
|
1272
|
+
signal
|
1273
|
+
});
|
1274
|
+
const updateCluster = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/clusters/{clusterId}", method: "patch", ...variables, signal });
|
756
1275
|
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
757
1276
|
url: "/workspaces/{workspaceId}/dbs",
|
758
1277
|
method: "get",
|
@@ -768,6 +1287,7 @@ const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
|
768
1287
|
});
|
769
1288
|
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
770
1289
|
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
1290
|
+
const renameDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/rename", method: "post", ...variables, signal });
|
771
1291
|
const getDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "get", ...variables, signal });
|
772
1292
|
const updateDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "put", ...variables, signal });
|
773
1293
|
const deleteDatabaseGithubSettings = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}/github", method: "delete", ...variables, signal });
|
@@ -778,6 +1298,15 @@ const listRegions = (variables, signal) => controlPlaneFetch({
|
|
778
1298
|
signal
|
779
1299
|
});
|
780
1300
|
const operationsByTag$1 = {
|
1301
|
+
oAuth: {
|
1302
|
+
getAuthorizationCode,
|
1303
|
+
grantAuthorizationCode,
|
1304
|
+
getUserOAuthClients,
|
1305
|
+
deleteUserOAuthClient,
|
1306
|
+
getUserOAuthAccessTokens,
|
1307
|
+
deleteOAuthAccessToken,
|
1308
|
+
updateOAuthAccessToken
|
1309
|
+
},
|
781
1310
|
users: { getUser, updateUser, deleteUser },
|
782
1311
|
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
783
1312
|
workspaces: {
|
@@ -797,12 +1326,14 @@ const operationsByTag$1 = {
|
|
797
1326
|
acceptWorkspaceMemberInvite,
|
798
1327
|
resendWorkspaceMemberInvite
|
799
1328
|
},
|
1329
|
+
xbcontrolOther: { listClusters, createCluster, getCluster, updateCluster },
|
800
1330
|
databases: {
|
801
1331
|
getDatabaseList,
|
802
1332
|
createDatabase,
|
803
1333
|
deleteDatabase,
|
804
1334
|
getDatabaseMetadata,
|
805
1335
|
updateDatabaseMetadata,
|
1336
|
+
renameDatabase,
|
806
1337
|
getDatabaseGithubSettings,
|
807
1338
|
updateDatabaseGithubSettings,
|
808
1339
|
deleteDatabaseGithubSettings,
|
@@ -812,51 +1343,6 @@ const operationsByTag$1 = {
|
|
812
1343
|
|
813
1344
|
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
814
1345
|
|
815
|
-
function getHostUrl(provider, type) {
|
816
|
-
if (isHostProviderAlias(provider)) {
|
817
|
-
return providers[provider][type];
|
818
|
-
} else if (isHostProviderBuilder(provider)) {
|
819
|
-
return provider[type];
|
820
|
-
}
|
821
|
-
throw new Error("Invalid API provider");
|
822
|
-
}
|
823
|
-
const providers = {
|
824
|
-
production: {
|
825
|
-
main: "https://api.xata.io",
|
826
|
-
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
827
|
-
},
|
828
|
-
staging: {
|
829
|
-
main: "https://staging.xatabase.co",
|
830
|
-
workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
|
831
|
-
}
|
832
|
-
};
|
833
|
-
function isHostProviderAlias(alias) {
|
834
|
-
return isString(alias) && Object.keys(providers).includes(alias);
|
835
|
-
}
|
836
|
-
function isHostProviderBuilder(builder) {
|
837
|
-
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
838
|
-
}
|
839
|
-
function parseProviderString(provider = "production") {
|
840
|
-
if (isHostProviderAlias(provider)) {
|
841
|
-
return provider;
|
842
|
-
}
|
843
|
-
const [main, workspaces] = provider.split(",");
|
844
|
-
if (!main || !workspaces)
|
845
|
-
return null;
|
846
|
-
return { main, workspaces };
|
847
|
-
}
|
848
|
-
function parseWorkspacesUrlParts(url) {
|
849
|
-
if (!isString(url))
|
850
|
-
return null;
|
851
|
-
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
852
|
-
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
|
853
|
-
const regexDev = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xata\.tech.*/;
|
854
|
-
const match = url.match(regex) || url.match(regexStaging) || url.match(regexDev);
|
855
|
-
if (!match)
|
856
|
-
return null;
|
857
|
-
return { workspace: match[1], region: match[2] };
|
858
|
-
}
|
859
|
-
|
860
1346
|
var __accessCheck$7 = (obj, member, msg) => {
|
861
1347
|
if (!member.has(obj))
|
862
1348
|
throw TypeError("Cannot " + msg);
|
@@ -890,7 +1376,7 @@ class XataApiClient {
|
|
890
1376
|
__privateSet$7(this, _extraProps, {
|
891
1377
|
apiUrl: getHostUrl(provider, "main"),
|
892
1378
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
893
|
-
|
1379
|
+
fetch: getFetchImplementation(options.fetch),
|
894
1380
|
apiKey,
|
895
1381
|
trace,
|
896
1382
|
clientName: options.clientName,
|
@@ -948,6 +1434,11 @@ class XataApiClient {
|
|
948
1434
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
949
1435
|
return __privateGet$7(this, _namespaces).records;
|
950
1436
|
}
|
1437
|
+
get files() {
|
1438
|
+
if (!__privateGet$7(this, _namespaces).files)
|
1439
|
+
__privateGet$7(this, _namespaces).files = new FilesApi(__privateGet$7(this, _extraProps));
|
1440
|
+
return __privateGet$7(this, _namespaces).files;
|
1441
|
+
}
|
951
1442
|
get searchAndFilter() {
|
952
1443
|
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
953
1444
|
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
@@ -1156,6 +1647,20 @@ class BranchApi {
|
|
1156
1647
|
...this.extraProps
|
1157
1648
|
});
|
1158
1649
|
}
|
1650
|
+
copyBranch({
|
1651
|
+
workspace,
|
1652
|
+
region,
|
1653
|
+
database,
|
1654
|
+
branch,
|
1655
|
+
destinationBranch,
|
1656
|
+
limit
|
1657
|
+
}) {
|
1658
|
+
return operationsByTag.branch.copyBranch({
|
1659
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1660
|
+
body: { destinationBranch, limit },
|
1661
|
+
...this.extraProps
|
1662
|
+
});
|
1663
|
+
}
|
1159
1664
|
updateBranchMetadata({
|
1160
1665
|
workspace,
|
1161
1666
|
region,
|
@@ -1511,6 +2016,164 @@ class RecordsApi {
|
|
1511
2016
|
});
|
1512
2017
|
}
|
1513
2018
|
}
|
2019
|
+
class FilesApi {
|
2020
|
+
constructor(extraProps) {
|
2021
|
+
this.extraProps = extraProps;
|
2022
|
+
}
|
2023
|
+
getFileItem({
|
2024
|
+
workspace,
|
2025
|
+
region,
|
2026
|
+
database,
|
2027
|
+
branch,
|
2028
|
+
table,
|
2029
|
+
record,
|
2030
|
+
column,
|
2031
|
+
fileId
|
2032
|
+
}) {
|
2033
|
+
return operationsByTag.files.getFileItem({
|
2034
|
+
pathParams: {
|
2035
|
+
workspace,
|
2036
|
+
region,
|
2037
|
+
dbBranchName: `${database}:${branch}`,
|
2038
|
+
tableName: table,
|
2039
|
+
recordId: record,
|
2040
|
+
columnName: column,
|
2041
|
+
fileId
|
2042
|
+
},
|
2043
|
+
...this.extraProps
|
2044
|
+
});
|
2045
|
+
}
|
2046
|
+
putFileItem({
|
2047
|
+
workspace,
|
2048
|
+
region,
|
2049
|
+
database,
|
2050
|
+
branch,
|
2051
|
+
table,
|
2052
|
+
record,
|
2053
|
+
column,
|
2054
|
+
fileId,
|
2055
|
+
file
|
2056
|
+
}) {
|
2057
|
+
return operationsByTag.files.putFileItem({
|
2058
|
+
pathParams: {
|
2059
|
+
workspace,
|
2060
|
+
region,
|
2061
|
+
dbBranchName: `${database}:${branch}`,
|
2062
|
+
tableName: table,
|
2063
|
+
recordId: record,
|
2064
|
+
columnName: column,
|
2065
|
+
fileId
|
2066
|
+
},
|
2067
|
+
// @ts-ignore
|
2068
|
+
body: file,
|
2069
|
+
...this.extraProps
|
2070
|
+
});
|
2071
|
+
}
|
2072
|
+
deleteFileItem({
|
2073
|
+
workspace,
|
2074
|
+
region,
|
2075
|
+
database,
|
2076
|
+
branch,
|
2077
|
+
table,
|
2078
|
+
record,
|
2079
|
+
column,
|
2080
|
+
fileId
|
2081
|
+
}) {
|
2082
|
+
return operationsByTag.files.deleteFileItem({
|
2083
|
+
pathParams: {
|
2084
|
+
workspace,
|
2085
|
+
region,
|
2086
|
+
dbBranchName: `${database}:${branch}`,
|
2087
|
+
tableName: table,
|
2088
|
+
recordId: record,
|
2089
|
+
columnName: column,
|
2090
|
+
fileId
|
2091
|
+
},
|
2092
|
+
...this.extraProps
|
2093
|
+
});
|
2094
|
+
}
|
2095
|
+
getFile({
|
2096
|
+
workspace,
|
2097
|
+
region,
|
2098
|
+
database,
|
2099
|
+
branch,
|
2100
|
+
table,
|
2101
|
+
record,
|
2102
|
+
column
|
2103
|
+
}) {
|
2104
|
+
return operationsByTag.files.getFile({
|
2105
|
+
pathParams: {
|
2106
|
+
workspace,
|
2107
|
+
region,
|
2108
|
+
dbBranchName: `${database}:${branch}`,
|
2109
|
+
tableName: table,
|
2110
|
+
recordId: record,
|
2111
|
+
columnName: column
|
2112
|
+
},
|
2113
|
+
...this.extraProps
|
2114
|
+
});
|
2115
|
+
}
|
2116
|
+
putFile({
|
2117
|
+
workspace,
|
2118
|
+
region,
|
2119
|
+
database,
|
2120
|
+
branch,
|
2121
|
+
table,
|
2122
|
+
record,
|
2123
|
+
column,
|
2124
|
+
file
|
2125
|
+
}) {
|
2126
|
+
return operationsByTag.files.putFile({
|
2127
|
+
pathParams: {
|
2128
|
+
workspace,
|
2129
|
+
region,
|
2130
|
+
dbBranchName: `${database}:${branch}`,
|
2131
|
+
tableName: table,
|
2132
|
+
recordId: record,
|
2133
|
+
columnName: column
|
2134
|
+
},
|
2135
|
+
body: file,
|
2136
|
+
...this.extraProps
|
2137
|
+
});
|
2138
|
+
}
|
2139
|
+
deleteFile({
|
2140
|
+
workspace,
|
2141
|
+
region,
|
2142
|
+
database,
|
2143
|
+
branch,
|
2144
|
+
table,
|
2145
|
+
record,
|
2146
|
+
column
|
2147
|
+
}) {
|
2148
|
+
return operationsByTag.files.deleteFile({
|
2149
|
+
pathParams: {
|
2150
|
+
workspace,
|
2151
|
+
region,
|
2152
|
+
dbBranchName: `${database}:${branch}`,
|
2153
|
+
tableName: table,
|
2154
|
+
recordId: record,
|
2155
|
+
columnName: column
|
2156
|
+
},
|
2157
|
+
...this.extraProps
|
2158
|
+
});
|
2159
|
+
}
|
2160
|
+
fileAccess({
|
2161
|
+
workspace,
|
2162
|
+
region,
|
2163
|
+
fileId,
|
2164
|
+
verify
|
2165
|
+
}) {
|
2166
|
+
return operationsByTag.files.fileAccess({
|
2167
|
+
pathParams: {
|
2168
|
+
workspace,
|
2169
|
+
region,
|
2170
|
+
fileId
|
2171
|
+
},
|
2172
|
+
queryParams: { verify },
|
2173
|
+
...this.extraProps
|
2174
|
+
});
|
2175
|
+
}
|
2176
|
+
}
|
1514
2177
|
class SearchAndFilterApi {
|
1515
2178
|
constructor(extraProps) {
|
1516
2179
|
this.extraProps = extraProps;
|
@@ -1570,6 +2233,53 @@ class SearchAndFilterApi {
|
|
1570
2233
|
...this.extraProps
|
1571
2234
|
});
|
1572
2235
|
}
|
2236
|
+
vectorSearchTable({
|
2237
|
+
workspace,
|
2238
|
+
region,
|
2239
|
+
database,
|
2240
|
+
branch,
|
2241
|
+
table,
|
2242
|
+
queryVector,
|
2243
|
+
column,
|
2244
|
+
similarityFunction,
|
2245
|
+
size,
|
2246
|
+
filter
|
2247
|
+
}) {
|
2248
|
+
return operationsByTag.searchAndFilter.vectorSearchTable({
|
2249
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2250
|
+
body: { queryVector, column, similarityFunction, size, filter },
|
2251
|
+
...this.extraProps
|
2252
|
+
});
|
2253
|
+
}
|
2254
|
+
askTable({
|
2255
|
+
workspace,
|
2256
|
+
region,
|
2257
|
+
database,
|
2258
|
+
branch,
|
2259
|
+
table,
|
2260
|
+
options
|
2261
|
+
}) {
|
2262
|
+
return operationsByTag.searchAndFilter.askTable({
|
2263
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
2264
|
+
body: { ...options },
|
2265
|
+
...this.extraProps
|
2266
|
+
});
|
2267
|
+
}
|
2268
|
+
askTableSession({
|
2269
|
+
workspace,
|
2270
|
+
region,
|
2271
|
+
database,
|
2272
|
+
branch,
|
2273
|
+
table,
|
2274
|
+
sessionId,
|
2275
|
+
message
|
2276
|
+
}) {
|
2277
|
+
return operationsByTag.searchAndFilter.askTableSession({
|
2278
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, sessionId },
|
2279
|
+
body: { message },
|
2280
|
+
...this.extraProps
|
2281
|
+
});
|
2282
|
+
}
|
1573
2283
|
summarizeTable({
|
1574
2284
|
workspace,
|
1575
2285
|
region,
|
@@ -1834,6 +2544,19 @@ class MigrationsApi {
|
|
1834
2544
|
...this.extraProps
|
1835
2545
|
});
|
1836
2546
|
}
|
2547
|
+
pushBranchMigrations({
|
2548
|
+
workspace,
|
2549
|
+
region,
|
2550
|
+
database,
|
2551
|
+
branch,
|
2552
|
+
migrations
|
2553
|
+
}) {
|
2554
|
+
return operationsByTag.migrations.pushBranchMigrations({
|
2555
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
2556
|
+
body: { migrations },
|
2557
|
+
...this.extraProps
|
2558
|
+
});
|
2559
|
+
}
|
1837
2560
|
}
|
1838
2561
|
class DatabaseApi {
|
1839
2562
|
constructor(extraProps) {
|
@@ -1848,11 +2571,13 @@ class DatabaseApi {
|
|
1848
2571
|
createDatabase({
|
1849
2572
|
workspace,
|
1850
2573
|
database,
|
1851
|
-
data
|
2574
|
+
data,
|
2575
|
+
headers
|
1852
2576
|
}) {
|
1853
2577
|
return operationsByTag.databases.createDatabase({
|
1854
2578
|
pathParams: { workspaceId: workspace, dbName: database },
|
1855
2579
|
body: data,
|
2580
|
+
headers,
|
1856
2581
|
...this.extraProps
|
1857
2582
|
});
|
1858
2583
|
}
|
@@ -1874,14 +2599,25 @@ class DatabaseApi {
|
|
1874
2599
|
...this.extraProps
|
1875
2600
|
});
|
1876
2601
|
}
|
1877
|
-
updateDatabaseMetadata({
|
2602
|
+
updateDatabaseMetadata({
|
2603
|
+
workspace,
|
2604
|
+
database,
|
2605
|
+
metadata
|
2606
|
+
}) {
|
2607
|
+
return operationsByTag.databases.updateDatabaseMetadata({
|
2608
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
2609
|
+
body: metadata,
|
2610
|
+
...this.extraProps
|
2611
|
+
});
|
2612
|
+
}
|
2613
|
+
renameDatabase({
|
1878
2614
|
workspace,
|
1879
2615
|
database,
|
1880
|
-
|
2616
|
+
newName
|
1881
2617
|
}) {
|
1882
|
-
return operationsByTag.databases.
|
2618
|
+
return operationsByTag.databases.renameDatabase({
|
1883
2619
|
pathParams: { workspaceId: workspace, dbName: database },
|
1884
|
-
body:
|
2620
|
+
body: { newName },
|
1885
2621
|
...this.extraProps
|
1886
2622
|
});
|
1887
2623
|
}
|
@@ -1923,20 +2659,203 @@ class DatabaseApi {
|
|
1923
2659
|
}
|
1924
2660
|
|
1925
2661
|
class XataApiPlugin {
|
1926
|
-
|
1927
|
-
|
1928
|
-
return new XataApiClient({ fetch: fetchImpl, apiKey });
|
2662
|
+
build(options) {
|
2663
|
+
return new XataApiClient(options);
|
1929
2664
|
}
|
1930
2665
|
}
|
1931
2666
|
|
1932
2667
|
class XataPlugin {
|
1933
2668
|
}
|
1934
2669
|
|
2670
|
+
function buildTransformString(transformations) {
|
2671
|
+
return transformations.flatMap(
|
2672
|
+
(t) => Object.entries(t).map(([key, value]) => {
|
2673
|
+
if (key === "trim") {
|
2674
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = value;
|
2675
|
+
return `${key}=${[top, right, bottom, left].join(";")}`;
|
2676
|
+
}
|
2677
|
+
if (key === "gravity" && typeof value === "object") {
|
2678
|
+
const { x = 0.5, y = 0.5 } = value;
|
2679
|
+
return `${key}=${[x, y].join("x")}`;
|
2680
|
+
}
|
2681
|
+
return `${key}=${value}`;
|
2682
|
+
})
|
2683
|
+
).join(",");
|
2684
|
+
}
|
2685
|
+
function transformImage(url, ...transformations) {
|
2686
|
+
if (!isDefined(url))
|
2687
|
+
return void 0;
|
2688
|
+
const newTransformations = buildTransformString(transformations);
|
2689
|
+
const { hostname, pathname, search } = new URL(url);
|
2690
|
+
const pathParts = pathname.split("/");
|
2691
|
+
const transformIndex = pathParts.findIndex((part) => part === "transform");
|
2692
|
+
const removedItems = transformIndex >= 0 ? pathParts.splice(transformIndex, 2) : [];
|
2693
|
+
const transform = `/transform/${[removedItems[1], newTransformations].filter(isDefined).join(",")}`;
|
2694
|
+
const path = pathParts.join("/");
|
2695
|
+
return `https://${hostname}${transform}${path}${search}`;
|
2696
|
+
}
|
2697
|
+
|
2698
|
+
class XataFile {
|
2699
|
+
constructor(file) {
|
2700
|
+
this.id = file.id;
|
2701
|
+
this.name = file.name;
|
2702
|
+
this.mediaType = file.mediaType;
|
2703
|
+
this.base64Content = file.base64Content;
|
2704
|
+
this.enablePublicUrl = file.enablePublicUrl;
|
2705
|
+
this.signedUrlTimeout = file.signedUrlTimeout;
|
2706
|
+
this.uploadUrlTimeout = file.uploadUrlTimeout;
|
2707
|
+
this.size = file.size;
|
2708
|
+
this.version = file.version;
|
2709
|
+
this.url = file.url;
|
2710
|
+
this.signedUrl = file.signedUrl;
|
2711
|
+
this.uploadUrl = file.uploadUrl;
|
2712
|
+
this.attributes = file.attributes;
|
2713
|
+
}
|
2714
|
+
static fromBuffer(buffer, options = {}) {
|
2715
|
+
const base64Content = buffer.toString("base64");
|
2716
|
+
return new XataFile({ ...options, base64Content });
|
2717
|
+
}
|
2718
|
+
toBuffer() {
|
2719
|
+
if (!this.base64Content) {
|
2720
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2721
|
+
}
|
2722
|
+
return Buffer.from(this.base64Content, "base64");
|
2723
|
+
}
|
2724
|
+
static fromArrayBuffer(arrayBuffer, options = {}) {
|
2725
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
2726
|
+
return this.fromUint8Array(uint8Array, options);
|
2727
|
+
}
|
2728
|
+
toArrayBuffer() {
|
2729
|
+
if (!this.base64Content) {
|
2730
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2731
|
+
}
|
2732
|
+
const binary = atob(this.base64Content);
|
2733
|
+
return new ArrayBuffer(binary.length);
|
2734
|
+
}
|
2735
|
+
static fromUint8Array(uint8Array, options = {}) {
|
2736
|
+
let binary = "";
|
2737
|
+
for (let i = 0; i < uint8Array.byteLength; i++) {
|
2738
|
+
binary += String.fromCharCode(uint8Array[i]);
|
2739
|
+
}
|
2740
|
+
const base64Content = btoa(binary);
|
2741
|
+
return new XataFile({ ...options, base64Content });
|
2742
|
+
}
|
2743
|
+
toUint8Array() {
|
2744
|
+
if (!this.base64Content) {
|
2745
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2746
|
+
}
|
2747
|
+
const binary = atob(this.base64Content);
|
2748
|
+
const uint8Array = new Uint8Array(binary.length);
|
2749
|
+
for (let i = 0; i < binary.length; i++) {
|
2750
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2751
|
+
}
|
2752
|
+
return uint8Array;
|
2753
|
+
}
|
2754
|
+
static async fromBlob(file, options = {}) {
|
2755
|
+
const name = options.name ?? file.name;
|
2756
|
+
const mediaType = file.type;
|
2757
|
+
const arrayBuffer = await file.arrayBuffer();
|
2758
|
+
return this.fromArrayBuffer(arrayBuffer, { ...options, name, mediaType });
|
2759
|
+
}
|
2760
|
+
toBlob() {
|
2761
|
+
if (!this.base64Content) {
|
2762
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2763
|
+
}
|
2764
|
+
const binary = atob(this.base64Content);
|
2765
|
+
const uint8Array = new Uint8Array(binary.length);
|
2766
|
+
for (let i = 0; i < binary.length; i++) {
|
2767
|
+
uint8Array[i] = binary.charCodeAt(i);
|
2768
|
+
}
|
2769
|
+
return new Blob([uint8Array], { type: this.mediaType });
|
2770
|
+
}
|
2771
|
+
static fromString(string, options = {}) {
|
2772
|
+
const base64Content = btoa(string);
|
2773
|
+
return new XataFile({ ...options, base64Content });
|
2774
|
+
}
|
2775
|
+
toString() {
|
2776
|
+
if (!this.base64Content) {
|
2777
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2778
|
+
}
|
2779
|
+
return atob(this.base64Content);
|
2780
|
+
}
|
2781
|
+
static fromBase64(base64Content, options = {}) {
|
2782
|
+
return new XataFile({ ...options, base64Content });
|
2783
|
+
}
|
2784
|
+
toBase64() {
|
2785
|
+
if (!this.base64Content) {
|
2786
|
+
throw new Error(`File content is not available, please select property "base64Content" when querying the file`);
|
2787
|
+
}
|
2788
|
+
return this.base64Content;
|
2789
|
+
}
|
2790
|
+
transform(...options) {
|
2791
|
+
return {
|
2792
|
+
url: transformImage(this.url, ...options),
|
2793
|
+
signedUrl: transformImage(this.signedUrl, ...options),
|
2794
|
+
metadataUrl: transformImage(this.url, ...options, { format: "json" }),
|
2795
|
+
metadataSignedUrl: transformImage(this.signedUrl, ...options, { format: "json" })
|
2796
|
+
};
|
2797
|
+
}
|
2798
|
+
}
|
2799
|
+
const parseInputFileEntry = async (entry) => {
|
2800
|
+
if (!isDefined(entry))
|
2801
|
+
return null;
|
2802
|
+
const { id, name, mediaType, base64Content, enablePublicUrl, signedUrlTimeout, uploadUrlTimeout } = await entry;
|
2803
|
+
return compactObject({
|
2804
|
+
id,
|
2805
|
+
// Name cannot be an empty string in our API
|
2806
|
+
name: name ? name : void 0,
|
2807
|
+
mediaType,
|
2808
|
+
base64Content,
|
2809
|
+
enablePublicUrl,
|
2810
|
+
signedUrlTimeout,
|
2811
|
+
uploadUrlTimeout
|
2812
|
+
});
|
2813
|
+
};
|
2814
|
+
|
1935
2815
|
function cleanFilter(filter) {
|
1936
|
-
if (!filter)
|
2816
|
+
if (!isDefined(filter))
|
1937
2817
|
return void 0;
|
1938
|
-
|
1939
|
-
|
2818
|
+
if (!isObject(filter))
|
2819
|
+
return filter;
|
2820
|
+
const values = Object.fromEntries(
|
2821
|
+
Object.entries(filter).reduce((acc, [key, value]) => {
|
2822
|
+
if (!isDefined(value))
|
2823
|
+
return acc;
|
2824
|
+
if (Array.isArray(value)) {
|
2825
|
+
const clean = value.map((item) => cleanFilter(item)).filter((item) => isDefined(item));
|
2826
|
+
if (clean.length === 0)
|
2827
|
+
return acc;
|
2828
|
+
return [...acc, [key, clean]];
|
2829
|
+
}
|
2830
|
+
if (isObject(value)) {
|
2831
|
+
const clean = cleanFilter(value);
|
2832
|
+
if (!isDefined(clean))
|
2833
|
+
return acc;
|
2834
|
+
return [...acc, [key, clean]];
|
2835
|
+
}
|
2836
|
+
return [...acc, [key, value]];
|
2837
|
+
}, [])
|
2838
|
+
);
|
2839
|
+
return Object.keys(values).length > 0 ? values : void 0;
|
2840
|
+
}
|
2841
|
+
|
2842
|
+
function stringifyJson(value) {
|
2843
|
+
if (!isDefined(value))
|
2844
|
+
return value;
|
2845
|
+
if (isString(value))
|
2846
|
+
return value;
|
2847
|
+
try {
|
2848
|
+
return JSON.stringify(value);
|
2849
|
+
} catch (e) {
|
2850
|
+
return value;
|
2851
|
+
}
|
2852
|
+
}
|
2853
|
+
function parseJson(value) {
|
2854
|
+
try {
|
2855
|
+
return JSON.parse(value);
|
2856
|
+
} catch (e) {
|
2857
|
+
return value;
|
2858
|
+
}
|
1940
2859
|
}
|
1941
2860
|
|
1942
2861
|
var __accessCheck$6 = (obj, member, msg) => {
|
@@ -1965,31 +2884,59 @@ class Page {
|
|
1965
2884
|
this.meta = meta;
|
1966
2885
|
this.records = new RecordArray(this, records);
|
1967
2886
|
}
|
2887
|
+
/**
|
2888
|
+
* Retrieves the next page of results.
|
2889
|
+
* @param size Maximum number of results to be retrieved.
|
2890
|
+
* @param offset Number of results to skip when retrieving the results.
|
2891
|
+
* @returns The next page or results.
|
2892
|
+
*/
|
1968
2893
|
async nextPage(size, offset) {
|
1969
2894
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
|
1970
2895
|
}
|
2896
|
+
/**
|
2897
|
+
* Retrieves the previous page of results.
|
2898
|
+
* @param size Maximum number of results to be retrieved.
|
2899
|
+
* @param offset Number of results to skip when retrieving the results.
|
2900
|
+
* @returns The previous page or results.
|
2901
|
+
*/
|
1971
2902
|
async previousPage(size, offset) {
|
1972
2903
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1973
2904
|
}
|
2905
|
+
/**
|
2906
|
+
* Retrieves the start page of results.
|
2907
|
+
* @param size Maximum number of results to be retrieved.
|
2908
|
+
* @param offset Number of results to skip when retrieving the results.
|
2909
|
+
* @returns The start page or results.
|
2910
|
+
*/
|
1974
2911
|
async startPage(size, offset) {
|
1975
2912
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1976
2913
|
}
|
2914
|
+
/**
|
2915
|
+
* Retrieves the end page of results.
|
2916
|
+
* @param size Maximum number of results to be retrieved.
|
2917
|
+
* @param offset Number of results to skip when retrieving the results.
|
2918
|
+
* @returns The end page or results.
|
2919
|
+
*/
|
1977
2920
|
async endPage(size, offset) {
|
1978
2921
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1979
2922
|
}
|
2923
|
+
/**
|
2924
|
+
* Shortcut method to check if there will be additional results if the next page of results is retrieved.
|
2925
|
+
* @returns Whether or not there will be additional results in the next page of results.
|
2926
|
+
*/
|
1980
2927
|
hasNextPage() {
|
1981
2928
|
return this.meta.page.more;
|
1982
2929
|
}
|
1983
2930
|
}
|
1984
2931
|
_query = new WeakMap();
|
1985
|
-
const PAGINATION_MAX_SIZE =
|
2932
|
+
const PAGINATION_MAX_SIZE = 1e3;
|
1986
2933
|
const PAGINATION_DEFAULT_SIZE = 20;
|
1987
|
-
const PAGINATION_MAX_OFFSET =
|
2934
|
+
const PAGINATION_MAX_OFFSET = 49e3;
|
1988
2935
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1989
2936
|
function isCursorPaginationOptions(options) {
|
1990
2937
|
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1991
2938
|
}
|
1992
|
-
const _RecordArray = class extends Array {
|
2939
|
+
const _RecordArray = class _RecordArray extends Array {
|
1993
2940
|
constructor(...args) {
|
1994
2941
|
super(..._RecordArray.parseConstructorParams(...args));
|
1995
2942
|
__privateAdd$6(this, _page, void 0);
|
@@ -2017,28 +2964,51 @@ const _RecordArray = class extends Array {
|
|
2017
2964
|
map(callbackfn, thisArg) {
|
2018
2965
|
return this.toArray().map(callbackfn, thisArg);
|
2019
2966
|
}
|
2967
|
+
/**
|
2968
|
+
* Retrieve next page of records
|
2969
|
+
*
|
2970
|
+
* @returns A new array of objects
|
2971
|
+
*/
|
2020
2972
|
async nextPage(size, offset) {
|
2021
2973
|
const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
|
2022
2974
|
return new _RecordArray(newPage);
|
2023
2975
|
}
|
2976
|
+
/**
|
2977
|
+
* Retrieve previous page of records
|
2978
|
+
*
|
2979
|
+
* @returns A new array of objects
|
2980
|
+
*/
|
2024
2981
|
async previousPage(size, offset) {
|
2025
2982
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
2026
2983
|
return new _RecordArray(newPage);
|
2027
2984
|
}
|
2985
|
+
/**
|
2986
|
+
* Retrieve start page of records
|
2987
|
+
*
|
2988
|
+
* @returns A new array of objects
|
2989
|
+
*/
|
2028
2990
|
async startPage(size, offset) {
|
2029
2991
|
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
2030
2992
|
return new _RecordArray(newPage);
|
2031
2993
|
}
|
2994
|
+
/**
|
2995
|
+
* Retrieve end page of records
|
2996
|
+
*
|
2997
|
+
* @returns A new array of objects
|
2998
|
+
*/
|
2032
2999
|
async endPage(size, offset) {
|
2033
3000
|
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
2034
3001
|
return new _RecordArray(newPage);
|
2035
3002
|
}
|
3003
|
+
/**
|
3004
|
+
* @returns Boolean indicating if there is a next page
|
3005
|
+
*/
|
2036
3006
|
hasNextPage() {
|
2037
3007
|
return __privateGet$6(this, _page).meta.page.more;
|
2038
3008
|
}
|
2039
3009
|
};
|
2040
|
-
let RecordArray = _RecordArray;
|
2041
3010
|
_page = new WeakMap();
|
3011
|
+
let RecordArray = _RecordArray;
|
2042
3012
|
|
2043
3013
|
var __accessCheck$5 = (obj, member, msg) => {
|
2044
3014
|
if (!member.has(obj))
|
@@ -2063,13 +3033,14 @@ var __privateMethod$3 = (obj, member, method) => {
|
|
2063
3033
|
return method;
|
2064
3034
|
};
|
2065
3035
|
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
2066
|
-
const _Query = class {
|
3036
|
+
const _Query = class _Query {
|
2067
3037
|
constructor(repository, table, data, rawParent) {
|
2068
3038
|
__privateAdd$5(this, _cleanFilterConstraint);
|
2069
3039
|
__privateAdd$5(this, _table$1, void 0);
|
2070
3040
|
__privateAdd$5(this, _repository, void 0);
|
2071
3041
|
__privateAdd$5(this, _data, { filter: {} });
|
2072
|
-
|
3042
|
+
// Implements pagination
|
3043
|
+
this.meta = { page: { cursor: "start", more: true, size: PAGINATION_DEFAULT_SIZE } };
|
2073
3044
|
this.records = new RecordArray(this, []);
|
2074
3045
|
__privateSet$5(this, _table$1, table);
|
2075
3046
|
if (repository) {
|
@@ -2106,18 +3077,38 @@ const _Query = class {
|
|
2106
3077
|
const key = JSON.stringify({ columns, filter, sort, pagination });
|
2107
3078
|
return toBase64(key);
|
2108
3079
|
}
|
3080
|
+
/**
|
3081
|
+
* Builds a new query object representing a logical OR between the given subqueries.
|
3082
|
+
* @param queries An array of subqueries.
|
3083
|
+
* @returns A new Query object.
|
3084
|
+
*/
|
2109
3085
|
any(...queries) {
|
2110
3086
|
const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2111
3087
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
|
2112
3088
|
}
|
3089
|
+
/**
|
3090
|
+
* Builds a new query object representing a logical AND between the given subqueries.
|
3091
|
+
* @param queries An array of subqueries.
|
3092
|
+
* @returns A new Query object.
|
3093
|
+
*/
|
2113
3094
|
all(...queries) {
|
2114
3095
|
const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2115
3096
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
2116
3097
|
}
|
3098
|
+
/**
|
3099
|
+
* Builds a new query object representing a logical OR negating each subquery. In pseudo-code: !q1 OR !q2
|
3100
|
+
* @param queries An array of subqueries.
|
3101
|
+
* @returns A new Query object.
|
3102
|
+
*/
|
2117
3103
|
not(...queries) {
|
2118
3104
|
const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2119
3105
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
|
2120
3106
|
}
|
3107
|
+
/**
|
3108
|
+
* Builds a new query object representing a logical AND negating each subquery. In pseudo-code: !q1 AND !q2
|
3109
|
+
* @param queries An array of subqueries.
|
3110
|
+
* @returns A new Query object.
|
3111
|
+
*/
|
2121
3112
|
none(...queries) {
|
2122
3113
|
const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
|
2123
3114
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
|
@@ -2140,6 +3131,11 @@ const _Query = class {
|
|
2140
3131
|
const sort = [...originalSort, { column, direction }];
|
2141
3132
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
2142
3133
|
}
|
3134
|
+
/**
|
3135
|
+
* Builds a new query specifying the set of columns to be returned in the query response.
|
3136
|
+
* @param columns Array of column names to be returned by the query.
|
3137
|
+
* @returns A new Query object.
|
3138
|
+
*/
|
2143
3139
|
select(columns) {
|
2144
3140
|
return new _Query(
|
2145
3141
|
__privateGet$5(this, _repository),
|
@@ -2152,6 +3148,12 @@ const _Query = class {
|
|
2152
3148
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
2153
3149
|
return __privateGet$5(this, _repository).query(query);
|
2154
3150
|
}
|
3151
|
+
/**
|
3152
|
+
* Get results in an iterator
|
3153
|
+
*
|
3154
|
+
* @async
|
3155
|
+
* @returns Async interable of results
|
3156
|
+
*/
|
2155
3157
|
async *[Symbol.asyncIterator]() {
|
2156
3158
|
for await (const [record] of this.getIterator({ batchSize: 1 })) {
|
2157
3159
|
yield record;
|
@@ -2212,26 +3214,53 @@ const _Query = class {
|
|
2212
3214
|
);
|
2213
3215
|
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2214
3216
|
}
|
3217
|
+
/**
|
3218
|
+
* Builds a new query object adding a cache TTL in milliseconds.
|
3219
|
+
* @param ttl The cache TTL in milliseconds.
|
3220
|
+
* @returns A new Query object.
|
3221
|
+
*/
|
2215
3222
|
cache(ttl) {
|
2216
3223
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
2217
3224
|
}
|
3225
|
+
/**
|
3226
|
+
* Retrieve next page of records
|
3227
|
+
*
|
3228
|
+
* @returns A new page object.
|
3229
|
+
*/
|
2218
3230
|
nextPage(size, offset) {
|
2219
3231
|
return this.startPage(size, offset);
|
2220
3232
|
}
|
3233
|
+
/**
|
3234
|
+
* Retrieve previous page of records
|
3235
|
+
*
|
3236
|
+
* @returns A new page object
|
3237
|
+
*/
|
2221
3238
|
previousPage(size, offset) {
|
2222
3239
|
return this.startPage(size, offset);
|
2223
3240
|
}
|
3241
|
+
/**
|
3242
|
+
* Retrieve start page of records
|
3243
|
+
*
|
3244
|
+
* @returns A new page object
|
3245
|
+
*/
|
2224
3246
|
startPage(size, offset) {
|
2225
3247
|
return this.getPaginated({ pagination: { size, offset } });
|
2226
3248
|
}
|
3249
|
+
/**
|
3250
|
+
* Retrieve last page of records
|
3251
|
+
*
|
3252
|
+
* @returns A new page object
|
3253
|
+
*/
|
2227
3254
|
endPage(size, offset) {
|
2228
3255
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
2229
3256
|
}
|
3257
|
+
/**
|
3258
|
+
* @returns Boolean indicating if there is a next page
|
3259
|
+
*/
|
2230
3260
|
hasNextPage() {
|
2231
3261
|
return this.meta.page.more;
|
2232
3262
|
}
|
2233
3263
|
};
|
2234
|
-
let Query = _Query;
|
2235
3264
|
_table$1 = new WeakMap();
|
2236
3265
|
_repository = new WeakMap();
|
2237
3266
|
_data = new WeakMap();
|
@@ -2246,6 +3275,7 @@ cleanFilterConstraint_fn = function(column, value) {
|
|
2246
3275
|
}
|
2247
3276
|
return value;
|
2248
3277
|
};
|
3278
|
+
let Query = _Query;
|
2249
3279
|
function cleanParent(data, parent) {
|
2250
3280
|
if (isCursorPaginationOptions(data.pagination)) {
|
2251
3281
|
return { ...parent, sort: void 0, filter: void 0 };
|
@@ -2253,6 +3283,22 @@ function cleanParent(data, parent) {
|
|
2253
3283
|
return parent;
|
2254
3284
|
}
|
2255
3285
|
|
3286
|
+
const RecordColumnTypes = [
|
3287
|
+
"bool",
|
3288
|
+
"int",
|
3289
|
+
"float",
|
3290
|
+
"string",
|
3291
|
+
"text",
|
3292
|
+
"email",
|
3293
|
+
"multiple",
|
3294
|
+
"link",
|
3295
|
+
"object",
|
3296
|
+
"datetime",
|
3297
|
+
"vector",
|
3298
|
+
"file[]",
|
3299
|
+
"file",
|
3300
|
+
"json"
|
3301
|
+
];
|
2256
3302
|
function isIdentifiable(x) {
|
2257
3303
|
return isObject(x) && isString(x?.id);
|
2258
3304
|
}
|
@@ -2262,11 +3308,33 @@ function isXataRecord(x) {
|
|
2262
3308
|
return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
|
2263
3309
|
}
|
2264
3310
|
|
3311
|
+
function isValidExpandedColumn(column) {
|
3312
|
+
return isObject(column) && isString(column.name);
|
3313
|
+
}
|
3314
|
+
function isValidSelectableColumns(columns) {
|
3315
|
+
if (!Array.isArray(columns)) {
|
3316
|
+
return false;
|
3317
|
+
}
|
3318
|
+
return columns.every((column) => {
|
3319
|
+
if (typeof column === "string") {
|
3320
|
+
return true;
|
3321
|
+
}
|
3322
|
+
if (typeof column === "object") {
|
3323
|
+
return isValidExpandedColumn(column);
|
3324
|
+
}
|
3325
|
+
return false;
|
3326
|
+
});
|
3327
|
+
}
|
3328
|
+
|
2265
3329
|
function isSortFilterString(value) {
|
2266
3330
|
return isString(value);
|
2267
3331
|
}
|
2268
3332
|
function isSortFilterBase(filter) {
|
2269
|
-
return isObject(filter) && Object.
|
3333
|
+
return isObject(filter) && Object.entries(filter).every(([key, value]) => {
|
3334
|
+
if (key === "*")
|
3335
|
+
return value === "random";
|
3336
|
+
return value === "asc" || value === "desc";
|
3337
|
+
});
|
2270
3338
|
}
|
2271
3339
|
function isSortFilterObject(filter) {
|
2272
3340
|
return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
|
@@ -2307,7 +3375,7 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
2307
3375
|
__accessCheck$4(obj, member, "access private method");
|
2308
3376
|
return method;
|
2309
3377
|
};
|
2310
|
-
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;
|
3378
|
+
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;
|
2311
3379
|
const BULK_OPERATION_MAX_SIZE = 1e3;
|
2312
3380
|
class Repository extends Query {
|
2313
3381
|
}
|
@@ -2329,6 +3397,7 @@ class RestRepository extends Query {
|
|
2329
3397
|
__privateAdd$4(this, _setCacheQuery);
|
2330
3398
|
__privateAdd$4(this, _getCacheQuery);
|
2331
3399
|
__privateAdd$4(this, _getSchemaTables$1);
|
3400
|
+
__privateAdd$4(this, _transformObjectToApi);
|
2332
3401
|
__privateAdd$4(this, _table, void 0);
|
2333
3402
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2334
3403
|
__privateAdd$4(this, _db, void 0);
|
@@ -2339,10 +3408,7 @@ class RestRepository extends Query {
|
|
2339
3408
|
__privateSet$4(this, _db, options.db);
|
2340
3409
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
2341
3410
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2342
|
-
__privateSet$4(this, _getFetchProps,
|
2343
|
-
const props = await options.pluginOptions.getFetchProps();
|
2344
|
-
return { ...props, sessionID: generateUUID() };
|
2345
|
-
});
|
3411
|
+
__privateSet$4(this, _getFetchProps, () => ({ ...options.pluginOptions, sessionID: generateUUID() }));
|
2346
3412
|
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2347
3413
|
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2348
3414
|
return trace(name, fn, {
|
@@ -2360,24 +3426,24 @@ class RestRepository extends Query {
|
|
2360
3426
|
if (a.length === 0)
|
2361
3427
|
return [];
|
2362
3428
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2363
|
-
const columns =
|
3429
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2364
3430
|
const result = await this.read(ids, columns);
|
2365
3431
|
return result;
|
2366
3432
|
}
|
2367
3433
|
if (isString(a) && isObject(b)) {
|
2368
3434
|
if (a === "")
|
2369
3435
|
throw new Error("The id can't be empty");
|
2370
|
-
const columns =
|
3436
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2371
3437
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2372
3438
|
}
|
2373
3439
|
if (isObject(a) && isString(a.id)) {
|
2374
3440
|
if (a.id === "")
|
2375
3441
|
throw new Error("The id can't be empty");
|
2376
|
-
const columns =
|
3442
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2377
3443
|
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2378
3444
|
}
|
2379
3445
|
if (isObject(a)) {
|
2380
|
-
const columns =
|
3446
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2381
3447
|
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2382
3448
|
}
|
2383
3449
|
throw new Error("Invalid arguments for create method");
|
@@ -2385,7 +3451,7 @@ class RestRepository extends Query {
|
|
2385
3451
|
}
|
2386
3452
|
async read(a, b) {
|
2387
3453
|
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2388
|
-
const columns =
|
3454
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2389
3455
|
if (Array.isArray(a)) {
|
2390
3456
|
if (a.length === 0)
|
2391
3457
|
return [];
|
@@ -2399,7 +3465,6 @@ class RestRepository extends Query {
|
|
2399
3465
|
}
|
2400
3466
|
const id = extractId(a);
|
2401
3467
|
if (id) {
|
2402
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2403
3468
|
try {
|
2404
3469
|
const response = await getRecord({
|
2405
3470
|
pathParams: {
|
@@ -2410,10 +3475,16 @@ class RestRepository extends Query {
|
|
2410
3475
|
recordId: id
|
2411
3476
|
},
|
2412
3477
|
queryParams: { columns },
|
2413
|
-
...
|
3478
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2414
3479
|
});
|
2415
3480
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2416
|
-
return initObject(
|
3481
|
+
return initObject(
|
3482
|
+
__privateGet$4(this, _db),
|
3483
|
+
schemaTables,
|
3484
|
+
__privateGet$4(this, _table),
|
3485
|
+
response,
|
3486
|
+
columns
|
3487
|
+
);
|
2417
3488
|
} catch (e) {
|
2418
3489
|
if (isObject(e) && e.status === 404) {
|
2419
3490
|
return null;
|
@@ -2455,17 +3526,17 @@ class RestRepository extends Query {
|
|
2455
3526
|
ifVersion,
|
2456
3527
|
upsert: false
|
2457
3528
|
});
|
2458
|
-
const columns =
|
3529
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2459
3530
|
const result = await this.read(a, columns);
|
2460
3531
|
return result;
|
2461
3532
|
}
|
2462
3533
|
try {
|
2463
3534
|
if (isString(a) && isObject(b)) {
|
2464
|
-
const columns =
|
3535
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
2465
3536
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2466
3537
|
}
|
2467
3538
|
if (isObject(a) && isString(a.id)) {
|
2468
|
-
const columns =
|
3539
|
+
const columns = isValidSelectableColumns(b) ? b : void 0;
|
2469
3540
|
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2470
3541
|
}
|
2471
3542
|
} catch (error) {
|
@@ -2505,17 +3576,27 @@ class RestRepository extends Query {
|
|
2505
3576
|
ifVersion,
|
2506
3577
|
upsert: true
|
2507
3578
|
});
|
2508
|
-
const columns =
|
3579
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2509
3580
|
const result = await this.read(a, columns);
|
2510
3581
|
return result;
|
2511
3582
|
}
|
2512
3583
|
if (isString(a) && isObject(b)) {
|
2513
|
-
|
2514
|
-
|
3584
|
+
if (a === "")
|
3585
|
+
throw new Error("The id can't be empty");
|
3586
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3587
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2515
3588
|
}
|
2516
3589
|
if (isObject(a) && isString(a.id)) {
|
2517
|
-
|
2518
|
-
|
3590
|
+
if (a.id === "")
|
3591
|
+
throw new Error("The id can't be empty");
|
3592
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3593
|
+
return await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
3594
|
+
}
|
3595
|
+
if (!isDefined(a) && isObject(b)) {
|
3596
|
+
return await this.create(b, c);
|
3597
|
+
}
|
3598
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3599
|
+
return await this.create(a, b);
|
2519
3600
|
}
|
2520
3601
|
throw new Error("Invalid arguments for createOrUpdate method");
|
2521
3602
|
});
|
@@ -2527,17 +3608,27 @@ class RestRepository extends Query {
|
|
2527
3608
|
if (a.length === 0)
|
2528
3609
|
return [];
|
2529
3610
|
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2530
|
-
const columns =
|
3611
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2531
3612
|
const result = await this.read(ids, columns);
|
2532
3613
|
return result;
|
2533
3614
|
}
|
2534
3615
|
if (isString(a) && isObject(b)) {
|
2535
|
-
|
2536
|
-
|
3616
|
+
if (a === "")
|
3617
|
+
throw new Error("The id can't be empty");
|
3618
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3619
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2537
3620
|
}
|
2538
3621
|
if (isObject(a) && isString(a.id)) {
|
2539
|
-
|
2540
|
-
|
3622
|
+
if (a.id === "")
|
3623
|
+
throw new Error("The id can't be empty");
|
3624
|
+
const columns = isValidSelectableColumns(c) ? c : void 0;
|
3625
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
3626
|
+
}
|
3627
|
+
if (!isDefined(a) && isObject(b)) {
|
3628
|
+
return await this.create(b, c);
|
3629
|
+
}
|
3630
|
+
if (isObject(a) && !isDefined(a.id)) {
|
3631
|
+
return await this.create(a, b);
|
2541
3632
|
}
|
2542
3633
|
throw new Error("Invalid arguments for createOrReplace method");
|
2543
3634
|
});
|
@@ -2554,7 +3645,7 @@ class RestRepository extends Query {
|
|
2554
3645
|
return o.id;
|
2555
3646
|
throw new Error("Invalid arguments for delete method");
|
2556
3647
|
});
|
2557
|
-
const columns =
|
3648
|
+
const columns = isValidSelectableColumns(b) ? b : ["*"];
|
2558
3649
|
const result = await this.read(a, columns);
|
2559
3650
|
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2560
3651
|
return result;
|
@@ -2588,8 +3679,7 @@ class RestRepository extends Query {
|
|
2588
3679
|
}
|
2589
3680
|
async search(query, options = {}) {
|
2590
3681
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2591
|
-
const
|
2592
|
-
const { records } = await searchTable({
|
3682
|
+
const { records, totalCount } = await searchTable({
|
2593
3683
|
pathParams: {
|
2594
3684
|
workspace: "{workspaceId}",
|
2595
3685
|
dbBranchName: "{dbBranch}",
|
@@ -2606,15 +3696,42 @@ class RestRepository extends Query {
|
|
2606
3696
|
page: options.page,
|
2607
3697
|
target: options.target
|
2608
3698
|
},
|
2609
|
-
...
|
3699
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3700
|
+
});
|
3701
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3702
|
+
return {
|
3703
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3704
|
+
totalCount
|
3705
|
+
};
|
3706
|
+
});
|
3707
|
+
}
|
3708
|
+
async vectorSearch(column, query, options) {
|
3709
|
+
return __privateGet$4(this, _trace).call(this, "vectorSearch", async () => {
|
3710
|
+
const { records, totalCount } = await vectorSearchTable({
|
3711
|
+
pathParams: {
|
3712
|
+
workspace: "{workspaceId}",
|
3713
|
+
dbBranchName: "{dbBranch}",
|
3714
|
+
region: "{region}",
|
3715
|
+
tableName: __privateGet$4(this, _table)
|
3716
|
+
},
|
3717
|
+
body: {
|
3718
|
+
column,
|
3719
|
+
queryVector: query,
|
3720
|
+
similarityFunction: options?.similarityFunction,
|
3721
|
+
size: options?.size,
|
3722
|
+
filter: options?.filter
|
3723
|
+
},
|
3724
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2610
3725
|
});
|
2611
3726
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2612
|
-
return
|
3727
|
+
return {
|
3728
|
+
records: records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"])),
|
3729
|
+
totalCount
|
3730
|
+
};
|
2613
3731
|
});
|
2614
3732
|
}
|
2615
3733
|
async aggregate(aggs, filter) {
|
2616
3734
|
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2617
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2618
3735
|
const result = await aggregateTable({
|
2619
3736
|
pathParams: {
|
2620
3737
|
workspace: "{workspaceId}",
|
@@ -2623,7 +3740,7 @@ class RestRepository extends Query {
|
|
2623
3740
|
tableName: __privateGet$4(this, _table)
|
2624
3741
|
},
|
2625
3742
|
body: { aggs, filter },
|
2626
|
-
...
|
3743
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2627
3744
|
});
|
2628
3745
|
return result;
|
2629
3746
|
});
|
@@ -2634,7 +3751,6 @@ class RestRepository extends Query {
|
|
2634
3751
|
if (cacheQuery)
|
2635
3752
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2636
3753
|
const data = query.getQueryOptions();
|
2637
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2638
3754
|
const { meta, records: objects } = await queryTable({
|
2639
3755
|
pathParams: {
|
2640
3756
|
workspace: "{workspaceId}",
|
@@ -2650,11 +3766,17 @@ class RestRepository extends Query {
|
|
2650
3766
|
consistency: data.consistency
|
2651
3767
|
},
|
2652
3768
|
fetchOptions: data.fetchOptions,
|
2653
|
-
...
|
3769
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2654
3770
|
});
|
2655
3771
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2656
3772
|
const records = objects.map(
|
2657
|
-
(record) => initObject(
|
3773
|
+
(record) => initObject(
|
3774
|
+
__privateGet$4(this, _db),
|
3775
|
+
schemaTables,
|
3776
|
+
__privateGet$4(this, _table),
|
3777
|
+
record,
|
3778
|
+
data.columns ?? ["*"]
|
3779
|
+
)
|
2658
3780
|
);
|
2659
3781
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2660
3782
|
return new Page(query, meta, records);
|
@@ -2663,7 +3785,6 @@ class RestRepository extends Query {
|
|
2663
3785
|
async summarizeTable(query, summaries, summariesFilter) {
|
2664
3786
|
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2665
3787
|
const data = query.getQueryOptions();
|
2666
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2667
3788
|
const result = await summarizeTable({
|
2668
3789
|
pathParams: {
|
2669
3790
|
workspace: "{workspaceId}",
|
@@ -2680,11 +3801,50 @@ class RestRepository extends Query {
|
|
2680
3801
|
summaries,
|
2681
3802
|
summariesFilter
|
2682
3803
|
},
|
2683
|
-
...
|
3804
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2684
3805
|
});
|
2685
|
-
|
3806
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
3807
|
+
return {
|
3808
|
+
...result,
|
3809
|
+
summaries: result.summaries.map(
|
3810
|
+
(summary) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), summary, data.columns ?? [])
|
3811
|
+
)
|
3812
|
+
};
|
2686
3813
|
});
|
2687
3814
|
}
|
3815
|
+
ask(question, options) {
|
3816
|
+
const questionParam = options?.sessionId ? { message: question } : { question };
|
3817
|
+
const params = {
|
3818
|
+
pathParams: {
|
3819
|
+
workspace: "{workspaceId}",
|
3820
|
+
dbBranchName: "{dbBranch}",
|
3821
|
+
region: "{region}",
|
3822
|
+
tableName: __privateGet$4(this, _table),
|
3823
|
+
sessionId: options?.sessionId
|
3824
|
+
},
|
3825
|
+
body: {
|
3826
|
+
...questionParam,
|
3827
|
+
rules: options?.rules,
|
3828
|
+
searchType: options?.searchType,
|
3829
|
+
search: options?.searchType === "keyword" ? options?.search : void 0,
|
3830
|
+
vectorSearch: options?.searchType === "vector" ? options?.vectorSearch : void 0
|
3831
|
+
},
|
3832
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
3833
|
+
};
|
3834
|
+
if (options?.onMessage) {
|
3835
|
+
fetchSSERequest({
|
3836
|
+
endpoint: "dataPlane",
|
3837
|
+
url: "/db/{dbBranchName}/tables/{tableName}/ask/{sessionId}",
|
3838
|
+
method: "POST",
|
3839
|
+
onMessage: (message) => {
|
3840
|
+
options.onMessage?.({ answer: message.text, records: message.records });
|
3841
|
+
},
|
3842
|
+
...params
|
3843
|
+
});
|
3844
|
+
} else {
|
3845
|
+
return askTableSession(params);
|
3846
|
+
}
|
3847
|
+
}
|
2688
3848
|
}
|
2689
3849
|
_table = new WeakMap();
|
2690
3850
|
_getFetchProps = new WeakMap();
|
@@ -2694,8 +3854,7 @@ _schemaTables$2 = new WeakMap();
|
|
2694
3854
|
_trace = new WeakMap();
|
2695
3855
|
_insertRecordWithoutId = new WeakSet();
|
2696
3856
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
2697
|
-
const
|
2698
|
-
const record = transformObjectLinks(object);
|
3857
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2699
3858
|
const response = await insertRecord({
|
2700
3859
|
pathParams: {
|
2701
3860
|
workspace: "{workspaceId}",
|
@@ -2705,15 +3864,16 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
2705
3864
|
},
|
2706
3865
|
queryParams: { columns },
|
2707
3866
|
body: record,
|
2708
|
-
...
|
3867
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2709
3868
|
});
|
2710
3869
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2711
3870
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2712
3871
|
};
|
2713
3872
|
_insertRecordWithId = new WeakSet();
|
2714
3873
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
2715
|
-
|
2716
|
-
|
3874
|
+
if (!recordId)
|
3875
|
+
return null;
|
3876
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2717
3877
|
const response = await insertRecordWithID({
|
2718
3878
|
pathParams: {
|
2719
3879
|
workspace: "{workspaceId}",
|
@@ -2724,30 +3884,28 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { crea
|
|
2724
3884
|
},
|
2725
3885
|
body: record,
|
2726
3886
|
queryParams: { createOnly, columns, ifVersion },
|
2727
|
-
...
|
3887
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2728
3888
|
});
|
2729
3889
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2730
3890
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2731
3891
|
};
|
2732
3892
|
_insertRecords = new WeakSet();
|
2733
3893
|
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
2734
|
-
const
|
2735
|
-
|
2736
|
-
|
2737
|
-
|
2738
|
-
|
2739
|
-
BULK_OPERATION_MAX_SIZE
|
2740
|
-
);
|
3894
|
+
const operations = await promiseMap(objects, async (object) => {
|
3895
|
+
const record = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3896
|
+
return { insert: { table: __privateGet$4(this, _table), record, createOnly, ifVersion } };
|
3897
|
+
});
|
3898
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2741
3899
|
const ids = [];
|
2742
|
-
for (const
|
3900
|
+
for (const operations2 of chunkedOperations) {
|
2743
3901
|
const { results } = await branchTransaction({
|
2744
3902
|
pathParams: {
|
2745
3903
|
workspace: "{workspaceId}",
|
2746
3904
|
dbBranchName: "{dbBranch}",
|
2747
3905
|
region: "{region}"
|
2748
3906
|
},
|
2749
|
-
body: { operations },
|
2750
|
-
...
|
3907
|
+
body: { operations: operations2 },
|
3908
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2751
3909
|
});
|
2752
3910
|
for (const result of results) {
|
2753
3911
|
if (result.operation === "insert") {
|
@@ -2761,8 +3919,9 @@ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
|
2761
3919
|
};
|
2762
3920
|
_updateRecordWithID = new WeakSet();
|
2763
3921
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2764
|
-
|
2765
|
-
|
3922
|
+
if (!recordId)
|
3923
|
+
return null;
|
3924
|
+
const { id: _id, ...record } = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
2766
3925
|
try {
|
2767
3926
|
const response = await updateRecordWithID({
|
2768
3927
|
pathParams: {
|
@@ -2774,7 +3933,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2774
3933
|
},
|
2775
3934
|
queryParams: { columns, ifVersion },
|
2776
3935
|
body: record,
|
2777
|
-
...
|
3936
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2778
3937
|
});
|
2779
3938
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2780
3939
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2787,23 +3946,21 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2787
3946
|
};
|
2788
3947
|
_updateRecords = new WeakSet();
|
2789
3948
|
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2790
|
-
const
|
2791
|
-
|
2792
|
-
|
2793
|
-
|
2794
|
-
|
2795
|
-
BULK_OPERATION_MAX_SIZE
|
2796
|
-
);
|
3949
|
+
const operations = await promiseMap(objects, async ({ id, ...object }) => {
|
3950
|
+
const fields = await __privateMethod$2(this, _transformObjectToApi, transformObjectToApi_fn).call(this, object);
|
3951
|
+
return { update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields } };
|
3952
|
+
});
|
3953
|
+
const chunkedOperations = chunk(operations, BULK_OPERATION_MAX_SIZE);
|
2797
3954
|
const ids = [];
|
2798
|
-
for (const
|
3955
|
+
for (const operations2 of chunkedOperations) {
|
2799
3956
|
const { results } = await branchTransaction({
|
2800
3957
|
pathParams: {
|
2801
3958
|
workspace: "{workspaceId}",
|
2802
3959
|
dbBranchName: "{dbBranch}",
|
2803
3960
|
region: "{region}"
|
2804
3961
|
},
|
2805
|
-
body: { operations },
|
2806
|
-
...
|
3962
|
+
body: { operations: operations2 },
|
3963
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2807
3964
|
});
|
2808
3965
|
for (const result of results) {
|
2809
3966
|
if (result.operation === "update") {
|
@@ -2817,7 +3974,8 @@ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
|
2817
3974
|
};
|
2818
3975
|
_upsertRecordWithID = new WeakSet();
|
2819
3976
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
2820
|
-
|
3977
|
+
if (!recordId)
|
3978
|
+
return null;
|
2821
3979
|
const response = await upsertRecordWithID({
|
2822
3980
|
pathParams: {
|
2823
3981
|
workspace: "{workspaceId}",
|
@@ -2828,14 +3986,15 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVe
|
|
2828
3986
|
},
|
2829
3987
|
queryParams: { columns, ifVersion },
|
2830
3988
|
body: object,
|
2831
|
-
...
|
3989
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2832
3990
|
});
|
2833
3991
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2834
3992
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2835
3993
|
};
|
2836
3994
|
_deleteRecord = new WeakSet();
|
2837
3995
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
2838
|
-
|
3996
|
+
if (!recordId)
|
3997
|
+
return null;
|
2839
3998
|
try {
|
2840
3999
|
const response = await deleteRecord({
|
2841
4000
|
pathParams: {
|
@@ -2846,7 +4005,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2846
4005
|
recordId
|
2847
4006
|
},
|
2848
4007
|
queryParams: { columns },
|
2849
|
-
...
|
4008
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2850
4009
|
});
|
2851
4010
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2852
4011
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
@@ -2859,9 +4018,8 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
2859
4018
|
};
|
2860
4019
|
_deleteRecords = new WeakSet();
|
2861
4020
|
deleteRecords_fn = async function(recordIds) {
|
2862
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2863
4021
|
const chunkedOperations = chunk(
|
2864
|
-
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
4022
|
+
compact(recordIds).map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2865
4023
|
BULK_OPERATION_MAX_SIZE
|
2866
4024
|
);
|
2867
4025
|
for (const operations of chunkedOperations) {
|
@@ -2872,21 +4030,22 @@ deleteRecords_fn = async function(recordIds) {
|
|
2872
4030
|
region: "{region}"
|
2873
4031
|
},
|
2874
4032
|
body: { operations },
|
2875
|
-
...
|
4033
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2876
4034
|
});
|
2877
4035
|
}
|
2878
4036
|
};
|
2879
4037
|
_setCacheQuery = new WeakSet();
|
2880
4038
|
setCacheQuery_fn = async function(query, meta, records) {
|
2881
|
-
await __privateGet$4(this, _cache)
|
4039
|
+
await __privateGet$4(this, _cache)?.set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: /* @__PURE__ */ new Date(), meta, records });
|
2882
4040
|
};
|
2883
4041
|
_getCacheQuery = new WeakSet();
|
2884
4042
|
getCacheQuery_fn = async function(query) {
|
2885
4043
|
const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
|
2886
|
-
const result = await __privateGet$4(this, _cache)
|
4044
|
+
const result = await __privateGet$4(this, _cache)?.get(key);
|
2887
4045
|
if (!result)
|
2888
4046
|
return null;
|
2889
|
-
const
|
4047
|
+
const defaultTTL = __privateGet$4(this, _cache)?.defaultQueryTTL ?? -1;
|
4048
|
+
const { cache: ttl = defaultTTL } = query.getQueryOptions();
|
2890
4049
|
if (ttl < 0)
|
2891
4050
|
return null;
|
2892
4051
|
const hasExpired = result.date.getTime() + ttl < Date.now();
|
@@ -2896,20 +4055,47 @@ _getSchemaTables$1 = new WeakSet();
|
|
2896
4055
|
getSchemaTables_fn$1 = async function() {
|
2897
4056
|
if (__privateGet$4(this, _schemaTables$2))
|
2898
4057
|
return __privateGet$4(this, _schemaTables$2);
|
2899
|
-
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2900
4058
|
const { schema } = await getBranchDetails({
|
2901
4059
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
2902
|
-
...
|
4060
|
+
...__privateGet$4(this, _getFetchProps).call(this)
|
2903
4061
|
});
|
2904
4062
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
2905
4063
|
return schema.tables;
|
2906
4064
|
};
|
2907
|
-
|
2908
|
-
|
4065
|
+
_transformObjectToApi = new WeakSet();
|
4066
|
+
transformObjectToApi_fn = async function(object) {
|
4067
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
4068
|
+
const schema = schemaTables.find((table) => table.name === __privateGet$4(this, _table));
|
4069
|
+
if (!schema)
|
4070
|
+
throw new Error(`Table ${__privateGet$4(this, _table)} not found in schema`);
|
4071
|
+
const result = {};
|
4072
|
+
for (const [key, value] of Object.entries(object)) {
|
2909
4073
|
if (key === "xata")
|
2910
|
-
|
2911
|
-
|
2912
|
-
|
4074
|
+
continue;
|
4075
|
+
const type = schema.columns.find((column) => column.name === key)?.type;
|
4076
|
+
switch (type) {
|
4077
|
+
case "link": {
|
4078
|
+
result[key] = isIdentifiable(value) ? value.id : value;
|
4079
|
+
break;
|
4080
|
+
}
|
4081
|
+
case "datetime": {
|
4082
|
+
result[key] = value instanceof Date ? value.toISOString() : value;
|
4083
|
+
break;
|
4084
|
+
}
|
4085
|
+
case `file`:
|
4086
|
+
result[key] = await parseInputFileEntry(value);
|
4087
|
+
break;
|
4088
|
+
case "file[]":
|
4089
|
+
result[key] = await promiseMap(value, (item) => parseInputFileEntry(item));
|
4090
|
+
break;
|
4091
|
+
case "json":
|
4092
|
+
result[key] = stringifyJson(value);
|
4093
|
+
break;
|
4094
|
+
default:
|
4095
|
+
result[key] = value;
|
4096
|
+
}
|
4097
|
+
}
|
4098
|
+
return result;
|
2913
4099
|
};
|
2914
4100
|
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2915
4101
|
const data = {};
|
@@ -2941,18 +4127,33 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2941
4127
|
if (item === column.name) {
|
2942
4128
|
return [...acc, "*"];
|
2943
4129
|
}
|
2944
|
-
if (item.startsWith(`${column.name}.`)) {
|
4130
|
+
if (isString(item) && item.startsWith(`${column.name}.`)) {
|
2945
4131
|
const [, ...path] = item.split(".");
|
2946
4132
|
return [...acc, path.join(".")];
|
2947
4133
|
}
|
2948
4134
|
return acc;
|
2949
4135
|
}, []);
|
2950
|
-
data[column.name] = initObject(
|
4136
|
+
data[column.name] = initObject(
|
4137
|
+
db,
|
4138
|
+
schemaTables,
|
4139
|
+
linkTable,
|
4140
|
+
value,
|
4141
|
+
selectedLinkColumns
|
4142
|
+
);
|
2951
4143
|
} else {
|
2952
4144
|
data[column.name] = null;
|
2953
4145
|
}
|
2954
4146
|
break;
|
2955
4147
|
}
|
4148
|
+
case "file":
|
4149
|
+
data[column.name] = isDefined(value) ? new XataFile(value) : null;
|
4150
|
+
break;
|
4151
|
+
case "file[]":
|
4152
|
+
data[column.name] = value?.map((item) => new XataFile(item)) ?? null;
|
4153
|
+
break;
|
4154
|
+
case "json":
|
4155
|
+
data[column.name] = parseJson(value);
|
4156
|
+
break;
|
2956
4157
|
default:
|
2957
4158
|
data[column.name] = value ?? null;
|
2958
4159
|
if (column.notNull === true && value === null) {
|
@@ -2962,30 +4163,34 @@ const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
2962
4163
|
}
|
2963
4164
|
}
|
2964
4165
|
const record = { ...data };
|
4166
|
+
const metadata = xata !== void 0 ? { ...xata, createdAt: new Date(xata.createdAt), updatedAt: new Date(xata.updatedAt) } : void 0;
|
2965
4167
|
record.read = function(columns2) {
|
2966
4168
|
return db[table].read(record["id"], columns2);
|
2967
4169
|
};
|
2968
4170
|
record.update = function(data2, b, c) {
|
2969
|
-
const columns2 =
|
4171
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2970
4172
|
const ifVersion = parseIfVersion(b, c);
|
2971
4173
|
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
2972
4174
|
};
|
2973
4175
|
record.replace = function(data2, b, c) {
|
2974
|
-
const columns2 =
|
4176
|
+
const columns2 = isValidSelectableColumns(b) ? b : ["*"];
|
2975
4177
|
const ifVersion = parseIfVersion(b, c);
|
2976
4178
|
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
2977
4179
|
};
|
2978
4180
|
record.delete = function() {
|
2979
4181
|
return db[table].delete(record["id"]);
|
2980
4182
|
};
|
4183
|
+
if (metadata !== void 0) {
|
4184
|
+
record.xata = Object.freeze(metadata);
|
4185
|
+
}
|
2981
4186
|
record.getMetadata = function() {
|
2982
|
-
return xata;
|
4187
|
+
return record.xata;
|
2983
4188
|
};
|
2984
4189
|
record.toSerializable = function() {
|
2985
|
-
return JSON.parse(JSON.stringify(
|
4190
|
+
return JSON.parse(JSON.stringify(record));
|
2986
4191
|
};
|
2987
4192
|
record.toString = function() {
|
2988
|
-
return JSON.stringify(
|
4193
|
+
return JSON.stringify(record);
|
2989
4194
|
};
|
2990
4195
|
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2991
4196
|
Object.defineProperty(record, prop, { enumerable: false });
|
@@ -3003,11 +4208,7 @@ function extractId(value) {
|
|
3003
4208
|
function isValidColumn(columns, column) {
|
3004
4209
|
if (columns.includes("*"))
|
3005
4210
|
return true;
|
3006
|
-
|
3007
|
-
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
3008
|
-
return linkColumns.length > 0;
|
3009
|
-
}
|
3010
|
-
return columns.includes(column.name);
|
4211
|
+
return columns.filter((item) => isString(item) && item.startsWith(column.name)).length > 0;
|
3011
4212
|
}
|
3012
4213
|
function parseIfVersion(...args) {
|
3013
4214
|
for (const arg of args) {
|
@@ -3084,10 +4285,12 @@ const notExists = (column) => ({ $notExists: column });
|
|
3084
4285
|
const startsWith = (value) => ({ $startsWith: value });
|
3085
4286
|
const endsWith = (value) => ({ $endsWith: value });
|
3086
4287
|
const pattern = (value) => ({ $pattern: value });
|
4288
|
+
const iPattern = (value) => ({ $iPattern: value });
|
3087
4289
|
const is = (value) => ({ $is: value });
|
3088
4290
|
const equals = is;
|
3089
4291
|
const isNot = (value) => ({ $isNot: value });
|
3090
4292
|
const contains = (value) => ({ $contains: value });
|
4293
|
+
const iContains = (value) => ({ $iContains: value });
|
3091
4294
|
const includes = (value) => ({ $includes: value });
|
3092
4295
|
const includesAll = (value) => ({ $includesAll: value });
|
3093
4296
|
const includesNone = (value) => ({ $includesNone: value });
|
@@ -3143,6 +4346,80 @@ class SchemaPlugin extends XataPlugin {
|
|
3143
4346
|
_tables = new WeakMap();
|
3144
4347
|
_schemaTables$1 = new WeakMap();
|
3145
4348
|
|
4349
|
+
class FilesPlugin extends XataPlugin {
|
4350
|
+
build(pluginOptions) {
|
4351
|
+
return {
|
4352
|
+
download: async (location) => {
|
4353
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4354
|
+
return await getFileItem({
|
4355
|
+
pathParams: {
|
4356
|
+
workspace: "{workspaceId}",
|
4357
|
+
dbBranchName: "{dbBranch}",
|
4358
|
+
region: "{region}",
|
4359
|
+
tableName: table ?? "",
|
4360
|
+
recordId: record ?? "",
|
4361
|
+
columnName: column ?? "",
|
4362
|
+
fileId
|
4363
|
+
},
|
4364
|
+
...pluginOptions,
|
4365
|
+
rawResponse: true
|
4366
|
+
});
|
4367
|
+
},
|
4368
|
+
upload: async (location, file, options) => {
|
4369
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4370
|
+
const resolvedFile = await file;
|
4371
|
+
const contentType = options?.mediaType || getContentType(resolvedFile);
|
4372
|
+
const body = resolvedFile instanceof XataFile ? resolvedFile.toBlob() : resolvedFile;
|
4373
|
+
return await putFileItem({
|
4374
|
+
...pluginOptions,
|
4375
|
+
pathParams: {
|
4376
|
+
workspace: "{workspaceId}",
|
4377
|
+
dbBranchName: "{dbBranch}",
|
4378
|
+
region: "{region}",
|
4379
|
+
tableName: table ?? "",
|
4380
|
+
recordId: record ?? "",
|
4381
|
+
columnName: column ?? "",
|
4382
|
+
fileId
|
4383
|
+
},
|
4384
|
+
body,
|
4385
|
+
headers: { "Content-Type": contentType }
|
4386
|
+
});
|
4387
|
+
},
|
4388
|
+
delete: async (location) => {
|
4389
|
+
const { table, record, column, fileId = "" } = location ?? {};
|
4390
|
+
return await deleteFileItem({
|
4391
|
+
pathParams: {
|
4392
|
+
workspace: "{workspaceId}",
|
4393
|
+
dbBranchName: "{dbBranch}",
|
4394
|
+
region: "{region}",
|
4395
|
+
tableName: table ?? "",
|
4396
|
+
recordId: record ?? "",
|
4397
|
+
columnName: column ?? "",
|
4398
|
+
fileId
|
4399
|
+
},
|
4400
|
+
...pluginOptions
|
4401
|
+
});
|
4402
|
+
}
|
4403
|
+
};
|
4404
|
+
}
|
4405
|
+
}
|
4406
|
+
function getContentType(file) {
|
4407
|
+
if (typeof file === "string") {
|
4408
|
+
return "text/plain";
|
4409
|
+
}
|
4410
|
+
if ("mediaType" in file && file.mediaType !== void 0) {
|
4411
|
+
return file.mediaType;
|
4412
|
+
}
|
4413
|
+
if (isBlob(file)) {
|
4414
|
+
return file.type;
|
4415
|
+
}
|
4416
|
+
try {
|
4417
|
+
return file.type;
|
4418
|
+
} catch (e) {
|
4419
|
+
}
|
4420
|
+
return "application/octet-stream";
|
4421
|
+
}
|
4422
|
+
|
3146
4423
|
var __accessCheck$1 = (obj, member, msg) => {
|
3147
4424
|
if (!member.has(obj))
|
3148
4425
|
throw TypeError("Cannot " + msg);
|
@@ -3175,63 +4452,137 @@ class SearchPlugin extends XataPlugin {
|
|
3175
4452
|
__privateAdd$1(this, _schemaTables, void 0);
|
3176
4453
|
__privateSet$1(this, _schemaTables, schemaTables);
|
3177
4454
|
}
|
3178
|
-
build(
|
4455
|
+
build(pluginOptions) {
|
3179
4456
|
return {
|
3180
4457
|
all: async (query, options = {}) => {
|
3181
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3182
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3183
|
-
return
|
3184
|
-
|
3185
|
-
|
3186
|
-
|
4458
|
+
const { records, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4459
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4460
|
+
return {
|
4461
|
+
totalCount,
|
4462
|
+
records: records.map((record) => {
|
4463
|
+
const { table = "orphan" } = record.xata;
|
4464
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
4465
|
+
})
|
4466
|
+
};
|
3187
4467
|
},
|
3188
4468
|
byTable: async (query, options = {}) => {
|
3189
|
-
const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options,
|
3190
|
-
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this,
|
3191
|
-
|
4469
|
+
const { records: rawRecords, totalCount } = await __privateMethod$1(this, _search, search_fn).call(this, query, options, pluginOptions);
|
4470
|
+
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, pluginOptions);
|
4471
|
+
const records = rawRecords.reduce((acc, record) => {
|
3192
4472
|
const { table = "orphan" } = record.xata;
|
3193
4473
|
const items = acc[table] ?? [];
|
3194
4474
|
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
3195
4475
|
return { ...acc, [table]: [...items, item] };
|
3196
4476
|
}, {});
|
4477
|
+
return { totalCount, records };
|
3197
4478
|
}
|
3198
4479
|
};
|
3199
4480
|
}
|
3200
4481
|
}
|
3201
4482
|
_schemaTables = new WeakMap();
|
3202
4483
|
_search = new WeakSet();
|
3203
|
-
search_fn = async function(query, options,
|
3204
|
-
const fetchProps = await getFetchProps();
|
4484
|
+
search_fn = async function(query, options, pluginOptions) {
|
3205
4485
|
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
3206
|
-
const { records } = await searchBranch({
|
4486
|
+
const { records, totalCount } = await searchBranch({
|
3207
4487
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4488
|
+
// @ts-ignore https://github.com/xataio/client-ts/issues/313
|
3208
4489
|
body: { tables, query, fuzziness, prefix, highlight, page },
|
3209
|
-
...
|
4490
|
+
...pluginOptions
|
3210
4491
|
});
|
3211
|
-
return records;
|
4492
|
+
return { records, totalCount };
|
3212
4493
|
};
|
3213
4494
|
_getSchemaTables = new WeakSet();
|
3214
|
-
getSchemaTables_fn = async function(
|
4495
|
+
getSchemaTables_fn = async function(pluginOptions) {
|
3215
4496
|
if (__privateGet$1(this, _schemaTables))
|
3216
4497
|
return __privateGet$1(this, _schemaTables);
|
3217
|
-
const fetchProps = await getFetchProps();
|
3218
4498
|
const { schema } = await getBranchDetails({
|
3219
4499
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3220
|
-
...
|
4500
|
+
...pluginOptions
|
3221
4501
|
});
|
3222
4502
|
__privateSet$1(this, _schemaTables, schema.tables);
|
3223
4503
|
return schema.tables;
|
3224
4504
|
};
|
3225
4505
|
|
4506
|
+
function escapeElement(elementRepresentation) {
|
4507
|
+
const escaped = elementRepresentation.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
4508
|
+
return '"' + escaped + '"';
|
4509
|
+
}
|
4510
|
+
function arrayString(val) {
|
4511
|
+
let result = "{";
|
4512
|
+
for (let i = 0; i < val.length; i++) {
|
4513
|
+
if (i > 0) {
|
4514
|
+
result = result + ",";
|
4515
|
+
}
|
4516
|
+
if (val[i] === null || typeof val[i] === "undefined") {
|
4517
|
+
result = result + "NULL";
|
4518
|
+
} else if (Array.isArray(val[i])) {
|
4519
|
+
result = result + arrayString(val[i]);
|
4520
|
+
} else if (val[i] instanceof Buffer) {
|
4521
|
+
result += "\\\\x" + val[i].toString("hex");
|
4522
|
+
} else {
|
4523
|
+
result += escapeElement(prepareValue(val[i]));
|
4524
|
+
}
|
4525
|
+
}
|
4526
|
+
result = result + "}";
|
4527
|
+
return result;
|
4528
|
+
}
|
4529
|
+
function prepareValue(value) {
|
4530
|
+
if (!isDefined(value))
|
4531
|
+
return null;
|
4532
|
+
if (value instanceof Date) {
|
4533
|
+
return value.toISOString();
|
4534
|
+
}
|
4535
|
+
if (Array.isArray(value)) {
|
4536
|
+
return arrayString(value);
|
4537
|
+
}
|
4538
|
+
if (isObject(value)) {
|
4539
|
+
return JSON.stringify(value);
|
4540
|
+
}
|
4541
|
+
try {
|
4542
|
+
return value.toString();
|
4543
|
+
} catch (e) {
|
4544
|
+
return value;
|
4545
|
+
}
|
4546
|
+
}
|
4547
|
+
function prepareParams(param1, param2) {
|
4548
|
+
if (isString(param1)) {
|
4549
|
+
return { statement: param1, params: param2?.map((value) => prepareValue(value)) };
|
4550
|
+
}
|
4551
|
+
if (isStringArray(param1)) {
|
4552
|
+
const statement = param1.reduce((acc, curr, index) => {
|
4553
|
+
return acc + curr + (index < (param2?.length ?? 0) ? "$" + (index + 1) : "");
|
4554
|
+
}, "");
|
4555
|
+
return { statement, params: param2?.map((value) => prepareValue(value)) };
|
4556
|
+
}
|
4557
|
+
if (isObject(param1)) {
|
4558
|
+
const { statement, params, consistency } = param1;
|
4559
|
+
return { statement, params: params?.map((value) => prepareValue(value)), consistency };
|
4560
|
+
}
|
4561
|
+
throw new Error("Invalid query");
|
4562
|
+
}
|
4563
|
+
|
4564
|
+
class SQLPlugin extends XataPlugin {
|
4565
|
+
build(pluginOptions) {
|
4566
|
+
return async (param1, ...param2) => {
|
4567
|
+
const { statement, params, consistency } = prepareParams(param1, param2);
|
4568
|
+
const { records, warning } = await sqlQuery({
|
4569
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
4570
|
+
body: { statement, params, consistency },
|
4571
|
+
...pluginOptions
|
4572
|
+
});
|
4573
|
+
return { records, warning };
|
4574
|
+
};
|
4575
|
+
}
|
4576
|
+
}
|
4577
|
+
|
3226
4578
|
class TransactionPlugin extends XataPlugin {
|
3227
|
-
build(
|
4579
|
+
build(pluginOptions) {
|
3228
4580
|
return {
|
3229
4581
|
run: async (operations) => {
|
3230
|
-
const fetchProps = await getFetchProps();
|
3231
4582
|
const response = await branchTransaction({
|
3232
4583
|
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3233
4584
|
body: { operations },
|
3234
|
-
...
|
4585
|
+
...pluginOptions
|
3235
4586
|
});
|
3236
4587
|
return response;
|
3237
4588
|
}
|
@@ -3239,91 +4590,6 @@ class TransactionPlugin extends XataPlugin {
|
|
3239
4590
|
}
|
3240
4591
|
}
|
3241
4592
|
|
3242
|
-
const isBranchStrategyBuilder = (strategy) => {
|
3243
|
-
return typeof strategy === "function";
|
3244
|
-
};
|
3245
|
-
|
3246
|
-
async function getCurrentBranchName(options) {
|
3247
|
-
const { branch, envBranch } = getEnvironment();
|
3248
|
-
if (branch)
|
3249
|
-
return branch;
|
3250
|
-
const gitBranch = envBranch || await getGitBranch();
|
3251
|
-
return resolveXataBranch(gitBranch, options);
|
3252
|
-
}
|
3253
|
-
async function getCurrentBranchDetails(options) {
|
3254
|
-
const branch = await getCurrentBranchName(options);
|
3255
|
-
return getDatabaseBranch(branch, options);
|
3256
|
-
}
|
3257
|
-
async function resolveXataBranch(gitBranch, options) {
|
3258
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3259
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3260
|
-
if (!databaseURL)
|
3261
|
-
throw new Error(
|
3262
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3263
|
-
);
|
3264
|
-
if (!apiKey)
|
3265
|
-
throw new Error(
|
3266
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3267
|
-
);
|
3268
|
-
const [protocol, , host, , dbName] = databaseURL.split("/");
|
3269
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3270
|
-
if (!urlParts)
|
3271
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3272
|
-
const { workspace, region } = urlParts;
|
3273
|
-
const { fallbackBranch } = getEnvironment();
|
3274
|
-
const { branch } = await resolveBranch({
|
3275
|
-
apiKey,
|
3276
|
-
apiUrl: databaseURL,
|
3277
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3278
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3279
|
-
pathParams: { dbName, workspace, region },
|
3280
|
-
queryParams: { gitBranch, fallbackBranch },
|
3281
|
-
trace: defaultTrace,
|
3282
|
-
clientName: options?.clientName,
|
3283
|
-
xataAgentExtra: options?.xataAgentExtra
|
3284
|
-
});
|
3285
|
-
return branch;
|
3286
|
-
}
|
3287
|
-
async function getDatabaseBranch(branch, options) {
|
3288
|
-
const databaseURL = options?.databaseURL || getDatabaseURL();
|
3289
|
-
const apiKey = options?.apiKey || getAPIKey();
|
3290
|
-
if (!databaseURL)
|
3291
|
-
throw new Error(
|
3292
|
-
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3293
|
-
);
|
3294
|
-
if (!apiKey)
|
3295
|
-
throw new Error(
|
3296
|
-
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3297
|
-
);
|
3298
|
-
const [protocol, , host, , database] = databaseURL.split("/");
|
3299
|
-
const urlParts = parseWorkspacesUrlParts(host);
|
3300
|
-
if (!urlParts)
|
3301
|
-
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3302
|
-
const { workspace, region } = urlParts;
|
3303
|
-
try {
|
3304
|
-
return await getBranchDetails({
|
3305
|
-
apiKey,
|
3306
|
-
apiUrl: databaseURL,
|
3307
|
-
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
3308
|
-
workspacesApiUrl: `${protocol}//${host}`,
|
3309
|
-
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3310
|
-
trace: defaultTrace
|
3311
|
-
});
|
3312
|
-
} catch (err) {
|
3313
|
-
if (isObject(err) && err.status === 404)
|
3314
|
-
return null;
|
3315
|
-
throw err;
|
3316
|
-
}
|
3317
|
-
}
|
3318
|
-
function getDatabaseURL() {
|
3319
|
-
try {
|
3320
|
-
const { databaseURL } = getEnvironment();
|
3321
|
-
return databaseURL;
|
3322
|
-
} catch (err) {
|
3323
|
-
return void 0;
|
3324
|
-
}
|
3325
|
-
}
|
3326
|
-
|
3327
4593
|
var __accessCheck = (obj, member, msg) => {
|
3328
4594
|
if (!member.has(obj))
|
3329
4595
|
throw TypeError("Cannot " + msg);
|
@@ -3347,46 +4613,41 @@ var __privateMethod = (obj, member, method) => {
|
|
3347
4613
|
return method;
|
3348
4614
|
};
|
3349
4615
|
const buildClient = (plugins) => {
|
3350
|
-
var
|
4616
|
+
var _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _a;
|
3351
4617
|
return _a = class {
|
3352
4618
|
constructor(options = {}, schemaTables) {
|
3353
4619
|
__privateAdd(this, _parseOptions);
|
3354
4620
|
__privateAdd(this, _getFetchProps);
|
3355
|
-
__privateAdd(this, _evaluateBranch);
|
3356
|
-
__privateAdd(this, _branch, void 0);
|
3357
4621
|
__privateAdd(this, _options, void 0);
|
3358
4622
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3359
4623
|
__privateSet(this, _options, safeOptions);
|
3360
4624
|
const pluginOptions = {
|
3361
|
-
|
4625
|
+
...__privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
3362
4626
|
cache: safeOptions.cache,
|
3363
|
-
|
4627
|
+
host: safeOptions.host
|
3364
4628
|
};
|
3365
4629
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
3366
4630
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3367
4631
|
const transactions = new TransactionPlugin().build(pluginOptions);
|
4632
|
+
const sql = new SQLPlugin().build(pluginOptions);
|
4633
|
+
const files = new FilesPlugin().build(pluginOptions);
|
3368
4634
|
this.db = db;
|
3369
4635
|
this.search = search;
|
3370
4636
|
this.transactions = transactions;
|
4637
|
+
this.sql = sql;
|
4638
|
+
this.files = files;
|
3371
4639
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
3372
4640
|
if (namespace === void 0)
|
3373
4641
|
continue;
|
3374
|
-
|
3375
|
-
if (result instanceof Promise) {
|
3376
|
-
void result.then((namespace2) => {
|
3377
|
-
this[key] = namespace2;
|
3378
|
-
});
|
3379
|
-
} else {
|
3380
|
-
this[key] = result;
|
3381
|
-
}
|
4642
|
+
this[key] = namespace.build(pluginOptions);
|
3382
4643
|
}
|
3383
4644
|
}
|
3384
4645
|
async getConfig() {
|
3385
4646
|
const databaseURL = __privateGet(this, _options).databaseURL;
|
3386
|
-
const branch =
|
4647
|
+
const branch = __privateGet(this, _options).branch;
|
3387
4648
|
return { databaseURL, branch };
|
3388
4649
|
}
|
3389
|
-
},
|
4650
|
+
}, _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3390
4651
|
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3391
4652
|
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3392
4653
|
if (isBrowser && !enableBrowser) {
|
@@ -3400,20 +4661,34 @@ const buildClient = (plugins) => {
|
|
3400
4661
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3401
4662
|
const trace = options?.trace ?? defaultTrace;
|
3402
4663
|
const clientName = options?.clientName;
|
4664
|
+
const host = options?.host ?? "production";
|
3403
4665
|
const xataAgentExtra = options?.xataAgentExtra;
|
3404
|
-
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
|
3405
|
-
apiKey,
|
3406
|
-
databaseURL,
|
3407
|
-
fetchImpl: options?.fetch,
|
3408
|
-
clientName,
|
3409
|
-
xataAgentExtra
|
3410
|
-
});
|
3411
4666
|
if (!apiKey) {
|
3412
4667
|
throw new Error("Option apiKey is required");
|
3413
4668
|
}
|
3414
4669
|
if (!databaseURL) {
|
3415
4670
|
throw new Error("Option databaseURL is required");
|
3416
4671
|
}
|
4672
|
+
const envBranch = getBranch();
|
4673
|
+
const previewBranch = getPreviewBranch();
|
4674
|
+
const branch = options?.branch || previewBranch || envBranch || "main";
|
4675
|
+
if (!!previewBranch && branch !== previewBranch) {
|
4676
|
+
console.warn(
|
4677
|
+
`Ignoring preview branch ${previewBranch} because branch option was passed to the client constructor with value ${branch}`
|
4678
|
+
);
|
4679
|
+
} else if (!!envBranch && branch !== envBranch) {
|
4680
|
+
console.warn(
|
4681
|
+
`Ignoring branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4682
|
+
);
|
4683
|
+
} else if (!!previewBranch && !!envBranch && previewBranch !== envBranch) {
|
4684
|
+
console.warn(
|
4685
|
+
`Ignoring preview branch ${previewBranch} and branch ${envBranch} because branch option was passed to the client constructor with value ${branch}`
|
4686
|
+
);
|
4687
|
+
} else if (!previewBranch && !envBranch && options?.branch === void 0) {
|
4688
|
+
console.warn(
|
4689
|
+
`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.`
|
4690
|
+
);
|
4691
|
+
}
|
3417
4692
|
return {
|
3418
4693
|
fetch,
|
3419
4694
|
databaseURL,
|
@@ -3421,12 +4696,13 @@ const buildClient = (plugins) => {
|
|
3421
4696
|
branch,
|
3422
4697
|
cache,
|
3423
4698
|
trace,
|
4699
|
+
host,
|
3424
4700
|
clientID: generateUUID(),
|
3425
4701
|
enableBrowser,
|
3426
4702
|
clientName,
|
3427
4703
|
xataAgentExtra
|
3428
4704
|
};
|
3429
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn =
|
4705
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = function({
|
3430
4706
|
fetch,
|
3431
4707
|
apiKey,
|
3432
4708
|
databaseURL,
|
@@ -3436,16 +4712,14 @@ const buildClient = (plugins) => {
|
|
3436
4712
|
clientName,
|
3437
4713
|
xataAgentExtra
|
3438
4714
|
}) {
|
3439
|
-
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
3440
|
-
if (!branchValue)
|
3441
|
-
throw new Error("Unable to resolve branch value");
|
3442
4715
|
return {
|
3443
|
-
|
4716
|
+
fetch,
|
3444
4717
|
apiKey,
|
3445
4718
|
apiUrl: "",
|
4719
|
+
// Instead of using workspace and dbBranch, we inject a probably CNAME'd URL
|
3446
4720
|
workspacesApiUrl: (path, params) => {
|
3447
4721
|
const hasBranch = params.dbBranchName ?? params.branch;
|
3448
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${
|
4722
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branch}` : "");
|
3449
4723
|
return databaseURL + newPath;
|
3450
4724
|
},
|
3451
4725
|
trace,
|
@@ -3453,22 +4727,6 @@ const buildClient = (plugins) => {
|
|
3453
4727
|
clientName,
|
3454
4728
|
xataAgentExtra
|
3455
4729
|
};
|
3456
|
-
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
3457
|
-
if (__privateGet(this, _branch))
|
3458
|
-
return __privateGet(this, _branch);
|
3459
|
-
if (param === void 0)
|
3460
|
-
return void 0;
|
3461
|
-
const strategies = Array.isArray(param) ? [...param] : [param];
|
3462
|
-
const evaluateBranch = async (strategy) => {
|
3463
|
-
return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
|
3464
|
-
};
|
3465
|
-
for await (const strategy of strategies) {
|
3466
|
-
const branch = await evaluateBranch(strategy);
|
3467
|
-
if (branch) {
|
3468
|
-
__privateSet(this, _branch, branch);
|
3469
|
-
return branch;
|
3470
|
-
}
|
3471
|
-
}
|
3472
4730
|
}, _a;
|
3473
4731
|
};
|
3474
4732
|
class BaseClient extends buildClient() {
|
@@ -3541,21 +4799,6 @@ const deserialize = (json) => {
|
|
3541
4799
|
return defaultSerializer.fromJSON(json);
|
3542
4800
|
};
|
3543
4801
|
|
3544
|
-
function buildWorkerRunner(config) {
|
3545
|
-
return function xataWorker(name, worker) {
|
3546
|
-
return async (...args) => {
|
3547
|
-
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3548
|
-
const result = await fetch(url, {
|
3549
|
-
method: "POST",
|
3550
|
-
headers: { "Content-Type": "application/json" },
|
3551
|
-
body: serialize({ args })
|
3552
|
-
});
|
3553
|
-
const text = await result.text();
|
3554
|
-
return deserialize(text);
|
3555
|
-
};
|
3556
|
-
};
|
3557
|
-
}
|
3558
|
-
|
3559
4802
|
class XataError extends Error {
|
3560
4803
|
constructor(message, status) {
|
3561
4804
|
super(message);
|
@@ -3563,5 +4806,5 @@ class XataError extends Error {
|
|
3563
4806
|
}
|
3564
4807
|
}
|
3565
4808
|
|
3566
|
-
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient,
|
4809
|
+
export { BaseClient, FetcherError, FilesPlugin, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, RecordColumnTypes, Repository, RestRepository, SQLPlugin, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, TransactionPlugin, XataApiClient, XataApiPlugin, XataError, XataFile, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, applyMigration, askTable, askTableSession, branchTransaction, buildClient, buildPreviewBranchName, buildProviderString, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, copyBranch, createBranch, createCluster, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteDatabaseGithubSettings, deleteFile, deleteFileItem, deleteOAuthAccessToken, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteUserOAuthClient, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, fileAccess, fileUpload, ge, getAPIKey, getAuthorizationCode, getBranch, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getCluster, getColumn, getDatabaseGithubSettings, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getFile, getFileItem, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getPreviewBranch, getRecord, getSchema, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getUserOAuthAccessTokens, getUserOAuthClients, getWorkspace, getWorkspaceMembersList, getWorkspacesList, grantAuthorizationCode, greaterEquals, greaterThan, greaterThanEquals, gt, gte, iContains, iPattern, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isValidExpandedColumn, isValidSelectableColumns, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listClusters, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, pgRollJobStatus, pgRollMigrationHistory, pgRollStatus, previewBranchSchemaEdit, pushBranchMigrations, putFile, putFileItem, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, renameDatabase, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, sqlQuery, startsWith, summarizeTable, transformImage, updateBranchMetadata, updateBranchSchema, updateCluster, updateColumn, updateDatabaseGithubSettings, updateDatabaseMetadata, updateMigrationRequest, updateOAuthAccessToken, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID, vectorSearchTable };
|
3567
4810
|
//# sourceMappingURL=index.mjs.map
|