@xata.io/client 0.0.0-alpha.vfe4a947 → 0.0.0-alpha.vfe9bed6

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/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",
@@ -168,13 +166,13 @@ function getFetchImplementation(userFetch) {
168
166
  const fetchImpl = userFetch ?? globalFetch;
169
167
  if (!fetchImpl) {
170
168
  throw new Error(
171
- `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
169
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
172
170
  );
173
171
  }
174
172
  return fetchImpl;
175
173
  }
176
174
 
177
- const VERSION = "0.0.0-alpha.vfe4a947";
175
+ const VERSION = "0.0.0-alpha.vfe9bed6";
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
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
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 (!pathParams?.workspace)
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, onError }) => {
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
- const fetcherError = new FetcherError(response.status, error, requestId);
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
- getBranchStats
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 (isValidAlias(provider)) {
646
+ if (isHostProviderAlias(provider)) {
595
647
  return providers[provider][type];
596
- } else if (isValidBuilder(provider)) {
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 isValidAlias(alias) {
663
+ function isHostProviderAlias(alias) {
612
664
  return isString(alias) && Object.keys(providers).includes(alias);
613
665
  }
614
- function isValidBuilder(builder) {
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 {
@@ -1199,9 +1379,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1199
1379
  setter ? setter.call(obj, value) : member.set(obj, value);
1200
1380
  return value;
1201
1381
  };
1202
- var _table$1, _repository, _data;
1382
+ var __privateMethod$3 = (obj, member, method) => {
1383
+ __accessCheck$5(obj, member, "access private method");
1384
+ return method;
1385
+ };
1386
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
1203
1387
  const _Query = class {
1204
1388
  constructor(repository, table, data, rawParent) {
1389
+ __privateAdd$5(this, _cleanFilterConstraint);
1205
1390
  __privateAdd$5(this, _table$1, void 0);
1206
1391
  __privateAdd$5(this, _repository, void 0);
1207
1392
  __privateAdd$5(this, _data, { filter: {} });
@@ -1258,11 +1443,14 @@ const _Query = class {
1258
1443
  }
1259
1444
  filter(a, b) {
1260
1445
  if (arguments.length === 1) {
1261
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1446
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
1447
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
1448
+ }));
1262
1449
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1263
1450
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1264
1451
  } else {
1265
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1452
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
1453
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1266
1454
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1267
1455
  }
1268
1456
  }
@@ -1300,11 +1488,20 @@ const _Query = class {
1300
1488
  }
1301
1489
  }
1302
1490
  async getMany(options = {}) {
1303
- const page = await this.getPaginated(options);
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
- return page.records;
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
  }
@@ -1341,6 +1544,17 @@ let Query = _Query;
1341
1544
  _table$1 = new WeakMap();
1342
1545
  _repository = new WeakMap();
1343
1546
  _data = new WeakMap();
1547
+ _cleanFilterConstraint = new WeakSet();
1548
+ cleanFilterConstraint_fn = function(column, value) {
1549
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1550
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1551
+ return { $includes: value };
1552
+ }
1553
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
1554
+ return value.id;
1555
+ }
1556
+ return value;
1557
+ };
1344
1558
  function cleanParent(data, parent) {
1345
1559
  if (isCursorPaginationOptions(data.pagination)) {
1346
1560
  return { ...parent, sorting: void 0, filter: void 0 };
@@ -1407,7 +1621,11 @@ class Repository extends Query {
1407
1621
  }
1408
1622
  class RestRepository extends Query {
1409
1623
  constructor(options) {
1410
- super(null, options.table, {});
1624
+ super(
1625
+ null,
1626
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
1627
+ {}
1628
+ );
1411
1629
  __privateAdd$4(this, _insertRecordWithoutId);
1412
1630
  __privateAdd$4(this, _insertRecordWithId);
1413
1631
  __privateAdd$4(this, _bulkInsertTableRecords);
@@ -1433,6 +1651,7 @@ class RestRepository extends Query {
1433
1651
  return trace(name, fn, {
1434
1652
  ...options2,
1435
1653
  [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1654
+ [TraceAttributes.KIND]: "sdk-operation",
1436
1655
  [TraceAttributes.VERSION]: VERSION
1437
1656
  });
1438
1657
  });
@@ -1470,16 +1689,16 @@ class RestRepository extends Query {
1470
1689
  if (Array.isArray(a)) {
1471
1690
  if (a.length === 0)
1472
1691
  return [];
1473
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1474
- const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1692
+ const ids = a.map((item) => extractId(item));
1693
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
1475
1694
  const dictionary = finalObjects.reduce((acc, object) => {
1476
1695
  acc[object.id] = object;
1477
1696
  return acc;
1478
1697
  }, {});
1479
- return ids.map((id2) => dictionary[id2] ?? null);
1698
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1480
1699
  }
1481
- const id = isString(a) ? a : a.id;
1482
- if (isString(id)) {
1700
+ const id = extractId(a);
1701
+ if (id) {
1483
1702
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1484
1703
  try {
1485
1704
  const response = await getRecord({
@@ -1504,6 +1723,25 @@ class RestRepository extends Query {
1504
1723
  return null;
1505
1724
  });
1506
1725
  }
1726
+ async readOrThrow(a, b) {
1727
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
1728
+ const result = await this.read(a, b);
1729
+ if (Array.isArray(result)) {
1730
+ const missingIds = compact(
1731
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1732
+ );
1733
+ if (missingIds.length > 0) {
1734
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1735
+ }
1736
+ return result;
1737
+ }
1738
+ if (result === null) {
1739
+ const id = extractId(a) ?? "unknown";
1740
+ throw new Error(`Record with id ${id} not found`);
1741
+ }
1742
+ return result;
1743
+ });
1744
+ }
1507
1745
  async update(a, b, c) {
1508
1746
  return __privateGet$4(this, _trace).call(this, "update", async () => {
1509
1747
  if (Array.isArray(a)) {
@@ -1526,6 +1764,25 @@ class RestRepository extends Query {
1526
1764
  throw new Error("Invalid arguments for update method");
1527
1765
  });
1528
1766
  }
1767
+ async updateOrThrow(a, b, c) {
1768
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
1769
+ const result = await this.update(a, b, c);
1770
+ if (Array.isArray(result)) {
1771
+ const missingIds = compact(
1772
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1773
+ );
1774
+ if (missingIds.length > 0) {
1775
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1776
+ }
1777
+ return result;
1778
+ }
1779
+ if (result === null) {
1780
+ const id = extractId(a) ?? "unknown";
1781
+ throw new Error(`Record with id ${id} not found`);
1782
+ }
1783
+ return result;
1784
+ });
1785
+ }
1529
1786
  async createOrUpdate(a, b, c) {
1530
1787
  return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1531
1788
  if (Array.isArray(a)) {
@@ -1548,28 +1805,43 @@ class RestRepository extends Query {
1548
1805
  throw new Error("Invalid arguments for createOrUpdate method");
1549
1806
  });
1550
1807
  }
1551
- async delete(a) {
1808
+ async delete(a, b) {
1552
1809
  return __privateGet$4(this, _trace).call(this, "delete", async () => {
1553
1810
  if (Array.isArray(a)) {
1554
1811
  if (a.length === 0)
1555
- return;
1812
+ return [];
1556
1813
  if (a.length > 100) {
1557
1814
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1558
1815
  }
1559
- await Promise.all(a.map((id) => this.delete(id)));
1560
- return;
1816
+ return Promise.all(a.map((id) => this.delete(id, b)));
1561
1817
  }
1562
1818
  if (isString(a)) {
1563
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1564
- return;
1819
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1565
1820
  }
1566
1821
  if (isObject(a) && isString(a.id)) {
1567
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1568
- return;
1822
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1569
1823
  }
1570
1824
  throw new Error("Invalid arguments for delete method");
1571
1825
  });
1572
1826
  }
1827
+ async deleteOrThrow(a, b) {
1828
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
1829
+ const result = await this.delete(a, b);
1830
+ if (Array.isArray(result)) {
1831
+ const missingIds = compact(
1832
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1833
+ );
1834
+ if (missingIds.length > 0) {
1835
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1836
+ }
1837
+ return result;
1838
+ } else if (result === null) {
1839
+ const id = extractId(a) ?? "unknown";
1840
+ throw new Error(`Record with id ${id} not found`);
1841
+ }
1842
+ return result;
1843
+ });
1844
+ }
1573
1845
  async search(query, options = {}) {
1574
1846
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1575
1847
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1596,7 +1868,7 @@ class RestRepository extends Query {
1596
1868
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1597
1869
  const data = query.getQueryOptions();
1598
1870
  const body = {
1599
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1871
+ filter: cleanFilter(data.filter),
1600
1872
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1601
1873
  page: data.pagination,
1602
1874
  columns: data.columns
@@ -1675,14 +1947,21 @@ _updateRecordWithID = new WeakSet();
1675
1947
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1676
1948
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1677
1949
  const record = transformObjectLinks(object);
1678
- const response = await updateRecordWithID({
1679
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1680
- queryParams: { columns },
1681
- body: record,
1682
- ...fetchProps
1683
- });
1684
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1685
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1950
+ try {
1951
+ const response = await updateRecordWithID({
1952
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1953
+ queryParams: { columns },
1954
+ body: record,
1955
+ ...fetchProps
1956
+ });
1957
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1958
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1959
+ } catch (e) {
1960
+ if (isObject(e) && e.status === 404) {
1961
+ return null;
1962
+ }
1963
+ throw e;
1964
+ }
1686
1965
  };
1687
1966
  _upsertRecordWithID = new WeakSet();
1688
1967
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1697,12 +1976,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1697
1976
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1698
1977
  };
1699
1978
  _deleteRecord = new WeakSet();
1700
- deleteRecord_fn = async function(recordId) {
1979
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1701
1980
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1702
- await deleteRecord({
1703
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1704
- ...fetchProps
1705
- });
1981
+ try {
1982
+ const response = await deleteRecord({
1983
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1984
+ queryParams: { columns },
1985
+ ...fetchProps
1986
+ });
1987
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1988
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1989
+ } catch (e) {
1990
+ if (isObject(e) && e.status === 404) {
1991
+ return null;
1992
+ }
1993
+ throw e;
1994
+ }
1706
1995
  };
1707
1996
  _setCacheQuery = new WeakSet();
1708
1997
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1764,9 +2053,17 @@ const initObject = (db, schemaTables, table, object) => {
1764
2053
  console.error(`Failed to parse link for field ${column.name}`);
1765
2054
  } else if (isObject(value)) {
1766
2055
  result[column.name] = initObject(db, schemaTables, linkTable, value);
2056
+ } else {
2057
+ result[column.name] = null;
1767
2058
  }
1768
2059
  break;
1769
2060
  }
2061
+ default:
2062
+ result[column.name] = value ?? null;
2063
+ if (column.notNull === true && value === null) {
2064
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2065
+ }
2066
+ break;
1770
2067
  }
1771
2068
  }
1772
2069
  result.read = function(columns2) {
@@ -1790,6 +2087,19 @@ const initObject = (db, schemaTables, table, object) => {
1790
2087
  function isResponseWithRecords(value) {
1791
2088
  return isObject(value) && Array.isArray(value.records);
1792
2089
  }
2090
+ function extractId(value) {
2091
+ if (isString(value))
2092
+ return value;
2093
+ if (isObject(value) && isString(value.id))
2094
+ return value.id;
2095
+ return void 0;
2096
+ }
2097
+ function cleanFilter(filter) {
2098
+ if (!filter)
2099
+ return void 0;
2100
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2101
+ return values.length > 0 ? filter : void 0;
2102
+ }
1793
2103
 
1794
2104
  var __accessCheck$3 = (obj, member, msg) => {
1795
2105
  if (!member.has(obj))
@@ -2162,7 +2472,7 @@ const buildClient = (plugins) => {
2162
2472
  apiUrl: "",
2163
2473
  workspacesApiUrl: (path, params) => {
2164
2474
  const hasBranch = params.dbBranchName ?? params.branch;
2165
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2475
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2166
2476
  return databaseURL + newPath;
2167
2477
  },
2168
2478
  trace
@@ -2299,13 +2609,18 @@ exports.XataPlugin = XataPlugin;
2299
2609
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2300
2610
  exports.addGitBranchesEntry = addGitBranchesEntry;
2301
2611
  exports.addTableColumn = addTableColumn;
2612
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
2302
2613
  exports.buildClient = buildClient;
2303
2614
  exports.buildWorkerRunner = buildWorkerRunner;
2304
2615
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2305
2616
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2617
+ exports.compareBranchSchemas = compareBranchSchemas;
2618
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
2619
+ exports.compareMigrationRequest = compareMigrationRequest;
2306
2620
  exports.contains = contains;
2307
2621
  exports.createBranch = createBranch;
2308
2622
  exports.createDatabase = createDatabase;
2623
+ exports.createMigrationRequest = createMigrationRequest;
2309
2624
  exports.createTable = createTable;
2310
2625
  exports.createUserAPIKey = createUserAPIKey;
2311
2626
  exports.createWorkspace = createWorkspace;
@@ -2329,6 +2644,7 @@ exports.getBranchList = getBranchList;
2329
2644
  exports.getBranchMetadata = getBranchMetadata;
2330
2645
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
2331
2646
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
2647
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
2332
2648
  exports.getBranchStats = getBranchStats;
2333
2649
  exports.getColumn = getColumn;
2334
2650
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
@@ -2337,6 +2653,8 @@ exports.getDatabaseList = getDatabaseList;
2337
2653
  exports.getDatabaseMetadata = getDatabaseMetadata;
2338
2654
  exports.getDatabaseURL = getDatabaseURL;
2339
2655
  exports.getGitBranchesMapping = getGitBranchesMapping;
2656
+ exports.getMigrationRequest = getMigrationRequest;
2657
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2340
2658
  exports.getRecord = getRecord;
2341
2659
  exports.getTableColumns = getTableColumns;
2342
2660
  exports.getTableSchema = getTableSchema;
@@ -2366,11 +2684,15 @@ exports.le = le;
2366
2684
  exports.lessEquals = lessEquals;
2367
2685
  exports.lessThan = lessThan;
2368
2686
  exports.lessThanEquals = lessThanEquals;
2687
+ exports.listMigrationRequests = listMigrationRequests;
2688
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
2369
2689
  exports.lt = lt;
2370
2690
  exports.lte = lte;
2691
+ exports.mergeMigrationRequest = mergeMigrationRequest;
2371
2692
  exports.notExists = notExists;
2372
2693
  exports.operationsByTag = operationsByTag;
2373
2694
  exports.pattern = pattern;
2695
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
2374
2696
  exports.queryTable = queryTable;
2375
2697
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2376
2698
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2381,8 +2703,12 @@ exports.searchTable = searchTable;
2381
2703
  exports.serialize = serialize;
2382
2704
  exports.setTableSchema = setTableSchema;
2383
2705
  exports.startsWith = startsWith;
2706
+ exports.summarizeTable = summarizeTable;
2384
2707
  exports.updateBranchMetadata = updateBranchMetadata;
2708
+ exports.updateBranchSchema = updateBranchSchema;
2385
2709
  exports.updateColumn = updateColumn;
2710
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
2711
+ exports.updateMigrationRequest = updateMigrationRequest;
2386
2712
  exports.updateRecordWithID = updateRecordWithID;
2387
2713
  exports.updateTable = updateTable;
2388
2714
  exports.updateUser = updateUser;