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

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.vf87d751";
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 patchDatabaseMetadata = (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",
@@ -495,6 +574,7 @@ const operationsByTag = {
495
574
  createDatabase,
496
575
  deleteDatabase,
497
576
  getDatabaseMetadata,
577
+ patchDatabaseMetadata,
498
578
  getGitBranchesMapping,
499
579
  addGitBranchesEntry,
500
580
  removeGitBranchesEntry,
@@ -507,10 +587,28 @@ const operationsByTag = {
507
587
  deleteBranch,
508
588
  updateBranchMetadata,
509
589
  getBranchMetadata,
590
+ getBranchStats
591
+ },
592
+ migrationRequests: {
593
+ listMigrationRequests,
594
+ createMigrationRequest,
595
+ getMigrationRequest,
596
+ updateMigrationRequest,
597
+ listMigrationRequestsCommits,
598
+ compareMigrationRequest,
599
+ getMigrationRequestIsMerged,
600
+ mergeMigrationRequest
601
+ },
602
+ branchSchema: {
510
603
  getBranchMigrationHistory,
511
604
  executeBranchMigrationPlan,
512
605
  getBranchMigrationPlan,
513
- getBranchStats
606
+ compareBranchWithUserSchema,
607
+ compareBranchSchemas,
608
+ updateBranchSchema,
609
+ previewBranchSchemaEdit,
610
+ applyBranchSchemaEdit,
611
+ getBranchSchemaHistory
514
612
  },
515
613
  table: {
516
614
  createTable,
@@ -539,9 +637,9 @@ const operationsByTag = {
539
637
  };
540
638
 
541
639
  function getHostUrl(provider, type) {
542
- if (isValidAlias(provider)) {
640
+ if (isHostProviderAlias(provider)) {
543
641
  return providers[provider][type];
544
- } else if (isValidBuilder(provider)) {
642
+ } else if (isHostProviderBuilder(provider)) {
545
643
  return provider[type];
546
644
  }
547
645
  throw new Error("Invalid API provider");
@@ -556,10 +654,10 @@ const providers = {
556
654
  workspaces: "https://{workspaceId}.staging.xatabase.co"
557
655
  }
558
656
  };
559
- function isValidAlias(alias) {
657
+ function isHostProviderAlias(alias) {
560
658
  return isString(alias) && Object.keys(providers).includes(alias);
561
659
  }
562
- function isValidBuilder(builder) {
660
+ function isHostProviderBuilder(builder) {
563
661
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
564
662
  }
565
663
 
@@ -587,7 +685,8 @@ class XataApiClient {
587
685
  __privateAdd$7(this, _extraProps, void 0);
588
686
  __privateAdd$7(this, _namespaces, {});
589
687
  const provider = options.host ?? "production";
590
- const apiKey = options?.apiKey ?? getAPIKey();
688
+ const apiKey = options.apiKey ?? getAPIKey();
689
+ const trace = options.trace ?? defaultTrace;
591
690
  if (!apiKey) {
592
691
  throw new Error("Could not resolve a valid apiKey");
593
692
  }
@@ -595,7 +694,8 @@ class XataApiClient {
595
694
  apiUrl: getHostUrl(provider, "main"),
596
695
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
597
696
  fetchImpl: getFetchImplementation(options.fetch),
598
- apiKey
697
+ apiKey,
698
+ trace
599
699
  });
600
700
  }
601
701
  get user() {
@@ -628,6 +728,16 @@ class XataApiClient {
628
728
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
629
729
  return __privateGet$7(this, _namespaces).records;
630
730
  }
731
+ get migrationRequests() {
732
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
733
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
734
+ return __privateGet$7(this, _namespaces).migrationRequests;
735
+ }
736
+ get branchSchema() {
737
+ if (!__privateGet$7(this, _namespaces).branchSchema)
738
+ __privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
739
+ return __privateGet$7(this, _namespaces).branchSchema;
740
+ }
631
741
  }
632
742
  _extraProps = new WeakMap();
633
743
  _namespaces = new WeakMap();
@@ -773,6 +883,13 @@ class DatabaseApi {
773
883
  ...this.extraProps
774
884
  });
775
885
  }
886
+ patchDatabaseMetadata(workspace, dbName, options = {}) {
887
+ return operationsByTag.database.patchDatabaseMetadata({
888
+ pathParams: { workspace, dbName },
889
+ body: options,
890
+ ...this.extraProps
891
+ });
892
+ }
776
893
  getGitBranchesMapping(workspace, dbName) {
777
894
  return operationsByTag.database.getGitBranchesMapping({
778
895
  pathParams: { workspace, dbName },
@@ -844,27 +961,6 @@ class BranchApi {
844
961
  ...this.extraProps
845
962
  });
846
963
  }
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
964
  getBranchStats(workspace, database, branch) {
869
965
  return operationsByTag.branch.getBranchStats({
870
966
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -1021,6 +1117,131 @@ class RecordsApi {
1021
1117
  });
1022
1118
  }
1023
1119
  }
1120
+ class MigrationRequestsApi {
1121
+ constructor(extraProps) {
1122
+ this.extraProps = extraProps;
1123
+ }
1124
+ listMigrationRequests(workspace, database, options = {}) {
1125
+ return operationsByTag.migrationRequests.listMigrationRequests({
1126
+ pathParams: { workspace, dbName: database },
1127
+ body: options,
1128
+ ...this.extraProps
1129
+ });
1130
+ }
1131
+ createMigrationRequest(workspace, database, options) {
1132
+ return operationsByTag.migrationRequests.createMigrationRequest({
1133
+ pathParams: { workspace, dbName: database },
1134
+ body: options,
1135
+ ...this.extraProps
1136
+ });
1137
+ }
1138
+ getMigrationRequest(workspace, database, migrationRequest) {
1139
+ return operationsByTag.migrationRequests.getMigrationRequest({
1140
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1141
+ ...this.extraProps
1142
+ });
1143
+ }
1144
+ updateMigrationRequest(workspace, database, migrationRequest, options) {
1145
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1146
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1147
+ body: options,
1148
+ ...this.extraProps
1149
+ });
1150
+ }
1151
+ listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
1152
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1153
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1154
+ body: options,
1155
+ ...this.extraProps
1156
+ });
1157
+ }
1158
+ compareMigrationRequest(workspace, database, migrationRequest) {
1159
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1160
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1161
+ ...this.extraProps
1162
+ });
1163
+ }
1164
+ getMigrationRequestIsMerged(workspace, database, migrationRequest) {
1165
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1166
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1167
+ ...this.extraProps
1168
+ });
1169
+ }
1170
+ mergeMigrationRequest(workspace, database, migrationRequest) {
1171
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1172
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1173
+ ...this.extraProps
1174
+ });
1175
+ }
1176
+ }
1177
+ class BranchSchemaApi {
1178
+ constructor(extraProps) {
1179
+ this.extraProps = extraProps;
1180
+ }
1181
+ getBranchMigrationHistory(workspace, database, branch, options = {}) {
1182
+ return operationsByTag.branchSchema.getBranchMigrationHistory({
1183
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1184
+ body: options,
1185
+ ...this.extraProps
1186
+ });
1187
+ }
1188
+ executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
1189
+ return operationsByTag.branchSchema.executeBranchMigrationPlan({
1190
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1191
+ body: migrationPlan,
1192
+ ...this.extraProps
1193
+ });
1194
+ }
1195
+ getBranchMigrationPlan(workspace, database, branch, schema) {
1196
+ return operationsByTag.branchSchema.getBranchMigrationPlan({
1197
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1198
+ body: schema,
1199
+ ...this.extraProps
1200
+ });
1201
+ }
1202
+ compareBranchWithUserSchema(workspace, database, branch, schema) {
1203
+ return operationsByTag.branchSchema.compareBranchWithUserSchema({
1204
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1205
+ body: { schema },
1206
+ ...this.extraProps
1207
+ });
1208
+ }
1209
+ compareBranchSchemas(workspace, database, branch, branchName, schema) {
1210
+ return operationsByTag.branchSchema.compareBranchSchemas({
1211
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
1212
+ body: { schema },
1213
+ ...this.extraProps
1214
+ });
1215
+ }
1216
+ updateBranchSchema(workspace, database, branch, migration) {
1217
+ return operationsByTag.branchSchema.updateBranchSchema({
1218
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1219
+ body: migration,
1220
+ ...this.extraProps
1221
+ });
1222
+ }
1223
+ previewBranchSchemaEdit(workspace, database, branch, migration) {
1224
+ return operationsByTag.branchSchema.previewBranchSchemaEdit({
1225
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1226
+ body: migration,
1227
+ ...this.extraProps
1228
+ });
1229
+ }
1230
+ applyBranchSchemaEdit(workspace, database, branch, edits) {
1231
+ return operationsByTag.branchSchema.applyBranchSchemaEdit({
1232
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1233
+ body: { edits },
1234
+ ...this.extraProps
1235
+ });
1236
+ }
1237
+ getBranchSchemaHistory(workspace, database, branch, options = {}) {
1238
+ return operationsByTag.branchSchema.getBranchSchemaHistory({
1239
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1240
+ body: options,
1241
+ ...this.extraProps
1242
+ });
1243
+ }
1244
+ }
1024
1245
 
