@xata.io/client 0.0.0-alpha.vf73045e → 0.0.0-alpha.vf7d30cc

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
@@ -20,6 +20,28 @@ function _interopNamespace(e) {
20
20
  return Object.freeze(n);
21
21
  }
22
22
 
23
+ const defaultTrace = async (_name, fn, _options) => {
24
+ return await fn({
25
+ setAttributes: () => {
26
+ return;
27
+ }
28
+ });
29
+ };
30
+ const TraceAttributes = {
31
+ KIND: "xata.trace.kind",
32
+ VERSION: "xata.sdk.version",
33
+ TABLE: "xata.table",
34
+ HTTP_REQUEST_ID: "http.request_id",
35
+ HTTP_STATUS_CODE: "http.status_code",
36
+ HTTP_HOST: "http.host",
37
+ HTTP_SCHEME: "http.scheme",
38
+ HTTP_USER_AGENT: "http.user_agent",
39
+ HTTP_METHOD: "http.method",
40
+ HTTP_URL: "http.url",
41
+ HTTP_ROUTE: "http.route",
42
+ HTTP_TARGET: "http.target"
43
+ };
44
+
23
45
  function notEmpty(value) {
24
46
  return value !== null && value !== void 0;
25
47
  }
@@ -144,13 +166,13 @@ function getFetchImplementation(userFetch) {
144
166
  const fetchImpl = userFetch ?? globalFetch;
145
167
  if (!fetchImpl) {
146
168
  throw new Error(
147
- `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.`
148
170
  );
149
171
  }
150
172
  return fetchImpl;
151
173
  }
152
174
 
153
- const VERSION = "0.0.0-alpha.vf73045e";
175
+ const VERSION = "0.0.0-alpha.vf7d30cc";
154
176
 
155
177
  class ErrorWithCause extends Error {
156
178
  constructor(message, options) {
@@ -201,7 +223,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
201
223
  }, {});
202
224
  const query = new URLSearchParams(cleanQueryParams).toString();
203
225
  const queryString = query.length > 0 ? `?${query}` : "";
204
- 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;
205
230
  };
