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