1025
1246
  class XataApiPlugin {
1026
1247
  async build(options) {
@@ -1204,14 +1425,22 @@ const _Query = class {
1204
1425
  }
1205
1426
  filter(a, b) {
1206
1427
  if (arguments.length === 1) {
1207
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1428
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
1208
1429
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1209
1430
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1210
1431
  } else {
1211
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1432
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
1433
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1212
1434
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1213
1435
  }
1214
1436
  }
1437
+ defaultFilter(column, value) {
1438
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1439
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1440
+ return { $includes: value };
1441
+ }
1442
+ return value;
1443
+ }
1215
1444
  sort(column, direction = "asc") {
1216
1445
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1217
1446
  const sort = [...originalSort, { column, direction }];
@@ -1348,12 +1577,16 @@ var __privateMethod$2 = (obj, member, method) => {
1348
1577
  __accessCheck$4(obj, member, "access private method");
1349
1578
  return method;
1350
1579
  };
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;
1580
+ 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
1581
  class Repository extends Query {
1353
1582
  }
1354
1583
  class RestRepository extends Query {
1355
1584
  constructor(options) {
1356
- super(null, options.table, {});
1585
+ super(
1586
+ null,
1587
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
1588
+ {}
1589
+ );
1357
1590
  __privateAdd$4(this, _insertRecordWithoutId);
1358
1591
  __privateAdd$4(this, _insertRecordWithId);
1359
1592
  __privateAdd$4(this, _bulkInsertTableRecords);
@@ -1368,168 +1601,194 @@ class RestRepository extends Query {
1368
1601
  __privateAdd$4(this, _db, void 0);
1369
1602
  __privateAdd$4(this, _cache, void 0);
1370
1603
  __privateAdd$4(this, _schemaTables$2, void 0);
1604
+ __privateAdd$4(this, _trace, void 0);
1371
1605
  __privateSet$4(this, _table, options.table);
1372
1606
  __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1373
1607
  __privateSet$4(this, _db, options.db);
1374
1608
  __privateSet$4(this, _cache, options.pluginOptions.cache);
1375
1609
  __privateSet$4(this, _schemaTables$2, options.schemaTables);
1610
+ const trace = options.pluginOptions.trace ?? defaultTrace;
1611
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1612
+ return trace(name, fn, {
1613
+ ...options2,
1614
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1615
+ [TraceAttributes.KIND]: "sdk-operation",
1616
+ [TraceAttributes.VERSION]: VERSION
1617
+ });
1618
+ });
1376
1619
  }
1377
1620
  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");
1621
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
1622
+ if (Array.isArray(a)) {
1623
+ if (a.length === 0)
1624
+ return [];
1625
+ const columns = isStringArray(b) ? b : void 0;
1626
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1627
+ }
1628
+ if (isString(a) && isObject(b)) {
1629
+ if (a === "")
1630
+ throw new Error("The id can't be empty");
1631
+ const columns = isStringArray(c) ? c : void 0;
1632
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1633
+ }
1634
+ if (isObject(a) && isString(a.id)) {
1635
+ if (a.id === "")
1636
+ throw new Error("The id can't be empty");
1637
+ const columns = isStringArray(b) ? b : void 0;
1638
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1639
+ }
1640
+ if (isObject(a)) {
1641
+ const columns = isStringArray(b) ? b : void 0;
1642
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1643
+ }
1644
+ throw new Error("Invalid arguments for create method");
1645
+ });
1401
1646
  }