206
231
  function buildBaseUrl({
207
232
  path,
@@ -209,10 +234,10 @@ function buildBaseUrl({
209
234
  apiUrl,
210
235
  pathParams
211
236
  }) {
212
- if (!pathParams?.workspace)
237
+ if (pathParams?.workspace === void 0)
213
238
  return `${apiUrl}${path}`;
214
239
  const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
215
- return url.replace("{workspaceId}", pathParams.workspace);
240
+ return url.replace("{workspaceId}", String(pathParams.workspace));
216
241
  }
217
242
  function hostHeader(url) {
218
243
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -229,34 +254,61 @@ async function fetch$1({
229
254
  fetchImpl,
230
255
  apiKey,
231
256
  apiUrl,
232
- workspacesApiUrl
257
+ workspacesApiUrl,
258
+ trace
233
259
  }) {
234
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
235
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
236
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
237
- const response = await fetchImpl(url, {
238
- method: method.toUpperCase(),
239
- body: body ? JSON.stringify(body) : void 0,
240
- headers: {
241
- "Content-Type": "application/json",
242
- "User-Agent": `Xata client-ts/${VERSION}`,
243
- ...headers,
244
- ...hostHeader(fullUrl),
245
- Authorization: `Bearer ${apiKey}`
246
- }
247
- });
248
- if (response.status === 204) {
249
- return {};
250
- }
251
- const requestId = response.headers?.get("x-request-id") ?? void 0;
260
+ return trace(
261
+ `${method.toUpperCase()} ${path}`,
262
+ async ({ setAttributes }) => {
263
+ const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
264
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
265
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
266
+ setAttributes({
267
+ [TraceAttributes.HTTP_URL]: url,
268
+ [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
269
+ });
270
+ const response = await fetchImpl(url, {
271
+ method: method.toUpperCase(),
272
+ body: body ? JSON.stringify(body) : void 0,
273
+ headers: {
274
+ "Content-Type": "application/json",
275
+ "User-Agent": `Xata client-ts/${VERSION}`,
276
+ ...headers,
277
+ ...hostHeader(fullUrl),
278
+ Authorization: `Bearer ${apiKey}`
279
+ }
280
+ });
281
+ if (response.status === 204) {
282
+ return {};
283
+ }
284
+ const { host, protocol } = parseUrl(response.url);
285
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
286
+ setAttributes({
287
+ [TraceAttributes.KIND]: "http",
288
+ [TraceAttributes.HTTP_REQUEST_ID]: requestId,
289
+ [TraceAttributes.HTTP_STATUS_CODE]: response.status,
290
+ [TraceAttributes.HTTP_HOST]: host,
291
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
292
+ });
293
+ try {
294
+ const jsonResponse = await response.json();
295
+ if (response.ok) {
296
+ return jsonResponse;
297
+ }
298
+ throw new FetcherError(response.status, jsonResponse, requestId);
299
+ } catch (error) {
300
+ throw new FetcherError(response.status, error, requestId);
301
+ }
302
+ },
303
+ { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
304
+ );
305
+ }
306
+ function parseUrl(url) {
252
307
  try {
253
- const jsonResponse = await response.json();
254
- if (response.ok) {
255
- return jsonResponse;
256
- }
257
- throw new FetcherError(response.status, jsonResponse, requestId);
308
+ const { host, protocol } = new URL(url);
309
+ return { host, protocol };
258
310
  } catch (error) {
259
- throw new FetcherError(response.status, error, requestId);
311
+ return {};
260
312
  }
261
313
  }
262
314
 
@@ -356,6 +408,7 @@ const getDatabaseMetadata = (variables) => fetch$1({
356
408
  method: "get",
357
409
  ...variables
358
410
  });
411
+ const updateDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
359
412
  const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
360
413
  const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
361
414
  const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
@@ -364,6 +417,22 @@ const resolveBranch = (variables) => fetch$1({
364
417
  method: "get",
365
418
  ...variables
366
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
+ });
367
436
  const getBranchDetails = (variables) => fetch$1({
368
437
  url: "/db/{dbBranchName}",
369
438
  method: "get",
@@ -388,6 +457,16 @@ const getBranchMetadata = (variables) => fetch$1({
388
457
  const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
389
458
  const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
390
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 });
391
470
  const getBranchStats = (variables) => fetch$1({
392
471
  url: "/db/{dbBranchName}/stats",
393
472
  method: "get",
@@ -473,6 +552,11 @@ const searchBranch = (variables) => fetch$1({
473
552
  method: "post",
474
553
  ...variables
475
554
  });
555
+ const summarizeTable = (variables) => fetch$1({
556
+ url: "/db/{dbBranchName}/tables/{tableName}/summarize",
557
+ method: "post",
558
+ ...variables
559
+ });
476
560
  const operationsByTag = {
477
561
  users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
478
562
  workspaces: {
@@ -495,6 +579,7 @@ const operationsByTag = {
495
579
  createDatabase,
496
580
  deleteDatabase,
497
581
  getDatabaseMetadata,
582
+ updateDatabaseMetadata,
498
583
  getGitBranchesMapping,
499
584
  addGitBranchesEntry,
500
585
  removeGitBranchesEntry,
@@ -507,10 +592,28 @@ const operationsByTag = {
507
592
  deleteBranch,
508
593
  updateBranchMetadata,
509
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: {
510
608
  getBranchMigrationHistory,
511
609
  executeBranchMigrationPlan,
512
610
  getBranchMigrationPlan,
513
- getBranchStats
611
+ compareBranchWithUserSchema,
612
+ compareBranchSchemas,
613
+ updateBranchSchema,
614
+ previewBranchSchemaEdit,
615
+ applyBranchSchemaEdit,
616
+ getBranchSchemaHistory
514
617
  },
515
618
  table: {
516
619
  createTable,
@@ -534,14 +637,15 @@ const operationsByTag = {
534
637
  bulkInsertTableRecords,
535
638
  queryTable,
536
639
  searchTable,
537
- searchBranch
640
+ searchBranch,
641
+ summarizeTable
538
642
  }
539
643
  };
540
644
 
541
645
  function getHostUrl(provider, type) {
542
- if (isValidAlias(provider)) {
646
+ if (isHostProviderAlias(provider)) {
543
647
  return providers[provider][type];
544
- } else if (isValidBuilder(provider)) {
648
+ } else if (isHostProviderBuilder(provider)) {
545
649
  return provider[type];
546
650
  }
547
651
  throw new Error("Invalid API provider");
@@ -556,10 +660,10 @@ const providers = {
556
660
  workspaces: "https://{workspaceId}.staging.xatabase.co"
557
661
  }
558
662
  };
559
- function isValidAlias(alias) {
663
+ function isHostProviderAlias(alias) {
560
664
  return isString(alias) && Object.keys(providers).includes(alias);
561
665
  }
562
- function isValidBuilder(builder) {
666
+ function isHostProviderBuilder(builder) {
563
667
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
564
668
  }
565
669
 
@@ -587,7 +691,8 @@ class XataApiClient {
587
691
  __privateAdd$7(this, _extraProps, void 0);
588
692
  __privateAdd$7(this, _namespaces, {});
589
693
  const provider = options.host ?? "production";
590
- const apiKey = options?.apiKey ?? getAPIKey();
694
+ const apiKey = options.apiKey ?? getAPIKey();
695
+ const trace = options.trace ?? defaultTrace;
591
696
  if (!apiKey) {
592
697
  throw new Error("Could not resolve a valid apiKey");
593
698
  }
@@ -595,7 +700,8 @@ class XataApiClient {
595
700
  apiUrl: getHostUrl(provider, "main"),
596
701
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
597
702
  fetchImpl: getFetchImplementation(options.fetch),
598
- apiKey
703
+ apiKey,
704
+ trace
599
705
  });
600
706
  }
601
707
  get user() {
@@ -628,6 +734,16 @@ class XataApiClient {
628
734
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
629
735
  return __privateGet$7(this, _namespaces).records;
630
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
+ }
631
747
  }
632
748
  _extraProps = new WeakMap();
633
749
  _namespaces = new WeakMap();
@@ -773,6 +889,13 @@ class DatabaseApi {
773
889
  ...this.extraProps
774
890
  });
775
891
  }
892
+ updateDatabaseMetadata(workspace, dbName, options = {}) {
893
+ return operationsByTag.database.updateDatabaseMetadata({
894
+ pathParams: { workspace, dbName },
895
+ body: options,
896
+ ...this.extraProps
897
+ });
898
+ }
776
899
  getGitBranchesMapping(workspace, dbName) {
777
900
  return operationsByTag.database.getGitBranchesMapping({
778
901
  pathParams: { workspace, dbName },
@@ -844,27 +967,6 @@ class BranchApi {
844
967
  ...this.extraProps
845
968
  });
846
969
  }
847
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
848
- return operationsByTag.branch.getBranchMigrationHistory({
849
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
850
- body: options,
851
- ...this.extraProps
852
- });
853
- }
854
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
855
- return operationsByTag.branch.executeBranchMigrationPlan({
856
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
857
- body: migrationPlan,
858
- ...this.extraProps
859
- });
860
- }
861
- getBranchMigrationPlan(workspace, database, branch, schema) {
862
- return operationsByTag.branch.getBranchMigrationPlan({
863
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
864
- body: schema,
865
- ...this.extraProps
866
- });
867
- }
868
970
  getBranchStats(workspace, database, branch) {
869
971
  return operationsByTag.branch.getBranchStats({
870
972
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -1020,6 +1122,138 @@ class RecordsApi {
1020
1122
  ...this.extraProps
1021
1123
  });
1022
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
+ }
1023
1257
  }
1024
1258
 
1025
1259
  class XataApiPlugin {
@@ -1204,14 +1438,22 @@ const _Query = class {
1204
1438
  }
1205
1439
  filter(a, b) {
1206
1440
  if (arguments.length === 1) {
1207
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1441
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
1208
1442
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1209
1443
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1210
1444
  } else {
1211
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1445
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
1446
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1212
1447
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1213
1448
  }
1214
1449
  }
1450
+ defaultFilter(column, value) {
1451
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1452
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1453
+ return { $includes: value };
1454
+ }
1455
+ return value;
1456
+ }
1215
1457
  sort(column, direction = "asc") {
1216
1458
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1217
1459
  const sort = [...originalSort, { column, direction }];
@@ -1246,11 +1488,20 @@ const _Query = class {
1246
1488
  }
1247
1489
  }
1248
1490
  async getMany(options = {}) {
1249
- 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
+ }
1250
1500
  if (page.hasNextPage() && options.pagination?.size === void 0) {
1251
1501
  console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1252
1502
  }
1253
- return page.records;
1503
+ const array = new RecordArray(page, results.slice(0, size));
1504
+ return array;
1254
1505
  }
1255
1506
  async getAll(options = {}) {
1256
1507
  const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
@@ -1264,6 +1515,12 @@ const _Query = class {
1264
1515
  const records = await this.getMany({ ...options, pagination: { size: 1 } });
1265
1516
  return records[0] ?? null;
1266
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
+ }
1267
1524
  cache(ttl) {
1268
1525
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1269
1526
  }
@@ -1348,12 +1605,16 @@ var __privateMethod$2 = (obj, member, method) => {
1348
1605
  __accessCheck$4(obj, member, "access private method");
1349
1606
  return method;
1350
1607
  };
1351
- var _table, _getFetchProps, _db, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
1608
+ var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
1352
1609
  class Repository extends Query {
1353
1610
  }
1354
1611
  class RestRepository extends Query {
1355
1612
  constructor(options) {
1356
- super(null, options.table, {});
1613
+ super(
1614
+ null,
1615
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
1616
+ {}
1617
+ );
1357
1618
  __privateAdd$4(this, _insertRecordWithoutId);
1358
1619
  __privateAdd$4(this, _insertRecordWithId);
1359
1620
  __privateAdd$4(this, _bulkInsertTableRecords);
@@ -1368,168 +1629,250 @@ class RestRepository extends Query {
1368
1629
  __privateAdd$4(this, _db, void 0);
1369
1630
  __privateAdd$4(this, _cache, void 0);
1370
1631
  __privateAdd$4(this, _schemaTables$2, void 0);
1632
+ __privateAdd$4(this, _trace, void 0);
1371
1633
  __privateSet$4(this, _table, options.table);
1372
1634
  __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1373
1635
  __privateSet$4(this, _db, options.db);
1374
1636
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1375
1637
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1638
+ const trace = options.pluginOptions.trace ?? defaultTrace;
1639
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1640
+ return trace(name, fn, {
1641
+ ...options2,
1642
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1643
+ [TraceAttributes.KIND]: "sdk-operation",
1644
+ [TraceAttributes.VERSION]: VERSION
1645
+ });
1646
+ });
1376
1647
  }
1377
1648
  async create(a, b, c) {
1378
- if (Array.isArray(a)) {
1379
- if (a.length === 0)
1380
- return [];
1381
- const columns = isStringArray(b) ? b : void 0;
1382
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1383
- }
1384
- if (isString(a) && isObject(b)) {
1385
- if (a === "")
1386
- throw new Error("The id can't be empty");
1387
- const columns = isStringArray(c) ? c : void 0;
1388
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1389
- }
1390
- if (isObject(a) && isString(a.id)) {
1391
- if (a.id === "")
1392
- throw new Error("The id can't be empty");
1393
- const columns = isStringArray(b) ? b : void 0;
1394
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1395
- }
1396
- if (isObject(a)) {
1397
- const columns = isStringArray(b) ? b : void 0;
1398
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1399
- }
1400
- throw new Error("Invalid arguments for create method");
1649
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
1650
+ if (Array.isArray(a)) {
1651
+ if (a.length === 0)
1652
+ return [];
1653
+ const columns = isStringArray(b) ? b : void 0;
1654
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1655
+ }
1656
+ if (isString(a) && isObject(b)) {
1657
+ if (a === "")
1658
+ throw new Error("The id can't be empty");
1659
+ const columns = isStringArray(c) ? c : void 0;
1660
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1661
+ }
1662
+ if (isObject(a) && isString(a.id)) {
1663
+ if (a.id === "")
1664
+ throw new Error("The id can't be empty");
1665
+ const columns = isStringArray(b) ? b : void 0;
1666
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1667
+ }
1668
+ if (isObject(a)) {
1669
+ const columns = isStringArray(b) ? b : void 0;
1670
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1671
+ }
1672
+ throw new Error("Invalid arguments for create method");
1673
+ });
1401
1674
  }
1402
1675
  async read(a, b) {
1403
- const columns = isStringArray(b) ? b : ["*"];
1404
- if (Array.isArray(a)) {
1405
- if (a.length === 0)
1406
- return [];
1407
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1408
- const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1409
- const dictionary = finalObjects.reduce((acc, object) => {
1410
- acc[object.id] = object;
1411
- return acc;
1412
- }, {});
1413
- return ids.map((id2) => dictionary[id2] ?? null);
1414
- }
1415
- const id = isString(a) ? a : a.id;
1416
- if (isString(id)) {
1417
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1418
- try {
1419
- const response = await getRecord({
1420
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1421
- queryParams: { columns },
1422
- ...fetchProps
1423
- });
1424
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1425
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1426
- } catch (e) {
1427
- if (isObject(e) && e.status === 404) {
1428
- return null;
1676
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
1677
+ const columns = isStringArray(b) ? b : ["*"];
1678
+ if (Array.isArray(a)) {
1679
+ if (a.length === 0)
1680
+ return [];
1681
+ const ids = a.map((item) => extractId(item));
1682
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
1683
+ const dictionary = finalObjects.reduce((acc, object) => {
1684
+ acc[object.id] = object;
1685
+ return acc;
1686
+ }, {});
1687
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1688
+ }
1689
+ const id = extractId(a);
1690
+ if (id) {
1691
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1692
+ try {
1693
+ const response = await getRecord({
1694
+ pathParams: {
1695
+ workspace: "{workspaceId}",
1696
+ dbBranchName: "{dbBranch}",
1697
+ tableName: __privateGet$4(this, _table),
1698
+ recordId: id
1699
+ },
1700
+ queryParams: { columns },
1701
+ ...fetchProps
1702
+ });
1703
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1704
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1705
+ } catch (e) {
1706
+ if (isObject(e) && e.status === 404) {
1707
+ return null;
1708
+ }
1709
+ throw e;
1429
1710
  }
1430
- throw e;
1431
1711
  }
1432
- }
1433
- return null;
1712
+ return null;
1713
+ });
1714
+ }
1715
+ async readOrThrow(a, b) {
1716
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
1717
+ const result = await this.read(a, b);
1718
+ if (Array.isArray(result)) {
1719
+ const missingIds = compact(
1720
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1721
+ );
1722
+ if (missingIds.length > 0) {
1723
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1724
+ }
1725
+ return result;
1726
+ }
1727
+ if (result === null) {
1728
+ const id = extractId(a) ?? "unknown";
1729
+ throw new Error(`Record with id ${id} not found`);
1730
+ }
1731
+ return result;
1732
+ });
1434
1733
  }
1435
1734
  async update(a, b, c) {
1436
- if (Array.isArray(a)) {
1437
- if (a.length === 0)
1438
- return [];
1439
- if (a.length > 100) {
1440
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1735
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
1736
+ if (Array.isArray(a)) {
1737
+ if (a.length === 0)
1738
+ return [];
1739
+ if (a.length > 100) {
1740
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1741
+ }
1742
+ const columns = isStringArray(b) ? b : ["*"];
1743
+ return Promise.all(a.map((object) => this.update(object, columns)));
1441
1744
  }
1442
- const columns = isStringArray(b) ? b : ["*"];
1443
- return Promise.all(a.map((object) => this.update(object, columns)));
1444
- }
1445
- if (isString(a) && isObject(b)) {
1446
- const columns = isStringArray(c) ? c : void 0;
1447
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1448
- }
1449
- if (isObject(a) && isString(a.id)) {
1450
- const columns = isStringArray(b) ? b : void 0;
1451
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1452
- }
1453
- throw new Error("Invalid arguments for update method");
1745
+ if (isString(a) && isObject(b)) {
1746
+ const columns = isStringArray(c) ? c : void 0;
1747
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1748
+ }
1749
+ if (isObject(a) && isString(a.id)) {
1750
+ const columns = isStringArray(b) ? b : void 0;
1751
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1752
+ }
1753
+ throw new Error("Invalid arguments for update method");
1754
+ });
1755
+ }
1756
+ async updateOrThrow(a, b, c) {
1757
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
1758
+ const result = await this.update(a, b, c);
1759
+ if (Array.isArray(result)) {
1760
+ const missingIds = compact(
1761
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1762
+ );
1763
+ if (missingIds.length > 0) {
1764
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1765
+ }
1766
+ return result;
1767
+ }
1768
+ if (result === null) {
1769
+ const id = extractId(a) ?? "unknown";
1770
+ throw new Error(`Record with id ${id} not found`);
1771
+ }
1772
+ return result;
1773
+ });
1454
1774
  }
1455
1775
  async createOrUpdate(a, b, c) {
1456
- if (Array.isArray(a)) {
1457
- if (a.length === 0)
1458
- return [];
1459
- if (a.length > 100) {
1460
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1776
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1777
+ if (Array.isArray(a)) {
1778
+ if (a.length === 0)
1779
+ return [];
1780
+ if (a.length > 100) {
1781
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1782
+ }
1783
+ const columns = isStringArray(b) ? b : ["*"];
1784
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1461
1785
  }
1462
- const columns = isStringArray(b) ? b : ["*"];
1463
- return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1464
- }
1465
- if (isString(a) && isObject(b)) {
1466
- const columns = isStringArray(c) ? c : void 0;
1467
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1468
- }
1469
- if (isObject(a) && isString(a.id)) {
1470
- const columns = isStringArray(c) ? c : void 0;
1471
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1472
- }
1473
- throw new Error("Invalid arguments for createOrUpdate method");
1474
- }
1475
- async delete(a) {
1476
- if (Array.isArray(a)) {
1477
- if (a.length === 0)
1478
- return;
1479
- if (a.length > 100) {
1480
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1786
+ if (isString(a) && isObject(b)) {
1787
+ const columns = isStringArray(c) ? c : void 0;
1788
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1481
1789
  }
1482
- await Promise.all(a.map((id) => this.delete(id)));
1483
- return;
1484
- }
1485
- if (isString(a)) {
1486
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1487
- return;
1488
- }
1489
- if (isObject(a) && isString(a.id)) {
1490
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1491
- return;
1492
- }
1493
- throw new Error("Invalid arguments for delete method");
1790
+ if (isObject(a) && isString(a.id)) {
1791
+ const columns = isStringArray(c) ? c : void 0;
1792
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1793
+ }
1794
+ throw new Error("Invalid arguments for createOrUpdate method");
1795
+ });
1796
+ }
1797
+ async delete(a, b) {
1798
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
1799
+ if (Array.isArray(a)) {
1800
+ if (a.length === 0)
1801
+ return [];
1802
+ if (a.length > 100) {
1803
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1804
+ }
1805
+ return Promise.all(a.map((id) => this.delete(id, b)));
1806
+ }
1807
+ if (isString(a)) {
1808
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1809
+ }
1810
+ if (isObject(a) && isString(a.id)) {
1811
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1812
+ }
1813
+ throw new Error("Invalid arguments for delete method");
1814
+ });
1815
+ }
1816
+ async deleteOrThrow(a, b) {
1817
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
1818
+ const result = await this.delete(a, b);
1819
+ if (Array.isArray(result)) {
1820
+ const missingIds = compact(
1821
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
1822
+ );
1823
+ if (missingIds.length > 0) {
1824
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
1825
+ }
1826
+ return result;
1827
+ } else if (result === null) {
1828
+ const id = extractId(a) ?? "unknown";
1829
+ throw new Error(`Record with id ${id} not found`);
1830
+ }
1831
+ return result;
1832
+ });
1494
1833
  }
1495
1834
  async search(query, options = {}) {
1496
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1497
- const { records } = await searchTable({
1498
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1499
- body: {
1500
- query,
1501
- fuzziness: options.fuzziness,
1502
- prefix: options.prefix,
1503
- highlight: options.highlight,
1504
- filter: options.filter,
1505
- boosters: options.boosters
1506
- },
1507
- ...fetchProps
1835
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
1836
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1837
+ const { records } = await searchTable({
1838
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1839
+ body: {
1840
+ query,
1841
+ fuzziness: options.fuzziness,
1842
+ prefix: options.prefix,
1843
+ highlight: options.highlight,
1844
+ filter: options.filter,
1845
+ boosters: options.boosters
1846
+ },
1847
+ ...fetchProps
1848
+ });
1849
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1850
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1508
1851
  });
1509
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1510
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1511
1852
  }
1512
1853
  async query(query) {
1513
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1514
- if (cacheQuery)
1515
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1516
- const data = query.getQueryOptions();
1517
- const body = {
1518
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1519
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1520
- page: data.pagination,
1521
- columns: data.columns
1522
- };
1523
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1524
- const { meta, records: objects } = await queryTable({
1525
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1526
- body,
1527
- ...fetchProps
1854
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
1855
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1856
+ if (cacheQuery)
1857
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1858
+ const data = query.getQueryOptions();
1859
+ const body = {
1860
+ filter: cleanFilter(data.filter),
1861
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1862
+ page: data.pagination,
1863
+ columns: data.columns
1864
+ };
1865
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1866
+ const { meta, records: objects } = await queryTable({
1867
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1868
+ body,
1869
+ ...fetchProps
1870
+ });
1871
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1872
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1873
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1874
+ return new Page(query, meta, records);
1528
1875
  });
1529
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1530
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1531
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1532
- return new Page(query, meta, records);
1533
1876
  }
1534
1877
  }
