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