1402
1647
  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;
1648
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
1649
+ const columns = isStringArray(b) ? b : ["*"];
1650
+ if (Array.isArray(a)) {
1651
+ if (a.length === 0)
1652
+ return [];
1653
+ const ids = a.map((item) => extractId(item));
1654
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
1655
+ const dictionary = finalObjects.reduce((acc, object) => {
1656
+ acc[object.id] = object;
1657
+ return acc;
1658
+ }, {});
1659
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1660
+ }
1661
+ const id = extractId(a);
1662
+ if (id) {
1663
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1664
+ try {
1665
+ const response = await getRecord({
1666
+ pathParams: {
1667
+ workspace: "{workspaceId}",
1668
+ dbBranchName: "{dbBranch}",
1669
+ tableName: __privateGet$4(this, _table),
1670
+ recordId: id
1671
+ },
1672
+ queryParams: { columns },
1673
+ ...fetchProps
1674
+ });
1675
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1676
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1677
+ } catch (e) {
1678
+ if (isObject(e) && e.status === 404) {
1679
+ return null;
1680
+ }
1681
+ throw e;
1429
1682
  }
1430
- throw e;
1431
1683
  }
1432
- }
1433
- return null;
1684
+ return null;
1685
+ });
1434
1686
  }
1435
1687
  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");