1535
1878
  _table = new WeakMap();
@@ -1537,6 +1880,7 @@ _getFetchProps = new WeakMap();
1537
1880
  _db = new WeakMap();
1538
1881
  _cache = new WeakMap();
1539
1882
  _schemaTables$2 = new WeakMap();
1883
+ _trace = new WeakMap();
1540
1884
  _insertRecordWithoutId = new WeakSet();
1541
1885
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1542
1886
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1592,14 +1936,21 @@ _updateRecordWithID = new WeakSet();
1592
1936
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1593
1937
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1594
1938
  const record = transformObjectLinks(object);
1595
- const response = await updateRecordWithID({
1596
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1597
- queryParams: { columns },
1598
- body: record,
1599
- ...fetchProps
1600
- });
1601
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1602
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1939
+ try {
1940
+ const response = await updateRecordWithID({
1941
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1942
+ queryParams: { columns },
1943
+ body: record,
1944
+ ...fetchProps
1945
+ });
1946
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1947
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1948
+ } catch (e) {
1949
+ if (isObject(e) && e.status === 404) {
1950
+ return null;
1951
+ }
1952
+ throw e;
1953
+ }
1603
1954
  };
1604
1955
  _upsertRecordWithID = new WeakSet();
1605
1956
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1614,12 +1965,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1614
1965
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1615
1966
  };
