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