1688
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
1689
+ if (Array.isArray(a)) {
1690
+ if (a.length === 0)
1691
+ return [];
1692
+ if (a.length > 100) {
1693
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1694
+ }
1695
+ const columns = isStringArray(b) ? b : ["*"];
1696
+ return Promise.all(a.map((object) => this.update(object, columns)));
1441
1697
  }
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");
1698
+ if (isString(a) && isObject(b)) {
1699
+ const columns = isStringArray(c) ? c : void 0;
1700
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1701
+ }
1702
+ if (isObject(a) && isString(a.id)) {
1703
+ const columns = isStringArray(b) ? b : void 0;
1704
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1705
+ }
1706
+ throw new Error("Invalid arguments for update method");
1707
+ });
1454
1708
  }
1455
1709
  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");
1710
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1711
+ if (Array.isArray(a)) {
1712
+ if (a.length === 0)
1713
+ return [];
1714
+ if (a.length > 100) {
1715
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1716
+ }
1717
+ const columns = isStringArray(b) ? b : ["*"];
1718
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1461
1719
  }
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");
1720
+ if (isString(a) && isObject(b)) {
1721
+ const columns = isStringArray(c) ? c : void 0;
1722
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1481
1723
  }
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");
1724
+ if (isObject(a) && isString(a.id)) {
1725
+ const columns = isStringArray(c) ? c : void 0;
1726
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1727
+ }
1728
+ throw new Error("Invalid arguments for createOrUpdate method");
1729
+ });
1730
+ }
1731
+ async delete(a, b) {
1732
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
1733
+ if (Array.isArray(a)) {
1734
+ if (a.length === 0)
1735
+ return [];
1736
+ if (a.length > 100) {
1737
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1738
+ }
1739
+ return Promise.all(a.map((id) => this.delete(id, b)));
1740
+ }
1741
+ if (isString(a)) {
1742
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1743
+ }
1744
+ if (isObject(a) && isString(a.id)) {
1745
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1746
+ }
1747
+ throw new Error("Invalid arguments for delete method");
1748
+ });
1494
1749
  }
1495
1750
  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