1616
1967
  _deleteRecord = new WeakSet();
1617
- deleteRecord_fn = async function(recordId) {
1968
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1618
1969
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1619
- await deleteRecord({
1620
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1621
- ...fetchProps
1622
- });
1970
+ try {
1971
+ const response = await deleteRecord({
1972
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1973
+ queryParams: { columns },
1974
+ ...fetchProps
1975
+ });
1976
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1977
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1978
+ } catch (e) {
1979
+ if (isObject(e) && e.status === 404) {
1980
+ return null;
1981
+ }
1982
+ throw e;
1983
+ }
1623
1984
  };
1624
1985
  _setCacheQuery = new WeakSet();
1625
1986
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1681,9 +2042,17 @@ const initObject = (db, schemaTables, table, object) => {
1681
2042
  console.error(`Failed to parse link for field ${column.name}`);
1682
2043
  } else if (isObject(value)) {
1683
2044
  result[column.name] = initObject(db, schemaTables, linkTable, value);
2045
+ } else {
2046
+ result[column.name] = null;
1684
2047
  }
1685
2048
  break;
1686
2049
  }
2050
+ default:
2051
+ result[column.name] = value ?? null;
2052
+ if (column.notNull === true && value === null) {
2053
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2054
+ }
2055
+ break;
1687
2056
  }
