@xata.io/client 0.0.0-alpha.vfbd878f → 0.0.0-alpha.vfbe46c7
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 +68 -0
- package/README.md +25 -25
- package/Usage.md +2 -0
- package/dist/index.cjs +568 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2250 -219
- package/dist/index.mjs +548 -153
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
@@ -2,13 +2,11 @@ const defaultTrace = async (_name, fn, _options) => {
|
|
2
2
|
return await fn({
|
3
3
|
setAttributes: () => {
|
4
4
|
return;
|
5
|
-
},
|
6
|
-
onError: () => {
|
7
|
-
return;
|
8
5
|
}
|
9
6
|
});
|
10
7
|
};
|
11
8
|
const TraceAttributes = {
|
9
|
+
KIND: "xata.trace.kind",
|
12
10
|
VERSION: "xata.sdk.version",
|
13
11
|
TABLE: "xata.table",
|
14
12
|
HTTP_REQUEST_ID: "http.request_id",
|
@@ -152,7 +150,7 @@ function getFetchImplementation(userFetch) {
|
|
152
150
|
return fetchImpl;
|
153
151
|
}
|
154
152
|
|
155
|
-
const VERSION = "0.0.0-alpha.
|
153
|
+
const VERSION = "0.0.0-alpha.vfbe46c7";
|
156
154
|
|
157
155
|
class ErrorWithCause extends Error {
|
158
156
|
constructor(message, options) {
|
@@ -203,7 +201,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
203
201
|
}, {});
|
204
202
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
205
203
|
const queryString = query.length > 0 ? `?${query}` : "";
|
206
|
-
|
204
|
+
const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
|
205
|
+
return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
|
206
|
+
}, {});
|
207
|
+
return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
|
207
208
|
};
|
208
209
|
function buildBaseUrl({
|
209
210
|
path,
|
@@ -211,10 +212,10 @@ function buildBaseUrl({
|
|
211
212
|
apiUrl,
|
212
213
|
pathParams
|
213
214
|
}) {
|
214
|
-
if (
|
215
|
+
if (pathParams?.workspace === void 0)
|
215
216
|
return `${apiUrl}${path}`;
|
216
217
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
217
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
218
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
218
219
|
}
|
219
220
|
function hostHeader(url) {
|
220
221
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -232,11 +233,12 @@ async function fetch$1({
|
|
232
233
|
apiKey,
|
233
234
|
apiUrl,
|
234
235
|
workspacesApiUrl,
|
235
|
-
trace
|
236
|
+
trace,
|
237
|
+
signal
|
236
238
|
}) {
|
237
239
|
return trace(
|
238
240
|
`${method.toUpperCase()} ${path}`,
|
239
|
-
async ({ setAttributes
|
241
|
+
async ({ setAttributes }) => {
|
240
242
|
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
241
243
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
242
244
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
@@ -253,7 +255,8 @@ async function fetch$1({
|
|
253
255
|
...headers,
|
254
256
|
...hostHeader(fullUrl),
|
255
257
|
Authorization: `Bearer ${apiKey}`
|
256
|
-
}
|
258
|
+
},
|
259
|
+
signal
|
257
260
|
});
|
258
261
|
if (response.status === 204) {
|
259
262
|
return {};
|
@@ -261,6 +264,7 @@ async function fetch$1({
|
|
261
264
|
const { host, protocol } = parseUrl(response.url);
|
262
265
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
263
266
|
setAttributes({
|
267
|
+
[TraceAttributes.KIND]: "http",
|
264
268
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
265
269
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
266
270
|
[TraceAttributes.HTTP_HOST]: host,
|
@@ -273,9 +277,7 @@ async function fetch$1({
|
|
273
277
|
}
|
274
278
|
throw new FetcherError(response.status, jsonResponse, requestId);
|
275
279
|
} catch (error) {
|
276
|
-
|
277
|
-
onError(fetcherError.message);
|
278
|
-
throw fetcherError;
|
280
|
+
throw new FetcherError(response.status, error, requestId);
|
279
281
|
}
|
280
282
|
},
|
281
283
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
@@ -290,217 +292,302 @@ function parseUrl(url) {
|
|
290
292
|
}
|
291
293
|
}
|
292
294
|
|
293
|
-
const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
|
294
|
-
const updateUser = (variables) => fetch$1({
|
295
|
-
|
296
|
-
|
295
|
+
const getUser = (variables, signal) => fetch$1({ url: "/user", method: "get", ...variables, signal });
|
296
|
+
const updateUser = (variables, signal) => fetch$1({
|
297
|
+
url: "/user",
|
298
|
+
method: "put",
|
299
|
+
...variables,
|
300
|
+
signal
|
301
|
+
});
|
302
|
+
const deleteUser = (variables, signal) => fetch$1({ url: "/user", method: "delete", ...variables, signal });
|
303
|
+
const getUserAPIKeys = (variables, signal) => fetch$1({
|
297
304
|
url: "/user/keys",
|
298
305
|
method: "get",
|
299
|
-
...variables
|
306
|
+
...variables,
|
307
|
+
signal
|
300
308
|
});
|
301
|
-
const createUserAPIKey = (variables) => fetch$1({
|
309
|
+
const createUserAPIKey = (variables, signal) => fetch$1({
|
302
310
|
url: "/user/keys/{keyName}",
|
303
311
|
method: "post",
|
304
|
-
...variables
|
312
|
+
...variables,
|
313
|
+
signal
|
305
314
|
});
|
306
|
-
const deleteUserAPIKey = (variables) => fetch$1({
|
315
|
+
const deleteUserAPIKey = (variables, signal) => fetch$1({
|
307
316
|
url: "/user/keys/{keyName}",
|
308
317
|
method: "delete",
|
309
|
-
...variables
|
318
|
+
...variables,
|
319
|
+
signal
|
310
320
|
});
|
311
|
-
const createWorkspace = (variables) => fetch$1({
|
321
|
+
const createWorkspace = (variables, signal) => fetch$1({
|
312
322
|
url: "/workspaces",
|
313
323
|
method: "post",
|
314
|
-
...variables
|
324
|
+
...variables,
|
325
|
+
signal
|
315
326
|
});
|
316
|
-
const getWorkspacesList = (variables) => fetch$1({
|
327
|
+
const getWorkspacesList = (variables, signal) => fetch$1({
|
317
328
|
url: "/workspaces",
|
318
329
|
method: "get",
|
319
|
-
...variables
|
330
|
+
...variables,
|
331
|
+
signal
|
320
332
|
});
|
321
|
-
const getWorkspace = (variables) => fetch$1({
|
333
|
+
const getWorkspace = (variables, signal) => fetch$1({
|
322
334
|
url: "/workspaces/{workspaceId}",
|
323
335
|
method: "get",
|
324
|
-
...variables
|
336
|
+
...variables,
|
337
|
+
signal
|
325
338
|
});
|
326
|
-
const updateWorkspace = (variables) => fetch$1({
|
339
|
+
const updateWorkspace = (variables, signal) => fetch$1({
|
327
340
|
url: "/workspaces/{workspaceId}",
|
328
341
|
method: "put",
|
329
|
-
...variables
|
342
|
+
...variables,
|
343
|
+
signal
|
330
344
|
});
|
331
|
-
const deleteWorkspace = (variables) => fetch$1({
|
345
|
+
const deleteWorkspace = (variables, signal) => fetch$1({
|
332
346
|
url: "/workspaces/{workspaceId}",
|
333
347
|
method: "delete",
|
334
|
-
...variables
|
348
|
+
...variables,
|
349
|
+
signal
|
335
350
|
});
|
336
|
-
const getWorkspaceMembersList = (variables) => fetch$1({
|
351
|
+
const getWorkspaceMembersList = (variables, signal) => fetch$1({
|
337
352
|
url: "/workspaces/{workspaceId}/members",
|
338
353
|
method: "get",
|
339
|
-
...variables
|
354
|
+
...variables,
|
355
|
+
signal
|
340
356
|
});
|
341
|
-
const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
|
342
|
-
const removeWorkspaceMember = (variables) => fetch$1({
|
357
|
+
const updateWorkspaceMemberRole = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
|
358
|
+
const removeWorkspaceMember = (variables, signal) => fetch$1({
|
343
359
|
url: "/workspaces/{workspaceId}/members/{userId}",
|
344
360
|
method: "delete",
|
345
|
-
...variables
|
361
|
+
...variables,
|
362
|
+
signal
|
346
363
|
});
|
347
|
-
const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
|
348
|
-
const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
|
349
|
-
const cancelWorkspaceMemberInvite = (variables) => fetch$1({
|
364
|
+
const inviteWorkspaceMember = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
|
365
|
+
const updateWorkspaceMemberInvite = (variables, signal) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
|
366
|
+
const cancelWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
350
367
|
url: "/workspaces/{workspaceId}/invites/{inviteId}",
|
351
368
|
method: "delete",
|
352
|
-
...variables
|
369
|
+
...variables,
|
370
|
+
signal
|
353
371
|
});
|
354
|
-
const resendWorkspaceMemberInvite = (variables) => fetch$1({
|
372
|
+
const resendWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
355
373
|
url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
|
356
374
|
method: "post",
|
357
|
-
...variables
|
375
|
+
...variables,
|
376
|
+
signal
|
358
377
|
});
|
359
|
-
const acceptWorkspaceMemberInvite = (variables) => fetch$1({
|
378
|
+
const acceptWorkspaceMemberInvite = (variables, signal) => fetch$1({
|
360
379
|
url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
|
361
380
|
method: "post",
|
362
|
-
...variables
|
381
|
+
...variables,
|
382
|
+
signal
|
363
383
|
});
|
364
|
-
const getDatabaseList = (variables) => fetch$1({
|
384
|
+
const getDatabaseList = (variables, signal) => fetch$1({
|
365
385
|
url: "/dbs",
|
366
386
|
method: "get",
|
367
|
-
...variables
|
387
|
+
...variables,
|
388
|
+
signal
|
368
389
|
});
|
369
|
-
const getBranchList = (variables) => fetch$1({
|
390
|
+
const getBranchList = (variables, signal) => fetch$1({
|
370
391
|
url: "/dbs/{dbName}",
|
371
392
|
method: "get",
|
372
|
-
...variables
|
393
|
+
...variables,
|
394
|
+
signal
|
373
395
|
});
|
374
|
-
const createDatabase = (variables) => fetch$1({
|
396
|
+
const createDatabase = (variables, signal) => fetch$1({
|
375
397
|
url: "/dbs/{dbName}",
|
376
398
|
method: "put",
|
377
|
-
...variables
|
399
|
+
...variables,
|
400
|
+
signal
|
378
401
|
});
|
379
|
-
const deleteDatabase = (variables) => fetch$1({
|
402
|
+
const deleteDatabase = (variables, signal) => fetch$1({
|
380
403
|
url: "/dbs/{dbName}",
|
381
404
|
method: "delete",
|
382
|
-
...variables
|
405
|
+
...variables,
|
406
|
+
signal
|
383
407
|
});
|
384
|
-
const getDatabaseMetadata = (variables) => fetch$1({
|
408
|
+
const getDatabaseMetadata = (variables, signal) => fetch$1({
|
385
409
|
url: "/dbs/{dbName}/metadata",
|
386
410
|
method: "get",
|
387
|
-
...variables
|
411
|
+
...variables,
|
412
|
+
signal
|
388
413
|
});
|
389
|
-
const
|
390
|
-
const
|
391
|
-
const
|
392
|
-
const
|
414
|
+
const updateDatabaseMetadata = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
|
415
|
+
const getGitBranchesMapping = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
|
416
|
+
const addGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
|
417
|
+
const removeGitBranchesEntry = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
|
418
|
+
const resolveBranch = (variables, signal) => fetch$1({
|
393
419
|
url: "/dbs/{dbName}/resolveBranch",
|
394
420
|
method: "get",
|
395
|
-
...variables
|
421
|
+
...variables,
|
422
|
+
signal
|
423
|
+
});
|
424
|
+
const queryMigrationRequests = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
|
425
|
+
const createMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
|
426
|
+
const getMigrationRequest = (variables, signal) => fetch$1({
|
427
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
428
|
+
method: "get",
|
429
|
+
...variables,
|
430
|
+
signal
|
431
|
+
});
|
432
|
+
const updateMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
|
433
|
+
const listMigrationRequestsCommits = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
|
434
|
+
const compareMigrationRequest = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
|
435
|
+
const getMigrationRequestIsMerged = (variables, signal) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
|
436
|
+
const mergeMigrationRequest = (variables, signal) => fetch$1({
|
437
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
438
|
+
method: "post",
|
439
|
+
...variables,
|
440
|
+
signal
|
396
441
|
});
|
397
|
-
const getBranchDetails = (variables) => fetch$1({
|
442
|
+
const getBranchDetails = (variables, signal) => fetch$1({
|
398
443
|
url: "/db/{dbBranchName}",
|
399
444
|
method: "get",
|
400
|
-
...variables
|
445
|
+
...variables,
|
446
|
+
signal
|
401
447
|
});
|
402
|
-
const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
|
403
|
-
const deleteBranch = (variables) => fetch$1({
|
448
|
+
const createBranch = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
|
449
|
+
const deleteBranch = (variables, signal) => fetch$1({
|
404
450
|
url: "/db/{dbBranchName}",
|
405
451
|
method: "delete",
|
406
|
-
...variables
|
452
|
+
...variables,
|
453
|
+
signal
|
407
454
|
});
|
408
|
-
const updateBranchMetadata = (variables) => fetch$1({
|
455
|
+
const updateBranchMetadata = (variables, signal) => fetch$1({
|
409
456
|
url: "/db/{dbBranchName}/metadata",
|
410
457
|
method: "put",
|
411
|
-
...variables
|
458
|
+
...variables,
|
459
|
+
signal
|
412
460
|
});
|
413
|
-
const getBranchMetadata = (variables) => fetch$1({
|
461
|
+
const getBranchMetadata = (variables, signal) => fetch$1({
|
414
462
|
url: "/db/{dbBranchName}/metadata",
|
415
463
|
method: "get",
|
416
|
-
...variables
|
464
|
+
...variables,
|
465
|
+
signal
|
417
466
|
});
|
418
|
-
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
419
|
-
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
420
|
-
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
421
|
-
const
|
467
|
+
const getBranchMigrationHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
|
468
|
+
const executeBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
|
469
|
+
const getBranchMigrationPlan = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
|
470
|
+
const compareBranchWithUserSchema = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
|
471
|
+
const compareBranchSchemas = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
|
472
|
+
const updateBranchSchema = (variables, signal) => fetch$1({
|
473
|
+
url: "/db/{dbBranchName}/schema/update",
|
474
|
+
method: "post",
|
475
|
+
...variables,
|
476
|
+
signal
|
477
|
+
});
|
478
|
+
const previewBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
|
479
|
+
const applyBranchSchemaEdit = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
|
480
|
+
const getBranchSchemaHistory = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
|
481
|
+
const getBranchStats = (variables, signal) => fetch$1({
|
422
482
|
url: "/db/{dbBranchName}/stats",
|
423
483
|
method: "get",
|
424
|
-
...variables
|
484
|
+
...variables,
|
485
|
+
signal
|
425
486
|
});
|
426
|
-
const createTable = (variables) => fetch$1({
|
487
|
+
const createTable = (variables, signal) => fetch$1({
|
427
488
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
428
489
|
method: "put",
|
429
|
-
...variables
|
490
|
+
...variables,
|
491
|
+
signal
|
430
492
|
});
|
431
|
-
const deleteTable = (variables) => fetch$1({
|
493
|
+
const deleteTable = (variables, signal) => fetch$1({
|
432
494
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
433
495
|
method: "delete",
|
434
|
-
...variables
|
496
|
+
...variables,
|
497
|
+
signal
|
435
498
|
});
|
436
|
-
const updateTable = (variables) => fetch$1({
|
499
|
+
const updateTable = (variables, signal) => fetch$1({
|
437
500
|
url: "/db/{dbBranchName}/tables/{tableName}",
|
438
501
|
method: "patch",
|
439
|
-
...variables
|
502
|
+
...variables,
|
503
|
+
signal
|
440
504
|
});
|
441
|
-
const getTableSchema = (variables) => fetch$1({
|
505
|
+
const getTableSchema = (variables, signal) => fetch$1({
|
442
506
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
443
507
|
method: "get",
|
444
|
-
...variables
|
508
|
+
...variables,
|
509
|
+
signal
|
445
510
|
});
|
446
|
-
const setTableSchema = (variables) => fetch$1({
|
511
|
+
const setTableSchema = (variables, signal) => fetch$1({
|
447
512
|
url: "/db/{dbBranchName}/tables/{tableName}/schema",
|
448
513
|
method: "put",
|
449
|
-
...variables
|
514
|
+
...variables,
|
515
|
+
signal
|
450
516
|
});
|
451
|
-
const getTableColumns = (variables) => fetch$1({
|
517
|
+
const getTableColumns = (variables, signal) => fetch$1({
|
452
518
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
453
519
|
method: "get",
|
454
|
-
...variables
|
520
|
+
...variables,
|
521
|
+
signal
|
455
522
|
});
|
456
|
-
const addTableColumn = (variables) => fetch$1({
|
523
|
+
const addTableColumn = (variables, signal) => fetch$1({
|
457
524
|
url: "/db/{dbBranchName}/tables/{tableName}/columns",
|
458
525
|
method: "post",
|
459
|
-
...variables
|
526
|
+
...variables,
|
527
|
+
signal
|
460
528
|
});
|
461
|
-
const getColumn = (variables) => fetch$1({
|
529
|
+
const getColumn = (variables, signal) => fetch$1({
|
462
530
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
463
531
|
method: "get",
|
464
|
-
...variables
|
532
|
+
...variables,
|
533
|
+
signal
|
465
534
|
});
|
466
|
-
const deleteColumn = (variables) => fetch$1({
|
535
|
+
const deleteColumn = (variables, signal) => fetch$1({
|
467
536
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
468
537
|
method: "delete",
|
469
|
-
...variables
|
538
|
+
...variables,
|
539
|
+
signal
|
470
540
|
});
|
471
|
-
const updateColumn = (variables) => fetch$1({
|
541
|
+
const updateColumn = (variables, signal) => fetch$1({
|
472
542
|
url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
|
473
543
|
method: "patch",
|
474
|
-
...variables
|
544
|
+
...variables,
|
545
|
+
signal
|
475
546
|
});
|
476
|
-
const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
|
477
|
-
const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
|
478
|
-
const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
|
479
|
-
const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
|
480
|
-
const deleteRecord = (variables) => fetch$1({
|
547
|
+
const insertRecord = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
|
548
|
+
const insertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
|
549
|
+
const updateRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
|
550
|
+
const upsertRecordWithID = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
|
551
|
+
const deleteRecord = (variables, signal) => fetch$1({
|
481
552
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
482
553
|
method: "delete",
|
483
|
-
...variables
|
554
|
+
...variables,
|
555
|
+
signal
|
484
556
|
});
|
485
|
-
const getRecord = (variables) => fetch$1({
|
557
|
+
const getRecord = (variables, signal) => fetch$1({
|
486
558
|
url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
|
487
559
|
method: "get",
|
488
|
-
...variables
|
560
|
+
...variables,
|
561
|
+
signal
|
489
562
|
});
|
490
|
-
const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
|
491
|
-
const queryTable = (variables) => fetch$1({
|
563
|
+
const bulkInsertTableRecords = (variables, signal) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
|
564
|
+
const queryTable = (variables, signal) => fetch$1({
|
492
565
|
url: "/db/{dbBranchName}/tables/{tableName}/query",
|
493
566
|
method: "post",
|
494
|
-
...variables
|
567
|
+
...variables,
|
568
|
+
signal
|
495
569
|
});
|
496
|
-
const searchTable = (variables) => fetch$1({
|
570
|
+
const searchTable = (variables, signal) => fetch$1({
|
497
571
|
url: "/db/{dbBranchName}/tables/{tableName}/search",
|
498
572
|
method: "post",
|
499
|
-
...variables
|
573
|
+
...variables,
|
574
|
+
signal
|
500
575
|
});
|
501
|
-
const searchBranch = (variables) => fetch$1({
|
576
|
+
const searchBranch = (variables, signal) => fetch$1({
|
502
577
|
url: "/db/{dbBranchName}/search",
|
503
578
|
method: "post",
|
579
|
+
...variables,
|
580
|
+
signal
|
581
|
+
});
|
582
|
+
const summarizeTable = (variables, signal) => fetch$1({
|
583
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
584
|
+
method: "post",
|
585
|
+
...variables,
|
586
|
+
signal
|
587
|
+
});
|
588
|
+
const aggregateTable = (variables) => fetch$1({
|
589
|
+
url: "/db/{dbBranchName}/tables/{tableName}/aggregate",
|
590
|
+
method: "post",
|
504
591
|
...variables
|
505
592
|
});
|
506
593
|
const operationsByTag = {
|
@@ -525,6 +612,7 @@ const operationsByTag = {
|
|
525
612
|
createDatabase,
|
526
613
|
deleteDatabase,
|
527
614
|
getDatabaseMetadata,
|
615
|
+
updateDatabaseMetadata,
|
528
616
|
getGitBranchesMapping,
|
529
617
|
addGitBranchesEntry,
|
530
618
|
removeGitBranchesEntry,
|
@@ -537,10 +625,28 @@ const operationsByTag = {
|
|
537
625
|
deleteBranch,
|
538
626
|
updateBranchMetadata,
|
539
627
|
getBranchMetadata,
|
628
|
+
getBranchStats
|
629
|
+
},
|
630
|
+
migrationRequests: {
|
631
|
+
queryMigrationRequests,
|
632
|
+
createMigrationRequest,
|
633
|
+
getMigrationRequest,
|
634
|
+
updateMigrationRequest,
|
635
|
+
listMigrationRequestsCommits,
|
636
|
+
compareMigrationRequest,
|
637
|
+
getMigrationRequestIsMerged,
|
638
|
+
mergeMigrationRequest
|
639
|
+
},
|
640
|
+
branchSchema: {
|
540
641
|
getBranchMigrationHistory,
|
541
642
|
executeBranchMigrationPlan,
|
542
643
|
getBranchMigrationPlan,
|
543
|
-
|
644
|
+
compareBranchWithUserSchema,
|
645
|
+
compareBranchSchemas,
|
646
|
+
updateBranchSchema,
|
647
|
+
previewBranchSchemaEdit,
|
648
|
+
applyBranchSchemaEdit,
|
649
|
+
getBranchSchemaHistory
|
544
650
|
},
|
545
651
|
table: {
|
546
652
|
createTable,
|
@@ -564,7 +670,9 @@ const operationsByTag = {
|
|
564
670
|
bulkInsertTableRecords,
|
565
671
|
queryTable,
|
566
672
|
searchTable,
|
567
|
-
searchBranch
|
673
|
+
searchBranch,
|
674
|
+
summarizeTable,
|
675
|
+
aggregateTable
|
568
676
|
}
|
569
677
|
};
|
570
678
|
|
@@ -592,6 +700,15 @@ function isHostProviderAlias(alias) {
|
|
592
700
|
function isHostProviderBuilder(builder) {
|
593
701
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
594
702
|
}
|
703
|
+
function parseProviderString(provider = "production") {
|
704
|
+
if (isHostProviderAlias(provider)) {
|
705
|
+
return provider;
|
706
|
+
}
|
707
|
+
const [main, workspaces] = provider.split(",");
|
708
|
+
if (!main || !workspaces)
|
709
|
+
return null;
|
710
|
+
return { main, workspaces };
|
711
|
+
}
|
595
712
|
|
596
713
|
var __accessCheck$7 = (obj, member, msg) => {
|
597
714
|
if (!member.has(obj))
|
@@ -660,6 +777,16 @@ class XataApiClient {
|
|
660
777
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
661
778
|
return __privateGet$7(this, _namespaces).records;
|
662
779
|
}
|
780
|
+
get migrationRequests() {
|
781
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
782
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
783
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
784
|
+
}
|
785
|
+
get branchSchema() {
|
786
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
787
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
788
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
789
|
+
}
|
663
790
|
}
|
664
791
|
_extraProps = new WeakMap();
|
665
792
|
_namespaces = new WeakMap();
|
@@ -805,6 +932,13 @@ class DatabaseApi {
|
|
805
932
|
...this.extraProps
|
806
933
|
});
|
807
934
|
}
|
935
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
936
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
937
|
+
pathParams: { workspace, dbName },
|
938
|
+
body: options,
|
939
|
+
...this.extraProps
|
940
|
+
});
|
941
|
+
}
|
808
942
|
getGitBranchesMapping(workspace, dbName) {
|
809
943
|
return operationsByTag.database.getGitBranchesMapping({
|
810
944
|
pathParams: { workspace, dbName },
|
@@ -876,27 +1010,6 @@ class BranchApi {
|
|
876
1010
|
...this.extraProps
|
877
1011
|
});
|
878
1012
|
}
|
879
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
880
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
881
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
882
|
-
body: options,
|
883
|
-
...this.extraProps
|
884
|
-
});
|
885
|
-
}
|
886
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
887
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
888
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
889
|
-
body: migrationPlan,
|
890
|
-
...this.extraProps
|
891
|
-
});
|
892
|
-
}
|
893
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
894
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
895
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
896
|
-
body: schema,
|
897
|
-
...this.extraProps
|
898
|
-
});
|
899
|
-
}
|
900
1013
|
getBranchStats(workspace, database, branch) {
|
901
1014
|
return operationsByTag.branch.getBranchStats({
|
902
1015
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -1052,6 +1165,145 @@ class RecordsApi {
|
|
1052
1165
|
...this.extraProps
|
1053
1166
|
});
|
1054
1167
|
}
|
1168
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
1169
|
+
return operationsByTag.records.summarizeTable({
|
1170
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1171
|
+
body: query,
|
1172
|
+
...this.extraProps
|
1173
|
+
});
|
1174
|
+
}
|
1175
|
+
aggregateTable(workspace, database, branch, tableName, query) {
|
1176
|
+
return operationsByTag.records.aggregateTable({
|
1177
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1178
|
+
body: query,
|
1179
|
+
...this.extraProps
|
1180
|
+
});
|
1181
|
+
}
|
1182
|
+
}
|
1183
|
+
class MigrationRequestsApi {
|
1184
|
+
constructor(extraProps) {
|
1185
|
+
this.extraProps = extraProps;
|
1186
|
+
}
|
1187
|
+
queryMigrationRequests(workspace, database, options = {}) {
|
1188
|
+
return operationsByTag.migrationRequests.queryMigrationRequests({
|
1189
|
+
pathParams: { workspace, dbName: database },
|
1190
|
+
body: options,
|
1191
|
+
...this.extraProps
|
1192
|
+
});
|
1193
|
+
}
|
1194
|
+
createMigrationRequest(workspace, database, options) {
|
1195
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1196
|
+
pathParams: { workspace, dbName: database },
|
1197
|
+
body: options,
|
1198
|
+
...this.extraProps
|
1199
|
+
});
|
1200
|
+
}
|
1201
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1202
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1203
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1204
|
+
...this.extraProps
|
1205
|
+
});
|
1206
|
+
}
|
1207
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1208
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1209
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1210
|
+
body: options,
|
1211
|
+
...this.extraProps
|
1212
|
+
});
|
1213
|
+
}
|
1214
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1215
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1216
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1217
|
+
body: options,
|
1218
|
+
...this.extraProps
|
1219
|
+
});
|
1220
|
+
}
|
1221
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1222
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1223
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1224
|
+
...this.extraProps
|
1225
|
+
});
|
1226
|
+
}
|
1227
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1228
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1229
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1230
|
+
...this.extraProps
|
1231
|
+
});
|
1232
|
+
}
|
1233
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1234
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1235
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1236
|
+
...this.extraProps
|
1237
|
+
});
|
1238
|
+
}
|
1239
|
+
}
|
1240
|
+
class BranchSchemaApi {
|
1241
|
+
constructor(extraProps) {
|
1242
|
+
this.extraProps = extraProps;
|
1243
|
+
}
|
1244
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1245
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1246
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1247
|
+
body: options,
|
1248
|
+
...this.extraProps
|
1249
|
+
});
|
1250
|
+
}
|
1251
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1252
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1253
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1254
|
+
body: migrationPlan,
|
1255
|
+
...this.extraProps
|
1256
|
+
});
|
1257
|
+
}
|
1258
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1259
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1260
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1261
|
+
body: schema,
|
1262
|
+
...this.extraProps
|
1263
|
+
});
|
1264
|
+
}
|
1265
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1266
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1267
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1268
|
+
body: { schema },
|
1269
|
+
...this.extraProps
|
1270
|
+
});
|
1271
|
+
}
|
1272
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1273
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1274
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1275
|
+
body: { schema },
|
1276
|
+
...this.extraProps
|
1277
|
+
});
|
1278
|
+
}
|
1279
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1280
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1281
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1282
|
+
body: migration,
|
1283
|
+
...this.extraProps
|
1284
|
+
});
|
1285
|
+
}
|
1286
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1287
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1288
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1289
|
+
body: migration,
|
1290
|
+
...this.extraProps
|
1291
|
+
});
|
1292
|
+
}
|
1293
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1294
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1295
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1296
|
+
body: { edits },
|
1297
|
+
...this.extraProps
|
1298
|
+
});
|
1299
|
+
}
|
1300
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1301
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1302
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1303
|
+
body: options,
|
1304
|
+
...this.extraProps
|
1305
|
+
});
|
1306
|
+
}
|
1055
1307
|
}
|
1056
1308
|
|
1057
1309
|
class XataApiPlugin {
|
@@ -1177,9 +1429,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
|
|
1177
1429
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
1178
1430
|
return value;
|
1179
1431
|
};
|
1180
|
-
var
|
1432
|
+
var __privateMethod$3 = (obj, member, method) => {
|
1433
|
+
__accessCheck$5(obj, member, "access private method");
|
1434
|
+
return method;
|
1435
|
+
};
|
1436
|
+
var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
|
1181
1437
|
const _Query = class {
|
1182
1438
|
constructor(repository, table, data, rawParent) {
|
1439
|
+
__privateAdd$5(this, _cleanFilterConstraint);
|
1183
1440
|
__privateAdd$5(this, _table$1, void 0);
|
1184
1441
|
__privateAdd$5(this, _repository, void 0);
|
1185
1442
|
__privateAdd$5(this, _data, { filter: {} });
|
@@ -1236,11 +1493,14 @@ const _Query = class {
|
|
1236
1493
|
}
|
1237
1494
|
filter(a, b) {
|
1238
1495
|
if (arguments.length === 1) {
|
1239
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({
|
1496
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
|
1497
|
+
[column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
|
1498
|
+
}));
|
1240
1499
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1241
1500
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1242
1501
|
} else {
|
1243
|
-
const
|
1502
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
|
1503
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1244
1504
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1245
1505
|
}
|
1246
1506
|
}
|
@@ -1278,11 +1538,20 @@ const _Query = class {
|
|
1278
1538
|
}
|
1279
1539
|
}
|
1280
1540
|
async getMany(options = {}) {
|
1281
|
-
const
|
1541
|
+
const { pagination = {}, ...rest } = options;
|
1542
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1543
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1544
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1545
|
+
const results = [...page.records];
|
1546
|
+
while (page.hasNextPage() && results.length < size) {
|
1547
|
+
page = await page.nextPage();
|
1548
|
+
results.push(...page.records);
|
1549
|
+
}
|
1282
1550
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1283
1551
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1284
1552
|
}
|
1285
|
-
|
1553
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1554
|
+
return array;
|
1286
1555
|
}
|
1287
1556
|
async getAll(options = {}) {
|
1288
1557
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1296,6 +1565,12 @@ const _Query = class {
|
|
1296
1565
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1297
1566
|
return records[0] ?? null;
|
1298
1567
|
}
|
1568
|
+
async getFirstOrThrow(options = {}) {
|
1569
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1570
|
+
if (records[0] === void 0)
|
1571
|
+
throw new Error("No results found.");
|
1572
|
+
return records[0];
|
1573
|
+
}
|
1299
1574
|
cache(ttl) {
|
1300
1575
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1301
1576
|
}
|
@@ -1319,6 +1594,17 @@ let Query = _Query;
|
|
1319
1594
|
_table$1 = new WeakMap();
|
1320
1595
|
_repository = new WeakMap();
|
1321
1596
|
_data = new WeakMap();
|
1597
|
+
_cleanFilterConstraint = new WeakSet();
|
1598
|
+
cleanFilterConstraint_fn = function(column, value) {
|
1599
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1600
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1601
|
+
return { $includes: value };
|
1602
|
+
}
|
1603
|
+
if (columnType === "link" && isObject(value) && isString(value.id)) {
|
1604
|
+
return value.id;
|
1605
|
+
}
|
1606
|
+
return value;
|
1607
|
+
};
|
1322
1608
|
function cleanParent(data, parent) {
|
1323
1609
|
if (isCursorPaginationOptions(data.pagination)) {
|
1324
1610
|
return { ...parent, sorting: void 0, filter: void 0 };
|
@@ -1385,7 +1671,11 @@ class Repository extends Query {
|
|
1385
1671
|
}
|
1386
1672
|
class RestRepository extends Query {
|
1387
1673
|
constructor(options) {
|
1388
|
-
super(
|
1674
|
+
super(
|
1675
|
+
null,
|
1676
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1677
|
+
{}
|
1678
|
+
);
|
1389
1679
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1390
1680
|
__privateAdd$4(this, _insertRecordWithId);
|
1391
1681
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
@@ -1411,6 +1701,7 @@ class RestRepository extends Query {
|
|
1411
1701
|
return trace(name, fn, {
|
1412
1702
|
...options2,
|
1413
1703
|
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1704
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1414
1705
|
[TraceAttributes.VERSION]: VERSION
|
1415
1706
|
});
|
1416
1707
|
});
|
@@ -1471,7 +1762,7 @@ class RestRepository extends Query {
|
|
1471
1762
|
...fetchProps
|
1472
1763
|
});
|
1473
1764
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1474
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1765
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1475
1766
|
} catch (e) {
|
1476
1767
|
if (isObject(e) && e.status === 404) {
|
1477
1768
|
return null;
|
@@ -1482,6 +1773,25 @@ class RestRepository extends Query {
|
|
1482
1773
|
return null;
|
1483
1774
|
});
|
1484
1775
|
}
|
1776
|
+
async readOrThrow(a, b) {
|
1777
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1778
|
+
const result = await this.read(a, b);
|
1779
|
+
if (Array.isArray(result)) {
|
1780
|
+
const missingIds = compact(
|
1781
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1782
|
+
);
|
1783
|
+
if (missingIds.length > 0) {
|
1784
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1785
|
+
}
|
1786
|
+
return result;
|
1787
|
+
}
|
1788
|
+
if (result === null) {
|
1789
|
+
const id = extractId(a) ?? "unknown";
|
1790
|
+
throw new Error(`Record with id ${id} not found`);
|
1791
|
+
}
|
1792
|
+
return result;
|
1793
|
+
});
|
1794
|
+
}
|
1485
1795
|
async update(a, b, c) {
|
1486
1796
|
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1487
1797
|
if (Array.isArray(a)) {
|
@@ -1504,6 +1814,25 @@ class RestRepository extends Query {
|
|
1504
1814
|
throw new Error("Invalid arguments for update method");
|
1505
1815
|
});
|
1506
1816
|
}
|
1817
|
+
async updateOrThrow(a, b, c) {
|
1818
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1819
|
+
const result = await this.update(a, b, c);
|
1820
|
+
if (Array.isArray(result)) {
|
1821
|
+
const missingIds = compact(
|
1822
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1823
|
+
);
|
1824
|
+
if (missingIds.length > 0) {
|
1825
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1826
|
+
}
|
1827
|
+
return result;
|
1828
|
+
}
|
1829
|
+
if (result === null) {
|
1830
|
+
const id = extractId(a) ?? "unknown";
|
1831
|
+
throw new Error(`Record with id ${id} not found`);
|
1832
|
+
}
|
1833
|
+
return result;
|
1834
|
+
});
|
1835
|
+
}
|
1507
1836
|
async createOrUpdate(a, b, c) {
|
1508
1837
|
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1509
1838
|
if (Array.isArray(a)) {
|
@@ -1545,6 +1874,24 @@ class RestRepository extends Query {
|
|
1545
1874
|
throw new Error("Invalid arguments for delete method");
|
1546
1875
|
});
|
1547
1876
|
}
|
1877
|
+
async deleteOrThrow(a, b) {
|
1878
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1879
|
+
const result = await this.delete(a, b);
|
1880
|
+
if (Array.isArray(result)) {
|
1881
|
+
const missingIds = compact(
|
1882
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1883
|
+
);
|
1884
|
+
if (missingIds.length > 0) {
|
1885
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1886
|
+
}
|
1887
|
+
return result;
|
1888
|
+
} else if (result === null) {
|
1889
|
+
const id = extractId(a) ?? "unknown";
|
1890
|
+
throw new Error(`Record with id ${id} not found`);
|
1891
|
+
}
|
1892
|
+
return result;
|
1893
|
+
});
|
1894
|
+
}
|
1548
1895
|
async search(query, options = {}) {
|
1549
1896
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1550
1897
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1561,7 +1908,18 @@ class RestRepository extends Query {
|
|
1561
1908
|
...fetchProps
|
1562
1909
|
});
|
1563
1910
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1564
|
-
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
1911
|
+
return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
|
1912
|
+
});
|
1913
|
+
}
|
1914
|
+
async aggregate(aggs, filter) {
|
1915
|
+
return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
|
1916
|
+
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1917
|
+
const result = await aggregateTable({
|
1918
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
|
1919
|
+
body: { aggs, filter },
|
1920
|
+
...fetchProps
|
1921
|
+
});
|
1922
|
+
return result;
|
1565
1923
|
});
|
1566
1924
|
}
|
1567
1925
|
async query(query) {
|
@@ -1571,7 +1929,7 @@ class RestRepository extends Query {
|
|
1571
1929
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1572
1930
|
const data = query.getQueryOptions();
|
1573
1931
|
const body = {
|
1574
|
-
filter:
|
1932
|
+
filter: cleanFilter(data.filter),
|
1575
1933
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1576
1934
|
page: data.pagination,
|
1577
1935
|
columns: data.columns
|
@@ -1583,7 +1941,9 @@ class RestRepository extends Query {
|
|
1583
1941
|
...fetchProps
|
1584
1942
|
});
|
1585
1943
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1586
|
-
const records = objects.map(
|
1944
|
+
const records = objects.map(
|
1945
|
+
(record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
|
1946
|
+
);
|
1587
1947
|
await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
|
1588
1948
|
return new Page(query, meta, records);
|
1589
1949
|
});
|
@@ -1610,7 +1970,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
|
|
1610
1970
|
...fetchProps
|
1611
1971
|
});
|
1612
1972
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1613
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1973
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1614
1974
|
};
|
1615
1975
|
_insertRecordWithId = new WeakSet();
|
1616
1976
|
insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1628,7 +1988,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
|
|
1628
1988
|
...fetchProps
|
1629
1989
|
});
|
1630
1990
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1631
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1991
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1632
1992
|
};
|
1633
1993
|
_bulkInsertTableRecords = new WeakSet();
|
1634
1994
|
bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
@@ -1644,7 +2004,7 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
|
|
1644
2004
|
throw new Error("Request included columns but server didn't include them");
|
1645
2005
|
}
|
1646
2006
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1647
|
-
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
|
2007
|
+
return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
|
1648
2008
|
};
|
1649
2009
|
_updateRecordWithID = new WeakSet();
|
1650
2010
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1658,7 +2018,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1658
2018
|
...fetchProps
|
1659
2019
|
});
|
1660
2020
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1661
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2021
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1662
2022
|
} catch (e) {
|
1663
2023
|
if (isObject(e) && e.status === 404) {
|
1664
2024
|
return null;
|
@@ -1676,7 +2036,7 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1676
2036
|
...fetchProps
|
1677
2037
|
});
|
1678
2038
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1679
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2039
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1680
2040
|
};
|
1681
2041
|
_deleteRecord = new WeakSet();
|
1682
2042
|
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
@@ -1688,7 +2048,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
|
1688
2048
|
...fetchProps
|
1689
2049
|
});
|
1690
2050
|
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1691
|
-
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
2051
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
|
1692
2052
|
} catch (e) {
|
1693
2053
|
if (isObject(e) && e.status === 404) {
|
1694
2054
|
return null;
|
@@ -1731,7 +2091,7 @@ const transformObjectLinks = (object) => {
|
|
1731
2091
|
return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
|
1732
2092
|
}, {});
|
1733
2093
|
};
|
1734
|
-
const initObject = (db, schemaTables, table, object) => {
|
2094
|
+
const initObject = (db, schemaTables, table, object, selectedColumns) => {
|
1735
2095
|
const result = {};
|
1736
2096
|
const { xata, ...rest } = object ?? {};
|
1737
2097
|
Object.assign(result, rest);
|
@@ -1739,6 +2099,8 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1739
2099
|
if (!columns)
|
1740
2100
|
console.error(`Table ${table} not found in schema`);
|
1741
2101
|
for (const column of columns ?? []) {
|
2102
|
+
if (!isValidColumn(selectedColumns, column))
|
2103
|
+
continue;
|
1742
2104
|
const value = result[column.name];
|
1743
2105
|
switch (column.type) {
|
1744
2106
|
case "datetime": {
|
@@ -1755,10 +2117,28 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1755
2117
|
if (!linkTable) {
|
1756
2118
|
console.error(`Failed to parse link for field ${column.name}`);
|
1757
2119
|
} else if (isObject(value)) {
|
1758
|
-
|
2120
|
+
const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
|
2121
|
+
if (item === column.name) {
|
2122
|
+
return [...acc, "*"];
|
2123
|
+
}
|
2124
|
+
if (item.startsWith(`${column.name}.`)) {
|
2125
|
+
const [, ...path] = item.split(".");
|
2126
|
+
return [...acc, path.join(".")];
|
2127
|
+
}
|
2128
|
+
return acc;
|
2129
|
+
}, []);
|
2130
|
+
result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
|
2131
|
+
} else {
|
2132
|
+
result[column.name] = null;
|
1759
2133
|
}
|
1760
2134
|
break;
|
1761
2135
|
}
|
2136
|
+
default:
|
2137
|
+
result[column.name] = value ?? null;
|
2138
|
+
if (column.notNull === true && value === null) {
|
2139
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2140
|
+
}
|
2141
|
+
break;
|
1762
2142
|
}
|
1763
2143
|
}
|
1764
2144
|
result.read = function(columns2) {
|
@@ -1789,6 +2169,21 @@ function extractId(value) {
|
|
1789
2169
|
return value.id;
|
1790
2170
|
return void 0;
|
1791
2171
|
}
|
2172
|
+
function cleanFilter(filter) {
|
2173
|
+
if (!filter)
|
2174
|
+
return void 0;
|
2175
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2176
|
+
return values.length > 0 ? filter : void 0;
|
2177
|
+
}
|
2178
|
+
function isValidColumn(columns, column) {
|
2179
|
+
if (columns.includes("*"))
|
2180
|
+
return true;
|
2181
|
+
if (column.type === "link") {
|
2182
|
+
const linkColumns = columns.filter((item) => item.startsWith(column.name));
|
2183
|
+
return linkColumns.length > 0;
|
2184
|
+
}
|
2185
|
+
return columns.includes(column.name);
|
2186
|
+
}
|
1792
2187
|
|
1793
2188
|
var __accessCheck$3 = (obj, member, msg) => {
|
1794
2189
|
if (!member.has(obj))
|
@@ -1954,7 +2349,7 @@ class SearchPlugin extends XataPlugin {
|
|
1954
2349
|
const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
|
1955
2350
|
return records.map((record) => {
|
1956
2351
|
const { table = "orphan" } = record.xata;
|
1957
|
-
return { table, record: initObject(this.db, schemaTables, table, record) };
|
2352
|
+
return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
|
1958
2353
|
});
|
1959
2354
|
},
|
1960
2355
|
byTable: async (query, options = {}) => {
|
@@ -1963,7 +2358,7 @@ class SearchPlugin extends XataPlugin {
|
|
1963
2358
|
return records.reduce((acc, record) => {
|
1964
2359
|
const { table = "orphan" } = record.xata;
|
1965
2360
|
const items = acc[table] ?? [];
|
1966
|
-
const item = initObject(this.db, schemaTables, table, record);
|
2361
|
+
const item = initObject(this.db, schemaTables, table, record, ["*"]);
|
1967
2362
|
return { ...acc, [table]: [...items, item] };
|
1968
2363
|
}, {});
|
1969
2364
|
}
|
@@ -2161,7 +2556,7 @@ const buildClient = (plugins) => {
|
|
2161
2556
|
apiUrl: "",
|
2162
2557
|
workspacesApiUrl: (path, params) => {
|
2163
2558
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2164
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2559
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2165
2560
|
return databaseURL + newPath;
|
2166
2561
|
},
|
2167
2562
|
trace
|
@@ -2276,5 +2671,5 @@ class XataError extends Error {
|
|
2276
2671
|
}
|
2277
2672
|
}
|
2278
2673
|
|
2279
|
-
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, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2674
|
+
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, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, 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, lt, lte, mergeMigrationRequest, notExists, operationsByTag, parseProviderString, 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 };
|
2280
2675
|
//# sourceMappingURL=index.mjs.map
|