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