1688
2057
  }
1689
2058
  result.read = function(columns2) {
@@ -1707,6 +2076,19 @@ const initObject = (db, schemaTables, table, object) => {
1707
2076
  function isResponseWithRecords(value) {
1708
2077
  return isObject(value) && Array.isArray(value.records);
1709
2078
  }
2079
+ function extractId(value) {
2080
+ if (isString(value))
2081
+ return value;
2082
+ if (isObject(value) && isString(value.id))
2083
+ return value.id;
2084
+ return void 0;
2085
+ }
2086
+ function cleanFilter(filter) {
2087
+ if (!filter)
2088
+ return void 0;
2089
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2090
+ return values.length > 0 ? filter : void 0;
2091
+ }
1710
2092
 
1711
2093
  var __accessCheck$3 = (obj, member, msg) => {
1712
2094
  if (!member.has(obj))
@@ -1757,18 +2139,25 @@ class SimpleCache {
1757
2139
  }
1758
2140
  _map = new WeakMap();
1759
2141
 
1760
- const gt = (value) => ({ $gt: value });
1761
- const ge = (value) => ({ $ge: value });
1762
- const gte = (value) => ({ $ge: value });
1763
- const lt = (value) => ({ $lt: value });
1764
- const lte = (value) => ({ $le: value });
1765
- const le = (value) => ({ $le: value });
2142
+ const greaterThan = (value) => ({ $gt: value });
2143
+ const gt = greaterThan;
2144
+ const greaterThanEquals = (value) => ({ $ge: value });
2145
+ const greaterEquals = greaterThanEquals;
2146
+ const gte = greaterThanEquals;
2147
+ const ge = greaterThanEquals;
2148
+ const lessThan = (value) => ({ $lt: value });
2149
+ const lt = lessThan;
2150
+ const lessThanEquals = (value) => ({ $le: value });
2151
+ const lessEquals = lessThanEquals;
2152
+ const lte = lessThanEquals;
2153
+ const le = lessThanEquals;
1766
2154
  const exists = (column) => ({ $exists: column });
1767
2155
  const notExists = (column) => ({ $notExists: column });
1768
2156
  const startsWith = (value) => ({ $startsWith: value });
1769
2157
  const endsWith = (value) => ({ $endsWith: value });
1770
2158
  const pattern = (value) => ({ $pattern: value });
1771
2159
  const is = (value) => ({ $is: value });
2160
+ const equals = is;
1772
2161
  const isNot = (value) => ({ $isNot: value });
1773
2162
  const contains = (value) => ({ $contains: value });
1774
2163
  const includes = (value) => ({ $includes: value });
@@ -1945,7 +2334,8 @@ async function resolveXataBranch(gitBranch, options) {
1945
2334
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1946
2335
  workspacesApiUrl: `${protocol}//${host}`,
1947
2336
  pathParams: { dbName, workspace },
1948
- queryParams: { gitBranch, fallbackBranch }
2337
+ queryParams: { gitBranch, fallbackBranch },
2338
+ trace: defaultTrace
1949
2339
  });
1950
2340
  return branch;
1951
2341
  }
@@ -1969,7 +2359,8 @@ async function getDatabaseBranch(branch, options) {
1969
2359
  apiUrl: databaseURL,
1970
2360
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1971
2361
  workspacesApiUrl: `${protocol}//${host}`,
1972
- pathParams: { dbBranchName, workspace }
2362
+ pathParams: { dbBranchName, workspace },
2363
+ trace: defaultTrace
1973
2364
  });
