@xata.io/client 0.0.0-alpha.vf603f80 → 0.0.0-alpha.vf61048f
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 -2
- package/.turbo/turbo-add-version.log +4 -0
- package/.turbo/turbo-build.log +13 -0
- package/CHANGELOG.md +268 -0
- package/README.md +41 -32
- package/Usage.md +67 -11
- package/dist/index.cjs +2152 -805
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5227 -1486
- package/dist/index.mjs +2121 -788
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -9
- package/rollup.config.mjs +44 -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
|
}
|
@@ -13,6 +36,24 @@ function isDefined(value) {
|
|
13
36
|
function isString(value) {
|
14
37
|
return isDefined(value) && typeof value === "string";
|
15
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
|
+
}
|
16
57
|
function toBase64(value) {
|
17
58
|
try {
|
18
59
|
return btoa(value);
|
@@ -21,10 +62,31 @@ function toBase64(value) {
|
|
21
62
|
return buf.from(value).toString("base64");
|
22
63
|
}
|
23
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));
|
85
|
+
}
|
24
86
|
|
25
87
|
function getEnvironment() {
|
26
88
|
try {
|
27
|
-
if (
|
89
|
+
if (isDefined(process) && isDefined(process.env)) {
|
28
90
|
return {
|
29
91
|
apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
|
30
92
|
databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
|
@@ -55,6 +117,25 @@ function getEnvironment() {
|
|
55
117
|
fallbackBranch: getGlobalFallbackBranch()
|
56
118
|
};
|
57
119
|
}
|
120
|
+
function getEnableBrowserVariable() {
|
121
|
+
try {
|
122
|
+
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
123
|
+
return process.env.XATA_ENABLE_BROWSER === "true";
|
124
|
+
}
|
125
|
+
} catch (err) {
|
126
|
+
}
|
127
|
+
try {
|
128
|
+
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
129
|
+
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
130
|
+
}
|
131
|
+
} catch (err) {
|
132
|
+
}
|
133
|
+
try {
|
134
|
+
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
135
|
+
} catch (err) {
|
136
|
+
return void 0;
|
137
|
+
}
|
138
|
+
}
|
58
139
|
function getGlobalApiKey() {
|
59
140
|
try {
|
60
141
|
return XATA_API_KEY;
|
@@ -89,9 +170,6 @@ async function getGitBranch() {
|
|
89
170
|
const nodeModule = ["child", "process"].join("_");
|
90
171
|
const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
|
91
172
|
try {
|
92
|
-
if (typeof require === "function") {
|
93
|
-
return require(nodeModule).execSync(fullCmd, execOptions).trim();
|
94
|
-
}
|
95
173
|
const { execSync } = await import(nodeModule);
|
96
174
|
return execSync(fullCmd, execOptions).toString().trim();
|
97
175
|
} catch (err) {
|
@@ -114,16 +192,114 @@ function getAPIKey() {
|
|
114
192
|
}
|
115
193
|
}
|
116
194
|
|
195
|
+
var __accessCheck$8 = (obj, member, msg) => {
|
196
|
+
if (!member.has(obj))
|
197
|
+
throw TypeError("Cannot " + msg);
|
198
|
+
};
|
199
|
+
var __privateGet$8 = (obj, member, getter) => {
|
200
|
+
__accessCheck$8(obj, member, "read from private field");
|
201
|
+
return getter ? getter.call(obj) : member.get(obj);
|
202
|
+
};
|
203
|
+
var __privateAdd$8 = (obj, member, value) => {
|
204
|
+
if (member.has(obj))
|
205
|
+
throw TypeError("Cannot add the same private member more than once");
|
206
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
207
|
+
};
|
208
|
+
var __privateSet$8 = (obj, member, value, setter) => {
|
209
|
+
__accessCheck$8(obj, member, "write to private field");
|
210
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
211
|
+
return value;
|
212
|
+
};
|
213
|
+
var __privateMethod$4 = (obj, member, method) => {
|
214
|
+
__accessCheck$8(obj, member, "access private method");
|
215
|
+
return method;
|
216
|
+
};
|
217
|
+
var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
|
117
218
|
function getFetchImplementation(userFetch) {
|
118
219
|
const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
|
119
220
|
const fetchImpl = userFetch ?? globalFetch;
|
120
221
|
if (!fetchImpl) {
|
121
|
-
throw new Error(
|
222
|
+
throw new Error(
|
223
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
224
|
+
);
|
122
225
|
}
|
123
226
|
return fetchImpl;
|
124
227
|
}
|
228
|
+
class ApiRequestPool {
|
229
|
+
constructor(concurrency = 10) {
|
230
|
+
__privateAdd$8(this, _enqueue);
|
231
|
+
__privateAdd$8(this, _fetch, void 0);
|
232
|
+
__privateAdd$8(this, _queue, void 0);
|
233
|
+
__privateAdd$8(this, _concurrency, void 0);
|
234
|
+
__privateSet$8(this, _queue, []);
|
235
|
+
__privateSet$8(this, _concurrency, concurrency);
|
236
|
+
this.running = 0;
|
237
|
+
this.started = 0;
|
238
|
+
}
|
239
|
+
setFetch(fetch2) {
|
240
|
+
__privateSet$8(this, _fetch, fetch2);
|
241
|
+
}
|
242
|
+
getFetch() {
|
243
|
+
if (!__privateGet$8(this, _fetch)) {
|
244
|
+
throw new Error("Fetch not set");
|
245
|
+
}
|
246
|
+
return __privateGet$8(this, _fetch);
|
247
|
+
}
|
248
|
+
request(url, options) {
|
249
|
+
const start = new Date();
|
250
|
+
const fetch2 = this.getFetch();
|
251
|
+
const runRequest = async (stalled = false) => {
|
252
|
+
const response = await fetch2(url, options);
|
253
|
+
if (response.status === 429) {
|
254
|
+
const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
|
255
|
+
await timeout(rateLimitReset * 1e3);
|
256
|
+
return await runRequest(true);
|
257
|
+
}
|
258
|
+
if (stalled) {
|
259
|
+
const stalledTime = new Date().getTime() - start.getTime();
|
260
|
+
console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
|
261
|
+
}
|
262
|
+
return response;
|
263
|
+
};
|
264
|
+
return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
|
265
|
+
return await runRequest();
|
266
|
+
});
|
267
|
+
}
|
268
|
+
}
|
269
|
+
_fetch = new WeakMap();
|
270
|
+
_queue = new WeakMap();
|
271
|
+
_concurrency = new WeakMap();
|
272
|
+
_enqueue = new WeakSet();
|
273
|
+
enqueue_fn = function(task) {
|
274
|
+
const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
|
275
|
+
this.started--;
|
276
|
+
this.running++;
|
277
|
+
}).then(() => task()).finally(() => {
|
278
|
+
this.running--;
|
279
|
+
const next = __privateGet$8(this, _queue).shift();
|
280
|
+
if (next !== void 0) {
|
281
|
+
this.started++;
|
282
|
+
next();
|
283
|
+
}
|
284
|
+
});
|
285
|
+
if (this.running + this.started < __privateGet$8(this, _concurrency)) {
|
286
|
+
const next = __privateGet$8(this, _queue).shift();
|
287
|
+
if (next !== void 0) {
|
288
|
+
this.started++;
|
289
|
+
next();
|
290
|
+
}
|
291
|
+
}
|
292
|
+
return promise;
|
293
|
+
};
|
294
|
+
|
295
|
+
function generateUUID() {
|
296
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
297
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
298
|
+
return v.toString(16);
|
299
|
+
});
|
300
|
+
}
|
125
301
|
|
126
|
-
const VERSION = "0.
|
302
|
+
const VERSION = "0.21.6";
|
127
303
|
|
128
304
|
class ErrorWithCause extends Error {
|
129
305
|
constructor(message, options) {
|
@@ -134,7 +310,7 @@ class FetcherError extends ErrorWithCause {
|
|
134
310
|
constructor(status, data, requestId) {
|
135
311
|
super(getMessage(data));
|
136
312
|
this.status = status;
|
137
|
-
this.errors = isBulkError(data) ? data.errors :
|
313
|
+
this.errors = isBulkError(data) ? data.errors : [{ message: getMessage(data), status }];
|
138
314
|
this.requestId = requestId;
|
139
315
|
if (data instanceof Error) {
|
140
316
|
this.stack = data.stack;
|
@@ -166,6 +342,7 @@ function getMessage(data) {
|
|
166
342
|
}
|
167
343
|
}
|
168
344
|
|
345
|
+
const pool = new ApiRequestPool();
|
169
346
|
const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
170
347
|
const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
|
171
348
|
if (value === void 0 || value === null)
|
@@ -174,307 +351,266 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
174
351
|
}, {});
|
175
352
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
176
353
|
const queryString = query.length > 0 ? `?${query}` : "";
|
177
|
-
|
354
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
355
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
356
|
+
}, {});
|
357
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
178
358
|
};
|
179
359
|
function buildBaseUrl({
|
360
|
+
endpoint,
|
180
361
|
path,
|
181
362
|
workspacesApiUrl,
|
182
363
|
apiUrl,
|
183
|
-
pathParams
|
364
|
+
pathParams = {}
|
184
365
|
}) {
|
185
|
-
if (
|
186
|
-
|
187
|
-
|
188
|
-
|
366
|
+
if (endpoint === "dataPlane") {
|
367
|
+
const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
368
|
+
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
369
|
+
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
370
|
+
}
|
371
|
+
return `${apiUrl}${path}`;
|
189
372
|
}
|
190
373
|
function hostHeader(url) {
|
191
374
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
192
375
|
const { groups } = pattern.exec(url) ?? {};
|
193
376
|
return groups?.host ? { Host: groups.host } : {};
|
194
377
|
}
|
378
|
+
const defaultClientID = generateUUID();
|
195
379
|
async function fetch$1({
|
196
380
|
url: path,
|
197
381
|
method,
|
198
382
|
body,
|
199
|
-
headers,
|
383
|
+
headers: customHeaders,
|
200
384
|
pathParams,
|
201
385
|
queryParams,
|
202
386
|
fetchImpl,
|
203
387
|
apiKey,
|
388
|
+
endpoint,
|
204
389
|
apiUrl,
|
205
|
-
workspacesApiUrl
|
390
|
+
workspacesApiUrl,
|
391
|
+
trace,
|
392
|
+
signal,
|
393
|
+
clientID,
|
394
|
+
sessionID,
|
395
|
+
clientName,
|
396
|
+
fetchOptions = {}
|
206
397
|
}) {
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
398
|
+
pool.setFetch(fetchImpl);
|
399
|
+
return await trace(
|
400
|
+
`${method.toUpperCase()} ${path}`,
|
401
|
+
async ({ setAttributes }) => {
|
402
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
403
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
404
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
405
|
+
setAttributes({
|
406
|
+
[TraceAttributes.HTTP_URL]: url,
|
407
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
408
|
+
});
|
409
|
+
const xataAgent = compact([
|
410
|
+
["client", "TS_SDK"],
|
411
|
+
["version", VERSION],
|
412
|
+
isDefined(clientName) ? ["service", clientName] : void 0
|
413
|
+
]).map(([key, value]) => `${key}=${value}`).join("; ");
|
414
|
+
const headers = {
|
415
|
+
"Accept-Encoding": "identity",
|
416
|
+
"Content-Type": "application/json",
|
417
|
+
"X-Xata-Client-ID": clientID ?? defaultClientID,
|
418
|
+
"X-Xata-Session-ID": sessionID ?? generateUUID(),
|
419
|
+
"X-Xata-Agent": xataAgent,
|
420
|
+
...customHeaders,
|
421
|
+
...hostHeader(fullUrl),
|
422
|
+
Authorization: `Bearer ${apiKey}`
|
423
|
+
};
|
424
|
+
const response = await pool.request(url, {
|
425
|
+
...fetchOptions,
|
426
|
+
method: method.toUpperCase(),
|
427
|
+
body: body ? JSON.stringify(body) : void 0,
|
428
|
+
headers,
|
429
|
+
signal
|
430
|
+
});
|
431
|
+
const { host, protocol } = parseUrl(response.url);
|
432
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
433
|
+
setAttributes({
|
434
|
+
[TraceAttributes.KIND]: "http",
|
435
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
436
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
437
|
+
[TraceAttributes.HTTP_HOST]: host,
|
438
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
439
|
+
});
|
440
|
+
if (response.status === 204) {
|
441
|
+
return {};
|
442
|
+
}
|
443
|
+
if (response.status === 429) {
|
444
|
+
throw new FetcherError(response.status, "Rate limit exceeded", requestId);
|
445
|
+
}
|
446
|
+
try {
|
447
|
+
const jsonResponse = await response.json();
|
448
|
+
if (response.ok) {
|
449
|
+
return jsonResponse;
|
450
|
+
}
|
451
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
452
|
+
} catch (error) {
|
453
|
+
throw new FetcherError(response.status, error, requestId);
|
454
|
+
}
|
455
|
+
},
|
456
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
457
|
+
);
|
458
|
+
}
|
459
|
+
function parseUrl(url) {
|
225
460
|
try {
|
226
|
-
const
|
227
|
-
|
228
|
-
return jsonResponse;
|
229
|
-
}
|
230
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
461
|
+
const { host, protocol } = new URL(url);
|
462
|
+
return { host, protocol };
|
231
463
|
} catch (error) {
|
232
|
-
|
464
|
+
return {};
|
233
465
|
}
|
234
466
|
}
|
235
467
|
|
236
|
-
const
|
237
|
-
|
238
|
-
const
|
239
|
-
const getUserAPIKeys = (variables) => fetch$1({
|
240
|
-
url: "/user/keys",
|
241
|
-
method: "get",
|
242
|
-
...variables
|
243
|
-
});
|
244
|
-
const createUserAPIKey = (variables) => fetch$1({
|
245
|
-
url: "/user/keys/{keyName}",
|
246
|
-
method: "post",
|
247
|
-
...variables
|
248
|
-
});
|
249
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
250
|
-
url: "/user/keys/{keyName}",
|
251
|
-
method: "delete",
|
252
|
-
...variables
|
253
|
-
});
|
254
|
-
const createWorkspace = (variables) => fetch$1({
|
255
|
-
url: "/workspaces",
|
256
|
-
method: "post",
|
257
|
-
...variables
|
258
|
-
});
|
259
|
-
const getWorkspacesList = (variables) => fetch$1({
|
260
|
-
url: "/workspaces",
|
261
|
-
method: "get",
|
262
|
-
...variables
|
263
|
-
});
|
264
|
-
const getWorkspace = (variables) => fetch$1({
|
265
|
-
url: "/workspaces/{workspaceId}",
|
266
|
-
method: "get",
|
267
|
-
...variables
|
268
|
-
});
|
269
|
-
const updateWorkspace = (variables) => fetch$1({
|
270
|
-
url: "/workspaces/{workspaceId}",
|
271
|
-
method: "put",
|
272
|
-
...variables
|
273
|
-
});
|
274
|
-
const deleteWorkspace = (variables) => fetch$1({
|
275
|
-
url: "/workspaces/{workspaceId}",
|
276
|
-
method: "delete",
|
277
|
-
...variables
|
278
|
-
});
|
279
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
280
|
-
url: "/workspaces/{workspaceId}/members",
|
281
|
-
method: "get",
|
282
|
-
...variables
|
283
|
-
});
|
284
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
285
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
286
|
-
url: "/workspaces/{workspaceId}/members/{userId}",
|
287
|
-
method: "delete",
|
288
|
-
...variables
|
289
|
-
});
|
290
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
291
|
-
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
292
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
293
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
294
|
-
method: "delete",
|
295
|
-
...variables
|
296
|
-
});
|
297
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
298
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
299
|
-
method: "post",
|
300
|
-
...variables
|
301
|
-
});
|
302
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
303
|
-
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
304
|
-
method: "post",
|
305
|
-
...variables
|
306
|
-
});
|
307
|
-
const getDatabaseList = (variables) => fetch$1({
|
308
|
-
url: "/dbs",
|
309
|
-
method: "get",
|
310
|
-
...variables
|
311
|
-
});
|
312
|
-
const getBranchList = (variables) => fetch$1({
|
313
|
-
url: "/dbs/{dbName}",
|
314
|
-
method: "get",
|
315
|
-
...variables
|
316
|
-
});
|
317
|
-
const createDatabase = (variables) => fetch$1({
|
318
|
-
url: "/dbs/{dbName}",
|
319
|
-
method: "put",
|
320
|
-
...variables
|
321
|
-
});
|
322
|
-
const deleteDatabase = (variables) => fetch$1({
|
468
|
+
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
469
|
+
|
470
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
323
471
|
url: "/dbs/{dbName}",
|
324
|
-
method: "delete",
|
325
|
-
...variables
|
326
|
-
});
|
327
|
-
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
328
|
-
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
329
|
-
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
330
|
-
const resolveBranch = (variables) => fetch$1({
|
331
|
-
url: "/dbs/{dbName}/resolveBranch",
|
332
472
|
method: "get",
|
333
|
-
...variables
|
473
|
+
...variables,
|
474
|
+
signal
|
334
475
|
});
|
335
|
-
const getBranchDetails = (variables) =>
|
476
|
+
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
336
477
|
url: "/db/{dbBranchName}",
|
337
478
|
method: "get",
|
338
|
-
...variables
|
479
|
+
...variables,
|
480
|
+
signal
|
339
481
|
});
|
340
|
-
const createBranch = (variables) =>
|
341
|
-
|
342
|
-
method: "put",
|
343
|
-
...variables
|
344
|
-
});
|
345
|
-
const deleteBranch = (variables) => fetch$1({
|
482
|
+
const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
483
|
+
const deleteBranch = (variables, signal) => dataPlaneFetch({
|
346
484
|
url: "/db/{dbBranchName}",
|
347
485
|
method: "delete",
|
348
|
-
...variables
|
486
|
+
...variables,
|
487
|
+
signal
|
349
488
|
});
|
350
|
-
const updateBranchMetadata = (variables) =>
|
489
|
+
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
351
490
|
url: "/db/{dbBranchName}/metadata",
|
352
491
|
method: "put",
|
353
|
-
...variables
|
492
|
+
...variables,
|
493
|
+
signal
|
354
494
|
});
|
355
|
-
const getBranchMetadata = (variables) =>
|
495
|
+
const getBranchMetadata = (variables, signal) => dataPlaneFetch({
|
356
496
|
url: "/db/{dbBranchName}/metadata",
|
357
497
|
method: "get",
|
358
|
-
...variables
|
498
|
+
...variables,
|
499
|
+
signal
|
359
500
|
});
|
360
|
-
const
|
361
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
362
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
363
|
-
const getBranchStats = (variables) => fetch$1({
|
501
|
+
const getBranchStats = (variables, signal) => dataPlaneFetch({
|
364
502
|
url: "/db/{dbBranchName}/stats",
|
365
503
|
method: "get",
|
366
|
-
...variables
|
504
|
+
...variables,
|
505
|
+
signal
|
506
|
+
});
|
507
|
+
const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
508
|
+
const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
509
|
+
const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
510
|
+
const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
|
511
|
+
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
512
|
+
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
513
|
+
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
514
|
+
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
515
|
+
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
516
|
+
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
517
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
518
|
+
method: "get",
|
519
|
+
...variables,
|
520
|
+
signal
|
521
|
+
});
|
522
|
+
const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
523
|
+
const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
524
|
+
const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
525
|
+
const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
526
|
+
const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
|
527
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
528
|
+
method: "post",
|
529
|
+
...variables,
|
530
|
+
signal
|
367
531
|
});
|
368
|
-
const
|
532
|
+
const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
533
|
+
const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
534
|
+
const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
535
|
+
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
536
|
+
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
537
|
+
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
538
|
+
const createTable = (variables, signal) => dataPlaneFetch({
|
369
539
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
370
540
|
method: "put",
|
371
|
-
...variables
|
541
|
+
...variables,
|
542
|
+
signal
|
372
543
|
});
|
373
|
-
const deleteTable = (variables) =>
|
544
|
+
const deleteTable = (variables, signal) => dataPlaneFetch({
|
374
545
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
375
546
|
method: "delete",
|
376
|
-
...variables
|
547
|
+
...variables,
|
548
|
+
signal
|
377
549
|
});
|
378
|
-
const updateTable = (variables) =>
|
379
|
-
|
380
|
-
method: "patch",
|
381
|
-
...variables
|
382
|
-
});
|
383
|
-
const getTableSchema = (variables) => fetch$1({
|
550
|
+
const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
|
551
|
+
const getTableSchema = (variables, signal) => dataPlaneFetch({
|
384
552
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
385
553
|
method: "get",
|
386
|
-
...variables
|
387
|
-
|
388
|
-
const setTableSchema = (variables) => fetch$1({
|
389
|
-
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
390
|
-
method: "put",
|
391
|
-
...variables
|
554
|
+
...variables,
|
555
|
+
signal
|
392
556
|
});
|
393
|
-
const
|
557
|
+
const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
|
558
|
+
const getTableColumns = (variables, signal) => dataPlaneFetch({
|
394
559
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
395
560
|
method: "get",
|
396
|
-
...variables
|
397
|
-
|
398
|
-
const addTableColumn = (variables) => fetch$1({
|
399
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
400
|
-
method: "post",
|
401
|
-
...variables
|
561
|
+
...variables,
|
562
|
+
signal
|
402
563
|
});
|
403
|
-
const
|
564
|
+
const addTableColumn = (variables, signal) => dataPlaneFetch(
|
565
|
+
{ url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
|
566
|
+
);
|
567
|
+
const getColumn = (variables, signal) => dataPlaneFetch({
|
404
568
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
405
569
|
method: "get",
|
406
|
-
...variables
|
407
|
-
|
408
|
-
const deleteColumn = (variables) => fetch$1({
|
409
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
410
|
-
method: "delete",
|
411
|
-
...variables
|
570
|
+
...variables,
|
571
|
+
signal
|
412
572
|
});
|
413
|
-
const updateColumn = (variables) =>
|
573
|
+
const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
|
574
|
+
const deleteColumn = (variables, signal) => dataPlaneFetch({
|
414
575
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
415
|
-
method: "patch",
|
416
|
-
...variables
|
417
|
-
});
|
418
|
-
const insertRecord = (variables) => fetch$1({
|
419
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data",
|
420
|
-
method: "post",
|
421
|
-
...variables
|
422
|
-
});
|
423
|
-
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
424
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
425
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
426
|
-
const deleteRecord = (variables) => fetch$1({
|
427
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
428
576
|
method: "delete",
|
429
|
-
...variables
|
577
|
+
...variables,
|
578
|
+
signal
|
430
579
|
});
|
431
|
-
const
|
580
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
581
|
+
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
582
|
+
const getRecord = (variables, signal) => dataPlaneFetch({
|
432
583
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
433
584
|
method: "get",
|
434
|
-
...variables
|
585
|
+
...variables,
|
586
|
+
signal
|
435
587
|
});
|
436
|
-
const
|
437
|
-
const
|
588
|
+
const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
589
|
+
const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
590
|
+
const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
591
|
+
const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
|
592
|
+
const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
593
|
+
const queryTable = (variables, signal) => dataPlaneFetch({
|
438
594
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
439
595
|
method: "post",
|
440
|
-
...variables
|
596
|
+
...variables,
|
597
|
+
signal
|
441
598
|
});
|
442
|
-
const
|
443
|
-
url: "/db/{dbBranchName}/
|
599
|
+
const searchBranch = (variables, signal) => dataPlaneFetch({
|
600
|
+
url: "/db/{dbBranchName}/search",
|
444
601
|
method: "post",
|
445
|
-
...variables
|
602
|
+
...variables,
|
603
|
+
signal
|
446
604
|
});
|
447
|
-
const
|
448
|
-
url: "/db/{dbBranchName}/search",
|
605
|
+
const searchTable = (variables, signal) => dataPlaneFetch({
|
606
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
449
607
|
method: "post",
|
450
|
-
...variables
|
608
|
+
...variables,
|
609
|
+
signal
|
451
610
|
});
|
452
|
-
const
|
453
|
-
|
454
|
-
|
455
|
-
createWorkspace,
|
456
|
-
getWorkspacesList,
|
457
|
-
getWorkspace,
|
458
|
-
updateWorkspace,
|
459
|
-
deleteWorkspace,
|
460
|
-
getWorkspaceMembersList,
|
461
|
-
updateWorkspaceMemberRole,
|
462
|
-
removeWorkspaceMember,
|
463
|
-
inviteWorkspaceMember,
|
464
|
-
updateWorkspaceMemberInvite,
|
465
|
-
cancelWorkspaceMemberInvite,
|
466
|
-
resendWorkspaceMemberInvite,
|
467
|
-
acceptWorkspaceMemberInvite
|
468
|
-
},
|
469
|
-
database: {
|
470
|
-
getDatabaseList,
|
471
|
-
createDatabase,
|
472
|
-
deleteDatabase,
|
473
|
-
getGitBranchesMapping,
|
474
|
-
addGitBranchesEntry,
|
475
|
-
removeGitBranchesEntry,
|
476
|
-
resolveBranch
|
477
|
-
},
|
611
|
+
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
612
|
+
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
613
|
+
const operationsByTag$2 = {
|
478
614
|
branch: {
|
479
615
|
getBranchList,
|
480
616
|
getBranchDetails,
|
@@ -482,10 +618,32 @@ const operationsByTag = {
|
|
482
618
|
deleteBranch,
|
483
619
|
updateBranchMetadata,
|
484
620
|
getBranchMetadata,
|
621
|
+
getBranchStats,
|
622
|
+
getGitBranchesMapping,
|
623
|
+
addGitBranchesEntry,
|
624
|
+
removeGitBranchesEntry,
|
625
|
+
resolveBranch
|
626
|
+
},
|
627
|
+
migrations: {
|
485
628
|
getBranchMigrationHistory,
|
486
|
-
executeBranchMigrationPlan,
|
487
629
|
getBranchMigrationPlan,
|
488
|
-
|
630
|
+
executeBranchMigrationPlan,
|
631
|
+
getBranchSchemaHistory,
|
632
|
+
compareBranchWithUserSchema,
|
633
|
+
compareBranchSchemas,
|
634
|
+
updateBranchSchema,
|
635
|
+
previewBranchSchemaEdit,
|
636
|
+
applyBranchSchemaEdit
|
637
|
+
},
|
638
|
+
migrationRequests: {
|
639
|
+
queryMigrationRequests,
|
640
|
+
createMigrationRequest,
|
641
|
+
getMigrationRequest,
|
642
|
+
updateMigrationRequest,
|
643
|
+
listMigrationRequestsCommits,
|
644
|
+
compareMigrationRequest,
|
645
|
+
getMigrationRequestIsMerged,
|
646
|
+
mergeMigrationRequest
|
489
647
|
},
|
490
648
|
table: {
|
491
649
|
createTable,
|
@@ -496,27 +654,160 @@ const operationsByTag = {
|
|
496
654
|
getTableColumns,
|
497
655
|
addTableColumn,
|
498
656
|
getColumn,
|
499
|
-
|
500
|
-
|
657
|
+
updateColumn,
|
658
|
+
deleteColumn
|
501
659
|
},
|
502
660
|
records: {
|
661
|
+
branchTransaction,
|
503
662
|
insertRecord,
|
663
|
+
getRecord,
|
504
664
|
insertRecordWithID,
|
505
665
|
updateRecordWithID,
|
506
666
|
upsertRecordWithID,
|
507
667
|
deleteRecord,
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
668
|
+
bulkInsertTableRecords
|
669
|
+
},
|
670
|
+
searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
|
671
|
+
};
|
672
|
+
|
673
|
+
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
674
|
+
|
675
|
+
const getUser = (variables, signal) => controlPlaneFetch({
|
676
|
+
url: "/user",
|
677
|
+
method: "get",
|
678
|
+
...variables,
|
679
|
+
signal
|
680
|
+
});
|
681
|
+
const updateUser = (variables, signal) => controlPlaneFetch({
|
682
|
+
url: "/user",
|
683
|
+
method: "put",
|
684
|
+
...variables,
|
685
|
+
signal
|
686
|
+
});
|
687
|
+
const deleteUser = (variables, signal) => controlPlaneFetch({
|
688
|
+
url: "/user",
|
689
|
+
method: "delete",
|
690
|
+
...variables,
|
691
|
+
signal
|
692
|
+
});
|
693
|
+
const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
694
|
+
url: "/user/keys",
|
695
|
+
method: "get",
|
696
|
+
...variables,
|
697
|
+
signal
|
698
|
+
});
|
699
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
700
|
+
url: "/user/keys/{keyName}",
|
701
|
+
method: "post",
|
702
|
+
...variables,
|
703
|
+
signal
|
704
|
+
});
|
705
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
706
|
+
url: "/user/keys/{keyName}",
|
707
|
+
method: "delete",
|
708
|
+
...variables,
|
709
|
+
signal
|
710
|
+
});
|
711
|
+
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
712
|
+
url: "/workspaces",
|
713
|
+
method: "get",
|
714
|
+
...variables,
|
715
|
+
signal
|
716
|
+
});
|
717
|
+
const createWorkspace = (variables, signal) => controlPlaneFetch({
|
718
|
+
url: "/workspaces",
|
719
|
+
method: "post",
|
720
|
+
...variables,
|
721
|
+
signal
|
722
|
+
});
|
723
|
+
const getWorkspace = (variables, signal) => controlPlaneFetch({
|
724
|
+
url: "/workspaces/{workspaceId}",
|
725
|
+
method: "get",
|
726
|
+
...variables,
|
727
|
+
signal
|
728
|
+
});
|
729
|
+
const updateWorkspace = (variables, signal) => controlPlaneFetch({
|
730
|
+
url: "/workspaces/{workspaceId}",
|
731
|
+
method: "put",
|
732
|
+
...variables,
|
733
|
+
signal
|
734
|
+
});
|
735
|
+
const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
736
|
+
url: "/workspaces/{workspaceId}",
|
737
|
+
method: "delete",
|
738
|
+
...variables,
|
739
|
+
signal
|
740
|
+
});
|
741
|
+
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
742
|
+
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
743
|
+
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
744
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
745
|
+
method: "delete",
|
746
|
+
...variables,
|
747
|
+
signal
|
748
|
+
});
|
749
|
+
const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
750
|
+
const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
751
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
752
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
753
|
+
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
754
|
+
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
755
|
+
url: "/workspaces/{workspaceId}/dbs",
|
756
|
+
method: "get",
|
757
|
+
...variables,
|
758
|
+
signal
|
759
|
+
});
|
760
|
+
const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
761
|
+
const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
762
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
763
|
+
method: "delete",
|
764
|
+
...variables,
|
765
|
+
signal
|
766
|
+
});
|
767
|
+
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
768
|
+
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
769
|
+
const listRegions = (variables, signal) => controlPlaneFetch({
|
770
|
+
url: "/workspaces/{workspaceId}/regions",
|
771
|
+
method: "get",
|
772
|
+
...variables,
|
773
|
+
signal
|
774
|
+
});
|
775
|
+
const operationsByTag$1 = {
|
776
|
+
users: { getUser, updateUser, deleteUser },
|
777
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
778
|
+
workspaces: {
|
779
|
+
getWorkspacesList,
|
780
|
+
createWorkspace,
|
781
|
+
getWorkspace,
|
782
|
+
updateWorkspace,
|
783
|
+
deleteWorkspace,
|
784
|
+
getWorkspaceMembersList,
|
785
|
+
updateWorkspaceMemberRole,
|
786
|
+
removeWorkspaceMember
|
787
|
+
},
|
788
|
+
invites: {
|
789
|
+
inviteWorkspaceMember,
|
790
|
+
updateWorkspaceMemberInvite,
|
791
|
+
cancelWorkspaceMemberInvite,
|
792
|
+
acceptWorkspaceMemberInvite,
|
793
|
+
resendWorkspaceMemberInvite
|
794
|
+
},
|
795
|
+
databases: {
|
796
|
+
getDatabaseList,
|
797
|
+
createDatabase,
|
798
|
+
deleteDatabase,
|
799
|
+
getDatabaseMetadata,
|
800
|
+
updateDatabaseMetadata,
|
801
|
+
listRegions
|
513
802
|
}
|
514
803
|
};
|
515
804
|
|
805
|
+
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
806
|
+
|
516
807
|
function getHostUrl(provider, type) {
|
517
|
-
if (
|
808
|
+
if (isHostProviderAlias(provider)) {
|
518
809
|
return providers[provider][type];
|
519
|
-
} else if (
|
810
|
+
} else if (isHostProviderBuilder(provider)) {
|
520
811
|
return provider[type];
|
521
812
|
}
|
522
813
|
throw new Error("Invalid API provider");
|
@@ -524,19 +815,38 @@ function getHostUrl(provider, type) {
|
|
524
815
|
const providers = {
|
525
816
|
production: {
|
526
817
|
main: "https://api.xata.io",
|
527
|
-
workspaces: "https://{workspaceId}.xata.sh"
|
818
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
528
819
|
},
|
529
820
|
staging: {
|
530
821
|
main: "https://staging.xatabase.co",
|
531
|
-
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
822
|
+
workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
|
532
823
|
}
|
533
824
|
};
|
534
|
-
function
|
825
|
+
function isHostProviderAlias(alias) {
|
535
826
|
return isString(alias) && Object.keys(providers).includes(alias);
|
536
827
|
}
|
537
|
-
function
|
828
|
+
function isHostProviderBuilder(builder) {
|
538
829
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
539
830
|
}
|
831
|
+
function parseProviderString(provider = "production") {
|
832
|
+
if (isHostProviderAlias(provider)) {
|
833
|
+
return provider;
|
834
|
+
}
|
835
|
+
const [main, workspaces] = provider.split(",");
|
836
|
+
if (!main || !workspaces)
|
837
|
+
return null;
|
838
|
+
return { main, workspaces };
|
839
|
+
}
|
840
|
+
function parseWorkspacesUrlParts(url) {
|
841
|
+
if (!isString(url))
|
842
|
+
return null;
|
843
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))\.xata\.sh.*/;
|
844
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))\.xatabase\.co.*/;
|
845
|
+
const match = url.match(regex) || url.match(regexStaging);
|
846
|
+
if (!match)
|
847
|
+
return null;
|
848
|
+
return { workspace: match[1], region: match[2] };
|
849
|
+
}
|
540
850
|
|
541
851
|
var __accessCheck$7 = (obj, member, msg) => {
|
542
852
|
if (!member.has(obj))
|
@@ -562,7 +872,9 @@ class XataApiClient {
|
|
562
872
|
__privateAdd$7(this, _extraProps, void 0);
|
563
873
|
__privateAdd$7(this, _namespaces, {});
|
564
874
|
const provider = options.host ?? "production";
|
565
|
-
const apiKey = options
|
875
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
876
|
+
const trace = options.trace ?? defaultTrace;
|
877
|
+
const clientID = generateUUID();
|
566
878
|
if (!apiKey) {
|
567
879
|
throw new Error("Could not resolve a valid apiKey");
|
568
880
|
}
|
@@ -570,7 +882,10 @@ class XataApiClient {
|
|
570
882
|
apiUrl: getHostUrl(provider, "main"),
|
571
883
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
572
884
|
fetchImpl: getFetchImplementation(options.fetch),
|
573
|
-
apiKey
|
885
|
+
apiKey,
|
886
|
+
trace,
|
887
|
+
clientName: options.clientName,
|
888
|
+
clientID
|
574
889
|
});
|
575
890
|
}
|
576
891
|
get user() {
|
@@ -578,21 +893,41 @@ class XataApiClient {
|
|
578
893
|
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
579
894
|
return __privateGet$7(this, _namespaces).user;
|
580
895
|
}
|
896
|
+
get authentication() {
|
897
|
+
if (!__privateGet$7(this, _namespaces).authentication)
|
898
|
+
__privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
|
899
|
+
return __privateGet$7(this, _namespaces).authentication;
|
900
|
+
}
|
581
901
|
get workspaces() {
|
582
902
|
if (!__privateGet$7(this, _namespaces).workspaces)
|
583
903
|
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
584
904
|
return __privateGet$7(this, _namespaces).workspaces;
|
585
905
|
}
|
586
|
-
get
|
587
|
-
if (!__privateGet$7(this, _namespaces).
|
588
|
-
__privateGet$7(this, _namespaces).
|
589
|
-
return __privateGet$7(this, _namespaces).
|
906
|
+
get invites() {
|
907
|
+
if (!__privateGet$7(this, _namespaces).invites)
|
908
|
+
__privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
|
909
|
+
return __privateGet$7(this, _namespaces).invites;
|
910
|
+
}
|
911
|
+
get database() {
|
912
|
+
if (!__privateGet$7(this, _namespaces).database)
|
913
|
+
__privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
|
914
|
+
return __privateGet$7(this, _namespaces).database;
|
590
915
|
}
|
591
916
|
get branches() {
|
592
917
|
if (!__privateGet$7(this, _namespaces).branches)
|
593
918
|
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
594
919
|
return __privateGet$7(this, _namespaces).branches;
|
595
920
|
}
|
921
|
+
get migrations() {
|
922
|
+
if (!__privateGet$7(this, _namespaces).migrations)
|
923
|
+
__privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
|
924
|
+
return __privateGet$7(this, _namespaces).migrations;
|
925
|
+
}
|
926
|
+
get migrationRequests() {
|
927
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
928
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
929
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
930
|
+
}
|
596
931
|
get tables() {
|
597
932
|
if (!__privateGet$7(this, _namespaces).tables)
|
598
933
|
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
@@ -603,6 +938,11 @@ class XataApiClient {
|
|
603
938
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
604
939
|
return __privateGet$7(this, _namespaces).records;
|
605
940
|
}
|
941
|
+
get searchAndFilter() {
|
942
|
+
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
943
|
+
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
944
|
+
return __privateGet$7(this, _namespaces).searchAndFilter;
|
945
|
+
}
|
606
946
|
}
|
607
947
|
_extraProps = new WeakMap();
|
608
948
|
_namespaces = new WeakMap();
|
@@ -613,24 +953,29 @@ class UserApi {
|
|
613
953
|
getUser() {
|
614
954
|
return operationsByTag.users.getUser({ ...this.extraProps });
|
615
955
|
}
|
616
|
-
updateUser(user) {
|
956
|
+
updateUser({ user }) {
|
617
957
|
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
618
958
|
}
|
619
959
|
deleteUser() {
|
620
960
|
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
621
961
|
}
|
962
|
+
}
|
963
|
+
class AuthenticationApi {
|
964
|
+
constructor(extraProps) {
|
965
|
+
this.extraProps = extraProps;
|
966
|
+
}
|
622
967
|
getUserAPIKeys() {
|
623
|
-
return operationsByTag.
|
968
|
+
return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
|
624
969
|
}
|
625
|
-
createUserAPIKey(
|
626
|
-
return operationsByTag.
|
627
|
-
pathParams: { keyName },
|
970
|
+
createUserAPIKey({ name }) {
|
971
|
+
return operationsByTag.authentication.createUserAPIKey({
|
972
|
+
pathParams: { keyName: name },
|
628
973
|
...this.extraProps
|
629
974
|
});
|
630
975
|
}
|
631
|
-
deleteUserAPIKey(
|
632
|
-
return operationsByTag.
|
633
|
-
pathParams: { keyName },
|
976
|
+
deleteUserAPIKey({ name }) {
|
977
|
+
return operationsByTag.authentication.deleteUserAPIKey({
|
978
|
+
pathParams: { keyName: name },
|
634
979
|
...this.extraProps
|
635
980
|
});
|
636
981
|
}
|
@@ -639,349 +984,897 @@ class WorkspaceApi {
|
|
639
984
|
constructor(extraProps) {
|
640
985
|
this.extraProps = extraProps;
|
641
986
|
}
|
642
|
-
|
987
|
+
getWorkspacesList() {
|
988
|
+
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
989
|
+
}
|
990
|
+
createWorkspace({ data }) {
|
643
991
|
return operationsByTag.workspaces.createWorkspace({
|
644
|
-
body:
|
992
|
+
body: data,
|
645
993
|
...this.extraProps
|
646
994
|
});
|
647
995
|
}
|
648
|
-
|
649
|
-
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
650
|
-
}
|
651
|
-
getWorkspace(workspaceId) {
|
996
|
+
getWorkspace({ workspace }) {
|
652
997
|
return operationsByTag.workspaces.getWorkspace({
|
653
|
-
pathParams: { workspaceId },
|
998
|
+
pathParams: { workspaceId: workspace },
|
654
999
|
...this.extraProps
|
655
1000
|
});
|
656
1001
|
}
|
657
|
-
updateWorkspace(
|
1002
|
+
updateWorkspace({
|
1003
|
+
workspace,
|
1004
|
+
update
|
1005
|
+
}) {
|
658
1006
|
return operationsByTag.workspaces.updateWorkspace({
|
659
|
-
pathParams: { workspaceId },
|
660
|
-
body:
|
1007
|
+
pathParams: { workspaceId: workspace },
|
1008
|
+
body: update,
|
661
1009
|
...this.extraProps
|
662
1010
|
});
|
663
1011
|
}
|
664
|
-
deleteWorkspace(
|
1012
|
+
deleteWorkspace({ workspace }) {
|
665
1013
|
return operationsByTag.workspaces.deleteWorkspace({
|
666
|
-
pathParams: { workspaceId },
|
1014
|
+
pathParams: { workspaceId: workspace },
|
667
1015
|
...this.extraProps
|
668
1016
|
});
|
669
1017
|
}
|
670
|
-
getWorkspaceMembersList(
|
1018
|
+
getWorkspaceMembersList({ workspace }) {
|
671
1019
|
return operationsByTag.workspaces.getWorkspaceMembersList({
|
672
|
-
pathParams: { workspaceId },
|
1020
|
+
pathParams: { workspaceId: workspace },
|
673
1021
|
...this.extraProps
|
674
1022
|
});
|
675
1023
|
}
|
676
|
-
updateWorkspaceMemberRole(
|
1024
|
+
updateWorkspaceMemberRole({
|
1025
|
+
workspace,
|
1026
|
+
user,
|
1027
|
+
role
|
1028
|
+
}) {
|
677
1029
|
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
678
|
-
pathParams: { workspaceId, userId },
|
1030
|
+
pathParams: { workspaceId: workspace, userId: user },
|
679
1031
|
body: { role },
|
680
1032
|
...this.extraProps
|
681
1033
|
});
|
682
1034
|
}
|
683
|
-
removeWorkspaceMember(
|
1035
|
+
removeWorkspaceMember({
|
1036
|
+
workspace,
|
1037
|
+
user
|
1038
|
+
}) {
|
684
1039
|
return operationsByTag.workspaces.removeWorkspaceMember({
|
685
|
-
pathParams: { workspaceId, userId },
|
1040
|
+
pathParams: { workspaceId: workspace, userId: user },
|
686
1041
|
...this.extraProps
|
687
1042
|
});
|
688
1043
|
}
|
689
|
-
|
690
|
-
|
691
|
-
|
1044
|
+
}
|
1045
|
+
class InvitesApi {
|
1046
|
+
constructor(extraProps) {
|
1047
|
+
this.extraProps = extraProps;
|
1048
|
+
}
|
1049
|
+
inviteWorkspaceMember({
|
1050
|
+
workspace,
|
1051
|
+
email,
|
1052
|
+
role
|
1053
|
+
}) {
|
1054
|
+
return operationsByTag.invites.inviteWorkspaceMember({
|
1055
|
+
pathParams: { workspaceId: workspace },
|
692
1056
|
body: { email, role },
|
693
1057
|
...this.extraProps
|
694
1058
|
});
|
695
1059
|
}
|
696
|
-
updateWorkspaceMemberInvite(
|
697
|
-
|
698
|
-
|
1060
|
+
updateWorkspaceMemberInvite({
|
1061
|
+
workspace,
|
1062
|
+
invite,
|
1063
|
+
role
|
1064
|
+
}) {
|
1065
|
+
return operationsByTag.invites.updateWorkspaceMemberInvite({
|
1066
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
699
1067
|
body: { role },
|
700
1068
|
...this.extraProps
|
701
1069
|
});
|
702
1070
|
}
|
703
|
-
cancelWorkspaceMemberInvite(
|
704
|
-
|
705
|
-
|
1071
|
+
cancelWorkspaceMemberInvite({
|
1072
|
+
workspace,
|
1073
|
+
invite
|
1074
|
+
}) {
|
1075
|
+
return operationsByTag.invites.cancelWorkspaceMemberInvite({
|
1076
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
706
1077
|
...this.extraProps
|
707
1078
|
});
|
708
1079
|
}
|
709
|
-
|
710
|
-
|
711
|
-
|
1080
|
+
acceptWorkspaceMemberInvite({
|
1081
|
+
workspace,
|
1082
|
+
key
|
1083
|
+
}) {
|
1084
|
+
return operationsByTag.invites.acceptWorkspaceMemberInvite({
|
1085
|
+
pathParams: { workspaceId: workspace, inviteKey: key },
|
712
1086
|
...this.extraProps
|
713
1087
|
});
|
714
1088
|
}
|
715
|
-
|
716
|
-
|
717
|
-
|
1089
|
+
resendWorkspaceMemberInvite({
|
1090
|
+
workspace,
|
1091
|
+
invite
|
1092
|
+
}) {
|
1093
|
+
return operationsByTag.invites.resendWorkspaceMemberInvite({
|
1094
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
718
1095
|
...this.extraProps
|
719
1096
|
});
|
720
1097
|
}
|
721
1098
|
}
|
722
|
-
class
|
1099
|
+
class BranchApi {
|
723
1100
|
constructor(extraProps) {
|
724
1101
|
this.extraProps = extraProps;
|
725
1102
|
}
|
726
|
-
|
727
|
-
|
728
|
-
|
1103
|
+
getBranchList({
|
1104
|
+
workspace,
|
1105
|
+
region,
|
1106
|
+
database
|
1107
|
+
}) {
|
1108
|
+
return operationsByTag.branch.getBranchList({
|
1109
|
+
pathParams: { workspace, region, dbName: database },
|
1110
|
+
...this.extraProps
|
1111
|
+
});
|
1112
|
+
}
|
1113
|
+
getBranchDetails({
|
1114
|
+
workspace,
|
1115
|
+
region,
|
1116
|
+
database,
|
1117
|
+
branch
|
1118
|
+
}) {
|
1119
|
+
return operationsByTag.branch.getBranchDetails({
|
1120
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1121
|
+
...this.extraProps
|
1122
|
+
});
|
1123
|
+
}
|
1124
|
+
createBranch({
|
1125
|
+
workspace,
|
1126
|
+
region,
|
1127
|
+
database,
|
1128
|
+
branch,
|
1129
|
+
from,
|
1130
|
+
metadata
|
1131
|
+
}) {
|
1132
|
+
return operationsByTag.branch.createBranch({
|
1133
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1134
|
+
body: { from, metadata },
|
1135
|
+
...this.extraProps
|
1136
|
+
});
|
1137
|
+
}
|
1138
|
+
deleteBranch({
|
1139
|
+
workspace,
|
1140
|
+
region,
|
1141
|
+
database,
|
1142
|
+
branch
|
1143
|
+
}) {
|
1144
|
+
return operationsByTag.branch.deleteBranch({
|
1145
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1146
|
+
...this.extraProps
|
1147
|
+
});
|
1148
|
+
}
|
1149
|
+
updateBranchMetadata({
|
1150
|
+
workspace,
|
1151
|
+
region,
|
1152
|
+
database,
|
1153
|
+
branch,
|
1154
|
+
metadata
|
1155
|
+
}) {
|
1156
|
+
return operationsByTag.branch.updateBranchMetadata({
|
1157
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1158
|
+
body: metadata,
|
729
1159
|
...this.extraProps
|
730
1160
|
});
|
731
1161
|
}
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
1162
|
+
getBranchMetadata({
|
1163
|
+
workspace,
|
1164
|
+
region,
|
1165
|
+
database,
|
1166
|
+
branch
|
1167
|
+
}) {
|
1168
|
+
return operationsByTag.branch.getBranchMetadata({
|
1169
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
736
1170
|
...this.extraProps
|
737
1171
|
});
|
738
1172
|
}
|
739
|
-
|
740
|
-
|
741
|
-
|
1173
|
+
getBranchStats({
|
1174
|
+
workspace,
|
1175
|
+
region,
|
1176
|
+
database,
|
1177
|
+
branch
|
1178
|
+
}) {
|
1179
|
+
return operationsByTag.branch.getBranchStats({
|
1180
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
742
1181
|
...this.extraProps
|
743
1182
|
});
|
744
1183
|
}
|
745
|
-
getGitBranchesMapping(
|
746
|
-
|
747
|
-
|
1184
|
+
getGitBranchesMapping({
|
1185
|
+
workspace,
|
1186
|
+
region,
|
1187
|
+
database
|
1188
|
+
}) {
|
1189
|
+
return operationsByTag.branch.getGitBranchesMapping({
|
1190
|
+
pathParams: { workspace, region, dbName: database },
|
748
1191
|
...this.extraProps
|
749
1192
|
});
|
750
1193
|
}
|
751
|
-
addGitBranchesEntry(
|
752
|
-
|
753
|
-
|
754
|
-
|
1194
|
+
addGitBranchesEntry({
|
1195
|
+
workspace,
|
1196
|
+
region,
|
1197
|
+
database,
|
1198
|
+
gitBranch,
|
1199
|
+
xataBranch
|
1200
|
+
}) {
|
1201
|
+
return operationsByTag.branch.addGitBranchesEntry({
|
1202
|
+
pathParams: { workspace, region, dbName: database },
|
1203
|
+
body: { gitBranch, xataBranch },
|
755
1204
|
...this.extraProps
|
756
1205
|
});
|
757
1206
|
}
|
758
|
-
removeGitBranchesEntry(
|
759
|
-
|
760
|
-
|
1207
|
+
removeGitBranchesEntry({
|
1208
|
+
workspace,
|
1209
|
+
region,
|
1210
|
+
database,
|
1211
|
+
gitBranch
|
1212
|
+
}) {
|
1213
|
+
return operationsByTag.branch.removeGitBranchesEntry({
|
1214
|
+
pathParams: { workspace, region, dbName: database },
|
761
1215
|
queryParams: { gitBranch },
|
762
1216
|
...this.extraProps
|
763
1217
|
});
|
764
1218
|
}
|
765
|
-
resolveBranch(
|
766
|
-
|
767
|
-
|
1219
|
+
resolveBranch({
|
1220
|
+
workspace,
|
1221
|
+
region,
|
1222
|
+
database,
|
1223
|
+
gitBranch,
|
1224
|
+
fallbackBranch
|
1225
|
+
}) {
|
1226
|
+
return operationsByTag.branch.resolveBranch({
|
1227
|
+
pathParams: { workspace, region, dbName: database },
|
768
1228
|
queryParams: { gitBranch, fallbackBranch },
|
769
1229
|
...this.extraProps
|
770
1230
|
});
|
771
1231
|
}
|
772
1232
|
}
|
773
|
-
class
|
1233
|
+
class TableApi {
|
774
1234
|
constructor(extraProps) {
|
775
1235
|
this.extraProps = extraProps;
|
776
1236
|
}
|
777
|
-
|
778
|
-
|
779
|
-
|
1237
|
+
createTable({
|
1238
|
+
workspace,
|
1239
|
+
region,
|
1240
|
+
database,
|
1241
|
+
branch,
|
1242
|
+
table
|
1243
|
+
}) {
|
1244
|
+
return operationsByTag.table.createTable({
|
1245
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
780
1246
|
...this.extraProps
|
781
1247
|
});
|
782
1248
|
}
|
783
|
-
|
784
|
-
|
785
|
-
|
1249
|
+
deleteTable({
|
1250
|
+
workspace,
|
1251
|
+
region,
|
1252
|
+
database,
|
1253
|
+
branch,
|
1254
|
+
table
|
1255
|
+
}) {
|
1256
|
+
return operationsByTag.table.deleteTable({
|
1257
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
786
1258
|
...this.extraProps
|
787
1259
|
});
|
788
1260
|
}
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
1261
|
+
updateTable({
|
1262
|
+
workspace,
|
1263
|
+
region,
|
1264
|
+
database,
|
1265
|
+
branch,
|
1266
|
+
table,
|
1267
|
+
update
|
1268
|
+
}) {
|
1269
|
+
return operationsByTag.table.updateTable({
|
1270
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1271
|
+
body: update,
|
794
1272
|
...this.extraProps
|
795
1273
|
});
|
796
1274
|
}
|
797
|
-
|
798
|
-
|
799
|
-
|
1275
|
+
getTableSchema({
|
1276
|
+
workspace,
|
1277
|
+
region,
|
1278
|
+
database,
|
1279
|
+
branch,
|
1280
|
+
table
|
1281
|
+
}) {
|
1282
|
+
return operationsByTag.table.getTableSchema({
|
1283
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1284
|
+
...this.extraProps
|
1285
|
+
});
|
1286
|
+
}
|
1287
|
+
setTableSchema({
|
1288
|
+
workspace,
|
1289
|
+
region,
|
1290
|
+
database,
|
1291
|
+
branch,
|
1292
|
+
table,
|
1293
|
+
schema
|
1294
|
+
}) {
|
1295
|
+
return operationsByTag.table.setTableSchema({
|
1296
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1297
|
+
body: schema,
|
1298
|
+
...this.extraProps
|
1299
|
+
});
|
1300
|
+
}
|
1301
|
+
getTableColumns({
|
1302
|
+
workspace,
|
1303
|
+
region,
|
1304
|
+
database,
|
1305
|
+
branch,
|
1306
|
+
table
|
1307
|
+
}) {
|
1308
|
+
return operationsByTag.table.getTableColumns({
|
1309
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1310
|
+
...this.extraProps
|
1311
|
+
});
|
1312
|
+
}
|
1313
|
+
addTableColumn({
|
1314
|
+
workspace,
|
1315
|
+
region,
|
1316
|
+
database,
|
1317
|
+
branch,
|
1318
|
+
table,
|
1319
|
+
column
|
1320
|
+
}) {
|
1321
|
+
return operationsByTag.table.addTableColumn({
|
1322
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1323
|
+
body: column,
|
1324
|
+
...this.extraProps
|
1325
|
+
});
|
1326
|
+
}
|
1327
|
+
getColumn({
|
1328
|
+
workspace,
|
1329
|
+
region,
|
1330
|
+
database,
|
1331
|
+
branch,
|
1332
|
+
table,
|
1333
|
+
column
|
1334
|
+
}) {
|
1335
|
+
return operationsByTag.table.getColumn({
|
1336
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1337
|
+
...this.extraProps
|
1338
|
+
});
|
1339
|
+
}
|
1340
|
+
updateColumn({
|
1341
|
+
workspace,
|
1342
|
+
region,
|
1343
|
+
database,
|
1344
|
+
branch,
|
1345
|
+
table,
|
1346
|
+
column,
|
1347
|
+
update
|
1348
|
+
}) {
|
1349
|
+
return operationsByTag.table.updateColumn({
|
1350
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1351
|
+
body: update,
|
1352
|
+
...this.extraProps
|
1353
|
+
});
|
1354
|
+
}
|
1355
|
+
deleteColumn({
|
1356
|
+
workspace,
|
1357
|
+
region,
|
1358
|
+
database,
|
1359
|
+
branch,
|
1360
|
+
table,
|
1361
|
+
column
|
1362
|
+
}) {
|
1363
|
+
return operationsByTag.table.deleteColumn({
|
1364
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1365
|
+
...this.extraProps
|
1366
|
+
});
|
1367
|
+
}
|
1368
|
+
}
|
1369
|
+
class RecordsApi {
|
1370
|
+
constructor(extraProps) {
|
1371
|
+
this.extraProps = extraProps;
|
1372
|
+
}
|
1373
|
+
insertRecord({
|
1374
|
+
workspace,
|
1375
|
+
region,
|
1376
|
+
database,
|
1377
|
+
branch,
|
1378
|
+
table,
|
1379
|
+
record,
|
1380
|
+
columns
|
1381
|
+
}) {
|
1382
|
+
return operationsByTag.records.insertRecord({
|
1383
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1384
|
+
queryParams: { columns },
|
1385
|
+
body: record,
|
1386
|
+
...this.extraProps
|
1387
|
+
});
|
1388
|
+
}
|
1389
|
+
getRecord({
|
1390
|
+
workspace,
|
1391
|
+
region,
|
1392
|
+
database,
|
1393
|
+
branch,
|
1394
|
+
table,
|
1395
|
+
id,
|
1396
|
+
columns
|
1397
|
+
}) {
|
1398
|
+
return operationsByTag.records.getRecord({
|
1399
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1400
|
+
queryParams: { columns },
|
1401
|
+
...this.extraProps
|
1402
|
+
});
|
1403
|
+
}
|
1404
|
+
insertRecordWithID({
|
1405
|
+
workspace,
|
1406
|
+
region,
|
1407
|
+
database,
|
1408
|
+
branch,
|
1409
|
+
table,
|
1410
|
+
id,
|
1411
|
+
record,
|
1412
|
+
columns,
|
1413
|
+
createOnly,
|
1414
|
+
ifVersion
|
1415
|
+
}) {
|
1416
|
+
return operationsByTag.records.insertRecordWithID({
|
1417
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1418
|
+
queryParams: { columns, createOnly, ifVersion },
|
1419
|
+
body: record,
|
1420
|
+
...this.extraProps
|
1421
|
+
});
|
1422
|
+
}
|
1423
|
+
updateRecordWithID({
|
1424
|
+
workspace,
|
1425
|
+
region,
|
1426
|
+
database,
|
1427
|
+
branch,
|
1428
|
+
table,
|
1429
|
+
id,
|
1430
|
+
record,
|
1431
|
+
columns,
|
1432
|
+
ifVersion
|
1433
|
+
}) {
|
1434
|
+
return operationsByTag.records.updateRecordWithID({
|
1435
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1436
|
+
queryParams: { columns, ifVersion },
|
1437
|
+
body: record,
|
1438
|
+
...this.extraProps
|
1439
|
+
});
|
1440
|
+
}
|
1441
|
+
upsertRecordWithID({
|
1442
|
+
workspace,
|
1443
|
+
region,
|
1444
|
+
database,
|
1445
|
+
branch,
|
1446
|
+
table,
|
1447
|
+
id,
|
1448
|
+
record,
|
1449
|
+
columns,
|
1450
|
+
ifVersion
|
1451
|
+
}) {
|
1452
|
+
return operationsByTag.records.upsertRecordWithID({
|
1453
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1454
|
+
queryParams: { columns, ifVersion },
|
1455
|
+
body: record,
|
1456
|
+
...this.extraProps
|
1457
|
+
});
|
1458
|
+
}
|
1459
|
+
deleteRecord({
|
1460
|
+
workspace,
|
1461
|
+
region,
|
1462
|
+
database,
|
1463
|
+
branch,
|
1464
|
+
table,
|
1465
|
+
id,
|
1466
|
+
columns
|
1467
|
+
}) {
|
1468
|
+
return operationsByTag.records.deleteRecord({
|
1469
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1470
|
+
queryParams: { columns },
|
1471
|
+
...this.extraProps
|
1472
|
+
});
|
1473
|
+
}
|
1474
|
+
bulkInsertTableRecords({
|
1475
|
+
workspace,
|
1476
|
+
region,
|
1477
|
+
database,
|
1478
|
+
branch,
|
1479
|
+
table,
|
1480
|
+
records,
|
1481
|
+
columns
|
1482
|
+
}) {
|
1483
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
1484
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1485
|
+
queryParams: { columns },
|
1486
|
+
body: { records },
|
1487
|
+
...this.extraProps
|
1488
|
+
});
|
1489
|
+
}
|
1490
|
+
branchTransaction({
|
1491
|
+
workspace,
|
1492
|
+
region,
|
1493
|
+
database,
|
1494
|
+
branch,
|
1495
|
+
operations
|
1496
|
+
}) {
|
1497
|
+
return operationsByTag.records.branchTransaction({
|
1498
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1499
|
+
body: { operations },
|
1500
|
+
...this.extraProps
|
1501
|
+
});
|
1502
|
+
}
|
1503
|
+
}
|
1504
|
+
class SearchAndFilterApi {
|
1505
|
+
constructor(extraProps) {
|
1506
|
+
this.extraProps = extraProps;
|
1507
|
+
}
|
1508
|
+
queryTable({
|
1509
|
+
workspace,
|
1510
|
+
region,
|
1511
|
+
database,
|
1512
|
+
branch,
|
1513
|
+
table,
|
1514
|
+
filter,
|
1515
|
+
sort,
|
1516
|
+
page,
|
1517
|
+
columns,
|
1518
|
+
consistency
|
1519
|
+
}) {
|
1520
|
+
return operationsByTag.searchAndFilter.queryTable({
|
1521
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1522
|
+
body: { filter, sort, page, columns, consistency },
|
1523
|
+
...this.extraProps
|
1524
|
+
});
|
1525
|
+
}
|
1526
|
+
searchTable({
|
1527
|
+
workspace,
|
1528
|
+
region,
|
1529
|
+
database,
|
1530
|
+
branch,
|
1531
|
+
table,
|
1532
|
+
query,
|
1533
|
+
fuzziness,
|
1534
|
+
target,
|
1535
|
+
prefix,
|
1536
|
+
filter,
|
1537
|
+
highlight,
|
1538
|
+
boosters
|
1539
|
+
}) {
|
1540
|
+
return operationsByTag.searchAndFilter.searchTable({
|
1541
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1542
|
+
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
1543
|
+
...this.extraProps
|
1544
|
+
});
|
1545
|
+
}
|
1546
|
+
searchBranch({
|
1547
|
+
workspace,
|
1548
|
+
region,
|
1549
|
+
database,
|
1550
|
+
branch,
|
1551
|
+
tables,
|
1552
|
+
query,
|
1553
|
+
fuzziness,
|
1554
|
+
prefix,
|
1555
|
+
highlight
|
1556
|
+
}) {
|
1557
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
1558
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1559
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
1560
|
+
...this.extraProps
|
1561
|
+
});
|
1562
|
+
}
|
1563
|
+
summarizeTable({
|
1564
|
+
workspace,
|
1565
|
+
region,
|
1566
|
+
database,
|
1567
|
+
branch,
|
1568
|
+
table,
|
1569
|
+
filter,
|
1570
|
+
columns,
|
1571
|
+
summaries,
|
1572
|
+
sort,
|
1573
|
+
summariesFilter,
|
1574
|
+
page,
|
1575
|
+
consistency
|
1576
|
+
}) {
|
1577
|
+
return operationsByTag.searchAndFilter.summarizeTable({
|
1578
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1579
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
1580
|
+
...this.extraProps
|
1581
|
+
});
|
1582
|
+
}
|
1583
|
+
aggregateTable({
|
1584
|
+
workspace,
|
1585
|
+
region,
|
1586
|
+
database,
|
1587
|
+
branch,
|
1588
|
+
table,
|
1589
|
+
filter,
|
1590
|
+
aggs
|
1591
|
+
}) {
|
1592
|
+
return operationsByTag.searchAndFilter.aggregateTable({
|
1593
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1594
|
+
body: { filter, aggs },
|
1595
|
+
...this.extraProps
|
1596
|
+
});
|
1597
|
+
}
|
1598
|
+
}
|
1599
|
+
class MigrationRequestsApi {
|
1600
|
+
constructor(extraProps) {
|
1601
|
+
this.extraProps = extraProps;
|
1602
|
+
}
|
1603
|
+
queryMigrationRequests({
|
1604
|
+
workspace,
|
1605
|
+
region,
|
1606
|
+
database,
|
1607
|
+
filter,
|
1608
|
+
sort,
|
1609
|
+
page,
|
1610
|
+
columns
|
1611
|
+
}) {
|
1612
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
1613
|
+
pathParams: { workspace, region, dbName: database },
|
1614
|
+
body: { filter, sort, page, columns },
|
1615
|
+
...this.extraProps
|
1616
|
+
});
|
1617
|
+
}
|
1618
|
+
createMigrationRequest({
|
1619
|
+
workspace,
|
1620
|
+
region,
|
1621
|
+
database,
|
1622
|
+
migration
|
1623
|
+
}) {
|
1624
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1625
|
+
pathParams: { workspace, region, dbName: database },
|
1626
|
+
body: migration,
|
800
1627
|
...this.extraProps
|
801
1628
|
});
|
802
1629
|
}
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
1630
|
+
getMigrationRequest({
|
1631
|
+
workspace,
|
1632
|
+
region,
|
1633
|
+
database,
|
1634
|
+
migrationRequest
|
1635
|
+
}) {
|
1636
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1637
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
807
1638
|
...this.extraProps
|
808
1639
|
});
|
809
1640
|
}
|
810
|
-
|
811
|
-
|
812
|
-
|
1641
|
+
updateMigrationRequest({
|
1642
|
+
workspace,
|
1643
|
+
region,
|
1644
|
+
database,
|
1645
|
+
migrationRequest,
|
1646
|
+
update
|
1647
|
+
}) {
|
1648
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1649
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1650
|
+
body: update,
|
813
1651
|
...this.extraProps
|
814
1652
|
});
|
815
1653
|
}
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
1654
|
+
listMigrationRequestsCommits({
|
1655
|
+
workspace,
|
1656
|
+
region,
|
1657
|
+
database,
|
1658
|
+
migrationRequest,
|
1659
|
+
page
|
1660
|
+
}) {
|
1661
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1662
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1663
|
+
body: { page },
|
820
1664
|
...this.extraProps
|
821
1665
|
});
|
822
1666
|
}
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
1667
|
+
compareMigrationRequest({
|
1668
|
+
workspace,
|
1669
|
+
region,
|
1670
|
+
database,
|
1671
|
+
migrationRequest
|
1672
|
+
}) {
|
1673
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1674
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
827
1675
|
...this.extraProps
|
828
1676
|
});
|
829
1677
|
}
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
1678
|
+
getMigrationRequestIsMerged({
|
1679
|
+
workspace,
|
1680
|
+
region,
|
1681
|
+
database,
|
1682
|
+
migrationRequest
|
1683
|
+
}) {
|
1684
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1685
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
834
1686
|
...this.extraProps
|
835
1687
|
});
|
836
1688
|
}
|
837
|
-
|
838
|
-
|
839
|
-
|
1689
|
+
mergeMigrationRequest({
|
1690
|
+
workspace,
|
1691
|
+
region,
|
1692
|
+
database,
|
1693
|
+
migrationRequest
|
1694
|
+
}) {
|
1695
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1696
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
840
1697
|
...this.extraProps
|
841
1698
|
});
|
842
1699
|
}
|
843
1700
|
}
|
844
|
-
class
|
1701
|
+
class MigrationsApi {
|
845
1702
|
constructor(extraProps) {
|
846
1703
|
this.extraProps = extraProps;
|
847
1704
|
}
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
1705
|
+
getBranchMigrationHistory({
|
1706
|
+
workspace,
|
1707
|
+
region,
|
1708
|
+
database,
|
1709
|
+
branch,
|
1710
|
+
limit,
|
1711
|
+
startFrom
|
1712
|
+
}) {
|
1713
|
+
return operationsByTag.migrations.getBranchMigrationHistory({
|
1714
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1715
|
+
body: { limit, startFrom },
|
857
1716
|
...this.extraProps
|
858
1717
|
});
|
859
1718
|
}
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
1719
|
+
getBranchMigrationPlan({
|
1720
|
+
workspace,
|
1721
|
+
region,
|
1722
|
+
database,
|
1723
|
+
branch,
|
1724
|
+
schema
|
1725
|
+
}) {
|
1726
|
+
return operationsByTag.migrations.getBranchMigrationPlan({
|
1727
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1728
|
+
body: schema,
|
864
1729
|
...this.extraProps
|
865
1730
|
});
|
866
1731
|
}
|
867
|
-
|
868
|
-
|
869
|
-
|
1732
|
+
executeBranchMigrationPlan({
|
1733
|
+
workspace,
|
1734
|
+
region,
|
1735
|
+
database,
|
1736
|
+
branch,
|
1737
|
+
plan
|
1738
|
+
}) {
|
1739
|
+
return operationsByTag.migrations.executeBranchMigrationPlan({
|
1740
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1741
|
+
body: plan,
|
870
1742
|
...this.extraProps
|
871
1743
|
});
|
872
1744
|
}
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
1745
|
+
getBranchSchemaHistory({
|
1746
|
+
workspace,
|
1747
|
+
region,
|
1748
|
+
database,
|
1749
|
+
branch,
|
1750
|
+
page
|
1751
|
+
}) {
|
1752
|
+
return operationsByTag.migrations.getBranchSchemaHistory({
|
1753
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1754
|
+
body: { page },
|
877
1755
|
...this.extraProps
|
878
1756
|
});
|
879
1757
|
}
|
880
|
-
|
881
|
-
|
882
|
-
|
1758
|
+
compareBranchWithUserSchema({
|
1759
|
+
workspace,
|
1760
|
+
region,
|
1761
|
+
database,
|
1762
|
+
branch,
|
1763
|
+
schema
|
1764
|
+
}) {
|
1765
|
+
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1766
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1767
|
+
body: { schema },
|
883
1768
|
...this.extraProps
|
884
1769
|
});
|
885
1770
|
}
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
1771
|
+
compareBranchSchemas({
|
1772
|
+
workspace,
|
1773
|
+
region,
|
1774
|
+
database,
|
1775
|
+
branch,
|
1776
|
+
compare,
|
1777
|
+
schema
|
1778
|
+
}) {
|
1779
|
+
return operationsByTag.migrations.compareBranchSchemas({
|
1780
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1781
|
+
body: { schema },
|
890
1782
|
...this.extraProps
|
891
1783
|
});
|
892
1784
|
}
|
893
|
-
|
894
|
-
|
895
|
-
|
1785
|
+
updateBranchSchema({
|
1786
|
+
workspace,
|
1787
|
+
region,
|
1788
|
+
database,
|
1789
|
+
branch,
|
1790
|
+
migration
|
1791
|
+
}) {
|
1792
|
+
return operationsByTag.migrations.updateBranchSchema({
|
1793
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1794
|
+
body: migration,
|
896
1795
|
...this.extraProps
|
897
1796
|
});
|
898
1797
|
}
|
899
|
-
|
900
|
-
|
901
|
-
|
1798
|
+
previewBranchSchemaEdit({
|
1799
|
+
workspace,
|
1800
|
+
region,
|
1801
|
+
database,
|
1802
|
+
branch,
|
1803
|
+
data
|
1804
|
+
}) {
|
1805
|
+
return operationsByTag.migrations.previewBranchSchemaEdit({
|
1806
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1807
|
+
body: data,
|
902
1808
|
...this.extraProps
|
903
1809
|
});
|
904
1810
|
}
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
1811
|
+
applyBranchSchemaEdit({
|
1812
|
+
workspace,
|
1813
|
+
region,
|
1814
|
+
database,
|
1815
|
+
branch,
|
1816
|
+
edits
|
1817
|
+
}) {
|
1818
|
+
return operationsByTag.migrations.applyBranchSchemaEdit({
|
1819
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1820
|
+
body: { edits },
|
909
1821
|
...this.extraProps
|
910
1822
|
});
|
911
1823
|
}
|
912
1824
|
}
|
913
|
-
class
|
1825
|
+
class DatabaseApi {
|
914
1826
|
constructor(extraProps) {
|
915
1827
|
this.extraProps = extraProps;
|
916
1828
|
}
|
917
|
-
|
918
|
-
return operationsByTag.
|
919
|
-
pathParams: {
|
920
|
-
body: record,
|
921
|
-
...this.extraProps
|
922
|
-
});
|
923
|
-
}
|
924
|
-
insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
925
|
-
return operationsByTag.records.insertRecordWithID({
|
926
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
927
|
-
queryParams: options,
|
928
|
-
body: record,
|
929
|
-
...this.extraProps
|
930
|
-
});
|
931
|
-
}
|
932
|
-
updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
933
|
-
return operationsByTag.records.updateRecordWithID({
|
934
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
935
|
-
queryParams: options,
|
936
|
-
body: record,
|
937
|
-
...this.extraProps
|
938
|
-
});
|
939
|
-
}
|
940
|
-
upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
|
941
|
-
return operationsByTag.records.upsertRecordWithID({
|
942
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
943
|
-
queryParams: options,
|
944
|
-
body: record,
|
945
|
-
...this.extraProps
|
946
|
-
});
|
947
|
-
}
|
948
|
-
deleteRecord(workspace, database, branch, tableName, recordId) {
|
949
|
-
return operationsByTag.records.deleteRecord({
|
950
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
|
1829
|
+
getDatabaseList({ workspace }) {
|
1830
|
+
return operationsByTag.databases.getDatabaseList({
|
1831
|
+
pathParams: { workspaceId: workspace },
|
951
1832
|
...this.extraProps
|
952
1833
|
});
|
953
1834
|
}
|
954
|
-
|
955
|
-
|
956
|
-
|
1835
|
+
createDatabase({
|
1836
|
+
workspace,
|
1837
|
+
database,
|
1838
|
+
data
|
1839
|
+
}) {
|
1840
|
+
return operationsByTag.databases.createDatabase({
|
1841
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1842
|
+
body: data,
|
957
1843
|
...this.extraProps
|
958
1844
|
});
|
959
1845
|
}
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
1846
|
+
deleteDatabase({
|
1847
|
+
workspace,
|
1848
|
+
database
|
1849
|
+
}) {
|
1850
|
+
return operationsByTag.databases.deleteDatabase({
|
1851
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
964
1852
|
...this.extraProps
|
965
1853
|
});
|
966
1854
|
}
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
1855
|
+
getDatabaseMetadata({
|
1856
|
+
workspace,
|
1857
|
+
database
|
1858
|
+
}) {
|
1859
|
+
return operationsByTag.databases.getDatabaseMetadata({
|
1860
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
971
1861
|
...this.extraProps
|
972
1862
|
});
|
973
1863
|
}
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
1864
|
+
updateDatabaseMetadata({
|
1865
|
+
workspace,
|
1866
|
+
database,
|
1867
|
+
metadata
|
1868
|
+
}) {
|
1869
|
+
return operationsByTag.databases.updateDatabaseMetadata({
|
1870
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1871
|
+
body: metadata,
|
978
1872
|
...this.extraProps
|
979
1873
|
});
|
980
1874
|
}
|
981
|
-
|
982
|
-
return operationsByTag.
|
983
|
-
pathParams: {
|
984
|
-
body: query,
|
1875
|
+
listRegions({ workspace }) {
|
1876
|
+
return operationsByTag.databases.listRegions({
|
1877
|
+
pathParams: { workspaceId: workspace },
|
985
1878
|
...this.extraProps
|
986
1879
|
});
|
987
1880
|
}
|
@@ -997,6 +1890,13 @@ class XataApiPlugin {
|
|
997
1890
|
class XataPlugin {
|
998
1891
|
}
|
999
1892
|
|
1893
|
+
function cleanFilter(filter) {
|
1894
|
+
if (!filter)
|
1895
|
+
return void 0;
|
1896
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
1897
|
+
return values.length > 0 ? filter : void 0;
|
1898
|
+
}
|
1899
|
+
|
1000
1900
|
var __accessCheck$6 = (obj, member, msg) => {
|
1001
1901
|
if (!member.has(obj))
|
1002
1902
|
throw TypeError("Cannot " + msg);
|
@@ -1029,11 +1929,11 @@ class Page {
|
|
1029
1929
|
async previousPage(size, offset) {
|
1030
1930
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1031
1931
|
}
|
1032
|
-
async
|
1033
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
1932
|
+
async startPage(size, offset) {
|
1933
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1034
1934
|
}
|
1035
|
-
async
|
1036
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
1935
|
+
async endPage(size, offset) {
|
1936
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1037
1937
|
}
|
1038
1938
|
hasNextPage() {
|
1039
1939
|
return this.meta.page.more;
|
@@ -1045,7 +1945,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
|
|
1045
1945
|
const PAGINATION_MAX_OFFSET = 800;
|
1046
1946
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1047
1947
|
function isCursorPaginationOptions(options) {
|
1048
|
-
return isDefined(options) && (isDefined(options.
|
1948
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1049
1949
|
}
|
1050
1950
|
const _RecordArray = class extends Array {
|
1051
1951
|
constructor(...args) {
|
@@ -1066,6 +1966,12 @@ const _RecordArray = class extends Array {
|
|
1066
1966
|
toArray() {
|
1067
1967
|
return new Array(...this);
|
1068
1968
|
}
|
1969
|
+
toSerializable() {
|
1970
|
+
return JSON.parse(this.toString());
|
1971
|
+
}
|
1972
|
+
toString() {
|
1973
|
+
return JSON.stringify(this.toArray());
|
1974
|
+
}
|
1069
1975
|
map(callbackfn, thisArg) {
|
1070
1976
|
return this.toArray().map(callbackfn, thisArg);
|
1071
1977
|
}
|
@@ -1077,12 +1983,12 @@ const _RecordArray = class extends Array {
|
|
1077
1983
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1078
1984
|
return new _RecordArray(newPage);
|
1079
1985
|
}
|
1080
|
-
async
|
1081
|
-
const newPage = await __privateGet$6(this, _page).
|
1986
|
+
async startPage(size, offset) {
|
1987
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1082
1988
|
return new _RecordArray(newPage);
|
1083
1989
|
}
|
1084
|
-
async
|
1085
|
-
const newPage = await __privateGet$6(this, _page).
|
1990
|
+
async endPage(size, offset) {
|
1991
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1086
1992
|
return new _RecordArray(newPage);
|
1087
1993
|
}
|
1088
1994
|
hasNextPage() {
|
@@ -1110,9 +2016,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1110
2016
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1111
2017
|
return value;
|
1112
2018
|
};
|
1113
|
-
var
|
2019
|
+
var __privateMethod$3 = (obj, member, method) => {
|
2020
|
+
__accessCheck$5(obj, member, "access private method");
|
2021
|
+
return method;
|
2022
|
+
};
|
2023
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1114
2024
|
const _Query = class {
|
1115
2025
|
constructor(repository, table, data, rawParent) {
|
2026
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1116
2027
|
__privateAdd$5(this, _table$1, void 0);
|
1117
2028
|
__privateAdd$5(this, _repository, void 0);
|
1118
2029
|
__privateAdd$5(this, _data, { filter: {} });
|
@@ -1131,9 +2042,11 @@ const _Query = class {
|
|
1131
2042
|
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1132
2043
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1133
2044
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1134
|
-
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns
|
2045
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
2046
|
+
__privateGet$5(this, _data).consistency = data.consistency ?? parent?.consistency;
|
1135
2047
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1136
2048
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
2049
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1137
2050
|
this.any = this.any.bind(this);
|
1138
2051
|
this.all = this.all.bind(this);
|
1139
2052
|
this.not = this.not.bind(this);
|
@@ -1169,21 +2082,29 @@ const _Query = class {
|
|
1169
2082
|
}
|
1170
2083
|
filter(a, b) {
|
1171
2084
|
if (arguments.length === 1) {
|
1172
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
2085
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
2086
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
2087
|
+
}));
|
1173
2088
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1174
2089
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1175
2090
|
} else {
|
1176
|
-
const
|
2091
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
2092
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1177
2093
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1178
2094
|
}
|
1179
2095
|
}
|
1180
|
-
sort(column, direction) {
|
2096
|
+
sort(column, direction = "asc") {
|
1181
2097
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1182
2098
|
const sort = [...originalSort, { column, direction }];
|
1183
2099
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
1184
2100
|
}
|
1185
2101
|
select(columns) {
|
1186
|
-
return new _Query(
|
2102
|
+
return new _Query(
|
2103
|
+
__privateGet$5(this, _repository),
|
2104
|
+
__privateGet$5(this, _table$1),
|
2105
|
+
{ columns },
|
2106
|
+
__privateGet$5(this, _data)
|
2107
|
+
);
|
1187
2108
|
}
|
1188
2109
|
getPaginated(options = {}) {
|
1189
2110
|
const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
|
@@ -1206,11 +2127,20 @@ const _Query = class {
|
|
1206
2127
|
}
|
1207
2128
|
}
|
1208
2129
|
async getMany(options = {}) {
|
1209
|
-
const
|
2130
|
+
const { pagination = {}, ...rest } = options;
|
2131
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
2132
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
2133
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
2134
|
+
const results = [...page.records];
|
2135
|
+
while (page.hasNextPage() && results.length < size) {
|
2136
|
+
page = await page.nextPage();
|
2137
|
+
results.push(...page.records);
|
2138
|
+
}
|
1210
2139
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1211
2140
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1212
2141
|
}
|
1213
|
-
|
2142
|
+
const array = new RecordArray(page, results.slice(0, size));
|
2143
|
+
return array;
|
1214
2144
|
}
|
1215
2145
|
async getAll(options = {}) {
|
1216
2146
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1224,19 +2154,35 @@ const _Query = class {
|
|
1224
2154
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1225
2155
|
return records[0] ?? null;
|
1226
2156
|
}
|
2157
|
+
async getFirstOrThrow(options = {}) {
|
2158
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
2159
|
+
if (records[0] === void 0)
|
2160
|
+
throw new Error("No results found.");
|
2161
|
+
return records[0];
|
2162
|
+
}
|
2163
|
+
async summarize(params = {}) {
|
2164
|
+
const { summaries, summariesFilter, ...options } = params;
|
2165
|
+
const query = new _Query(
|
2166
|
+
__privateGet$5(this, _repository),
|
2167
|
+
__privateGet$5(this, _table$1),
|
2168
|
+
options,
|
2169
|
+
__privateGet$5(this, _data)
|
2170
|
+
);
|
2171
|
+
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2172
|
+
}
|
1227
2173
|
cache(ttl) {
|
1228
2174
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1229
2175
|
}
|
1230
2176
|
nextPage(size, offset) {
|
1231
|
-
return this.
|
2177
|
+
return this.startPage(size, offset);
|
1232
2178
|
}
|
1233
2179
|
previousPage(size, offset) {
|
1234
|
-
return this.
|
2180
|
+
return this.startPage(size, offset);
|
1235
2181
|
}
|
1236
|
-
|
2182
|
+
startPage(size, offset) {
|
1237
2183
|
return this.getPaginated({ pagination: { size, offset } });
|
1238
2184
|
}
|
1239
|
-
|
2185
|
+
endPage(size, offset) {
|
1240
2186
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
1241
2187
|
}
|
1242
2188
|
hasNextPage() {
|
@@ -1247,9 +2193,20 @@ let Query = _Query;
|
|
1247
2193
|
_table$1 = new WeakMap();
|
1248
2194
|
_repository = new WeakMap();
|
1249
2195
|
_data = new WeakMap();
|
2196
|
+
_cleanFilterConstraint = new WeakSet();
|
2197
|
+
cleanFilterConstraint_fn = function(column, value) {
|
2198
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
2199
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
2200
|
+
return { $includes: value };
|
2201
|
+
}
|
2202
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
2203
|
+
return value.id;
|
2204
|
+
}
|
2205
|
+
return value;
|
2206
|
+
};
|
1250
2207
|
function cleanParent(data, parent) {
|
1251
2208
|
if (isCursorPaginationOptions(data.pagination)) {
|
1252
|
-
return { ...parent,
|
2209
|
+
return { ...parent, sort: void 0, filter: void 0 };
|
1253
2210
|
}
|
1254
2211
|
return parent;
|
1255
2212
|
}
|
@@ -1308,317 +2265,574 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1308
2265
|
__accessCheck$4(obj, member, "access private method");
|
1309
2266
|
return method;
|
1310
2267
|
};
|
1311
|
-
var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2268
|
+
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;
|
2269
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
1312
2270
|
class Repository extends Query {
|
1313
2271
|
}
|
1314
2272
|
class RestRepository extends Query {
|
1315
2273
|
constructor(options) {
|
1316
|
-
super(
|
2274
|
+
super(
|
2275
|
+
null,
|
2276
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
2277
|
+
{}
|
2278
|
+
);
|
1317
2279
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1318
2280
|
__privateAdd$4(this, _insertRecordWithId);
|
1319
|
-
__privateAdd$4(this,
|
2281
|
+
__privateAdd$4(this, _insertRecords);
|
1320
2282
|
__privateAdd$4(this, _updateRecordWithID);
|
2283
|
+
__privateAdd$4(this, _updateRecords);
|
1321
2284
|
__privateAdd$4(this, _upsertRecordWithID);
|
1322
2285
|
__privateAdd$4(this, _deleteRecord);
|
1323
|
-
__privateAdd$4(this,
|
1324
|
-
__privateAdd$4(this, _setCacheRecord);
|
1325
|
-
__privateAdd$4(this, _getCacheRecord);
|
2286
|
+
__privateAdd$4(this, _deleteRecords);
|
1326
2287
|
__privateAdd$4(this, _setCacheQuery);
|
1327
2288
|
__privateAdd$4(this, _getCacheQuery);
|
1328
2289
|
__privateAdd$4(this, _getSchemaTables$1);
|
1329
2290
|
__privateAdd$4(this, _table, void 0);
|
1330
2291
|
__privateAdd$4(this, _getFetchProps, void 0);
|
2292
|
+
__privateAdd$4(this, _db, void 0);
|
1331
2293
|
__privateAdd$4(this, _cache, void 0);
|
1332
2294
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
2295
|
+
__privateAdd$4(this, _trace, void 0);
|
1333
2296
|
__privateSet$4(this, _table, options.table);
|
1334
|
-
__privateSet$4(this,
|
1335
|
-
this.db = options.db;
|
2297
|
+
__privateSet$4(this, _db, options.db);
|
1336
2298
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1337
2299
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2300
|
+
__privateSet$4(this, _getFetchProps, async () => {
|
2301
|
+
const props = await options.pluginOptions.getFetchProps();
|
2302
|
+
return { ...props, sessionID: generateUUID() };
|
2303
|
+
});
|
2304
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2305
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2306
|
+
return trace(name, fn, {
|
2307
|
+
...options2,
|
2308
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
2309
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
2310
|
+
[TraceAttributes.VERSION]: VERSION
|
2311
|
+
});
|
2312
|
+
});
|
1338
2313
|
}
|
1339
|
-
async create(a, b) {
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
2314
|
+
async create(a, b, c, d) {
|
2315
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
2316
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2317
|
+
if (Array.isArray(a)) {
|
2318
|
+
if (a.length === 0)
|
2319
|
+
return [];
|
2320
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2321
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2322
|
+
const result = await this.read(ids, columns);
|
2323
|
+
return result;
|
2324
|
+
}
|
2325
|
+
if (isString(a) && isObject(b)) {
|
2326
|
+
if (a === "")
|
2327
|
+
throw new Error("The id can't be empty");
|
2328
|
+
const columns = isStringArray(c) ? c : void 0;
|
2329
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2330
|
+
}
|
2331
|
+
if (isObject(a) && isString(a.id)) {
|
2332
|
+
if (a.id === "")
|
2333
|
+
throw new Error("The id can't be empty");
|
2334
|
+
const columns = isStringArray(b) ? b : void 0;
|
2335
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2336
|
+
}
|
2337
|
+
if (isObject(a)) {
|
2338
|
+
const columns = isStringArray(b) ? b : void 0;
|
2339
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2340
|
+
}
|
2341
|
+
throw new Error("Invalid arguments for create method");
|
2342
|
+
});
|
2343
|
+
}
|
2344
|
+
async read(a, b) {
|
2345
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2346
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2347
|
+
if (Array.isArray(a)) {
|
2348
|
+
if (a.length === 0)
|
2349
|
+
return [];
|
2350
|
+
const ids = a.map((item) => extractId(item));
|
2351
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
2352
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
2353
|
+
acc[object.id] = object;
|
2354
|
+
return acc;
|
2355
|
+
}, {});
|
2356
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
2357
|
+
}
|
2358
|
+
const id = extractId(a);
|
2359
|
+
if (id) {
|
2360
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2361
|
+
try {
|
2362
|
+
const response = await getRecord({
|
2363
|
+
pathParams: {
|
2364
|
+
workspace: "{workspaceId}",
|
2365
|
+
dbBranchName: "{dbBranch}",
|
2366
|
+
region: "{region}",
|
2367
|
+
tableName: __privateGet$4(this, _table),
|
2368
|
+
recordId: id
|
2369
|
+
},
|
2370
|
+
queryParams: { columns },
|
2371
|
+
...fetchProps
|
2372
|
+
});
|
2373
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2374
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2375
|
+
} catch (e) {
|
2376
|
+
if (isObject(e) && e.status === 404) {
|
2377
|
+
return null;
|
2378
|
+
}
|
2379
|
+
throw e;
|
2380
|
+
}
|
2381
|
+
}
|
2382
|
+
return null;
|
2383
|
+
});
|
2384
|
+
}
|
2385
|
+
async readOrThrow(a, b) {
|
2386
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
2387
|
+
const result = await this.read(a, b);
|
2388
|
+
if (Array.isArray(result)) {
|
2389
|
+
const missingIds = compact(
|
2390
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2391
|
+
);
|
2392
|
+
if (missingIds.length > 0) {
|
2393
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2394
|
+
}
|
2395
|
+
return result;
|
2396
|
+
}
|
2397
|
+
if (result === null) {
|
2398
|
+
const id = extractId(a) ?? "unknown";
|
2399
|
+
throw new Error(`Record with id ${id} not found`);
|
2400
|
+
}
|
2401
|
+
return result;
|
2402
|
+
});
|
2403
|
+
}
|
2404
|
+
async update(a, b, c, d) {
|
2405
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
2406
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2407
|
+
if (Array.isArray(a)) {
|
2408
|
+
if (a.length === 0)
|
2409
|
+
return [];
|
2410
|
+
const existing = await this.read(a, ["id"]);
|
2411
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
2412
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2413
|
+
ifVersion,
|
2414
|
+
upsert: false
|
1385
2415
|
});
|
1386
|
-
const
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
2416
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2417
|
+
const result = await this.read(a, columns);
|
2418
|
+
return result;
|
2419
|
+
}
|
2420
|
+
try {
|
2421
|
+
if (isString(a) && isObject(b)) {
|
2422
|
+
const columns = isStringArray(c) ? c : void 0;
|
2423
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2424
|
+
}
|
2425
|
+
if (isObject(a) && isString(a.id)) {
|
2426
|
+
const columns = isStringArray(b) ? b : void 0;
|
2427
|
+
return await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2428
|
+
}
|
2429
|
+
} catch (error) {
|
2430
|
+
if (error.status === 422)
|
1390
2431
|
return null;
|
2432
|
+
throw error;
|
2433
|
+
}
|
2434
|
+
throw new Error("Invalid arguments for update method");
|
2435
|
+
});
|
2436
|
+
}
|
2437
|
+
async updateOrThrow(a, b, c, d) {
|
2438
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
2439
|
+
const result = await this.update(a, b, c, d);
|
2440
|
+
if (Array.isArray(result)) {
|
2441
|
+
const missingIds = compact(
|
2442
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2443
|
+
);
|
2444
|
+
if (missingIds.length > 0) {
|
2445
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1391
2446
|
}
|
1392
|
-
|
2447
|
+
return result;
|
1393
2448
|
}
|
1394
|
-
|
2449
|
+
if (result === null) {
|
2450
|
+
const id = extractId(a) ?? "unknown";
|
2451
|
+
throw new Error(`Record with id ${id} not found`);
|
2452
|
+
}
|
2453
|
+
return result;
|
2454
|
+
});
|
1395
2455
|
}
|
1396
|
-
async
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
2456
|
+
async createOrUpdate(a, b, c, d) {
|
2457
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
2458
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2459
|
+
if (Array.isArray(a)) {
|
2460
|
+
if (a.length === 0)
|
2461
|
+
return [];
|
2462
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
2463
|
+
ifVersion,
|
2464
|
+
upsert: true
|
2465
|
+
});
|
2466
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2467
|
+
const result = await this.read(a, columns);
|
2468
|
+
return result;
|
1402
2469
|
}
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1407
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
|
1408
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1409
|
-
return record;
|
1410
|
-
}
|
1411
|
-
if (isObject(a) && isString(a.id)) {
|
1412
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1413
|
-
const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1414
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1415
|
-
return record;
|
1416
|
-
}
|
1417
|
-
throw new Error("Invalid arguments for update method");
|
1418
|
-
}
|
1419
|
-
async createOrUpdate(a, b) {
|
1420
|
-
if (Array.isArray(a)) {
|
1421
|
-
if (a.length === 0)
|
1422
|
-
return [];
|
1423
|
-
if (a.length > 100) {
|
1424
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
2470
|
+
if (isString(a) && isObject(b)) {
|
2471
|
+
const columns = isStringArray(c) ? c : void 0;
|
2472
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
1425
2473
|
}
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
|
1430
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
|
1431
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1432
|
-
return record;
|
1433
|
-
}
|
1434
|
-
if (isObject(a) && isString(a.id)) {
|
1435
|
-
await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
|
1436
|
-
const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
|
1437
|
-
await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
|
1438
|
-
return record;
|
1439
|
-
}
|
1440
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1441
|
-
}
|
1442
|
-
async delete(a) {
|
1443
|
-
if (Array.isArray(a)) {
|
1444
|
-
if (a.length === 0)
|
1445
|
-
return;
|
1446
|
-
if (a.length > 100) {
|
1447
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
2474
|
+
if (isObject(a) && isString(a.id)) {
|
2475
|
+
const columns = isStringArray(c) ? c : void 0;
|
2476
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
1448
2477
|
}
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
2478
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
2479
|
+
});
|
2480
|
+
}
|
2481
|
+
async createOrReplace(a, b, c, d) {
|
2482
|
+
return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
|
2483
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2484
|
+
if (Array.isArray(a)) {
|
2485
|
+
if (a.length === 0)
|
2486
|
+
return [];
|
2487
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2488
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2489
|
+
const result = await this.read(ids, columns);
|
2490
|
+
return result;
|
2491
|
+
}
|
2492
|
+
if (isString(a) && isObject(b)) {
|
2493
|
+
const columns = isStringArray(c) ? c : void 0;
|
2494
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2495
|
+
}
|
2496
|
+
if (isObject(a) && isString(a.id)) {
|
2497
|
+
const columns = isStringArray(c) ? c : void 0;
|
2498
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
2499
|
+
}
|
2500
|
+
throw new Error("Invalid arguments for createOrReplace method");
|
2501
|
+
});
|
2502
|
+
}
|
2503
|
+
async delete(a, b) {
|
2504
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
2505
|
+
if (Array.isArray(a)) {
|
2506
|
+
if (a.length === 0)
|
2507
|
+
return [];
|
2508
|
+
const ids = a.map((o) => {
|
2509
|
+
if (isString(o))
|
2510
|
+
return o;
|
2511
|
+
if (isString(o.id))
|
2512
|
+
return o.id;
|
2513
|
+
throw new Error("Invalid arguments for delete method");
|
2514
|
+
});
|
2515
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2516
|
+
const result = await this.read(a, columns);
|
2517
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2518
|
+
return result;
|
2519
|
+
}
|
2520
|
+
if (isString(a)) {
|
2521
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
2522
|
+
}
|
2523
|
+
if (isObject(a) && isString(a.id)) {
|
2524
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
2525
|
+
}
|
2526
|
+
throw new Error("Invalid arguments for delete method");
|
2527
|
+
});
|
2528
|
+
}
|
2529
|
+
async deleteOrThrow(a, b) {
|
2530
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
2531
|
+
const result = await this.delete(a, b);
|
2532
|
+
if (Array.isArray(result)) {
|
2533
|
+
const missingIds = compact(
|
2534
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2535
|
+
);
|
2536
|
+
if (missingIds.length > 0) {
|
2537
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2538
|
+
}
|
2539
|
+
return result;
|
2540
|
+
} else if (result === null) {
|
2541
|
+
const id = extractId(a) ?? "unknown";
|
2542
|
+
throw new Error(`Record with id ${id} not found`);
|
2543
|
+
}
|
2544
|
+
return result;
|
2545
|
+
});
|
1463
2546
|
}
|
1464
2547
|
async search(query, options = {}) {
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
2548
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2549
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2550
|
+
const { records } = await searchTable({
|
2551
|
+
pathParams: {
|
2552
|
+
workspace: "{workspaceId}",
|
2553
|
+
dbBranchName: "{dbBranch}",
|
2554
|
+
region: "{region}",
|
2555
|
+
tableName: __privateGet$4(this, _table)
|
2556
|
+
},
|
2557
|
+
body: {
|
2558
|
+
query,
|
2559
|
+
fuzziness: options.fuzziness,
|
2560
|
+
prefix: options.prefix,
|
2561
|
+
highlight: options.highlight,
|
2562
|
+
filter: options.filter,
|
2563
|
+
boosters: options.boosters,
|
2564
|
+
page: options.page,
|
2565
|
+
target: options.target
|
2566
|
+
},
|
2567
|
+
...fetchProps
|
2568
|
+
});
|
2569
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2570
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
2571
|
+
});
|
2572
|
+
}
|
2573
|
+
async aggregate(aggs, filter) {
|
2574
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2575
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2576
|
+
const result = await aggregateTable({
|
2577
|
+
pathParams: {
|
2578
|
+
workspace: "{workspaceId}",
|
2579
|
+
dbBranchName: "{dbBranch}",
|
2580
|
+
region: "{region}",
|
2581
|
+
tableName: __privateGet$4(this, _table)
|
2582
|
+
},
|
2583
|
+
body: { aggs, filter },
|
2584
|
+
...fetchProps
|
2585
|
+
});
|
2586
|
+
return result;
|
1475
2587
|
});
|
1476
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1477
|
-
return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
|
1478
2588
|
}
|
1479
2589
|
async query(query) {
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
2590
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
2591
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
2592
|
+
if (cacheQuery)
|
2593
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2594
|
+
const data = query.getQueryOptions();
|
2595
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2596
|
+
const { meta, records: objects } = await queryTable({
|
2597
|
+
pathParams: {
|
2598
|
+
workspace: "{workspaceId}",
|
2599
|
+
dbBranchName: "{dbBranch}",
|
2600
|
+
region: "{region}",
|
2601
|
+
tableName: __privateGet$4(this, _table)
|
2602
|
+
},
|
2603
|
+
body: {
|
2604
|
+
filter: cleanFilter(data.filter),
|
2605
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2606
|
+
page: data.pagination,
|
2607
|
+
columns: data.columns ?? ["*"],
|
2608
|
+
consistency: data.consistency
|
2609
|
+
},
|
2610
|
+
fetchOptions: data.fetchOptions,
|
2611
|
+
...fetchProps
|
2612
|
+
});
|
2613
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2614
|
+
const records = objects.map(
|
2615
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
2616
|
+
);
|
2617
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2618
|
+
return new Page(query, meta, records);
|
2619
|
+
});
|
2620
|
+
}
|
2621
|
+
async summarizeTable(query, summaries, summariesFilter) {
|
2622
|
+
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2623
|
+
const data = query.getQueryOptions();
|
2624
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2625
|
+
const result = await summarizeTable({
|
2626
|
+
pathParams: {
|
2627
|
+
workspace: "{workspaceId}",
|
2628
|
+
dbBranchName: "{dbBranch}",
|
2629
|
+
region: "{region}",
|
2630
|
+
tableName: __privateGet$4(this, _table)
|
2631
|
+
},
|
2632
|
+
body: {
|
2633
|
+
filter: cleanFilter(data.filter),
|
2634
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2635
|
+
columns: data.columns,
|
2636
|
+
consistency: data.consistency,
|
2637
|
+
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2638
|
+
summaries,
|
2639
|
+
summariesFilter
|
2640
|
+
},
|
2641
|
+
...fetchProps
|
2642
|
+
});
|
2643
|
+
return result;
|
1495
2644
|
});
|
1496
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1497
|
-
const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
|
1498
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1499
|
-
return new Page(query, meta, records);
|
1500
2645
|
}
|
1501
2646
|
}
|
1502
2647
|
_table = new WeakMap();
|
1503
2648
|
_getFetchProps = new WeakMap();
|
2649
|
+
_db = new WeakMap();
|
1504
2650
|
_cache = new WeakMap();
|
1505
2651
|
_schemaTables$2 = new WeakMap();
|
2652
|
+
_trace = new WeakMap();
|
1506
2653
|
_insertRecordWithoutId = new WeakSet();
|
1507
|
-
insertRecordWithoutId_fn = async function(object) {
|
2654
|
+
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1508
2655
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1509
2656
|
const record = transformObjectLinks(object);
|
1510
2657
|
const response = await insertRecord({
|
1511
2658
|
pathParams: {
|
1512
2659
|
workspace: "{workspaceId}",
|
1513
2660
|
dbBranchName: "{dbBranch}",
|
2661
|
+
region: "{region}",
|
1514
2662
|
tableName: __privateGet$4(this, _table)
|
1515
2663
|
},
|
2664
|
+
queryParams: { columns },
|
1516
2665
|
body: record,
|
1517
2666
|
...fetchProps
|
1518
2667
|
});
|
1519
|
-
const
|
1520
|
-
|
1521
|
-
throw new Error("The server failed to save the record");
|
1522
|
-
}
|
1523
|
-
return finalObject;
|
2668
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2669
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1524
2670
|
};
|
1525
2671
|
_insertRecordWithId = new WeakSet();
|
1526
|
-
insertRecordWithId_fn = async function(recordId, object) {
|
2672
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
1527
2673
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1528
2674
|
const record = transformObjectLinks(object);
|
1529
2675
|
const response = await insertRecordWithID({
|
1530
2676
|
pathParams: {
|
1531
2677
|
workspace: "{workspaceId}",
|
1532
2678
|
dbBranchName: "{dbBranch}",
|
2679
|
+
region: "{region}",
|
1533
2680
|
tableName: __privateGet$4(this, _table),
|
1534
2681
|
recordId
|
1535
2682
|
},
|
1536
2683
|
body: record,
|
1537
|
-
queryParams: { createOnly
|
2684
|
+
queryParams: { createOnly, columns, ifVersion },
|
1538
2685
|
...fetchProps
|
1539
2686
|
});
|
1540
|
-
const
|
1541
|
-
|
1542
|
-
throw new Error("The server failed to save the record");
|
1543
|
-
}
|
1544
|
-
return finalObject;
|
2687
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2688
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1545
2689
|
};
|
1546
|
-
|
1547
|
-
|
2690
|
+
_insertRecords = new WeakSet();
|
2691
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
1548
2692
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1549
|
-
const
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
const
|
1556
|
-
|
1557
|
-
|
2693
|
+
const chunkedOperations = chunk(
|
2694
|
+
objects.map((object) => ({
|
2695
|
+
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
2696
|
+
})),
|
2697
|
+
BULK_OPERATION_MAX_SIZE
|
2698
|
+
);
|
2699
|
+
const ids = [];
|
2700
|
+
for (const operations of chunkedOperations) {
|
2701
|
+
const { results } = await branchTransaction({
|
2702
|
+
pathParams: {
|
2703
|
+
workspace: "{workspaceId}",
|
2704
|
+
dbBranchName: "{dbBranch}",
|
2705
|
+
region: "{region}"
|
2706
|
+
},
|
2707
|
+
body: { operations },
|
2708
|
+
...fetchProps
|
2709
|
+
});
|
2710
|
+
for (const result of results) {
|
2711
|
+
if (result.operation === "insert") {
|
2712
|
+
ids.push(result.id);
|
2713
|
+
} else {
|
2714
|
+
ids.push(null);
|
2715
|
+
}
|
2716
|
+
}
|
1558
2717
|
}
|
1559
|
-
|
1560
|
-
acc[object.id] = object;
|
1561
|
-
return acc;
|
1562
|
-
}, {});
|
1563
|
-
return recordIDs.map((id) => dictionary[id]);
|
2718
|
+
return ids;
|
1564
2719
|
};
|
1565
2720
|
_updateRecordWithID = new WeakSet();
|
1566
|
-
updateRecordWithID_fn = async function(recordId, object) {
|
2721
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
1567
2722
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1568
|
-
const record = transformObjectLinks(object);
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
2723
|
+
const { id: _id, ...record } = transformObjectLinks(object);
|
2724
|
+
try {
|
2725
|
+
const response = await updateRecordWithID({
|
2726
|
+
pathParams: {
|
2727
|
+
workspace: "{workspaceId}",
|
2728
|
+
dbBranchName: "{dbBranch}",
|
2729
|
+
region: "{region}",
|
2730
|
+
tableName: __privateGet$4(this, _table),
|
2731
|
+
recordId
|
2732
|
+
},
|
2733
|
+
queryParams: { columns, ifVersion },
|
2734
|
+
body: record,
|
2735
|
+
...fetchProps
|
2736
|
+
});
|
2737
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2738
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2739
|
+
} catch (e) {
|
2740
|
+
if (isObject(e) && e.status === 404) {
|
2741
|
+
return null;
|
2742
|
+
}
|
2743
|
+
throw e;
|
2744
|
+
}
|
2745
|
+
};
|
2746
|
+
_updateRecords = new WeakSet();
|
2747
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2748
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2749
|
+
const chunkedOperations = chunk(
|
2750
|
+
objects.map(({ id, ...object }) => ({
|
2751
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
2752
|
+
})),
|
2753
|
+
BULK_OPERATION_MAX_SIZE
|
2754
|
+
);
|
2755
|
+
const ids = [];
|
2756
|
+
for (const operations of chunkedOperations) {
|
2757
|
+
const { results } = await branchTransaction({
|
2758
|
+
pathParams: {
|
2759
|
+
workspace: "{workspaceId}",
|
2760
|
+
dbBranchName: "{dbBranch}",
|
2761
|
+
region: "{region}"
|
2762
|
+
},
|
2763
|
+
body: { operations },
|
2764
|
+
...fetchProps
|
2765
|
+
});
|
2766
|
+
for (const result of results) {
|
2767
|
+
if (result.operation === "update") {
|
2768
|
+
ids.push(result.id);
|
2769
|
+
} else {
|
2770
|
+
ids.push(null);
|
2771
|
+
}
|
2772
|
+
}
|
2773
|
+
}
|
2774
|
+
return ids;
|
1578
2775
|
};
|
1579
2776
|
_upsertRecordWithID = new WeakSet();
|
1580
|
-
upsertRecordWithID_fn = async function(recordId, object) {
|
2777
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
1581
2778
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1582
2779
|
const response = await upsertRecordWithID({
|
1583
|
-
pathParams: {
|
2780
|
+
pathParams: {
|
2781
|
+
workspace: "{workspaceId}",
|
2782
|
+
dbBranchName: "{dbBranch}",
|
2783
|
+
region: "{region}",
|
2784
|
+
tableName: __privateGet$4(this, _table),
|
2785
|
+
recordId
|
2786
|
+
},
|
2787
|
+
queryParams: { columns, ifVersion },
|
1584
2788
|
body: object,
|
1585
2789
|
...fetchProps
|
1586
2790
|
});
|
1587
|
-
const
|
1588
|
-
|
1589
|
-
throw new Error("The server failed to save the record");
|
1590
|
-
return item;
|
2791
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2792
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1591
2793
|
};
|
1592
2794
|
_deleteRecord = new WeakSet();
|
1593
|
-
deleteRecord_fn = async function(recordId) {
|
2795
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1594
2796
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
2797
|
+
try {
|
2798
|
+
const response = await deleteRecord({
|
2799
|
+
pathParams: {
|
2800
|
+
workspace: "{workspaceId}",
|
2801
|
+
dbBranchName: "{dbBranch}",
|
2802
|
+
region: "{region}",
|
2803
|
+
tableName: __privateGet$4(this, _table),
|
2804
|
+
recordId
|
2805
|
+
},
|
2806
|
+
queryParams: { columns },
|
2807
|
+
...fetchProps
|
2808
|
+
});
|
2809
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2810
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2811
|
+
} catch (e) {
|
2812
|
+
if (isObject(e) && e.status === 404) {
|
2813
|
+
return null;
|
2814
|
+
}
|
2815
|
+
throw e;
|
2816
|
+
}
|
1599
2817
|
};
|
1600
|
-
|
1601
|
-
|
1602
|
-
await __privateGet$4(this,
|
1603
|
-
const
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
}
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
};
|
1617
|
-
|
1618
|
-
getCacheRecord_fn = async function(recordId) {
|
1619
|
-
if (!__privateGet$4(this, _cache).cacheRecords)
|
1620
|
-
return null;
|
1621
|
-
return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
|
2818
|
+
_deleteRecords = new WeakSet();
|
2819
|
+
deleteRecords_fn = async function(recordIds) {
|
2820
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2821
|
+
const chunkedOperations = chunk(
|
2822
|
+
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2823
|
+
BULK_OPERATION_MAX_SIZE
|
2824
|
+
);
|
2825
|
+
for (const operations of chunkedOperations) {
|
2826
|
+
await branchTransaction({
|
2827
|
+
pathParams: {
|
2828
|
+
workspace: "{workspaceId}",
|
2829
|
+
dbBranchName: "{dbBranch}",
|
2830
|
+
region: "{region}"
|
2831
|
+
},
|
2832
|
+
body: { operations },
|
2833
|
+
...fetchProps
|
2834
|
+
});
|
2835
|
+
}
|
1622
2836
|
};
|
1623
2837
|
_setCacheQuery = new WeakSet();
|
1624
2838
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1642,7 +2856,7 @@ getSchemaTables_fn$1 = async function() {
|
|
1642
2856
|
return __privateGet$4(this, _schemaTables$2);
|
1643
2857
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1644
2858
|
const { schema } = await getBranchDetails({
|
1645
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
2859
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
1646
2860
|
...fetchProps
|
1647
2861
|
});
|
1648
2862
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
@@ -1655,22 +2869,24 @@ const transformObjectLinks = (object) => {
|
|
1655
2869
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1656
2870
|
}, {});
|
1657
2871
|
};
|
1658
|
-
const initObject = (db, schemaTables, table, object) => {
|
1659
|
-
const
|
2872
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
2873
|
+
const data = {};
|
1660
2874
|
const { xata, ...rest } = object ?? {};
|
1661
|
-
Object.assign(
|
2875
|
+
Object.assign(data, rest);
|
1662
2876
|
const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
|
1663
2877
|
if (!columns)
|
1664
2878
|
console.error(`Table ${table} not found in schema`);
|
1665
2879
|
for (const column of columns ?? []) {
|
1666
|
-
|
2880
|
+
if (!isValidColumn(selectedColumns, column))
|
2881
|
+
continue;
|
2882
|
+
const value = data[column.name];
|
1667
2883
|
switch (column.type) {
|
1668
2884
|
case "datetime": {
|
1669
|
-
const date = value !== void 0 ? new Date(value) :
|
1670
|
-
if (date && isNaN(date.getTime())) {
|
2885
|
+
const date = value !== void 0 ? new Date(value) : null;
|
2886
|
+
if (date !== null && isNaN(date.getTime())) {
|
1671
2887
|
console.error(`Failed to parse date ${value} for field ${column.name}`);
|
1672
|
-
} else
|
1673
|
-
|
2888
|
+
} else {
|
2889
|
+
data[column.name] = date;
|
1674
2890
|
}
|
1675
2891
|
break;
|
1676
2892
|
}
|
@@ -1679,38 +2895,85 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1679
2895
|
if (!linkTable) {
|
1680
2896
|
console.error(`Failed to parse link for field ${column.name}`);
|
1681
2897
|
} else if (isObject(value)) {
|
1682
|
-
|
2898
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2899
|
+
if (item === column.name) {
|
2900
|
+
return [...acc, "*"];
|
2901
|
+
}
|
2902
|
+
if (item.startsWith(`${column.name}.`)) {
|
2903
|
+
const [, ...path] = item.split(".");
|
2904
|
+
return [...acc, path.join(".")];
|
2905
|
+
}
|
2906
|
+
return acc;
|
2907
|
+
}, []);
|
2908
|
+
data[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2909
|
+
} else {
|
2910
|
+
data[column.name] = null;
|
1683
2911
|
}
|
1684
2912
|
break;
|
1685
2913
|
}
|
2914
|
+
default:
|
2915
|
+
data[column.name] = value ?? null;
|
2916
|
+
if (column.notNull === true && value === null) {
|
2917
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2918
|
+
}
|
2919
|
+
break;
|
1686
2920
|
}
|
1687
2921
|
}
|
1688
|
-
|
1689
|
-
|
2922
|
+
const record = { ...data };
|
2923
|
+
record.read = function(columns2) {
|
2924
|
+
return db[table].read(record["id"], columns2);
|
2925
|
+
};
|
2926
|
+
record.update = function(data2, b, c) {
|
2927
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
2928
|
+
const ifVersion = parseIfVersion(b, c);
|
2929
|
+
return db[table].update(record["id"], data2, columns2, { ifVersion });
|
1690
2930
|
};
|
1691
|
-
|
1692
|
-
|
2931
|
+
record.replace = function(data2, b, c) {
|
2932
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
2933
|
+
const ifVersion = parseIfVersion(b, c);
|
2934
|
+
return db[table].createOrReplace(record["id"], data2, columns2, { ifVersion });
|
1693
2935
|
};
|
1694
|
-
|
1695
|
-
return db[table].delete(
|
2936
|
+
record.delete = function() {
|
2937
|
+
return db[table].delete(record["id"]);
|
1696
2938
|
};
|
1697
|
-
|
2939
|
+
record.getMetadata = function() {
|
1698
2940
|
return xata;
|
1699
2941
|
};
|
1700
|
-
|
1701
|
-
|
2942
|
+
record.toSerializable = function() {
|
2943
|
+
return JSON.parse(JSON.stringify(transformObjectLinks(data)));
|
2944
|
+
};
|
2945
|
+
record.toString = function() {
|
2946
|
+
return JSON.stringify(transformObjectLinks(data));
|
2947
|
+
};
|
2948
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata", "toSerializable", "toString"]) {
|
2949
|
+
Object.defineProperty(record, prop, { enumerable: false });
|
1702
2950
|
}
|
1703
|
-
Object.freeze(
|
1704
|
-
return
|
2951
|
+
Object.freeze(record);
|
2952
|
+
return record;
|
1705
2953
|
};
|
1706
|
-
function
|
1707
|
-
if (
|
1708
|
-
return value
|
2954
|
+
function extractId(value) {
|
2955
|
+
if (isString(value))
|
2956
|
+
return value;
|
2957
|
+
if (isObject(value) && isString(value.id))
|
2958
|
+
return value.id;
|
2959
|
+
return void 0;
|
2960
|
+
}
|
2961
|
+
function isValidColumn(columns, column) {
|
2962
|
+
if (columns.includes("*"))
|
2963
|
+
return true;
|
2964
|
+
if (column.type === "link") {
|
2965
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2966
|
+
return linkColumns.length > 0;
|
2967
|
+
}
|
2968
|
+
return columns.includes(column.name);
|
2969
|
+
}
|
2970
|
+
function parseIfVersion(...args) {
|
2971
|
+
for (const arg of args) {
|
2972
|
+
if (isObject(arg) && isNumber(arg.ifVersion)) {
|
2973
|
+
return arg.ifVersion;
|
2974
|
+
}
|
1709
2975
|
}
|
1710
|
-
|
1711
|
-
return [];
|
1712
|
-
const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
|
1713
|
-
return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
|
2976
|
+
return void 0;
|
1714
2977
|
}
|
1715
2978
|
|
1716
2979
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1737,7 +3000,6 @@ class SimpleCache {
|
|
1737
3000
|
__privateAdd$3(this, _map, void 0);
|
1738
3001
|
__privateSet$3(this, _map, /* @__PURE__ */ new Map());
|
1739
3002
|
this.capacity = options.max ?? 500;
|
1740
|
-
this.cacheRecords = options.cacheRecords ?? true;
|
1741
3003
|
this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
|
1742
3004
|
}
|
1743
3005
|
async getAll() {
|
@@ -1763,18 +3025,25 @@ class SimpleCache {
|
|
1763
3025
|
}
|
1764
3026
|
_map = new WeakMap();
|
1765
3027
|
|
1766
|
-
const
|
1767
|
-
const
|
1768
|
-
const
|
1769
|
-
const
|
1770
|
-
const
|
1771
|
-
const
|
3028
|
+
const greaterThan = (value) => ({ $gt: value });
|
3029
|
+
const gt = greaterThan;
|
3030
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
3031
|
+
const greaterEquals = greaterThanEquals;
|
3032
|
+
const gte = greaterThanEquals;
|
3033
|
+
const ge = greaterThanEquals;
|
3034
|
+
const lessThan = (value) => ({ $lt: value });
|
3035
|
+
const lt = lessThan;
|
3036
|
+
const lessThanEquals = (value) => ({ $le: value });
|
3037
|
+
const lessEquals = lessThanEquals;
|
3038
|
+
const lte = lessThanEquals;
|
3039
|
+
const le = lessThanEquals;
|
1772
3040
|
const exists = (column) => ({ $exists: column });
|
1773
3041
|
const notExists = (column) => ({ $notExists: column });
|
1774
3042
|
const startsWith = (value) => ({ $startsWith: value });
|
1775
3043
|
const endsWith = (value) => ({ $endsWith: value });
|
1776
3044
|
const pattern = (value) => ({ $pattern: value });
|
1777
3045
|
const is = (value) => ({ $is: value });
|
3046
|
+
const equals = is;
|
1778
3047
|
const isNot = (value) => ({ $isNot: value });
|
1779
3048
|
const contains = (value) => ({ $contains: value });
|
1780
3049
|
const includes = (value) => ({ $includes: value });
|
@@ -1809,16 +3078,19 @@ class SchemaPlugin extends XataPlugin {
|
|
1809
3078
|
__privateSet$2(this, _schemaTables$1, schemaTables);
|
1810
3079
|
}
|
1811
3080
|
build(pluginOptions) {
|
1812
|
-
const db = new Proxy(
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
3081
|
+
const db = new Proxy(
|
3082
|
+
{},
|
3083
|
+
{
|
3084
|
+
get: (_target, table) => {
|
3085
|
+
if (!isString(table))
|
3086
|
+
throw new Error("Invalid table name");
|
3087
|
+
if (__privateGet$2(this, _tables)[table] === void 0) {
|
3088
|
+
__privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
3089
|
+
}
|
3090
|
+
return __privateGet$2(this, _tables)[table];
|
1818
3091
|
}
|
1819
|
-
return __privateGet$2(this, _tables)[table];
|
1820
3092
|
}
|
1821
|
-
|
3093
|
+
);
|
1822
3094
|
const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
|
1823
3095
|
for (const table of tableNames) {
|
1824
3096
|
db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
|
@@ -1868,7 +3140,7 @@ class SearchPlugin extends XataPlugin {
|
|
1868
3140
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1869
3141
|
return records.map((record) => {
|
1870
3142
|
const { table = "orphan" } = record.xata;
|
1871
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
3143
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
1872
3144
|
});
|
1873
3145
|
},
|
1874
3146
|
byTable: async (query, options = {}) => {
|
@@ -1877,7 +3149,7 @@ class SearchPlugin extends XataPlugin {
|
|
1877
3149
|
return records.reduce((acc, record) => {
|
1878
3150
|
const { table = "orphan" } = record.xata;
|
1879
3151
|
const items = acc[table] ?? [];
|
1880
|
-
const item = initObject(this.db, schemaTables, table, record);
|
3152
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1881
3153
|
return { ...acc, [table]: [...items, item] };
|
1882
3154
|
}, {});
|
1883
3155
|
}
|
@@ -1888,10 +3160,10 @@ _schemaTables = new WeakMap();
|
|
1888
3160
|
_search = new WeakSet();
|
1889
3161
|
search_fn = async function(query, options, getFetchProps) {
|
1890
3162
|
const fetchProps = await getFetchProps();
|
1891
|
-
const { tables, fuzziness, highlight } = options ?? {};
|
3163
|
+
const { tables, fuzziness, highlight, prefix, page } = options ?? {};
|
1892
3164
|
const { records } = await searchBranch({
|
1893
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
1894
|
-
body: { tables, query, fuzziness, highlight },
|
3165
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3166
|
+
body: { tables, query, fuzziness, prefix, highlight, page },
|
1895
3167
|
...fetchProps
|
1896
3168
|
});
|
1897
3169
|
return records;
|
@@ -1902,25 +3174,37 @@ getSchemaTables_fn = async function(getFetchProps) {
|
|
1902
3174
|
return __privateGet$1(this, _schemaTables);
|
1903
3175
|
const fetchProps = await getFetchProps();
|
1904
3176
|
const { schema } = await getBranchDetails({
|
1905
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
3177
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
1906
3178
|
...fetchProps
|
1907
3179
|
});
|
1908
3180
|
__privateSet$1(this, _schemaTables, schema.tables);
|
1909
3181
|
return schema.tables;
|
1910
3182
|
};
|
1911
3183
|
|
3184
|
+
class TransactionPlugin extends XataPlugin {
|
3185
|
+
build({ getFetchProps }) {
|
3186
|
+
return {
|
3187
|
+
run: async (operations) => {
|
3188
|
+
const fetchProps = await getFetchProps();
|
3189
|
+
const response = await branchTransaction({
|
3190
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
3191
|
+
body: { operations },
|
3192
|
+
...fetchProps
|
3193
|
+
});
|
3194
|
+
return response;
|
3195
|
+
}
|
3196
|
+
};
|
3197
|
+
}
|
3198
|
+
}
|
3199
|
+
|
1912
3200
|
const isBranchStrategyBuilder = (strategy) => {
|
1913
3201
|
return typeof strategy === "function";
|
1914
3202
|
};
|
1915
3203
|
|
1916
3204
|
async function getCurrentBranchName(options) {
|
1917
3205
|
const { branch, envBranch } = getEnvironment();
|
1918
|
-
if (branch)
|
1919
|
-
|
1920
|
-
if (details)
|
1921
|
-
return branch;
|
1922
|
-
console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
|
1923
|
-
}
|
3206
|
+
if (branch)
|
3207
|
+
return branch;
|
1924
3208
|
const gitBranch = envBranch || await getGitBranch();
|
1925
3209
|
return resolveXataBranch(gitBranch, options);
|
1926
3210
|
}
|
@@ -1932,19 +3216,28 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1932
3216
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1933
3217
|
const apiKey = options?.apiKey || getAPIKey();
|
1934
3218
|
if (!databaseURL)
|
1935
|
-
throw new Error(
|
3219
|
+
throw new Error(
|
3220
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3221
|
+
);
|
1936
3222
|
if (!apiKey)
|
1937
|
-
throw new Error(
|
3223
|
+
throw new Error(
|
3224
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3225
|
+
);
|
1938
3226
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1939
|
-
const
|
3227
|
+
const urlParts = parseWorkspacesUrlParts(host);
|
3228
|
+
if (!urlParts)
|
3229
|
+
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3230
|
+
const { workspace, region } = urlParts;
|
1940
3231
|
const { fallbackBranch } = getEnvironment();
|
1941
3232
|
const { branch } = await resolveBranch({
|
1942
3233
|
apiKey,
|
1943
3234
|
apiUrl: databaseURL,
|
1944
3235
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1945
3236
|
workspacesApiUrl: `${protocol}//${host}`,
|
1946
|
-
pathParams: { dbName, workspace },
|
1947
|
-
queryParams: { gitBranch, fallbackBranch }
|
3237
|
+
pathParams: { dbName, workspace, region },
|
3238
|
+
queryParams: { gitBranch, fallbackBranch },
|
3239
|
+
trace: defaultTrace,
|
3240
|
+
clientName: options?.clientName
|
1948
3241
|
});
|
1949
3242
|
return branch;
|
1950
3243
|
}
|
@@ -1952,19 +3245,26 @@ async function getDatabaseBranch(branch, options) {
|
|
1952
3245
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
1953
3246
|
const apiKey = options?.apiKey || getAPIKey();
|
1954
3247
|
if (!databaseURL)
|
1955
|
-
throw new Error(
|
3248
|
+
throw new Error(
|
3249
|
+
"A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
|
3250
|
+
);
|
1956
3251
|
if (!apiKey)
|
1957
|
-
throw new Error(
|
3252
|
+
throw new Error(
|
3253
|
+
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
3254
|
+
);
|
1958
3255
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1959
|
-
const
|
1960
|
-
|
3256
|
+
const urlParts = parseWorkspacesUrlParts(host);
|
3257
|
+
if (!urlParts)
|
3258
|
+
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3259
|
+
const { workspace, region } = urlParts;
|
1961
3260
|
try {
|
1962
3261
|
return await getBranchDetails({
|
1963
3262
|
apiKey,
|
1964
3263
|
apiUrl: databaseURL,
|
1965
3264
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1966
3265
|
workspacesApiUrl: `${protocol}//${host}`,
|
1967
|
-
pathParams: { dbBranchName
|
3266
|
+
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3267
|
+
trace: defaultTrace
|
1968
3268
|
});
|
1969
3269
|
} catch (err) {
|
1970
3270
|
if (isObject(err) && err.status === 404)
|
@@ -2004,22 +3304,27 @@ var __privateMethod = (obj, member, method) => {
|
|
2004
3304
|
return method;
|
2005
3305
|
};
|
2006
3306
|
const buildClient = (plugins) => {
|
2007
|
-
var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
3307
|
+
var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
|
2008
3308
|
return _a = class {
|
2009
3309
|
constructor(options = {}, schemaTables) {
|
2010
3310
|
__privateAdd(this, _parseOptions);
|
2011
3311
|
__privateAdd(this, _getFetchProps);
|
2012
3312
|
__privateAdd(this, _evaluateBranch);
|
2013
3313
|
__privateAdd(this, _branch, void 0);
|
3314
|
+
__privateAdd(this, _options, void 0);
|
2014
3315
|
const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
|
3316
|
+
__privateSet(this, _options, safeOptions);
|
2015
3317
|
const pluginOptions = {
|
2016
3318
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2017
|
-
cache: safeOptions.cache
|
3319
|
+
cache: safeOptions.cache,
|
3320
|
+
trace: safeOptions.trace
|
2018
3321
|
};
|
2019
3322
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2020
3323
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
3324
|
+
const transactions = new TransactionPlugin().build(pluginOptions);
|
2021
3325
|
this.db = db;
|
2022
3326
|
this.search = search;
|
3327
|
+
this.transactions = transactions;
|
2023
3328
|
for (const [key, namespace] of Object.entries(plugins ?? {})) {
|
2024
3329
|
if (namespace === void 0)
|
2025
3330
|
continue;
|
@@ -2033,21 +3338,46 @@ const buildClient = (plugins) => {
|
|
2033
3338
|
}
|
2034
3339
|
}
|
2035
3340
|
}
|
2036
|
-
|
3341
|
+
async getConfig() {
|
3342
|
+
const databaseURL = __privateGet(this, _options).databaseURL;
|
3343
|
+
const branch = await __privateGet(this, _options).branch();
|
3344
|
+
return { databaseURL, branch };
|
3345
|
+
}
|
3346
|
+
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3347
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3348
|
+
const isBrowser = typeof window !== "undefined" && typeof Deno === "undefined";
|
3349
|
+
if (isBrowser && !enableBrowser) {
|
3350
|
+
throw new Error(
|
3351
|
+
"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."
|
3352
|
+
);
|
3353
|
+
}
|
2037
3354
|
const fetch = getFetchImplementation(options?.fetch);
|
2038
3355
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2039
3356
|
const apiKey = options?.apiKey || getAPIKey();
|
2040
|
-
const cache = options?.cache ?? new SimpleCache({
|
2041
|
-
const
|
2042
|
-
|
2043
|
-
|
3357
|
+
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3358
|
+
const trace = options?.trace ?? defaultTrace;
|
3359
|
+
const clientName = options?.clientName;
|
3360
|
+
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({
|
3361
|
+
apiKey,
|
3362
|
+
databaseURL,
|
3363
|
+
fetchImpl: options?.fetch,
|
3364
|
+
clientName: options?.clientName
|
3365
|
+
});
|
3366
|
+
if (!apiKey) {
|
3367
|
+
throw new Error("Option apiKey is required");
|
2044
3368
|
}
|
2045
|
-
|
3369
|
+
if (!databaseURL) {
|
3370
|
+
throw new Error("Option databaseURL is required");
|
3371
|
+
}
|
3372
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser, clientName };
|
2046
3373
|
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
2047
3374
|
fetch,
|
2048
3375
|
apiKey,
|
2049
3376
|
databaseURL,
|
2050
|
-
branch
|
3377
|
+
branch,
|
3378
|
+
trace,
|
3379
|
+
clientID,
|
3380
|
+
clientName
|
2051
3381
|
}) {
|
2052
3382
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2053
3383
|
if (!branchValue)
|
@@ -2058,9 +3388,12 @@ const buildClient = (plugins) => {
|
|
2058
3388
|
apiUrl: "",
|
2059
3389
|
workspacesApiUrl: (path, params) => {
|
2060
3390
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2061
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
3391
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2062
3392
|
return databaseURL + newPath;
|
2063
|
-
}
|
3393
|
+
},
|
3394
|
+
trace,
|
3395
|
+
clientID,
|
3396
|
+
clientName
|
2064
3397
|
};
|
2065
3398
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2066
3399
|
if (__privateGet(this, _branch))
|
@@ -2142,25 +3475,25 @@ class Serializer {
|
|
2142
3475
|
});
|
2143
3476
|
}
|
2144
3477
|
}
|
2145
|
-
const
|
2146
|
-
|
3478
|
+
const defaultSerializer = new Serializer();
|
3479
|
+
const serialize = (data) => {
|
3480
|
+
return defaultSerializer.toJSON(data);
|
2147
3481
|
};
|
2148
|
-
const deserialize = () => {
|
2149
|
-
|
3482
|
+
const deserialize = (json) => {
|
3483
|
+
return defaultSerializer.fromJSON(json);
|
2150
3484
|
};
|
2151
3485
|
|
2152
3486
|
function buildWorkerRunner(config) {
|
2153
|
-
return function xataWorker(name,
|
3487
|
+
return function xataWorker(name, worker) {
|
2154
3488
|
return async (...args) => {
|
2155
|
-
const
|
3489
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
3490
|
+
const result = await fetch(url, {
|
2156
3491
|
method: "POST",
|
2157
3492
|
headers: { "Content-Type": "application/json" },
|
2158
|
-
body:
|
2159
|
-
name,
|
2160
|
-
payload: args
|
2161
|
-
})
|
3493
|
+
body: serialize({ args })
|
2162
3494
|
});
|
2163
|
-
|
3495
|
+
const text = await result.text();
|
3496
|
+
return deserialize(text);
|
2164
3497
|
};
|
2165
3498
|
};
|
2166
3499
|
}
|
@@ -2172,5 +3505,5 @@ class XataError extends Error {
|
|
2172
3505
|
}
|
2173
3506
|
}
|
2174
3507
|
|
2175
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
3508
|
+
export { BaseClient, FetcherError, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, 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, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2176
3509
|
//# sourceMappingURL=index.mjs.map
|