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