@xata.io/client 0.0.0-alpha.vf0c7bc2 → 0.0.0-alpha.vf0e0021

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.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",
@@ -146,13 +144,13 @@ function getFetchImplementation(userFetch) {
146
144
  const fetchImpl = userFetch ?? globalFetch;
147
145
  if (!fetchImpl) {
148
146
  throw new Error(
149
- `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
147
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
150
148
  );
151
149
  }
152
150
  return fetchImpl;
153
151
  }
154
152
 
155
- const VERSION = "0.0.0-alpha.vf0c7bc2";
153
+ const VERSION = "0.0.0-alpha.vf0e0021";
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
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
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 (!pathParams?.workspace)
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, onError }) => {
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
- const fetcherError = new FetcherError(response.status, error, requestId);
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,26 @@ 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
+ });
538
+ const cPgetDatabaseList = (variables) => fetch$1({
539
+ url: "/workspaces/{workspaceId}/dbs",
540
+ method: "get",
541
+ ...variables
542
+ });
543
+ const cPcreateDatabase = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables });
544
+ const cPdeleteDatabase = (variables) => fetch$1({
545
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
546
+ method: "delete",
547
+ ...variables
548
+ });
549
+ const cPgetCPDatabaseMetadata = (variables) => fetch$1(
550
+ { url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "get", ...variables }
551
+ );
552
+ const cPupdateCPDatabaseMetadata = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/dbs/{dbName}/metadata", method: "patch", ...variables });
506
553
  const operationsByTag = {
507
554
  users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
508
555
  workspaces: {
@@ -525,6 +572,7 @@ const operationsByTag = {
525
572
  createDatabase,
526
573
  deleteDatabase,
527
574
  getDatabaseMetadata,
575
+ updateDatabaseMetadata,
528
576
  getGitBranchesMapping,
529
577
  addGitBranchesEntry,
530
578
  removeGitBranchesEntry,
@@ -537,10 +585,28 @@ const operationsByTag = {
537
585
  deleteBranch,
538
586
  updateBranchMetadata,
539
587
  getBranchMetadata,
588
+ getBranchStats
589
+ },
590
+ migrationRequests: {
591
+ listMigrationRequests,
592
+ createMigrationRequest,
593
+ getMigrationRequest,
594
+ updateMigrationRequest,
595
+ listMigrationRequestsCommits,
596
+ compareMigrationRequest,
597
+ getMigrationRequestIsMerged,
598
+ mergeMigrationRequest
599
+ },
600
+ branchSchema: {
540
601
  getBranchMigrationHistory,
541
602
  executeBranchMigrationPlan,
542
603
  getBranchMigrationPlan,
543
- getBranchStats
604
+ compareBranchWithUserSchema,
605
+ compareBranchSchemas,
606
+ updateBranchSchema,
607
+ previewBranchSchemaEdit,
608
+ applyBranchSchemaEdit,
609
+ getBranchSchemaHistory
544
610
  },
545
611
  table: {
546
612
  createTable,
@@ -564,14 +630,22 @@ const operationsByTag = {
564
630
  bulkInsertTableRecords,
565
631
  queryTable,
566
632
  searchTable,
567
- searchBranch
633
+ searchBranch,
634
+ summarizeTable
635
+ },
636
+ databases: {
637
+ cPgetDatabaseList,
638
+ cPcreateDatabase,
639
+ cPdeleteDatabase,
640
+ cPgetCPDatabaseMetadata,
641
+ cPupdateCPDatabaseMetadata
568
642
  }
569
643
  };
570
644
 
571
645
  function getHostUrl(provider, type) {
572
- if (isValidAlias(provider)) {
646
+ if (isHostProviderAlias(provider)) {
573
647
  return providers[provider][type];
574
- } else if (isValidBuilder(provider)) {
648
+ } else if (isHostProviderBuilder(provider)) {
575
649
  return provider[type];
576
650
  }
577
651
  throw new Error("Invalid API provider");
@@ -586,10 +660,10 @@ const providers = {
586
660
  workspaces: "https://{workspaceId}.staging.xatabase.co"
587
661
  }
588
662
  };
589
- function isValidAlias(alias) {
663
+ function isHostProviderAlias(alias) {
590
664
  return isString(alias) && Object.keys(providers).includes(alias);
591
665
  }
592
- function isValidBuilder(builder) {
666
+ function isHostProviderBuilder(builder) {
593
667
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
594
668
  }
595
669
 
@@ -660,6 +734,16 @@ class XataApiClient {
660
734
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
661
735
  return __privateGet$7(this, _namespaces).records;
662
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
+ }
663
747
  }
664
748
  _extraProps = new WeakMap();
665
749
  _namespaces = new WeakMap();
@@ -805,6 +889,13 @@ class DatabaseApi {
805
889
  ...this.extraProps
806
890
  });
807
891
  }
892
+ updateDatabaseMetadata(workspace, dbName, options = {}) {
893
+ return operationsByTag.database.updateDatabaseMetadata({
894
+ pathParams: { workspace, dbName },
895
+ body: options,
896
+ ...this.extraProps
897
+ });
898
+ }
808
899
  getGitBranchesMapping(workspace, dbName) {
809
900
  return operationsByTag.database.getGitBranchesMapping({
810
901
  pathParams: { workspace, dbName },
@@ -876,27 +967,6 @@ class BranchApi {
876
967
  ...this.extraProps
877
968
  });
878
969
  }
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
970
  getBranchStats(workspace, database, branch) {
901
971
  return operationsByTag.branch.getBranchStats({
902
972
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -1052,6 +1122,138 @@ class RecordsApi {
1052
1122
  ...this.extraProps
1053
1123
  });
1054
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
+ }
1055
1257
  }
1056
1258
 
1057
1259
  class XataApiPlugin {
@@ -1177,9 +1379,14 @@ var __privateSet$5 = (obj, member, value, setter) => {
1177
1379
  setter ? setter.call(obj, value) : member.set(obj, value);
1178
1380
  return value;
1179
1381
  };
1180
- 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;
1181
1387
  const _Query = class {
1182
1388
  constructor(repository, table, data, rawParent) {
1389
+ __privateAdd$5(this, _cleanFilterConstraint);
1183
1390
  __privateAdd$5(this, _table$1, void 0);
1184
1391
  __privateAdd$5(this, _repository, void 0);
1185
1392
  __privateAdd$5(this, _data, { filter: {} });
@@ -1236,11 +1443,14 @@ const _Query = class {
1236
1443
  }
1237
1444
  filter(a, b) {
1238
1445
  if (arguments.length === 1) {
1239
- 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
+ }));
1240
1449
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1241
1450
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1242
1451
  } else {
1243
- 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));
1244
1454
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1245
1455
  }
1246
1456
  }
@@ -1278,11 +1488,20 @@ const _Query = class {
1278
1488
  }
1279
1489
  }
1280
1490
  async getMany(options = {}) {
1281
- 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
+ }
1282
1500
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1283
1501
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1284
1502
  }
1285
- return page.records;
1503
+ const array = new RecordArray(page, results.slice(0, size));
1504
+ return array;
1286
1505
  }
1287
1506
  async getAll(options = {}) {
1288
1507
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1296,6 +1515,12 @@ const _Query = class {
1296
1515
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1297
1516
  return records[0] ?? null;
1298
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
+ }
1299
1524
  cache(ttl) {
1300
1525
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1301
1526
  }
@@ -1319,6 +1544,17 @@ let Query = _Query;
1319
1544
  _table$1 = new WeakMap();
1320
1545
  _repository = new WeakMap();
1321
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
+ };
1322
1558
  function cleanParent(data, parent) {
1323
1559
  if (isCursorPaginationOptions(data.pagination)) {
1324
1560
  return { ...parent, sorting: void 0, filter: void 0 };
@@ -1385,7 +1621,11 @@ class Repository extends Query {
1385
1621
  }
1386
1622
  class RestRepository extends Query {
1387
1623
  constructor(options) {
1388
- super(null, options.table, {});
1624
+ super(
1625
+ null,
1626
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
1627
+ {}
1628
+ );
1389
1629
  __privateAdd$4(this, _insertRecordWithoutId);
1390
1630
  __privateAdd$4(this, _insertRecordWithId);
1391
1631
  __privateAdd$4(this, _bulkInsertTableRecords);
@@ -1411,6 +1651,7 @@ class RestRepository extends Query {
1411
1651
  return trace(name, fn, {
1412
1652
  ...options2,
1413
1653
  [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1654
+ [TraceAttributes.KIND]: "sdk-operation",
1414
1655
  [TraceAttributes.VERSION]: VERSION
1415
1656
  });
1416
1657
  });
@@ -1448,16 +1689,16 @@ class RestRepository extends Query {
1448
1689
  if (Array.isArray(a)) {
1449
1690
  if (a.length === 0)
1450
1691
  return [];
1451
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1452
- 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 });
1453
1694
  const dictionary = finalObjects.reduce((acc, object) => {
1454
1695
  acc[object.id] = object;
1455
1696
  return acc;
1456
1697
  }, {});
1457
- return ids.map((id2) => dictionary[id2] ?? null);
1698
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1458
1699
  }
1459
- const id = isString(a) ? a : a.id;
1460
- if (isString(id)) {
1700
+ const id = extractId(a);
1701
+ if (id) {
1461
1702
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1462
1703
  try {
1463
1704
  const response = await getRecord({
@@ -1471,7 +1712,7 @@ class RestRepository extends Query {
1471
1712
  ...fetchProps
1472
1713
  });
1473
1714
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1474
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1715
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1475
1716
  } catch (e) {
1476
1717
  if (isObject(e) && e.status === 404) {
1477
1718
  return null;
@@ -1482,6 +1723,25 @@ class RestRepository extends Query {
1482
1723
  return null;
1483
1724
  });
1484
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
+ }
1485
1745
  async update(a, b, c) {
1486
1746
  return __privateGet$4(this, _trace).call(this, "update", async () => {
1487
1747
  if (Array.isArray(a)) {
@@ -1504,6 +1764,25 @@ class RestRepository extends Query {
1504
1764
  throw new Error("Invalid arguments for update method");
1505
1765
  });
1506
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
+ }
1507
1786
  async createOrUpdate(a, b, c) {
1508
1787
  return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1509
1788
  if (Array.isArray(a)) {
@@ -1526,28 +1805,43 @@ class RestRepository extends Query {
1526
1805
  throw new Error("Invalid arguments for createOrUpdate method");
1527
1806
  });
1528
1807
  }
1529
- async delete(a) {
1808
+ async delete(a, b) {
1530
1809
  return __privateGet$4(this, _trace).call(this, "delete", async () => {
1531
1810
  if (Array.isArray(a)) {
1532
1811
  if (a.length === 0)
1533
- return;
1812
+ return [];
1534
1813
  if (a.length > 100) {
1535
1814
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1536
1815
  }
1537
- await Promise.all(a.map((id) => this.delete(id)));
1538
- return;
1816
+ return Promise.all(a.map((id) => this.delete(id, b)));
1539
1817
  }
1540
1818
  if (isString(a)) {
1541
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1542
- return;
1819
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1543
1820
  }
1544
1821
  if (isObject(a) && isString(a.id)) {
1545
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1546
- return;
1822
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1547
1823
  }
1548
1824
  throw new Error("Invalid arguments for delete method");
1549
1825
  });
1550
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
+ }
1551
1845
  async search(query, options = {}) {
1552
1846
  return __privateGet$4(this, _trace).call(this, "search", async () => {
1553
1847
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1564,7 +1858,7 @@ class RestRepository extends Query {
1564
1858
  ...fetchProps
1565
1859
  });
1566
1860
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1567
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1861
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
1568
1862
  });
1569
1863
  }
1570
1864
  async query(query) {
@@ -1574,7 +1868,7 @@ class RestRepository extends Query {
1574
1868
  return new Page(query, cacheQuery.meta, cacheQuery.records);
1575
1869
  const data = query.getQueryOptions();
1576
1870
  const body = {
1577
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1871
+ filter: cleanFilter(data.filter),
1578
1872
  sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1579
1873
  page: data.pagination,
1580
1874
  columns: data.columns
@@ -1586,7 +1880,9 @@ class RestRepository extends Query {
1586
1880
  ...fetchProps
1587
1881
  });
1588
1882
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1589
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1883
+ const records = objects.map(
1884
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
1885
+ );
1590
1886
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1591
1887
  return new Page(query, meta, records);
1592
1888
  });
@@ -1613,7 +1909,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1613
1909
  ...fetchProps
1614
1910
  });
1615
1911
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1616
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1912
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1617
1913
  };
1618
1914
  _insertRecordWithId = new WeakSet();
1619
1915
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
@@ -1631,7 +1927,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1631
1927
  ...fetchProps
1632
1928
  });
1633
1929
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1634
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1930
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1635
1931
  };
1636
1932
  _bulkInsertTableRecords = new WeakSet();
1637
1933
  bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
@@ -1647,20 +1943,27 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1647
1943
  throw new Error("Request included columns but server didn't include them");
1648
1944
  }
1649
1945
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1650
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1946
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
1651
1947
  };
1652
1948
  _updateRecordWithID = new WeakSet();
1653
1949
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1654
1950
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1655
1951
  const record = transformObjectLinks(object);
1656
- const response = await updateRecordWithID({
1657
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1658
- queryParams: { columns },
1659
- body: record,
1660
- ...fetchProps
1661
- });
1662
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1663
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1952
+ try {
1953
+ const response = await updateRecordWithID({
1954
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1955
+ queryParams: { columns },
1956
+ body: record,
1957
+ ...fetchProps
1958
+ });
1959
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1960
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1961
+ } catch (e) {
1962
+ if (isObject(e) && e.status === 404) {
1963
+ return null;
1964
+ }
1965
+ throw e;
1966
+ }
1664
1967
  };
1665
1968
  _upsertRecordWithID = new WeakSet();
1666
1969
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1672,15 +1975,25 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1672
1975
  ...fetchProps
1673
1976
  });
1674
1977
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1675
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1978
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1676
1979
  };
1677
1980
  _deleteRecord = new WeakSet();
1678
- deleteRecord_fn = async function(recordId) {
1981
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1679
1982
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1680
- await deleteRecord({
1681
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1682
- ...fetchProps
1683
- });
1983
+ try {
1984
+ const response = await deleteRecord({
1985
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1986
+ queryParams: { columns },
1987
+ ...fetchProps
1988
+ });
1989
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1990
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1991
+ } catch (e) {
1992
+ if (isObject(e) && e.status === 404) {
1993
+ return null;
1994
+ }
1995
+ throw e;
1996
+ }
1684
1997
  };
1685
1998
  _setCacheQuery = new WeakSet();
1686
1999
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1717,7 +2030,7 @@ const transformObjectLinks = (object) => {
1717
2030
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1718
2031
  }, {});
1719
2032
  };
1720
- const initObject = (db, schemaTables, table, object) => {
2033
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
1721
2034
  const result = {};
1722
2035
  const { xata, ...rest } = object ?? {};
1723
2036
  Object.assign(result, rest);
@@ -1725,6 +2038,8 @@ const initObject = (db, schemaTables, table, object) => {
1725
2038
  if (!columns)
1726
2039
  console.error(`Table ${table} not found in schema`);
1727
2040
  for (const column of columns ?? []) {
2041
+ if (!isValidColumn(selectedColumns, column))
2042
+ continue;
1728
2043
  const value = result[column.name];
1729
2044
  switch (column.type) {
1730
2045
  case "datetime": {
@@ -1741,10 +2056,28 @@ const initObject = (db, schemaTables, table, object) => {
1741
2056
  if (!linkTable) {
1742
2057
  console.error(`Failed to parse link for field ${column.name}`);
1743
2058
  } else if (isObject(value)) {
1744
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2059
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2060
+ if (item === column.name) {
2061
+ return [...acc, "*"];
2062
+ }
2063
+ if (item.startsWith(`${column.name}.`)) {
2064
+ const [, ...path] = item.split(".");
2065
+ return [...acc, path.join(".")];
2066
+ }
2067
+ return acc;
2068
+ }, []);
2069
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2070
+ } else {
2071
+ result[column.name] = null;
1745
2072
  }
1746
2073
  break;
1747
2074
  }
2075
+ default:
2076
+ result[column.name] = value ?? null;
2077
+ if (column.notNull === true && value === null) {
2078
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2079
+ }
2080
+ break;
1748
2081
  }
1749
2082
  }
1750
2083
  result.read = function(columns2) {
@@ -1768,6 +2101,28 @@ const initObject = (db, schemaTables, table, object) => {
1768
2101
  function isResponseWithRecords(value) {
1769
2102
  return isObject(value) && Array.isArray(value.records);
1770
2103
  }
2104
+ function extractId(value) {
2105
+ if (isString(value))
2106
+ return value;
2107
+ if (isObject(value) && isString(value.id))
2108
+ return value.id;
2109
+ return void 0;
2110
+ }
2111
+ function cleanFilter(filter) {
2112
+ if (!filter)
2113
+ return void 0;
2114
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2115
+ return values.length > 0 ? filter : void 0;
2116
+ }
2117
+ function isValidColumn(columns, column) {
2118
+ if (columns.includes("*"))
2119
+ return true;
2120
+ if (column.type === "link") {
2121
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2122
+ return linkColumns.length > 0;
2123
+ }
2124
+ return columns.includes(column.name);
2125
+ }
1771
2126
 
1772
2127
  var __accessCheck$3 = (obj, member, msg) => {
1773
2128
  if (!member.has(obj))
@@ -1818,18 +2173,25 @@ class SimpleCache {
1818
2173
  }
1819
2174
  _map = new WeakMap();
1820
2175
 
1821
- const gt = (value) => ({ $gt: value });
1822
- const ge = (value) => ({ $ge: value });
1823
- const gte = (value) => ({ $ge: value });
1824
- const lt = (value) => ({ $lt: value });
1825
- const lte = (value) => ({ $le: value });
1826
- const le = (value) => ({ $le: value });
2176
+ const greaterThan = (value) => ({ $gt: value });
2177
+ const gt = greaterThan;
2178
+ const greaterThanEquals = (value) => ({ $ge: value });
2179
+ const greaterEquals = greaterThanEquals;
2180
+ const gte = greaterThanEquals;
2181
+ const ge = greaterThanEquals;
2182
+ const lessThan = (value) => ({ $lt: value });
2183
+ const lt = lessThan;
2184
+ const lessThanEquals = (value) => ({ $le: value });
2185
+ const lessEquals = lessThanEquals;
2186
+ const lte = lessThanEquals;
2187
+ const le = lessThanEquals;
1827
2188
  const exists = (column) => ({ $exists: column });
1828
2189
  const notExists = (column) => ({ $notExists: column });
1829
2190
  const startsWith = (value) => ({ $startsWith: value });
1830
2191
  const endsWith = (value) => ({ $endsWith: value });
1831
2192
  const pattern = (value) => ({ $pattern: value });
1832
2193
  const is = (value) => ({ $is: value });
2194
+ const equals = is;
1833
2195
  const isNot = (value) => ({ $isNot: value });
1834
2196
  const contains = (value) => ({ $contains: value });
1835
2197
  const includes = (value) => ({ $includes: value });
@@ -1926,7 +2288,7 @@ class SearchPlugin extends XataPlugin {
1926
2288
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1927
2289
  return records.map((record) => {
1928
2290
  const { table = "orphan" } = record.xata;
1929
- return { table, record: initObject(this.db, schemaTables, table, record) };
2291
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1930
2292
  });
1931
2293
  },
1932
2294
  byTable: async (query, options = {}) => {
@@ -1935,7 +2297,7 @@ class SearchPlugin extends XataPlugin {
1935
2297
  return records.reduce((acc, record) => {
1936
2298
  const { table = "orphan" } = record.xata;
1937
2299
  const items = acc[table] ?? [];
1938
- const item = initObject(this.db, schemaTables, table, record);
2300
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1939
2301
  return { ...acc, [table]: [...items, item] };
1940
2302
  }, {});
1941
2303
  }
@@ -2116,8 +2478,11 @@ const buildClient = (plugins) => {
2116
2478
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2117
2479
  const trace = options?.trace ?? defaultTrace;
2118
2480
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2119
- if (!databaseURL || !apiKey) {
2120
- throw new Error("Options databaseURL and apiKey are required");
2481
+ if (!apiKey) {
2482
+ throw new Error("Option apiKey is required");
2483
+ }
2484
+ if (!databaseURL) {
2485
+ throw new Error("Option databaseURL is required");
2121
2486
  }
2122
2487
  return { fetch, databaseURL, apiKey, branch, cache, trace };
2123
2488
  }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
@@ -2130,7 +2495,7 @@ const buildClient = (plugins) => {
2130
2495
  apiUrl: "",
2131
2496
  workspacesApiUrl: (path, params) => {
2132
2497
  const hasBranch = params.dbBranchName ?? params.branch;
2133
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2498
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2134
2499
  return databaseURL + newPath;
2135
2500
  },
2136
2501
  trace
@@ -2245,5 +2610,5 @@ class XataError extends Error {
2245
2610
  }
2246
2611
  }
2247
2612
 
2248
- 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, 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, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2613
+ 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, cPcreateDatabase, cPdeleteDatabase, cPgetCPDatabaseMetadata, cPgetDatabaseList, cPupdateCPDatabaseMetadata, 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 };
2249
2614
  //# sourceMappingURL=index.mjs.map