1974
2365
  } catch (err) {
1975
2366
  if (isObject(err) && err.status === 404)
@@ -2021,7 +2412,8 @@ const buildClient = (plugins) => {
2021
2412
  __privateSet(this, _options, safeOptions);
2022
2413
  const pluginOptions = {
2023
2414
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2024
- cache: safeOptions.cache
2415
+ cache: safeOptions.cache,
2416
+ trace: safeOptions.trace
2025
2417
  };
2026
2418
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2027
2419
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2050,12 +2442,16 @@ const buildClient = (plugins) => {
2050
2442
  const databaseURL = options?.databaseURL || getDatabaseURL();
2051
2443
  const apiKey = options?.apiKey || getAPIKey();
2052
2444
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2445
+ const trace = options?.trace ?? defaultTrace;
2053
2446
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2054
- if (!databaseURL || !apiKey) {
2055
- throw new Error("Options databaseURL and apiKey are required");
2447
+ if (!apiKey) {
2448
+ throw new Error("Option apiKey is required");
2449
+ }
2450
+ if (!databaseURL) {
2451
+ throw new Error("Option databaseURL is required");
2056
2452
  }
2057
- return { fetch, databaseURL, apiKey, branch, cache };
2058
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
2453
+ return { fetch, databaseURL, apiKey, branch, cache, trace };
2454
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2059
2455
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2060
2456
  if (!branchValue)
2061
2457
  throw new Error("Unable to resolve branch value");
@@ -2065,9 +2461,10 @@ const buildClient = (plugins) => {
2065
2461
  apiUrl: "",
2066
2462
  workspacesApiUrl: (path, params) => {
2067
2463
  const hasBranch = params.dbBranchName ?? params.branch;
2068
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2464
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2069
2465
  return databaseURL + newPath;
2070
- }
2466
+ },
2467
+ trace
2071
2468
  };
2072
2469
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2073
2470
  if (__privateGet(this, _branch))
@@ -2201,13 +2598,18 @@ exports.XataPlugin = XataPlugin;
2201
2598
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2202
2599
  exports.addGitBranchesEntry = addGitBranchesEntry;
2203
2600
  exports.addTableColumn = addTableColumn;
2601
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
2204
2602
  exports.buildClient = buildClient;
2205
2603
  exports.buildWorkerRunner = buildWorkerRunner;
2206
2604
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2207
2605
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2606
+ exports.compareBranchSchemas = compareBranchSchemas;
2607
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
2608
+ exports.compareMigrationRequest = compareMigrationRequest;
2208
2609
  exports.contains = contains;
2209
2610
  exports.createBranch = createBranch;
2210
2611
  exports.createDatabase = createDatabase;
2612
+ exports.createMigrationRequest = createMigrationRequest;
2211
2613
  exports.createTable = createTable;
2212
2614
  exports.createUserAPIKey = createUserAPIKey;
2213
2615
  exports.createWorkspace = createWorkspace;
@@ -2221,6 +2623,7 @@ exports.deleteUserAPIKey = deleteUserAPIKey;
2221
2623
  exports.deleteWorkspace = deleteWorkspace;
2222
2624
  exports.deserialize = deserialize;
2223
2625
  exports.endsWith = endsWith;
2626
+ exports.equals = equals;
2224
2627
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2225
2628
  exports.exists = exists;
2226
2629
  exports.ge = ge;
@@ -2230,6 +2633,7 @@ exports.getBranchList = getBranchList;
2230
2633
  exports.getBranchMetadata = getBranchMetadata;
2231
2634
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
2232
2635
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
2636
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
2233
2637
  exports.getBranchStats = getBranchStats;
2234
2638
  exports.getColumn = getColumn;
2235
2639
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
@@ -2238,6 +2642,8 @@ exports.getDatabaseList = getDatabaseList;
2238
2642
  exports.getDatabaseMetadata = getDatabaseMetadata;
2239
2643
  exports.getDatabaseURL = getDatabaseURL;
2240
2644
  exports.getGitBranchesMapping = getGitBranchesMapping;
2645
+ exports.getMigrationRequest = getMigrationRequest;
2646
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2241
2647
  exports.getRecord = getRecord;
2242
2648
  exports.getTableColumns = getTableColumns;
2243
2649
  exports.getTableSchema = getTableSchema;
@@ -2246,6 +2652,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2246
2652
  exports.getWorkspace = getWorkspace;
2247
2653
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2248
2654
  exports.getWorkspacesList = getWorkspacesList;
2655
+ exports.greaterEquals = greaterEquals;
2656
+ exports.greaterThan = greaterThan;
2657
+ exports.greaterThanEquals = greaterThanEquals;
2249
2658
  exports.gt = gt;
2250
2659
  exports.gte = gte;
2251
2660
  exports.includes = includes;
@@ -2261,11 +2670,18 @@ exports.isIdentifiable = isIdentifiable;
2261
2670
  exports.isNot = isNot;
2262
2671
  exports.isXataRecord = isXataRecord;
2263
2672
  exports.le = le;
2673
+ exports.lessEquals = lessEquals;
2674
+ exports.lessThan = lessThan;
2675
+ exports.lessThanEquals = lessThanEquals;
2676
+ exports.listMigrationRequests = listMigrationRequests;
2677
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
2264
2678
  exports.lt = lt;
2265
2679
  exports.lte = lte;
2680
+ exports.mergeMigrationRequest = mergeMigrationRequest;
2266
2681
  exports.notExists = notExists;
2267
2682
  exports.operationsByTag = operationsByTag;
2268
2683
  exports.pattern = pattern;
2684
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
2269
2685
  exports.queryTable = queryTable;
2270
2686
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2271
2687
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2276,8 +2692,12 @@ exports.searchTable = searchTable;
2276
2692
  exports.serialize = serialize;
2277
2693
  exports.setTableSchema = setTableSchema;
2278
2694
  exports.startsWith = startsWith;
2695
+ exports.summarizeTable = summarizeTable;
2279
2696
  exports.updateBranchMetadata = updateBranchMetadata;
2697
+ exports.updateBranchSchema = updateBranchSchema;
2280
2698
  exports.updateColumn = updateColumn;
2699
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
2700
+ exports.updateMigrationRequest = updateMigrationRequest;
2281
2701
  exports.updateRecordWithID = updateRecordWithID;
2282
2702
  exports.updateTable = updateTable;
2283
2703
  exports.updateUser = updateUser;