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