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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -7,43 +7,101 @@ function compact(arr) {
7
7
  function isObject(value) {
8
8
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
9
9
  }
10
+ function isDefined(value) {
11
+ return value !== null && value !== void 0;
12
+ }
10
13
  function isString(value) {
11
- return value !== void 0 && value !== null && typeof value === "string";
14
+ return isDefined(value) && typeof value === "string";
15
+ }
16
+ function isStringArray(value) {
17
+ return isDefined(value) && Array.isArray(value) && value.every(isString);
12
18
  }
13
19
  function toBase64(value) {
14
20
  try {
15
21
  return btoa(value);
16
22
  } catch (err) {
17
- return Buffer.from(value).toString("base64");
23
+ const buf = Buffer;
24
+ return buf.from(value).toString("base64");
18
25
  }
19
26
  }
20
27
 
21
- function getEnvVariable(name) {
28
+ function getEnvironment() {
22
29
  try {
23
- if (isObject(process) && isString(process?.env?.[name])) {
24
- return process.env[name];
30
+ if (isObject(process) && isObject(process.env)) {
31
+ return {
32
+ apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
33
+ databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
34
+ branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
35
+ envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
36
+ fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
37
+ };
25
38
  }
26
39
  } catch (err) {
27
40
  }
28
41
  try {
29
- if (isObject(Deno) && isString(Deno?.env?.get(name))) {
30
- return Deno.env.get(name);
42
+ if (isObject(Deno) && isObject(Deno.env)) {
43
+ return {
44
+ apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
45
+ databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
46
+ branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
47
+ envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
48
+ fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
49
+ };
31
50
  }
32
51
  } catch (err) {
33
52
  }
53
+ return {
54
+ apiKey: getGlobalApiKey(),
55
+ databaseURL: getGlobalDatabaseURL(),
56
+ branch: getGlobalBranch(),
57
+ envBranch: void 0,
58
+ fallbackBranch: getGlobalFallbackBranch()
59
+ };
60
+ }
61
+ function getGlobalApiKey() {
62
+ try {
63
+ return XATA_API_KEY;
64
+ } catch (err) {
65
+ return void 0;
66
+ }
67
+ }
68
+ function getGlobalDatabaseURL() {
69
+ try {
70
+ return XATA_DATABASE_URL;
71
+ } catch (err) {
72
+ return void 0;
73
+ }
74
+ }
75
+ function getGlobalBranch() {
76
+ try {
77
+ return XATA_BRANCH;
78
+ } catch (err) {
79
+ return void 0;
80
+ }
81
+ }
82
+ function getGlobalFallbackBranch() {
83
+ try {
84
+ return XATA_FALLBACK_BRANCH;
85
+ } catch (err) {
86
+ return void 0;
87
+ }
34
88
  }
35
89
  async function getGitBranch() {
90
+ const cmd = ["git", "branch", "--show-current"];
91
+ const fullCmd = cmd.join(" ");
92
+ const nodeModule = ["child", "process"].join("_");
93
+ const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
36
94
  try {
37
- return require("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
95
+ if (typeof require === "function") {
96
+ return require(nodeModule).execSync(fullCmd, execOptions).trim();
97
+ }
98
+ const { execSync } = await import(nodeModule);
99
+ return execSync(fullCmd, execOptions).toString().trim();
38
100
  } catch (err) {
39
101
  }
40
102
  try {
41
103
  if (isObject(Deno)) {
42
- const process2 = Deno.run({
43
- cmd: ["git", "branch", "--show-current"],
44
- stdout: "piped",
45
- stderr: "piped"
46
- });
104
+ const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
47
105
  return new TextDecoder().decode(await process2.output()).trim();
48
106
  }
49
107
  } catch (err) {
@@ -52,7 +110,8 @@ async function getGitBranch() {
52
110
 
53
111
  function getAPIKey() {
54
112
  try {
55
- return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
113
+ const { apiKey } = getEnvironment();
114
+ return apiKey;
56
115
  } catch (err) {
57
116
  return void 0;
58
117
  }
@@ -62,21 +121,35 @@ function getFetchImplementation(userFetch) {
62
121
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
63
122
  const fetchImpl = userFetch ?? globalFetch;
64
123
  if (!fetchImpl) {
65
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
124
+ throw new Error(
125
+ `The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`
126
+ );
66
127
  }
67
128
  return fetchImpl;
68
129
  }
69
130
 
70
- class FetcherError extends Error {
71
- constructor(status, data) {
131
+ const VERSION = "0.0.0-alpha.vf73045e";
132
+
133
+ class ErrorWithCause extends Error {
134
+ constructor(message, options) {
135
+ super(message, options);
136
+ }
137
+ }
138
+ class FetcherError extends ErrorWithCause {
139
+ constructor(status, data, requestId) {
72
140
  super(getMessage(data));
73
141
  this.status = status;
74
142
  this.errors = isBulkError(data) ? data.errors : void 0;
143
+ this.requestId = requestId;
75
144
  if (data instanceof Error) {
76
145
  this.stack = data.stack;
77
146
  this.cause = data.cause;
78
147
  }
79
148
  }
149
+ toString() {
150
+ const error = super.toString();
151
+ return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
152
+ }
80
153
  }
81
154
  function isBulkError(error) {
82
155
  return isObject(error) && Array.isArray(error.errors);
@@ -99,7 +172,12 @@ function getMessage(data) {
99
172
  }
100
173
 
101
174
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
102
- const query = new URLSearchParams(queryParams).toString();
175
+ const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
176
+ if (value === void 0 || value === null)
177
+ return acc;
178
+ return { ...acc, [key]: value };
179
+ }, {});
180
+ const query = new URLSearchParams(cleanQueryParams).toString();
103
181
  const queryString = query.length > 0 ? `?${query}` : "";
104
182
  return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
105
183
  };
@@ -139,6 +217,7 @@ async function fetch$1({
139
217
  body: body ? JSON.stringify(body) : void 0,
140
218
  headers: {
141
219
  "Content-Type": "application/json",
220
+ "User-Agent": `Xata client-ts/${VERSION}`,
142
221
  ...headers,
143
222
  ...hostHeader(fullUrl),
144
223
  Authorization: `Bearer ${apiKey}`
@@ -147,14 +226,15 @@ async function fetch$1({
147
226
  if (response.status === 204) {
148
227
  return {};
149
228
  }
229
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
150
230
  try {
151
231
  const jsonResponse = await response.json();
152
232
  if (response.ok) {
153
233
  return jsonResponse;
154
234
  }
155
- throw new FetcherError(response.status, jsonResponse);
235
+ throw new FetcherError(response.status, jsonResponse, requestId);
156
236
  } catch (error) {
157
- throw new FetcherError(response.status, error);
237
+ throw new FetcherError(response.status, error, requestId);
158
238
  }
159
239
  }
160
240
 
@@ -213,6 +293,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
213
293
  ...variables
214
294
  });
215
295
  const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
296
+ const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
216
297
  const cancelWorkspaceMemberInvite = (variables) => fetch$1({
217
298
  url: "/workspaces/{workspaceId}/invites/{inviteId}",
218
299
  method: "delete",
@@ -248,16 +329,25 @@ const deleteDatabase = (variables) => fetch$1({
248
329
  method: "delete",
249
330
  ...variables
250
331
  });
251
- const getBranchDetails = (variables) => fetch$1({
252
- url: "/db/{dbBranchName}",
332
+ const getDatabaseMetadata = (variables) => fetch$1({
333
+ url: "/dbs/{dbName}/metadata",
334
+ method: "get",
335
+ ...variables
336
+ });
337
+ const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
338
+ const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
339
+ const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
340
+ const resolveBranch = (variables) => fetch$1({
341
+ url: "/dbs/{dbName}/resolveBranch",
253
342
  method: "get",
254
343
  ...variables
255
344
  });
256
- const createBranch = (variables) => fetch$1({
345
+ const getBranchDetails = (variables) => fetch$1({
257
346
  url: "/db/{dbBranchName}",
258
- method: "put",
347
+ method: "get",
259
348
  ...variables
260
349
  });
350
+ const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
261
351
  const deleteBranch = (variables) => fetch$1({
262
352
  url: "/db/{dbBranchName}",
263
353
  method: "delete",
@@ -331,11 +421,7 @@ const updateColumn = (variables) => fetch$1({
331
421
  method: "patch",
332
422
  ...variables
333
423
  });
334
- const insertRecord = (variables) => fetch$1({
335
- url: "/db/{dbBranchName}/tables/{tableName}/data",
336
- method: "post",
337
- ...variables
338
- });
424
+ const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
339
425
  const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
340
426
  const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
341
427
  const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
@@ -355,6 +441,11 @@ const queryTable = (variables) => fetch$1({
355
441
  method: "post",
356
442
  ...variables
357
443
  });
444
+ const searchTable = (variables) => fetch$1({
445
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
446
+ method: "post",
447
+ ...variables
448
+ });
358
449
  const searchBranch = (variables) => fetch$1({
359
450
  url: "/db/{dbBranchName}/search",
360
451
  method: "post",
@@ -372,11 +463,21 @@ const operationsByTag = {
372
463
  updateWorkspaceMemberRole,
373
464
  removeWorkspaceMember,
374
465
  inviteWorkspaceMember,
466
+ updateWorkspaceMemberInvite,
375
467
  cancelWorkspaceMemberInvite,
376
468
  resendWorkspaceMemberInvite,
377
469
  acceptWorkspaceMemberInvite
378
470
  },
379
- database: { getDatabaseList, createDatabase, deleteDatabase },
471
+ database: {
472
+ getDatabaseList,
473
+ createDatabase,
474
+ deleteDatabase,
475
+ getDatabaseMetadata,
476
+ getGitBranchesMapping,
477
+ addGitBranchesEntry,
478
+ removeGitBranchesEntry,
479
+ resolveBranch
480
+ },
380
481
  branch: {
381
482
  getBranchList,
382
483
  getBranchDetails,
@@ -410,6 +511,7 @@ const operationsByTag = {
410
511
  getRecord,
411
512
  bulkInsertTableRecords,
412
513
  queryTable,
514
+ searchTable,
413
515
  searchBranch
414
516
  }
415
517
  };
@@ -443,7 +545,7 @@ var __accessCheck$7 = (obj, member, msg) => {
443
545
  if (!member.has(obj))
444
546
  throw TypeError("Cannot " + msg);
445
547
  };
446
- var __privateGet$6 = (obj, member, getter) => {
548
+ var __privateGet$7 = (obj, member, getter) => {
447
549
  __accessCheck$7(obj, member, "read from private field");
448
550
  return getter ? getter.call(obj) : member.get(obj);
449
551
  };
@@ -452,7 +554,7 @@ var __privateAdd$7 = (obj, member, value) => {
452
554
  throw TypeError("Cannot add the same private member more than once");
453
555
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
454
556
  };
455
- var __privateSet$5 = (obj, member, value, setter) => {
557
+ var __privateSet$7 = (obj, member, value, setter) => {
456
558
  __accessCheck$7(obj, member, "write to private field");
457
559
  setter ? setter.call(obj, value) : member.set(obj, value);
458
560
  return value;
@@ -467,7 +569,7 @@ class XataApiClient {
467
569
  if (!apiKey) {
468
570
  throw new Error("Could not resolve a valid apiKey");
469
571
  }
470
- __privateSet$5(this, _extraProps, {
572
+ __privateSet$7(this, _extraProps, {
471
573
  apiUrl: getHostUrl(provider, "main"),
472
574
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
473
575
  fetchImpl: getFetchImplementation(options.fetch),
@@ -475,34 +577,34 @@ class XataApiClient {
475
577
  });
476
578
  }
477
579
  get user() {
478
- if (!__privateGet$6(this, _namespaces).user)
479
- __privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
480
- return __privateGet$6(this, _namespaces).user;
580
+ if (!__privateGet$7(this, _namespaces).user)
581
+ __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
582
+ return __privateGet$7(this, _namespaces).user;
481
583
  }
482
584
  get workspaces() {
483
- if (!__privateGet$6(this, _namespaces).workspaces)
484
- __privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
485
- return __privateGet$6(this, _namespaces).workspaces;
585
+ if (!__privateGet$7(this, _namespaces).workspaces)
586
+ __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
587
+ return __privateGet$7(this, _namespaces).workspaces;
486
588
  }
487
589
  get databases() {
488
- if (!__privateGet$6(this, _namespaces).databases)
489
- __privateGet$6(this, _namespaces).databases = new DatabaseApi(__privateGet$6(this, _extraProps));
490
- return __privateGet$6(this, _namespaces).databases;
590
+ if (!__privateGet$7(this, _namespaces).databases)
591
+ __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
592
+ return __privateGet$7(this, _namespaces).databases;
491
593
  }
492
594
  get branches() {
493
- if (!__privateGet$6(this, _namespaces).branches)
494
- __privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
495
- return __privateGet$6(this, _namespaces).branches;
595
+ if (!__privateGet$7(this, _namespaces).branches)
596
+ __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
597
+ return __privateGet$7(this, _namespaces).branches;
496
598
  }
497
599
  get tables() {
498
- if (!__privateGet$6(this, _namespaces).tables)
499
- __privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
500
- return __privateGet$6(this, _namespaces).tables;
600
+ if (!__privateGet$7(this, _namespaces).tables)
601
+ __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
602
+ return __privateGet$7(this, _namespaces).tables;
501
603
  }
502
604
  get records() {
503
- if (!__privateGet$6(this, _namespaces).records)
504
- __privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
505
- return __privateGet$6(this, _namespaces).records;
605
+ if (!__privateGet$7(this, _namespaces).records)
606
+ __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
607
+ return __privateGet$7(this, _namespaces).records;
506
608
  }
507
609
  }
508
610
  _extraProps = new WeakMap();
@@ -594,6 +696,13 @@ class WorkspaceApi {
594
696
  ...this.extraProps
595
697
  });
596
698
  }
699
+ updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
700
+ return operationsByTag.workspaces.updateWorkspaceMemberInvite({
701
+ pathParams: { workspaceId, inviteId },
702
+ body: { role },
703
+ ...this.extraProps
704
+ });
705
+ }
597
706
  cancelWorkspaceMemberInvite(workspaceId, inviteId) {
598
707
  return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
599
708
  pathParams: { workspaceId, inviteId },
@@ -636,6 +745,39 @@ class DatabaseApi {
636
745
  ...this.extraProps
637
746
  });
638
747
  }
748
+ getDatabaseMetadata(workspace, dbName) {
749
+ return operationsByTag.database.getDatabaseMetadata({
750
+ pathParams: { workspace, dbName },
751
+ ...this.extraProps
752
+ });
753
+ }
754
+ getGitBranchesMapping(workspace, dbName) {
755
+ return operationsByTag.database.getGitBranchesMapping({
756
+ pathParams: { workspace, dbName },
757
+ ...this.extraProps
758
+ });
759
+ }
760
+ addGitBranchesEntry(workspace, dbName, body) {
761
+ return operationsByTag.database.addGitBranchesEntry({
762
+ pathParams: { workspace, dbName },
763
+ body,
764
+ ...this.extraProps
765
+ });
766
+ }
767
+ removeGitBranchesEntry(workspace, dbName, gitBranch) {
768
+ return operationsByTag.database.removeGitBranchesEntry({
769
+ pathParams: { workspace, dbName },
770
+ queryParams: { gitBranch },
771
+ ...this.extraProps
772
+ });
773
+ }
774
+ resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
775
+ return operationsByTag.database.resolveBranch({
776
+ pathParams: { workspace, dbName },
777
+ queryParams: { gitBranch, fallbackBranch },
778
+ ...this.extraProps
779
+ });
780
+ }
639
781
  }
640
782
  class BranchApi {
641
783
  constructor(extraProps) {
@@ -653,10 +795,10 @@ class BranchApi {
653
795
  ...this.extraProps
654
796
  });
655
797
  }
656
- createBranch(workspace, database, branch, from = "", options = {}) {
798
+ createBranch(workspace, database, branch, from, options = {}) {
657
799
  return operationsByTag.branch.createBranch({
658
800
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
659
- queryParams: { from },
801
+ queryParams: isString(from) ? { from } : void 0,
660
802
  body: options,
661
803
  ...this.extraProps
662
804
  });
@@ -781,9 +923,10 @@ class RecordsApi {
781
923
  constructor(extraProps) {
782
924
  this.extraProps = extraProps;
783
925
  }
784
- insertRecord(workspace, database, branch, tableName, record) {
926
+ insertRecord(workspace, database, branch, tableName, record, options = {}) {
785
927
  return operationsByTag.records.insertRecord({
786
928
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
929
+ queryParams: options,
787
930
  body: record,
788
931
  ...this.extraProps
789
932
  });
@@ -812,21 +955,24 @@ class RecordsApi {
812
955
  ...this.extraProps
813
956
  });
814
957
  }
815
- deleteRecord(workspace, database, branch, tableName, recordId) {
958
+ deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
816
959
  return operationsByTag.records.deleteRecord({
817
960
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
961
+ queryParams: options,
818
962
  ...this.extraProps
819
963
  });
820
964
  }
821
965
  getRecord(workspace, database, branch, tableName, recordId, options = {}) {
822
966
  return operationsByTag.records.getRecord({
823
967
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
968
+ queryParams: options,
824
969
  ...this.extraProps
825
970
  });
826
971
  }
827
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
972
+ bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
828
973
  return operationsByTag.records.bulkInsertTableRecords({
829
974
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
975
+ queryParams: options,
830
976
  body: { records },
831
977
  ...this.extraProps
832
978
  });
@@ -838,6 +984,13 @@ class RecordsApi {
838
984
  ...this.extraProps
839
985
  });
840
986
  }
987
+ searchTable(workspace, database, branch, tableName, query) {
988
+ return operationsByTag.records.searchTable({
989
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
990
+ body: query,
991
+ ...this.extraProps
992
+ });
993
+ }
841
994
  searchBranch(workspace, database, branch, query) {
842
995
  return operationsByTag.records.searchBranch({
843
996
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -861,7 +1014,7 @@ var __accessCheck$6 = (obj, member, msg) => {
861
1014
  if (!member.has(obj))
862
1015
  throw TypeError("Cannot " + msg);
863
1016
  };
864
- var __privateGet$5 = (obj, member, getter) => {
1017
+ var __privateGet$6 = (obj, member, getter) => {
865
1018
  __accessCheck$6(obj, member, "read from private field");
866
1019
  return getter ? getter.call(obj) : member.get(obj);
867
1020
  };
@@ -870,30 +1023,30 @@ var __privateAdd$6 = (obj, member, value) => {
870
1023
  throw TypeError("Cannot add the same private member more than once");
871
1024
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
872
1025
  };
873
- var __privateSet$4 = (obj, member, value, setter) => {
1026
+ var __privateSet$6 = (obj, member, value, setter) => {
874
1027
  __accessCheck$6(obj, member, "write to private field");
875
1028
  setter ? setter.call(obj, value) : member.set(obj, value);
876
1029
  return value;
877
1030
  };
878
- var _query;
1031
+ var _query, _page;
879
1032
  class Page {
880
1033
  constructor(query, meta, records = []) {
881
1034
  __privateAdd$6(this, _query, void 0);
882
- __privateSet$4(this, _query, query);
1035
+ __privateSet$6(this, _query, query);
883
1036
  this.meta = meta;
884
- this.records = records;
1037
+ this.records = new RecordArray(this, records);
885
1038
  }
886
1039
  async nextPage(size, offset) {
887
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
1040
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
888
1041
  }
889
1042
  async previousPage(size, offset) {
890
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
1043
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
891
1044
  }
892
1045
  async firstPage(size, offset) {
893
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
1046
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
894
1047
  }
895
1048
  async lastPage(size, offset) {
896
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
1049
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
897
1050
  }
898
1051
  hasNextPage() {
899
1052
  return this.meta.page.more;
@@ -901,15 +1054,62 @@ class Page {
901
1054
  }
902
1055
  _query = new WeakMap();
903
1056
  const PAGINATION_MAX_SIZE = 200;
904
- const PAGINATION_DEFAULT_SIZE = 200;
1057
+ const PAGINATION_DEFAULT_SIZE = 20;
905
1058
  const PAGINATION_MAX_OFFSET = 800;
906
1059
  const PAGINATION_DEFAULT_OFFSET = 0;
1060
+ function isCursorPaginationOptions(options) {
1061
+ return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1062
+ }
1063
+ const _RecordArray = class extends Array {
1064
+ constructor(...args) {
1065
+ super(..._RecordArray.parseConstructorParams(...args));
1066
+ __privateAdd$6(this, _page, void 0);
1067
+ __privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
1068
+ }
1069
+ static parseConstructorParams(...args) {
1070
+ if (args.length === 1 && typeof args[0] === "number") {
1071
+ return new Array(args[0]);
1072
+ }
1073
+ if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
1074
+ const result = args[1] ?? args[0].records ?? [];
1075
+ return new Array(...result);
1076
+ }
1077
+ return new Array(...args);
1078
+ }
1079
+ toArray() {
1080
+ return new Array(...this);
1081
+ }
1082
+ map(callbackfn, thisArg) {
1083
+ return this.toArray().map(callbackfn, thisArg);
1084
+ }
1085
+ async nextPage(size, offset) {
1086
+ const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1087
+ return new _RecordArray(newPage);
1088
+ }
1089
+ async previousPage(size, offset) {
1090
+ const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1091
+ return new _RecordArray(newPage);
1092
+ }
1093
+ async firstPage(size, offset) {
1094
+ const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1095
+ return new _RecordArray(newPage);
1096
+ }
1097
+ async lastPage(size, offset) {
1098
+ const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1099
+ return new _RecordArray(newPage);
1100
+ }
1101
+ hasNextPage() {
1102
+ return __privateGet$6(this, _page).meta.page.more;
1103
+ }
1104
+ };
1105
+ let RecordArray = _RecordArray;
1106
+ _page = new WeakMap();
907
1107
 
908
1108
  var __accessCheck$5 = (obj, member, msg) => {
909
1109
  if (!member.has(obj))
910
1110
  throw TypeError("Cannot " + msg);
911
1111
  };
912
- var __privateGet$4 = (obj, member, getter) => {
1112
+ var __privateGet$5 = (obj, member, getter) => {
913
1113
  __accessCheck$5(obj, member, "read from private field");
914
1114
  return getter ? getter.call(obj) : member.get(obj);
915
1115
  };
@@ -918,34 +1118,35 @@ var __privateAdd$5 = (obj, member, value) => {
918
1118
  throw TypeError("Cannot add the same private member more than once");
919
1119
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
920
1120
  };
921
- var __privateSet$3 = (obj, member, value, setter) => {
1121
+ var __privateSet$5 = (obj, member, value, setter) => {
922
1122
  __accessCheck$5(obj, member, "write to private field");
923
1123
  setter ? setter.call(obj, value) : member.set(obj, value);
924
1124
  return value;
925
1125
  };
926
1126
  var _table$1, _repository, _data;
927
1127
  const _Query = class {
928
- constructor(repository, table, data, parent) {
1128
+ constructor(repository, table, data, rawParent) {
929
1129
  __privateAdd$5(this, _table$1, void 0);
930
1130
  __privateAdd$5(this, _repository, void 0);
931
1131
  __privateAdd$5(this, _data, { filter: {} });
932
1132
  this.meta = { page: { cursor: "start", more: true } };
933
- this.records = [];
934
- __privateSet$3(this, _table$1, table);
1133
+ this.records = new RecordArray(this, []);
1134
+ __privateSet$5(this, _table$1, table);
935
1135
  if (repository) {
936
- __privateSet$3(this, _repository, repository);
1136
+ __privateSet$5(this, _repository, repository);
937
1137
  } else {
938
- __privateSet$3(this, _repository, this);
1138
+ __privateSet$5(this, _repository, this);
939
1139
  }
940
- __privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
941
- __privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
942
- __privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
943
- __privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
944
- __privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
945
- __privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
946
- __privateGet$4(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
947
- __privateGet$4(this, _data).page = data.page ?? parent?.page;
948
- __privateGet$4(this, _data).ttl = data.ttl ?? parent?.ttl;
1140
+ const parent = cleanParent(data, rawParent);
1141
+ __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
1142
+ __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
1143
+ __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
1144
+ __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1145
+ __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1146
+ __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1147
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1148
+ __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1149
+ __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
949
1150
  this.any = this.any.bind(this);
950
1151
  this.all = this.all.bind(this);
951
1152
  this.not = this.not.bind(this);
@@ -956,80 +1157,93 @@ const _Query = class {
956
1157
  Object.defineProperty(this, "repository", { enumerable: false });
957
1158
  }
958
1159
  getQueryOptions() {
959
- return __privateGet$4(this, _data);
1160
+ return __privateGet$5(this, _data);
960
1161
  }
961
1162
  key() {
962
- const { columns = [], filter = {}, sort = [], page = {} } = __privateGet$4(this, _data);
963
- const key = JSON.stringify({ columns, filter, sort, page });
1163
+ const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
1164
+ const key = JSON.stringify({ columns, filter, sort, pagination });
964
1165
  return toBase64(key);
965
1166
  }
966
1167
  any(...queries) {
967
1168
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
968
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
1169
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
969
1170
  }
970
1171
  all(...queries) {
971
1172
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
972
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
1173
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
973
1174
  }
974
1175
  not(...queries) {
975
1176
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
976
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
1177
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
977
1178
  }
978
1179
  none(...queries) {
979
1180
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
980
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
1181
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
981
1182
  }
982
1183
  filter(a, b) {
983
1184
  if (arguments.length === 1) {
984
1185
  const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
985
- const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
986
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
1186
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1187
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
987
1188
  } else {
988
- const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
989
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
1189
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1190
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
990
1191
  }
991
1192
  }
992
- sort(column, direction) {
993
- const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
1193
+ sort(column, direction = "asc") {
1194
+ const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
994
1195
  const sort = [...originalSort, { column, direction }];
995
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
1196
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
996
1197
  }
997
1198
  select(columns) {
998
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { columns }, __privateGet$4(this, _data));
1199
+ return new _Query(
1200
+ __privateGet$5(this, _repository),
1201
+ __privateGet$5(this, _table$1),
1202
+ { columns },
1203
+ __privateGet$5(this, _data)
1204
+ );
999
1205
  }
1000
1206
  getPaginated(options = {}) {
1001
- const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
1002
- return __privateGet$4(this, _repository).query(query);
1207
+ const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
1208
+ return __privateGet$5(this, _repository).query(query);
1003
1209
  }
1004
1210
  async *[Symbol.asyncIterator]() {
1005
- for await (const [record] of this.getIterator(1)) {
1211
+ for await (const [record] of this.getIterator({ batchSize: 1 })) {
1006
1212
  yield record;
1007
1213
  }
1008
1214
  }
1009
- async *getIterator(chunk, options = {}) {
1010
- let offset = 0;
1011
- let end = false;
1012
- while (!end) {
1013
- const { records, meta } = await this.getPaginated({ ...options, page: { size: chunk, offset } });
1014
- yield records;
1015
- offset += chunk;
1016
- end = !meta.page.more;
1215
+ async *getIterator(options = {}) {
1216
+ const { batchSize = 1 } = options;
1217
+ let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
1218
+ let more = page.hasNextPage();
1219
+ yield page.records;
1220
+ while (more) {
1221
+ page = await page.nextPage();
1222
+ more = page.hasNextPage();
1223
+ yield page.records;
1017
1224
  }
1018
1225
  }
1019
1226
  async getMany(options = {}) {
1020
- const { records } = await this.getPaginated(options);
1021
- return records;
1227
+ const page = await this.getPaginated(options);
1228
+ if (page.hasNextPage() && options.pagination?.size === void 0) {
1229
+ console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1230
+ }
1231
+ return page.records;
1022
1232
  }
1023
- async getAll(chunk = PAGINATION_MAX_SIZE, options = {}) {
1233
+ async getAll(options = {}) {
1234
+ const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
1024
1235
  const results = [];
1025
- for await (const page of this.getIterator(chunk, options)) {
1236
+ for await (const page of this.getIterator({ ...rest, batchSize })) {
1026
1237
  results.push(...page);
1027
1238
  }
1028
1239
  return results;
1029
1240
  }
1030
1241
  async getFirst(options = {}) {
1031
- const records = await this.getMany({ ...options, page: { size: 1 } });
1032
- return records[0] || null;
1242
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
1243
+ return records[0] ?? null;
1244
+ }
1245
+ cache(ttl) {
1246
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1033
1247
  }
1034
1248
  nextPage(size, offset) {
1035
1249
  return this.firstPage(size, offset);
@@ -1038,10 +1252,10 @@ const _Query = class {
1038
1252
  return this.firstPage(size, offset);
1039
1253
  }
1040
1254
  firstPage(size, offset) {
1041
- return this.getPaginated({ page: { size, offset } });
1255
+ return this.getPaginated({ pagination: { size, offset } });
1042
1256
  }
1043
1257
  lastPage(size, offset) {
1044
- return this.getPaginated({ page: { size, offset, before: "end" } });
1258
+ return this.getPaginated({ pagination: { size, offset, before: "end" } });
1045
1259
  }
1046
1260
  hasNextPage() {
1047
1261
  return this.meta.page.more;
@@ -1051,12 +1265,20 @@ let Query = _Query;
1051
1265
  _table$1 = new WeakMap();
1052
1266
  _repository = new WeakMap();
1053
1267
  _data = new WeakMap();
1268
+ function cleanParent(data, parent) {
1269
+ if (isCursorPaginationOptions(data.pagination)) {
1270
+ return { ...parent, sorting: void 0, filter: void 0 };
1271
+ }
1272
+ return parent;
1273
+ }
1054
1274
 
1055
1275
  function isIdentifiable(x) {
1056
1276
  return isObject(x) && isString(x?.id);
1057
1277
  }
1058
1278
  function isXataRecord(x) {
1059
- return isIdentifiable(x) && typeof x?.xata === "object" && typeof x?.xata?.version === "number";
1279
+ const record = x;
1280
+ const metadata = record?.getMetadata();
1281
+ return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
1060
1282
  }
1061
1283
 
1062
1284
  function isSortFilterString(value) {
@@ -1086,7 +1308,7 @@ var __accessCheck$4 = (obj, member, msg) => {
1086
1308
  if (!member.has(obj))
1087
1309
  throw TypeError("Cannot " + msg);
1088
1310
  };
1089
- var __privateGet$3 = (obj, member, getter) => {
1311
+ var __privateGet$4 = (obj, member, getter) => {
1090
1312
  __accessCheck$4(obj, member, "read from private field");
1091
1313
  return getter ? getter.call(obj) : member.get(obj);
1092
1314
  };
@@ -1095,7 +1317,7 @@ var __privateAdd$4 = (obj, member, value) => {
1095
1317
  throw TypeError("Cannot add the same private member more than once");
1096
1318
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1097
1319
  };
1098
- var __privateSet$2 = (obj, member, value, setter) => {
1320
+ var __privateSet$4 = (obj, member, value, setter) => {
1099
1321
  __accessCheck$4(obj, member, "write to private field");
1100
1322
  setter ? setter.call(obj, value) : member.set(obj, value);
1101
1323
  return value;
@@ -1104,7 +1326,7 @@ var __privateMethod$2 = (obj, member, method) => {
1104
1326
  __accessCheck$4(obj, member, "access private method");
1105
1327
  return method;
1106
1328
  };
1107
- var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn;
1329
+ 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;
1108
1330
  class Repository extends Query {
1109
1331
  }
1110
1332
  class RestRepository extends Query {
@@ -1116,109 +1338,122 @@ class RestRepository extends Query {
1116
1338
  __privateAdd$4(this, _updateRecordWithID);
1117
1339
  __privateAdd$4(this, _upsertRecordWithID);
1118
1340
  __privateAdd$4(this, _deleteRecord);
1119
- __privateAdd$4(this, _invalidateCache);
1120
- __privateAdd$4(this, _setCacheRecord);
1121
- __privateAdd$4(this, _getCacheRecord);
1122
1341
  __privateAdd$4(this, _setCacheQuery);
1123
1342
  __privateAdd$4(this, _getCacheQuery);
1343
+ __privateAdd$4(this, _getSchemaTables$1);
1124
1344
  __privateAdd$4(this, _table, void 0);
1125
- __privateAdd$4(this, _links, void 0);
1126
1345
  __privateAdd$4(this, _getFetchProps, void 0);
1127
- __privateSet$2(this, _table, options.table);
1128
- __privateSet$2(this, _links, options.links ?? {});
1129
- __privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
1130
- this.db = options.db;
1131
- this.cache = options.pluginOptions.cache;
1132
- }
1133
- async create(a, b) {
1346
+ __privateAdd$4(this, _db, void 0);
1347
+ __privateAdd$4(this, _cache, void 0);
1348
+ __privateAdd$4(this, _schemaTables$2, void 0);
1349
+ __privateSet$4(this, _table, options.table);
1350
+ __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1351
+ __privateSet$4(this, _db, options.db);
1352
+ __privateSet$4(this, _cache, options.pluginOptions.cache);
1353
+ __privateSet$4(this, _schemaTables$2, options.schemaTables);
1354
+ }
1355
+ async create(a, b, c) {
1134
1356
  if (Array.isArray(a)) {
1135
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1136
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1137
- return records;
1357
+ if (a.length === 0)
1358
+ return [];
1359
+ const columns = isStringArray(b) ? b : void 0;
1360
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1138
1361
  }
1139
1362
  if (isString(a) && isObject(b)) {
1140
1363
  if (a === "")
1141
1364
  throw new Error("The id can't be empty");
1142
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1143
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1144
- return record;
1365
+ const columns = isStringArray(c) ? c : void 0;
1366
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1145
1367
  }
1146
1368
  if (isObject(a) && isString(a.id)) {
1147
1369
  if (a.id === "")
1148
1370
  throw new Error("The id can't be empty");
1149
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1150
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1151
- return record;
1371
+ const columns = isStringArray(b) ? b : void 0;
1372
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1152
1373
  }
1153
1374
  if (isObject(a)) {
1154
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1155
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1156
- return record;
1375
+ const columns = isStringArray(b) ? b : void 0;
1376
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1157
1377
  }
1158
1378
  throw new Error("Invalid arguments for create method");
1159
1379
  }
1160
- async read(recordId) {
1161
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1162
- if (cacheRecord)
1163
- return cacheRecord;
1164
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1165
- try {
1166
- const response = await getRecord({
1167
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1168
- ...fetchProps
1169
- });
1170
- return initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), response);
1171
- } catch (e) {
1172
- if (isObject(e) && e.status === 404) {
1173
- return null;
1380
+ async read(a, b) {
1381
+ const columns = isStringArray(b) ? b : ["*"];
1382
+ if (Array.isArray(a)) {
1383
+ if (a.length === 0)
1384
+ return [];
1385
+ const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1386
+ const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1387
+ const dictionary = finalObjects.reduce((acc, object) => {
1388
+ acc[object.id] = object;
1389
+ return acc;
1390
+ }, {});
1391
+ return ids.map((id2) => dictionary[id2] ?? null);
1392
+ }
1393
+ const id = isString(a) ? a : a.id;
1394
+ if (isString(id)) {
1395
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1396
+ try {
1397
+ const response = await getRecord({
1398
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1399
+ queryParams: { columns },
1400
+ ...fetchProps
1401
+ });
1402
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1403
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1404
+ } catch (e) {
1405
+ if (isObject(e) && e.status === 404) {
1406
+ return null;
1407
+ }
1408
+ throw e;
1174
1409
  }
1175
- throw e;
1176
1410
  }
1411
+ return null;
1177
1412
  }
1178
- async update(a, b) {
1413
+ async update(a, b, c) {
1179
1414
  if (Array.isArray(a)) {
1415
+ if (a.length === 0)
1416
+ return [];
1180
1417
  if (a.length > 100) {
1181
1418
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1182
1419
  }
1183
- return Promise.all(a.map((object) => this.update(object)));
1420
+ const columns = isStringArray(b) ? b : ["*"];
1421
+ return Promise.all(a.map((object) => this.update(object, columns)));
1184
1422
  }
1185
1423
  if (isString(a) && isObject(b)) {
1186
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1187
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1188
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1189
- return record;
1424
+ const columns = isStringArray(c) ? c : void 0;
1425
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1190
1426
  }
1191
1427
  if (isObject(a) && isString(a.id)) {
1192
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1193
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1194
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1195
- return record;
1428
+ const columns = isStringArray(b) ? b : void 0;
1429
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1196
1430
  }
1197
1431
  throw new Error("Invalid arguments for update method");
1198
1432
  }
1199
- async createOrUpdate(a, b) {
1433
+ async createOrUpdate(a, b, c) {
1200
1434
  if (Array.isArray(a)) {
1435
+ if (a.length === 0)
1436
+ return [];
1201
1437
  if (a.length > 100) {
1202
1438
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1203
1439
  }
1204
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1440
+ const columns = isStringArray(b) ? b : ["*"];
1441
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1205
1442
  }
1206
1443
  if (isString(a) && isObject(b)) {
1207
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1208
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1209
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1210
- return record;
1444
+ const columns = isStringArray(c) ? c : void 0;
1445
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1211
1446
  }
1212
1447
  if (isObject(a) && isString(a.id)) {
1213
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1214
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1215
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1216
- return record;
1448
+ const columns = isStringArray(c) ? c : void 0;
1449
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1217
1450
  }
1218
1451
  throw new Error("Invalid arguments for createOrUpdate method");
1219
1452
  }
1220
1453
  async delete(a) {
1221
1454
  if (Array.isArray(a)) {
1455
+ if (a.length === 0)
1456
+ return;
1222
1457
  if (a.length > 100) {
1223
1458
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1224
1459
  }
@@ -1227,24 +1462,30 @@ class RestRepository extends Query {
1227
1462
  }
1228
1463
  if (isString(a)) {
1229
1464
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1230
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1231
1465
  return;
1232
1466
  }
1233
1467
  if (isObject(a) && isString(a.id)) {
1234
1468
  await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1235
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1236
1469
  return;
1237
1470
  }
1238
1471
  throw new Error("Invalid arguments for delete method");
1239
1472
  }
1240
1473
  async search(query, options = {}) {
1241
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1242
- const { records } = await searchBranch({
1243
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1244
- body: { tables: [__privateGet$3(this, _table)], query, fuzziness: options.fuzziness },
1474
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1475
+ const { records } = await searchTable({
1476
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1477
+ body: {
1478
+ query,
1479
+ fuzziness: options.fuzziness,
1480
+ prefix: options.prefix,
1481
+ highlight: options.highlight,
1482
+ filter: options.filter,
1483
+ boosters: options.boosters
1484
+ },
1245
1485
  ...fetchProps
1246
1486
  });
1247
- return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
1487
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1488
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1248
1489
  }
1249
1490
  async query(query) {
1250
1491
  const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
@@ -1253,149 +1494,139 @@ class RestRepository extends Query {
1253
1494
  const data = query.getQueryOptions();
1254
1495
  const body = {
1255
1496
  filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1256
- sort: data.sort ? buildSortFilter(data.sort) : void 0,
1257
- page: data.page,
1497
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1498
+ page: data.pagination,
1258
1499
  columns: data.columns
1259
1500
  };
1260
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1501
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1261
1502
  const { meta, records: objects } = await queryTable({
1262
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1503
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1263
1504
  body,
1264
1505
  ...fetchProps
1265
1506
  });
1266
- const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
1507
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1508
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1267
1509
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1268
1510
  return new Page(query, meta, records);
1269
1511
  }
1270
1512
  }
1271
1513
  _table = new WeakMap();
1272
- _links = new WeakMap();
1273
1514
  _getFetchProps = new WeakMap();
1515
+ _db = new WeakMap();
1516
+ _cache = new WeakMap();
1517
+ _schemaTables$2 = new WeakMap();
1274
1518
  _insertRecordWithoutId = new WeakSet();
1275
- insertRecordWithoutId_fn = async function(object) {
1276
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1519
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1520
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1277
1521
  const record = transformObjectLinks(object);
1278
1522
  const response = await insertRecord({
1279
1523
  pathParams: {
1280
1524
  workspace: "{workspaceId}",
1281
1525
  dbBranchName: "{dbBranch}",
1282
- tableName: __privateGet$3(this, _table)
1526
+ tableName: __privateGet$4(this, _table)
1283
1527
  },
1528
+ queryParams: { columns },
1284
1529
  body: record,
1285
1530
  ...fetchProps
1286
1531
  });
1287
- const finalObject = await this.read(response.id);
1288
- if (!finalObject) {
1289
- throw new Error("The server failed to save the record");
1290
- }
1291
- return finalObject;
1532
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1533
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1292
1534
  };
1293
1535
  _insertRecordWithId = new WeakSet();
1294
- insertRecordWithId_fn = async function(recordId, object) {
1295
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1536
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1537
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1296
1538
  const record = transformObjectLinks(object);
1297
1539
  const response = await insertRecordWithID({
1298
1540
  pathParams: {
1299
1541
  workspace: "{workspaceId}",
1300
1542
  dbBranchName: "{dbBranch}",
1301
- tableName: __privateGet$3(this, _table),
1543
+ tableName: __privateGet$4(this, _table),
1302
1544
  recordId
1303
1545
  },
1304
1546
  body: record,
1305
- queryParams: { createOnly: true },
1547
+ queryParams: { createOnly: true, columns },
1306
1548
  ...fetchProps
1307
1549
  });
1308
- const finalObject = await this.read(response.id);
1309
- if (!finalObject) {
1310
- throw new Error("The server failed to save the record");
1311
- }
1312
- return finalObject;
1550
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1551
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1313
1552
  };
1314
1553
  _bulkInsertTableRecords = new WeakSet();
1315
- bulkInsertTableRecords_fn = async function(objects) {
1316
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1554
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1555
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1317
1556
  const records = objects.map((object) => transformObjectLinks(object));
1318
1557
  const response = await bulkInsertTableRecords({
1319
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1558
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1559
+ queryParams: { columns },
1320
1560
  body: { records },
1321
1561
  ...fetchProps
1322
1562
  });
1323
- const finalObjects = await this.any(...response.recordIDs.map((id) => this.filter("id", id))).getAll();
1324
- if (finalObjects.length !== objects.length) {
1325
- throw new Error("The server failed to save some records");
1563
+ if (!isResponseWithRecords(response)) {
1564
+ throw new Error("Request included columns but server didn't include them");
1326
1565
  }
1327
- return finalObjects;
1566
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1567
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1328
1568
  };
1329
1569
  _updateRecordWithID = new WeakSet();
1330
- updateRecordWithID_fn = async function(recordId, object) {
1331
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1570
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1571
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1332
1572
  const record = transformObjectLinks(object);
1333
1573
  const response = await updateRecordWithID({
1334
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1574
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1575
+ queryParams: { columns },
1335
1576
  body: record,
1336
1577
  ...fetchProps
1337
1578
  });
1338
- const item = await this.read(response.id);
1339
- if (!item)
1340
- throw new Error("The server failed to save the record");
1341
- return item;
1579
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1580
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1342
1581
  };
1343
1582
  _upsertRecordWithID = new WeakSet();
1344
- upsertRecordWithID_fn = async function(recordId, object) {
1345
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1583
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1584
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1346
1585
  const response = await upsertRecordWithID({
1347
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1586
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1587
+ queryParams: { columns },
1348
1588
  body: object,
1349
1589
  ...fetchProps
1350
1590
  });
1351
- const item = await this.read(response.id);
1352
- if (!item)
1353
- throw new Error("The server failed to save the record");
1354
- return item;
1591
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1592
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1355
1593
  };
1356
1594
  _deleteRecord = new WeakSet();
1357
1595
  deleteRecord_fn = async function(recordId) {
1358
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1596
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1359
1597
  await deleteRecord({
1360
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1598
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1361
1599
  ...fetchProps
1362
1600
  });
1363
1601
  };
1364
- _invalidateCache = new WeakSet();
1365
- invalidateCache_fn = async function(recordId) {
1366
- await this.cache.delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1367
- const cacheItems = await this.cache.getAll();
1368
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1369
- for (const [key, value] of queries) {
1370
- const ids = getIds(value);
1371
- if (ids.includes(recordId))
1372
- await this.cache.delete(key);
1373
- }
1374
- };
1375
- _setCacheRecord = new WeakSet();
1376
- setCacheRecord_fn = async function(record) {
1377
- await this.cache.set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
1378
- };
1379
- _getCacheRecord = new WeakSet();
1380
- getCacheRecord_fn = async function(recordId) {
1381
- return this.cache.get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1382
- };
1383
1602
  _setCacheQuery = new WeakSet();
1384
1603
  setCacheQuery_fn = async function(query, meta, records) {
1385
- await this.cache.set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1604
+ await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1386
1605
  };
1387
1606
  _getCacheQuery = new WeakSet();
1388
1607
  getCacheQuery_fn = async function(query) {
1389
- const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
1390
- const result = await this.cache.get(key);
1608
+ const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
1609
+ const result = await __privateGet$4(this, _cache).get(key);
1391
1610
  if (!result)
1392
1611
  return null;
1393
- const { ttl = 0 } = query.getQueryOptions();
1394
- if (!ttl || ttl < 0)
1395
- return result;
1612
+ const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1613
+ if (ttl < 0)
1614
+ return null;
1396
1615
  const hasExpired = result.date.getTime() + ttl < Date.now();
1397
1616
  return hasExpired ? null : result;
1398
1617
  };
1618
+ _getSchemaTables$1 = new WeakSet();
1619
+ getSchemaTables_fn$1 = async function() {
1620
+ if (__privateGet$4(this, _schemaTables$2))
1621
+ return __privateGet$4(this, _schemaTables$2);
1622
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1623
+ const { schema } = await getBranchDetails({
1624
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1625
+ ...fetchProps
1626
+ });
1627
+ __privateSet$4(this, _schemaTables$2, schema.tables);
1628
+ return schema.tables;
1629
+ };
1399
1630
  const transformObjectLinks = (object) => {
1400
1631
  return Object.entries(object).reduce((acc, [key, value]) => {
1401
1632
  if (key === "xata")
@@ -1403,47 +1634,63 @@ const transformObjectLinks = (object) => {
1403
1634
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1404
1635
  }, {});
1405
1636
  };
1406
- const initObject = (db, links, table, object) => {
1637
+ const initObject = (db, schemaTables, table, object) => {
1407
1638
  const result = {};
1408
- Object.assign(result, object);
1409
- const tableLinks = links[table] || [];
1410
- for (const link of tableLinks) {
1411
- const [field, linkTable] = link;
1412
- const value = result[field];
1413
- if (value && isObject(value)) {
1414
- result[field] = initObject(db, links, linkTable, value);
1639
+ const { xata, ...rest } = object ?? {};
1640
+ Object.assign(result, rest);
1641
+ const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
1642
+ if (!columns)
1643
+ console.error(`Table ${table} not found in schema`);
1644
+ for (const column of columns ?? []) {
1645
+ const value = result[column.name];
1646
+ switch (column.type) {
1647
+ case "datetime": {
1648
+ const date = value !== void 0 ? new Date(value) : void 0;
1649
+ if (date && isNaN(date.getTime())) {
1650
+ console.error(`Failed to parse date ${value} for field ${column.name}`);
1651
+ } else if (date) {
1652
+ result[column.name] = date;
1653
+ }
1654
+ break;
1655
+ }
1656
+ case "link": {
1657
+ const linkTable = column.link?.table;
1658
+ if (!linkTable) {
1659
+ console.error(`Failed to parse link for field ${column.name}`);
1660
+ } else if (isObject(value)) {
1661
+ result[column.name] = initObject(db, schemaTables, linkTable, value);
1662
+ }
1663
+ break;
1664
+ }
1415
1665
  }
1416
1666
  }
1417
- result.read = function() {
1418
- return db[table].read(result["id"]);
1667
+ result.read = function(columns2) {
1668
+ return db[table].read(result["id"], columns2);
1419
1669
  };
1420
- result.update = function(data) {
1421
- return db[table].update(result["id"], data);
1670
+ result.update = function(data, columns2) {
1671
+ return db[table].update(result["id"], data, columns2);
1422
1672
  };
1423
1673
  result.delete = function() {
1424
1674
  return db[table].delete(result["id"]);
1425
1675
  };
1426
- for (const prop of ["read", "update", "delete"]) {
1676
+ result.getMetadata = function() {
1677
+ return xata;
1678
+ };
1679
+ for (const prop of ["read", "update", "delete", "getMetadata"]) {
1427
1680
  Object.defineProperty(result, prop, { enumerable: false });
1428
1681
  }
1429
1682
  Object.freeze(result);
1430
1683
  return result;
1431
1684
  };
1432
- function getIds(value) {
1433
- if (Array.isArray(value)) {
1434
- return value.map((item) => getIds(item)).flat();
1435
- }
1436
- if (!isObject(value))
1437
- return [];
1438
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1439
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1685
+ function isResponseWithRecords(value) {
1686
+ return isObject(value) && Array.isArray(value.records);
1440
1687
  }
1441
1688
 
1442
1689
  var __accessCheck$3 = (obj, member, msg) => {
1443
1690
  if (!member.has(obj))
1444
1691
  throw TypeError("Cannot " + msg);
1445
1692
  };
1446
- var __privateGet$2 = (obj, member, getter) => {
1693
+ var __privateGet$3 = (obj, member, getter) => {
1447
1694
  __accessCheck$3(obj, member, "read from private field");
1448
1695
  return getter ? getter.call(obj) : member.get(obj);
1449
1696
  };
@@ -1452,31 +1699,38 @@ var __privateAdd$3 = (obj, member, value) => {
1452
1699
  throw TypeError("Cannot add the same private member more than once");
1453
1700
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1454
1701
  };
1455
- var __privateSet$1 = (obj, member, value, setter) => {
1702
+ var __privateSet$3 = (obj, member, value, setter) => {
1456
1703
  __accessCheck$3(obj, member, "write to private field");
1457
1704
  setter ? setter.call(obj, value) : member.set(obj, value);
1458
1705
  return value;
1459
1706
  };
1460
1707
  var _map;
1461
1708
  class SimpleCache {
1462
- constructor() {
1709
+ constructor(options = {}) {
1463
1710
  __privateAdd$3(this, _map, void 0);
1464
- __privateSet$1(this, _map, /* @__PURE__ */ new Map());
1711
+ __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1712
+ this.capacity = options.max ?? 500;
1713
+ this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1465
1714
  }
1466
1715
  async getAll() {
1467
- return Object.fromEntries(__privateGet$2(this, _map));
1716
+ return Object.fromEntries(__privateGet$3(this, _map));
1468
1717
  }
1469
1718
  async get(key) {
1470
- return __privateGet$2(this, _map).get(key) ?? null;
1719
+ return __privateGet$3(this, _map).get(key) ?? null;
1471
1720
  }
1472
1721
  async set(key, value) {
1473
- __privateGet$2(this, _map).set(key, value);
1722
+ await this.delete(key);
1723
+ __privateGet$3(this, _map).set(key, value);
1724
+ if (__privateGet$3(this, _map).size > this.capacity) {
1725
+ const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
1726
+ await this.delete(leastRecentlyUsed);
1727
+ }
1474
1728
  }
1475
1729
  async delete(key) {
1476
- __privateGet$2(this, _map).delete(key);
1730
+ __privateGet$3(this, _map).delete(key);
1477
1731
  }
1478
1732
  async clear() {
1479
- return __privateGet$2(this, _map).clear();
1733
+ return __privateGet$3(this, _map).clear();
1480
1734
  }
1481
1735
  }
1482
1736
  _map = new WeakMap();
@@ -1504,7 +1758,7 @@ var __accessCheck$2 = (obj, member, msg) => {
1504
1758
  if (!member.has(obj))
1505
1759
  throw TypeError("Cannot " + msg);
1506
1760
  };
1507
- var __privateGet$1 = (obj, member, getter) => {
1761
+ var __privateGet$2 = (obj, member, getter) => {
1508
1762
  __accessCheck$2(obj, member, "read from private field");
1509
1763
  return getter ? getter.call(obj) : member.get(obj);
1510
1764
  };
@@ -1513,130 +1767,177 @@ var __privateAdd$2 = (obj, member, value) => {
1513
1767
  throw TypeError("Cannot add the same private member more than once");
1514
1768
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1515
1769
  };
1516
- var _tables;
1770
+ var __privateSet$2 = (obj, member, value, setter) => {
1771
+ __accessCheck$2(obj, member, "write to private field");
1772
+ setter ? setter.call(obj, value) : member.set(obj, value);
1773
+ return value;
1774
+ };
1775
+ var _tables, _schemaTables$1;
1517
1776
  class SchemaPlugin extends XataPlugin {
1518
- constructor(links, tableNames) {
1777
+ constructor(schemaTables) {
1519
1778
  super();
1520
- this.links = links;
1521
- this.tableNames = tableNames;
1522
1779
  __privateAdd$2(this, _tables, {});
1780
+ __privateAdd$2(this, _schemaTables$1, void 0);
1781
+ __privateSet$2(this, _schemaTables$1, schemaTables);
1523
1782
  }
1524
1783
  build(pluginOptions) {
1525
- const links = this.links;
1526
- const db = new Proxy({}, {
1527
- get: (_target, table) => {
1528
- if (!isString(table))
1529
- throw new Error("Invalid table name");
1530
- if (!__privateGet$1(this, _tables)[table]) {
1531
- __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, links });
1784
+ const db = new Proxy(
1785
+ {},
1786
+ {
1787
+ get: (_target, table) => {
1788
+ if (!isString(table))
1789
+ throw new Error("Invalid table name");
1790
+ if (__privateGet$2(this, _tables)[table] === void 0) {
1791
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1792
+ }
1793
+ return __privateGet$2(this, _tables)[table];
1532
1794
  }
1533
- return __privateGet$1(this, _tables)[table];
1534
1795
  }
1535
- });
1536
- for (const table of this.tableNames ?? []) {
1537
- db[table] = new RestRepository({ db, pluginOptions, table, links });
1796
+ );
1797
+ const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
1798
+ for (const table of tableNames) {
1799
+ db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1538
1800
  }
1539
1801
  return db;
1540
1802
  }
1541
1803
  }
1542
1804
  _tables = new WeakMap();
1805
+ _schemaTables$1 = new WeakMap();
1543
1806
 
1544
1807
  var __accessCheck$1 = (obj, member, msg) => {
1545
1808
  if (!member.has(obj))
1546
1809
  throw TypeError("Cannot " + msg);
1547
1810
  };
1811
+ var __privateGet$1 = (obj, member, getter) => {
1812
+ __accessCheck$1(obj, member, "read from private field");
1813
+ return getter ? getter.call(obj) : member.get(obj);
1814
+ };
1548
1815
  var __privateAdd$1 = (obj, member, value) => {
1549
1816
  if (member.has(obj))
1550
1817
  throw TypeError("Cannot add the same private member more than once");
1551
1818
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1552
1819
  };
1820
+ var __privateSet$1 = (obj, member, value, setter) => {
1821
+ __accessCheck$1(obj, member, "write to private field");
1822
+ setter ? setter.call(obj, value) : member.set(obj, value);
1823
+ return value;
1824
+ };
1553
1825
  var __privateMethod$1 = (obj, member, method) => {
1554
1826
  __accessCheck$1(obj, member, "access private method");
1555
1827
  return method;
1556
1828
  };
1557
- var _search, search_fn;
1829
+ var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
1558
1830
  class SearchPlugin extends XataPlugin {
1559
- constructor(db, links) {
1831
+ constructor(db, schemaTables) {
1560
1832
  super();
1561
1833
  this.db = db;
1562
- this.links = links;
1563
1834
  __privateAdd$1(this, _search);
1835
+ __privateAdd$1(this, _getSchemaTables);
1836
+ __privateAdd$1(this, _schemaTables, void 0);
1837
+ __privateSet$1(this, _schemaTables, schemaTables);
1564
1838
  }
1565
1839
  build({ getFetchProps }) {
1566
1840
  return {
1567
1841
  all: async (query, options = {}) => {
1568
1842
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1843
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1569
1844
  return records.map((record) => {
1570
1845
  const { table = "orphan" } = record.xata;
1571
- return { table, record: initObject(this.db, this.links, table, record) };
1846
+ return { table, record: initObject(this.db, schemaTables, table, record) };
1572
1847
  });
1573
1848
  },
1574
1849
  byTable: async (query, options = {}) => {
1575
1850
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1851
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1576
1852
  return records.reduce((acc, record) => {
1577
1853
  const { table = "orphan" } = record.xata;
1578
1854
  const items = acc[table] ?? [];
1579
- const item = initObject(this.db, this.links, table, record);
1855
+ const item = initObject(this.db, schemaTables, table, record);
1580
1856
  return { ...acc, [table]: [...items, item] };
1581
1857
  }, {});
1582
1858
  }
1583
1859
  };
1584
1860
  }
1585
1861
  }
1862
+ _schemaTables = new WeakMap();
1586
1863
  _search = new WeakSet();
1587
1864
  search_fn = async function(query, options, getFetchProps) {
1588
1865
  const fetchProps = await getFetchProps();
1589
- const { tables, fuzziness } = options ?? {};
1866
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1590
1867
  const { records } = await searchBranch({
1591
1868
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1592
- body: { tables, query, fuzziness },
1869
+ body: { tables, query, fuzziness, prefix, highlight },
1593
1870
  ...fetchProps
1594
1871
  });
1595
1872
  return records;
1596
1873
  };
1874
+ _getSchemaTables = new WeakSet();
1875
+ getSchemaTables_fn = async function(getFetchProps) {
1876
+ if (__privateGet$1(this, _schemaTables))
1877
+ return __privateGet$1(this, _schemaTables);
1878
+ const fetchProps = await getFetchProps();
1879
+ const { schema } = await getBranchDetails({
1880
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1881
+ ...fetchProps
1882
+ });
1883
+ __privateSet$1(this, _schemaTables, schema.tables);
1884
+ return schema.tables;
1885
+ };
1597
1886
 
1598
1887
  const isBranchStrategyBuilder = (strategy) => {
1599
1888
  return typeof strategy === "function";
1600
1889
  };
1601
1890
 
1602
- const envBranchNames = [
1603
- "XATA_BRANCH",
1604
- "VERCEL_GIT_COMMIT_REF",
1605
- "CF_PAGES_BRANCH",
1606
- "BRANCH"
1607
- ];
1608
- const defaultBranch = "main";
1609
1891
  async function getCurrentBranchName(options) {
1610
- const env = await getBranchByEnvVariable();
1611
- if (env)
1612
- return env;
1613
- const branch = await getGitBranch();
1614
- if (!branch)
1615
- return defaultBranch;
1616
- const details = await getDatabaseBranch(branch, options);
1617
- if (details)
1618
- return branch;
1619
- return defaultBranch;
1892
+ const { branch, envBranch } = getEnvironment();
1893
+ if (branch) {
1894
+ const details = await getDatabaseBranch(branch, options);
1895
+ if (details)
1896
+ return branch;
1897
+ console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
1898
+ }
1899
+ const gitBranch = envBranch || await getGitBranch();
1900
+ return resolveXataBranch(gitBranch, options);
1620
1901
  }
1621
1902
  async function getCurrentBranchDetails(options) {
1622
- const env = await getBranchByEnvVariable();
1623
- if (env)
1624
- return getDatabaseBranch(env, options);
1625
- const branch = await getGitBranch();
1626
- if (!branch)
1627
- return getDatabaseBranch(defaultBranch, options);
1628
- const details = await getDatabaseBranch(branch, options);
1629
- if (details)
1630
- return details;
1631
- return getDatabaseBranch(defaultBranch, options);
1903
+ const branch = await getCurrentBranchName(options);
1904
+ return getDatabaseBranch(branch, options);
1905
+ }
1906
+ async function resolveXataBranch(gitBranch, options) {
1907
+ const databaseURL = options?.databaseURL || getDatabaseURL();
1908
+ const apiKey = options?.apiKey || getAPIKey();
1909
+ if (!databaseURL)
1910
+ throw new Error(
1911
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
1912
+ );
1913
+ if (!apiKey)
1914
+ throw new Error(
1915
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1916
+ );
1917
+ const [protocol, , host, , dbName] = databaseURL.split("/");
1918
+ const [workspace] = host.split(".");
1919
+ const { fallbackBranch } = getEnvironment();
1920
+ const { branch } = await resolveBranch({
1921
+ apiKey,
1922
+ apiUrl: databaseURL,
1923
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
1924
+ workspacesApiUrl: `${protocol}//${host}`,
1925
+ pathParams: { dbName, workspace },
1926
+ queryParams: { gitBranch, fallbackBranch }
1927
+ });
1928
+ return branch;
1632
1929
  }
1633
1930
  async function getDatabaseBranch(branch, options) {
1634
1931
  const databaseURL = options?.databaseURL || getDatabaseURL();
1635
1932
  const apiKey = options?.apiKey || getAPIKey();
1636
1933
  if (!databaseURL)
1637
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1934
+ throw new Error(
1935
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
1936
+ );
1638
1937
  if (!apiKey)
1639
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1938
+ throw new Error(
1939
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
1940
+ );
1640
1941
  const [protocol, , host, , database] = databaseURL.split("/");
1641
1942
  const [workspace] = host.split(".");
1642
1943
  const dbBranchName = `${database}:${branch}`;
@@ -1646,10 +1947,7 @@ async function getDatabaseBranch(branch, options) {
1646
1947
  apiUrl: databaseURL,
1647
1948
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1648
1949
  workspacesApiUrl: `${protocol}//${host}`,
1649
- pathParams: {
1650
- dbBranchName,
1651
- workspace
1652
- }
1950
+ pathParams: { dbBranchName, workspace }
1653
1951
  });
1654
1952
  } catch (err) {
1655
1953
  if (isObject(err) && err.status === 404)
@@ -1657,21 +1955,10 @@ async function getDatabaseBranch(branch, options) {
1657
1955
  throw err;
1658
1956
  }
1659
1957
  }
1660
- function getBranchByEnvVariable() {
1661
- for (const name of envBranchNames) {
1662
- const value = getEnvVariable(name);
1663
- if (value) {
1664
- return value;
1665
- }
1666
- }
1667
- try {
1668
- return XATA_BRANCH;
1669
- } catch (err) {
1670
- }
1671
- }
1672
1958
  function getDatabaseURL() {
1673
1959
  try {
1674
- return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
1960
+ const { databaseURL } = getEnvironment();
1961
+ return databaseURL;
1675
1962
  } catch (err) {
1676
1963
  return void 0;
1677
1964
  }
@@ -1700,24 +1987,26 @@ var __privateMethod = (obj, member, method) => {
1700
1987
  return method;
1701
1988
  };
1702
1989
  const buildClient = (plugins) => {
1703
- var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1990
+ var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1704
1991
  return _a = class {
1705
- constructor(options = {}, links, tables) {
1992
+ constructor(options = {}, schemaTables) {
1706
1993
  __privateAdd(this, _parseOptions);
1707
1994
  __privateAdd(this, _getFetchProps);
1708
1995
  __privateAdd(this, _evaluateBranch);
1709
1996
  __privateAdd(this, _branch, void 0);
1997
+ __privateAdd(this, _options, void 0);
1710
1998
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
1999
+ __privateSet(this, _options, safeOptions);
1711
2000
  const pluginOptions = {
1712
2001
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1713
2002
  cache: safeOptions.cache
1714
2003
  };
1715
- const db = new SchemaPlugin(links, tables).build(pluginOptions);
1716
- const search = new SearchPlugin(db, links ?? {}).build(pluginOptions);
2004
+ const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2005
+ const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
1717
2006
  this.db = db;
1718
2007
  this.search = search;
1719
2008
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1720
- if (!namespace)
2009
+ if (namespace === void 0)
1721
2010
  continue;
1722
2011
  const result = namespace.build(pluginOptions);
1723
2012
  if (result instanceof Promise) {
@@ -1729,22 +2018,22 @@ const buildClient = (plugins) => {
1729
2018
  }
1730
2019
  }
1731
2020
  }
1732
- }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2021
+ async getConfig() {
2022
+ const databaseURL = __privateGet(this, _options).databaseURL;
2023
+ const branch = await __privateGet(this, _options).branch();
2024
+ return { databaseURL, branch };
2025
+ }
2026
+ }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
1733
2027
  const fetch = getFetchImplementation(options?.fetch);
1734
2028
  const databaseURL = options?.databaseURL || getDatabaseURL();
1735
2029
  const apiKey = options?.apiKey || getAPIKey();
1736
- const cache = options?.cache ?? new SimpleCache();
1737
- const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2030
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2031
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1738
2032
  if (!databaseURL || !apiKey) {
1739
2033
  throw new Error("Options databaseURL and apiKey are required");
1740
2034
  }
1741
2035
  return { fetch, databaseURL, apiKey, branch, cache };
1742
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1743
- fetch,
1744
- apiKey,
1745
- databaseURL,
1746
- branch
1747
- }) {
2036
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch }) {
1748
2037
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
1749
2038
  if (!branchValue)
1750
2039
  throw new Error("Unable to resolve branch value");
@@ -1761,7 +2050,7 @@ const buildClient = (plugins) => {
1761
2050
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
1762
2051
  if (__privateGet(this, _branch))
1763
2052
  return __privateGet(this, _branch);
1764
- if (!param)
2053
+ if (param === void 0)
1765
2054
  return void 0;
1766
2055
  const strategies = Array.isArray(param) ? [...param] : [param];
1767
2056
  const evaluateBranch = async (strategy) => {
@@ -1779,6 +2068,88 @@ const buildClient = (plugins) => {
1779
2068
  class BaseClient extends buildClient() {
1780
2069
  }
1781
2070
 
2071
+ const META = "__";
2072
+ const VALUE = "___";
2073
+ class Serializer {
2074
+ constructor() {
2075
+ this.classes = {};
2076
+ }
2077
+ add(clazz) {
2078
+ this.classes[clazz.name] = clazz;
2079
+ }
2080
+ toJSON(data) {
2081
+ function visit(obj) {
2082
+ if (Array.isArray(obj))
2083
+ return obj.map(visit);
2084
+ const type = typeof obj;
2085
+ if (type === "undefined")
2086
+ return { [META]: "undefined" };
2087
+ if (type === "bigint")
2088
+ return { [META]: "bigint", [VALUE]: obj.toString() };
2089
+ if (obj === null || type !== "object")
2090
+ return obj;
2091
+ const constructor = obj.constructor;
2092
+ const o = { [META]: constructor.name };
2093
+ for (const [key, value] of Object.entries(obj)) {
2094
+ o[key] = visit(value);
2095
+ }
2096
+ if (constructor === Date)
2097
+ o[VALUE] = obj.toISOString();
2098
+ if (constructor === Map)
2099
+ o[VALUE] = Object.fromEntries(obj);
2100
+ if (constructor === Set)
2101
+ o[VALUE] = [...obj];
2102
+ return o;
2103
+ }
2104
+ return JSON.stringify(visit(data));
2105
+ }
2106
+ fromJSON(json) {
2107
+ return JSON.parse(json, (key, value) => {
2108
+ if (value && typeof value === "object" && !Array.isArray(value)) {
2109
+ const { [META]: clazz, [VALUE]: val, ...rest } = value;
2110
+ const constructor = this.classes[clazz];
2111
+ if (constructor) {
2112
+ return Object.assign(Object.create(constructor.prototype), rest);
2113
+ }
2114
+ if (clazz === "Date")
2115
+ return new Date(val);
2116
+ if (clazz === "Set")
2117
+ return new Set(val);
2118
+ if (clazz === "Map")
2119
+ return new Map(Object.entries(val));
2120
+ if (clazz === "bigint")
2121
+ return BigInt(val);
2122
+ if (clazz === "undefined")
2123
+ return void 0;
2124
+ return rest;
2125
+ }
2126
+ return value;
2127
+ });
2128
+ }
2129
+ }
2130
+ const defaultSerializer = new Serializer();
2131
+ const serialize = (data) => {
2132
+ return defaultSerializer.toJSON(data);
2133
+ };
2134
+ const deserialize = (json) => {
2135
+ return defaultSerializer.fromJSON(json);
2136
+ };
2137
+
2138
+ function buildWorkerRunner(config) {
2139
+ return function xataWorker(name, _worker) {
2140
+ return async (...args) => {
2141
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2142
+ const result = await fetch(url, {
2143
+ method: "POST",
2144
+ headers: { "Content-Type": "application/json" },
2145
+ body: serialize({ args })
2146
+ });
2147
+ const text = await result.text();
2148
+ return deserialize(text);
2149
+ };
2150
+ };
2151
+ }
2152
+
1782
2153
  class XataError extends Error {
1783
2154
  constructor(message, status) {
1784
2155
  super(message);
@@ -1786,5 +2157,5 @@ class XataError extends Error {
1786
2157
  }
1787
2158
  }
1788
2159
 
1789
- export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeWorkspaceMember, resendWorkspaceMemberInvite, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
2160
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
1790
2161
  //# sourceMappingURL=index.mjs.map