1751
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
1752
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1753
+ const { records } = await searchTable({
1754
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1755
+ body: {
1756
+ query,
1757
+ fuzziness: options.fuzziness,
1758
+ prefix: options.prefix,
1759
+ highlight: options.highlight,
1760
+ filter: options.filter,
1761
+ boosters: options.boosters
1762
+ },
1763
+ ...fetchProps
1764
+ });
1765
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1766
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1508
1767
  });
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
1768
  }
1512
1769
  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
1770
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
1771
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1772
+ if (cacheQuery)
1773
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1774
+ const data = query.getQueryOptions();
1775
+ const body = {
1776
+ filter: cleanFilter(data.filter),
1777
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1778
+ page: data.pagination,
1779
+ columns: data.columns
1780
+ };
1781
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1782
+ const { meta, records: objects } = await queryTable({
1783
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1784
+ body,
1785
+ ...fetchProps
1786
+ });
1787
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1788
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1789
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1790
+ return new Page(query, meta, records);
1528
1791
  });
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
1792
  }
1534
1793
  }
1535
1794
  _table = new WeakMap();
@@ -1537,6 +1796,7 @@ _getFetchProps = new WeakMap();
1537
1796
  _db = new WeakMap();
1538
1797
  _cache = new WeakMap();
1539
1798
  _schemaTables$2 = new WeakMap();
1799
+ _trace = new WeakMap();
1540
1800
  _insertRecordWithoutId = new WeakSet();
1541
1801
  insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1542
1802
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
@@ -1592,14 +1852,21 @@ _updateRecordWithID = new WeakSet();
1592
1852
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1593
1853
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1594
1854
  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);
1855
+ try {
1856
+ const response = await updateRecordWithID({
1857
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1858
+ queryParams: { columns },
1859
+ body: record,
1860
+ ...fetchProps
1861
+ });
1862
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1863
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1864
+ } catch (e) {
1865
+ if (isObject(e) && e.status === 404) {
1866
+ return null;
1867
+ }
1868
+ throw e;
1869
+ }
1603
1870
  };
1604
1871
  _upsertRecordWithID = new WeakSet();
1605
1872
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1614,12 +1881,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1614
1881
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1615
1882
  };
1616
1883
  _deleteRecord = new WeakSet();
1617
- deleteRecord_fn = async function(recordId) {
1884
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1618
1885
  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
- });
1886
+ try {
1887
+ const response = await deleteRecord({
1888
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1889
+ queryParams: { columns },
1890
+ ...fetchProps
1891
+ });
1892
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1893
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1894
+ } catch (e) {
1895
+ if (isObject(e) && e.status === 404) {
1896
+ return null;
1897
+ }
1898
+ throw e;
1899
+ }
1623
1900
  };
1624
1901
  _setCacheQuery = new WeakSet();
1625
1902
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1707,6 +1984,19 @@ const initObject = (db, schemaTables, table, object) => {
1707
1984
  function isResponseWithRecords(value) {
1708
1985
  return isObject(value) && Array.isArray(value.records);
1709
1986
  }
1987
+ function extractId(value) {
1988
+ if (isString(value))
1989
+ return value;
1990
+ if (isObject(value) && isString(value.id))
1991
+ return value.id;
1992
+ return void 0;
1993
+ }
1994
+ function cleanFilter(filter) {
1995
+ if (!filter)
1996
+ return void 0;
1997
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1998
+ return values.length > 0 ? filter : void 0;
1999
+ }
1710
2000
 
1711
2001
  var __accessCheck$3 = (obj, member, msg) => {
1712
2002
  if (!member.has(obj))
@@ -1757,18 +2047,25 @@ class SimpleCache {
1757
2047
  }
1758
2048
  _map = new WeakMap();
1759
2049
 
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 });
2050
+ const greaterThan = (value) => ({ $gt: value });
2051
+ const gt = greaterThan;
2052
+ const greaterThanEquals = (value) => ({ $ge: value });
2053
+ const greaterEquals = greaterThanEquals;
2054
+ const gte = greaterThanEquals;
2055
+ const ge = greaterThanEquals;
2056
+ const lessThan = (value) => ({ $lt: value });
2057
+ const lt = lessThan;
2058
+ const lessThanEquals = (value) => ({ $le: value });
2059
+ const lessEquals = lessThanEquals;
2060
+ const lte = lessThanEquals;
2061
+ const le = lessThanEquals;
1766
2062
  const exists = (column) => ({ $exists: column });
