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