@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.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.
|
153
|
+
const VERSION = "0.18.0";
|
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>[^/]+).*/;
|
@@ -236,7 +237,7 @@ async function fetch$1({
|
|
236
237
|
}) {
|
237
238
|
return trace(
|
238
239
|
`${method.toUpperCase()} ${path}`,
|
239
|
-
async ({ setAttributes
|
240
|
+
async ({ setAttributes }) => {
|
240
241
|
const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
|
241
242
|
const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
|
242
243
|
const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
|
@@ -261,6 +262,7 @@ async function fetch$1({
|
|
261
262
|
const { host, protocol } = parseUrl(response.url);
|
262
263
|
const requestId = response.headers?.get("x-request-id") ?? void 0;
|
263
264
|
setAttributes({
|
265
|
+
[TraceAttributes.KIND]: "http",
|
264
266
|
[TraceAttributes.HTTP_REQUEST_ID]: requestId,
|
265
267
|
[TraceAttributes.HTTP_STATUS_CODE]: response.status,
|
266
268
|
[TraceAttributes.HTTP_HOST]: host,
|
@@ -273,9 +275,7 @@ async function fetch$1({
|
|
273
275
|
}
|
274
276
|
throw new FetcherError(response.status, jsonResponse, requestId);
|
275
277
|
} catch (error) {
|
276
|
-
|
277
|
-
onError(fetcherError.message);
|
278
|
-
throw fetcherError;
|
278
|
+
throw new FetcherError(response.status, error, requestId);
|
279
279
|
}
|
280
280
|
},
|
281
281
|
{ [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
|
@@ -386,6 +386,7 @@ const getDatabaseMetadata = (variables) => fetch$1({
|
|
386
386
|
method: "get",
|
387
387
|
...variables
|
388
388
|
});
|
389
|
+
const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
|
389
390
|
const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
|
390
391
|
const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
|
391
392
|
const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
|
@@ -394,6 +395,22 @@ const resolveBranch = (variables) => fetch$1({
|
|
394
395
|
method: "get",
|
395
396
|
...variables
|
396
397
|
});
|
398
|
+
const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
|
399
|
+
const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
|
400
|
+
const getMigrationRequest = (variables) => fetch$1({
|
401
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}",
|
402
|
+
method: "get",
|
403
|
+
...variables
|
404
|
+
});
|
405
|
+
const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
|
406
|
+
const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
|
407
|
+
const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
|
408
|
+
const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
|
409
|
+
const mergeMigrationRequest = (variables) => fetch$1({
|
410
|
+
url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
|
411
|
+
method: "post",
|
412
|
+
...variables
|
413
|
+
});
|
397
414
|
const getBranchDetails = (variables) => fetch$1({
|
398
415
|
url: "/db/{dbBranchName}",
|
399
416
|
method: "get",
|
@@ -418,6 +435,16 @@ const getBranchMetadata = (variables) => fetch$1({
|
|
418
435
|
const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
|
419
436
|
const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
|
420
437
|
const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
|
438
|
+
const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
|
439
|
+
const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
|
440
|
+
const updateBranchSchema = (variables) => fetch$1({
|
441
|
+
url: "/db/{dbBranchName}/schema/update",
|
442
|
+
method: "post",
|
443
|
+
...variables
|
444
|
+
});
|
445
|
+
const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
|
446
|
+
const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
|
447
|
+
const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
|
421
448
|
const getBranchStats = (variables) => fetch$1({
|
422
449
|
url: "/db/{dbBranchName}/stats",
|
423
450
|
method: "get",
|
@@ -503,6 +530,11 @@ const searchBranch = (variables) => fetch$1({
|
|
503
530
|
method: "post",
|
504
531
|
...variables
|
505
532
|
});
|
533
|
+
const summarizeTable = (variables) => fetch$1({
|
534
|
+
url: "/db/{dbBranchName}/tables/{tableName}/summarize",
|
535
|
+
method: "post",
|
536
|
+
...variables
|
537
|
+
});
|
506
538
|
const operationsByTag = {
|
507
539
|
users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
|
508
540
|
workspaces: {
|
@@ -525,6 +557,7 @@ const operationsByTag = {
|
|
525
557
|
createDatabase,
|
526
558
|
deleteDatabase,
|
527
559
|
getDatabaseMetadata,
|
560
|
+
updateDatabaseMetadata,
|
528
561
|
getGitBranchesMapping,
|
529
562
|
addGitBranchesEntry,
|
530
563
|
removeGitBranchesEntry,
|
@@ -537,10 +570,28 @@ const operationsByTag = {
|
|
537
570
|
deleteBranch,
|
538
571
|
updateBranchMetadata,
|
539
572
|
getBranchMetadata,
|
573
|
+
getBranchStats
|
574
|
+
},
|
575
|
+
migrationRequests: {
|
576
|
+
listMigrationRequests,
|
577
|
+
createMigrationRequest,
|
578
|
+
getMigrationRequest,
|
579
|
+
updateMigrationRequest,
|
580
|
+
listMigrationRequestsCommits,
|
581
|
+
compareMigrationRequest,
|
582
|
+
getMigrationRequestIsMerged,
|
583
|
+
mergeMigrationRequest
|
584
|
+
},
|
585
|
+
branchSchema: {
|
540
586
|
getBranchMigrationHistory,
|
541
587
|
executeBranchMigrationPlan,
|
542
588
|
getBranchMigrationPlan,
|
543
|
-
|
589
|
+
compareBranchWithUserSchema,
|
590
|
+
compareBranchSchemas,
|
591
|
+
updateBranchSchema,
|
592
|
+
previewBranchSchemaEdit,
|
593
|
+
applyBranchSchemaEdit,
|
594
|
+
getBranchSchemaHistory
|
544
595
|
},
|
545
596
|
table: {
|
546
597
|
createTable,
|
@@ -564,14 +615,15 @@ const operationsByTag = {
|
|
564
615
|
bulkInsertTableRecords,
|
565
616
|
queryTable,
|
566
617
|
searchTable,
|
567
|
-
searchBranch
|
618
|
+
searchBranch,
|
619
|
+
summarizeTable
|
568
620
|
}
|
569
621
|
};
|
570
622
|
|
571
623
|
function getHostUrl(provider, type) {
|
572
|
-
if (
|
624
|
+
if (isHostProviderAlias(provider)) {
|
573
625
|
return providers[provider][type];
|
574
|
-
} else if (
|
626
|
+
} else if (isHostProviderBuilder(provider)) {
|
575
627
|
return provider[type];
|
576
628
|
}
|
577
629
|
throw new Error("Invalid API provider");
|
@@ -586,10 +638,10 @@ const providers = {
|
|
586
638
|
workspaces: "https://{workspaceId}.staging.xatabase.co"
|
587
639
|
}
|
588
640
|
};
|
589
|
-
function
|
641
|
+
function isHostProviderAlias(alias) {
|
590
642
|
return isString(alias) && Object.keys(providers).includes(alias);
|
591
643
|
}
|
592
|
-
function
|
644
|
+
function isHostProviderBuilder(builder) {
|
593
645
|
return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
|
594
646
|
}
|
595
647
|
|
@@ -660,6 +712,16 @@ class XataApiClient {
|
|
660
712
|
__privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
|
661
713
|
return __privateGet$7(this, _namespaces).records;
|
662
714
|
}
|
715
|
+
get migrationRequests() {
|
716
|
+
if (!__privateGet$7(this, _namespaces).migrationRequests)
|
717
|
+
__privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
|
718
|
+
return __privateGet$7(this, _namespaces).migrationRequests;
|
719
|
+
}
|
720
|
+
get branchSchema() {
|
721
|
+
if (!__privateGet$7(this, _namespaces).branchSchema)
|
722
|
+
__privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
|
723
|
+
return __privateGet$7(this, _namespaces).branchSchema;
|
724
|
+
}
|
663
725
|
}
|
664
726
|
_extraProps = new WeakMap();
|
665
727
|
_namespaces = new WeakMap();
|
@@ -805,6 +867,13 @@ class DatabaseApi {
|
|
805
867
|
...this.extraProps
|
806
868
|
});
|
807
869
|
}
|
870
|
+
updateDatabaseMetadata(workspace, dbName, options = {}) {
|
871
|
+
return operationsByTag.database.updateDatabaseMetadata({
|
872
|
+
pathParams: { workspace, dbName },
|
873
|
+
body: options,
|
874
|
+
...this.extraProps
|
875
|
+
});
|
876
|
+
}
|
808
877
|
getGitBranchesMapping(workspace, dbName) {
|
809
878
|
return operationsByTag.database.getGitBranchesMapping({
|
810
879
|
pathParams: { workspace, dbName },
|
@@ -876,27 +945,6 @@ class BranchApi {
|
|
876
945
|
...this.extraProps
|
877
946
|
});
|
878
947
|
}
|
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
948
|
getBranchStats(workspace, database, branch) {
|
901
949
|
return operationsByTag.branch.getBranchStats({
|
902
950
|
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
@@ -1052,6 +1100,138 @@ class RecordsApi {
|
|
1052
1100
|
...this.extraProps
|
1053
1101
|
});
|
1054
1102
|
}
|
1103
|
+
summarizeTable(workspace, database, branch, tableName, query) {
|
1104
|
+
return operationsByTag.records.summarizeTable({
|
1105
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
|
1106
|
+
body: query,
|
1107
|
+
...this.extraProps
|
1108
|
+
});
|
1109
|
+
}
|
1110
|
+
}
|
1111
|
+
class MigrationRequestsApi {
|
1112
|
+
constructor(extraProps) {
|
1113
|
+
this.extraProps = extraProps;
|
1114
|
+
}
|
1115
|
+
listMigrationRequests(workspace, database, options = {}) {
|
1116
|
+
return operationsByTag.migrationRequests.listMigrationRequests({
|
1117
|
+
pathParams: { workspace, dbName: database },
|
1118
|
+
body: options,
|
1119
|
+
...this.extraProps
|
1120
|
+
});
|
1121
|
+
}
|
1122
|
+
createMigrationRequest(workspace, database, options) {
|
1123
|
+
return operationsByTag.migrationRequests.createMigrationRequest({
|
1124
|
+
pathParams: { workspace, dbName: database },
|
1125
|
+
body: options,
|
1126
|
+
...this.extraProps
|
1127
|
+
});
|
1128
|
+
}
|
1129
|
+
getMigrationRequest(workspace, database, migrationRequest) {
|
1130
|
+
return operationsByTag.migrationRequests.getMigrationRequest({
|
1131
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1132
|
+
...this.extraProps
|
1133
|
+
});
|
1134
|
+
}
|
1135
|
+
updateMigrationRequest(workspace, database, migrationRequest, options) {
|
1136
|
+
return operationsByTag.migrationRequests.updateMigrationRequest({
|
1137
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1138
|
+
body: options,
|
1139
|
+
...this.extraProps
|
1140
|
+
});
|
1141
|
+
}
|
1142
|
+
listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
|
1143
|
+
return operationsByTag.migrationRequests.listMigrationRequestsCommits({
|
1144
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1145
|
+
body: options,
|
1146
|
+
...this.extraProps
|
1147
|
+
});
|
1148
|
+
}
|
1149
|
+
compareMigrationRequest(workspace, database, migrationRequest) {
|
1150
|
+
return operationsByTag.migrationRequests.compareMigrationRequest({
|
1151
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1152
|
+
...this.extraProps
|
1153
|
+
});
|
1154
|
+
}
|
1155
|
+
getMigrationRequestIsMerged(workspace, database, migrationRequest) {
|
1156
|
+
return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
|
1157
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1158
|
+
...this.extraProps
|
1159
|
+
});
|
1160
|
+
}
|
1161
|
+
mergeMigrationRequest(workspace, database, migrationRequest) {
|
1162
|
+
return operationsByTag.migrationRequests.mergeMigrationRequest({
|
1163
|
+
pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
|
1164
|
+
...this.extraProps
|
1165
|
+
});
|
1166
|
+
}
|
1167
|
+
}
|
1168
|
+
class BranchSchemaApi {
|
1169
|
+
constructor(extraProps) {
|
1170
|
+
this.extraProps = extraProps;
|
1171
|
+
}
|
1172
|
+
getBranchMigrationHistory(workspace, database, branch, options = {}) {
|
1173
|
+
return operationsByTag.branchSchema.getBranchMigrationHistory({
|
1174
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1175
|
+
body: options,
|
1176
|
+
...this.extraProps
|
1177
|
+
});
|
1178
|
+
}
|
1179
|
+
executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
|
1180
|
+
return operationsByTag.branchSchema.executeBranchMigrationPlan({
|
1181
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1182
|
+
body: migrationPlan,
|
1183
|
+
...this.extraProps
|
1184
|
+
});
|
1185
|
+
}
|
1186
|
+
getBranchMigrationPlan(workspace, database, branch, schema) {
|
1187
|
+
return operationsByTag.branchSchema.getBranchMigrationPlan({
|
1188
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1189
|
+
body: schema,
|
1190
|
+
...this.extraProps
|
1191
|
+
});
|
1192
|
+
}
|
1193
|
+
compareBranchWithUserSchema(workspace, database, branch, schema) {
|
1194
|
+
return operationsByTag.branchSchema.compareBranchWithUserSchema({
|
1195
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1196
|
+
body: { schema },
|
1197
|
+
...this.extraProps
|
1198
|
+
});
|
1199
|
+
}
|
1200
|
+
compareBranchSchemas(workspace, database, branch, branchName, schema) {
|
1201
|
+
return operationsByTag.branchSchema.compareBranchSchemas({
|
1202
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
|
1203
|
+
body: { schema },
|
1204
|
+
...this.extraProps
|
1205
|
+
});
|
1206
|
+
}
|
1207
|
+
updateBranchSchema(workspace, database, branch, migration) {
|
1208
|
+
return operationsByTag.branchSchema.updateBranchSchema({
|
1209
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1210
|
+
body: migration,
|
1211
|
+
...this.extraProps
|
1212
|
+
});
|
1213
|
+
}
|
1214
|
+
previewBranchSchemaEdit(workspace, database, branch, migration) {
|
1215
|
+
return operationsByTag.branchSchema.previewBranchSchemaEdit({
|
1216
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1217
|
+
body: migration,
|
1218
|
+
...this.extraProps
|
1219
|
+
});
|
1220
|
+
}
|
1221
|
+
applyBranchSchemaEdit(workspace, database, branch, edits) {
|
1222
|
+
return operationsByTag.branchSchema.applyBranchSchemaEdit({
|
1223
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1224
|
+
body: { edits },
|
1225
|
+
...this.extraProps
|
1226
|
+
});
|
1227
|
+
}
|
1228
|
+
getBranchSchemaHistory(workspace, database, branch, options = {}) {
|
1229
|
+
return operationsByTag.branchSchema.getBranchSchemaHistory({
|
1230
|
+
pathParams: { workspace, dbBranchName: `${database}:${branch}` },
|
1231
|
+
body: options,
|
1232
|
+
...this.extraProps
|
1233
|
+
});
|
1234
|
+
}
|
1055
1235
|
}
|
1056
1236
|
|
1057
1237
|
class XataApiPlugin {
|
@@ -1236,14 +1416,22 @@ const _Query = class {
|
|
1236
1416
|
}
|
1237
1417
|
filter(a, b) {
|
1238
1418
|
if (arguments.length === 1) {
|
1239
|
-
const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
|
1419
|
+
const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
|
1240
1420
|
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1241
1421
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1242
1422
|
} else {
|
1243
|
-
const
|
1423
|
+
const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
|
1424
|
+
const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
|
1244
1425
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
|
1245
1426
|
}
|
1246
1427
|
}
|
1428
|
+
defaultFilter(column, value) {
|
1429
|
+
const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
|
1430
|
+
if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
|
1431
|
+
return { $includes: value };
|
1432
|
+
}
|
1433
|
+
return value;
|
1434
|
+
}
|
1247
1435
|
sort(column, direction = "asc") {
|
1248
1436
|
const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
|
1249
1437
|
const sort = [...originalSort, { column, direction }];
|
@@ -1278,11 +1466,20 @@ const _Query = class {
|
|
1278
1466
|
}
|
1279
1467
|
}
|
1280
1468
|
async getMany(options = {}) {
|
1281
|
-
const
|
1469
|
+
const { pagination = {}, ...rest } = options;
|
1470
|
+
const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
|
1471
|
+
const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
|
1472
|
+
let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
|
1473
|
+
const results = [...page.records];
|
1474
|
+
while (page.hasNextPage() && results.length < size) {
|
1475
|
+
page = await page.nextPage();
|
1476
|
+
results.push(...page.records);
|
1477
|
+
}
|
1282
1478
|
if (page.hasNextPage() && options.pagination?.size === void 0) {
|
1283
1479
|
console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
|
1284
1480
|
}
|
1285
|
-
|
1481
|
+
const array = new RecordArray(page, results.slice(0, size));
|
1482
|
+
return array;
|
1286
1483
|
}
|
1287
1484
|
async getAll(options = {}) {
|
1288
1485
|
const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
|
@@ -1296,6 +1493,12 @@ const _Query = class {
|
|
1296
1493
|
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1297
1494
|
return records[0] ?? null;
|
1298
1495
|
}
|
1496
|
+
async getFirstOrThrow(options = {}) {
|
1497
|
+
const records = await this.getMany({ ...options, pagination: { size: 1 } });
|
1498
|
+
if (records[0] === void 0)
|
1499
|
+
throw new Error("No results found.");
|
1500
|
+
return records[0];
|
1501
|
+
}
|
1299
1502
|
cache(ttl) {
|
1300
1503
|
return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
|
1301
1504
|
}
|
@@ -1385,7 +1588,11 @@ class Repository extends Query {
|
|
1385
1588
|
}
|
1386
1589
|
class RestRepository extends Query {
|
1387
1590
|
constructor(options) {
|
1388
|
-
super(
|
1591
|
+
super(
|
1592
|
+
null,
|
1593
|
+
{ name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
|
1594
|
+
{}
|
1595
|
+
);
|
1389
1596
|
__privateAdd$4(this, _insertRecordWithoutId);
|
1390
1597
|
__privateAdd$4(this, _insertRecordWithId);
|
1391
1598
|
__privateAdd$4(this, _bulkInsertTableRecords);
|
@@ -1411,6 +1618,7 @@ class RestRepository extends Query {
|
|
1411
1618
|
return trace(name, fn, {
|
1412
1619
|
...options2,
|
1413
1620
|
[TraceAttributes.TABLE]: __privateGet$4(this, _table),
|
1621
|
+
[TraceAttributes.KIND]: "sdk-operation",
|
1414
1622
|
[TraceAttributes.VERSION]: VERSION
|
1415
1623
|
});
|
1416
1624
|
});
|
@@ -1448,16 +1656,16 @@ class RestRepository extends Query {
|
|
1448
1656
|
if (Array.isArray(a)) {
|
1449
1657
|
if (a.length === 0)
|
1450
1658
|
return [];
|
1451
|
-
const ids = a.map((item) =>
|
1452
|
-
const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
|
1659
|
+
const ids = a.map((item) => extractId(item));
|
1660
|
+
const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
|
1453
1661
|
const dictionary = finalObjects.reduce((acc, object) => {
|
1454
1662
|
acc[object.id] = object;
|
1455
1663
|
return acc;
|
1456
1664
|
}, {});
|
1457
|
-
return ids.map((id2) => dictionary[id2] ?? null);
|
1665
|
+
return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
|
1458
1666
|
}
|
1459
|
-
const id =
|
1460
|
-
if (
|
1667
|
+
const id = extractId(a);
|
1668
|
+
if (id) {
|
1461
1669
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1462
1670
|
try {
|
1463
1671
|
const response = await getRecord({
|
@@ -1482,6 +1690,25 @@ class RestRepository extends Query {
|
|
1482
1690
|
return null;
|
1483
1691
|
});
|
1484
1692
|
}
|
1693
|
+
async readOrThrow(a, b) {
|
1694
|
+
return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
|
1695
|
+
const result = await this.read(a, b);
|
1696
|
+
if (Array.isArray(result)) {
|
1697
|
+
const missingIds = compact(
|
1698
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1699
|
+
);
|
1700
|
+
if (missingIds.length > 0) {
|
1701
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1702
|
+
}
|
1703
|
+
return result;
|
1704
|
+
}
|
1705
|
+
if (result === null) {
|
1706
|
+
const id = extractId(a) ?? "unknown";
|
1707
|
+
throw new Error(`Record with id ${id} not found`);
|
1708
|
+
}
|
1709
|
+
return result;
|
1710
|
+
});
|
1711
|
+
}
|
1485
1712
|
async update(a, b, c) {
|
1486
1713
|
return __privateGet$4(this, _trace).call(this, "update", async () => {
|
1487
1714
|
if (Array.isArray(a)) {
|
@@ -1504,6 +1731,25 @@ class RestRepository extends Query {
|
|
1504
1731
|
throw new Error("Invalid arguments for update method");
|
1505
1732
|
});
|
1506
1733
|
}
|
1734
|
+
async updateOrThrow(a, b, c) {
|
1735
|
+
return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
|
1736
|
+
const result = await this.update(a, b, c);
|
1737
|
+
if (Array.isArray(result)) {
|
1738
|
+
const missingIds = compact(
|
1739
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1740
|
+
);
|
1741
|
+
if (missingIds.length > 0) {
|
1742
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1743
|
+
}
|
1744
|
+
return result;
|
1745
|
+
}
|
1746
|
+
if (result === null) {
|
1747
|
+
const id = extractId(a) ?? "unknown";
|
1748
|
+
throw new Error(`Record with id ${id} not found`);
|
1749
|
+
}
|
1750
|
+
return result;
|
1751
|
+
});
|
1752
|
+
}
|
1507
1753
|
async createOrUpdate(a, b, c) {
|
1508
1754
|
return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
|
1509
1755
|
if (Array.isArray(a)) {
|
@@ -1526,28 +1772,43 @@ class RestRepository extends Query {
|
|
1526
1772
|
throw new Error("Invalid arguments for createOrUpdate method");
|
1527
1773
|
});
|
1528
1774
|
}
|
1529
|
-
async delete(a) {
|
1775
|
+
async delete(a, b) {
|
1530
1776
|
return __privateGet$4(this, _trace).call(this, "delete", async () => {
|
1531
1777
|
if (Array.isArray(a)) {
|
1532
1778
|
if (a.length === 0)
|
1533
|
-
return;
|
1779
|
+
return [];
|
1534
1780
|
if (a.length > 100) {
|
1535
1781
|
console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
|
1536
1782
|
}
|
1537
|
-
|
1538
|
-
return;
|
1783
|
+
return Promise.all(a.map((id) => this.delete(id, b)));
|
1539
1784
|
}
|
1540
1785
|
if (isString(a)) {
|
1541
|
-
|
1542
|
-
return;
|
1786
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
|
1543
1787
|
}
|
1544
1788
|
if (isObject(a) && isString(a.id)) {
|
1545
|
-
|
1546
|
-
return;
|
1789
|
+
return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
|
1547
1790
|
}
|
1548
1791
|
throw new Error("Invalid arguments for delete method");
|
1549
1792
|
});
|
1550
1793
|
}
|
1794
|
+
async deleteOrThrow(a, b) {
|
1795
|
+
return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
|
1796
|
+
const result = await this.delete(a, b);
|
1797
|
+
if (Array.isArray(result)) {
|
1798
|
+
const missingIds = compact(
|
1799
|
+
a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
|
1800
|
+
);
|
1801
|
+
if (missingIds.length > 0) {
|
1802
|
+
throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
|
1803
|
+
}
|
1804
|
+
return result;
|
1805
|
+
} else if (result === null) {
|
1806
|
+
const id = extractId(a) ?? "unknown";
|
1807
|
+
throw new Error(`Record with id ${id} not found`);
|
1808
|
+
}
|
1809
|
+
return result;
|
1810
|
+
});
|
1811
|
+
}
|
1551
1812
|
async search(query, options = {}) {
|
1552
1813
|
return __privateGet$4(this, _trace).call(this, "search", async () => {
|
1553
1814
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
@@ -1574,7 +1835,7 @@ class RestRepository extends Query {
|
|
1574
1835
|
return new Page(query, cacheQuery.meta, cacheQuery.records);
|
1575
1836
|
const data = query.getQueryOptions();
|
1576
1837
|
const body = {
|
1577
|
-
filter:
|
1838
|
+
filter: cleanFilter(data.filter),
|
1578
1839
|
sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
|
1579
1840
|
page: data.pagination,
|
1580
1841
|
columns: data.columns
|
@@ -1653,14 +1914,21 @@ _updateRecordWithID = new WeakSet();
|
|
1653
1914
|
updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
1654
1915
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1655
1916
|
const record = transformObjectLinks(object);
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1917
|
+
try {
|
1918
|
+
const response = await updateRecordWithID({
|
1919
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1920
|
+
queryParams: { columns },
|
1921
|
+
body: record,
|
1922
|
+
...fetchProps
|
1923
|
+
});
|
1924
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1925
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1926
|
+
} catch (e) {
|
1927
|
+
if (isObject(e) && e.status === 404) {
|
1928
|
+
return null;
|
1929
|
+
}
|
1930
|
+
throw e;
|
1931
|
+
}
|
1664
1932
|
};
|
1665
1933
|
_upsertRecordWithID = new WeakSet();
|
1666
1934
|
upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
@@ -1675,12 +1943,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
|
|
1675
1943
|
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1676
1944
|
};
|
1677
1945
|
_deleteRecord = new WeakSet();
|
1678
|
-
deleteRecord_fn = async function(recordId) {
|
1946
|
+
deleteRecord_fn = async function(recordId, columns = ["*"]) {
|
1679
1947
|
const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1948
|
+
try {
|
1949
|
+
const response = await deleteRecord({
|
1950
|
+
pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
|
1951
|
+
queryParams: { columns },
|
1952
|
+
...fetchProps
|
1953
|
+
});
|
1954
|
+
const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
|
1955
|
+
return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
|
1956
|
+
} catch (e) {
|
1957
|
+
if (isObject(e) && e.status === 404) {
|
1958
|
+
return null;
|
1959
|
+
}
|
1960
|
+
throw e;
|
1961
|
+
}
|
1684
1962
|
};
|
1685
1963
|
_setCacheQuery = new WeakSet();
|
1686
1964
|
setCacheQuery_fn = async function(query, meta, records) {
|
@@ -1742,9 +2020,17 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1742
2020
|
console.error(`Failed to parse link for field ${column.name}`);
|
1743
2021
|
} else if (isObject(value)) {
|
1744
2022
|
result[column.name] = initObject(db, schemaTables, linkTable, value);
|
2023
|
+
} else {
|
2024
|
+
result[column.name] = null;
|
1745
2025
|
}
|
1746
2026
|
break;
|
1747
2027
|
}
|
2028
|
+
default:
|
2029
|
+
result[column.name] = value ?? null;
|
2030
|
+
if (column.notNull === true && value === null) {
|
2031
|
+
console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
|
2032
|
+
}
|
2033
|
+
break;
|
1748
2034
|
}
|
1749
2035
|
}
|
1750
2036
|
result.read = function(columns2) {
|
@@ -1768,6 +2054,19 @@ const initObject = (db, schemaTables, table, object) => {
|
|
1768
2054
|
function isResponseWithRecords(value) {
|
1769
2055
|
return isObject(value) && Array.isArray(value.records);
|
1770
2056
|
}
|
2057
|
+
function extractId(value) {
|
2058
|
+
if (isString(value))
|
2059
|
+
return value;
|
2060
|
+
if (isObject(value) && isString(value.id))
|
2061
|
+
return value.id;
|
2062
|
+
return void 0;
|
2063
|
+
}
|
2064
|
+
function cleanFilter(filter) {
|
2065
|
+
if (!filter)
|
2066
|
+
return void 0;
|
2067
|
+
const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
|
2068
|
+
return values.length > 0 ? filter : void 0;
|
2069
|
+
}
|
1771
2070
|
|
1772
2071
|
var __accessCheck$3 = (obj, member, msg) => {
|
1773
2072
|
if (!member.has(obj))
|
@@ -2140,7 +2439,7 @@ const buildClient = (plugins) => {
|
|
2140
2439
|
apiUrl: "",
|
2141
2440
|
workspacesApiUrl: (path, params) => {
|
2142
2441
|
const hasBranch = params.dbBranchName ?? params.branch;
|
2143
|
-
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
|
2442
|
+
const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
|
2144
2443
|
return databaseURL + newPath;
|
2145
2444
|
},
|
2146
2445
|
trace
|
@@ -2255,5 +2554,5 @@ class XataError extends Error {
|
|
2255
2554
|
}
|
2256
2555
|
}
|
2257
2556
|
|
2258
|
-
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 };
|
2557
|
+
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, 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, getMigrationRequest, getMigrationRequestIsMerged, 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, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, summarizeTable, updateBranchMetadata, updateBranchSchema, updateColumn, updateDatabaseMetadata, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
|
2259
2558
|
//# sourceMappingURL=index.mjs.map
|