1767
2063
  const notExists = (column) => ({ $notExists: column });
1768
2064
  const startsWith = (value) => ({ $startsWith: value });
1769
2065
  const endsWith = (value) => ({ $endsWith: value });
1770
2066
  const pattern = (value) => ({ $pattern: value });
1771
2067
  const is = (value) => ({ $is: value });
2068
+ const equals = is;
1772
2069
  const isNot = (value) => ({ $isNot: value });
1773
2070
  const contains = (value) => ({ $contains: value });
1774
2071
  const includes = (value) => ({ $includes: value });
@@ -1945,7 +2242,8 @@ async function resolveXataBranch(gitBranch, options) {
1945
2242
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1946
2243
  workspacesApiUrl: `${protocol}//${host}`,
1947
2244
  pathParams: { dbName, workspace },
1948
- queryParams: { gitBranch, fallbackBranch }
2245
+ queryParams: { gitBranch, fallbackBranch },
2246
+ trace: defaultTrace
1949
2247
  });
1950
2248
  return branch;
1951
2249
  }
@@ -1969,7 +2267,8 @@ async function getDatabaseBranch(branch, options) {
1969
2267
  apiUrl: databaseURL,
1970
2268
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1971
2269
  workspacesApiUrl: `${protocol}//${host}`,
1972
- pathParams: { dbBranchName, workspace }
2270
+ pathParams: { dbBranchName, workspace },
2271
+ trace: defaultTrace
1973
2272
  });
