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