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