@xata.io/client 0.0.0-alpha.vf73045e → 0.0.0-alpha.vf76843f
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 +158 -0
- package/README.md +30 -30
- package/Usage.md +15 -11
- package/dist/index.cjs +1907 -704
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4665 -1242
- package/dist/index.mjs +1872 -685
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- /package/{rollup.config.js → rollup.config.mjs} +0 -0
package/dist/index.mjs
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
const defaultTrace = async (_name, fn, _options) => {
|
2
|
+
return await fn({
|
3
|
+
setAttributes: () => {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
});
|
7
|
+
};
|
8
|
+
const TraceAttributes = {
|
9
|
+
KIND: "xata.trace.kind",
|
10
|
+
VERSION: "xata.sdk.version",
|
11
|
+
TABLE: "xata.table",
|
12
|
+
HTTP_REQUEST_ID: "http.request_id",
|
13
|
+
HTTP_STATUS_CODE: "http.status_code",
|
14
|
+
HTTP_HOST: "http.host",
|
15
|
+
HTTP_SCHEME: "http.scheme",
|
16
|
+
HTTP_USER_AGENT: "http.user_agent",
|
17
|
+
HTTP_METHOD: "http.method",
|
18
|
+
HTTP_URL: "http.url",
|
19
|
+
HTTP_ROUTE: "http.route",
|
20
|
+
HTTP_TARGET: "http.target"
|
21
|
+
};
|
22
|
+
|
1
23
|
function notEmpty(value) {
|
2
24
|
return value !== null && value !== void 0;
|
3
25
|
}
|
@@ -16,6 +38,9 @@ function isString(value) {
|
|
16
38
|
function isStringArray(value) {
|
17
39
|
return isDefined(value) && Array.isArray(value) && value.every(isString);
|
18
40
|
}
|
41
|
+
function isNumber(value) {
|
42
|
+
return isDefined(value) && typeof value === "number";
|
43
|
+
}
|
19
44
|
function toBase64(value) {
|
20
45
|
try {
|
21
46
|
return btoa(value);
|
@@ -24,6 +49,24 @@ function toBase64(value) {
|
|
24
49
|
return buf.from(value).toString("base64");
|
25
50
|
}
|
26
51
|
}
|
52
|
+
function deepMerge(a, b) {
|
53
|
+
const result = { ...a };
|
54
|
+
for (const [key, value] of Object.entries(b)) {
|
55
|
+
if (isObject(value) && isObject(result[key])) {
|
56
|
+
result[key] = deepMerge(result[key], value);
|
57
|
+
} else {
|
58
|
+
result[key] = value;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
return result;
|
62
|
+
}
|
63
|
+
function chunk(array, chunkSize) {
|
64
|
+
const result = [];
|
65
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
66
|
+
result.push(array.slice(i, i + chunkSize));
|
67
|
+
}
|
68
|
+
return result;
|
69
|
+
}
|
27
70
|
|
28
71
|
function getEnvironment() {
|
29
72
|
try {
|
@@ -58,6 +101,25 @@ function getEnvironment() {
|
|
58
101
|
fallbackBranch: getGlobalFallbackBranch()
|
59
102
|
};
|
60
103
|
}
|
104
|
+
function getEnableBrowserVariable() {
|
105
|
+
try {
|
106
|
+
if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
|
107
|
+
return process.env.XATA_ENABLE_BROWSER === "true";
|
108
|
+
}
|
109
|
+
} catch (err) {
|
110
|
+
}
|
111
|
+
try {
|
112
|
+
if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
|
113
|
+
return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
|
114
|
+
}
|
115
|
+
} catch (err) {
|
116
|
+
}
|
117
|
+
try {
|
118
|
+
return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
|
119
|
+
} catch (err) {
|
120
|
+
return void 0;
|
121
|
+
}
|
122
|
+
}
|
61
123
|
function getGlobalApiKey() {
|
62
124
|
try {
|
63
125
|
return XATA_API_KEY;
|
@@ -122,13 +184,13 @@ function getFetchImplementation(userFetch) {
|
|
122
184
|
const fetchImpl = userFetch ?? globalFetch;
|
123
185
|
if (!fetchImpl) {
|
124
186
|
throw new Error(
|
125
|
-
`
|
187
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
126
188
|
);
|
127
189
|
}
|
128
190
|
return fetchImpl;
|
129
191
|
}
|
130
192
|
|
131
|
-
const VERSION = "0.0.0-alpha.
|
193
|
+
const VERSION = "0.0.0-alpha.vf76843f";
|
132
194
|
|
133
195
|
class ErrorWithCause extends Error {
|
134
196
|
constructor(message, options) {
|
@@ -179,18 +241,24 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
179
241
|
}, {});
|
180
242
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
181
243
|
const queryString = query.length > 0 ? `?${query}` : "";
|
182
|
-
|
244
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
245
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
246
|
+
}, {});
|
247
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
183
248
|
};
|
184
249
|
function buildBaseUrl({
|
250
|
+
endpoint,
|
185
251
|
path,
|
186
252
|
workspacesApiUrl,
|
187
253
|
apiUrl,
|
188
|
-
pathParams
|
254
|
+
pathParams = {}
|
189
255
|
}) {
|
190
|
-
if (
|
191
|
-
|
192
|
-
|
193
|
-
|
256
|
+
if (endpoint === "dataPlane") {
|
257
|
+
const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
258
|
+
const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
|
259
|
+
return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
|
260
|
+
}
|
261
|
+
return `${apiUrl}${path}`;
|
194
262
|
}
|
195
263
|
function hostHeader(url) {
|
196
264
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -206,277 +274,231 @@ async function fetch$1({
|
|
206
274
|
queryParams,
|
207
275
|
fetchImpl,
|
208
276
|
apiKey,
|
277
|
+
endpoint,
|
209
278
|
apiUrl,
|
210
|
-
workspacesApiUrl
|
279
|
+
workspacesApiUrl,
|
280
|
+
trace,
|
281
|
+
signal,
|
282
|
+
clientID,
|
283
|
+
sessionID,
|
284
|
+
fetchOptions = {}
|
211
285
|
}) {
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
286
|
+
return trace(
|
287
|
+
`${method.toUpperCase()} ${path}`,
|
288
|
+
async ({ setAttributes }) => {
|
289
|
+
const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
|
290
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
291
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
292
|
+
setAttributes({
|
293
|
+
[TraceAttributes.HTTP_URL]: url,
|
294
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
295
|
+
});
|
296
|
+
const response = await fetchImpl(url, {
|
297
|
+
...fetchOptions,
|
298
|
+
method: method.toUpperCase(),
|
299
|
+
body: body ? JSON.stringify(body) : void 0,
|
300
|
+
headers: {
|
301
|
+
"Content-Type": "application/json",
|
302
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
303
|
+
"X-Xata-Client-ID": clientID ?? "",
|
304
|
+
"X-Xata-Session-ID": sessionID ?? "",
|
305
|
+
...headers,
|
306
|
+
...hostHeader(fullUrl),
|
307
|
+
Authorization: `Bearer ${apiKey}`
|
308
|
+
},
|
309
|
+
signal
|
310
|
+
});
|
311
|
+
if (response.status === 204) {
|
312
|
+
return {};
|
313
|
+
}
|
314
|
+
const { host, protocol } = parseUrl(response.url);
|
315
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
316
|
+
setAttributes({
|
317
|
+
[TraceAttributes.KIND]: "http",
|
318
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
319
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
320
|
+
[TraceAttributes.HTTP_HOST]: host,
|
321
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
322
|
+
});
|
323
|
+
try {
|
324
|
+
const jsonResponse = await response.json();
|
325
|
+
if (response.ok) {
|
326
|
+
return jsonResponse;
|
327
|
+
}
|
328
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
329
|
+
} catch (error) {
|
330
|
+
throw new FetcherError(response.status, error, requestId);
|
331
|
+
}
|
332
|
+
},
|
333
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
334
|
+
);
|
335
|
+
}
|
336
|
+
function parseUrl(url) {
|
230
337
|
try {
|
231
|
-
const
|
232
|
-
|
233
|
-
return jsonResponse;
|
234
|
-
}
|
235
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
338
|
+
const { host, protocol } = new URL(url);
|
339
|
+
return { host, protocol };
|
236
340
|
} catch (error) {
|
237
|
-
|
341
|
+
return {};
|
238
342
|
}
|
239
343
|
}
|
240
344
|
|
241
|
-
const
|
242
|
-
|
243
|
-
const
|
244
|
-
const
|
245
|
-
url: "/user/keys",
|
246
|
-
method: "get",
|
247
|
-
...variables
|
248
|
-
});
|
249
|
-
const createUserAPIKey = (variables) => fetch$1({
|
250
|
-
url: "/user/keys/{keyName}",
|
251
|
-
method: "post",
|
252
|
-
...variables
|
253
|
-
});
|
254
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
255
|
-
url: "/user/keys/{keyName}",
|
256
|
-
method: "delete",
|
257
|
-
...variables
|
258
|
-
});
|
259
|
-
const createWorkspace = (variables) => fetch$1({
|
260
|
-
url: "/workspaces",
|
261
|
-
method: "post",
|
262
|
-
...variables
|
263
|
-
});
|
264
|
-
const getWorkspacesList = (variables) => fetch$1({
|
265
|
-
url: "/workspaces",
|
266
|
-
method: "get",
|
267
|
-
...variables
|
268
|
-
});
|
269
|
-
const getWorkspace = (variables) => fetch$1({
|
270
|
-
url: "/workspaces/{workspaceId}",
|
271
|
-
method: "get",
|
272
|
-
...variables
|
273
|
-
});
|
274
|
-
const updateWorkspace = (variables) => fetch$1({
|
275
|
-
url: "/workspaces/{workspaceId}",
|
276
|
-
method: "put",
|
277
|
-
...variables
|
278
|
-
});
|
279
|
-
const deleteWorkspace = (variables) => fetch$1({
|
280
|
-
url: "/workspaces/{workspaceId}",
|
281
|
-
method: "delete",
|
282
|
-
...variables
|
283
|
-
});
|
284
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
285
|
-
url: "/workspaces/{workspaceId}/members",
|
286
|
-
method: "get",
|
287
|
-
...variables
|
288
|
-
});
|
289
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
290
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
291
|
-
url: "/workspaces/{workspaceId}/members/{userId}",
|
292
|
-
method: "delete",
|
293
|
-
...variables
|
294
|
-
});
|
295
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
296
|
-
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
297
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
298
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
299
|
-
method: "delete",
|
300
|
-
...variables
|
301
|
-
});
|
302
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
303
|
-
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
304
|
-
method: "post",
|
305
|
-
...variables
|
306
|
-
});
|
307
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
308
|
-
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
309
|
-
method: "post",
|
310
|
-
...variables
|
311
|
-
});
|
312
|
-
const getDatabaseList = (variables) => fetch$1({
|
313
|
-
url: "/dbs",
|
314
|
-
method: "get",
|
315
|
-
...variables
|
316
|
-
});
|
317
|
-
const getBranchList = (variables) => fetch$1({
|
318
|
-
url: "/dbs/{dbName}",
|
319
|
-
method: "get",
|
320
|
-
...variables
|
321
|
-
});
|
322
|
-
const createDatabase = (variables) => fetch$1({
|
323
|
-
url: "/dbs/{dbName}",
|
324
|
-
method: "put",
|
325
|
-
...variables
|
326
|
-
});
|
327
|
-
const deleteDatabase = (variables) => fetch$1({
|
345
|
+
const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
|
346
|
+
|
347
|
+
const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
|
348
|
+
const getBranchList = (variables, signal) => dataPlaneFetch({
|
328
349
|
url: "/dbs/{dbName}",
|
329
|
-
method: "delete",
|
330
|
-
...variables
|
331
|
-
});
|
332
|
-
const getDatabaseMetadata = (variables) => fetch$1({
|
333
|
-
url: "/dbs/{dbName}/metadata",
|
334
|
-
method: "get",
|
335
|
-
...variables
|
336
|
-
});
|
337
|
-
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
338
|
-
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
339
|
-
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
340
|
-
const resolveBranch = (variables) => fetch$1({
|
341
|
-
url: "/dbs/{dbName}/resolveBranch",
|
342
350
|
method: "get",
|
343
|
-
...variables
|
351
|
+
...variables,
|
352
|
+
signal
|
344
353
|
});
|
345
|
-
const
|
354
|
+
const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
|
355
|
+
const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
|
356
|
+
const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
|
357
|
+
const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
358
|
+
const getBranchDetails = (variables, signal) => dataPlaneFetch({
|
346
359
|
url: "/db/{dbBranchName}",
|
347
360
|
method: "get",
|
348
|
-
...variables
|
361
|
+
...variables,
|
362
|
+
signal
|
349
363
|
});
|
350
|
-
const createBranch = (variables) =>
|
351
|
-
const deleteBranch = (variables) =>
|
364
|
+
const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
365
|
+
const deleteBranch = (variables, signal) => dataPlaneFetch({
|
352
366
|
url: "/db/{dbBranchName}",
|
353
367
|
method: "delete",
|
354
|
-
...variables
|
368
|
+
...variables,
|
369
|
+
signal
|
355
370
|
});
|
356
|
-
const updateBranchMetadata = (variables) =>
|
371
|
+
const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
|
357
372
|
url: "/db/{dbBranchName}/metadata",
|
358
373
|
method: "put",
|
359
|
-
...variables
|
374
|
+
...variables,
|
375
|
+
signal
|
360
376
|
});
|
361
|
-
const getBranchMetadata = (variables) =>
|
377
|
+
const getBranchMetadata = (variables, signal) => dataPlaneFetch({
|
362
378
|
url: "/db/{dbBranchName}/metadata",
|
363
379
|
method: "get",
|
364
|
-
...variables
|
380
|
+
...variables,
|
381
|
+
signal
|
365
382
|
});
|
366
|
-
const
|
367
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
368
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
369
|
-
const getBranchStats = (variables) => fetch$1({
|
383
|
+
const getBranchStats = (variables, signal) => dataPlaneFetch({
|
370
384
|
url: "/db/{dbBranchName}/stats",
|
371
385
|
method: "get",
|
372
|
-
...variables
|
386
|
+
...variables,
|
387
|
+
signal
|
388
|
+
});
|
389
|
+
const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
390
|
+
const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
391
|
+
const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
392
|
+
const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
|
393
|
+
const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
394
|
+
const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
395
|
+
const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
396
|
+
const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
|
397
|
+
const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
398
|
+
const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
399
|
+
const getMigrationRequest = (variables, signal) => dataPlaneFetch({
|
400
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
401
|
+
method: "get",
|
402
|
+
...variables,
|
403
|
+
signal
|
373
404
|
});
|
374
|
-
const
|
405
|
+
const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
406
|
+
const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
407
|
+
const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
408
|
+
const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
409
|
+
const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
|
410
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
411
|
+
method: "post",
|
412
|
+
...variables,
|
413
|
+
signal
|
414
|
+
});
|
415
|
+
const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
416
|
+
const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
417
|
+
const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
418
|
+
const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
|
419
|
+
const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
420
|
+
const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
421
|
+
const createTable = (variables, signal) => dataPlaneFetch({
|
375
422
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
376
423
|
method: "put",
|
377
|
-
...variables
|
424
|
+
...variables,
|
425
|
+
signal
|
378
426
|
});
|
379
|
-
const deleteTable = (variables) =>
|
427
|
+
const deleteTable = (variables, signal) => dataPlaneFetch({
|
380
428
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
381
429
|
method: "delete",
|
382
|
-
...variables
|
430
|
+
...variables,
|
431
|
+
signal
|
383
432
|
});
|
384
|
-
const updateTable = (variables) =>
|
385
|
-
|
386
|
-
method: "patch",
|
387
|
-
...variables
|
388
|
-
});
|
389
|
-
const getTableSchema = (variables) => fetch$1({
|
433
|
+
const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
|
434
|
+
const getTableSchema = (variables, signal) => dataPlaneFetch({
|
390
435
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
391
436
|
method: "get",
|
392
|
-
...variables
|
393
|
-
|
394
|
-
const setTableSchema = (variables) => fetch$1({
|
395
|
-
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
396
|
-
method: "put",
|
397
|
-
...variables
|
437
|
+
...variables,
|
438
|
+
signal
|
398
439
|
});
|
399
|
-
const
|
440
|
+
const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
|
441
|
+
const getTableColumns = (variables, signal) => dataPlaneFetch({
|
400
442
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
401
443
|
method: "get",
|
402
|
-
...variables
|
403
|
-
|
404
|
-
const addTableColumn = (variables) => fetch$1({
|
405
|
-
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
406
|
-
method: "post",
|
407
|
-
...variables
|
444
|
+
...variables,
|
445
|
+
signal
|
408
446
|
});
|
409
|
-
const
|
447
|
+
const addTableColumn = (variables, signal) => dataPlaneFetch(
|
448
|
+
{ url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
|
449
|
+
);
|
450
|
+
const getColumn = (variables, signal) => dataPlaneFetch({
|
410
451
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
411
452
|
method: "get",
|
412
|
-
...variables
|
453
|
+
...variables,
|
454
|
+
signal
|
413
455
|
});
|
414
|
-
const
|
456
|
+
const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
|
457
|
+
const deleteColumn = (variables, signal) => dataPlaneFetch({
|
415
458
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
416
459
|
method: "delete",
|
417
|
-
...variables
|
460
|
+
...variables,
|
461
|
+
signal
|
418
462
|
});
|
419
|
-
const
|
420
|
-
|
421
|
-
method: "patch",
|
422
|
-
...variables
|
423
|
-
});
|
424
|
-
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
425
|
-
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
426
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
427
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
428
|
-
const deleteRecord = (variables) => fetch$1({
|
429
|
-
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
430
|
-
method: "delete",
|
431
|
-
...variables
|
432
|
-
});
|
433
|
-
const getRecord = (variables) => fetch$1({
|
463
|
+
const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
464
|
+
const getRecord = (variables, signal) => dataPlaneFetch({
|
434
465
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
435
466
|
method: "get",
|
436
|
-
...variables
|
467
|
+
...variables,
|
468
|
+
signal
|
437
469
|
});
|
438
|
-
const
|
439
|
-
const
|
470
|
+
const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
471
|
+
const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
472
|
+
const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
473
|
+
const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
|
474
|
+
const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
475
|
+
const queryTable = (variables, signal) => dataPlaneFetch({
|
440
476
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
441
477
|
method: "post",
|
442
|
-
...variables
|
478
|
+
...variables,
|
479
|
+
signal
|
443
480
|
});
|
444
|
-
const
|
445
|
-
url: "/db/{dbBranchName}/
|
481
|
+
const searchBranch = (variables, signal) => dataPlaneFetch({
|
482
|
+
url: "/db/{dbBranchName}/search",
|
446
483
|
method: "post",
|
447
|
-
...variables
|
484
|
+
...variables,
|
485
|
+
signal
|
448
486
|
});
|
449
|
-
const
|
450
|
-
url: "/db/{dbBranchName}/search",
|
487
|
+
const searchTable = (variables, signal) => dataPlaneFetch({
|
488
|
+
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
451
489
|
method: "post",
|
452
|
-
...variables
|
490
|
+
...variables,
|
491
|
+
signal
|
453
492
|
});
|
454
|
-
const
|
455
|
-
|
456
|
-
|
457
|
-
createWorkspace,
|
458
|
-
getWorkspacesList,
|
459
|
-
getWorkspace,
|
460
|
-
updateWorkspace,
|
461
|
-
deleteWorkspace,
|
462
|
-
getWorkspaceMembersList,
|
463
|
-
updateWorkspaceMemberRole,
|
464
|
-
removeWorkspaceMember,
|
465
|
-
inviteWorkspaceMember,
|
466
|
-
updateWorkspaceMemberInvite,
|
467
|
-
cancelWorkspaceMemberInvite,
|
468
|
-
resendWorkspaceMemberInvite,
|
469
|
-
acceptWorkspaceMemberInvite
|
470
|
-
},
|
493
|
+
const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
|
494
|
+
const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
|
495
|
+
const operationsByTag$2 = {
|
471
496
|
database: {
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
addGitBranchesEntry,
|
478
|
-
removeGitBranchesEntry,
|
479
|
-
resolveBranch
|
497
|
+
dEPRECATEDgetDatabaseList,
|
498
|
+
dEPRECATEDcreateDatabase,
|
499
|
+
dEPRECATEDdeleteDatabase,
|
500
|
+
dEPRECATEDgetDatabaseMetadata,
|
501
|
+
dEPRECATEDupdateDatabaseMetadata
|
480
502
|
},
|
481
503
|
branch: {
|
482
504
|
getBranchList,
|
@@ -485,10 +507,42 @@ const operationsByTag = {
|
|
485
507
|
deleteBranch,
|
486
508
|
updateBranchMetadata,
|
487
509
|
getBranchMetadata,
|
510
|
+
getBranchStats,
|
511
|
+
getGitBranchesMapping,
|
512
|
+
addGitBranchesEntry,
|
513
|
+
removeGitBranchesEntry,
|
514
|
+
resolveBranch
|
515
|
+
},
|
516
|
+
migrations: {
|
488
517
|
getBranchMigrationHistory,
|
489
|
-
executeBranchMigrationPlan,
|
490
518
|
getBranchMigrationPlan,
|
491
|
-
|
519
|
+
executeBranchMigrationPlan,
|
520
|
+
getBranchSchemaHistory,
|
521
|
+
compareBranchWithUserSchema,
|
522
|
+
compareBranchSchemas,
|
523
|
+
updateBranchSchema,
|
524
|
+
previewBranchSchemaEdit,
|
525
|
+
applyBranchSchemaEdit
|
526
|
+
},
|
527
|
+
records: {
|
528
|
+
branchTransaction,
|
529
|
+
insertRecord,
|
530
|
+
getRecord,
|
531
|
+
insertRecordWithID,
|
532
|
+
updateRecordWithID,
|
533
|
+
upsertRecordWithID,
|
534
|
+
deleteRecord,
|
535
|
+
bulkInsertTableRecords
|
536
|
+
},
|
537
|
+
migrationRequests: {
|
538
|
+
queryMigrationRequests,
|
539
|
+
createMigrationRequest,
|
540
|
+
getMigrationRequest,
|
541
|
+
updateMigrationRequest,
|
542
|
+
listMigrationRequestsCommits,
|
543
|
+
compareMigrationRequest,
|
544
|
+
getMigrationRequestIsMerged,
|
545
|
+
mergeMigrationRequest
|
492
546
|
},
|
493
547
|
table: {
|
494
548
|
createTable,
|
@@ -499,27 +553,150 @@ const operationsByTag = {
|
|
499
553
|
getTableColumns,
|
500
554
|
addTableColumn,
|
501
555
|
getColumn,
|
502
|
-
|
503
|
-
|
556
|
+
updateColumn,
|
557
|
+
deleteColumn
|
504
558
|
},
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
559
|
+
searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
|
560
|
+
};
|
561
|
+
|
562
|
+
const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
|
563
|
+
|
564
|
+
const getUser = (variables, signal) => controlPlaneFetch({
|
565
|
+
url: "/user",
|
566
|
+
method: "get",
|
567
|
+
...variables,
|
568
|
+
signal
|
569
|
+
});
|
570
|
+
const updateUser = (variables, signal) => controlPlaneFetch({
|
571
|
+
url: "/user",
|
572
|
+
method: "put",
|
573
|
+
...variables,
|
574
|
+
signal
|
575
|
+
});
|
576
|
+
const deleteUser = (variables, signal) => controlPlaneFetch({
|
577
|
+
url: "/user",
|
578
|
+
method: "delete",
|
579
|
+
...variables,
|
580
|
+
signal
|
581
|
+
});
|
582
|
+
const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
|
583
|
+
url: "/user/keys",
|
584
|
+
method: "get",
|
585
|
+
...variables,
|
586
|
+
signal
|
587
|
+
});
|
588
|
+
const createUserAPIKey = (variables, signal) => controlPlaneFetch({
|
589
|
+
url: "/user/keys/{keyName}",
|
590
|
+
method: "post",
|
591
|
+
...variables,
|
592
|
+
signal
|
593
|
+
});
|
594
|
+
const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
|
595
|
+
url: "/user/keys/{keyName}",
|
596
|
+
method: "delete",
|
597
|
+
...variables,
|
598
|
+
signal
|
599
|
+
});
|
600
|
+
const getWorkspacesList = (variables, signal) => controlPlaneFetch({
|
601
|
+
url: "/workspaces",
|
602
|
+
method: "get",
|
603
|
+
...variables,
|
604
|
+
signal
|
605
|
+
});
|
606
|
+
const createWorkspace = (variables, signal) => controlPlaneFetch({
|
607
|
+
url: "/workspaces",
|
608
|
+
method: "post",
|
609
|
+
...variables,
|
610
|
+
signal
|
611
|
+
});
|
612
|
+
const getWorkspace = (variables, signal) => controlPlaneFetch({
|
613
|
+
url: "/workspaces/{workspaceId}",
|
614
|
+
method: "get",
|
615
|
+
...variables,
|
616
|
+
signal
|
617
|
+
});
|
618
|
+
const updateWorkspace = (variables, signal) => controlPlaneFetch({
|
619
|
+
url: "/workspaces/{workspaceId}",
|
620
|
+
method: "put",
|
621
|
+
...variables,
|
622
|
+
signal
|
623
|
+
});
|
624
|
+
const deleteWorkspace = (variables, signal) => controlPlaneFetch({
|
625
|
+
url: "/workspaces/{workspaceId}",
|
626
|
+
method: "delete",
|
627
|
+
...variables,
|
628
|
+
signal
|
629
|
+
});
|
630
|
+
const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
|
631
|
+
const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
632
|
+
const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
|
633
|
+
url: "/workspaces/{workspaceId}/members/{userId}",
|
634
|
+
method: "delete",
|
635
|
+
...variables,
|
636
|
+
signal
|
637
|
+
});
|
638
|
+
const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
639
|
+
const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
640
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
|
641
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
|
642
|
+
const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
|
643
|
+
const getDatabaseList = (variables, signal) => controlPlaneFetch({
|
644
|
+
url: "/workspaces/{workspaceId}/dbs",
|
645
|
+
method: "get",
|
646
|
+
...variables,
|
647
|
+
signal
|
648
|
+
});
|
649
|
+
const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
650
|
+
const deleteDatabase = (variables, signal) => controlPlaneFetch({
|
651
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
652
|
+
method: "delete",
|
653
|
+
...variables,
|
654
|
+
signal
|
655
|
+
});
|
656
|
+
const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
|
657
|
+
const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
|
658
|
+
const listRegions = (variables, signal) => controlPlaneFetch({
|
659
|
+
url: "/workspaces/{workspaceId}/regions",
|
660
|
+
method: "get",
|
661
|
+
...variables,
|
662
|
+
signal
|
663
|
+
});
|
664
|
+
const operationsByTag$1 = {
|
665
|
+
users: { getUser, updateUser, deleteUser },
|
666
|
+
authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
667
|
+
workspaces: {
|
668
|
+
getWorkspacesList,
|
669
|
+
createWorkspace,
|
670
|
+
getWorkspace,
|
671
|
+
updateWorkspace,
|
672
|
+
deleteWorkspace,
|
673
|
+
getWorkspaceMembersList,
|
674
|
+
updateWorkspaceMemberRole,
|
675
|
+
removeWorkspaceMember
|
676
|
+
},
|
677
|
+
invites: {
|
678
|
+
inviteWorkspaceMember,
|
679
|
+
updateWorkspaceMemberInvite,
|
680
|
+
cancelWorkspaceMemberInvite,
|
681
|
+
acceptWorkspaceMemberInvite,
|
682
|
+
resendWorkspaceMemberInvite
|
683
|
+
},
|
684
|
+
databases: {
|
685
|
+
getDatabaseList,
|
686
|
+
createDatabase,
|
687
|
+
deleteDatabase,
|
688
|
+
getDatabaseMetadata,
|
689
|
+
updateDatabaseMetadata,
|
690
|
+
listRegions
|
516
691
|
}
|
517
692
|
};
|
518
693
|
|
694
|
+
const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
|
695
|
+
|
519
696
|
function getHostUrl(provider, type) {
|
520
|
-
if (
|
697
|
+
if (isHostProviderAlias(provider)) {
|
521
698
|
return providers[provider][type];
|
522
|
-
} else if (
|
699
|
+
} else if (isHostProviderBuilder(provider)) {
|
523
700
|
return provider[type];
|
524
701
|
}
|
525
702
|
throw new Error("Invalid API provider");
|
@@ -527,19 +704,38 @@ function getHostUrl(provider, type) {
|
|
527
704
|
const providers = {
|
528
705
|
production: {
|
529
706
|
main: "https://api.xata.io",
|
530
|
-
workspaces: "https://{workspaceId}.xata.sh"
|
707
|
+
workspaces: "https://{workspaceId}.{region}.xata.sh"
|
531
708
|
},
|
532
709
|
staging: {
|
533
710
|
main: "https://staging.xatabase.co",
|
534
|
-
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
711
|
+
workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
|
535
712
|
}
|
536
713
|
};
|
537
|
-
function
|
714
|
+
function isHostProviderAlias(alias) {
|
538
715
|
return isString(alias) && Object.keys(providers).includes(alias);
|
539
716
|
}
|
540
|
-
function
|
717
|
+
function isHostProviderBuilder(builder) {
|
541
718
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
542
719
|
}
|
720
|
+
function parseProviderString(provider = "production") {
|
721
|
+
if (isHostProviderAlias(provider)) {
|
722
|
+
return provider;
|
723
|
+
}
|
724
|
+
const [main, workspaces] = provider.split(",");
|
725
|
+
if (!main || !workspaces)
|
726
|
+
return null;
|
727
|
+
return { main, workspaces };
|
728
|
+
}
|
729
|
+
function parseWorkspacesUrlParts(url) {
|
730
|
+
if (!isString(url))
|
731
|
+
return null;
|
732
|
+
const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
|
733
|
+
const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
|
734
|
+
const match = url.match(regex) || url.match(regexStaging);
|
735
|
+
if (!match)
|
736
|
+
return null;
|
737
|
+
return { workspace: match[1], region: match[2] ?? "eu-west-1" };
|
738
|
+
}
|
543
739
|
|
544
740
|
var __accessCheck$7 = (obj, member, msg) => {
|
545
741
|
if (!member.has(obj))
|
@@ -565,7 +761,8 @@ class XataApiClient {
|
|
565
761
|
__privateAdd$7(this, _extraProps, void 0);
|
566
762
|
__privateAdd$7(this, _namespaces, {});
|
567
763
|
const provider = options.host ?? "production";
|
568
|
-
const apiKey = options
|
764
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
765
|
+
const trace = options.trace ?? defaultTrace;
|
569
766
|
if (!apiKey) {
|
570
767
|
throw new Error("Could not resolve a valid apiKey");
|
571
768
|
}
|
@@ -573,7 +770,8 @@ class XataApiClient {
|
|
573
770
|
apiUrl: getHostUrl(provider, "main"),
|
574
771
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
575
772
|
fetchImpl: getFetchImplementation(options.fetch),
|
576
|
-
apiKey
|
773
|
+
apiKey,
|
774
|
+
trace
|
577
775
|
});
|
578
776
|
}
|
579
777
|
get user() {
|
@@ -581,21 +779,41 @@ class XataApiClient {
|
|
581
779
|
__privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
|
582
780
|
return __privateGet$7(this, _namespaces).user;
|
583
781
|
}
|
782
|
+
get authentication() {
|
783
|
+
if (!__privateGet$7(this, _namespaces).authentication)
|
784
|
+
__privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
|
785
|
+
return __privateGet$7(this, _namespaces).authentication;
|
786
|
+
}
|
584
787
|
get workspaces() {
|
585
788
|
if (!__privateGet$7(this, _namespaces).workspaces)
|
586
789
|
__privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
|
587
790
|
return __privateGet$7(this, _namespaces).workspaces;
|
588
791
|
}
|
589
|
-
get
|
590
|
-
if (!__privateGet$7(this, _namespaces).
|
591
|
-
__privateGet$7(this, _namespaces).
|
592
|
-
return __privateGet$7(this, _namespaces).
|
792
|
+
get invites() {
|
793
|
+
if (!__privateGet$7(this, _namespaces).invites)
|
794
|
+
__privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
|
795
|
+
return __privateGet$7(this, _namespaces).invites;
|
796
|
+
}
|
797
|
+
get database() {
|
798
|
+
if (!__privateGet$7(this, _namespaces).database)
|
799
|
+
__privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
|
800
|
+
return __privateGet$7(this, _namespaces).database;
|
593
801
|
}
|
594
802
|
get branches() {
|
595
803
|
if (!__privateGet$7(this, _namespaces).branches)
|
596
804
|
__privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
|
597
805
|
return __privateGet$7(this, _namespaces).branches;
|
598
806
|
}
|
807
|
+
get migrations() {
|
808
|
+
if (!__privateGet$7(this, _namespaces).migrations)
|
809
|
+
__privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
|
810
|
+
return __privateGet$7(this, _namespaces).migrations;
|
811
|
+
}
|
812
|
+
get migrationRequests() {
|
813
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
814
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
815
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
816
|
+
}
|
599
817
|
get tables() {
|
600
818
|
if (!__privateGet$7(this, _namespaces).tables)
|
601
819
|
__privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
|
@@ -606,6 +824,11 @@ class XataApiClient {
|
|
606
824
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
607
825
|
return __privateGet$7(this, _namespaces).records;
|
608
826
|
}
|
827
|
+
get searchAndFilter() {
|
828
|
+
if (!__privateGet$7(this, _namespaces).searchAndFilter)
|
829
|
+
__privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
|
830
|
+
return __privateGet$7(this, _namespaces).searchAndFilter;
|
831
|
+
}
|
609
832
|
}
|
610
833
|
_extraProps = new WeakMap();
|
611
834
|
_namespaces = new WeakMap();
|
@@ -616,24 +839,29 @@ class UserApi {
|
|
616
839
|
getUser() {
|
617
840
|
return operationsByTag.users.getUser({ ...this.extraProps });
|
618
841
|
}
|
619
|
-
updateUser(user) {
|
842
|
+
updateUser({ user }) {
|
620
843
|
return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
|
621
844
|
}
|
622
845
|
deleteUser() {
|
623
846
|
return operationsByTag.users.deleteUser({ ...this.extraProps });
|
624
847
|
}
|
848
|
+
}
|
849
|
+
class AuthenticationApi {
|
850
|
+
constructor(extraProps) {
|
851
|
+
this.extraProps = extraProps;
|
852
|
+
}
|
625
853
|
getUserAPIKeys() {
|
626
|
-
return operationsByTag.
|
854
|
+
return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
|
627
855
|
}
|
628
|
-
createUserAPIKey(
|
629
|
-
return operationsByTag.
|
630
|
-
pathParams: { keyName },
|
856
|
+
createUserAPIKey({ name }) {
|
857
|
+
return operationsByTag.authentication.createUserAPIKey({
|
858
|
+
pathParams: { keyName: name },
|
631
859
|
...this.extraProps
|
632
860
|
});
|
633
861
|
}
|
634
|
-
deleteUserAPIKey(
|
635
|
-
return operationsByTag.
|
636
|
-
pathParams: { keyName },
|
862
|
+
deleteUserAPIKey({ name }) {
|
863
|
+
return operationsByTag.authentication.deleteUserAPIKey({
|
864
|
+
pathParams: { keyName: name },
|
637
865
|
...this.extraProps
|
638
866
|
});
|
639
867
|
}
|
@@ -642,359 +870,897 @@ class WorkspaceApi {
|
|
642
870
|
constructor(extraProps) {
|
643
871
|
this.extraProps = extraProps;
|
644
872
|
}
|
645
|
-
|
873
|
+
getWorkspacesList() {
|
874
|
+
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
875
|
+
}
|
876
|
+
createWorkspace({ data }) {
|
646
877
|
return operationsByTag.workspaces.createWorkspace({
|
647
|
-
body:
|
878
|
+
body: data,
|
648
879
|
...this.extraProps
|
649
880
|
});
|
650
881
|
}
|
651
|
-
|
652
|
-
return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
|
653
|
-
}
|
654
|
-
getWorkspace(workspaceId) {
|
882
|
+
getWorkspace({ workspace }) {
|
655
883
|
return operationsByTag.workspaces.getWorkspace({
|
656
|
-
pathParams: { workspaceId },
|
884
|
+
pathParams: { workspaceId: workspace },
|
657
885
|
...this.extraProps
|
658
886
|
});
|
659
887
|
}
|
660
|
-
updateWorkspace(
|
888
|
+
updateWorkspace({
|
889
|
+
workspace,
|
890
|
+
update
|
891
|
+
}) {
|
661
892
|
return operationsByTag.workspaces.updateWorkspace({
|
662
|
-
pathParams: { workspaceId },
|
663
|
-
body:
|
893
|
+
pathParams: { workspaceId: workspace },
|
894
|
+
body: update,
|
664
895
|
...this.extraProps
|
665
896
|
});
|
666
897
|
}
|
667
|
-
deleteWorkspace(
|
898
|
+
deleteWorkspace({ workspace }) {
|
668
899
|
return operationsByTag.workspaces.deleteWorkspace({
|
669
|
-
pathParams: { workspaceId },
|
900
|
+
pathParams: { workspaceId: workspace },
|
670
901
|
...this.extraProps
|
671
902
|
});
|
672
903
|
}
|
673
|
-
getWorkspaceMembersList(
|
904
|
+
getWorkspaceMembersList({ workspace }) {
|
674
905
|
return operationsByTag.workspaces.getWorkspaceMembersList({
|
675
|
-
pathParams: { workspaceId },
|
906
|
+
pathParams: { workspaceId: workspace },
|
676
907
|
...this.extraProps
|
677
908
|
});
|
678
909
|
}
|
679
|
-
updateWorkspaceMemberRole(
|
910
|
+
updateWorkspaceMemberRole({
|
911
|
+
workspace,
|
912
|
+
user,
|
913
|
+
role
|
914
|
+
}) {
|
680
915
|
return operationsByTag.workspaces.updateWorkspaceMemberRole({
|
681
|
-
pathParams: { workspaceId, userId },
|
916
|
+
pathParams: { workspaceId: workspace, userId: user },
|
682
917
|
body: { role },
|
683
918
|
...this.extraProps
|
684
919
|
});
|
685
920
|
}
|
686
|
-
removeWorkspaceMember(
|
921
|
+
removeWorkspaceMember({
|
922
|
+
workspace,
|
923
|
+
user
|
924
|
+
}) {
|
687
925
|
return operationsByTag.workspaces.removeWorkspaceMember({
|
688
|
-
pathParams: { workspaceId, userId },
|
926
|
+
pathParams: { workspaceId: workspace, userId: user },
|
689
927
|
...this.extraProps
|
690
928
|
});
|
691
929
|
}
|
692
|
-
|
693
|
-
|
694
|
-
|
930
|
+
}
|
931
|
+
class InvitesApi {
|
932
|
+
constructor(extraProps) {
|
933
|
+
this.extraProps = extraProps;
|
934
|
+
}
|
935
|
+
inviteWorkspaceMember({
|
936
|
+
workspace,
|
937
|
+
email,
|
938
|
+
role
|
939
|
+
}) {
|
940
|
+
return operationsByTag.invites.inviteWorkspaceMember({
|
941
|
+
pathParams: { workspaceId: workspace },
|
695
942
|
body: { email, role },
|
696
943
|
...this.extraProps
|
697
944
|
});
|
698
945
|
}
|
699
|
-
updateWorkspaceMemberInvite(
|
700
|
-
|
701
|
-
|
946
|
+
updateWorkspaceMemberInvite({
|
947
|
+
workspace,
|
948
|
+
invite,
|
949
|
+
role
|
950
|
+
}) {
|
951
|
+
return operationsByTag.invites.updateWorkspaceMemberInvite({
|
952
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
702
953
|
body: { role },
|
703
954
|
...this.extraProps
|
704
955
|
});
|
705
956
|
}
|
706
|
-
cancelWorkspaceMemberInvite(
|
707
|
-
|
708
|
-
|
957
|
+
cancelWorkspaceMemberInvite({
|
958
|
+
workspace,
|
959
|
+
invite
|
960
|
+
}) {
|
961
|
+
return operationsByTag.invites.cancelWorkspaceMemberInvite({
|
962
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
709
963
|
...this.extraProps
|
710
964
|
});
|
711
965
|
}
|
712
|
-
|
713
|
-
|
714
|
-
|
966
|
+
acceptWorkspaceMemberInvite({
|
967
|
+
workspace,
|
968
|
+
key
|
969
|
+
}) {
|
970
|
+
return operationsByTag.invites.acceptWorkspaceMemberInvite({
|
971
|
+
pathParams: { workspaceId: workspace, inviteKey: key },
|
972
|
+
...this.extraProps
|
973
|
+
});
|
974
|
+
}
|
975
|
+
resendWorkspaceMemberInvite({
|
976
|
+
workspace,
|
977
|
+
invite
|
978
|
+
}) {
|
979
|
+
return operationsByTag.invites.resendWorkspaceMemberInvite({
|
980
|
+
pathParams: { workspaceId: workspace, inviteId: invite },
|
981
|
+
...this.extraProps
|
982
|
+
});
|
983
|
+
}
|
984
|
+
}
|
985
|
+
class BranchApi {
|
986
|
+
constructor(extraProps) {
|
987
|
+
this.extraProps = extraProps;
|
988
|
+
}
|
989
|
+
getBranchList({
|
990
|
+
workspace,
|
991
|
+
region,
|
992
|
+
database
|
993
|
+
}) {
|
994
|
+
return operationsByTag.branch.getBranchList({
|
995
|
+
pathParams: { workspace, region, dbName: database },
|
996
|
+
...this.extraProps
|
997
|
+
});
|
998
|
+
}
|
999
|
+
getBranchDetails({
|
1000
|
+
workspace,
|
1001
|
+
region,
|
1002
|
+
database,
|
1003
|
+
branch
|
1004
|
+
}) {
|
1005
|
+
return operationsByTag.branch.getBranchDetails({
|
1006
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1007
|
+
...this.extraProps
|
1008
|
+
});
|
1009
|
+
}
|
1010
|
+
createBranch({
|
1011
|
+
workspace,
|
1012
|
+
region,
|
1013
|
+
database,
|
1014
|
+
branch,
|
1015
|
+
from,
|
1016
|
+
metadata
|
1017
|
+
}) {
|
1018
|
+
return operationsByTag.branch.createBranch({
|
1019
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1020
|
+
body: { from, metadata },
|
1021
|
+
...this.extraProps
|
1022
|
+
});
|
1023
|
+
}
|
1024
|
+
deleteBranch({
|
1025
|
+
workspace,
|
1026
|
+
region,
|
1027
|
+
database,
|
1028
|
+
branch
|
1029
|
+
}) {
|
1030
|
+
return operationsByTag.branch.deleteBranch({
|
1031
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1032
|
+
...this.extraProps
|
1033
|
+
});
|
1034
|
+
}
|
1035
|
+
updateBranchMetadata({
|
1036
|
+
workspace,
|
1037
|
+
region,
|
1038
|
+
database,
|
1039
|
+
branch,
|
1040
|
+
metadata
|
1041
|
+
}) {
|
1042
|
+
return operationsByTag.branch.updateBranchMetadata({
|
1043
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1044
|
+
body: metadata,
|
1045
|
+
...this.extraProps
|
1046
|
+
});
|
1047
|
+
}
|
1048
|
+
getBranchMetadata({
|
1049
|
+
workspace,
|
1050
|
+
region,
|
1051
|
+
database,
|
1052
|
+
branch
|
1053
|
+
}) {
|
1054
|
+
return operationsByTag.branch.getBranchMetadata({
|
1055
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1056
|
+
...this.extraProps
|
1057
|
+
});
|
1058
|
+
}
|
1059
|
+
getBranchStats({
|
1060
|
+
workspace,
|
1061
|
+
region,
|
1062
|
+
database,
|
1063
|
+
branch
|
1064
|
+
}) {
|
1065
|
+
return operationsByTag.branch.getBranchStats({
|
1066
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1067
|
+
...this.extraProps
|
1068
|
+
});
|
1069
|
+
}
|
1070
|
+
getGitBranchesMapping({
|
1071
|
+
workspace,
|
1072
|
+
region,
|
1073
|
+
database
|
1074
|
+
}) {
|
1075
|
+
return operationsByTag.branch.getGitBranchesMapping({
|
1076
|
+
pathParams: { workspace, region, dbName: database },
|
1077
|
+
...this.extraProps
|
1078
|
+
});
|
1079
|
+
}
|
1080
|
+
addGitBranchesEntry({
|
1081
|
+
workspace,
|
1082
|
+
region,
|
1083
|
+
database,
|
1084
|
+
gitBranch,
|
1085
|
+
xataBranch
|
1086
|
+
}) {
|
1087
|
+
return operationsByTag.branch.addGitBranchesEntry({
|
1088
|
+
pathParams: { workspace, region, dbName: database },
|
1089
|
+
body: { gitBranch, xataBranch },
|
1090
|
+
...this.extraProps
|
1091
|
+
});
|
1092
|
+
}
|
1093
|
+
removeGitBranchesEntry({
|
1094
|
+
workspace,
|
1095
|
+
region,
|
1096
|
+
database,
|
1097
|
+
gitBranch
|
1098
|
+
}) {
|
1099
|
+
return operationsByTag.branch.removeGitBranchesEntry({
|
1100
|
+
pathParams: { workspace, region, dbName: database },
|
1101
|
+
queryParams: { gitBranch },
|
1102
|
+
...this.extraProps
|
1103
|
+
});
|
1104
|
+
}
|
1105
|
+
resolveBranch({
|
1106
|
+
workspace,
|
1107
|
+
region,
|
1108
|
+
database,
|
1109
|
+
gitBranch,
|
1110
|
+
fallbackBranch
|
1111
|
+
}) {
|
1112
|
+
return operationsByTag.branch.resolveBranch({
|
1113
|
+
pathParams: { workspace, region, dbName: database },
|
1114
|
+
queryParams: { gitBranch, fallbackBranch },
|
1115
|
+
...this.extraProps
|
1116
|
+
});
|
1117
|
+
}
|
1118
|
+
}
|
1119
|
+
class TableApi {
|
1120
|
+
constructor(extraProps) {
|
1121
|
+
this.extraProps = extraProps;
|
1122
|
+
}
|
1123
|
+
createTable({
|
1124
|
+
workspace,
|
1125
|
+
region,
|
1126
|
+
database,
|
1127
|
+
branch,
|
1128
|
+
table
|
1129
|
+
}) {
|
1130
|
+
return operationsByTag.table.createTable({
|
1131
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1132
|
+
...this.extraProps
|
1133
|
+
});
|
1134
|
+
}
|
1135
|
+
deleteTable({
|
1136
|
+
workspace,
|
1137
|
+
region,
|
1138
|
+
database,
|
1139
|
+
branch,
|
1140
|
+
table
|
1141
|
+
}) {
|
1142
|
+
return operationsByTag.table.deleteTable({
|
1143
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1144
|
+
...this.extraProps
|
1145
|
+
});
|
1146
|
+
}
|
1147
|
+
updateTable({
|
1148
|
+
workspace,
|
1149
|
+
region,
|
1150
|
+
database,
|
1151
|
+
branch,
|
1152
|
+
table,
|
1153
|
+
update
|
1154
|
+
}) {
|
1155
|
+
return operationsByTag.table.updateTable({
|
1156
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1157
|
+
body: update,
|
1158
|
+
...this.extraProps
|
1159
|
+
});
|
1160
|
+
}
|
1161
|
+
getTableSchema({
|
1162
|
+
workspace,
|
1163
|
+
region,
|
1164
|
+
database,
|
1165
|
+
branch,
|
1166
|
+
table
|
1167
|
+
}) {
|
1168
|
+
return operationsByTag.table.getTableSchema({
|
1169
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1170
|
+
...this.extraProps
|
1171
|
+
});
|
1172
|
+
}
|
1173
|
+
setTableSchema({
|
1174
|
+
workspace,
|
1175
|
+
region,
|
1176
|
+
database,
|
1177
|
+
branch,
|
1178
|
+
table,
|
1179
|
+
schema
|
1180
|
+
}) {
|
1181
|
+
return operationsByTag.table.setTableSchema({
|
1182
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1183
|
+
body: schema,
|
1184
|
+
...this.extraProps
|
1185
|
+
});
|
1186
|
+
}
|
1187
|
+
getTableColumns({
|
1188
|
+
workspace,
|
1189
|
+
region,
|
1190
|
+
database,
|
1191
|
+
branch,
|
1192
|
+
table
|
1193
|
+
}) {
|
1194
|
+
return operationsByTag.table.getTableColumns({
|
1195
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1196
|
+
...this.extraProps
|
1197
|
+
});
|
1198
|
+
}
|
1199
|
+
addTableColumn({
|
1200
|
+
workspace,
|
1201
|
+
region,
|
1202
|
+
database,
|
1203
|
+
branch,
|
1204
|
+
table,
|
1205
|
+
column
|
1206
|
+
}) {
|
1207
|
+
return operationsByTag.table.addTableColumn({
|
1208
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1209
|
+
body: column,
|
1210
|
+
...this.extraProps
|
1211
|
+
});
|
1212
|
+
}
|
1213
|
+
getColumn({
|
1214
|
+
workspace,
|
1215
|
+
region,
|
1216
|
+
database,
|
1217
|
+
branch,
|
1218
|
+
table,
|
1219
|
+
column
|
1220
|
+
}) {
|
1221
|
+
return operationsByTag.table.getColumn({
|
1222
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1223
|
+
...this.extraProps
|
1224
|
+
});
|
1225
|
+
}
|
1226
|
+
updateColumn({
|
1227
|
+
workspace,
|
1228
|
+
region,
|
1229
|
+
database,
|
1230
|
+
branch,
|
1231
|
+
table,
|
1232
|
+
column,
|
1233
|
+
update
|
1234
|
+
}) {
|
1235
|
+
return operationsByTag.table.updateColumn({
|
1236
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
1237
|
+
body: update,
|
715
1238
|
...this.extraProps
|
716
1239
|
});
|
717
1240
|
}
|
718
|
-
|
719
|
-
|
720
|
-
|
1241
|
+
deleteColumn({
|
1242
|
+
workspace,
|
1243
|
+
region,
|
1244
|
+
database,
|
1245
|
+
branch,
|
1246
|
+
table,
|
1247
|
+
column
|
1248
|
+
}) {
|
1249
|
+
return operationsByTag.table.deleteColumn({
|
1250
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
|
721
1251
|
...this.extraProps
|
722
1252
|
});
|
723
1253
|
}
|
724
1254
|
}
|
725
|
-
class
|
1255
|
+
class RecordsApi {
|
726
1256
|
constructor(extraProps) {
|
727
1257
|
this.extraProps = extraProps;
|
728
1258
|
}
|
729
|
-
|
730
|
-
|
731
|
-
|
1259
|
+
insertRecord({
|
1260
|
+
workspace,
|
1261
|
+
region,
|
1262
|
+
database,
|
1263
|
+
branch,
|
1264
|
+
table,
|
1265
|
+
record,
|
1266
|
+
columns
|
1267
|
+
}) {
|
1268
|
+
return operationsByTag.records.insertRecord({
|
1269
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1270
|
+
queryParams: { columns },
|
1271
|
+
body: record,
|
732
1272
|
...this.extraProps
|
733
1273
|
});
|
734
1274
|
}
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
1275
|
+
getRecord({
|
1276
|
+
workspace,
|
1277
|
+
region,
|
1278
|
+
database,
|
1279
|
+
branch,
|
1280
|
+
table,
|
1281
|
+
id,
|
1282
|
+
columns
|
1283
|
+
}) {
|
1284
|
+
return operationsByTag.records.getRecord({
|
1285
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1286
|
+
queryParams: { columns },
|
739
1287
|
...this.extraProps
|
740
1288
|
});
|
741
1289
|
}
|
742
|
-
|
743
|
-
|
744
|
-
|
1290
|
+
insertRecordWithID({
|
1291
|
+
workspace,
|
1292
|
+
region,
|
1293
|
+
database,
|
1294
|
+
branch,
|
1295
|
+
table,
|
1296
|
+
id,
|
1297
|
+
record,
|
1298
|
+
columns,
|
1299
|
+
createOnly,
|
1300
|
+
ifVersion
|
1301
|
+
}) {
|
1302
|
+
return operationsByTag.records.insertRecordWithID({
|
1303
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1304
|
+
queryParams: { columns, createOnly, ifVersion },
|
1305
|
+
body: record,
|
745
1306
|
...this.extraProps
|
746
1307
|
});
|
747
1308
|
}
|
748
|
-
|
749
|
-
|
750
|
-
|
1309
|
+
updateRecordWithID({
|
1310
|
+
workspace,
|
1311
|
+
region,
|
1312
|
+
database,
|
1313
|
+
branch,
|
1314
|
+
table,
|
1315
|
+
id,
|
1316
|
+
record,
|
1317
|
+
columns,
|
1318
|
+
ifVersion
|
1319
|
+
}) {
|
1320
|
+
return operationsByTag.records.updateRecordWithID({
|
1321
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1322
|
+
queryParams: { columns, ifVersion },
|
1323
|
+
body: record,
|
751
1324
|
...this.extraProps
|
752
1325
|
});
|
753
1326
|
}
|
754
|
-
|
755
|
-
|
756
|
-
|
1327
|
+
upsertRecordWithID({
|
1328
|
+
workspace,
|
1329
|
+
region,
|
1330
|
+
database,
|
1331
|
+
branch,
|
1332
|
+
table,
|
1333
|
+
id,
|
1334
|
+
record,
|
1335
|
+
columns,
|
1336
|
+
ifVersion
|
1337
|
+
}) {
|
1338
|
+
return operationsByTag.records.upsertRecordWithID({
|
1339
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1340
|
+
queryParams: { columns, ifVersion },
|
1341
|
+
body: record,
|
757
1342
|
...this.extraProps
|
758
1343
|
});
|
759
1344
|
}
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
1345
|
+
deleteRecord({
|
1346
|
+
workspace,
|
1347
|
+
region,
|
1348
|
+
database,
|
1349
|
+
branch,
|
1350
|
+
table,
|
1351
|
+
id,
|
1352
|
+
columns
|
1353
|
+
}) {
|
1354
|
+
return operationsByTag.records.deleteRecord({
|
1355
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
|
1356
|
+
queryParams: { columns },
|
764
1357
|
...this.extraProps
|
765
1358
|
});
|
766
1359
|
}
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
1360
|
+
bulkInsertTableRecords({
|
1361
|
+
workspace,
|
1362
|
+
region,
|
1363
|
+
database,
|
1364
|
+
branch,
|
1365
|
+
table,
|
1366
|
+
records,
|
1367
|
+
columns
|
1368
|
+
}) {
|
1369
|
+
return operationsByTag.records.bulkInsertTableRecords({
|
1370
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1371
|
+
queryParams: { columns },
|
1372
|
+
body: { records },
|
771
1373
|
...this.extraProps
|
772
1374
|
});
|
773
1375
|
}
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
1376
|
+
branchTransaction({
|
1377
|
+
workspace,
|
1378
|
+
region,
|
1379
|
+
database,
|
1380
|
+
branch,
|
1381
|
+
operations
|
1382
|
+
}) {
|
1383
|
+
return operationsByTag.records.branchTransaction({
|
1384
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1385
|
+
body: { operations },
|
778
1386
|
...this.extraProps
|
779
1387
|
});
|
780
1388
|
}
|
781
1389
|
}
|
782
|
-
class
|
1390
|
+
class SearchAndFilterApi {
|
783
1391
|
constructor(extraProps) {
|
784
1392
|
this.extraProps = extraProps;
|
785
1393
|
}
|
786
|
-
|
787
|
-
|
788
|
-
|
1394
|
+
queryTable({
|
1395
|
+
workspace,
|
1396
|
+
region,
|
1397
|
+
database,
|
1398
|
+
branch,
|
1399
|
+
table,
|
1400
|
+
filter,
|
1401
|
+
sort,
|
1402
|
+
page,
|
1403
|
+
columns,
|
1404
|
+
consistency
|
1405
|
+
}) {
|
1406
|
+
return operationsByTag.searchAndFilter.queryTable({
|
1407
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1408
|
+
body: { filter, sort, page, columns, consistency },
|
789
1409
|
...this.extraProps
|
790
1410
|
});
|
791
1411
|
}
|
792
|
-
|
793
|
-
|
794
|
-
|
1412
|
+
searchTable({
|
1413
|
+
workspace,
|
1414
|
+
region,
|
1415
|
+
database,
|
1416
|
+
branch,
|
1417
|
+
table,
|
1418
|
+
query,
|
1419
|
+
fuzziness,
|
1420
|
+
target,
|
1421
|
+
prefix,
|
1422
|
+
filter,
|
1423
|
+
highlight,
|
1424
|
+
boosters
|
1425
|
+
}) {
|
1426
|
+
return operationsByTag.searchAndFilter.searchTable({
|
1427
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1428
|
+
body: { query, fuzziness, target, prefix, filter, highlight, boosters },
|
795
1429
|
...this.extraProps
|
796
1430
|
});
|
797
1431
|
}
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
1432
|
+
searchBranch({
|
1433
|
+
workspace,
|
1434
|
+
region,
|
1435
|
+
database,
|
1436
|
+
branch,
|
1437
|
+
tables,
|
1438
|
+
query,
|
1439
|
+
fuzziness,
|
1440
|
+
prefix,
|
1441
|
+
highlight
|
1442
|
+
}) {
|
1443
|
+
return operationsByTag.searchAndFilter.searchBranch({
|
1444
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1445
|
+
body: { tables, query, fuzziness, prefix, highlight },
|
803
1446
|
...this.extraProps
|
804
1447
|
});
|
805
1448
|
}
|
806
|
-
|
807
|
-
|
808
|
-
|
1449
|
+
summarizeTable({
|
1450
|
+
workspace,
|
1451
|
+
region,
|
1452
|
+
database,
|
1453
|
+
branch,
|
1454
|
+
table,
|
1455
|
+
filter,
|
1456
|
+
columns,
|
1457
|
+
summaries,
|
1458
|
+
sort,
|
1459
|
+
summariesFilter,
|
1460
|
+
page,
|
1461
|
+
consistency
|
1462
|
+
}) {
|
1463
|
+
return operationsByTag.searchAndFilter.summarizeTable({
|
1464
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1465
|
+
body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
|
809
1466
|
...this.extraProps
|
810
1467
|
});
|
811
1468
|
}
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
1469
|
+
aggregateTable({
|
1470
|
+
workspace,
|
1471
|
+
region,
|
1472
|
+
database,
|
1473
|
+
branch,
|
1474
|
+
table,
|
1475
|
+
filter,
|
1476
|
+
aggs
|
1477
|
+
}) {
|
1478
|
+
return operationsByTag.searchAndFilter.aggregateTable({
|
1479
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
|
1480
|
+
body: { filter, aggs },
|
816
1481
|
...this.extraProps
|
817
1482
|
});
|
818
1483
|
}
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
});
|
1484
|
+
}
|
1485
|
+
class MigrationRequestsApi {
|
1486
|
+
constructor(extraProps) {
|
1487
|
+
this.extraProps = extraProps;
|
824
1488
|
}
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
1489
|
+
queryMigrationRequests({
|
1490
|
+
workspace,
|
1491
|
+
region,
|
1492
|
+
database,
|
1493
|
+
filter,
|
1494
|
+
sort,
|
1495
|
+
page,
|
1496
|
+
columns
|
1497
|
+
}) {
|
1498
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
1499
|
+
pathParams: { workspace, region, dbName: database },
|
1500
|
+
body: { filter, sort, page, columns },
|
829
1501
|
...this.extraProps
|
830
1502
|
});
|
831
1503
|
}
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
1504
|
+
createMigrationRequest({
|
1505
|
+
workspace,
|
1506
|
+
region,
|
1507
|
+
database,
|
1508
|
+
migration
|
1509
|
+
}) {
|
1510
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1511
|
+
pathParams: { workspace, region, dbName: database },
|
1512
|
+
body: migration,
|
836
1513
|
...this.extraProps
|
837
1514
|
});
|
838
1515
|
}
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
1516
|
+
getMigrationRequest({
|
1517
|
+
workspace,
|
1518
|
+
region,
|
1519
|
+
database,
|
1520
|
+
migrationRequest
|
1521
|
+
}) {
|
1522
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1523
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
843
1524
|
...this.extraProps
|
844
1525
|
});
|
845
1526
|
}
|
846
|
-
|
847
|
-
|
848
|
-
|
1527
|
+
updateMigrationRequest({
|
1528
|
+
workspace,
|
1529
|
+
region,
|
1530
|
+
database,
|
1531
|
+
migrationRequest,
|
1532
|
+
update
|
1533
|
+
}) {
|
1534
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1535
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1536
|
+
body: update,
|
849
1537
|
...this.extraProps
|
850
1538
|
});
|
851
1539
|
}
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
1540
|
+
listMigrationRequestsCommits({
|
1541
|
+
workspace,
|
1542
|
+
region,
|
1543
|
+
database,
|
1544
|
+
migrationRequest,
|
1545
|
+
page
|
1546
|
+
}) {
|
1547
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1548
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
1549
|
+
body: { page },
|
860
1550
|
...this.extraProps
|
861
1551
|
});
|
862
1552
|
}
|
863
|
-
|
864
|
-
|
865
|
-
|
1553
|
+
compareMigrationRequest({
|
1554
|
+
workspace,
|
1555
|
+
region,
|
1556
|
+
database,
|
1557
|
+
migrationRequest
|
1558
|
+
}) {
|
1559
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1560
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
866
1561
|
...this.extraProps
|
867
1562
|
});
|
868
1563
|
}
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
1564
|
+
getMigrationRequestIsMerged({
|
1565
|
+
workspace,
|
1566
|
+
region,
|
1567
|
+
database,
|
1568
|
+
migrationRequest
|
1569
|
+
}) {
|
1570
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1571
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
873
1572
|
...this.extraProps
|
874
1573
|
});
|
875
1574
|
}
|
876
|
-
|
877
|
-
|
878
|
-
|
1575
|
+
mergeMigrationRequest({
|
1576
|
+
workspace,
|
1577
|
+
region,
|
1578
|
+
database,
|
1579
|
+
migrationRequest
|
1580
|
+
}) {
|
1581
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1582
|
+
pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
|
879
1583
|
...this.extraProps
|
880
1584
|
});
|
881
1585
|
}
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
...this.extraProps
|
887
|
-
});
|
1586
|
+
}
|
1587
|
+
class MigrationsApi {
|
1588
|
+
constructor(extraProps) {
|
1589
|
+
this.extraProps = extraProps;
|
888
1590
|
}
|
889
|
-
|
890
|
-
|
891
|
-
|
1591
|
+
getBranchMigrationHistory({
|
1592
|
+
workspace,
|
1593
|
+
region,
|
1594
|
+
database,
|
1595
|
+
branch,
|
1596
|
+
limit,
|
1597
|
+
startFrom
|
1598
|
+
}) {
|
1599
|
+
return operationsByTag.migrations.getBranchMigrationHistory({
|
1600
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1601
|
+
body: { limit, startFrom },
|
892
1602
|
...this.extraProps
|
893
1603
|
});
|
894
1604
|
}
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
1605
|
+
getBranchMigrationPlan({
|
1606
|
+
workspace,
|
1607
|
+
region,
|
1608
|
+
database,
|
1609
|
+
branch,
|
1610
|
+
schema
|
1611
|
+
}) {
|
1612
|
+
return operationsByTag.migrations.getBranchMigrationPlan({
|
1613
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1614
|
+
body: schema,
|
899
1615
|
...this.extraProps
|
900
1616
|
});
|
901
1617
|
}
|
902
|
-
|
903
|
-
|
904
|
-
|
1618
|
+
executeBranchMigrationPlan({
|
1619
|
+
workspace,
|
1620
|
+
region,
|
1621
|
+
database,
|
1622
|
+
branch,
|
1623
|
+
plan
|
1624
|
+
}) {
|
1625
|
+
return operationsByTag.migrations.executeBranchMigrationPlan({
|
1626
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1627
|
+
body: plan,
|
905
1628
|
...this.extraProps
|
906
1629
|
});
|
907
1630
|
}
|
908
|
-
|
909
|
-
|
910
|
-
|
1631
|
+
getBranchSchemaHistory({
|
1632
|
+
workspace,
|
1633
|
+
region,
|
1634
|
+
database,
|
1635
|
+
branch,
|
1636
|
+
page
|
1637
|
+
}) {
|
1638
|
+
return operationsByTag.migrations.getBranchSchemaHistory({
|
1639
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1640
|
+
body: { page },
|
911
1641
|
...this.extraProps
|
912
1642
|
});
|
913
1643
|
}
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
1644
|
+
compareBranchWithUserSchema({
|
1645
|
+
workspace,
|
1646
|
+
region,
|
1647
|
+
database,
|
1648
|
+
branch,
|
1649
|
+
schema
|
1650
|
+
}) {
|
1651
|
+
return operationsByTag.migrations.compareBranchWithUserSchema({
|
1652
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1653
|
+
body: { schema },
|
918
1654
|
...this.extraProps
|
919
1655
|
});
|
920
1656
|
}
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
1657
|
+
compareBranchSchemas({
|
1658
|
+
workspace,
|
1659
|
+
region,
|
1660
|
+
database,
|
1661
|
+
branch,
|
1662
|
+
compare,
|
1663
|
+
schema
|
1664
|
+
}) {
|
1665
|
+
return operationsByTag.migrations.compareBranchSchemas({
|
1666
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
|
1667
|
+
body: { schema },
|
931
1668
|
...this.extraProps
|
932
1669
|
});
|
933
1670
|
}
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
1671
|
+
updateBranchSchema({
|
1672
|
+
workspace,
|
1673
|
+
region,
|
1674
|
+
database,
|
1675
|
+
branch,
|
1676
|
+
migration
|
1677
|
+
}) {
|
1678
|
+
return operationsByTag.migrations.updateBranchSchema({
|
1679
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1680
|
+
body: migration,
|
939
1681
|
...this.extraProps
|
940
1682
|
});
|
941
1683
|
}
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
1684
|
+
previewBranchSchemaEdit({
|
1685
|
+
workspace,
|
1686
|
+
region,
|
1687
|
+
database,
|
1688
|
+
branch,
|
1689
|
+
data
|
1690
|
+
}) {
|
1691
|
+
return operationsByTag.migrations.previewBranchSchemaEdit({
|
1692
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1693
|
+
body: data,
|
947
1694
|
...this.extraProps
|
948
1695
|
});
|
949
1696
|
}
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
1697
|
+
applyBranchSchemaEdit({
|
1698
|
+
workspace,
|
1699
|
+
region,
|
1700
|
+
database,
|
1701
|
+
branch,
|
1702
|
+
edits
|
1703
|
+
}) {
|
1704
|
+
return operationsByTag.migrations.applyBranchSchemaEdit({
|
1705
|
+
pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
|
1706
|
+
body: { edits },
|
955
1707
|
...this.extraProps
|
956
1708
|
});
|
957
1709
|
}
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
1710
|
+
}
|
1711
|
+
class DatabaseApi {
|
1712
|
+
constructor(extraProps) {
|
1713
|
+
this.extraProps = extraProps;
|
1714
|
+
}
|
1715
|
+
getDatabaseList({ workspace }) {
|
1716
|
+
return operationsByTag.databases.getDatabaseList({
|
1717
|
+
pathParams: { workspaceId: workspace },
|
962
1718
|
...this.extraProps
|
963
1719
|
});
|
964
1720
|
}
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
1721
|
+
createDatabase({
|
1722
|
+
workspace,
|
1723
|
+
database,
|
1724
|
+
data
|
1725
|
+
}) {
|
1726
|
+
return operationsByTag.databases.createDatabase({
|
1727
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1728
|
+
body: data,
|
969
1729
|
...this.extraProps
|
970
1730
|
});
|
971
1731
|
}
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
1732
|
+
deleteDatabase({
|
1733
|
+
workspace,
|
1734
|
+
database
|
1735
|
+
}) {
|
1736
|
+
return operationsByTag.databases.deleteDatabase({
|
1737
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
977
1738
|
...this.extraProps
|
978
1739
|
});
|
979
1740
|
}
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
1741
|
+
getDatabaseMetadata({
|
1742
|
+
workspace,
|
1743
|
+
database
|
1744
|
+
}) {
|
1745
|
+
return operationsByTag.databases.getDatabaseMetadata({
|
1746
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
984
1747
|
...this.extraProps
|
985
1748
|
});
|
986
1749
|
}
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
1750
|
+
updateDatabaseMetadata({
|
1751
|
+
workspace,
|
1752
|
+
database,
|
1753
|
+
metadata
|
1754
|
+
}) {
|
1755
|
+
return operationsByTag.databases.updateDatabaseMetadata({
|
1756
|
+
pathParams: { workspaceId: workspace, dbName: database },
|
1757
|
+
body: metadata,
|
991
1758
|
...this.extraProps
|
992
1759
|
});
|
993
1760
|
}
|
994
|
-
|
995
|
-
return operationsByTag.
|
996
|
-
pathParams: {
|
997
|
-
body: query,
|
1761
|
+
listRegions({ workspace }) {
|
1762
|
+
return operationsByTag.databases.listRegions({
|
1763
|
+
pathParams: { workspaceId: workspace },
|
998
1764
|
...this.extraProps
|
999
1765
|
});
|
1000
1766
|
}
|
@@ -1010,6 +1776,20 @@ class XataApiPlugin {
|
|
1010
1776
|
class XataPlugin {
|
1011
1777
|
}
|
1012
1778
|
|
1779
|
+
function generateUUID() {
|
1780
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
1781
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
1782
|
+
return v.toString(16);
|
1783
|
+
});
|
1784
|
+
}
|
1785
|
+
|
1786
|
+
function cleanFilter(filter) {
|
1787
|
+
if (!filter)
|
1788
|
+
return void 0;
|
1789
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
1790
|
+
return values.length > 0 ? filter : void 0;
|
1791
|
+
}
|
1792
|
+
|
1013
1793
|
var __accessCheck$6 = (obj, member, msg) => {
|
1014
1794
|
if (!member.has(obj))
|
1015
1795
|
throw TypeError("Cannot " + msg);
|
@@ -1042,11 +1822,11 @@ class Page {
|
|
1042
1822
|
async previousPage(size, offset) {
|
1043
1823
|
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
|
1044
1824
|
}
|
1045
|
-
async
|
1046
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
1825
|
+
async startPage(size, offset) {
|
1826
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
|
1047
1827
|
}
|
1048
|
-
async
|
1049
|
-
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset,
|
1828
|
+
async endPage(size, offset) {
|
1829
|
+
return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
|
1050
1830
|
}
|
1051
1831
|
hasNextPage() {
|
1052
1832
|
return this.meta.page.more;
|
@@ -1058,7 +1838,7 @@ const PAGINATION_DEFAULT_SIZE = 20;
|
|
1058
1838
|
const PAGINATION_MAX_OFFSET = 800;
|
1059
1839
|
const PAGINATION_DEFAULT_OFFSET = 0;
|
1060
1840
|
function isCursorPaginationOptions(options) {
|
1061
|
-
return isDefined(options) && (isDefined(options.
|
1841
|
+
return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
|
1062
1842
|
}
|
1063
1843
|
const _RecordArray = class extends Array {
|
1064
1844
|
constructor(...args) {
|
@@ -1090,12 +1870,12 @@ const _RecordArray = class extends Array {
|
|
1090
1870
|
const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
|
1091
1871
|
return new _RecordArray(newPage);
|
1092
1872
|
}
|
1093
|
-
async
|
1094
|
-
const newPage = await __privateGet$6(this, _page).
|
1873
|
+
async startPage(size, offset) {
|
1874
|
+
const newPage = await __privateGet$6(this, _page).startPage(size, offset);
|
1095
1875
|
return new _RecordArray(newPage);
|
1096
1876
|
}
|
1097
|
-
async
|
1098
|
-
const newPage = await __privateGet$6(this, _page).
|
1877
|
+
async endPage(size, offset) {
|
1878
|
+
const newPage = await __privateGet$6(this, _page).endPage(size, offset);
|
1099
1879
|
return new _RecordArray(newPage);
|
1100
1880
|
}
|
1101
1881
|
hasNextPage() {
|
@@ -1123,9 +1903,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1123
1903
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1124
1904
|
return value;
|
1125
1905
|
};
|
1126
|
-
var
|
1906
|
+
var __privateMethod$3 = (obj, member, method) => {
|
1907
|
+
__accessCheck$5(obj, member, "access private method");
|
1908
|
+
return method;
|
1909
|
+
};
|
1910
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1127
1911
|
const _Query = class {
|
1128
1912
|
constructor(repository, table, data, rawParent) {
|
1913
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1129
1914
|
__privateAdd$5(this, _table$1, void 0);
|
1130
1915
|
__privateAdd$5(this, _repository, void 0);
|
1131
1916
|
__privateAdd$5(this, _data, { filter: {} });
|
@@ -1144,9 +1929,10 @@ const _Query = class {
|
|
1144
1929
|
__privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
|
1145
1930
|
__privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
|
1146
1931
|
__privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
|
1147
|
-
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns
|
1932
|
+
__privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
|
1148
1933
|
__privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
|
1149
1934
|
__privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
|
1935
|
+
__privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
|
1150
1936
|
this.any = this.any.bind(this);
|
1151
1937
|
this.all = this.all.bind(this);
|
1152
1938
|
this.not = this.not.bind(this);
|
@@ -1182,11 +1968,14 @@ const _Query = class {
|
|
1182
1968
|
}
|
1183
1969
|
filter(a, b) {
|
1184
1970
|
if (arguments.length === 1) {
|
1185
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
1971
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
1972
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
1973
|
+
}));
|
1186
1974
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1187
1975
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1188
1976
|
} else {
|
1189
|
-
const
|
1977
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
1978
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1190
1979
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1191
1980
|
}
|
1192
1981
|
}
|
@@ -1224,11 +2013,20 @@ const _Query = class {
|
|
1224
2013
|
}
|
1225
2014
|
}
|
1226
2015
|
async getMany(options = {}) {
|
1227
|
-
const
|
2016
|
+
const { pagination = {}, ...rest } = options;
|
2017
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
2018
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
2019
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
2020
|
+
const results = [...page.records];
|
2021
|
+
while (page.hasNextPage() && results.length < size) {
|
2022
|
+
page = await page.nextPage();
|
2023
|
+
results.push(...page.records);
|
2024
|
+
}
|
1228
2025
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1229
2026
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1230
2027
|
}
|
1231
|
-
|
2028
|
+
const array = new RecordArray(page, results.slice(0, size));
|
2029
|
+
return array;
|
1232
2030
|
}
|
1233
2031
|
async getAll(options = {}) {
|
1234
2032
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1242,19 +2040,35 @@ const _Query = class {
|
|
1242
2040
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1243
2041
|
return records[0] ?? null;
|
1244
2042
|
}
|
2043
|
+
async getFirstOrThrow(options = {}) {
|
2044
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
2045
|
+
if (records[0] === void 0)
|
2046
|
+
throw new Error("No results found.");
|
2047
|
+
return records[0];
|
2048
|
+
}
|
2049
|
+
async summarize(params = {}) {
|
2050
|
+
const { summaries, summariesFilter, ...options } = params;
|
2051
|
+
const query = new _Query(
|
2052
|
+
__privateGet$5(this, _repository),
|
2053
|
+
__privateGet$5(this, _table$1),
|
2054
|
+
options,
|
2055
|
+
__privateGet$5(this, _data)
|
2056
|
+
);
|
2057
|
+
return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
|
2058
|
+
}
|
1245
2059
|
cache(ttl) {
|
1246
2060
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1247
2061
|
}
|
1248
2062
|
nextPage(size, offset) {
|
1249
|
-
return this.
|
2063
|
+
return this.startPage(size, offset);
|
1250
2064
|
}
|
1251
2065
|
previousPage(size, offset) {
|
1252
|
-
return this.
|
2066
|
+
return this.startPage(size, offset);
|
1253
2067
|
}
|
1254
|
-
|
2068
|
+
startPage(size, offset) {
|
1255
2069
|
return this.getPaginated({ pagination: { size, offset } });
|
1256
2070
|
}
|
1257
|
-
|
2071
|
+
endPage(size, offset) {
|
1258
2072
|
return this.getPaginated({ pagination: { size, offset, before: "end" } });
|
1259
2073
|
}
|
1260
2074
|
hasNextPage() {
|
@@ -1265,9 +2079,20 @@ let Query = _Query;
|
|
1265
2079
|
_table$1 = new WeakMap();
|
1266
2080
|
_repository = new WeakMap();
|
1267
2081
|
_data = new WeakMap();
|
2082
|
+
_cleanFilterConstraint = new WeakSet();
|
2083
|
+
cleanFilterConstraint_fn = function(column, value) {
|
2084
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
2085
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
2086
|
+
return { $includes: value };
|
2087
|
+
}
|
2088
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
2089
|
+
return value.id;
|
2090
|
+
}
|
2091
|
+
return value;
|
2092
|
+
};
|
1268
2093
|
function cleanParent(data, parent) {
|
1269
2094
|
if (isCursorPaginationOptions(data.pagination)) {
|
1270
|
-
return { ...parent,
|
2095
|
+
return { ...parent, sort: void 0, filter: void 0 };
|
1271
2096
|
}
|
1272
2097
|
return parent;
|
1273
2098
|
}
|
@@ -1326,18 +2151,25 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
1326
2151
|
__accessCheck$4(obj, member, "access private method");
|
1327
2152
|
return method;
|
1328
2153
|
};
|
1329
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn,
|
2154
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
2155
|
+
const BULK_OPERATION_MAX_SIZE = 1e3;
|
1330
2156
|
class Repository extends Query {
|
1331
2157
|
}
|
1332
2158
|
class RestRepository extends Query {
|
1333
2159
|
constructor(options) {
|
1334
|
-
super(
|
2160
|
+
super(
|
2161
|
+
null,
|
2162
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
2163
|
+
{}
|
2164
|
+
);
|
1335
2165
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1336
2166
|
__privateAdd$4(this, _insertRecordWithId);
|
1337
|
-
__privateAdd$4(this,
|
2167
|
+
__privateAdd$4(this, _insertRecords);
|
1338
2168
|
__privateAdd$4(this, _updateRecordWithID);
|
2169
|
+
__privateAdd$4(this, _updateRecords);
|
1339
2170
|
__privateAdd$4(this, _upsertRecordWithID);
|
1340
2171
|
__privateAdd$4(this, _deleteRecord);
|
2172
|
+
__privateAdd$4(this, _deleteRecords);
|
1341
2173
|
__privateAdd$4(this, _setCacheQuery);
|
1342
2174
|
__privateAdd$4(this, _getCacheQuery);
|
1343
2175
|
__privateAdd$4(this, _getSchemaTables$1);
|
@@ -1346,168 +2178,346 @@ class RestRepository extends Query {
|
|
1346
2178
|
__privateAdd$4(this, _db, void 0);
|
1347
2179
|
__privateAdd$4(this, _cache, void 0);
|
1348
2180
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
2181
|
+
__privateAdd$4(this, _trace, void 0);
|
1349
2182
|
__privateSet$4(this, _table, options.table);
|
1350
|
-
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
1351
2183
|
__privateSet$4(this, _db, options.db);
|
1352
2184
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
1353
2185
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
2186
|
+
__privateSet$4(this, _getFetchProps, async () => {
|
2187
|
+
const props = await options.pluginOptions.getFetchProps();
|
2188
|
+
return { ...props, sessionID: generateUUID() };
|
2189
|
+
});
|
2190
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
2191
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
2192
|
+
return trace(name, fn, {
|
2193
|
+
...options2,
|
2194
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
2195
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
2196
|
+
[TraceAttributes.VERSION]: VERSION
|
2197
|
+
});
|
2198
|
+
});
|
1354
2199
|
}
|
1355
|
-
async create(a, b, c) {
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
2200
|
+
async create(a, b, c, d) {
|
2201
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
2202
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2203
|
+
if (Array.isArray(a)) {
|
2204
|
+
if (a.length === 0)
|
2205
|
+
return [];
|
2206
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
|
2207
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2208
|
+
const result = await this.read(ids, columns);
|
2209
|
+
return result;
|
2210
|
+
}
|
2211
|
+
if (isString(a) && isObject(b)) {
|
2212
|
+
if (a === "")
|
2213
|
+
throw new Error("The id can't be empty");
|
2214
|
+
const columns = isStringArray(c) ? c : void 0;
|
2215
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
|
2216
|
+
}
|
2217
|
+
if (isObject(a) && isString(a.id)) {
|
2218
|
+
if (a.id === "")
|
2219
|
+
throw new Error("The id can't be empty");
|
2220
|
+
const columns = isStringArray(b) ? b : void 0;
|
2221
|
+
return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
|
2222
|
+
}
|
2223
|
+
if (isObject(a)) {
|
2224
|
+
const columns = isStringArray(b) ? b : void 0;
|
2225
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
2226
|
+
}
|
2227
|
+
throw new Error("Invalid arguments for create method");
|
2228
|
+
});
|
1379
2229
|
}
|
1380
2230
|
async read(a, b) {
|
1381
|
-
|
1382
|
-
|
1383
|
-
if (a
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
acc
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
2231
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
2232
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2233
|
+
if (Array.isArray(a)) {
|
2234
|
+
if (a.length === 0)
|
2235
|
+
return [];
|
2236
|
+
const ids = a.map((item) => extractId(item));
|
2237
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
2238
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
2239
|
+
acc[object.id] = object;
|
2240
|
+
return acc;
|
2241
|
+
}, {});
|
2242
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
2243
|
+
}
|
2244
|
+
const id = extractId(a);
|
2245
|
+
if (id) {
|
2246
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2247
|
+
try {
|
2248
|
+
const response = await getRecord({
|
2249
|
+
pathParams: {
|
2250
|
+
workspace: "{workspaceId}",
|
2251
|
+
dbBranchName: "{dbBranch}",
|
2252
|
+
region: "{region}",
|
2253
|
+
tableName: __privateGet$4(this, _table),
|
2254
|
+
recordId: id
|
2255
|
+
},
|
2256
|
+
queryParams: { columns },
|
2257
|
+
...fetchProps
|
2258
|
+
});
|
2259
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2260
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2261
|
+
} catch (e) {
|
2262
|
+
if (isObject(e) && e.status === 404) {
|
2263
|
+
return null;
|
2264
|
+
}
|
2265
|
+
throw e;
|
2266
|
+
}
|
2267
|
+
}
|
2268
|
+
return null;
|
2269
|
+
});
|
2270
|
+
}
|
2271
|
+
async readOrThrow(a, b) {
|
2272
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
2273
|
+
const result = await this.read(a, b);
|
2274
|
+
if (Array.isArray(result)) {
|
2275
|
+
const missingIds = compact(
|
2276
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2277
|
+
);
|
2278
|
+
if (missingIds.length > 0) {
|
2279
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2280
|
+
}
|
2281
|
+
return result;
|
2282
|
+
}
|
2283
|
+
if (result === null) {
|
2284
|
+
const id = extractId(a) ?? "unknown";
|
2285
|
+
throw new Error(`Record with id ${id} not found`);
|
2286
|
+
}
|
2287
|
+
return result;
|
2288
|
+
});
|
2289
|
+
}
|
2290
|
+
async update(a, b, c, d) {
|
2291
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
2292
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2293
|
+
if (Array.isArray(a)) {
|
2294
|
+
if (a.length === 0)
|
2295
|
+
return [];
|
2296
|
+
const existing = await this.read(a, ["id"]);
|
2297
|
+
const updates = a.filter((_item, index) => existing[index] !== null);
|
2298
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
|
2299
|
+
ifVersion,
|
2300
|
+
upsert: false
|
1401
2301
|
});
|
1402
|
-
const
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
2302
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2303
|
+
const result = await this.read(a, columns);
|
2304
|
+
return result;
|
2305
|
+
}
|
2306
|
+
if (isString(a) && isObject(b)) {
|
2307
|
+
const columns = isStringArray(c) ? c : void 0;
|
2308
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
2309
|
+
}
|
2310
|
+
if (isObject(a) && isString(a.id)) {
|
2311
|
+
const columns = isStringArray(b) ? b : void 0;
|
2312
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
2313
|
+
}
|
2314
|
+
throw new Error("Invalid arguments for update method");
|
2315
|
+
});
|
2316
|
+
}
|
2317
|
+
async updateOrThrow(a, b, c, d) {
|
2318
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
2319
|
+
const result = await this.update(a, b, c, d);
|
2320
|
+
if (Array.isArray(result)) {
|
2321
|
+
const missingIds = compact(
|
2322
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2323
|
+
);
|
2324
|
+
if (missingIds.length > 0) {
|
2325
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1407
2326
|
}
|
1408
|
-
|
2327
|
+
return result;
|
1409
2328
|
}
|
1410
|
-
|
1411
|
-
|
2329
|
+
if (result === null) {
|
2330
|
+
const id = extractId(a) ?? "unknown";
|
2331
|
+
throw new Error(`Record with id ${id} not found`);
|
2332
|
+
}
|
2333
|
+
return result;
|
2334
|
+
});
|
1412
2335
|
}
|
1413
|
-
async
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
2336
|
+
async createOrUpdate(a, b, c, d) {
|
2337
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
2338
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2339
|
+
if (Array.isArray(a)) {
|
2340
|
+
if (a.length === 0)
|
2341
|
+
return [];
|
2342
|
+
await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
|
2343
|
+
ifVersion,
|
2344
|
+
upsert: true
|
2345
|
+
});
|
2346
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2347
|
+
const result = await this.read(a, columns);
|
2348
|
+
return result;
|
1419
2349
|
}
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
if (isString(a) && isObject(b)) {
|
1424
|
-
const columns = isStringArray(c) ? c : void 0;
|
1425
|
-
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
1426
|
-
}
|
1427
|
-
if (isObject(a) && isString(a.id)) {
|
1428
|
-
const columns = isStringArray(b) ? b : void 0;
|
1429
|
-
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1430
|
-
}
|
1431
|
-
throw new Error("Invalid arguments for update method");
|
1432
|
-
}
|
1433
|
-
async createOrUpdate(a, b, c) {
|
1434
|
-
if (Array.isArray(a)) {
|
1435
|
-
if (a.length === 0)
|
1436
|
-
return [];
|
1437
|
-
if (a.length > 100) {
|
1438
|
-
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
2350
|
+
if (isString(a) && isObject(b)) {
|
2351
|
+
const columns = isStringArray(c) ? c : void 0;
|
2352
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
|
1439
2353
|
}
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
if (isString(a) && isObject(b)) {
|
1444
|
-
const columns = isStringArray(c) ? c : void 0;
|
1445
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
1446
|
-
}
|
1447
|
-
if (isObject(a) && isString(a.id)) {
|
1448
|
-
const columns = isStringArray(c) ? c : void 0;
|
1449
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
1450
|
-
}
|
1451
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
1452
|
-
}
|
1453
|
-
async delete(a) {
|
1454
|
-
if (Array.isArray(a)) {
|
1455
|
-
if (a.length === 0)
|
1456
|
-
return;
|
1457
|
-
if (a.length > 100) {
|
1458
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
2354
|
+
if (isObject(a) && isString(a.id)) {
|
2355
|
+
const columns = isStringArray(c) ? c : void 0;
|
2356
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
|
1459
2357
|
}
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
2358
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
2359
|
+
});
|
2360
|
+
}
|
2361
|
+
async createOrReplace(a, b, c, d) {
|
2362
|
+
return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
|
2363
|
+
const ifVersion = parseIfVersion(b, c, d);
|
2364
|
+
if (Array.isArray(a)) {
|
2365
|
+
if (a.length === 0)
|
2366
|
+
return [];
|
2367
|
+
const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
|
2368
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2369
|
+
const result = await this.read(ids, columns);
|
2370
|
+
return result;
|
2371
|
+
}
|
2372
|
+
if (isString(a) && isObject(b)) {
|
2373
|
+
const columns = isStringArray(c) ? c : void 0;
|
2374
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
|
2375
|
+
}
|
2376
|
+
if (isObject(a) && isString(a.id)) {
|
2377
|
+
const columns = isStringArray(c) ? c : void 0;
|
2378
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
|
2379
|
+
}
|
2380
|
+
throw new Error("Invalid arguments for createOrReplace method");
|
2381
|
+
});
|
2382
|
+
}
|
2383
|
+
async delete(a, b) {
|
2384
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
2385
|
+
if (Array.isArray(a)) {
|
2386
|
+
if (a.length === 0)
|
2387
|
+
return [];
|
2388
|
+
const ids = a.map((o) => {
|
2389
|
+
if (isString(o))
|
2390
|
+
return o;
|
2391
|
+
if (isString(o.id))
|
2392
|
+
return o.id;
|
2393
|
+
throw new Error("Invalid arguments for delete method");
|
2394
|
+
});
|
2395
|
+
const columns = isStringArray(b) ? b : ["*"];
|
2396
|
+
const result = await this.read(a, columns);
|
2397
|
+
await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
|
2398
|
+
return result;
|
2399
|
+
}
|
2400
|
+
if (isString(a)) {
|
2401
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
2402
|
+
}
|
2403
|
+
if (isObject(a) && isString(a.id)) {
|
2404
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
2405
|
+
}
|
2406
|
+
throw new Error("Invalid arguments for delete method");
|
2407
|
+
});
|
2408
|
+
}
|
2409
|
+
async deleteOrThrow(a, b) {
|
2410
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
2411
|
+
const result = await this.delete(a, b);
|
2412
|
+
if (Array.isArray(result)) {
|
2413
|
+
const missingIds = compact(
|
2414
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
2415
|
+
);
|
2416
|
+
if (missingIds.length > 0) {
|
2417
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
2418
|
+
}
|
2419
|
+
return result;
|
2420
|
+
} else if (result === null) {
|
2421
|
+
const id = extractId(a) ?? "unknown";
|
2422
|
+
throw new Error(`Record with id ${id} not found`);
|
2423
|
+
}
|
2424
|
+
return result;
|
2425
|
+
});
|
1472
2426
|
}
|
1473
2427
|
async search(query, options = {}) {
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
2428
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
2429
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2430
|
+
const { records } = await searchTable({
|
2431
|
+
pathParams: {
|
2432
|
+
workspace: "{workspaceId}",
|
2433
|
+
dbBranchName: "{dbBranch}",
|
2434
|
+
region: "{region}",
|
2435
|
+
tableName: __privateGet$4(this, _table)
|
2436
|
+
},
|
2437
|
+
body: {
|
2438
|
+
query,
|
2439
|
+
fuzziness: options.fuzziness,
|
2440
|
+
prefix: options.prefix,
|
2441
|
+
highlight: options.highlight,
|
2442
|
+
filter: options.filter,
|
2443
|
+
boosters: options.boosters
|
2444
|
+
},
|
2445
|
+
...fetchProps
|
2446
|
+
});
|
2447
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2448
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
2449
|
+
});
|
2450
|
+
}
|
2451
|
+
async aggregate(aggs, filter) {
|
2452
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
2453
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2454
|
+
const result = await aggregateTable({
|
2455
|
+
pathParams: {
|
2456
|
+
workspace: "{workspaceId}",
|
2457
|
+
dbBranchName: "{dbBranch}",
|
2458
|
+
region: "{region}",
|
2459
|
+
tableName: __privateGet$4(this, _table)
|
2460
|
+
},
|
2461
|
+
body: { aggs, filter },
|
2462
|
+
...fetchProps
|
2463
|
+
});
|
2464
|
+
return result;
|
1486
2465
|
});
|
1487
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1488
|
-
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1489
2466
|
}
|
1490
2467
|
async query(query) {
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
2468
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
2469
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
2470
|
+
if (cacheQuery)
|
2471
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
2472
|
+
const data = query.getQueryOptions();
|
2473
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2474
|
+
const { meta, records: objects } = await queryTable({
|
2475
|
+
pathParams: {
|
2476
|
+
workspace: "{workspaceId}",
|
2477
|
+
dbBranchName: "{dbBranch}",
|
2478
|
+
region: "{region}",
|
2479
|
+
tableName: __privateGet$4(this, _table)
|
2480
|
+
},
|
2481
|
+
body: {
|
2482
|
+
filter: cleanFilter(data.filter),
|
2483
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2484
|
+
page: data.pagination,
|
2485
|
+
columns: data.columns ?? ["*"]
|
2486
|
+
},
|
2487
|
+
fetchOptions: data.fetchOptions,
|
2488
|
+
...fetchProps
|
2489
|
+
});
|
2490
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2491
|
+
const records = objects.map(
|
2492
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
2493
|
+
);
|
2494
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
2495
|
+
return new Page(query, meta, records);
|
2496
|
+
});
|
2497
|
+
}
|
2498
|
+
async summarizeTable(query, summaries, summariesFilter) {
|
2499
|
+
return __privateGet$4(this, _trace).call(this, "summarize", async () => {
|
2500
|
+
const data = query.getQueryOptions();
|
2501
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2502
|
+
const result = await summarizeTable({
|
2503
|
+
pathParams: {
|
2504
|
+
workspace: "{workspaceId}",
|
2505
|
+
dbBranchName: "{dbBranch}",
|
2506
|
+
region: "{region}",
|
2507
|
+
tableName: __privateGet$4(this, _table)
|
2508
|
+
},
|
2509
|
+
body: {
|
2510
|
+
filter: cleanFilter(data.filter),
|
2511
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
2512
|
+
columns: data.columns,
|
2513
|
+
page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
|
2514
|
+
summaries,
|
2515
|
+
summariesFilter
|
2516
|
+
},
|
2517
|
+
...fetchProps
|
2518
|
+
});
|
2519
|
+
return result;
|
1506
2520
|
});
|
1507
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1508
|
-
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
1509
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1510
|
-
return new Page(query, meta, records);
|
1511
2521
|
}
|
1512
2522
|
}
|
1513
2523
|
_table = new WeakMap();
|
@@ -1515,6 +2525,7 @@ _getFetchProps = new WeakMap();
|
|
1515
2525
|
_db = new WeakMap();
|
1516
2526
|
_cache = new WeakMap();
|
1517
2527
|
_schemaTables$2 = new WeakMap();
|
2528
|
+
_trace = new WeakMap();
|
1518
2529
|
_insertRecordWithoutId = new WeakSet();
|
1519
2530
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
1520
2531
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1523,6 +2534,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1523
2534
|
pathParams: {
|
1524
2535
|
workspace: "{workspaceId}",
|
1525
2536
|
dbBranchName: "{dbBranch}",
|
2537
|
+
region: "{region}",
|
1526
2538
|
tableName: __privateGet$4(this, _table)
|
1527
2539
|
},
|
1528
2540
|
queryParams: { columns },
|
@@ -1530,74 +2542,173 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1530
2542
|
...fetchProps
|
1531
2543
|
});
|
1532
2544
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1533
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2545
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1534
2546
|
};
|
1535
2547
|
_insertRecordWithId = new WeakSet();
|
1536
|
-
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
2548
|
+
insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
|
1537
2549
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1538
2550
|
const record = transformObjectLinks(object);
|
1539
2551
|
const response = await insertRecordWithID({
|
1540
2552
|
pathParams: {
|
1541
2553
|
workspace: "{workspaceId}",
|
1542
2554
|
dbBranchName: "{dbBranch}",
|
2555
|
+
region: "{region}",
|
1543
2556
|
tableName: __privateGet$4(this, _table),
|
1544
2557
|
recordId
|
1545
2558
|
},
|
1546
2559
|
body: record,
|
1547
|
-
queryParams: { createOnly
|
2560
|
+
queryParams: { createOnly, columns, ifVersion },
|
1548
2561
|
...fetchProps
|
1549
2562
|
});
|
1550
2563
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1551
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2564
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1552
2565
|
};
|
1553
|
-
|
1554
|
-
|
2566
|
+
_insertRecords = new WeakSet();
|
2567
|
+
insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
|
1555
2568
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1556
|
-
const
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
2569
|
+
const chunkedOperations = chunk(
|
2570
|
+
objects.map((object) => ({
|
2571
|
+
insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
|
2572
|
+
})),
|
2573
|
+
BULK_OPERATION_MAX_SIZE
|
2574
|
+
);
|
2575
|
+
const ids = [];
|
2576
|
+
for (const operations of chunkedOperations) {
|
2577
|
+
const { results } = await branchTransaction({
|
2578
|
+
pathParams: {
|
2579
|
+
workspace: "{workspaceId}",
|
2580
|
+
dbBranchName: "{dbBranch}",
|
2581
|
+
region: "{region}"
|
2582
|
+
},
|
2583
|
+
body: { operations },
|
2584
|
+
...fetchProps
|
2585
|
+
});
|
2586
|
+
for (const result of results) {
|
2587
|
+
if (result.operation === "insert") {
|
2588
|
+
ids.push(result.id);
|
2589
|
+
} else {
|
2590
|
+
ids.push(null);
|
2591
|
+
}
|
2592
|
+
}
|
1565
2593
|
}
|
1566
|
-
|
1567
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
2594
|
+
return ids;
|
1568
2595
|
};
|
1569
2596
|
_updateRecordWithID = new WeakSet();
|
1570
|
-
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
2597
|
+
updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
1571
2598
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1572
|
-
const record = transformObjectLinks(object);
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
2599
|
+
const { id: _id, ...record } = transformObjectLinks(object);
|
2600
|
+
try {
|
2601
|
+
const response = await updateRecordWithID({
|
2602
|
+
pathParams: {
|
2603
|
+
workspace: "{workspaceId}",
|
2604
|
+
dbBranchName: "{dbBranch}",
|
2605
|
+
region: "{region}",
|
2606
|
+
tableName: __privateGet$4(this, _table),
|
2607
|
+
recordId
|
2608
|
+
},
|
2609
|
+
queryParams: { columns, ifVersion },
|
2610
|
+
body: record,
|
2611
|
+
...fetchProps
|
2612
|
+
});
|
2613
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2614
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2615
|
+
} catch (e) {
|
2616
|
+
if (isObject(e) && e.status === 404) {
|
2617
|
+
return null;
|
2618
|
+
}
|
2619
|
+
throw e;
|
2620
|
+
}
|
2621
|
+
};
|
2622
|
+
_updateRecords = new WeakSet();
|
2623
|
+
updateRecords_fn = async function(objects, { ifVersion, upsert }) {
|
2624
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2625
|
+
const chunkedOperations = chunk(
|
2626
|
+
objects.map(({ id, ...object }) => ({
|
2627
|
+
update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
|
2628
|
+
})),
|
2629
|
+
BULK_OPERATION_MAX_SIZE
|
2630
|
+
);
|
2631
|
+
const ids = [];
|
2632
|
+
for (const operations of chunkedOperations) {
|
2633
|
+
const { results } = await branchTransaction({
|
2634
|
+
pathParams: {
|
2635
|
+
workspace: "{workspaceId}",
|
2636
|
+
dbBranchName: "{dbBranch}",
|
2637
|
+
region: "{region}"
|
2638
|
+
},
|
2639
|
+
body: { operations },
|
2640
|
+
...fetchProps
|
2641
|
+
});
|
2642
|
+
for (const result of results) {
|
2643
|
+
if (result.operation === "update") {
|
2644
|
+
ids.push(result.id);
|
2645
|
+
} else {
|
2646
|
+
ids.push(null);
|
2647
|
+
}
|
2648
|
+
}
|
2649
|
+
}
|
2650
|
+
return ids;
|
1581
2651
|
};
|
1582
2652
|
_upsertRecordWithID = new WeakSet();
|
1583
|
-
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
2653
|
+
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
|
1584
2654
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1585
2655
|
const response = await upsertRecordWithID({
|
1586
|
-
pathParams: {
|
1587
|
-
|
2656
|
+
pathParams: {
|
2657
|
+
workspace: "{workspaceId}",
|
2658
|
+
dbBranchName: "{dbBranch}",
|
2659
|
+
region: "{region}",
|
2660
|
+
tableName: __privateGet$4(this, _table),
|
2661
|
+
recordId
|
2662
|
+
},
|
2663
|
+
queryParams: { columns, ifVersion },
|
1588
2664
|
body: object,
|
1589
2665
|
...fetchProps
|
1590
2666
|
});
|
1591
2667
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1592
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2668
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1593
2669
|
};
|
1594
2670
|
_deleteRecord = new WeakSet();
|
1595
|
-
deleteRecord_fn = async function(recordId) {
|
2671
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1596
2672
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
2673
|
+
try {
|
2674
|
+
const response = await deleteRecord({
|
2675
|
+
pathParams: {
|
2676
|
+
workspace: "{workspaceId}",
|
2677
|
+
dbBranchName: "{dbBranch}",
|
2678
|
+
region: "{region}",
|
2679
|
+
tableName: __privateGet$4(this, _table),
|
2680
|
+
recordId
|
2681
|
+
},
|
2682
|
+
queryParams: { columns },
|
2683
|
+
...fetchProps
|
2684
|
+
});
|
2685
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
2686
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
2687
|
+
} catch (e) {
|
2688
|
+
if (isObject(e) && e.status === 404) {
|
2689
|
+
return null;
|
2690
|
+
}
|
2691
|
+
throw e;
|
2692
|
+
}
|
2693
|
+
};
|
2694
|
+
_deleteRecords = new WeakSet();
|
2695
|
+
deleteRecords_fn = async function(recordIds) {
|
2696
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
2697
|
+
const chunkedOperations = chunk(
|
2698
|
+
recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
|
2699
|
+
BULK_OPERATION_MAX_SIZE
|
2700
|
+
);
|
2701
|
+
for (const operations of chunkedOperations) {
|
2702
|
+
await branchTransaction({
|
2703
|
+
pathParams: {
|
2704
|
+
workspace: "{workspaceId}",
|
2705
|
+
dbBranchName: "{dbBranch}",
|
2706
|
+
region: "{region}"
|
2707
|
+
},
|
2708
|
+
body: { operations },
|
2709
|
+
...fetchProps
|
2710
|
+
});
|
2711
|
+
}
|
1601
2712
|
};
|
1602
2713
|
_setCacheQuery = new WeakSet();
|
1603
2714
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1621,7 +2732,7 @@ getSchemaTables_fn$1 = async function() {
|
|
1621
2732
|
return __privateGet$4(this, _schemaTables$2);
|
1622
2733
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1623
2734
|
const { schema } = await getBranchDetails({
|
1624
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
2735
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
1625
2736
|
...fetchProps
|
1626
2737
|
});
|
1627
2738
|
__privateSet$4(this, _schemaTables$2, schema.tables);
|
@@ -1634,7 +2745,7 @@ const transformObjectLinks = (object) => {
|
|
1634
2745
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1635
2746
|
}, {});
|
1636
2747
|
};
|
1637
|
-
const initObject = (db, schemaTables, table, object) => {
|
2748
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
1638
2749
|
const result = {};
|
1639
2750
|
const { xata, ...rest } = object ?? {};
|
1640
2751
|
Object.assign(result, rest);
|
@@ -1642,6 +2753,8 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1642
2753
|
if (!columns)
|
1643
2754
|
console.error(`Table ${table} not found in schema`);
|
1644
2755
|
for (const column of columns ?? []) {
|
2756
|
+
if (!isValidColumn(selectedColumns, column))
|
2757
|
+
continue;
|
1645
2758
|
const value = result[column.name];
|
1646
2759
|
switch (column.type) {
|
1647
2760
|
case "datetime": {
|
@@ -1658,17 +2771,42 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1658
2771
|
if (!linkTable) {
|
1659
2772
|
console.error(`Failed to parse link for field ${column.name}`);
|
1660
2773
|
} else if (isObject(value)) {
|
1661
|
-
|
2774
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2775
|
+
if (item === column.name) {
|
2776
|
+
return [...acc, "*"];
|
2777
|
+
}
|
2778
|
+
if (item.startsWith(`${column.name}.`)) {
|
2779
|
+
const [, ...path] = item.split(".");
|
2780
|
+
return [...acc, path.join(".")];
|
2781
|
+
}
|
2782
|
+
return acc;
|
2783
|
+
}, []);
|
2784
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2785
|
+
} else {
|
2786
|
+
result[column.name] = null;
|
1662
2787
|
}
|
1663
2788
|
break;
|
1664
2789
|
}
|
2790
|
+
default:
|
2791
|
+
result[column.name] = value ?? null;
|
2792
|
+
if (column.notNull === true && value === null) {
|
2793
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2794
|
+
}
|
2795
|
+
break;
|
1665
2796
|
}
|
1666
2797
|
}
|
1667
2798
|
result.read = function(columns2) {
|
1668
2799
|
return db[table].read(result["id"], columns2);
|
1669
2800
|
};
|
1670
|
-
result.update = function(data,
|
1671
|
-
|
2801
|
+
result.update = function(data, b, c) {
|
2802
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
2803
|
+
const ifVersion = parseIfVersion(b, c);
|
2804
|
+
return db[table].update(result["id"], data, columns2, { ifVersion });
|
2805
|
+
};
|
2806
|
+
result.replace = function(data, b, c) {
|
2807
|
+
const columns2 = isStringArray(b) ? b : ["*"];
|
2808
|
+
const ifVersion = parseIfVersion(b, c);
|
2809
|
+
return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
|
1672
2810
|
};
|
1673
2811
|
result.delete = function() {
|
1674
2812
|
return db[table].delete(result["id"]);
|
@@ -1676,14 +2814,35 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1676
2814
|
result.getMetadata = function() {
|
1677
2815
|
return xata;
|
1678
2816
|
};
|
1679
|
-
for (const prop of ["read", "update", "delete", "getMetadata"]) {
|
2817
|
+
for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
|
1680
2818
|
Object.defineProperty(result, prop, { enumerable: false });
|
1681
2819
|
}
|
1682
2820
|
Object.freeze(result);
|
1683
2821
|
return result;
|
1684
2822
|
};
|
1685
|
-
function
|
1686
|
-
|
2823
|
+
function extractId(value) {
|
2824
|
+
if (isString(value))
|
2825
|
+
return value;
|
2826
|
+
if (isObject(value) && isString(value.id))
|
2827
|
+
return value.id;
|
2828
|
+
return void 0;
|
2829
|
+
}
|
2830
|
+
function isValidColumn(columns, column) {
|
2831
|
+
if (columns.includes("*"))
|
2832
|
+
return true;
|
2833
|
+
if (column.type === "link") {
|
2834
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2835
|
+
return linkColumns.length > 0;
|
2836
|
+
}
|
2837
|
+
return columns.includes(column.name);
|
2838
|
+
}
|
2839
|
+
function parseIfVersion(...args) {
|
2840
|
+
for (const arg of args) {
|
2841
|
+
if (isObject(arg) && isNumber(arg.ifVersion)) {
|
2842
|
+
return arg.ifVersion;
|
2843
|
+
}
|
2844
|
+
}
|
2845
|
+
return void 0;
|
1687
2846
|
}
|
1688
2847
|
|
1689
2848
|
var __accessCheck$3 = (obj, member, msg) => {
|
@@ -1735,18 +2894,25 @@ class SimpleCache {
|
|
1735
2894
|
}
|
1736
2895
|
_map = new WeakMap();
|
1737
2896
|
|
1738
|
-
const
|
1739
|
-
const
|
1740
|
-
const
|
1741
|
-
const
|
1742
|
-
const
|
1743
|
-
const
|
2897
|
+
const greaterThan = (value) => ({ $gt: value });
|
2898
|
+
const gt = greaterThan;
|
2899
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
2900
|
+
const greaterEquals = greaterThanEquals;
|
2901
|
+
const gte = greaterThanEquals;
|
2902
|
+
const ge = greaterThanEquals;
|
2903
|
+
const lessThan = (value) => ({ $lt: value });
|
2904
|
+
const lt = lessThan;
|
2905
|
+
const lessThanEquals = (value) => ({ $le: value });
|
2906
|
+
const lessEquals = lessThanEquals;
|
2907
|
+
const lte = lessThanEquals;
|
2908
|
+
const le = lessThanEquals;
|
1744
2909
|
const exists = (column) => ({ $exists: column });
|
1745
2910
|
const notExists = (column) => ({ $notExists: column });
|
1746
2911
|
const startsWith = (value) => ({ $startsWith: value });
|
1747
2912
|
const endsWith = (value) => ({ $endsWith: value });
|
1748
2913
|
const pattern = (value) => ({ $pattern: value });
|
1749
2914
|
const is = (value) => ({ $is: value });
|
2915
|
+
const equals = is;
|
1750
2916
|
const isNot = (value) => ({ $isNot: value });
|
1751
2917
|
const contains = (value) => ({ $contains: value });
|
1752
2918
|
const includes = (value) => ({ $includes: value });
|
@@ -1843,7 +3009,7 @@ class SearchPlugin extends XataPlugin {
|
|
1843
3009
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1844
3010
|
return records.map((record) => {
|
1845
3011
|
const { table = "orphan" } = record.xata;
|
1846
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
3012
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
1847
3013
|
});
|
1848
3014
|
},
|
1849
3015
|
byTable: async (query, options = {}) => {
|
@@ -1852,7 +3018,7 @@ class SearchPlugin extends XataPlugin {
|
|
1852
3018
|
return records.reduce((acc, record) => {
|
1853
3019
|
const { table = "orphan" } = record.xata;
|
1854
3020
|
const items = acc[table] ?? [];
|
1855
|
-
const item = initObject(this.db, schemaTables, table, record);
|
3021
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1856
3022
|
return { ...acc, [table]: [...items, item] };
|
1857
3023
|
}, {});
|
1858
3024
|
}
|
@@ -1865,7 +3031,7 @@ search_fn = async function(query, options, getFetchProps) {
|
|
1865
3031
|
const fetchProps = await getFetchProps();
|
1866
3032
|
const { tables, fuzziness, highlight, prefix } = options ?? {};
|
1867
3033
|
const { records } = await searchBranch({
|
1868
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
3034
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
1869
3035
|
body: { tables, query, fuzziness, prefix, highlight },
|
1870
3036
|
...fetchProps
|
1871
3037
|
});
|
@@ -1877,7 +3043,7 @@ getSchemaTables_fn = async function(getFetchProps) {
|
|
1877
3043
|
return __privateGet$1(this, _schemaTables);
|
1878
3044
|
const fetchProps = await getFetchProps();
|
1879
3045
|
const { schema } = await getBranchDetails({
|
1880
|
-
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
|
3046
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
|
1881
3047
|
...fetchProps
|
1882
3048
|
});
|
1883
3049
|
__privateSet$1(this, _schemaTables, schema.tables);
|
@@ -1915,15 +3081,19 @@ async function resolveXataBranch(gitBranch, options) {
|
|
1915
3081
|
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1916
3082
|
);
|
1917
3083
|
const [protocol, , host, , dbName] = databaseURL.split("/");
|
1918
|
-
const
|
3084
|
+
const urlParts = parseWorkspacesUrlParts(host);
|
3085
|
+
if (!urlParts)
|
3086
|
+
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3087
|
+
const { workspace, region } = urlParts;
|
1919
3088
|
const { fallbackBranch } = getEnvironment();
|
1920
3089
|
const { branch } = await resolveBranch({
|
1921
3090
|
apiKey,
|
1922
3091
|
apiUrl: databaseURL,
|
1923
3092
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1924
3093
|
workspacesApiUrl: `${protocol}//${host}`,
|
1925
|
-
pathParams: { dbName, workspace },
|
1926
|
-
queryParams: { gitBranch, fallbackBranch }
|
3094
|
+
pathParams: { dbName, workspace, region },
|
3095
|
+
queryParams: { gitBranch, fallbackBranch },
|
3096
|
+
trace: defaultTrace
|
1927
3097
|
});
|
1928
3098
|
return branch;
|
1929
3099
|
}
|
@@ -1939,15 +3109,18 @@ async function getDatabaseBranch(branch, options) {
|
|
1939
3109
|
"An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
|
1940
3110
|
);
|
1941
3111
|
const [protocol, , host, , database] = databaseURL.split("/");
|
1942
|
-
const
|
1943
|
-
|
3112
|
+
const urlParts = parseWorkspacesUrlParts(host);
|
3113
|
+
if (!urlParts)
|
3114
|
+
throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
|
3115
|
+
const { workspace, region } = urlParts;
|
1944
3116
|
try {
|
1945
3117
|
return await getBranchDetails({
|
1946
3118
|
apiKey,
|
1947
3119
|
apiUrl: databaseURL,
|
1948
3120
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
1949
3121
|
workspacesApiUrl: `${protocol}//${host}`,
|
1950
|
-
pathParams: { dbBranchName
|
3122
|
+
pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
|
3123
|
+
trace: defaultTrace
|
1951
3124
|
});
|
1952
3125
|
} catch (err) {
|
1953
3126
|
if (isObject(err) && err.status === 404)
|
@@ -1999,7 +3172,8 @@ const buildClient = (plugins) => {
|
|
1999
3172
|
__privateSet(this, _options, safeOptions);
|
2000
3173
|
const pluginOptions = {
|
2001
3174
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
2002
|
-
cache: safeOptions.cache
|
3175
|
+
cache: safeOptions.cache,
|
3176
|
+
trace: safeOptions.trace
|
2003
3177
|
};
|
2004
3178
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
2005
3179
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
@@ -2024,16 +3198,27 @@ const buildClient = (plugins) => {
|
|
2024
3198
|
return { databaseURL, branch };
|
2025
3199
|
}
|
2026
3200
|
}, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
|
3201
|
+
const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
|
3202
|
+
const isBrowser = typeof window !== "undefined";
|
3203
|
+
if (isBrowser && !enableBrowser) {
|
3204
|
+
throw new Error(
|
3205
|
+
"You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
|
3206
|
+
);
|
3207
|
+
}
|
2027
3208
|
const fetch = getFetchImplementation(options?.fetch);
|
2028
3209
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
2029
3210
|
const apiKey = options?.apiKey || getAPIKey();
|
2030
3211
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
3212
|
+
const trace = options?.trace ?? defaultTrace;
|
2031
3213
|
const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
|
2032
|
-
if (!
|
2033
|
-
throw new Error("
|
3214
|
+
if (!apiKey) {
|
3215
|
+
throw new Error("Option apiKey is required");
|
3216
|
+
}
|
3217
|
+
if (!databaseURL) {
|
3218
|
+
throw new Error("Option databaseURL is required");
|
2034
3219
|
}
|
2035
|
-
return { fetch, databaseURL, apiKey, branch, cache };
|
2036
|
-
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
|
3220
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
|
3221
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
|
2037
3222
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
2038
3223
|
if (!branchValue)
|
2039
3224
|
throw new Error("Unable to resolve branch value");
|
@@ -2043,9 +3228,11 @@ const buildClient = (plugins) => {
|
|
2043
3228
|
apiUrl: "",
|
2044
3229
|
workspacesApiUrl: (path, params) => {
|
2045
3230
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2046
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
3231
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2047
3232
|
return databaseURL + newPath;
|
2048
|
-
}
|
3233
|
+
},
|
3234
|
+
trace,
|
3235
|
+
clientID
|
2049
3236
|
};
|
2050
3237
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
2051
3238
|
if (__privateGet(this, _branch))
|
@@ -2157,5 +3344,5 @@ class XataError extends Error {
|
|
2157
3344
|
}
|
2158
3345
|
}
|
2159
3346
|
|
2160
|
-
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
3347
|
+
export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, aggregateTable, applyBranchSchemaEdit, branchTransaction, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, dEPRECATEDcreateDatabase, dEPRECATEDdeleteDatabase, dEPRECATEDgetDatabaseList, dEPRECATEDgetDatabaseMetadata, dEPRECATEDupdateDatabaseMetadata, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getHostUrl, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isHostProviderAlias, isHostProviderBuilder, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequestsCommits, listRegions, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, parseWorkspacesUrlParts, pattern, previewBranchSchemaEdit, queryMigrationRequests, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2161
3348
|
//# sourceMappingURL=index.mjs.map
|