1974
2273
  } catch (err) {
1975
2274
  if (isObject(err) && err.status === 404)
@@ -2021,7 +2320,8 @@ const buildClient = (plugins) => {
2021
2320
  __privateSet(this, _options, safeOptions);
2022
2321
  const pluginOptions = {
2023
2322
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2024
- cache: safeOptions.cache
2323
+ cache: safeOptions.cache,
2324
+ trace: safeOptions.trace
2025
2325
  };
2026
2326
  const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2027
2327
  const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
@@ -2050,12 +2350,16 @@ const buildClient = (plugins) => {
2050
2350
  const databaseURL = options?.databaseURL || getDatabaseURL();
2051
2351
  const apiKey = options?.apiKey || getAPIKey();
2052
2352
  const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2353
+ const trace = options?.trace ?? defaultTrace;
2053
2354
  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");
2355
+ if (!apiKey) {
2356
+ throw new Error("Option apiKey is required");
2056
2357
  }
2057
- return { fetch, databaseURL, apiKey, branch, cache };
2058
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
2358
+ if (!databaseURL) {
2359
+ throw new Error("Option databaseURL is required");
2360
+ }
2361
+ return { fetch, databaseURL, apiKey, branch, cache, trace };
2362
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
2059
2363
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2060
2364
  if (!branchValue)
2061
2365
  throw new Error("Unable to resolve branch value");
@@ -2065,9 +2369,10 @@ const buildClient = (plugins) => {
2065
2369
  apiUrl: "",
2066
2370
  workspacesApiUrl: (path, params) => {
2067
2371
  const hasBranch = params.dbBranchName ?? params.branch;
2068
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2372
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2069
2373
  return databaseURL + newPath;
2070
- }
2374
+ },
2375
+ trace
2071
2376
  };
2072
2377
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2073
2378
  if (__privateGet(this, _branch))
@@ -2201,13 +2506,18 @@ exports.XataPlugin = XataPlugin;
2201
2506
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
2202
2507
  exports.addGitBranchesEntry = addGitBranchesEntry;
2203
2508
  exports.addTableColumn = addTableColumn;
2509
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
2204
2510
  exports.buildClient = buildClient;
2205
2511
  exports.buildWorkerRunner = buildWorkerRunner;
2206
2512
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
2207
2513
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2514
+ exports.compareBranchSchemas = compareBranchSchemas;
2515
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
2516
+ exports.compareMigrationRequest = compareMigrationRequest;
2208
2517
  exports.contains = contains;
2209
2518
  exports.createBranch = createBranch;
2210
2519
  exports.createDatabase = createDatabase;
2520
+ exports.createMigrationRequest = createMigrationRequest;
2211
2521
  exports.createTable = createTable;
2212
2522
  exports.createUserAPIKey = createUserAPIKey;
2213
2523
  exports.createWorkspace = createWorkspace;
@@ -2221,6 +2531,7 @@ exports.deleteUserAPIKey = deleteUserAPIKey;
2221
2531
  exports.deleteWorkspace = deleteWorkspace;
2222
2532
  exports.deserialize = deserialize;
2223
2533
  exports.endsWith = endsWith;
2534
+ exports.equals = equals;
2224
2535
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
2225
2536
  exports.exists = exists;
2226
2537
  exports.ge = ge;
@@ -2230,6 +2541,7 @@ exports.getBranchList = getBranchList;
2230
2541
  exports.getBranchMetadata = getBranchMetadata;
2231
2542
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
2232
2543
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
2544
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
2233
2545
  exports.getBranchStats = getBranchStats;
2234
2546
  exports.getColumn = getColumn;
2235
2547
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
@@ -2238,6 +2550,8 @@ exports.getDatabaseList = getDatabaseList;
2238
2550
  exports.getDatabaseMetadata = getDatabaseMetadata;
2239
2551
  exports.getDatabaseURL = getDatabaseURL;
2240
2552
  exports.getGitBranchesMapping = getGitBranchesMapping;
2553
+ exports.getMigrationRequest = getMigrationRequest;
2554
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
2241
2555
  exports.getRecord = getRecord;
2242
2556
  exports.getTableColumns = getTableColumns;
2243
2557
  exports.getTableSchema = getTableSchema;
@@ -2246,6 +2560,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
2246
2560
  exports.getWorkspace = getWorkspace;
2247
2561
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
2248
2562
  exports.getWorkspacesList = getWorkspacesList;
2563
+ exports.greaterEquals = greaterEquals;
2564
+ exports.greaterThan = greaterThan;
2565
+ exports.greaterThanEquals = greaterThanEquals;
2249
2566
  exports.gt = gt;
2250
2567
  exports.gte = gte;
2251
2568
  exports.includes = includes;
@@ -2261,11 +2578,19 @@ exports.isIdentifiable = isIdentifiable;
2261
2578
  exports.isNot = isNot;
2262
2579
  exports.isXataRecord = isXataRecord;
2263
2580
  exports.le = le;
2581
+ exports.lessEquals = lessEquals;
2582
+ exports.lessThan = lessThan;
2583
+ exports.lessThanEquals = lessThanEquals;
2584
+ exports.listMigrationRequests = listMigrationRequests;
2585
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
2264
2586
  exports.lt = lt;
2265
2587
  exports.lte = lte;
2588
+ exports.mergeMigrationRequest = mergeMigrationRequest;
2266
2589
  exports.notExists = notExists;
2267
2590
  exports.operationsByTag = operationsByTag;
2591
+ exports.patchDatabaseMetadata = patchDatabaseMetadata;
2268
2592
  exports.pattern = pattern;
2593
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
2269
2594
  exports.queryTable = queryTable;
2270
2595
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2271
2596
  exports.removeWorkspaceMember = removeWorkspaceMember;
@@ -2277,7 +2602,9 @@ exports.serialize = serialize;
2277
2602
  exports.setTableSchema = setTableSchema;
2278
2603
  exports.startsWith = startsWith;
2279
2604
  exports.updateBranchMetadata = updateBranchMetadata;
2605
+ exports.updateBranchSchema = updateBranchSchema;
2280
2606
  exports.updateColumn = updateColumn;
2607
+ exports.updateMigrationRequest = updateMigrationRequest;
2281
2608
  exports.updateRecordWithID = updateRecordWithID;
2282
2609
  exports.updateTable = updateTable;
2283
2610
  exports.updateUser = updateUser;