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