@xata.io/client 0.0.0-alpha.vec0bff6 → 0.0.0-alpha.vec26c56
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 +100 -0
- package/README.md +27 -25
- package/Usage.md +29 -6
- package/dist/index.cjs +1011 -336
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2564 -343
- package/dist/index.mjs +974 -337
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,28 @@ function _interopNamespace(e) {
|
|
|
20
20
|
return Object.freeze(n);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
const defaultTrace = async (_name, fn, _options) => {
|
|
24
|
+
return await fn({
|
|
25
|
+
setAttributes: () => {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const TraceAttributes = {
|
|
31
|
+
KIND: "xata.trace.kind",
|
|
32
|
+
VERSION: "xata.sdk.version",
|
|
33
|
+
TABLE: "xata.table",
|
|
34
|
+
HTTP_REQUEST_ID: "http.request_id",
|
|
35
|
+
HTTP_STATUS_CODE: "http.status_code",
|
|
36
|
+
HTTP_HOST: "http.host",
|
|
37
|
+
HTTP_SCHEME: "http.scheme",
|
|
38
|
+
HTTP_USER_AGENT: "http.user_agent",
|
|
39
|
+
HTTP_METHOD: "http.method",
|
|
40
|
+
HTTP_URL: "http.url",
|
|
41
|
+
HTTP_ROUTE: "http.route",
|
|
42
|
+
HTTP_TARGET: "http.target"
|
|
43
|
+
};
|
|
44
|
+
|
|
23
45
|
function notEmpty(value) {
|
|
24
46
|
return value !== null && value !== void 0;
|
|
25
47
|
}
|
|
@@ -144,13 +166,13 @@ function getFetchImplementation(userFetch) {
|
|
|
144
166
|
const fetchImpl = userFetch ?? globalFetch;
|
|
145
167
|
if (!fetchImpl) {
|
|
146
168
|
throw new Error(
|
|
147
|
-
`
|
|
169
|
+
`Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
|
|
148
170
|
);
|
|
149
171
|
}
|
|
150
172
|
return fetchImpl;
|
|
151
173
|
}
|
|
152
174
|
|
|
153
|
-
const VERSION = "0.0.0-alpha.
|
|
175
|
+
const VERSION = "0.0.0-alpha.vec26c56";
|
|
154
176
|
|
|
155
177
|
class ErrorWithCause extends Error {
|
|
156
178
|
constructor(message, options) {
|
|
@@ -201,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
|
201
223
|
}, {});
|
|
202
224
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
|
203
225
|
const queryString = query.length > 0 ? `?${query}` : "";
|
|
204
|
-
|
|
226
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
|
227
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
|
228
|
+
}, {});
|
|
229
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
|
205
230
|
};
|
|
206
231
|
function buildBaseUrl({
|
|
207
232
|
path,
|
|
@@ -209,10 +234,10 @@ function buildBaseUrl({
|
|
|
209
234
|
apiUrl,
|
|
210
235
|
pathParams
|
|
211
236
|
}) {
|
|
212
|
-
if (
|
|
237
|
+
if (pathParams?.workspace === void 0 || !path.startsWith("/db"))
|
|
213
238
|
return `${apiUrl}${path}`;
|
|
214
239
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
|
215
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
|
240
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
|
216
241
|
}
|
|
217
242
|
function hostHeader(url) {
|
|
218
243
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
|
@@ -229,245 +254,386 @@ async function fetch$1({
|
|
|
229
254
|
fetchImpl,
|
|
230
255
|
apiKey,
|
|
231
256
|
apiUrl,
|
|
232
|
-
workspacesApiUrl
|
|
257
|
+
workspacesApiUrl,
|
|
258
|
+
trace,
|
|
259
|
+
signal,
|
|
260
|
+
clientID,
|
|
261
|
+
sessionID
|
|
233
262
|
}) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
263
|
+
return trace(
|
|
264
|
+
`${method.toUpperCase()} ${path}`,
|
|
265
|
+
async ({ setAttributes }) => {
|
|
266
|
+
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
|
267
|
+
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
|
268
|
+
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
|
269
|
+
setAttributes({
|
|
270
|
+
[TraceAttributes.HTTP_URL]: url,
|
|
271
|
+
[TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
|
|
272
|
+
});
|
|
273
|
+
const response = await fetchImpl(url, {
|
|
274
|
+
method: method.toUpperCase(),
|
|
275
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
276
|
+
headers: {
|
|
277
|
+
"Content-Type": "application/json",
|
|
278
|
+
"User-Agent": `Xata client-ts/${VERSION}`,
|
|
279
|
+
"X-Xata-Client-ID": clientID ?? "",
|
|
280
|
+
"X-Xata-Session-ID": sessionID ?? "",
|
|
281
|
+
...headers,
|
|
282
|
+
...hostHeader(fullUrl),
|
|
283
|
+
Authorization: `Bearer ${apiKey}`
|
|
284
|
+
},
|
|
285
|
+
signal
|
|
286
|
+
});
|
|
287
|
+
if (response.status === 204) {
|
|
288
|
+
return {};
|
|
289
|
+
}
|
|
290
|
+
const { host, protocol } = parseUrl(response.url);
|
|
291
|
+
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
|
292
|
+
setAttributes({
|
|
293
|
+
[TraceAttributes.KIND]: "http",
|
|
294
|
+
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
|
295
|
+
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
|
296
|
+
[TraceAttributes.HTTP_HOST]: host,
|
|
297
|
+
[TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
|
|
298
|
+
});
|
|
299
|
+
try {
|
|
300
|
+
const jsonResponse = await response.json();
|
|
301
|
+
if (response.ok) {
|
|
302
|
+
return jsonResponse;
|
|
303
|
+
}
|
|
304
|
+
throw new FetcherError(response.status, jsonResponse, requestId);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
throw new FetcherError(response.status, error, requestId);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
function parseUrl(url) {
|
|
252
313
|
try {
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
return jsonResponse;
|
|
256
|
-
}
|
|
257
|
-
throw new FetcherError(response.status, jsonResponse, requestId);
|
|
314
|
+
const { host, protocol } = new URL(url);
|
|
315
|
+
return { host, protocol };
|
|
258
316
|
} catch (error) {
|
|
259
|
-
|
|
317
|
+
return {};
|
|
260
318
|
}
|
|
261
319
|
}
|
|
262
320
|
|
|
263
|
-
const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
|
|
264
|
-
const updateUser = (variables) => fetch$1({
|
|
265
|
-
|
|
266
|
-
|
|
321
|
+
const getUser = (variables, signal) => fetch$1({ url: "/user", method: "get", ...variables, signal });
|
|
322
|
+
const updateUser = (variables, signal) => fetch$1({
|
|
323
|
+
url: "/user",
|
|
324
|
+
method: "put",
|
|
325
|
+
...variables,
|
|
326
|
+
signal
|
|
327
|
+
});
|
|
328
|
+
const deleteUser = (variables, signal) => fetch$1({ url: "/user", method: "delete", ...variables, signal });
|
|
329
|
+
const getUserAPIKeys = (variables, signal) => fetch$1({
|
|
267
330
|
url: "/user/keys",
|
|
268
331
|
method: "get",
|
|
269
|
-
...variables
|
|
332
|
+
...variables,
|
|
333
|
+
signal
|
|
270
334
|
});
|
|
271
|
-
const createUserAPIKey = (variables) => fetch$1({
|
|
335
|
+
const createUserAPIKey = (variables, signal) => fetch$1({
|
|
272
336
|
url: "/user/keys/{keyName}",
|
|
273
337
|
method: "post",
|
|
274
|
-
...variables
|
|
338
|
+
...variables,
|
|
339
|
+
signal
|
|
275
340
|
});
|
|
276
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
|
341
|
+
const deleteUserAPIKey = (variables, signal) => fetch$1({
|
|
277
342
|
url: "/user/keys/{keyName}",
|
|
278
343
|
method: "delete",
|
|
279
|
-
...variables
|
|
344
|
+
...variables,
|
|
345
|
+
signal
|
|
280
346
|
});
|
|
281
|
-
const createWorkspace = (variables) => fetch$1({
|
|
347
|
+
const createWorkspace = (variables, signal) => fetch$1({
|
|
282
348
|
url: "/workspaces",
|
|
283
349
|
method: "post",
|
|
284
|
-
...variables
|
|
350
|
+
...variables,
|
|
351
|
+
signal
|
|
285
352
|
});
|
|
286
|
-
const getWorkspacesList = (variables) => fetch$1({
|
|
353
|
+
const getWorkspacesList = (variables, signal) => fetch$1({
|
|
287
354
|
url: "/workspaces",
|
|
288
355
|
method: "get",
|
|
289
|
-
...variables
|
|
356
|
+
...variables,
|
|
357
|
+
signal
|
|
290
358
|
});
|
|
291
|
-
const getWorkspace = (variables) => fetch$1({
|
|
359
|
+
const getWorkspace = (variables, signal) => fetch$1({
|
|
292
360
|
url: "/workspaces/{workspaceId}",
|
|
293
361
|
method: "get",
|
|
294
|
-
...variables
|
|
362
|
+
...variables,
|
|
363
|
+
signal
|
|
295
364
|
});
|
|
296
|
-
const updateWorkspace = (variables) => fetch$1({
|
|
365
|
+
const updateWorkspace = (variables, signal) => fetch$1({
|
|
297
366
|
url: "/workspaces/{workspaceId}",
|
|
298
367
|
method: "put",
|
|
299
|
-
...variables
|
|
368
|
+
...variables,
|
|
369
|
+
signal
|
|
300
370
|
});
|
|
301
|
-
const deleteWorkspace = (variables) => fetch$1({
|
|
371
|
+
const deleteWorkspace = (variables, signal) => fetch$1({
|
|
302
372
|
url: "/workspaces/{workspaceId}",
|
|
303
373
|
method: "delete",
|
|
304
|
-
...variables
|
|
374
|
+
...variables,
|
|
375
|
+
signal
|
|
305
376
|
});
|
|
306
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
|
377
|
+
const getWorkspaceMembersList = (variables, signal) => fetch$1({
|
|
307
378
|
url: "/workspaces/{workspaceId}/members",
|
|
308
379
|
method: "get",
|
|
309
|
-
...variables
|
|
380
|
+
...variables,
|
|
381
|
+
signal
|
|
310
382
|
});
|
|
311
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
|
312
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
|
383
|
+
const updateWorkspaceMemberRole = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
|
384
|
+
const removeWorkspaceMember = (variables, signal) => fetch$1({
|
|
313
385
|
url: "/workspaces/{workspaceId}/members/{userId}",
|
|
314
386
|
method: "delete",
|
|
315
|
-
...variables
|
|
387
|
+
...variables,
|
|
388
|
+
signal
|
|
316
389
|
});
|
|
317
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
|
318
|
-
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
|
319
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
|
390
|
+
const inviteWorkspaceMember = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
|
391
|
+
const updateWorkspaceMemberInvite = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
|
392
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
|
320
393
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
|
321
394
|
method: "delete",
|
|
322
|
-
...variables
|
|
395
|
+
...variables,
|
|
396
|
+
signal
|
|
323
397
|
});
|
|
324
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
|
398
|
+
const resendWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
|
325
399
|
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
|
326
400
|
method: "post",
|
|
327
|
-
...variables
|
|
401
|
+
...variables,
|
|
402
|
+
signal
|
|
328
403
|
});
|
|
329
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
|
404
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
|
330
405
|
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
|
331
406
|
method: "post",
|
|
332
|
-
...variables
|
|
407
|
+
...variables,
|
|
408
|
+
signal
|
|
333
409
|
});
|
|
334
|
-
const getDatabaseList = (variables) => fetch$1({
|
|
410
|
+
const getDatabaseList = (variables, signal) => fetch$1({
|
|
335
411
|
url: "/dbs",
|
|
336
412
|
method: "get",
|
|
337
|
-
...variables
|
|
413
|
+
...variables,
|
|
414
|
+
signal
|
|
338
415
|
});
|
|
339
|
-
const getBranchList = (variables) => fetch$1({
|
|
416
|
+
const getBranchList = (variables, signal) => fetch$1({
|
|
340
417
|
url: "/dbs/{dbName}",
|
|
341
418
|
method: "get",
|
|
342
|
-
...variables
|
|
419
|
+
...variables,
|
|
420
|
+
signal
|
|
343
421
|
});
|
|
344
|
-
const createDatabase = (variables) => fetch$1({
|
|
422
|
+
const createDatabase = (variables, signal) => fetch$1({
|
|
345
423
|
url: "/dbs/{dbName}",
|
|
346
424
|
method: "put",
|
|
347
|
-
...variables
|
|
425
|
+
...variables,
|
|
426
|
+
signal
|
|
348
427
|
});
|
|
349
|
-
const deleteDatabase = (variables) => fetch$1({
|
|
428
|
+
const deleteDatabase = (variables, signal) => fetch$1({
|
|
350
429
|
url: "/dbs/{dbName}",
|
|
351
430
|
method: "delete",
|
|
352
|
-
...variables
|
|
431
|
+
...variables,
|
|
432
|
+
signal
|
|
433
|
+
});
|
|
434
|
+
const getDatabaseMetadata = (variables, signal) => fetch$1({
|
|
435
|
+
url: "/dbs/{dbName}/metadata",
|
|
436
|
+
method: "get",
|
|
437
|
+
...variables,
|
|
438
|
+
signal
|
|
353
439
|
});
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const
|
|
357
|
-
const
|
|
440
|
+
const updateDatabaseMetadata = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
|
441
|
+
const getGitBranchesMapping = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
|
442
|
+
const addGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
|
443
|
+
const removeGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
|
444
|
+
const resolveBranch = (variables, signal) => fetch$1({
|
|
358
445
|
url: "/dbs/{dbName}/resolveBranch",
|
|
359
446
|
method: "get",
|
|
360
|
-
...variables
|
|
447
|
+
...variables,
|
|
448
|
+
signal
|
|
361
449
|
});
|
|
362
|
-
const
|
|
450
|
+
const queryMigrationRequests = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
|
451
|
+
const createMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
|
452
|
+
const getMigrationRequest = (variables, signal) => fetch$1({
|
|
453
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
|
454
|
+
method: "get",
|
|
455
|
+
...variables,
|
|
456
|
+
signal
|
|
457
|
+
});
|
|
458
|
+
const updateMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
|
459
|
+
const listMigrationRequestsCommits = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
|
460
|
+
const compareMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
|
461
|
+
const getMigrationRequestIsMerged = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
|
462
|
+
const mergeMigrationRequest = (variables, signal) => fetch$1({
|
|
463
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
|
464
|
+
method: "post",
|
|
465
|
+
...variables,
|
|
466
|
+
signal
|
|
467
|
+
});
|
|
468
|
+
const getBranchDetails = (variables, signal) => fetch$1({
|
|
363
469
|
url: "/db/{dbBranchName}",
|
|
364
470
|
method: "get",
|
|
365
|
-
...variables
|
|
471
|
+
...variables,
|
|
472
|
+
signal
|
|
366
473
|
});
|
|
367
|
-
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
|
368
|
-
const deleteBranch = (variables) => fetch$1({
|
|
474
|
+
const createBranch = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
|
475
|
+
const deleteBranch = (variables, signal) => fetch$1({
|
|
369
476
|
url: "/db/{dbBranchName}",
|
|
370
477
|
method: "delete",
|
|
371
|
-
...variables
|
|
478
|
+
...variables,
|
|
479
|
+
signal
|
|
372
480
|
});
|
|
373
|
-
const updateBranchMetadata = (variables) => fetch$1({
|
|
481
|
+
const updateBranchMetadata = (variables, signal) => fetch$1({
|
|
374
482
|
url: "/db/{dbBranchName}/metadata",
|
|
375
483
|
method: "put",
|
|
376
|
-
...variables
|
|
484
|
+
...variables,
|
|
485
|
+
signal
|
|
377
486
|
});
|
|
378
|
-
const getBranchMetadata = (variables) => fetch$1({
|
|
487
|
+
const getBranchMetadata = (variables, signal) => fetch$1({
|
|
379
488
|
url: "/db/{dbBranchName}/metadata",
|
|
380
489
|
method: "get",
|
|
381
|
-
...variables
|
|
490
|
+
...variables,
|
|
491
|
+
signal
|
|
382
492
|
});
|
|
383
|
-
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
|
384
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
|
385
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
|
386
|
-
const
|
|
493
|
+
const getBranchMigrationHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
|
494
|
+
const executeBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
|
495
|
+
const getBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
|
496
|
+
const compareBranchWithUserSchema = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
|
497
|
+
const compareBranchSchemas = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
|
498
|
+
const updateBranchSchema = (variables, signal) => fetch$1({
|
|
499
|
+
url: "/db/{dbBranchName}/schema/update",
|
|
500
|
+
method: "post",
|
|
501
|
+
...variables,
|
|
502
|
+
signal
|
|
503
|
+
});
|
|
504
|
+
const previewBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
|
505
|
+
const applyBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
|
506
|
+
const getBranchSchemaHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
|
507
|
+
const getBranchStats = (variables, signal) => fetch$1({
|
|
387
508
|
url: "/db/{dbBranchName}/stats",
|
|
388
509
|
method: "get",
|
|
389
|
-
...variables
|
|
510
|
+
...variables,
|
|
511
|
+
signal
|
|
390
512
|
});
|
|
391
|
-
const createTable = (variables) => fetch$1({
|
|
513
|
+
const createTable = (variables, signal) => fetch$1({
|
|
392
514
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
|
393
515
|
method: "put",
|
|
394
|
-
...variables
|
|
516
|
+
...variables,
|
|
517
|
+
signal
|
|
395
518
|
});
|
|
396
|
-
const deleteTable = (variables) => fetch$1({
|
|
519
|
+
const deleteTable = (variables, signal) => fetch$1({
|
|
397
520
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
|
398
521
|
method: "delete",
|
|
399
|
-
...variables
|
|
522
|
+
...variables,
|
|
523
|
+
signal
|
|
400
524
|
});
|
|
401
|
-
const updateTable = (variables) => fetch$1({
|
|
525
|
+
const updateTable = (variables, signal) => fetch$1({
|
|
402
526
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
|
403
527
|
method: "patch",
|
|
404
|
-
...variables
|
|
528
|
+
...variables,
|
|
529
|
+
signal
|
|
405
530
|
});
|
|
406
|
-
const getTableSchema = (variables) => fetch$1({
|
|
531
|
+
const getTableSchema = (variables, signal) => fetch$1({
|
|
407
532
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
|
408
533
|
method: "get",
|
|
409
|
-
...variables
|
|
534
|
+
...variables,
|
|
535
|
+
signal
|
|
410
536
|
});
|
|
411
|
-
const setTableSchema = (variables) => fetch$1({
|
|
537
|
+
const setTableSchema = (variables, signal) => fetch$1({
|
|
412
538
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
|
413
539
|
method: "put",
|
|
414
|
-
...variables
|
|
540
|
+
...variables,
|
|
541
|
+
signal
|
|
415
542
|
});
|
|
416
|
-
const getTableColumns = (variables) => fetch$1({
|
|
543
|
+
const getTableColumns = (variables, signal) => fetch$1({
|
|
417
544
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
|
418
545
|
method: "get",
|
|
419
|
-
...variables
|
|
546
|
+
...variables,
|
|
547
|
+
signal
|
|
420
548
|
});
|
|
421
|
-
const addTableColumn = (variables) => fetch$1({
|
|
549
|
+
const addTableColumn = (variables, signal) => fetch$1({
|
|
422
550
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
|
423
551
|
method: "post",
|
|
424
|
-
...variables
|
|
552
|
+
...variables,
|
|
553
|
+
signal
|
|
425
554
|
});
|
|
426
|
-
const getColumn = (variables) => fetch$1({
|
|
555
|
+
const getColumn = (variables, signal) => fetch$1({
|
|
427
556
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
|
428
557
|
method: "get",
|
|
429
|
-
...variables
|
|
558
|
+
...variables,
|
|
559
|
+
signal
|
|
430
560
|
});
|
|
431
|
-
const deleteColumn = (variables) => fetch$1({
|
|
561
|
+
const deleteColumn = (variables, signal) => fetch$1({
|
|
432
562
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
|
433
563
|
method: "delete",
|
|
434
|
-
...variables
|
|
564
|
+
...variables,
|
|
565
|
+
signal
|
|
435
566
|
});
|
|
436
|
-
const updateColumn = (variables) => fetch$1({
|
|
567
|
+
const updateColumn = (variables, signal) => fetch$1({
|
|
437
568
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
|
438
569
|
method: "patch",
|
|
439
|
-
...variables
|
|
570
|
+
...variables,
|
|
571
|
+
signal
|
|
440
572
|
});
|
|
441
|
-
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
|
442
|
-
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
|
443
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
|
444
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
|
445
|
-
const deleteRecord = (variables) => fetch$1({
|
|
573
|
+
const insertRecord = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
|
574
|
+
const insertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
|
575
|
+
const updateRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
|
576
|
+
const upsertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
|
577
|
+
const deleteRecord = (variables, signal) => fetch$1({
|
|
446
578
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
|
447
579
|
method: "delete",
|
|
448
|
-
...variables
|
|
580
|
+
...variables,
|
|
581
|
+
signal
|
|
449
582
|
});
|
|
450
|
-
const getRecord = (variables) => fetch$1({
|
|
583
|
+
const getRecord = (variables, signal) => fetch$1({
|
|
451
584
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
|
452
585
|
method: "get",
|
|
453
|
-
...variables
|
|
586
|
+
...variables,
|
|
587
|
+
signal
|
|
454
588
|
});
|
|
455
|
-
const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
|
|
456
|
-
const queryTable = (variables) => fetch$1({
|
|
589
|
+
const bulkInsertTableRecords = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
|
590
|
+
const queryTable = (variables, signal) => fetch$1({
|
|
457
591
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
|
458
592
|
method: "post",
|
|
459
|
-
...variables
|
|
593
|
+
...variables,
|
|
594
|
+
signal
|
|
460
595
|
});
|
|
461
|
-
const searchTable = (variables) => fetch$1({
|
|
596
|
+
const searchTable = (variables, signal) => fetch$1({
|
|
462
597
|
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
|
463
598
|
method: "post",
|
|
464
|
-
...variables
|
|
599
|
+
...variables,
|
|
600
|
+
signal
|
|
465
601
|
});
|
|
466
|
-
const searchBranch = (variables) => fetch$1({
|
|
602
|
+
const searchBranch = (variables, signal) => fetch$1({
|
|
467
603
|
url: "/db/{dbBranchName}/search",
|
|
468
604
|
method: "post",
|
|
469
|
-
...variables
|
|
605
|
+
...variables,
|
|
606
|
+
signal
|
|
607
|
+
});
|
|
608
|
+
const summarizeTable = (variables, signal) => fetch$1({
|
|
609
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
|
610
|
+
method: "post",
|
|
611
|
+
...variables,
|
|
612
|
+
signal
|
|
613
|
+
});
|
|
614
|
+
const aggregateTable = (variables, signal) => fetch$1({
|
|
615
|
+
url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
|
|
616
|
+
method: "post",
|
|
617
|
+
...variables,
|
|
618
|
+
signal
|
|
619
|
+
});
|
|
620
|
+
const cPGetDatabaseList = (variables, signal) => fetch$1({
|
|
621
|
+
url: "/workspaces/{workspaceId}/dbs",
|
|
622
|
+
method: "get",
|
|
623
|
+
...variables,
|
|
624
|
+
signal
|
|
625
|
+
});
|
|
626
|
+
const cPCreateDatabase = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
|
|
627
|
+
const cPDeleteDatabase = (variables, signal) => fetch$1({
|
|
628
|
+
url: "/workspaces/{workspaceId}/dbs/{dbName}",
|
|
629
|
+
method: "delete",
|
|
630
|
+
...variables,
|
|
631
|
+
signal
|
|
470
632
|
});
|
|
633
|
+
const cPGetCPDatabaseMetadata = (variables, signal) => fetch$1(
|
|
634
|
+
{ url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "get", ...variables, signal }
|
|
635
|
+
);
|
|
636
|
+
const cPUpdateCPDatabaseMetadata = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
|
471
637
|
const operationsByTag = {
|
|
472
638
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
|
473
639
|
workspaces: {
|
|
@@ -489,6 +655,8 @@ const operationsByTag = {
|
|
|
489
655
|
getDatabaseList,
|
|
490
656
|
createDatabase,
|
|
491
657
|
deleteDatabase,
|
|
658
|
+
getDatabaseMetadata,
|
|
659
|
+
updateDatabaseMetadata,
|
|
492
660
|
getGitBranchesMapping,
|
|
493
661
|
addGitBranchesEntry,
|
|
494
662
|
removeGitBranchesEntry,
|
|
@@ -501,10 +669,28 @@ const operationsByTag = {
|
|
|
501
669
|
deleteBranch,
|
|
502
670
|
updateBranchMetadata,
|
|
503
671
|
getBranchMetadata,
|
|
672
|
+
getBranchStats
|
|
673
|
+
},
|
|
674
|
+
migrationRequests: {
|
|
675
|
+
queryMigrationRequests,
|
|
676
|
+
createMigrationRequest,
|
|
677
|
+
getMigrationRequest,
|
|
678
|
+
updateMigrationRequest,
|
|
679
|
+
listMigrationRequestsCommits,
|
|
680
|
+
compareMigrationRequest,
|
|
681
|
+
getMigrationRequestIsMerged,
|
|
682
|
+
mergeMigrationRequest
|
|
683
|
+
},
|
|
684
|
+
branchSchema: {
|
|
504
685
|
getBranchMigrationHistory,
|
|
505
686
|
executeBranchMigrationPlan,
|
|
506
687
|
getBranchMigrationPlan,
|
|
507
|
-
|
|
688
|
+
compareBranchWithUserSchema,
|
|
689
|
+
compareBranchSchemas,
|
|
690
|
+
updateBranchSchema,
|
|
691
|
+
previewBranchSchemaEdit,
|
|
692
|
+
applyBranchSchemaEdit,
|
|
693
|
+
getBranchSchemaHistory
|
|
508
694
|
},
|
|
509
695
|
table: {
|
|
510
696
|
createTable,
|
|
@@ -528,14 +714,23 @@ const operationsByTag = {
|
|
|
528
714
|
bulkInsertTableRecords,
|
|
529
715
|
queryTable,
|
|
530
716
|
searchTable,
|
|
531
|
-
searchBranch
|
|
717
|
+
searchBranch,
|
|
718
|
+
summarizeTable,
|
|
719
|
+
aggregateTable
|
|
720
|
+
},
|
|
721
|
+
databases: {
|
|
722
|
+
cPGetDatabaseList,
|
|
723
|
+
cPCreateDatabase,
|
|
724
|
+
cPDeleteDatabase,
|
|
725
|
+
cPGetCPDatabaseMetadata,
|
|
726
|
+
cPUpdateCPDatabaseMetadata
|
|
532
727
|
}
|
|
533
728
|
};
|
|
534
729
|
|
|
535
730
|
function getHostUrl(provider, type) {
|
|
536
|
-
if (
|
|
731
|
+
if (isHostProviderAlias(provider)) {
|
|
537
732
|
return providers[provider][type];
|
|
538
|
-
} else if (
|
|
733
|
+
} else if (isHostProviderBuilder(provider)) {
|
|
539
734
|
return provider[type];
|
|
540
735
|
}
|
|
541
736
|
throw new Error("Invalid API provider");
|
|
@@ -550,12 +745,21 @@ const providers = {
|
|
|
550
745
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
|
551
746
|
}
|
|
552
747
|
};
|
|
553
|
-
function
|
|
748
|
+
function isHostProviderAlias(alias) {
|
|
554
749
|
return isString(alias) && Object.keys(providers).includes(alias);
|
|
555
750
|
}
|
|
556
|
-
function
|
|
751
|
+
function isHostProviderBuilder(builder) {
|
|
557
752
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
|
558
753
|
}
|
|
754
|
+
function parseProviderString(provider = "production") {
|
|
755
|
+
if (isHostProviderAlias(provider)) {
|
|
756
|
+
return provider;
|
|
757
|
+
}
|
|
758
|
+
const [main, workspaces] = provider.split(",");
|
|
759
|
+
if (!main || !workspaces)
|
|
760
|
+
return null;
|
|
761
|
+
return { main, workspaces };
|
|
762
|
+
}
|
|
559
763
|
|
|
560
764
|
var __accessCheck$7 = (obj, member, msg) => {
|
|
561
765
|
if (!member.has(obj))
|
|
@@ -581,7 +785,8 @@ class XataApiClient {
|
|
|
581
785
|
__privateAdd$7(this, _extraProps, void 0);
|
|
582
786
|
__privateAdd$7(this, _namespaces, {});
|
|
583
787
|
const provider = options.host ?? "production";
|
|
584
|
-
const apiKey = options
|
|
788
|
+
const apiKey = options.apiKey ?? getAPIKey();
|
|
789
|
+
const trace = options.trace ?? defaultTrace;
|
|
585
790
|
if (!apiKey) {
|
|
586
791
|
throw new Error("Could not resolve a valid apiKey");
|
|
587
792
|
}
|
|
@@ -589,7 +794,8 @@ class XataApiClient {
|
|
|
589
794
|
apiUrl: getHostUrl(provider, "main"),
|
|
590
795
|
workspacesApiUrl: getHostUrl(provider, "workspaces"),
|
|
591
796
|
fetchImpl: getFetchImplementation(options.fetch),
|
|
592
|
-
apiKey
|
|
797
|
+
apiKey,
|
|
798
|
+
trace
|
|
593
799
|
});
|
|
594
800
|
}
|
|
595
801
|
get user() {
|
|
@@ -622,6 +828,16 @@ class XataApiClient {
|
|
|
622
828
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
|
623
829
|
return __privateGet$7(this, _namespaces).records;
|
|
624
830
|
}
|
|
831
|
+
get migrationRequests() {
|
|
832
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
|
833
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
|
834
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
|
835
|
+
}
|
|
836
|
+
get branchSchema() {
|
|
837
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
|
838
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
|
839
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
|
840
|
+
}
|
|
625
841
|
}
|
|
626
842
|
_extraProps = new WeakMap();
|
|
627
843
|
_namespaces = new WeakMap();
|
|
@@ -761,6 +977,19 @@ class DatabaseApi {
|
|
|
761
977
|
...this.extraProps
|
|
762
978
|
});
|
|
763
979
|
}
|
|
980
|
+
getDatabaseMetadata(workspace, dbName) {
|
|
981
|
+
return operationsByTag.database.getDatabaseMetadata({
|
|
982
|
+
pathParams: { workspace, dbName },
|
|
983
|
+
...this.extraProps
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
|
987
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
|
988
|
+
pathParams: { workspace, dbName },
|
|
989
|
+
body: options,
|
|
990
|
+
...this.extraProps
|
|
991
|
+
});
|
|
992
|
+
}
|
|
764
993
|
getGitBranchesMapping(workspace, dbName) {
|
|
765
994
|
return operationsByTag.database.getGitBranchesMapping({
|
|
766
995
|
pathParams: { workspace, dbName },
|
|
@@ -832,27 +1061,6 @@ class BranchApi {
|
|
|
832
1061
|
...this.extraProps
|
|
833
1062
|
});
|
|
834
1063
|
}
|
|
835
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
|
836
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
|
837
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
838
|
-
body: options,
|
|
839
|
-
...this.extraProps
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
|
843
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
|
844
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
845
|
-
body: migrationPlan,
|
|
846
|
-
...this.extraProps
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
|
850
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
|
851
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
852
|
-
body: schema,
|
|
853
|
-
...this.extraProps
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
1064
|
getBranchStats(workspace, database, branch) {
|
|
857
1065
|
return operationsByTag.branch.getBranchStats({
|
|
858
1066
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
@@ -1008,6 +1216,138 @@ class RecordsApi {
|
|
|
1008
1216
|
...this.extraProps
|
|
1009
1217
|
});
|
|
1010
1218
|
}
|
|
1219
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
|
1220
|
+
return operationsByTag.records.summarizeTable({
|
|
1221
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
|
1222
|
+
body: query,
|
|
1223
|
+
...this.extraProps
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
class MigrationRequestsApi {
|
|
1228
|
+
constructor(extraProps) {
|
|
1229
|
+
this.extraProps = extraProps;
|
|
1230
|
+
}
|
|
1231
|
+
queryMigrationRequests(workspace, database, options = {}) {
|
|
1232
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
|
1233
|
+
pathParams: { workspace, dbName: database },
|
|
1234
|
+
body: options,
|
|
1235
|
+
...this.extraProps
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
createMigrationRequest(workspace, database, options) {
|
|
1239
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
|
1240
|
+
pathParams: { workspace, dbName: database },
|
|
1241
|
+
body: options,
|
|
1242
|
+
...this.extraProps
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
|
1246
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
|
1247
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1248
|
+
...this.extraProps
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
|
1252
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
|
1253
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1254
|
+
body: options,
|
|
1255
|
+
...this.extraProps
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
|
1259
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
|
1260
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1261
|
+
body: options,
|
|
1262
|
+
...this.extraProps
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
|
1266
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
|
1267
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1268
|
+
...this.extraProps
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
|
1272
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
|
1273
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1274
|
+
...this.extraProps
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
|
1278
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
|
1279
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
|
1280
|
+
...this.extraProps
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
class BranchSchemaApi {
|
|
1285
|
+
constructor(extraProps) {
|
|
1286
|
+
this.extraProps = extraProps;
|
|
1287
|
+
}
|
|
1288
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
|
1289
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
|
1290
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1291
|
+
body: options,
|
|
1292
|
+
...this.extraProps
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
|
1296
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
|
1297
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1298
|
+
body: migrationPlan,
|
|
1299
|
+
...this.extraProps
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
|
1303
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
|
1304
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1305
|
+
body: schema,
|
|
1306
|
+
...this.extraProps
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
|
1310
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
|
1311
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1312
|
+
body: { schema },
|
|
1313
|
+
...this.extraProps
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
|
1317
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
|
1318
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
|
1319
|
+
body: { schema },
|
|
1320
|
+
...this.extraProps
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
|
1324
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
|
1325
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1326
|
+
body: migration,
|
|
1327
|
+
...this.extraProps
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1330
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
|
1331
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
|
1332
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1333
|
+
body: migration,
|
|
1334
|
+
...this.extraProps
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
|
1338
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
|
1339
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1340
|
+
body: { edits },
|
|
1341
|
+
...this.extraProps
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
|
1345
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
|
1346
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
|
1347
|
+
body: options,
|
|
1348
|
+
...this.extraProps
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1011
1351
|
}
|
|
1012
1352
|
|
|
1013
1353
|
class XataApiPlugin {
|
|
@@ -1020,6 +1360,13 @@ class XataApiPlugin {
|
|
|
1020
1360
|
class XataPlugin {
|
|
1021
1361
|
}
|
|
1022
1362
|
|
|
1363
|
+
function generateUUID() {
|
|
1364
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
1365
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
1366
|
+
return v.toString(16);
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1023
1370
|
var __accessCheck$6 = (obj, member, msg) => {
|
|
1024
1371
|
if (!member.has(obj))
|
|
1025
1372
|
throw TypeError("Cannot " + msg);
|
|
@@ -1133,9 +1480,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
|
1133
1480
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1134
1481
|
return value;
|
|
1135
1482
|
};
|
|
1136
|
-
var
|
|
1483
|
+
var __privateMethod$3 = (obj, member, method) => {
|
|
1484
|
+
__accessCheck$5(obj, member, "access private method");
|
|
1485
|
+
return method;
|
|
1486
|
+
};
|
|
1487
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
|
1137
1488
|
const _Query = class {
|
|
1138
1489
|
constructor(repository, table, data, rawParent) {
|
|
1490
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
|
1139
1491
|
__privateAdd$5(this, _table$1, void 0);
|
|
1140
1492
|
__privateAdd$5(this, _repository, void 0);
|
|
1141
1493
|
__privateAdd$5(this, _data, { filter: {} });
|
|
@@ -1192,15 +1544,18 @@ const _Query = class {
|
|
|
1192
1544
|
}
|
|
1193
1545
|
filter(a, b) {
|
|
1194
1546
|
if (arguments.length === 1) {
|
|
1195
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
|
1547
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
|
1548
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
|
1549
|
+
}));
|
|
1196
1550
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
|
1197
1551
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1198
1552
|
} else {
|
|
1199
|
-
const
|
|
1553
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
|
1554
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
|
1200
1555
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
|
1201
1556
|
}
|
|
1202
1557
|
}
|
|
1203
|
-
sort(column, direction) {
|
|
1558
|
+
sort(column, direction = "asc") {
|
|
1204
1559
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
|
1205
1560
|
const sort = [...originalSort, { column, direction }];
|
|
1206
1561
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
|
|
@@ -1234,11 +1589,20 @@ const _Query = class {
|
|
|
1234
1589
|
}
|
|
1235
1590
|
}
|
|
1236
1591
|
async getMany(options = {}) {
|
|
1237
|
-
const
|
|
1592
|
+
const { pagination = {}, ...rest } = options;
|
|
1593
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
|
1594
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
|
1595
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
|
1596
|
+
const results = [...page.records];
|
|
1597
|
+
while (page.hasNextPage() && results.length < size) {
|
|
1598
|
+
page = await page.nextPage();
|
|
1599
|
+
results.push(...page.records);
|
|
1600
|
+
}
|
|
1238
1601
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
|
1239
1602
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
|
1240
1603
|
}
|
|
1241
|
-
|
|
1604
|
+
const array = new RecordArray(page, results.slice(0, size));
|
|
1605
|
+
return array;
|
|
1242
1606
|
}
|
|
1243
1607
|
async getAll(options = {}) {
|
|
1244
1608
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
|
@@ -1252,6 +1616,12 @@ const _Query = class {
|
|
|
1252
1616
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
|
1253
1617
|
return records[0] ?? null;
|
|
1254
1618
|
}
|
|
1619
|
+
async getFirstOrThrow(options = {}) {
|
|
1620
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
|
1621
|
+
if (records[0] === void 0)
|
|
1622
|
+
throw new Error("No results found.");
|
|
1623
|
+
return records[0];
|
|
1624
|
+
}
|
|
1255
1625
|
cache(ttl) {
|
|
1256
1626
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
|
1257
1627
|
}
|
|
@@ -1275,6 +1645,17 @@ let Query = _Query;
|
|
|
1275
1645
|
_table$1 = new WeakMap();
|
|
1276
1646
|
_repository = new WeakMap();
|
|
1277
1647
|
_data = new WeakMap();
|
|
1648
|
+
_cleanFilterConstraint = new WeakSet();
|
|
1649
|
+
cleanFilterConstraint_fn = function(column, value) {
|
|
1650
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
|
1651
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
|
1652
|
+
return { $includes: value };
|
|
1653
|
+
}
|
|
1654
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
|
1655
|
+
return value.id;
|
|
1656
|
+
}
|
|
1657
|
+
return value;
|
|
1658
|
+
};
|
|
1278
1659
|
function cleanParent(data, parent) {
|
|
1279
1660
|
if (isCursorPaginationOptions(data.pagination)) {
|
|
1280
1661
|
return { ...parent, sorting: void 0, filter: void 0 };
|
|
@@ -1336,12 +1717,16 @@ var __privateMethod$2 = (obj, member, method) => {
|
|
|
1336
1717
|
__accessCheck$4(obj, member, "access private method");
|
|
1337
1718
|
return method;
|
|
1338
1719
|
};
|
|
1339
|
-
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
|
1720
|
+
var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
|
|
1340
1721
|
class Repository extends Query {
|
|
1341
1722
|
}
|
|
1342
1723
|
class RestRepository extends Query {
|
|
1343
1724
|
constructor(options) {
|
|
1344
|
-
super(
|
|
1725
|
+
super(
|
|
1726
|
+
null,
|
|
1727
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
|
1728
|
+
{}
|
|
1729
|
+
);
|
|
1345
1730
|
__privateAdd$4(this, _insertRecordWithoutId);
|
|
1346
1731
|
__privateAdd$4(this, _insertRecordWithId);
|
|
1347
1732
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
|
@@ -1356,168 +1741,255 @@ class RestRepository extends Query {
|
|
|
1356
1741
|
__privateAdd$4(this, _db, void 0);
|
|
1357
1742
|
__privateAdd$4(this, _cache, void 0);
|
|
1358
1743
|
__privateAdd$4(this, _schemaTables$2, void 0);
|
|
1744
|
+
__privateAdd$4(this, _trace, void 0);
|
|
1359
1745
|
__privateSet$4(this, _table, options.table);
|
|
1360
|
-
__privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
|
|
1361
1746
|
__privateSet$4(this, _db, options.db);
|
|
1362
1747
|
__privateSet$4(this, _cache, options.pluginOptions.cache);
|
|
1363
1748
|
__privateSet$4(this, _schemaTables$2, options.schemaTables);
|
|
1749
|
+
__privateSet$4(this, _getFetchProps, async () => {
|
|
1750
|
+
const props = await options.pluginOptions.getFetchProps();
|
|
1751
|
+
return { ...props, sessionID: generateUUID() };
|
|
1752
|
+
});
|
|
1753
|
+
const trace = options.pluginOptions.trace ?? defaultTrace;
|
|
1754
|
+
__privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
|
|
1755
|
+
return trace(name, fn, {
|
|
1756
|
+
...options2,
|
|
1757
|
+
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
|
1758
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
|
1759
|
+
[TraceAttributes.VERSION]: VERSION
|
|
1760
|
+
});
|
|
1761
|
+
});
|
|
1364
1762
|
}
|
|
1365
1763
|
async create(a, b, c) {
|
|
1366
|
-
|
|
1367
|
-
if (a
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
if (a
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
if (a.id
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1764
|
+
return __privateGet$4(this, _trace).call(this, "create", async () => {
|
|
1765
|
+
if (Array.isArray(a)) {
|
|
1766
|
+
if (a.length === 0)
|
|
1767
|
+
return [];
|
|
1768
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1769
|
+
return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
|
|
1770
|
+
}
|
|
1771
|
+
if (isString(a) && isObject(b)) {
|
|
1772
|
+
if (a === "")
|
|
1773
|
+
throw new Error("The id can't be empty");
|
|
1774
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1775
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
|
|
1776
|
+
}
|
|
1777
|
+
if (isObject(a) && isString(a.id)) {
|
|
1778
|
+
if (a.id === "")
|
|
1779
|
+
throw new Error("The id can't be empty");
|
|
1780
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1781
|
+
return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1782
|
+
}
|
|
1783
|
+
if (isObject(a)) {
|
|
1784
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1785
|
+
return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
|
|
1786
|
+
}
|
|
1787
|
+
throw new Error("Invalid arguments for create method");
|
|
1788
|
+
});
|
|
1389
1789
|
}
|
|
1390
1790
|
async read(a, b) {
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
if (a
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
acc
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1791
|
+
return __privateGet$4(this, _trace).call(this, "read", async () => {
|
|
1792
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1793
|
+
if (Array.isArray(a)) {
|
|
1794
|
+
if (a.length === 0)
|
|
1795
|
+
return [];
|
|
1796
|
+
const ids = a.map((item) => extractId(item));
|
|
1797
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
|
1798
|
+
const dictionary = finalObjects.reduce((acc, object) => {
|
|
1799
|
+
acc[object.id] = object;
|
|
1800
|
+
return acc;
|
|
1801
|
+
}, {});
|
|
1802
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
|
1803
|
+
}
|
|
1804
|
+
const id = extractId(a);
|
|
1805
|
+
if (id) {
|
|
1806
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1807
|
+
try {
|
|
1808
|
+
const response = await getRecord({
|
|
1809
|
+
pathParams: {
|
|
1810
|
+
workspace: "{workspaceId}",
|
|
1811
|
+
dbBranchName: "{dbBranch}",
|
|
1812
|
+
tableName: __privateGet$4(this, _table),
|
|
1813
|
+
recordId: id
|
|
1814
|
+
},
|
|
1815
|
+
queryParams: { columns },
|
|
1816
|
+
...fetchProps
|
|
1817
|
+
});
|
|
1818
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1819
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
1820
|
+
} catch (e) {
|
|
1821
|
+
if (isObject(e) && e.status === 404) {
|
|
1822
|
+
return null;
|
|
1823
|
+
}
|
|
1824
|
+
throw e;
|
|
1417
1825
|
}
|
|
1418
|
-
throw e;
|
|
1419
1826
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1827
|
+
return null;
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
async readOrThrow(a, b) {
|
|
1831
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
|
1832
|
+
const result = await this.read(a, b);
|
|
1833
|
+
if (Array.isArray(result)) {
|
|
1834
|
+
const missingIds = compact(
|
|
1835
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
1836
|
+
);
|
|
1837
|
+
if (missingIds.length > 0) {
|
|
1838
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
1839
|
+
}
|
|
1840
|
+
return result;
|
|
1841
|
+
}
|
|
1842
|
+
if (result === null) {
|
|
1843
|
+
const id = extractId(a) ?? "unknown";
|
|
1844
|
+
throw new Error(`Record with id ${id} not found`);
|
|
1845
|
+
}
|
|
1846
|
+
return result;
|
|
1847
|
+
});
|
|
1422
1848
|
}
|
|
1423
1849
|
async update(a, b, c) {
|
|
1424
|
-
|
|
1425
|
-
if (a
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1850
|
+
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
|
1851
|
+
if (Array.isArray(a)) {
|
|
1852
|
+
if (a.length === 0)
|
|
1853
|
+
return [];
|
|
1854
|
+
if (a.length > 100) {
|
|
1855
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1856
|
+
}
|
|
1857
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1858
|
+
return Promise.all(a.map((object) => this.update(object, columns)));
|
|
1429
1859
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1860
|
+
if (isString(a) && isObject(b)) {
|
|
1861
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1862
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
|
|
1863
|
+
}
|
|
1864
|
+
if (isObject(a) && isString(a.id)) {
|
|
1865
|
+
const columns = isStringArray(b) ? b : void 0;
|
|
1866
|
+
return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1867
|
+
}
|
|
1868
|
+
throw new Error("Invalid arguments for update method");
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
async updateOrThrow(a, b, c) {
|
|
1872
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
|
1873
|
+
const result = await this.update(a, b, c);
|
|
1874
|
+
if (Array.isArray(result)) {
|
|
1875
|
+
const missingIds = compact(
|
|
1876
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
1877
|
+
);
|
|
1878
|
+
if (missingIds.length > 0) {
|
|
1879
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
1880
|
+
}
|
|
1881
|
+
return result;
|
|
1882
|
+
}
|
|
1883
|
+
if (result === null) {
|
|
1884
|
+
const id = extractId(a) ?? "unknown";
|
|
1885
|
+
throw new Error(`Record with id ${id} not found`);
|
|
1886
|
+
}
|
|
1887
|
+
return result;
|
|
1888
|
+
});
|
|
1442
1889
|
}
|
|
1443
1890
|
async createOrUpdate(a, b, c) {
|
|
1444
|
-
|
|
1445
|
-
if (a
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1891
|
+
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
|
1892
|
+
if (Array.isArray(a)) {
|
|
1893
|
+
if (a.length === 0)
|
|
1894
|
+
return [];
|
|
1895
|
+
if (a.length > 100) {
|
|
1896
|
+
console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
|
|
1897
|
+
}
|
|
1898
|
+
const columns = isStringArray(b) ? b : ["*"];
|
|
1899
|
+
return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
|
|
1449
1900
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
if (isString(a) && isObject(b)) {
|
|
1454
|
-
const columns = isStringArray(c) ? c : void 0;
|
|
1455
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
|
1456
|
-
}
|
|
1457
|
-
if (isObject(a) && isString(a.id)) {
|
|
1458
|
-
const columns = isStringArray(c) ? c : void 0;
|
|
1459
|
-
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1460
|
-
}
|
|
1461
|
-
throw new Error("Invalid arguments for createOrUpdate method");
|
|
1462
|
-
}
|
|
1463
|
-
async delete(a) {
|
|
1464
|
-
if (Array.isArray(a)) {
|
|
1465
|
-
if (a.length === 0)
|
|
1466
|
-
return;
|
|
1467
|
-
if (a.length > 100) {
|
|
1468
|
-
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
|
1901
|
+
if (isString(a) && isObject(b)) {
|
|
1902
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1903
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
|
|
1469
1904
|
}
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1905
|
+
if (isObject(a) && isString(a.id)) {
|
|
1906
|
+
const columns = isStringArray(c) ? c : void 0;
|
|
1907
|
+
return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
|
|
1908
|
+
}
|
|
1909
|
+
throw new Error("Invalid arguments for createOrUpdate method");
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
async delete(a, b) {
|
|
1913
|
+
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
|
1914
|
+
if (Array.isArray(a)) {
|
|
1915
|
+
if (a.length === 0)
|
|
1916
|
+
return [];
|
|
1917
|
+
if (a.length > 100) {
|
|
1918
|
+
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
|
1919
|
+
}
|
|
1920
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
|
1921
|
+
}
|
|
1922
|
+
if (isString(a)) {
|
|
1923
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
|
1924
|
+
}
|
|
1925
|
+
if (isObject(a) && isString(a.id)) {
|
|
1926
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
|
1927
|
+
}
|
|
1928
|
+
throw new Error("Invalid arguments for delete method");
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
async deleteOrThrow(a, b) {
|
|
1932
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
|
1933
|
+
const result = await this.delete(a, b);
|
|
1934
|
+
if (Array.isArray(result)) {
|
|
1935
|
+
const missingIds = compact(
|
|
1936
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
|
1937
|
+
);
|
|
1938
|
+
if (missingIds.length > 0) {
|
|
1939
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
|
1940
|
+
}
|
|
1941
|
+
return result;
|
|
1942
|
+
} else if (result === null) {
|
|
1943
|
+
const id = extractId(a) ?? "unknown";
|
|
1944
|
+
throw new Error(`Record with id ${id} not found`);
|
|
1945
|
+
}
|
|
1946
|
+
return result;
|
|
1947
|
+
});
|
|
1482
1948
|
}
|
|
1483
1949
|
async search(query, options = {}) {
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1950
|
+
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
|
1951
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1952
|
+
const { records } = await searchTable({
|
|
1953
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
|
1954
|
+
body: {
|
|
1955
|
+
query,
|
|
1956
|
+
fuzziness: options.fuzziness,
|
|
1957
|
+
prefix: options.prefix,
|
|
1958
|
+
highlight: options.highlight,
|
|
1959
|
+
filter: options.filter,
|
|
1960
|
+
boosters: options.boosters
|
|
1961
|
+
},
|
|
1962
|
+
...fetchProps
|
|
1963
|
+
});
|
|
1964
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1965
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
|
1496
1966
|
});
|
|
1497
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1498
|
-
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
|
1499
1967
|
}
|
|
1500
1968
|
async query(query) {
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1969
|
+
return __privateGet$4(this, _trace).call(this, "query", async () => {
|
|
1970
|
+
const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
|
|
1971
|
+
if (cacheQuery)
|
|
1972
|
+
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
|
1973
|
+
const data = query.getQueryOptions();
|
|
1974
|
+
const body = {
|
|
1975
|
+
filter: cleanFilter(data.filter),
|
|
1976
|
+
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
|
1977
|
+
page: data.pagination,
|
|
1978
|
+
columns: data.columns
|
|
1979
|
+
};
|
|
1980
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1981
|
+
const { meta, records: objects } = await queryTable({
|
|
1982
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
|
1983
|
+
body,
|
|
1984
|
+
...fetchProps
|
|
1985
|
+
});
|
|
1986
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1987
|
+
const records = objects.map(
|
|
1988
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
|
1989
|
+
);
|
|
1990
|
+
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
1991
|
+
return new Page(query, meta, records);
|
|
1516
1992
|
});
|
|
1517
|
-
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1518
|
-
const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
|
|
1519
|
-
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
|
1520
|
-
return new Page(query, meta, records);
|
|
1521
1993
|
}
|
|
1522
1994
|
}
|
|
1523
1995
|
_table = new WeakMap();
|
|
@@ -1525,6 +1997,7 @@ _getFetchProps = new WeakMap();
|
|
|
1525
1997
|
_db = new WeakMap();
|
|
1526
1998
|
_cache = new WeakMap();
|
|
1527
1999
|
_schemaTables$2 = new WeakMap();
|
|
2000
|
+
_trace = new WeakMap();
|
|
1528
2001
|
_insertRecordWithoutId = new WeakSet();
|
|
1529
2002
|
insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1530
2003
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
@@ -1540,7 +2013,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
|
1540
2013
|
...fetchProps
|
|
1541
2014
|
});
|
|
1542
2015
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1543
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
2016
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
1544
2017
|
};
|
|
1545
2018
|
_insertRecordWithId = new WeakSet();
|
|
1546
2019
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
@@ -1558,7 +2031,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
|
1558
2031
|
...fetchProps
|
|
1559
2032
|
});
|
|
1560
2033
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1561
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
2034
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
1562
2035
|
};
|
|
1563
2036
|
_bulkInsertTableRecords = new WeakSet();
|
|
1564
2037
|
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
@@ -1574,20 +2047,27 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
|
1574
2047
|
throw new Error("Request included columns but server didn't include them");
|
|
1575
2048
|
}
|
|
1576
2049
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1577
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
|
2050
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
|
1578
2051
|
};
|
|
1579
2052
|
_updateRecordWithID = new WeakSet();
|
|
1580
2053
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1581
2054
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1582
2055
|
const record = transformObjectLinks(object);
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
2056
|
+
try {
|
|
2057
|
+
const response = await updateRecordWithID({
|
|
2058
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
|
2059
|
+
queryParams: { columns },
|
|
2060
|
+
body: record,
|
|
2061
|
+
...fetchProps
|
|
2062
|
+
});
|
|
2063
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2064
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2065
|
+
} catch (e) {
|
|
2066
|
+
if (isObject(e) && e.status === 404) {
|
|
2067
|
+
return null;
|
|
2068
|
+
}
|
|
2069
|
+
throw e;
|
|
2070
|
+
}
|
|
1591
2071
|
};
|
|
1592
2072
|
_upsertRecordWithID = new WeakSet();
|
|
1593
2073
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
@@ -1599,15 +2079,25 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
|
1599
2079
|
...fetchProps
|
|
1600
2080
|
});
|
|
1601
2081
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
1602
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
|
2082
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
1603
2083
|
};
|
|
1604
2084
|
_deleteRecord = new WeakSet();
|
|
1605
|
-
deleteRecord_fn = async function(recordId) {
|
|
2085
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
1606
2086
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
2087
|
+
try {
|
|
2088
|
+
const response = await deleteRecord({
|
|
2089
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
|
2090
|
+
queryParams: { columns },
|
|
2091
|
+
...fetchProps
|
|
2092
|
+
});
|
|
2093
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
|
2094
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
|
2095
|
+
} catch (e) {
|
|
2096
|
+
if (isObject(e) && e.status === 404) {
|
|
2097
|
+
return null;
|
|
2098
|
+
}
|
|
2099
|
+
throw e;
|
|
2100
|
+
}
|
|
1611
2101
|
};
|
|
1612
2102
|
_setCacheQuery = new WeakSet();
|
|
1613
2103
|
setCacheQuery_fn = async function(query, meta, records) {
|
|
@@ -1644,7 +2134,7 @@ const transformObjectLinks = (object) => {
|
|
|
1644
2134
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
|
1645
2135
|
}, {});
|
|
1646
2136
|
};
|
|
1647
|
-
const initObject = (db, schemaTables, table, object) => {
|
|
2137
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
|
1648
2138
|
const result = {};
|
|
1649
2139
|
const { xata, ...rest } = object ?? {};
|
|
1650
2140
|
Object.assign(result, rest);
|
|
@@ -1652,6 +2142,8 @@ const initObject = (db, schemaTables, table, object) => {
|
|
|
1652
2142
|
if (!columns)
|
|
1653
2143
|
console.error(`Table ${table} not found in schema`);
|
|
1654
2144
|
for (const column of columns ?? []) {
|
|
2145
|
+
if (!isValidColumn(selectedColumns, column))
|
|
2146
|
+
continue;
|
|
1655
2147
|
const value = result[column.name];
|
|
1656
2148
|
switch (column.type) {
|
|
1657
2149
|
case "datetime": {
|
|
@@ -1668,10 +2160,28 @@ const initObject = (db, schemaTables, table, object) => {
|
|
|
1668
2160
|
if (!linkTable) {
|
|
1669
2161
|
console.error(`Failed to parse link for field ${column.name}`);
|
|
1670
2162
|
} else if (isObject(value)) {
|
|
1671
|
-
|
|
2163
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
|
2164
|
+
if (item === column.name) {
|
|
2165
|
+
return [...acc, "*"];
|
|
2166
|
+
}
|
|
2167
|
+
if (item.startsWith(`${column.name}.`)) {
|
|
2168
|
+
const [, ...path] = item.split(".");
|
|
2169
|
+
return [...acc, path.join(".")];
|
|
2170
|
+
}
|
|
2171
|
+
return acc;
|
|
2172
|
+
}, []);
|
|
2173
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
|
2174
|
+
} else {
|
|
2175
|
+
result[column.name] = null;
|
|
1672
2176
|
}
|
|
1673
2177
|
break;
|
|
1674
2178
|
}
|
|
2179
|
+
default:
|
|
2180
|
+
result[column.name] = value ?? null;
|
|
2181
|
+
if (column.notNull === true && value === null) {
|
|
2182
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
|
2183
|
+
}
|
|
2184
|
+
break;
|
|
1675
2185
|
}
|
|
1676
2186
|
}
|
|
1677
2187
|
result.read = function(columns2) {
|
|
@@ -1695,6 +2205,28 @@ const initObject = (db, schemaTables, table, object) => {
|
|
|
1695
2205
|
function isResponseWithRecords(value) {
|
|
1696
2206
|
return isObject(value) && Array.isArray(value.records);
|
|
1697
2207
|
}
|
|
2208
|
+
function extractId(value) {
|
|
2209
|
+
if (isString(value))
|
|
2210
|
+
return value;
|
|
2211
|
+
if (isObject(value) && isString(value.id))
|
|
2212
|
+
return value.id;
|
|
2213
|
+
return void 0;
|
|
2214
|
+
}
|
|
2215
|
+
function cleanFilter(filter) {
|
|
2216
|
+
if (!filter)
|
|
2217
|
+
return void 0;
|
|
2218
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
|
2219
|
+
return values.length > 0 ? filter : void 0;
|
|
2220
|
+
}
|
|
2221
|
+
function isValidColumn(columns, column) {
|
|
2222
|
+
if (columns.includes("*"))
|
|
2223
|
+
return true;
|
|
2224
|
+
if (column.type === "link") {
|
|
2225
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
|
2226
|
+
return linkColumns.length > 0;
|
|
2227
|
+
}
|
|
2228
|
+
return columns.includes(column.name);
|
|
2229
|
+
}
|
|
1698
2230
|
|
|
1699
2231
|
var __accessCheck$3 = (obj, member, msg) => {
|
|
1700
2232
|
if (!member.has(obj))
|
|
@@ -1745,18 +2277,25 @@ class SimpleCache {
|
|
|
1745
2277
|
}
|
|
1746
2278
|
_map = new WeakMap();
|
|
1747
2279
|
|
|
1748
|
-
const
|
|
1749
|
-
const
|
|
1750
|
-
const
|
|
1751
|
-
const
|
|
1752
|
-
const
|
|
1753
|
-
const
|
|
2280
|
+
const greaterThan = (value) => ({ $gt: value });
|
|
2281
|
+
const gt = greaterThan;
|
|
2282
|
+
const greaterThanEquals = (value) => ({ $ge: value });
|
|
2283
|
+
const greaterEquals = greaterThanEquals;
|
|
2284
|
+
const gte = greaterThanEquals;
|
|
2285
|
+
const ge = greaterThanEquals;
|
|
2286
|
+
const lessThan = (value) => ({ $lt: value });
|
|
2287
|
+
const lt = lessThan;
|
|
2288
|
+
const lessThanEquals = (value) => ({ $le: value });
|
|
2289
|
+
const lessEquals = lessThanEquals;
|
|
2290
|
+
const lte = lessThanEquals;
|
|
2291
|
+
const le = lessThanEquals;
|
|
1754
2292
|
const exists = (column) => ({ $exists: column });
|
|
1755
2293
|
const notExists = (column) => ({ $notExists: column });
|
|
1756
2294
|
const startsWith = (value) => ({ $startsWith: value });
|
|
1757
2295
|
const endsWith = (value) => ({ $endsWith: value });
|
|
1758
2296
|
const pattern = (value) => ({ $pattern: value });
|
|
1759
2297
|
const is = (value) => ({ $is: value });
|
|
2298
|
+
const equals = is;
|
|
1760
2299
|
const isNot = (value) => ({ $isNot: value });
|
|
1761
2300
|
const contains = (value) => ({ $contains: value });
|
|
1762
2301
|
const includes = (value) => ({ $includes: value });
|
|
@@ -1853,7 +2392,7 @@ class SearchPlugin extends XataPlugin {
|
|
|
1853
2392
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
|
1854
2393
|
return records.map((record) => {
|
|
1855
2394
|
const { table = "orphan" } = record.xata;
|
|
1856
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
|
2395
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
|
1857
2396
|
});
|
|
1858
2397
|
},
|
|
1859
2398
|
byTable: async (query, options = {}) => {
|
|
@@ -1862,7 +2401,7 @@ class SearchPlugin extends XataPlugin {
|
|
|
1862
2401
|
return records.reduce((acc, record) => {
|
|
1863
2402
|
const { table = "orphan" } = record.xata;
|
|
1864
2403
|
const items = acc[table] ?? [];
|
|
1865
|
-
const item = initObject(this.db, schemaTables, table, record);
|
|
2404
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
|
1866
2405
|
return { ...acc, [table]: [...items, item] };
|
|
1867
2406
|
}, {});
|
|
1868
2407
|
}
|
|
@@ -1933,7 +2472,8 @@ async function resolveXataBranch(gitBranch, options) {
|
|
|
1933
2472
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1934
2473
|
workspacesApiUrl: `${protocol}//${host}`,
|
|
1935
2474
|
pathParams: { dbName, workspace },
|
|
1936
|
-
queryParams: { gitBranch, fallbackBranch }
|
|
2475
|
+
queryParams: { gitBranch, fallbackBranch },
|
|
2476
|
+
trace: defaultTrace
|
|
1937
2477
|
});
|
|
1938
2478
|
return branch;
|
|
1939
2479
|
}
|
|
@@ -1957,7 +2497,8 @@ async function getDatabaseBranch(branch, options) {
|
|
|
1957
2497
|
apiUrl: databaseURL,
|
|
1958
2498
|
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1959
2499
|
workspacesApiUrl: `${protocol}//${host}`,
|
|
1960
|
-
pathParams: { dbBranchName, workspace }
|
|
2500
|
+
pathParams: { dbBranchName, workspace },
|
|
2501
|
+
trace: defaultTrace
|
|
1961
2502
|
});
|
|
1962
2503
|
} catch (err) {
|
|
1963
2504
|
if (isObject(err) && err.status === 404)
|
|
@@ -2009,7 +2550,8 @@ const buildClient = (plugins) => {
|
|
|
2009
2550
|
__privateSet(this, _options, safeOptions);
|
|
2010
2551
|
const pluginOptions = {
|
|
2011
2552
|
getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
|
|
2012
|
-
cache: safeOptions.cache
|
|
2553
|
+
cache: safeOptions.cache,
|
|
2554
|
+
trace: safeOptions.trace
|
|
2013
2555
|
};
|
|
2014
2556
|
const db = new SchemaPlugin(schemaTables).build(pluginOptions);
|
|
2015
2557
|
const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
|
|
@@ -2038,12 +2580,23 @@ const buildClient = (plugins) => {
|
|
|
2038
2580
|
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
2039
2581
|
const apiKey = options?.apiKey || getAPIKey();
|
|
2040
2582
|
const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
|
|
2583
|
+
const trace = options?.trace ?? defaultTrace;
|
|
2041
2584
|
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("
|
|
2585
|
+
if (!apiKey) {
|
|
2586
|
+
throw new Error("Option apiKey is required");
|
|
2044
2587
|
}
|
|
2045
|
-
|
|
2046
|
-
|
|
2588
|
+
if (!databaseURL) {
|
|
2589
|
+
throw new Error("Option databaseURL is required");
|
|
2590
|
+
}
|
|
2591
|
+
return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID() };
|
|
2592
|
+
}, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
|
|
2593
|
+
fetch,
|
|
2594
|
+
apiKey,
|
|
2595
|
+
databaseURL,
|
|
2596
|
+
branch,
|
|
2597
|
+
trace,
|
|
2598
|
+
clientID
|
|
2599
|
+
}) {
|
|
2047
2600
|
const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
|
|
2048
2601
|
if (!branchValue)
|
|
2049
2602
|
throw new Error("Unable to resolve branch value");
|
|
@@ -2053,9 +2606,11 @@ const buildClient = (plugins) => {
|
|
|
2053
2606
|
apiUrl: "",
|
|
2054
2607
|
workspacesApiUrl: (path, params) => {
|
|
2055
2608
|
const hasBranch = params.dbBranchName ?? params.branch;
|
|
2056
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
|
2609
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
|
2057
2610
|
return databaseURL + newPath;
|
|
2058
|
-
}
|
|
2611
|
+
},
|
|
2612
|
+
trace,
|
|
2613
|
+
clientID
|
|
2059
2614
|
};
|
|
2060
2615
|
}, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
|
|
2061
2616
|
if (__privateGet(this, _branch))
|
|
@@ -2078,6 +2633,88 @@ const buildClient = (plugins) => {
|
|
|
2078
2633
|
class BaseClient extends buildClient() {
|
|
2079
2634
|
}
|
|
2080
2635
|
|
|
2636
|
+
const META = "__";
|
|
2637
|
+
const VALUE = "___";
|
|
2638
|
+
class Serializer {
|
|
2639
|
+
constructor() {
|
|
2640
|
+
this.classes = {};
|
|
2641
|
+
}
|
|
2642
|
+
add(clazz) {
|
|
2643
|
+
this.classes[clazz.name] = clazz;
|
|
2644
|
+
}
|
|
2645
|
+
toJSON(data) {
|
|
2646
|
+
function visit(obj) {
|
|
2647
|
+
if (Array.isArray(obj))
|
|
2648
|
+
return obj.map(visit);
|
|
2649
|
+
const type = typeof obj;
|
|
2650
|
+
if (type === "undefined")
|
|
2651
|
+
return { [META]: "undefined" };
|
|
2652
|
+
if (type === "bigint")
|
|
2653
|
+
return { [META]: "bigint", [VALUE]: obj.toString() };
|
|
2654
|
+
if (obj === null || type !== "object")
|
|
2655
|
+
return obj;
|
|
2656
|
+
const constructor = obj.constructor;
|
|
2657
|
+
const o = { [META]: constructor.name };
|
|
2658
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2659
|
+
o[key] = visit(value);
|
|
2660
|
+
}
|
|
2661
|
+
if (constructor === Date)
|
|
2662
|
+
o[VALUE] = obj.toISOString();
|
|
2663
|
+
if (constructor === Map)
|
|
2664
|
+
o[VALUE] = Object.fromEntries(obj);
|
|
2665
|
+
if (constructor === Set)
|
|
2666
|
+
o[VALUE] = [...obj];
|
|
2667
|
+
return o;
|
|
2668
|
+
}
|
|
2669
|
+
return JSON.stringify(visit(data));
|
|
2670
|
+
}
|
|
2671
|
+
fromJSON(json) {
|
|
2672
|
+
return JSON.parse(json, (key, value) => {
|
|
2673
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
2674
|
+
const { [META]: clazz, [VALUE]: val, ...rest } = value;
|
|
2675
|
+
const constructor = this.classes[clazz];
|
|
2676
|
+
if (constructor) {
|
|
2677
|
+
return Object.assign(Object.create(constructor.prototype), rest);
|
|
2678
|
+
}
|
|
2679
|
+
if (clazz === "Date")
|
|
2680
|
+
return new Date(val);
|
|
2681
|
+
if (clazz === "Set")
|
|
2682
|
+
return new Set(val);
|
|
2683
|
+
if (clazz === "Map")
|
|
2684
|
+
return new Map(Object.entries(val));
|
|
2685
|
+
if (clazz === "bigint")
|
|
2686
|
+
return BigInt(val);
|
|
2687
|
+
if (clazz === "undefined")
|
|
2688
|
+
return void 0;
|
|
2689
|
+
return rest;
|
|
2690
|
+
}
|
|
2691
|
+
return value;
|
|
2692
|
+
});
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
const defaultSerializer = new Serializer();
|
|
2696
|
+
const serialize = (data) => {
|
|
2697
|
+
return defaultSerializer.toJSON(data);
|
|
2698
|
+
};
|
|
2699
|
+
const deserialize = (json) => {
|
|
2700
|
+
return defaultSerializer.fromJSON(json);
|
|
2701
|
+
};
|
|
2702
|
+
|
|
2703
|
+
function buildWorkerRunner(config) {
|
|
2704
|
+
return function xataWorker(name, _worker) {
|
|
2705
|
+
return async (...args) => {
|
|
2706
|
+
const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
|
|
2707
|
+
const result = await fetch(url, {
|
|
2708
|
+
method: "POST",
|
|
2709
|
+
headers: { "Content-Type": "application/json" },
|
|
2710
|
+
body: serialize({ args })
|
|
2711
|
+
});
|
|
2712
|
+
const text = await result.text();
|
|
2713
|
+
return deserialize(text);
|
|
2714
|
+
};
|
|
2715
|
+
};
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2081
2718
|
class XataError extends Error {
|
|
2082
2719
|
constructor(message, status) {
|
|
2083
2720
|
super(message);
|
|
@@ -2098,6 +2735,7 @@ exports.Repository = Repository;
|
|
|
2098
2735
|
exports.RestRepository = RestRepository;
|
|
2099
2736
|
exports.SchemaPlugin = SchemaPlugin;
|
|
2100
2737
|
exports.SearchPlugin = SearchPlugin;
|
|
2738
|
+
exports.Serializer = Serializer;
|
|
2101
2739
|
exports.SimpleCache = SimpleCache;
|
|
2102
2740
|
exports.XataApiClient = XataApiClient;
|
|
2103
2741
|
exports.XataApiPlugin = XataApiPlugin;
|
|
@@ -2106,12 +2744,24 @@ exports.XataPlugin = XataPlugin;
|
|
|
2106
2744
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
|
2107
2745
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
|
2108
2746
|
exports.addTableColumn = addTableColumn;
|
|
2747
|
+
exports.aggregateTable = aggregateTable;
|
|
2748
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
|
2109
2749
|
exports.buildClient = buildClient;
|
|
2750
|
+
exports.buildWorkerRunner = buildWorkerRunner;
|
|
2110
2751
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
|
2752
|
+
exports.cPCreateDatabase = cPCreateDatabase;
|
|
2753
|
+
exports.cPDeleteDatabase = cPDeleteDatabase;
|
|
2754
|
+
exports.cPGetCPDatabaseMetadata = cPGetCPDatabaseMetadata;
|
|
2755
|
+
exports.cPGetDatabaseList = cPGetDatabaseList;
|
|
2756
|
+
exports.cPUpdateCPDatabaseMetadata = cPUpdateCPDatabaseMetadata;
|
|
2111
2757
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
|
2758
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
|
2759
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
|
2760
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
|
2112
2761
|
exports.contains = contains;
|
|
2113
2762
|
exports.createBranch = createBranch;
|
|
2114
2763
|
exports.createDatabase = createDatabase;
|
|
2764
|
+
exports.createMigrationRequest = createMigrationRequest;
|
|
2115
2765
|
exports.createTable = createTable;
|
|
2116
2766
|
exports.createUserAPIKey = createUserAPIKey;
|
|
2117
2767
|
exports.createWorkspace = createWorkspace;
|
|
@@ -2123,7 +2773,9 @@ exports.deleteTable = deleteTable;
|
|
|
2123
2773
|
exports.deleteUser = deleteUser;
|
|
2124
2774
|
exports.deleteUserAPIKey = deleteUserAPIKey;
|
|
2125
2775
|
exports.deleteWorkspace = deleteWorkspace;
|
|
2776
|
+
exports.deserialize = deserialize;
|
|
2126
2777
|
exports.endsWith = endsWith;
|
|
2778
|
+
exports.equals = equals;
|
|
2127
2779
|
exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
|
|
2128
2780
|
exports.exists = exists;
|
|
2129
2781
|
exports.ge = ge;
|
|
@@ -2133,13 +2785,18 @@ exports.getBranchList = getBranchList;
|
|
|
2133
2785
|
exports.getBranchMetadata = getBranchMetadata;
|
|
2134
2786
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
|
2135
2787
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
|
2788
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
|
2136
2789
|
exports.getBranchStats = getBranchStats;
|
|
2137
2790
|
exports.getColumn = getColumn;
|
|
2138
2791
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
|
2139
2792
|
exports.getCurrentBranchName = getCurrentBranchName;
|
|
2140
2793
|
exports.getDatabaseList = getDatabaseList;
|
|
2794
|
+
exports.getDatabaseMetadata = getDatabaseMetadata;
|
|
2141
2795
|
exports.getDatabaseURL = getDatabaseURL;
|
|
2142
2796
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
|
2797
|
+
exports.getHostUrl = getHostUrl;
|
|
2798
|
+
exports.getMigrationRequest = getMigrationRequest;
|
|
2799
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
|
2143
2800
|
exports.getRecord = getRecord;
|
|
2144
2801
|
exports.getTableColumns = getTableColumns;
|
|
2145
2802
|
exports.getTableSchema = getTableSchema;
|
|
@@ -2148,6 +2805,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
|
|
|
2148
2805
|
exports.getWorkspace = getWorkspace;
|
|
2149
2806
|
exports.getWorkspaceMembersList = getWorkspaceMembersList;
|
|
2150
2807
|
exports.getWorkspacesList = getWorkspacesList;
|
|
2808
|
+
exports.greaterEquals = greaterEquals;
|
|
2809
|
+
exports.greaterThan = greaterThan;
|
|
2810
|
+
exports.greaterThanEquals = greaterThanEquals;
|
|
2151
2811
|
exports.gt = gt;
|
|
2152
2812
|
exports.gte = gte;
|
|
2153
2813
|
exports.includes = includes;
|
|
@@ -2159,15 +2819,25 @@ exports.insertRecordWithID = insertRecordWithID;
|
|
|
2159
2819
|
exports.inviteWorkspaceMember = inviteWorkspaceMember;
|
|
2160
2820
|
exports.is = is;
|
|
2161
2821
|
exports.isCursorPaginationOptions = isCursorPaginationOptions;
|
|
2822
|
+
exports.isHostProviderAlias = isHostProviderAlias;
|
|
2823
|
+
exports.isHostProviderBuilder = isHostProviderBuilder;
|
|
2162
2824
|
exports.isIdentifiable = isIdentifiable;
|
|
2163
2825
|
exports.isNot = isNot;
|
|
2164
2826
|
exports.isXataRecord = isXataRecord;
|
|
2165
2827
|
exports.le = le;
|
|
2828
|
+
exports.lessEquals = lessEquals;
|
|
2829
|
+
exports.lessThan = lessThan;
|
|
2830
|
+
exports.lessThanEquals = lessThanEquals;
|
|
2831
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
|
2166
2832
|
exports.lt = lt;
|
|
2167
2833
|
exports.lte = lte;
|
|
2834
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
|
2168
2835
|
exports.notExists = notExists;
|
|
2169
2836
|
exports.operationsByTag = operationsByTag;
|
|
2837
|
+
exports.parseProviderString = parseProviderString;
|
|
2170
2838
|
exports.pattern = pattern;
|
|
2839
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
|
2840
|
+
exports.queryMigrationRequests = queryMigrationRequests;
|
|
2171
2841
|
exports.queryTable = queryTable;
|
|
2172
2842
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
|
2173
2843
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
|
@@ -2175,10 +2845,15 @@ exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
|
|
|
2175
2845
|
exports.resolveBranch = resolveBranch;
|
|
2176
2846
|
exports.searchBranch = searchBranch;
|
|
2177
2847
|
exports.searchTable = searchTable;
|
|
2848
|
+
exports.serialize = serialize;
|
|
2178
2849
|
exports.setTableSchema = setTableSchema;
|
|
2179
2850
|
exports.startsWith = startsWith;
|
|
2851
|
+
exports.summarizeTable = summarizeTable;
|
|
2180
2852
|
exports.updateBranchMetadata = updateBranchMetadata;
|
|
2853
|
+
exports.updateBranchSchema = updateBranchSchema;
|
|
2181
2854
|
exports.updateColumn = updateColumn;
|
|
2855
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
|
2856
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
|
2182
2857
|
exports.updateRecordWithID = updateRecordWithID;
|
|
2183
2858
|
exports.updateTable = updateTable;
|
|
2184
2859
|
exports.updateUser = updateUser;
|