@xata.io/client 0.16.2 → 0.18.0
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 +46 -0
- package/README.md +25 -25
- package/Usage.md +2 -0
- package/dist/index.cjs +386 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +988 -120
- package/dist/index.mjs +371 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -24,13 +24,11 @@ const defaultTrace = async (_name, fn, _options) => {
|
|
24
24
|
return await fn({
|
25
25
|
setAttributes: () => {
|
26
26
|
return;
|
27
|
-
},
|
28
|
-
onError: () => {
|
29
|
-
return;
|
30
27
|
}
|
31
28
|
});
|
32
29
|
};
|
33
30
|
const TraceAttributes = {
|
31
|
+
KIND: "xata.trace.kind",
|
34
32
|
VERSION: "xata.sdk.version",
|
35
33
|
TABLE: "xata.table",
|
36
34
|
HTTP_REQUEST_ID: "http.request_id",
|
@@ -174,7 +172,7 @@ function getFetchImplementation(userFetch) {
|
|
174
172
|
return fetchImpl;
|
175
173
|
}
|
176
174
|
|
177
|
-
const VERSION = "0.
|
175
|
+
const VERSION = "0.18.0";
|
178
176
|
|
179
177
|
class ErrorWithCause extends Error {
|
180
178
|
constructor(message, options) {
|
@@ -225,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
|
|
225
223
|
}, {});
|
226
224
|
const query = new URLSearchParams(cleanQueryParams).toString();
|
227
225
|
const queryString = query.length > 0 ? `?${query}` : "";
|
228
|
-
|
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;
|
229
230
|
};
|
230
231
|
function buildBaseUrl({
|
231
232
|
path,
|
@@ -233,10 +234,10 @@ function buildBaseUrl({
|
|
233
234
|
apiUrl,
|
234
235
|
pathParams
|
235
236
|
}) {
|
236
|
-
if (
|
237
|
+
if (pathParams?.workspace === void 0)
|
237
238
|
return `${apiUrl}${path}`;
|
238
239
|
const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
|
239
|
-
return url.replace("{workspaceId}", pathParams.workspace);
|
240
|
+
return url.replace("{workspaceId}", String(pathParams.workspace));
|
240
241
|
}
|
241
242
|
function hostHeader(url) {
|
242
243
|
const pattern = /.*:\/\/(?<host>[^/]+).*/;
|
@@ -258,7 +259,7 @@ async function fetch$1({
|
|
258
259
|
}) {
|
259
260
|
return trace(
|
260
261
|
`${method.toUpperCase()} ${path}`,
|
261
|
-
async ({ setAttributes
|
262
|
+
async ({ setAttributes }) => {
|
262
263
|
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
263
264
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
264
265
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
@@ -283,6 +284,7 @@ async function fetch$1({
|
|
283
284
|
const { host, protocol } = parseUrl(response.url);
|
284
285
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
285
286
|
setAttributes({
|
287
|
+
[TraceAttributes.KIND]: "http",
|
286
288
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
287
289
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
288
290
|
[TraceAttributes.HTTP_HOST]: host,
|
@@ -295,9 +297,7 @@ async function fetch$1({
|
|
295
297
|
}
|
296
298
|
throw new FetcherError(response.status, jsonResponse, requestId);
|
297
299
|
} catch (error) {
|
298
|
-
|
299
|
-
onError(fetcherError.message);
|
300
|
-
throw fetcherError;
|
300
|
+
throw new FetcherError(response.status, error, requestId);
|
301
301
|
}
|
302
302
|
},
|
303
303
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
@@ -408,6 +408,7 @@ const getDatabaseMetadata = (variables) => fetch$1({
|
|
408
408
|
method: "get",
|
409
409
|
...variables
|
410
410
|
});
|
411
|
+
const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
411
412
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
412
413
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
413
414
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -416,6 +417,22 @@ const resolveBranch = (variables) => fetch$1({
|
|
416
417
|
method: "get",
|
417
418
|
...variables
|
418
419
|
});
|
420
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
421
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
422
|
+
const getMigrationRequest = (variables) => fetch$1({
|
423
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
424
|
+
method: "get",
|
425
|
+
...variables
|
426
|
+
});
|
427
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
428
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
429
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
430
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
431
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
432
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
433
|
+
method: "post",
|
434
|
+
...variables
|
435
|
+
});
|
419
436
|
const getBranchDetails = (variables) => fetch$1({
|
420
437
|
url: "/db/{dbBranchName}",
|
421
438
|
method: "get",
|
@@ -440,6 +457,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
440
457
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
441
458
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
442
459
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
460
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
461
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
462
|
+
const updateBranchSchema = (variables) => fetch$1({
|
463
|
+
url: "/db/{dbBranchName}/schema/update",
|
464
|
+
method: "post",
|
465
|
+
...variables
|
466
|
+
});
|
467
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
468
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
469
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
443
470
|
const getBranchStats = (variables) => fetch$1({
|
444
471
|
url: "/db/{dbBranchName}/stats",
|
445
472
|
method: "get",
|
@@ -525,6 +552,11 @@ const searchBranch = (variables) => fetch$1({
|
|
525
552
|
method: "post",
|
526
553
|
...variables
|
527
554
|
});
|
555
|
+
const summarizeTable = (variables) => fetch$1({
|
556
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
557
|
+
method: "post",
|
558
|
+
...variables
|
559
|
+
});
|
528
560
|
const operationsByTag = {
|
529
561
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
530
562
|
workspaces: {
|
@@ -547,6 +579,7 @@ const operationsByTag = {
|
|
547
579
|
createDatabase,
|
548
580
|
deleteDatabase,
|
549
581
|
getDatabaseMetadata,
|
582
|
+
updateDatabaseMetadata,
|
550
583
|
getGitBranchesMapping,
|
551
584
|
addGitBranchesEntry,
|
552
585
|
removeGitBranchesEntry,
|
@@ -559,10 +592,28 @@ const operationsByTag = {
|
|
559
592
|
deleteBranch,
|
560
593
|
updateBranchMetadata,
|
561
594
|
getBranchMetadata,
|
595
|
+
getBranchStats
|
596
|
+
},
|
597
|
+
migrationRequests: {
|
598
|
+
listMigrationRequests,
|
599
|
+
createMigrationRequest,
|
600
|
+
getMigrationRequest,
|
601
|
+
updateMigrationRequest,
|
602
|
+
listMigrationRequestsCommits,
|
603
|
+
compareMigrationRequest,
|
604
|
+
getMigrationRequestIsMerged,
|
605
|
+
mergeMigrationRequest
|
606
|
+
},
|
607
|
+
branchSchema: {
|
562
608
|
getBranchMigrationHistory,
|
563
609
|
executeBranchMigrationPlan,
|
564
610
|
getBranchMigrationPlan,
|
565
|
-
|
611
|
+
compareBranchWithUserSchema,
|
612
|
+
compareBranchSchemas,
|
613
|
+
updateBranchSchema,
|
614
|
+
previewBranchSchemaEdit,
|
615
|
+
applyBranchSchemaEdit,
|
616
|
+
getBranchSchemaHistory
|
566
617
|
},
|
567
618
|
table: {
|
568
619
|
createTable,
|
@@ -586,14 +637,15 @@ const operationsByTag = {
|
|
586
637
|
bulkInsertTableRecords,
|
587
638
|
queryTable,
|
588
639
|
searchTable,
|
589
|
-
searchBranch
|
640
|
+
searchBranch,
|
641
|
+
summarizeTable
|
590
642
|
}
|
591
643
|
};
|
592
644
|
|
593
645
|
function getHostUrl(provider, type) {
|
594
|
-
if (
|
646
|
+
if (isHostProviderAlias(provider)) {
|
595
647
|
return providers[provider][type];
|
596
|
-
} else if (
|
648
|
+
} else if (isHostProviderBuilder(provider)) {
|
597
649
|
return provider[type];
|
598
650
|
}
|
599
651
|
throw new Error("Invalid API provider");
|
@@ -608,10 +660,10 @@ const providers = {
|
|
608
660
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
609
661
|
}
|
610
662
|
};
|
611
|
-
function
|
663
|
+
function isHostProviderAlias(alias) {
|
612
664
|
return isString(alias) && Object.keys(providers).includes(alias);
|
613
665
|
}
|
614
|
-
function
|
666
|
+
function isHostProviderBuilder(builder) {
|
615
667
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
616
668
|
}
|
617
669
|
|
@@ -682,6 +734,16 @@ class XataApiClient {
|
|
682
734
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
683
735
|
return __privateGet$7(this, _namespaces).records;
|
684
736
|
}
|
737
|
+
get migrationRequests() {
|
738
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
739
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
740
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
741
|
+
}
|
742
|
+
get branchSchema() {
|
743
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
744
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
745
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
746
|
+
}
|
685
747
|
}
|
686
748
|
_extraProps = new WeakMap();
|
687
749
|
_namespaces = new WeakMap();
|
@@ -827,6 +889,13 @@ class DatabaseApi {
|
|
827
889
|
...this.extraProps
|
828
890
|
});
|
829
891
|
}
|
892
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
893
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
894
|
+
pathParams: { workspace, dbName },
|
895
|
+
body: options,
|
896
|
+
...this.extraProps
|
897
|
+
});
|
898
|
+
}
|
830
899
|
getGitBranchesMapping(workspace, dbName) {
|
831
900
|
return operationsByTag.database.getGitBranchesMapping({
|
832
901
|
pathParams: { workspace, dbName },
|
@@ -898,27 +967,6 @@ class BranchApi {
|
|
898
967
|
...this.extraProps
|
899
968
|
});
|
900
969
|
}
|
901
|
-
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
902
|
-
return operationsByTag.branch.getBranchMigrationHistory({
|
903
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
904
|
-
body: options,
|
905
|
-
...this.extraProps
|
906
|
-
});
|
907
|
-
}
|
908
|
-
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
909
|
-
return operationsByTag.branch.executeBranchMigrationPlan({
|
910
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
911
|
-
body: migrationPlan,
|
912
|
-
...this.extraProps
|
913
|
-
});
|
914
|
-
}
|
915
|
-
getBranchMigrationPlan(workspace, database, branch, schema) {
|
916
|
-
return operationsByTag.branch.getBranchMigrationPlan({
|
917
|
-
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
918
|
-
body: schema,
|
919
|
-
...this.extraProps
|
920
|
-
});
|
921
|
-
}
|
922
970
|
getBranchStats(workspace, database, branch) {
|
923
971
|
return operationsByTag.branch.getBranchStats({
|
924
972
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -1074,6 +1122,138 @@ class RecordsApi {
|
|
1074
1122
|
...this.extraProps
|
1075
1123
|
});
|
1076
1124
|
}
|
1125
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
1126
|
+
return operationsByTag.records.summarizeTable({
|
1127
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1128
|
+
body: query,
|
1129
|
+
...this.extraProps
|
1130
|
+
});
|
1131
|
+
}
|
1132
|
+
}
|
1133
|
+
class MigrationRequestsApi {
|
1134
|
+
constructor(extraProps) {
|
1135
|
+
this.extraProps = extraProps;
|
1136
|
+
}
|
1137
|
+
listMigrationRequests(workspace, database, options = {}) {
|
1138
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
1139
|
+
pathParams: { workspace, dbName: database },
|
1140
|
+
body: options,
|
1141
|
+
...this.extraProps
|
1142
|
+
});
|
1143
|
+
}
|
1144
|
+
createMigrationRequest(workspace, database, options) {
|
1145
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1146
|
+
pathParams: { workspace, dbName: database },
|
1147
|
+
body: options,
|
1148
|
+
...this.extraProps
|
1149
|
+
});
|
1150
|
+
}
|
1151
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1152
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1153
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1154
|
+
...this.extraProps
|
1155
|
+
});
|
1156
|
+
}
|
1157
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1158
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1159
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1160
|
+
body: options,
|
1161
|
+
...this.extraProps
|
1162
|
+
});
|
1163
|
+
}
|
1164
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1165
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1166
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1167
|
+
body: options,
|
1168
|
+
...this.extraProps
|
1169
|
+
});
|
1170
|
+
}
|
1171
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1172
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1173
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1174
|
+
...this.extraProps
|
1175
|
+
});
|
1176
|
+
}
|
1177
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1178
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1179
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1180
|
+
...this.extraProps
|
1181
|
+
});
|
1182
|
+
}
|
1183
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1184
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1185
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1186
|
+
...this.extraProps
|
1187
|
+
});
|
1188
|
+
}
|
1189
|
+
}
|
1190
|
+
class BranchSchemaApi {
|
1191
|
+
constructor(extraProps) {
|
1192
|
+
this.extraProps = extraProps;
|
1193
|
+
}
|
1194
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1195
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1196
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1197
|
+
body: options,
|
1198
|
+
...this.extraProps
|
1199
|
+
});
|
1200
|
+
}
|
1201
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1202
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1203
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1204
|
+
body: migrationPlan,
|
1205
|
+
...this.extraProps
|
1206
|
+
});
|
1207
|
+
}
|
1208
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1209
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1210
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1211
|
+
body: schema,
|
1212
|
+
...this.extraProps
|
1213
|
+
});
|
1214
|
+
}
|
1215
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1216
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1217
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1218
|
+
body: { schema },
|
1219
|
+
...this.extraProps
|
1220
|
+
});
|
1221
|
+
}
|
1222
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1223
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1224
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1225
|
+
body: { schema },
|
1226
|
+
...this.extraProps
|
1227
|
+
});
|
1228
|
+
}
|
1229
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1230
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1231
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1232
|
+
body: migration,
|
1233
|
+
...this.extraProps
|
1234
|
+
});
|
1235
|
+
}
|
1236
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1237
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1238
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1239
|
+
body: migration,
|
1240
|
+
...this.extraProps
|
1241
|
+
});
|
1242
|
+
}
|
1243
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1244
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1245
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1246
|
+
body: { edits },
|
1247
|
+
...this.extraProps
|
1248
|
+
});
|
1249
|
+
}
|
1250
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1251
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1252
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1253
|
+
body: options,
|
1254
|
+
...this.extraProps
|
1255
|
+
});
|
1256
|
+
}
|
1077
1257
|
}
|
1078
1258
|
|
1079
1259
|
class XataApiPlugin {
|
@@ -1258,14 +1438,22 @@ const _Query = class {
|
|
1258
1438
|
}
|
1259
1439
|
filter(a, b) {
|
1260
1440
|
if (arguments.length === 1) {
|
1261
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1441
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1262
1442
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1263
1443
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1264
1444
|
} else {
|
1265
|
-
const
|
1445
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1446
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1266
1447
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1267
1448
|
}
|
1268
1449
|
}
|
1450
|
+
defaultFilter(column, value) {
|
1451
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1452
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1453
|
+
return { $includes: value };
|
1454
|
+
}
|
1455
|
+
return value;
|
1456
|
+
}
|
1269
1457
|
sort(column, direction = "asc") {
|
1270
1458
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1271
1459
|
const sort = [...originalSort, { column, direction }];
|
@@ -1300,11 +1488,20 @@ const _Query = class {
|
|
1300
1488
|
}
|
1301
1489
|
}
|
1302
1490
|
async getMany(options = {}) {
|
1303
|
-
const
|
1491
|
+
const { pagination = {}, ...rest } = options;
|
1492
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1493
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1494
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1495
|
+
const results = [...page.records];
|
1496
|
+
while (page.hasNextPage() && results.length < size) {
|
1497
|
+
page = await page.nextPage();
|
1498
|
+
results.push(...page.records);
|
1499
|
+
}
|
1304
1500
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1305
1501
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1306
1502
|
}
|
1307
|
-
|
1503
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1504
|
+
return array;
|
1308
1505
|
}
|
1309
1506
|
async getAll(options = {}) {
|
1310
1507
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1318,6 +1515,12 @@ const _Query = class {
|
|
1318
1515
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1319
1516
|
return records[0] ?? null;
|
1320
1517
|
}
|
1518
|
+
async getFirstOrThrow(options = {}) {
|
1519
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1520
|
+
if (records[0] === void 0)
|
1521
|
+
throw new Error("No results found.");
|
1522
|
+
return records[0];
|
1523
|
+
}
|
1321
1524
|
cache(ttl) {
|
1322
1525
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1323
1526
|
}
|
@@ -1407,7 +1610,11 @@ class Repository extends Query {
|
|
1407
1610
|
}
|
1408
1611
|
class RestRepository extends Query {
|
1409
1612
|
constructor(options) {
|
1410
|
-
super(
|
1613
|
+
super(
|
1614
|
+
null,
|
1615
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1616
|
+
{}
|
1617
|
+
);
|
1411
1618
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1412
1619
|
__privateAdd$4(this, _insertRecordWithId);
|
1413
1620
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
@@ -1433,6 +1640,7 @@ class RestRepository extends Query {
|
|
1433
1640
|
return trace(name, fn, {
|
1434
1641
|
...options2,
|
1435
1642
|
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1643
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1436
1644
|
[TraceAttributes.VERSION]: VERSION
|
1437
1645
|
});
|
1438
1646
|
});
|
@@ -1470,16 +1678,16 @@ class RestRepository extends Query {
|
|
1470
1678
|
if (Array.isArray(a)) {
|
1471
1679
|
if (a.length === 0)
|
1472
1680
|
return [];
|
1473
|
-
const ids = a.map((item) =>
|
1474
|
-
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
1681
|
+
const ids = a.map((item) => extractId(item));
|
1682
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1475
1683
|
const dictionary = finalObjects.reduce((acc, object) => {
|
1476
1684
|
acc[object.id] = object;
|
1477
1685
|
return acc;
|
1478
1686
|
}, {});
|
1479
|
-
return ids.map((id2) => dictionary[id2] ?? null);
|
1687
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1480
1688
|
}
|
1481
|
-
const id =
|
1482
|
-
if (
|
1689
|
+
const id = extractId(a);
|
1690
|
+
if (id) {
|
1483
1691
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1484
1692
|
try {
|
1485
1693
|
const response = await getRecord({
|
@@ -1504,6 +1712,25 @@ class RestRepository extends Query {
|
|
1504
1712
|
return null;
|
1505
1713
|
});
|
1506
1714
|
}
|
1715
|
+
async readOrThrow(a, b) {
|
1716
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1717
|
+
const result = await this.read(a, b);
|
1718
|
+
if (Array.isArray(result)) {
|
1719
|
+
const missingIds = compact(
|
1720
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1721
|
+
);
|
1722
|
+
if (missingIds.length > 0) {
|
1723
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1724
|
+
}
|
1725
|
+
return result;
|
1726
|
+
}
|
1727
|
+
if (result === null) {
|
1728
|
+
const id = extractId(a) ?? "unknown";
|
1729
|
+
throw new Error(`Record with id ${id} not found`);
|
1730
|
+
}
|
1731
|
+
return result;
|
1732
|
+
});
|
1733
|
+
}
|
1507
1734
|
async update(a, b, c) {
|
1508
1735
|
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1509
1736
|
if (Array.isArray(a)) {
|
@@ -1526,6 +1753,25 @@ class RestRepository extends Query {
|
|
1526
1753
|
throw new Error("Invalid arguments for update method");
|
1527
1754
|
});
|
1528
1755
|
}
|
1756
|
+
async updateOrThrow(a, b, c) {
|
1757
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1758
|
+
const result = await this.update(a, b, c);
|
1759
|
+
if (Array.isArray(result)) {
|
1760
|
+
const missingIds = compact(
|
1761
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1762
|
+
);
|
1763
|
+
if (missingIds.length > 0) {
|
1764
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1765
|
+
}
|
1766
|
+
return result;
|
1767
|
+
}
|
1768
|
+
if (result === null) {
|
1769
|
+
const id = extractId(a) ?? "unknown";
|
1770
|
+
throw new Error(`Record with id ${id} not found`);
|
1771
|
+
}
|
1772
|
+
return result;
|
1773
|
+
});
|
1774
|
+
}
|
1529
1775
|
async createOrUpdate(a, b, c) {
|
1530
1776
|
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1531
1777
|
if (Array.isArray(a)) {
|
@@ -1548,28 +1794,43 @@ class RestRepository extends Query {
|
|
1548
1794
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1549
1795
|
});
|
1550
1796
|
}
|
1551
|
-
async delete(a) {
|
1797
|
+
async delete(a, b) {
|
1552
1798
|
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1553
1799
|
if (Array.isArray(a)) {
|
1554
1800
|
if (a.length === 0)
|
1555
|
-
return;
|
1801
|
+
return [];
|
1556
1802
|
if (a.length > 100) {
|
1557
1803
|
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1558
1804
|
}
|
1559
|
-
|
1560
|
-
return;
|
1805
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1561
1806
|
}
|
1562
1807
|
if (isString(a)) {
|
1563
|
-
|
1564
|
-
return;
|
1808
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1565
1809
|
}
|
1566
1810
|
if (isObject(a) && isString(a.id)) {
|
1567
|
-
|
1568
|
-
return;
|
1811
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1569
1812
|
}
|
1570
1813
|
throw new Error("Invalid arguments for delete method");
|
1571
1814
|
});
|
1572
1815
|
}
|
1816
|
+
async deleteOrThrow(a, b) {
|
1817
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1818
|
+
const result = await this.delete(a, b);
|
1819
|
+
if (Array.isArray(result)) {
|
1820
|
+
const missingIds = compact(
|
1821
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1822
|
+
);
|
1823
|
+
if (missingIds.length > 0) {
|
1824
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1825
|
+
}
|
1826
|
+
return result;
|
1827
|
+
} else if (result === null) {
|
1828
|
+
const id = extractId(a) ?? "unknown";
|
1829
|
+
throw new Error(`Record with id ${id} not found`);
|
1830
|
+
}
|
1831
|
+
return result;
|
1832
|
+
});
|
1833
|
+
}
|
1573
1834
|
async search(query, options = {}) {
|
1574
1835
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1575
1836
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1596,7 +1857,7 @@ class RestRepository extends Query {
|
|
1596
1857
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1597
1858
|
const data = query.getQueryOptions();
|
1598
1859
|
const body = {
|
1599
|
-
filter:
|
1860
|
+
filter: cleanFilter(data.filter),
|
1600
1861
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1601
1862
|
page: data.pagination,
|
1602
1863
|
columns: data.columns
|
@@ -1675,14 +1936,21 @@ _updateRecordWithID = new WeakSet();
|
|
1675
1936
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1676
1937
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1677
1938
|
const record = transformObjectLinks(object);
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1939
|
+
try {
|
1940
|
+
const response = await updateRecordWithID({
|
1941
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1942
|
+
queryParams: { columns },
|
1943
|
+
body: record,
|
1944
|
+
...fetchProps
|
1945
|
+
});
|
1946
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1947
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1948
|
+
} catch (e) {
|
1949
|
+
if (isObject(e) && e.status === 404) {
|
1950
|
+
return null;
|
1951
|
+
}
|
1952
|
+
throw e;
|
1953
|
+
}
|
1686
1954
|
};
|
1687
1955
|
_upsertRecordWithID = new WeakSet();
|
1688
1956
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1697,12 +1965,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1697
1965
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1698
1966
|
};
|
1699
1967
|
_deleteRecord = new WeakSet();
|
1700
|
-
deleteRecord_fn = async function(recordId) {
|
1968
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1701
1969
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1970
|
+
try {
|
1971
|
+
const response = await deleteRecord({
|
1972
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1973
|
+
queryParams: { columns },
|
1974
|
+
...fetchProps
|
1975
|
+
});
|
1976
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1977
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1978
|
+
} catch (e) {
|
1979
|
+
if (isObject(e) && e.status === 404) {
|
1980
|
+
return null;
|
1981
|
+
}
|
1982
|
+
throw e;
|
1983
|
+
}
|
1706
1984
|
};
|
1707
1985
|
_setCacheQuery = new WeakSet();
|
1708
1986
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1764,9 +2042,17 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1764
2042
|
console.error(`Failed to parse link for field ${column.name}`);
|
1765
2043
|
} else if (isObject(value)) {
|
1766
2044
|
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
2045
|
+
} else {
|
2046
|
+
result[column.name] = null;
|
1767
2047
|
}
|
1768
2048
|
break;
|
1769
2049
|
}
|
2050
|
+
default:
|
2051
|
+
result[column.name] = value ?? null;
|
2052
|
+
if (column.notNull === true && value === null) {
|
2053
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2054
|
+
}
|
2055
|
+
break;
|
1770
2056
|
}
|
1771
2057
|
}
|
1772
2058
|
result.read = function(columns2) {
|
@@ -1790,6 +2076,19 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1790
2076
|
function isResponseWithRecords(value) {
|
1791
2077
|
return isObject(value) && Array.isArray(value.records);
|
1792
2078
|
}
|
2079
|
+
function extractId(value) {
|
2080
|
+
if (isString(value))
|
2081
|
+
return value;
|
2082
|
+
if (isObject(value) && isString(value.id))
|
2083
|
+
return value.id;
|
2084
|
+
return void 0;
|
2085
|
+
}
|
2086
|
+
function cleanFilter(filter) {
|
2087
|
+
if (!filter)
|
2088
|
+
return void 0;
|
2089
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2090
|
+
return values.length > 0 ? filter : void 0;
|
2091
|
+
}
|
1793
2092
|
|
1794
2093
|
var __accessCheck$3 = (obj, member, msg) => {
|
1795
2094
|
if (!member.has(obj))
|
@@ -2162,7 +2461,7 @@ const buildClient = (plugins) => {
|
|
2162
2461
|
apiUrl: "",
|
2163
2462
|
workspacesApiUrl: (path, params) => {
|
2164
2463
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2165
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2464
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2166
2465
|
return databaseURL + newPath;
|
2167
2466
|
},
|
2168
2467
|
trace
|
@@ -2299,13 +2598,18 @@ exports.XataPlugin = XataPlugin;
|
|
2299
2598
|
exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
|
2300
2599
|
exports.addGitBranchesEntry = addGitBranchesEntry;
|
2301
2600
|
exports.addTableColumn = addTableColumn;
|
2601
|
+
exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
|
2302
2602
|
exports.buildClient = buildClient;
|
2303
2603
|
exports.buildWorkerRunner = buildWorkerRunner;
|
2304
2604
|
exports.bulkInsertTableRecords = bulkInsertTableRecords;
|
2305
2605
|
exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
|
2606
|
+
exports.compareBranchSchemas = compareBranchSchemas;
|
2607
|
+
exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
|
2608
|
+
exports.compareMigrationRequest = compareMigrationRequest;
|
2306
2609
|
exports.contains = contains;
|
2307
2610
|
exports.createBranch = createBranch;
|
2308
2611
|
exports.createDatabase = createDatabase;
|
2612
|
+
exports.createMigrationRequest = createMigrationRequest;
|
2309
2613
|
exports.createTable = createTable;
|
2310
2614
|
exports.createUserAPIKey = createUserAPIKey;
|
2311
2615
|
exports.createWorkspace = createWorkspace;
|
@@ -2329,6 +2633,7 @@ exports.getBranchList = getBranchList;
|
|
2329
2633
|
exports.getBranchMetadata = getBranchMetadata;
|
2330
2634
|
exports.getBranchMigrationHistory = getBranchMigrationHistory;
|
2331
2635
|
exports.getBranchMigrationPlan = getBranchMigrationPlan;
|
2636
|
+
exports.getBranchSchemaHistory = getBranchSchemaHistory;
|
2332
2637
|
exports.getBranchStats = getBranchStats;
|
2333
2638
|
exports.getColumn = getColumn;
|
2334
2639
|
exports.getCurrentBranchDetails = getCurrentBranchDetails;
|
@@ -2337,6 +2642,8 @@ exports.getDatabaseList = getDatabaseList;
|
|
2337
2642
|
exports.getDatabaseMetadata = getDatabaseMetadata;
|
2338
2643
|
exports.getDatabaseURL = getDatabaseURL;
|
2339
2644
|
exports.getGitBranchesMapping = getGitBranchesMapping;
|
2645
|
+
exports.getMigrationRequest = getMigrationRequest;
|
2646
|
+
exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
|
2340
2647
|
exports.getRecord = getRecord;
|
2341
2648
|
exports.getTableColumns = getTableColumns;
|
2342
2649
|
exports.getTableSchema = getTableSchema;
|
@@ -2366,11 +2673,15 @@ exports.le = le;
|
|
2366
2673
|
exports.lessEquals = lessEquals;
|
2367
2674
|
exports.lessThan = lessThan;
|
2368
2675
|
exports.lessThanEquals = lessThanEquals;
|
2676
|
+
exports.listMigrationRequests = listMigrationRequests;
|
2677
|
+
exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
|
2369
2678
|
exports.lt = lt;
|
2370
2679
|
exports.lte = lte;
|
2680
|
+
exports.mergeMigrationRequest = mergeMigrationRequest;
|
2371
2681
|
exports.notExists = notExists;
|
2372
2682
|
exports.operationsByTag = operationsByTag;
|
2373
2683
|
exports.pattern = pattern;
|
2684
|
+
exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
|
2374
2685
|
exports.queryTable = queryTable;
|
2375
2686
|
exports.removeGitBranchesEntry = removeGitBranchesEntry;
|
2376
2687
|
exports.removeWorkspaceMember = removeWorkspaceMember;
|
@@ -2381,8 +2692,12 @@ exports.searchTable = searchTable;
|
|
2381
2692
|
exports.serialize = serialize;
|
2382
2693
|
exports.setTableSchema = setTableSchema;
|
2383
2694
|
exports.startsWith = startsWith;
|
2695
|
+
exports.summarizeTable = summarizeTable;
|
2384
2696
|
exports.updateBranchMetadata = updateBranchMetadata;
|
2697
|
+
exports.updateBranchSchema = updateBranchSchema;
|
2385
2698
|
exports.updateColumn = updateColumn;
|
2699
|
+
exports.updateDatabaseMetadata = updateDatabaseMetadata;
|
2700
|
+
exports.updateMigrationRequest = updateMigrationRequest;
|
2386
2701
|
exports.updateRecordWithID = updateRecordWithID;
|
2387
2702
|
exports.updateTable = updateTable;
|
2388
2703
|
exports.updateUser = updateUser;
|