@xata.io/client 0.0.0-alpha.vfd071d9 → 0.0.0-alpha.vfd1a215

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
@@ -2,6 +2,46 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ function _interopNamespace(e) {
6
+ if (e && e.__esModule) return e;
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n["default"] = e;
20
+ return Object.freeze(n);
21
+ }
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
+
5
45
  function notEmpty(value) {
6
46
  return value !== null && value !== void 0;
7
47
  }
@@ -11,46 +51,101 @@ function compact(arr) {
11
51
  function isObject(value) {
12
52
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
13
53
  }
54
+ function isDefined(value) {
55
+ return value !== null && value !== void 0;
56
+ }
14
57
  function isString(value) {
15
- return value !== void 0 && value !== null && typeof value === "string";
58
+ return isDefined(value) && typeof value === "string";
59
+ }
60
+ function isStringArray(value) {
61
+ return isDefined(value) && Array.isArray(value) && value.every(isString);
16
62
  }
17
63
  function toBase64(value) {
18
64
  try {
19
65
  return btoa(value);
20
66
  } catch (err) {
21
- return Buffer.from(value).toString("base64");
67
+ const buf = Buffer;
68
+ return buf.from(value).toString("base64");
22
69
  }
23
70
  }
24
71
 
25
- function getEnvVariable(name) {
72
+ function getEnvironment() {
26
73
  try {
27
- if (isObject(process) && isString(process?.env?.[name])) {
28
- return process.env[name];
74
+ if (isObject(process) && isObject(process.env)) {
75
+ return {
76
+ apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
77
+ databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
78
+ branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
79
+ envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
80
+ fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
81
+ };
29
82
  }
30
83
  } catch (err) {
31
84
  }
32
85
  try {
33
- if (isObject(Deno) && isString(Deno?.env?.get(name))) {
34
- return Deno.env.get(name);
86
+ if (isObject(Deno) && isObject(Deno.env)) {
87
+ return {
88
+ apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
89
+ databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
90
+ branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
91
+ envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
92
+ fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
93
+ };
35
94
  }
36
95
  } catch (err) {
37
96
  }
97
+ return {
98
+ apiKey: getGlobalApiKey(),
99
+ databaseURL: getGlobalDatabaseURL(),
100
+ branch: getGlobalBranch(),
101
+ envBranch: void 0,
102
+ fallbackBranch: getGlobalFallbackBranch()
103
+ };
104
+ }
105
+ function getGlobalApiKey() {
106
+ try {
107
+ return XATA_API_KEY;
108
+ } catch (err) {
109
+ return void 0;
110
+ }
111
+ }
112
+ function getGlobalDatabaseURL() {
113
+ try {
114
+ return XATA_DATABASE_URL;
115
+ } catch (err) {
116
+ return void 0;
117
+ }
118
+ }
119
+ function getGlobalBranch() {
120
+ try {
121
+ return XATA_BRANCH;
122
+ } catch (err) {
123
+ return void 0;
124
+ }
125
+ }
126
+ function getGlobalFallbackBranch() {
127
+ try {
128
+ return XATA_FALLBACK_BRANCH;
129
+ } catch (err) {
130
+ return void 0;
131
+ }
38
132
  }
39
133
  async function getGitBranch() {
134
+ const cmd = ["git", "branch", "--show-current"];
135
+ const fullCmd = cmd.join(" ");
136
+ const nodeModule = ["child", "process"].join("_");
137
+ const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
40
138
  try {
41
139
  if (typeof require === "function") {
42
- const req = require;
43
- return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
140
+ return require(nodeModule).execSync(fullCmd, execOptions).trim();
44
141
  }
142
+ const { execSync } = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(nodeModule);
143
+ return execSync(fullCmd, execOptions).toString().trim();
45
144
  } catch (err) {
46
145
  }
47
146
  try {
48
147
  if (isObject(Deno)) {
49
- const process2 = Deno.run({
50
- cmd: ["git", "branch", "--show-current"],
51
- stdout: "piped",
52
- stderr: "piped"
53
- });
148
+ const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
54
149
  return new TextDecoder().decode(await process2.output()).trim();
55
150
  }
56
151
  } catch (err) {
@@ -59,7 +154,8 @@ async function getGitBranch() {
59
154
 
60
155
  function getAPIKey() {
61
156
  try {
62
- return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
157
+ const { apiKey } = getEnvironment();
158
+ return apiKey;
63
159
  } catch (err) {
64
160
  return void 0;
65
161
  }
@@ -69,21 +165,35 @@ function getFetchImplementation(userFetch) {
69
165
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
70
166
  const fetchImpl = userFetch ?? globalFetch;
71
167
  if (!fetchImpl) {
72
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
168
+ throw new Error(
169
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
170
+ );
73
171
  }
74
172
  return fetchImpl;
75
173
  }
76
174
 
77
- class FetcherError extends Error {
78
- constructor(status, data) {
175
+ const VERSION = "0.0.0-alpha.vfd1a215";
176
+
177
+ class ErrorWithCause extends Error {
178
+ constructor(message, options) {
179
+ super(message, options);
180
+ }
181
+ }
182
+ class FetcherError extends ErrorWithCause {
183
+ constructor(status, data, requestId) {
79
184
  super(getMessage(data));
80
185
  this.status = status;
81
186
  this.errors = isBulkError(data) ? data.errors : void 0;
187
+ this.requestId = requestId;
82
188
  if (data instanceof Error) {
83
189
  this.stack = data.stack;
84
190
  this.cause = data.cause;
85
191
  }
86
192
  }
193
+ toString() {
194
+ const error = super.toString();
195
+ return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
196
+ }
87
197
  }
88
198
  function isBulkError(error) {
89
199
  return isObject(error) && Array.isArray(error.errors);
@@ -106,9 +216,17 @@ function getMessage(data) {
106
216
  }
107
217
 
108
218
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
109
- const query = new URLSearchParams(queryParams).toString();
219
+ const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
220
+ if (value === void 0 || value === null)
221
+ return acc;
222
+ return { ...acc, [key]: value };
223
+ }, {});
224
+ const query = new URLSearchParams(cleanQueryParams).toString();
110
225
  const queryString = query.length > 0 ? `?${query}` : "";
111
- 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;
112
230
  };
113
231
  function buildBaseUrl({
114
232
  path,
@@ -116,10 +234,10 @@ function buildBaseUrl({
116
234
  apiUrl,
117
235
  pathParams
118
236
  }) {
119
- if (!pathParams?.workspace)
237
+ if (pathParams?.workspace === void 0)
120
238
  return `${apiUrl}${path}`;
121
239
  const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
122
- return url.replace("{workspaceId}", pathParams.workspace);
240
+ return url.replace("{workspaceId}", String(pathParams.workspace));
123
241
  }
124
242
  function hostHeader(url) {
125
243
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -136,32 +254,61 @@ async function fetch$1({
136
254
  fetchImpl,
137
255
  apiKey,
138
256
  apiUrl,
139
- workspacesApiUrl
257
+ workspacesApiUrl,
258
+ trace
140
259
  }) {
141
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
142
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
143
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
144
- const response = await fetchImpl(url, {
145
- method: method.toUpperCase(),
146
- body: body ? JSON.stringify(body) : void 0,
147
- headers: {
148
- "Content-Type": "application/json",
149
- ...headers,
150
- ...hostHeader(fullUrl),
151
- Authorization: `Bearer ${apiKey}`
152
- }
153
- });
154
- if (response.status === 204) {
155
- return {};
156
- }
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) {
157
307
  try {
158
- const jsonResponse = await response.json();
159
- if (response.ok) {
160
- return jsonResponse;
161
- }
162
- throw new FetcherError(response.status, jsonResponse);
308
+ const { host, protocol } = new URL(url);
309
+ return { host, protocol };
163
310
  } catch (error) {
164
- throw new FetcherError(response.status, error);
311
+ return {};
165
312
  }
166
313
  }
167
314
 
@@ -220,6 +367,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
220
367
  ...variables
221
368
  });
222
369
  const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
370
+ const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
223
371
  const cancelWorkspaceMemberInvite = (variables) => fetch$1({
224
372
  url: "/workspaces/{workspaceId}/invites/{inviteId}",
225
373
  method: "delete",
@@ -255,6 +403,11 @@ const deleteDatabase = (variables) => fetch$1({
255
403
  method: "delete",
256
404
  ...variables
257
405
  });
406
+ const getDatabaseMetadata = (variables) => fetch$1({
407
+ url: "/dbs/{dbName}/metadata",
408
+ method: "get",
409
+ ...variables
410
+ });
258
411
  const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
259
412
  const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
260
413
  const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
@@ -263,16 +416,28 @@ const resolveBranch = (variables) => fetch$1({
263
416
  method: "get",
264
417
  ...variables
265
418
  });
266
- const getBranchDetails = (variables) => fetch$1({
267
- url: "/db/{dbBranchName}",
419
+ const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
420
+ const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
421
+ const getMigrationRequest = (variables) => fetch$1({
422
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
268
423
  method: "get",
269
424
  ...variables
270
425
  });
271
- const createBranch = (variables) => fetch$1({
426
+ const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
427
+ const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
428
+ const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
429
+ const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
430
+ const mergeMigrationRequest = (variables) => fetch$1({
431
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
432
+ method: "post",
433
+ ...variables
434
+ });
435
+ const getBranchDetails = (variables) => fetch$1({
272
436
  url: "/db/{dbBranchName}",
273
- method: "put",
437
+ method: "get",
274
438
  ...variables
275
439
  });
440
+ const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
276
441
  const deleteBranch = (variables) => fetch$1({
277
442
  url: "/db/{dbBranchName}",
278
443
  method: "delete",
@@ -291,6 +456,16 @@ const getBranchMetadata = (variables) => fetch$1({
291
456
  const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
292
457
  const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
293
458
  const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
459
+ const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
460
+ const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
461
+ const updateBranchSchema = (variables) => fetch$1({
462
+ url: "/db/{dbBranchName}/schema/update",
463
+ method: "post",
464
+ ...variables
465
+ });
466
+ const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
467
+ const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
468
+ const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
294
469
  const getBranchStats = (variables) => fetch$1({
295
470
  url: "/db/{dbBranchName}/stats",
296
471
  method: "get",
@@ -346,11 +521,7 @@ const updateColumn = (variables) => fetch$1({
346
521
  method: "patch",
347
522
  ...variables
348
523
  });
349
- const insertRecord = (variables) => fetch$1({
350
- url: "/db/{dbBranchName}/tables/{tableName}/data",
351
- method: "post",
352
- ...variables
353
- });
524
+ const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
354
525
  const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
355
526
  const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
356
527
  const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
@@ -370,6 +541,11 @@ const queryTable = (variables) => fetch$1({
370
541
  method: "post",
371
542
  ...variables
372
543
  });
544
+ const searchTable = (variables) => fetch$1({
545
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
546
+ method: "post",
547
+ ...variables
548
+ });
373
549
  const searchBranch = (variables) => fetch$1({
374
550
  url: "/db/{dbBranchName}/search",
375
551
  method: "post",
@@ -387,6 +563,7 @@ const operationsByTag = {
387
563
  updateWorkspaceMemberRole,
388
564
  removeWorkspaceMember,
389
565
  inviteWorkspaceMember,
566
+ updateWorkspaceMemberInvite,
390
567
  cancelWorkspaceMemberInvite,
391
568
  resendWorkspaceMemberInvite,
392
569
  acceptWorkspaceMemberInvite
@@ -395,6 +572,7 @@ const operationsByTag = {
395
572
  getDatabaseList,
396
573
  createDatabase,
397
574
  deleteDatabase,
575
+ getDatabaseMetadata,
398
576
  getGitBranchesMapping,
399
577
  addGitBranchesEntry,
400
578
  removeGitBranchesEntry,
@@ -407,10 +585,28 @@ const operationsByTag = {
407
585
  deleteBranch,
408
586
  updateBranchMetadata,
409
587
  getBranchMetadata,
588
+ getBranchStats
589
+ },
590
+ migrationRequests: {
591
+ listMigrationRequests,
592
+ createMigrationRequest,
593
+ getMigrationRequest,
594
+ updateMigrationRequest,
595
+ listMigrationRequestsCommits,
596
+ compareMigrationRequest,
597
+ getMigrationRequestIsMerged,
598
+ mergeMigrationRequest
599
+ },
600
+ branchSchema: {
410
601
  getBranchMigrationHistory,
411
602
  executeBranchMigrationPlan,
412
603
  getBranchMigrationPlan,
413
- getBranchStats
604
+ compareBranchWithUserSchema,
605
+ compareBranchSchemas,
606
+ updateBranchSchema,
607
+ previewBranchSchemaEdit,
608
+ applyBranchSchemaEdit,
609
+ getBranchSchemaHistory
414
610
  },
415
611
  table: {
416
612
  createTable,
@@ -433,14 +629,15 @@ const operationsByTag = {
433
629
  getRecord,
434
630
  bulkInsertTableRecords,
435
631
  queryTable,
632
+ searchTable,
436
633
  searchBranch
437
634
  }
438
635
  };
439
636
 
440
637
  function getHostUrl(provider, type) {
441
- if (isValidAlias(provider)) {
638
+ if (isHostProviderAlias(provider)) {
442
639
  return providers[provider][type];
443
- } else if (isValidBuilder(provider)) {
640
+ } else if (isHostProviderBuilder(provider)) {
444
641
  return provider[type];
445
642
  }
446
643
  throw new Error("Invalid API provider");
@@ -455,10 +652,10 @@ const providers = {
455
652
  workspaces: "https://{workspaceId}.staging.xatabase.co"
456
653
  }
457
654
  };
458
- function isValidAlias(alias) {
655
+ function isHostProviderAlias(alias) {
459
656
  return isString(alias) && Object.keys(providers).includes(alias);
460
657
  }
461
- function isValidBuilder(builder) {
658
+ function isHostProviderBuilder(builder) {
462
659
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
463
660
  }
464
661
 
@@ -466,7 +663,7 @@ var __accessCheck$7 = (obj, member, msg) => {
466
663
  if (!member.has(obj))
467
664
  throw TypeError("Cannot " + msg);
468
665
  };
469
- var __privateGet$6 = (obj, member, getter) => {
666
+ var __privateGet$7 = (obj, member, getter) => {
470
667
  __accessCheck$7(obj, member, "read from private field");
471
668
  return getter ? getter.call(obj) : member.get(obj);
472
669
  };
@@ -475,7 +672,7 @@ var __privateAdd$7 = (obj, member, value) => {
475
672
  throw TypeError("Cannot add the same private member more than once");
476
673
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
477
674
  };
478
- var __privateSet$5 = (obj, member, value, setter) => {
675
+ var __privateSet$7 = (obj, member, value, setter) => {
479
676
  __accessCheck$7(obj, member, "write to private field");
480
677
  setter ? setter.call(obj, value) : member.set(obj, value);
481
678
  return value;
@@ -486,46 +683,58 @@ class XataApiClient {
486
683
  __privateAdd$7(this, _extraProps, void 0);
487
684
  __privateAdd$7(this, _namespaces, {});
488
685
  const provider = options.host ?? "production";
489
- const apiKey = options?.apiKey ?? getAPIKey();
686
+ const apiKey = options.apiKey ?? getAPIKey();
687
+ const trace = options.trace ?? defaultTrace;
490
688
  if (!apiKey) {
491
689
  throw new Error("Could not resolve a valid apiKey");
492
690
  }
493
- __privateSet$5(this, _extraProps, {
691
+ __privateSet$7(this, _extraProps, {
494
692
  apiUrl: getHostUrl(provider, "main"),
495
693
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
496
694
  fetchImpl: getFetchImplementation(options.fetch),
497
- apiKey
695
+ apiKey,
696
+ trace
498
697
  });
499
698
  }
500
699
  get user() {
501
- if (!__privateGet$6(this, _namespaces).user)
502
- __privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
503
- return __privateGet$6(this, _namespaces).user;
700
+ if (!__privateGet$7(this, _namespaces).user)
701
+ __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
702
+ return __privateGet$7(this, _namespaces).user;
504
703
  }
505
704
  get workspaces() {
506
- if (!__privateGet$6(this, _namespaces).workspaces)
507
- __privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
508
- return __privateGet$6(this, _namespaces).workspaces;
705
+ if (!__privateGet$7(this, _namespaces).workspaces)
706
+ __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
707
+ return __privateGet$7(this, _namespaces).workspaces;
509
708
  }
510
709
  get databases() {
511
- if (!__privateGet$6(this, _namespaces).databases)
512
- __privateGet$6(this, _namespaces).databases = new DatabaseApi(__privateGet$6(this, _extraProps));
513
- return __privateGet$6(this, _namespaces).databases;
710
+ if (!__privateGet$7(this, _namespaces).databases)
711
+ __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
712
+ return __privateGet$7(this, _namespaces).databases;
514
713
  }
515
714
  get branches() {
516
- if (!__privateGet$6(this, _namespaces).branches)
517
- __privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
518
- return __privateGet$6(this, _namespaces).branches;
715
+ if (!__privateGet$7(this, _namespaces).branches)
716
+ __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
717
+ return __privateGet$7(this, _namespaces).branches;
519
718
  }
520
719
  get tables() {
521
- if (!__privateGet$6(this, _namespaces).tables)
522
- __privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
523
- return __privateGet$6(this, _namespaces).tables;
720
+ if (!__privateGet$7(this, _namespaces).tables)
721
+ __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
722
+ return __privateGet$7(this, _namespaces).tables;
524
723
  }
525
724
  get records() {
526
- if (!__privateGet$6(this, _namespaces).records)
527
- __privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
528
- return __privateGet$6(this, _namespaces).records;
725
+ if (!__privateGet$7(this, _namespaces).records)
726
+ __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
727
+ return __privateGet$7(this, _namespaces).records;
728
+ }
729
+ get migrationRequests() {
730
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
731
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
732
+ return __privateGet$7(this, _namespaces).migrationRequests;
733
+ }
734
+ get branchSchema() {
735
+ if (!__privateGet$7(this, _namespaces).branchSchema)
736
+ __privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
737
+ return __privateGet$7(this, _namespaces).branchSchema;
529
738
  }
530
739
  }
531
740
  _extraProps = new WeakMap();
@@ -617,6 +826,13 @@ class WorkspaceApi {
617
826
  ...this.extraProps
618
827
  });
619
828
  }
829
+ updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
830
+ return operationsByTag.workspaces.updateWorkspaceMemberInvite({
831
+ pathParams: { workspaceId, inviteId },
832
+ body: { role },
833
+ ...this.extraProps
834
+ });
835
+ }
620
836
  cancelWorkspaceMemberInvite(workspaceId, inviteId) {
621
837
  return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
622
838
  pathParams: { workspaceId, inviteId },
@@ -659,6 +875,12 @@ class DatabaseApi {
659
875
  ...this.extraProps
660
876
  });
661
877
  }
878
+ getDatabaseMetadata(workspace, dbName) {
879
+ return operationsByTag.database.getDatabaseMetadata({
880
+ pathParams: { workspace, dbName },
881
+ ...this.extraProps
882
+ });
883
+ }
662
884
  getGitBranchesMapping(workspace, dbName) {
663
885
  return operationsByTag.database.getGitBranchesMapping({
664
886
  pathParams: { workspace, dbName },
@@ -679,10 +901,10 @@ class DatabaseApi {
679
901
  ...this.extraProps
680
902
  });
681
903
  }
682
- resolveBranch(workspace, dbName, gitBranch) {
904
+ resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
683
905
  return operationsByTag.database.resolveBranch({
684
906
  pathParams: { workspace, dbName },
685
- queryParams: { gitBranch },
907
+ queryParams: { gitBranch, fallbackBranch },
686
908
  ...this.extraProps
687
909
  });
688
910
  }
@@ -703,10 +925,10 @@ class BranchApi {
703
925
  ...this.extraProps
704
926
  });
705
927
  }
706
- createBranch(workspace, database, branch, from = "", options = {}) {
928
+ createBranch(workspace, database, branch, from, options = {}) {
707
929
  return operationsByTag.branch.createBranch({
708
930
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
709
- queryParams: { from },
931
+ queryParams: isString(from) ? { from } : void 0,
710
932
  body: options,
711
933
  ...this.extraProps
712
934
  });
@@ -730,27 +952,6 @@ class BranchApi {
730
952
  ...this.extraProps
731
953
  });
732
954
  }
733
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
734
- return operationsByTag.branch.getBranchMigrationHistory({
735
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
736
- body: options,
737
- ...this.extraProps
738
- });
739
- }
740
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
741
- return operationsByTag.branch.executeBranchMigrationPlan({
742
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
743
- body: migrationPlan,
744
- ...this.extraProps
745
- });
746
- }
747
- getBranchMigrationPlan(workspace, database, branch, schema) {
748
- return operationsByTag.branch.getBranchMigrationPlan({
749
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
750
- body: schema,
751
- ...this.extraProps
752
- });
753
- }
754
955
  getBranchStats(workspace, database, branch) {
755
956
  return operationsByTag.branch.getBranchStats({
756
957
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -831,9 +1032,10 @@ class RecordsApi {
831
1032
  constructor(extraProps) {
832
1033
  this.extraProps = extraProps;
833
1034
  }
834
- insertRecord(workspace, database, branch, tableName, record) {
1035
+ insertRecord(workspace, database, branch, tableName, record, options = {}) {
835
1036
  return operationsByTag.records.insertRecord({
836
1037
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1038
+ queryParams: options,
837
1039
  body: record,
838
1040
  ...this.extraProps
839
1041
  });
@@ -862,21 +1064,24 @@ class RecordsApi {
862
1064
  ...this.extraProps
863
1065
  });
864
1066
  }
865
- deleteRecord(workspace, database, branch, tableName, recordId) {
1067
+ deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
866
1068
  return operationsByTag.records.deleteRecord({
867
1069
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1070
+ queryParams: options,
868
1071
  ...this.extraProps
869
1072
  });
870
1073
  }
871
1074
  getRecord(workspace, database, branch, tableName, recordId, options = {}) {
872
1075
  return operationsByTag.records.getRecord({
873
1076
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1077
+ queryParams: options,
874
1078
  ...this.extraProps
875
1079
  });
876
1080
  }
877
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
1081
+ bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
878
1082
  return operationsByTag.records.bulkInsertTableRecords({
879
1083
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1084
+ queryParams: options,
880
1085
  body: { records },
881
1086
  ...this.extraProps
882
1087
  });
@@ -888,6 +1093,13 @@ class RecordsApi {
888
1093
  ...this.extraProps
889
1094
  });
890
1095
  }
1096
+ searchTable(workspace, database, branch, tableName, query) {
1097
+ return operationsByTag.records.searchTable({
1098
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1099
+ body: query,
1100
+ ...this.extraProps
1101
+ });
1102
+ }
891
1103
  searchBranch(workspace, database, branch, query) {
892
1104
  return operationsByTag.records.searchBranch({
893
1105
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -896,6 +1108,131 @@ class RecordsApi {
896
1108
  });
897
1109
  }
898
1110
  }
1111
+ class MigrationRequestsApi {
1112
+ constructor(extraProps) {
1113
+ this.extraProps = extraProps;
1114
+ }
1115
+ listMigrationRequests(workspace, database, options = {}) {
1116
+ return operationsByTag.migrationRequests.listMigrationRequests({
1117
+ pathParams: { workspace, dbName: database },
1118
+ body: options,
1119
+ ...this.extraProps
1120
+ });
1121
+ }
1122
+ createMigrationRequest(workspace, database, options) {
1123
+ return operationsByTag.migrationRequests.createMigrationRequest({
1124
+ pathParams: { workspace, dbName: database },
1125
+ body: options,
1126
+ ...this.extraProps
1127
+ });
1128
+ }
1129
+ getMigrationRequest(workspace, database, migrationRequest) {
1130
+ return operationsByTag.migrationRequests.getMigrationRequest({
1131
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1132
+ ...this.extraProps
1133
+ });
1134
+ }
1135
+ updateMigrationRequest(workspace, database, migrationRequest, options) {
1136
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1137
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1138
+ body: options,
1139
+ ...this.extraProps
1140
+ });
1141
+ }
1142
+ listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
1143
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1144
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1145
+ body: options,
1146
+ ...this.extraProps
1147
+ });
1148
+ }
1149
+ compareMigrationRequest(workspace, database, migrationRequest) {
1150
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1151
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1152
+ ...this.extraProps
1153
+ });
1154
+ }
1155
+ getMigrationRequestIsMerged(workspace, database, migrationRequest) {
1156
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1157
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1158
+ ...this.extraProps
1159
+ });
1160
+ }
1161
+ mergeMigrationRequest(workspace, database, migrationRequest) {
1162
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1163
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1164
+ ...this.extraProps
1165
+ });
1166
+ }
1167
+ }
1168
+ class BranchSchemaApi {
1169
+ constructor(extraProps) {
1170
+ this.extraProps = extraProps;
1171
+ }
1172
+ getBranchMigrationHistory(workspace, database, branch, options = {}) {
1173
+ return operationsByTag.branchSchema.getBranchMigrationHistory({
1174
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1175
+ body: options,
1176
+ ...this.extraProps
1177
+ });
1178
+ }
1179
+ executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
1180
+ return operationsByTag.branchSchema.executeBranchMigrationPlan({
1181
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1182
+ body: migrationPlan,
1183
+ ...this.extraProps
1184
+ });
1185
+ }
1186
+ getBranchMigrationPlan(workspace, database, branch, schema) {
1187
+ return operationsByTag.branchSchema.getBranchMigrationPlan({
1188
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1189
+ body: schema,
1190
+ ...this.extraProps
1191
+ });
1192
+ }
1193
+ compareBranchWithUserSchema(workspace, database, branch, schema) {
1194
+ return operationsByTag.branchSchema.compareBranchWithUserSchema({
1195
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1196
+ body: { schema },
1197
+ ...this.extraProps
1198
+ });
1199
+ }
1200
+ compareBranchSchemas(workspace, database, branch, branchName, schema) {
1201
+ return operationsByTag.branchSchema.compareBranchSchemas({
1202
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
1203
+ body: { schema },
1204
+ ...this.extraProps
1205
+ });
1206
+ }
1207
+ updateBranchSchema(workspace, database, branch, migration) {
1208
+ return operationsByTag.branchSchema.updateBranchSchema({
1209
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1210
+ body: migration,
1211
+ ...this.extraProps
1212
+ });
1213
+ }
1214
+ previewBranchSchemaEdit(workspace, database, branch, migration) {
1215
+ return operationsByTag.branchSchema.previewBranchSchemaEdit({
1216
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1217
+ body: migration,
1218
+ ...this.extraProps
1219
+ });
1220
+ }
1221
+ applyBranchSchemaEdit(workspace, database, branch, edits) {
1222
+ return operationsByTag.branchSchema.applyBranchSchemaEdit({
1223
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1224
+ body: { edits },
1225
+ ...this.extraProps
1226
+ });
1227
+ }
1228
+ getBranchSchemaHistory(workspace, database, branch, options = {}) {
1229
+ return operationsByTag.branchSchema.getBranchSchemaHistory({
1230
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1231
+ body: options,
1232
+ ...this.extraProps
1233
+ });
1234
+ }
1235
+ }
899
1236
 
900
1237
  class XataApiPlugin {
901
1238
  async build(options) {
@@ -911,7 +1248,7 @@ var __accessCheck$6 = (obj, member, msg) => {
911
1248
  if (!member.has(obj))
912
1249
  throw TypeError("Cannot " + msg);
913
1250
  };
914
- var __privateGet$5 = (obj, member, getter) => {
1251
+ var __privateGet$6 = (obj, member, getter) => {
915
1252
  __accessCheck$6(obj, member, "read from private field");
916
1253
  return getter ? getter.call(obj) : member.get(obj);
917
1254
  };
@@ -920,30 +1257,30 @@ var __privateAdd$6 = (obj, member, value) => {
920
1257
  throw TypeError("Cannot add the same private member more than once");
921
1258
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
922
1259
  };
923
- var __privateSet$4 = (obj, member, value, setter) => {
1260
+ var __privateSet$6 = (obj, member, value, setter) => {
924
1261
  __accessCheck$6(obj, member, "write to private field");
925
1262
  setter ? setter.call(obj, value) : member.set(obj, value);
926
1263
  return value;
927
1264
  };
928
- var _query;
1265
+ var _query, _page;
929
1266
  class Page {
930
1267
  constructor(query, meta, records = []) {
931
1268
  __privateAdd$6(this, _query, void 0);
932
- __privateSet$4(this, _query, query);
1269
+ __privateSet$6(this, _query, query);
933
1270
  this.meta = meta;
934
- this.records = records;
1271
+ this.records = new RecordArray(this, records);
935
1272
  }
936
1273
  async nextPage(size, offset) {
937
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
1274
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
938
1275
  }
939
1276
  async previousPage(size, offset) {
940
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
1277
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
941
1278
  }
942
1279
  async firstPage(size, offset) {
943
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
1280
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
944
1281
  }
945
1282
  async lastPage(size, offset) {
946
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
1283
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
947
1284
  }
948
1285
  hasNextPage() {
949
1286
  return this.meta.page.more;
@@ -951,15 +1288,62 @@ class Page {
951
1288
  }
952
1289
  _query = new WeakMap();
953
1290
  const PAGINATION_MAX_SIZE = 200;
954
- const PAGINATION_DEFAULT_SIZE = 200;
1291
+ const PAGINATION_DEFAULT_SIZE = 20;
955
1292
  const PAGINATION_MAX_OFFSET = 800;
956
1293
  const PAGINATION_DEFAULT_OFFSET = 0;
1294
+ function isCursorPaginationOptions(options) {
1295
+ return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1296
+ }
1297
+ const _RecordArray = class extends Array {
1298
+ constructor(...args) {
1299
+ super(..._RecordArray.parseConstructorParams(...args));
1300
+ __privateAdd$6(this, _page, void 0);
1301
+ __privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
1302
+ }
1303
+ static parseConstructorParams(...args) {
1304
+ if (args.length === 1 && typeof args[0] === "number") {
1305
+ return new Array(args[0]);
1306
+ }
1307
+ if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
1308
+ const result = args[1] ?? args[0].records ?? [];
1309
+ return new Array(...result);
1310
+ }
1311
+ return new Array(...args);
1312
+ }
1313
+ toArray() {
1314
+ return new Array(...this);
1315
+ }
1316
+ map(callbackfn, thisArg) {
1317
+ return this.toArray().map(callbackfn, thisArg);
1318
+ }
1319
+ async nextPage(size, offset) {
1320
+ const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1321
+ return new _RecordArray(newPage);
1322
+ }
1323
+ async previousPage(size, offset) {
1324
+ const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1325
+ return new _RecordArray(newPage);
1326
+ }
1327
+ async firstPage(size, offset) {
1328
+ const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1329
+ return new _RecordArray(newPage);
1330
+ }
1331
+ async lastPage(size, offset) {
1332
+ const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1333
+ return new _RecordArray(newPage);
1334
+ }
1335
+ hasNextPage() {
1336
+ return __privateGet$6(this, _page).meta.page.more;
1337
+ }
1338
+ };
1339
+ let RecordArray = _RecordArray;
1340
+ _page = new WeakMap();
957
1341
 
958
1342
  var __accessCheck$5 = (obj, member, msg) => {
959
1343
  if (!member.has(obj))
960
1344
  throw TypeError("Cannot " + msg);
961
1345
  };
962
- var __privateGet$4 = (obj, member, getter) => {
1346
+ var __privateGet$5 = (obj, member, getter) => {
963
1347
  __accessCheck$5(obj, member, "read from private field");
964
1348
  return getter ? getter.call(obj) : member.get(obj);
965
1349
  };
@@ -968,34 +1352,35 @@ var __privateAdd$5 = (obj, member, value) => {
968
1352
  throw TypeError("Cannot add the same private member more than once");
969
1353
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
970
1354
  };
971
- var __privateSet$3 = (obj, member, value, setter) => {
1355
+ var __privateSet$5 = (obj, member, value, setter) => {
972
1356
  __accessCheck$5(obj, member, "write to private field");
973
1357
  setter ? setter.call(obj, value) : member.set(obj, value);
974
1358
  return value;
975
1359
  };
976
1360
  var _table$1, _repository, _data;
977
1361
  const _Query = class {
978
- constructor(repository, table, data, parent) {
1362
+ constructor(repository, table, data, rawParent) {
979
1363
  __privateAdd$5(this, _table$1, void 0);
980
1364
  __privateAdd$5(this, _repository, void 0);
981
1365
  __privateAdd$5(this, _data, { filter: {} });
982
1366
  this.meta = { page: { cursor: "start", more: true } };
983
- this.records = [];
984
- __privateSet$3(this, _table$1, table);
1367
+ this.records = new RecordArray(this, []);
1368
+ __privateSet$5(this, _table$1, table);
985
1369
  if (repository) {
986
- __privateSet$3(this, _repository, repository);
1370
+ __privateSet$5(this, _repository, repository);
987
1371
  } else {
988
- __privateSet$3(this, _repository, this);
1372
+ __privateSet$5(this, _repository, this);
989
1373
  }
990
- __privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
991
- __privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
992
- __privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
993
- __privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
994
- __privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
995
- __privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
996
- __privateGet$4(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
997
- __privateGet$4(this, _data).page = data.page ?? parent?.page;
998
- __privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
1374
+ const parent = cleanParent(data, rawParent);
1375
+ __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
1376
+ __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
1377
+ __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
1378
+ __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1379
+ __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1380
+ __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1381
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1382
+ __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1383
+ __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
999
1384
  this.any = this.any.bind(this);
1000
1385
  this.all = this.all.bind(this);
1001
1386
  this.not = this.not.bind(this);
@@ -1006,83 +1391,101 @@ const _Query = class {
1006
1391
  Object.defineProperty(this, "repository", { enumerable: false });
1007
1392
  }
1008
1393
  getQueryOptions() {
1009
- return __privateGet$4(this, _data);
1394
+ return __privateGet$5(this, _data);
1010
1395
  }
1011
1396
  key() {
1012
- const { columns = [], filter = {}, sort = [], page = {} } = __privateGet$4(this, _data);
1013
- const key = JSON.stringify({ columns, filter, sort, page });
1397
+ const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
1398
+ const key = JSON.stringify({ columns, filter, sort, pagination });
1014
1399
  return toBase64(key);
1015
1400
  }
1016
1401
  any(...queries) {
1017
1402
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
1018
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
1403
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
1019
1404
  }
1020
1405
  all(...queries) {
1021
1406
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
1022
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
1407
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1023
1408
  }
1024
1409
  not(...queries) {
1025
1410
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
1026
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
1411
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
1027
1412
  }
1028
1413
  none(...queries) {
1029
1414
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
1030
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
1415
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
1031
1416
  }
1032
1417
  filter(a, b) {
1033
1418
  if (arguments.length === 1) {
1034
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1035
- const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
1036
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
1419
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
1420
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1421
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1037
1422
  } else {
1038
- const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1039
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
1423
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
1424
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1425
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1426
+ }
1427
+ }
1428
+ defaultFilter(column, value) {
1429
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1430
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1431
+ return { $includes: value };
1040
1432
  }
1433
+ return value;
1041
1434
  }
1042
- sort(column, direction) {
1043
- const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
1435
+ sort(column, direction = "asc") {
1436
+ const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1044
1437
  const sort = [...originalSort, { column, direction }];
1045
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
1438
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
1046
1439
  }
1047
1440
  select(columns) {
1048
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { columns }, __privateGet$4(this, _data));
1441
+ return new _Query(
1442
+ __privateGet$5(this, _repository),
1443
+ __privateGet$5(this, _table$1),
1444
+ { columns },
1445
+ __privateGet$5(this, _data)
1446
+ );
1049
1447
  }
1050
1448
  getPaginated(options = {}) {
1051
- const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
1052
- return __privateGet$4(this, _repository).query(query);
1449
+ const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
1450
+ return __privateGet$5(this, _repository).query(query);
1053
1451
  }
1054
1452
  async *[Symbol.asyncIterator]() {
1055
- for await (const [record] of this.getIterator(1)) {
1453
+ for await (const [record] of this.getIterator({ batchSize: 1 })) {
1056
1454
  yield record;
1057
1455
  }
1058
1456
  }
1059
- async *getIterator(chunk, options = {}) {
1060
- let offset = 0;
1061
- let end = false;
1062
- while (!end) {
1063
- const { records, meta } = await this.getPaginated({ ...options, page: { size: chunk, offset } });
1064
- yield records;
1065
- offset += chunk;
1066
- end = !meta.page.more;
1457
+ async *getIterator(options = {}) {
1458
+ const { batchSize = 1 } = options;
1459
+ let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
1460
+ let more = page.hasNextPage();
1461
+ yield page.records;
1462
+ while (more) {
1463
+ page = await page.nextPage();
1464
+ more = page.hasNextPage();
1465
+ yield page.records;
1067
1466
  }
1068
1467
  }
1069
1468
  async getMany(options = {}) {
1070
- const { records } = await this.getPaginated(options);
1071
- return records;
1469
+ const page = await this.getPaginated(options);
1470
+ if (page.hasNextPage() && options.pagination?.size === void 0) {
1471
+ console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1472
+ }
1473
+ return page.records;
1072
1474
  }
1073
- async getAll(chunk = PAGINATION_MAX_SIZE, options = {}) {
1475
+ async getAll(options = {}) {
1476
+ const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
1074
1477
  const results = [];
1075
- for await (const page of this.getIterator(chunk, options)) {
1478
+ for await (const page of this.getIterator({ ...rest, batchSize })) {
1076
1479
  results.push(...page);
1077
1480
  }
1078
1481
  return results;
1079
1482
  }
1080
1483
  async getFirst(options = {}) {
1081
- const records = await this.getMany({ ...options, page: { size: 1 } });
1082
- return records[0] || null;
1484
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
1485
+ return records[0] ?? null;
1083
1486
  }
1084
1487
  cache(ttl) {
1085
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
1488
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1086
1489
  }
1087
1490
  nextPage(size, offset) {
1088
1491
  return this.firstPage(size, offset);
@@ -1091,10 +1494,10 @@ const _Query = class {
1091
1494
  return this.firstPage(size, offset);
1092
1495
  }
1093
1496
  firstPage(size, offset) {
1094
- return this.getPaginated({ page: { size, offset } });
1497
+ return this.getPaginated({ pagination: { size, offset } });
1095
1498
  }
1096
1499
  lastPage(size, offset) {
1097
- return this.getPaginated({ page: { size, offset, before: "end" } });
1500
+ return this.getPaginated({ pagination: { size, offset, before: "end" } });
1098
1501
  }
1099
1502
  hasNextPage() {
1100
1503
  return this.meta.page.more;
@@ -1104,12 +1507,20 @@ let Query = _Query;
1104
1507
  _table$1 = new WeakMap();
1105
1508
  _repository = new WeakMap();
1106
1509
  _data = new WeakMap();
1510
+ function cleanParent(data, parent) {
1511
+ if (isCursorPaginationOptions(data.pagination)) {
1512
+ return { ...parent, sorting: void 0, filter: void 0 };
1513
+ }
1514
+ return parent;
1515
+ }
1107
1516
 
1108
1517
  function isIdentifiable(x) {
1109
1518
  return isObject(x) && isString(x?.id);
1110
1519
  }
1111
1520
  function isXataRecord(x) {
1112
- return isIdentifiable(x) && typeof x?.xata === "object" && typeof x?.xata?.version === "number";
1521
+ const record = x;
1522
+ const metadata = record?.getMetadata();
1523
+ return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
1113
1524
  }
1114
1525
 
1115
1526
  function isSortFilterString(value) {
@@ -1139,7 +1550,7 @@ var __accessCheck$4 = (obj, member, msg) => {
1139
1550
  if (!member.has(obj))
1140
1551
  throw TypeError("Cannot " + msg);
1141
1552
  };
1142
- var __privateGet$3 = (obj, member, getter) => {
1553
+ var __privateGet$4 = (obj, member, getter) => {
1143
1554
  __accessCheck$4(obj, member, "read from private field");
1144
1555
  return getter ? getter.call(obj) : member.get(obj);
1145
1556
  };
@@ -1148,7 +1559,7 @@ var __privateAdd$4 = (obj, member, value) => {
1148
1559
  throw TypeError("Cannot add the same private member more than once");
1149
1560
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1150
1561
  };
1151
- var __privateSet$2 = (obj, member, value, setter) => {
1562
+ var __privateSet$4 = (obj, member, value, setter) => {
1152
1563
  __accessCheck$4(obj, member, "write to private field");
1153
1564
  setter ? setter.call(obj, value) : member.set(obj, value);
1154
1565
  return value;
@@ -1157,304 +1568,355 @@ var __privateMethod$2 = (obj, member, method) => {
1157
1568
  __accessCheck$4(obj, member, "access private method");
1158
1569
  return method;
1159
1570
  };
1160
- var _table, _links, _getFetchProps, _cache, _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;
1571
+ 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;
1161
1572
  class Repository extends Query {
1162
1573
  }
1163
1574
  class RestRepository extends Query {
1164
1575
  constructor(options) {
1165
- super(null, options.table, {});
1576
+ super(
1577
+ null,
1578
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
1579
+ {}
1580
+ );
1166
1581
  __privateAdd$4(this, _insertRecordWithoutId);
1167
1582
  __privateAdd$4(this, _insertRecordWithId);
1168
1583
  __privateAdd$4(this, _bulkInsertTableRecords);
1169
1584
  __privateAdd$4(this, _updateRecordWithID);
1170
1585
  __privateAdd$4(this, _upsertRecordWithID);
1171
1586
  __privateAdd$4(this, _deleteRecord);
1172
- __privateAdd$4(this, _invalidateCache);
1173
- __privateAdd$4(this, _setCacheRecord);
1174
- __privateAdd$4(this, _getCacheRecord);
1175
1587
  __privateAdd$4(this, _setCacheQuery);
1176
1588
  __privateAdd$4(this, _getCacheQuery);
1589
+ __privateAdd$4(this, _getSchemaTables$1);
1177
1590
  __privateAdd$4(this, _table, void 0);
1178
- __privateAdd$4(this, _links, void 0);
1179
1591
  __privateAdd$4(this, _getFetchProps, void 0);
1592
+ __privateAdd$4(this, _db, void 0);
1180
1593
  __privateAdd$4(this, _cache, void 0);
1181
- __privateSet$2(this, _table, options.table);
1182
- __privateSet$2(this, _links, options.links ?? {});
1183
- __privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
1184
- this.db = options.db;
1185
- __privateSet$2(this, _cache, options.pluginOptions.cache);
1186
- }
1187
- async create(a, b) {
1188
- if (Array.isArray(a)) {
1189
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1190
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1191
- return records;
1192
- }
1193
- if (isString(a) && isObject(b)) {
1194
- if (a === "")
1195
- throw new Error("The id can't be empty");
1196
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1197
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1198
- return record;
1199
- }
1200
- if (isObject(a) && isString(a.id)) {
1201
- if (a.id === "")
1202
- throw new Error("The id can't be empty");
1203
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1204
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1205
- return record;
1206
- }
1207
- if (isObject(a)) {
1208
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1209
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1210
- return record;
1211
- }
1212
- throw new Error("Invalid arguments for create method");
1213
- }
1214
- async read(recordId) {
1215
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1216
- if (cacheRecord)
1217
- return cacheRecord;
1218
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1219
- try {
1220
- const response = await getRecord({
1221
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1222
- ...fetchProps
1594
+ __privateAdd$4(this, _schemaTables$2, void 0);
1595
+ __privateAdd$4(this, _trace, void 0);
1596
+ __privateSet$4(this, _table, options.table);
1597
+ __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1598
+ __privateSet$4(this, _db, options.db);
1599
+ __privateSet$4(this, _cache, options.pluginOptions.cache);
1600
+ __privateSet$4(this, _schemaTables$2, options.schemaTables);
1601
+ const trace = options.pluginOptions.trace ?? defaultTrace;
1602
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1603
+ return trace(name, fn, {
1604
+ ...options2,
1605
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1606
+ [TraceAttributes.KIND]: "sdk-operation",
1607
+ [TraceAttributes.VERSION]: VERSION
1223
1608
  });
1224
- return initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), response);
1225
- } catch (e) {
1226
- if (isObject(e) && e.status === 404) {
1227
- return null;
1609
+ });
1610
+ }
1611
+ async create(a, b, c) {
1612
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
1613
+ if (Array.isArray(a)) {
1614
+ if (a.length === 0)
1615
+ return [];
1616
+ const columns = isStringArray(b) ? b : void 0;
1617
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1228
1618
  }
1229
- throw e;
1230
- }
1619
+ if (isString(a) && isObject(b)) {
1620
+ if (a === "")
1621
+ throw new Error("The id can't be empty");
1622
+ const columns = isStringArray(c) ? c : void 0;
1623
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1624
+ }
1625
+ if (isObject(a) && isString(a.id)) {
1626
+ if (a.id === "")
1627
+ throw new Error("The id can't be empty");
1628
+ const columns = isStringArray(b) ? b : void 0;
1629
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1630
+ }
1631
+ if (isObject(a)) {
1632
+ const columns = isStringArray(b) ? b : void 0;
1633
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1634
+ }
1635
+ throw new Error("Invalid arguments for create method");
1636
+ });
1231
1637
  }
1232
- async update(a, b) {
1233
- if (Array.isArray(a)) {
1234
- if (a.length > 100) {
1235
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1638
+ async read(a, b) {
1639
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
1640
+ const columns = isStringArray(b) ? b : ["*"];
1641
+ if (Array.isArray(a)) {
1642
+ if (a.length === 0)
1643
+ return [];
1644
+ const ids = a.map((item) => extractId(item));
1645
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
1646
+ const dictionary = finalObjects.reduce((acc, object) => {
1647
+ acc[object.id] = object;
1648
+ return acc;
1649
+ }, {});
1650
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1236
1651
  }
1237
- return Promise.all(a.map((object) => this.update(object)));
1238
- }
1239
- if (isString(a) && isObject(b)) {
1240
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1241
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1242
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1243
- return record;
1244
- }
1245
- if (isObject(a) && isString(a.id)) {
1246
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1247
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1248
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1249
- return record;
1250
- }
1251
- throw new Error("Invalid arguments for update method");
1652
+ const id = extractId(a);
1653
+ if (id) {
1654
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1655
+ try {
1656
+ const response = await getRecord({
1657
+ pathParams: {
1658
+ workspace: "{workspaceId}",
1659
+ dbBranchName: "{dbBranch}",
1660
+ tableName: __privateGet$4(this, _table),
1661
+ recordId: id
1662
+ },
1663
+ queryParams: { columns },
1664
+ ...fetchProps
1665
+ });
1666
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1667
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1668
+ } catch (e) {
1669
+ if (isObject(e) && e.status === 404) {
1670
+ return null;
1671
+ }
1672
+ throw e;
1673
+ }
1674
+ }
1675
+ return null;
1676
+ });
1252
1677
  }
1253
- async createOrUpdate(a, b) {
1254
- if (Array.isArray(a)) {
1255
- if (a.length > 100) {
1256
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1678
+ async update(a, b, c) {
1679
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
1680
+ if (Array.isArray(a)) {
1681
+ if (a.length === 0)
1682
+ return [];
1683
+ if (a.length > 100) {
1684
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1685
+ }
1686
+ const columns = isStringArray(b) ? b : ["*"];
1687
+ return Promise.all(a.map((object) => this.update(object, columns)));
1257
1688
  }
1258
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1259
- }
1260
- if (isString(a) && isObject(b)) {
1261
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1262
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1263
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1264
- return record;
1265
- }
1266
- if (isObject(a) && isString(a.id)) {
1267
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1268
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1269
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1270
- return record;
1271
- }
1272
- throw new Error("Invalid arguments for createOrUpdate method");
1689
+ if (isString(a) && isObject(b)) {
1690
+ const columns = isStringArray(c) ? c : void 0;
1691
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1692
+ }
1693
+ if (isObject(a) && isString(a.id)) {
1694
+ const columns = isStringArray(b) ? b : void 0;
1695
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1696
+ }
1697
+ throw new Error("Invalid arguments for update method");
1698
+ });
1273
1699
  }
1274
- async delete(a) {
1275
- if (Array.isArray(a)) {
1276
- if (a.length > 100) {
1277
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1700
+ async createOrUpdate(a, b, c) {
1701
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1702
+ if (Array.isArray(a)) {
1703
+ if (a.length === 0)
1704
+ return [];
1705
+ if (a.length > 100) {
1706
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1707
+ }
1708
+ const columns = isStringArray(b) ? b : ["*"];
1709
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1278
1710
  }
1279
- await Promise.all(a.map((id) => this.delete(id)));
1280
- return;
1281
- }
1282
- if (isString(a)) {
1283
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1284
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1285
- return;
1286
- }
1287
- if (isObject(a) && isString(a.id)) {
1288
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1289
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1290
- return;
1291
- }
1292
- throw new Error("Invalid arguments for delete method");
1711
+ if (isString(a) && isObject(b)) {
1712
+ const columns = isStringArray(c) ? c : void 0;
1713
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1714
+ }
1715
+ if (isObject(a) && isString(a.id)) {
1716
+ const columns = isStringArray(c) ? c : void 0;
1717
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1718
+ }
1719
+ throw new Error("Invalid arguments for createOrUpdate method");
1720
+ });
1721
+ }
1722
+ async delete(a, b) {
1723
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
1724
+ if (Array.isArray(a)) {
1725
+ if (a.length === 0)
1726
+ return [];
1727
+ if (a.length > 100) {
1728
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1729
+ }
1730
+ return Promise.all(a.map((id) => this.delete(id, b)));
1731
+ }
1732
+ if (isString(a)) {
1733
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1734
+ }
1735
+ if (isObject(a) && isString(a.id)) {
1736
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1737
+ }
1738
+ throw new Error("Invalid arguments for delete method");
1739
+ });
1293
1740
  }
1294
1741
  async search(query, options = {}) {
1295
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1296
- const { records } = await searchBranch({
1297
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1298
- body: { tables: [__privateGet$3(this, _table)], query, fuzziness: options.fuzziness },
1299
- ...fetchProps
1742
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
1743
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1744
+ const { records } = await searchTable({
1745
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1746
+ body: {
1747
+ query,
1748
+ fuzziness: options.fuzziness,
1749
+ prefix: options.prefix,
1750
+ highlight: options.highlight,
1751
+ filter: options.filter,
1752
+ boosters: options.boosters
1753
+ },
1754
+ ...fetchProps
1755
+ });
1756
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1757
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1300
1758
  });
1301
- return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
1302
1759
  }
1303
1760
  async query(query) {
1304
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1305
- if (cacheQuery)
1306
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1307
- const data = query.getQueryOptions();
1308
- const body = {
1309
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1310
- sort: data.sort ? buildSortFilter(data.sort) : void 0,
1311
- page: data.page,
1312
- columns: data.columns
1313
- };
1314
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1315
- const { meta, records: objects } = await queryTable({
1316
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1317
- body,
1318
- ...fetchProps
1761
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
1762
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1763
+ if (cacheQuery)
1764
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1765
+ const data = query.getQueryOptions();
1766
+ const body = {
1767
+ filter: cleanFilter(data.filter),
1768
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1769
+ page: data.pagination,
1770
+ columns: data.columns
1771
+ };
1772
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1773
+ const { meta, records: objects } = await queryTable({
1774
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1775
+ body,
1776
+ ...fetchProps
1777
+ });
1778
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1779
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1780
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1781
+ return new Page(query, meta, records);
1319
1782
  });
1320
- const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
1321
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1322
- return new Page(query, meta, records);
1323
1783
  }
1324
1784
  }
1325
1785
  _table = new WeakMap();
1326
- _links = new WeakMap();
1327
1786
  _getFetchProps = new WeakMap();
1787
+ _db = new WeakMap();
1328
1788
  _cache = new WeakMap();
1789
+ _schemaTables$2 = new WeakMap();
1790
+ _trace = new WeakMap();
1329
1791
  _insertRecordWithoutId = new WeakSet();
1330
- insertRecordWithoutId_fn = async function(object) {
1331
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1792
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1793
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1332
1794
  const record = transformObjectLinks(object);
1333
1795
  const response = await insertRecord({
1334
1796
  pathParams: {
1335
1797
  workspace: "{workspaceId}",
1336
1798
  dbBranchName: "{dbBranch}",
1337
- tableName: __privateGet$3(this, _table)
1799
+ tableName: __privateGet$4(this, _table)
1338
1800
  },
1801
+ queryParams: { columns },
1339
1802
  body: record,
1340
1803
  ...fetchProps
1341
1804
  });
1342
- const finalObject = await this.read(response.id);
1343
- if (!finalObject) {
1344
- throw new Error("The server failed to save the record");
1345
- }
1346
- return finalObject;
1805
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1806
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1347
1807
  };
1348
1808
  _insertRecordWithId = new WeakSet();
1349
- insertRecordWithId_fn = async function(recordId, object) {
1350
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1809
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1810
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1351
1811
  const record = transformObjectLinks(object);
1352
1812
  const response = await insertRecordWithID({
1353
1813
  pathParams: {
1354
1814
  workspace: "{workspaceId}",
1355
1815
  dbBranchName: "{dbBranch}",
1356
- tableName: __privateGet$3(this, _table),
1816
+ tableName: __privateGet$4(this, _table),
1357
1817
  recordId
1358
1818
  },
1359
1819
  body: record,
1360
- queryParams: { createOnly: true },
1820
+ queryParams: { createOnly: true, columns },
1361
1821
  ...fetchProps
1362
1822
  });
1363
- const finalObject = await this.read(response.id);
1364
- if (!finalObject) {
1365
- throw new Error("The server failed to save the record");
1366
- }
1367
- return finalObject;
1823
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1824
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1368
1825
  };
1369
1826
  _bulkInsertTableRecords = new WeakSet();
1370
- bulkInsertTableRecords_fn = async function(objects) {
1371
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1827
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1828
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1372
1829
  const records = objects.map((object) => transformObjectLinks(object));
1373
1830
  const response = await bulkInsertTableRecords({
1374
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1831
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1832
+ queryParams: { columns },
1375
1833
  body: { records },
1376
1834
  ...fetchProps
1377
1835
  });
1378
- const finalObjects = await this.any(...response.recordIDs.map((id) => this.filter("id", id))).getAll();
1379
- if (finalObjects.length !== objects.length) {
1380
- throw new Error("The server failed to save some records");
1836
+ if (!isResponseWithRecords(response)) {
1837
+ throw new Error("Request included columns but server didn't include them");
1381
1838
  }
1382
- return finalObjects;
1839
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1840
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1383
1841
  };
1384
1842
  _updateRecordWithID = new WeakSet();
1385
- updateRecordWithID_fn = async function(recordId, object) {
1386
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1843
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1844
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1387
1845
  const record = transformObjectLinks(object);
1388
- const response = await updateRecordWithID({
1389
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1390
- body: record,
1391
- ...fetchProps
1392
- });
1393
- const item = await this.read(response.id);
1394
- if (!item)
1395
- throw new Error("The server failed to save the record");
1396
- return item;
1846
+ try {
1847
+ const response = await updateRecordWithID({
1848
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1849
+ queryParams: { columns },
1850
+ body: record,
1851
+ ...fetchProps
1852
+ });
1853
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1854
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1855
+ } catch (e) {
1856
+ if (isObject(e) && e.status === 404) {
1857
+ return null;
1858
+ }
1859
+ throw e;
1860
+ }
1397
1861
  };
1398
1862
  _upsertRecordWithID = new WeakSet();
1399
- upsertRecordWithID_fn = async function(recordId, object) {
1400
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1863
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1864
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1401
1865
  const response = await upsertRecordWithID({
1402
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1866
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1867
+ queryParams: { columns },
1403
1868
  body: object,
1404
1869
  ...fetchProps
1405
1870
  });
1406
- const item = await this.read(response.id);
1407
- if (!item)
1408
- throw new Error("The server failed to save the record");
1409
- return item;
1871
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1872
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1410
1873
  };
1411
1874
  _deleteRecord = new WeakSet();
1412
- deleteRecord_fn = async function(recordId) {
1413
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1414
- await deleteRecord({
1415
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1416
- ...fetchProps
1417
- });
1418
- };
1419
- _invalidateCache = new WeakSet();
1420
- invalidateCache_fn = async function(recordId) {
1421
- await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1422
- const cacheItems = await __privateGet$3(this, _cache).getAll();
1423
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1424
- for (const [key, value] of queries) {
1425
- const ids = getIds(value);
1426
- if (ids.includes(recordId))
1427
- await __privateGet$3(this, _cache).delete(key);
1875
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1876
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1877
+ try {
1878
+ const response = await deleteRecord({
1879
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1880
+ queryParams: { columns },
1881
+ ...fetchProps
1882
+ });
1883
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1884
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1885
+ } catch (e) {
1886
+ if (isObject(e) && e.status === 404) {
1887
+ return null;
1888
+ }
1889
+ throw e;
1428
1890
  }
1429
1891
  };
1430
- _setCacheRecord = new WeakSet();
1431
- setCacheRecord_fn = async function(record) {
1432
- if (!__privateGet$3(this, _cache).cacheRecords)
1433
- return;
1434
- await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
1435
- };
1436
- _getCacheRecord = new WeakSet();
1437
- getCacheRecord_fn = async function(recordId) {
1438
- if (!__privateGet$3(this, _cache).cacheRecords)
1439
- return null;
1440
- return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1441
- };
1442
1892
  _setCacheQuery = new WeakSet();
1443
1893
  setCacheQuery_fn = async function(query, meta, records) {
1444
- await __privateGet$3(this, _cache).set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1894
+ await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1445
1895
  };
1446
1896
  _getCacheQuery = new WeakSet();
1447
1897
  getCacheQuery_fn = async function(query) {
1448
- const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
1449
- const result = await __privateGet$3(this, _cache).get(key);
1898
+ const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
1899
+ const result = await __privateGet$4(this, _cache).get(key);
1450
1900
  if (!result)
1451
1901
  return null;
1452
- const { cache: ttl = __privateGet$3(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1453
- if (!ttl || ttl < 0)
1454
- return result;
1902
+ const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1903
+ if (ttl < 0)
1904
+ return null;
1455
1905
  const hasExpired = result.date.getTime() + ttl < Date.now();
1456
1906
  return hasExpired ? null : result;
1457
1907
  };
1908
+ _getSchemaTables$1 = new WeakSet();
1909
+ getSchemaTables_fn$1 = async function() {
1910
+ if (__privateGet$4(this, _schemaTables$2))
1911
+ return __privateGet$4(this, _schemaTables$2);
1912
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1913
+ const { schema } = await getBranchDetails({
1914
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1915
+ ...fetchProps
1916
+ });
1917
+ __privateSet$4(this, _schemaTables$2, schema.tables);
1918
+ return schema.tables;
1919
+ };
1458
1920
  const transformObjectLinks = (object) => {
1459
1921
  return Object.entries(object).reduce((acc, [key, value]) => {
1460
1922
  if (key === "xata")
@@ -1462,47 +1924,76 @@ const transformObjectLinks = (object) => {
1462
1924
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1463
1925
  }, {});
1464
1926
  };
1465
- const initObject = (db, links, table, object) => {
1927
+ const initObject = (db, schemaTables, table, object) => {
1466
1928
  const result = {};
1467
- Object.assign(result, object);
1468
- const tableLinks = links[table] || [];
1469
- for (const link of tableLinks) {
1470
- const [field, linkTable] = link;
1471
- const value = result[field];
1472
- if (value && isObject(value)) {
1473
- result[field] = initObject(db, links, linkTable, value);
1929
+ const { xata, ...rest } = object ?? {};
1930
+ Object.assign(result, rest);
1931
+ const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
1932
+ if (!columns)
1933
+ console.error(`Table ${table} not found in schema`);
1934
+ for (const column of columns ?? []) {
1935
+ const value = result[column.name];
1936
+ switch (column.type) {
1937
+ case "datetime": {
1938
+ const date = value !== void 0 ? new Date(value) : void 0;
1939
+ if (date && isNaN(date.getTime())) {
1940
+ console.error(`Failed to parse date ${value} for field ${column.name}`);
1941
+ } else if (date) {
1942
+ result[column.name] = date;
1943
+ }
1944
+ break;
1945
+ }
1946
+ case "link": {
1947
+ const linkTable = column.link?.table;
1948
+ if (!linkTable) {
1949
+ console.error(`Failed to parse link for field ${column.name}`);
1950
+ } else if (isObject(value)) {
1951
+ result[column.name] = initObject(db, schemaTables, linkTable, value);
1952
+ }
1953
+ break;
1954
+ }
1474
1955
  }
1475
1956
  }
1476
- result.read = function() {
1477
- return db[table].read(result["id"]);
1957
+ result.read = function(columns2) {
1958
+ return db[table].read(result["id"], columns2);
1478
1959
  };
1479
- result.update = function(data) {
1480
- return db[table].update(result["id"], data);
1960
+ result.update = function(data, columns2) {
1961
+ return db[table].update(result["id"], data, columns2);
1481
1962
  };
1482
1963
  result.delete = function() {
1483
1964
  return db[table].delete(result["id"]);
1484
1965
  };
1485
- for (const prop of ["read", "update", "delete"]) {
1966
+ result.getMetadata = function() {
1967
+ return xata;
1968
+ };
1969
+ for (const prop of ["read", "update", "delete", "getMetadata"]) {
1486
1970
  Object.defineProperty(result, prop, { enumerable: false });
1487
1971
  }
1488
1972
  Object.freeze(result);
1489
1973
  return result;
1490
1974
  };
1491
- function getIds(value) {
1492
- if (Array.isArray(value)) {
1493
- return value.map((item) => getIds(item)).flat();
1494
- }
1495
- if (!isObject(value))
1496
- return [];
1497
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1498
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1975
+ function isResponseWithRecords(value) {
1976
+ return isObject(value) && Array.isArray(value.records);
1977
+ }
1978
+ function extractId(value) {
1979
+ if (isString(value))
1980
+ return value;
1981
+ if (isObject(value) && isString(value.id))
1982
+ return value.id;
1983
+ return void 0;
1984
+ }
1985
+ function cleanFilter(filter) {
1986
+ if (!filter)
1987
+ return void 0;
1988
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1989
+ return values.length > 0 ? filter : void 0;
1499
1990
  }
1500
1991
 
1501
1992
  var __accessCheck$3 = (obj, member, msg) => {
1502
1993
  if (!member.has(obj))
1503
1994
  throw TypeError("Cannot " + msg);
1504
1995
  };
1505
- var __privateGet$2 = (obj, member, getter) => {
1996
+ var __privateGet$3 = (obj, member, getter) => {
1506
1997
  __accessCheck$3(obj, member, "read from private field");
1507
1998
  return getter ? getter.call(obj) : member.get(obj);
1508
1999
  };
@@ -1511,7 +2002,7 @@ var __privateAdd$3 = (obj, member, value) => {
1511
2002
  throw TypeError("Cannot add the same private member more than once");
1512
2003
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1513
2004
  };
1514
- var __privateSet$1 = (obj, member, value, setter) => {
2005
+ var __privateSet$3 = (obj, member, value, setter) => {
1515
2006
  __accessCheck$3(obj, member, "write to private field");
1516
2007
  setter ? setter.call(obj, value) : member.set(obj, value);
1517
2008
  return value;
@@ -1520,46 +2011,52 @@ var _map;
1520
2011
  class SimpleCache {
1521
2012
  constructor(options = {}) {
1522
2013
  __privateAdd$3(this, _map, void 0);
1523
- __privateSet$1(this, _map, /* @__PURE__ */ new Map());
2014
+ __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1524
2015
  this.capacity = options.max ?? 500;
1525
- this.cacheRecords = options.cacheRecords ?? true;
1526
2016
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1527
2017
  }
1528
2018
  async getAll() {
1529
- return Object.fromEntries(__privateGet$2(this, _map));
2019
+ return Object.fromEntries(__privateGet$3(this, _map));
1530
2020
  }
1531
2021
  async get(key) {
1532
- return __privateGet$2(this, _map).get(key) ?? null;
2022
+ return __privateGet$3(this, _map).get(key) ?? null;
1533
2023
  }
1534
2024
  async set(key, value) {
1535
2025
  await this.delete(key);
1536
- __privateGet$2(this, _map).set(key, value);
1537
- if (__privateGet$2(this, _map).size > this.capacity) {
1538
- const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
2026
+ __privateGet$3(this, _map).set(key, value);
2027
+ if (__privateGet$3(this, _map).size > this.capacity) {
2028
+ const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
1539
2029
  await this.delete(leastRecentlyUsed);
1540
2030
  }
1541
2031
  }
1542
2032
  async delete(key) {
1543
- __privateGet$2(this, _map).delete(key);
2033
+ __privateGet$3(this, _map).delete(key);
1544
2034
  }
1545
2035
  async clear() {
1546
- return __privateGet$2(this, _map).clear();
2036
+ return __privateGet$3(this, _map).clear();
1547
2037
  }
1548
2038
  }
1549
2039
  _map = new WeakMap();
1550
2040
 
1551
- const gt = (value) => ({ $gt: value });
1552
- const ge = (value) => ({ $ge: value });
1553
- const gte = (value) => ({ $ge: value });
1554
- const lt = (value) => ({ $lt: value });
1555
- const lte = (value) => ({ $le: value });
1556
- const le = (value) => ({ $le: value });
2041
+ const greaterThan = (value) => ({ $gt: value });
2042
+ const gt = greaterThan;
2043
+ const greaterThanEquals = (value) => ({ $ge: value });
2044
+ const greaterEquals = greaterThanEquals;
2045
+ const gte = greaterThanEquals;
2046
+ const ge = greaterThanEquals;
2047
+ const lessThan = (value) => ({ $lt: value });
2048
+ const lt = lessThan;
2049
+ const lessThanEquals = (value) => ({ $le: value });
2050
+ const lessEquals = lessThanEquals;
2051
+ const lte = lessThanEquals;
2052
+ const le = lessThanEquals;
1557
2053
  const exists = (column) => ({ $exists: column });
1558
2054
  const notExists = (column) => ({ $notExists: column });
1559
2055
  const startsWith = (value) => ({ $startsWith: value });
1560
2056
  const endsWith = (value) => ({ $endsWith: value });
1561
2057
  const pattern = (value) => ({ $pattern: value });
1562
2058
  const is = (value) => ({ $is: value });
2059
+ const equals = is;
1563
2060
  const isNot = (value) => ({ $isNot: value });
1564
2061
  const contains = (value) => ({ $contains: value });
1565
2062
  const includes = (value) => ({ $includes: value });
@@ -1571,7 +2068,7 @@ var __accessCheck$2 = (obj, member, msg) => {
1571
2068
  if (!member.has(obj))
1572
2069
  throw TypeError("Cannot " + msg);
1573
2070
  };
1574
- var __privateGet$1 = (obj, member, getter) => {
2071
+ var __privateGet$2 = (obj, member, getter) => {
1575
2072
  __accessCheck$2(obj, member, "read from private field");
1576
2073
  return getter ? getter.call(obj) : member.get(obj);
1577
2074
  };
@@ -1580,130 +2077,178 @@ var __privateAdd$2 = (obj, member, value) => {
1580
2077
  throw TypeError("Cannot add the same private member more than once");
1581
2078
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1582
2079
  };
1583
- var _tables;
2080
+ var __privateSet$2 = (obj, member, value, setter) => {
2081
+ __accessCheck$2(obj, member, "write to private field");
2082
+ setter ? setter.call(obj, value) : member.set(obj, value);
2083
+ return value;
2084
+ };
2085
+ var _tables, _schemaTables$1;
1584
2086
  class SchemaPlugin extends XataPlugin {
1585
- constructor(links, tableNames) {
2087
+ constructor(schemaTables) {
1586
2088
  super();
1587
- this.links = links;
1588
- this.tableNames = tableNames;
1589
2089
  __privateAdd$2(this, _tables, {});
2090
+ __privateAdd$2(this, _schemaTables$1, void 0);
2091
+ __privateSet$2(this, _schemaTables$1, schemaTables);
1590
2092
  }
1591
2093
  build(pluginOptions) {
1592
- const links = this.links;
1593
- const db = new Proxy({}, {
1594
- get: (_target, table) => {
1595
- if (!isString(table))
1596
- throw new Error("Invalid table name");
1597
- if (!__privateGet$1(this, _tables)[table]) {
1598
- __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, links });
2094
+ const db = new Proxy(
2095
+ {},
2096
+ {
2097
+ get: (_target, table) => {
2098
+ if (!isString(table))
2099
+ throw new Error("Invalid table name");
2100
+ if (__privateGet$2(this, _tables)[table] === void 0) {
2101
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
2102
+ }
2103
+ return __privateGet$2(this, _tables)[table];
1599
2104
  }
1600
- return __privateGet$1(this, _tables)[table];
1601
2105
  }
1602
- });
1603
- for (const table of this.tableNames ?? []) {
1604
- db[table] = new RestRepository({ db, pluginOptions, table, links });
2106
+ );
2107
+ const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
2108
+ for (const table of tableNames) {
2109
+ db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1605
2110
  }
1606
2111
  return db;
1607
2112
  }
1608
2113
  }
1609
2114
  _tables = new WeakMap();
2115
+ _schemaTables$1 = new WeakMap();
1610
2116
 
1611
2117
  var __accessCheck$1 = (obj, member, msg) => {
1612
2118
  if (!member.has(obj))
1613
2119
  throw TypeError("Cannot " + msg);
1614
2120
  };
2121
+ var __privateGet$1 = (obj, member, getter) => {
2122
+ __accessCheck$1(obj, member, "read from private field");
2123
+ return getter ? getter.call(obj) : member.get(obj);
2124
+ };
1615
2125
  var __privateAdd$1 = (obj, member, value) => {
1616
2126
  if (member.has(obj))
1617
2127
  throw TypeError("Cannot add the same private member more than once");
1618
2128
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1619
2129
  };
2130
+ var __privateSet$1 = (obj, member, value, setter) => {
2131
+ __accessCheck$1(obj, member, "write to private field");
2132
+ setter ? setter.call(obj, value) : member.set(obj, value);
2133
+ return value;
2134
+ };
1620
2135
  var __privateMethod$1 = (obj, member, method) => {
1621
2136
  __accessCheck$1(obj, member, "access private method");
1622
2137
  return method;
1623
2138
  };
1624
- var _search, search_fn;
2139
+ var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
1625
2140
  class SearchPlugin extends XataPlugin {
1626
- constructor(db, links) {
2141
+ constructor(db, schemaTables) {
1627
2142
  super();
1628
2143
  this.db = db;
1629
- this.links = links;
1630
2144
  __privateAdd$1(this, _search);
2145
+ __privateAdd$1(this, _getSchemaTables);
2146
+ __privateAdd$1(this, _schemaTables, void 0);
2147
+ __privateSet$1(this, _schemaTables, schemaTables);
1631
2148
  }
1632
2149
  build({ getFetchProps }) {
1633
2150
  return {
1634
2151
  all: async (query, options = {}) => {
1635
2152
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
2153
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1636
2154
  return records.map((record) => {
1637
2155
  const { table = "orphan" } = record.xata;
1638
- return { table, record: initObject(this.db, this.links, table, record) };
2156
+ return { table, record: initObject(this.db, schemaTables, table, record) };
1639
2157
  });
1640
2158
  },
1641
2159
  byTable: async (query, options = {}) => {
1642
2160
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
2161
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1643
2162
  return records.reduce((acc, record) => {
1644
2163
  const { table = "orphan" } = record.xata;
1645
2164
  const items = acc[table] ?? [];
1646
- const item = initObject(this.db, this.links, table, record);
2165
+ const item = initObject(this.db, schemaTables, table, record);
1647
2166
  return { ...acc, [table]: [...items, item] };
1648
2167
  }, {});
1649
2168
  }
1650
2169
  };
1651
2170
  }
1652
2171
  }
2172
+ _schemaTables = new WeakMap();
1653
2173
  _search = new WeakSet();
1654
2174
  search_fn = async function(query, options, getFetchProps) {
1655
2175
  const fetchProps = await getFetchProps();
1656
- const { tables, fuzziness } = options ?? {};
2176
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1657
2177
  const { records } = await searchBranch({
1658
2178
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1659
- body: { tables, query, fuzziness },
2179
+ body: { tables, query, fuzziness, prefix, highlight },
1660
2180
  ...fetchProps
1661
2181
  });
1662
2182
  return records;
1663
2183
  };
2184
+ _getSchemaTables = new WeakSet();
2185
+ getSchemaTables_fn = async function(getFetchProps) {
2186
+ if (__privateGet$1(this, _schemaTables))
2187
+ return __privateGet$1(this, _schemaTables);
2188
+ const fetchProps = await getFetchProps();
2189
+ const { schema } = await getBranchDetails({
2190
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
2191
+ ...fetchProps
2192
+ });
2193
+ __privateSet$1(this, _schemaTables, schema.tables);
2194
+ return schema.tables;
2195
+ };
1664
2196
 
1665
2197
  const isBranchStrategyBuilder = (strategy) => {
1666
2198
  return typeof strategy === "function";
1667
2199
  };
1668
2200
 
1669
- const envBranchNames = [
1670
- "XATA_BRANCH",
1671
- "VERCEL_GIT_COMMIT_REF",
1672
- "CF_PAGES_BRANCH",
1673
- "BRANCH"
1674
- ];
1675
- const defaultBranch = "main";
1676
2201
  async function getCurrentBranchName(options) {
1677
- const env = await getBranchByEnvVariable();
1678
- if (env)
1679
- return env;
1680
- const branch = await getGitBranch();
1681
- if (!branch)
1682
- return defaultBranch;
1683
- const details = await getDatabaseBranch(branch, options);
1684
- if (details)
1685
- return branch;
1686
- return defaultBranch;
2202
+ const { branch, envBranch } = getEnvironment();
2203
+ if (branch) {
2204
+ const details = await getDatabaseBranch(branch, options);
2205
+ if (details)
2206
+ return branch;
2207
+ console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
2208
+ }
2209
+ const gitBranch = envBranch || await getGitBranch();
2210
+ return resolveXataBranch(gitBranch, options);
1687
2211
  }
1688
2212
  async function getCurrentBranchDetails(options) {
1689
- const env = await getBranchByEnvVariable();
1690
- if (env)
1691
- return getDatabaseBranch(env, options);
1692
- const branch = await getGitBranch();
1693
- if (!branch)
1694
- return getDatabaseBranch(defaultBranch, options);
1695
- const details = await getDatabaseBranch(branch, options);
1696
- if (details)
1697
- return details;
1698
- return getDatabaseBranch(defaultBranch, options);
2213
+ const branch = await getCurrentBranchName(options);
2214
+ return getDatabaseBranch(branch, options);
2215
+ }
2216
+ async function resolveXataBranch(gitBranch, options) {
2217
+ const databaseURL = options?.databaseURL || getDatabaseURL();
2218
+ const apiKey = options?.apiKey || getAPIKey();
2219
+ if (!databaseURL)
2220
+ throw new Error(
2221
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2222
+ );
2223
+ if (!apiKey)
2224
+ throw new Error(
2225
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2226
+ );
2227
+ const [protocol, , host, , dbName] = databaseURL.split("/");
2228
+ const [workspace] = host.split(".");
2229
+ const { fallbackBranch } = getEnvironment();
2230
+ const { branch } = await resolveBranch({
2231
+ apiKey,
2232
+ apiUrl: databaseURL,
2233
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
2234
+ workspacesApiUrl: `${protocol}//${host}`,
2235
+ pathParams: { dbName, workspace },
2236
+ queryParams: { gitBranch, fallbackBranch },
2237
+ trace: defaultTrace
2238
+ });
2239
+ return branch;
1699
2240
  }
1700
2241
  async function getDatabaseBranch(branch, options) {
1701
2242
  const databaseURL = options?.databaseURL || getDatabaseURL();
1702
2243
  const apiKey = options?.apiKey || getAPIKey();
1703
2244
  if (!databaseURL)
1704
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
2245
+ throw new Error(
2246
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2247
+ );
1705
2248
  if (!apiKey)
1706
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
2249
+ throw new Error(
2250
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2251
+ );
1707
2252
  const [protocol, , host, , database] = databaseURL.split("/");
1708
2253
  const [workspace] = host.split(".");
1709
2254
  const dbBranchName = `${database}:${branch}`;
@@ -1713,10 +2258,8 @@ async function getDatabaseBranch(branch, options) {
1713
2258
  apiUrl: databaseURL,
1714
2259
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1715
2260
  workspacesApiUrl: `${protocol}//${host}`,
1716
- pathParams: {
1717
- dbBranchName,
1718
- workspace
1719
- }
2261
+ pathParams: { dbBranchName, workspace },
2262
+ trace: defaultTrace
1720
2263
  });
1721
2264
  } catch (err) {
1722
2265
  if (isObject(err) && err.status === 404)
@@ -1724,21 +2267,10 @@ async function getDatabaseBranch(branch, options) {
1724
2267
  throw err;
1725
2268
  }
1726
2269
  }
1727
- function getBranchByEnvVariable() {
1728
- for (const name of envBranchNames) {
1729
- const value = getEnvVariable(name);
1730
- if (value) {
1731
- return value;
1732
- }
1733
- }
1734
- try {
1735
- return XATA_BRANCH;
1736
- } catch (err) {
1737
- }
1738
- }
1739
2270
  function getDatabaseURL() {
1740
2271
  try {
1741
- return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
2272
+ const { databaseURL } = getEnvironment();
2273
+ return databaseURL;
1742
2274
  } catch (err) {
1743
2275
  return void 0;
1744
2276
  }
@@ -1767,24 +2299,27 @@ var __privateMethod = (obj, member, method) => {
1767
2299
  return method;
1768
2300
  };
1769
2301
  const buildClient = (plugins) => {
1770
- var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
2302
+ var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1771
2303
  return _a = class {
1772
- constructor(options = {}, links, tables) {
2304
+ constructor(options = {}, schemaTables) {
1773
2305
  __privateAdd(this, _parseOptions);
1774
2306
  __privateAdd(this, _getFetchProps);
1775
2307
  __privateAdd(this, _evaluateBranch);
1776
2308
  __privateAdd(this, _branch, void 0);
2309
+ __privateAdd(this, _options, void 0);
1777
2310
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
2311
+ __privateSet(this, _options, safeOptions);
1778
2312
  const pluginOptions = {
1779
2313
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1780
- cache: safeOptions.cache
2314
+ cache: safeOptions.cache,
2315
+ trace: safeOptions.trace
1781
2316
  };
1782
- const db = new SchemaPlugin(links, tables).build(pluginOptions);
1783
- const search = new SearchPlugin(db, links ?? {}).build(pluginOptions);
2317
+ const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2318
+ const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
1784
2319
  this.db = db;
1785
2320
  this.search = search;
1786
2321
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1787
- if (!namespace)
2322
+ if (namespace === void 0)
1788
2323
  continue;
1789
2324
  const result = namespace.build(pluginOptions);
1790
2325
  if (result instanceof Promise) {
@@ -1796,22 +2331,26 @@ const buildClient = (plugins) => {
1796
2331
  }
1797
2332
  }
1798
2333
  }
1799
- }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2334
+ async getConfig() {
2335
+ const databaseURL = __privateGet(this, _options).databaseURL;
2336
+ const branch = await __privateGet(this, _options).branch();
2337
+ return { databaseURL, branch };
2338
+ }
2339
+ }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
1800
2340
  const fetch = getFetchImplementation(options?.fetch);
1801
2341
  const databaseURL = options?.databaseURL || getDatabaseURL();
1802
2342
  const apiKey = options?.apiKey || getAPIKey();
1803
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1804
- const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1805
- if (!databaseURL || !apiKey) {
1806
- throw new Error("Options databaseURL and apiKey are required");
2343
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2344
+ const trace = options?.trace ?? defaultTrace;
2345
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2346
+ if (!apiKey) {
2347
+ throw new Error("Option apiKey is required");
1807
2348
  }
1808
- return { fetch, databaseURL, apiKey, branch, cache };
1809
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1810
- fetch,
1811
- apiKey,
1812
- databaseURL,
1813
- branch
1814
- }) {
2349
+ if (!databaseURL) {
2350
+ throw new Error("Option databaseURL is required");
2351
+ }
2352
+ return { fetch, databaseURL, apiKey, branch, cache, trace };
2353
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
1815
2354
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
1816
2355
  if (!branchValue)
1817
2356
  throw new Error("Unable to resolve branch value");
@@ -1821,14 +2360,15 @@ const buildClient = (plugins) => {
1821
2360
  apiUrl: "",
1822
2361
  workspacesApiUrl: (path, params) => {
1823
2362
  const hasBranch = params.dbBranchName ?? params.branch;
1824
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2363
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
1825
2364
  return databaseURL + newPath;
1826
- }
2365
+ },
2366
+ trace
1827
2367
  };
1828
2368
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
1829
2369
  if (__privateGet(this, _branch))
1830
2370
  return __privateGet(this, _branch);
1831
- if (!param)
2371
+ if (param === void 0)
1832
2372
  return void 0;
1833
2373
  const strategies = Array.isArray(param) ? [...param] : [param];
1834
2374
  const evaluateBranch = async (strategy) => {
@@ -1846,6 +2386,88 @@ const buildClient = (plugins) => {
1846
2386
  class BaseClient extends buildClient() {
1847
2387
  }
1848
2388
 
2389
+ const META = "__";
2390
+ const VALUE = "___";
2391
+ class Serializer {
2392
+ constructor() {
2393
+ this.classes = {};
2394
+ }
2395
+ add(clazz) {
2396
+ this.classes[clazz.name] = clazz;
2397
+ }
2398
+ toJSON(data) {
2399
+ function visit(obj) {
2400
+ if (Array.isArray(obj))
2401
+ return obj.map(visit);
2402
+ const type = typeof obj;
2403
+ if (type === "undefined")
2404
+ return { [META]: "undefined" };
2405
+ if (type === "bigint")
2406
+ return { [META]: "bigint", [VALUE]: obj.toString() };
2407
+ if (obj === null || type !== "object")
2408
+ return obj;
2409
+ const constructor = obj.constructor;
2410
+ const o = { [META]: constructor.name };
2411
+ for (const [key, value] of Object.entries(obj)) {
2412
+ o[key] = visit(value);
2413
+ }
2414
+ if (constructor === Date)
2415
+ o[VALUE] = obj.toISOString();
2416
+ if (constructor === Map)
2417
+ o[VALUE] = Object.fromEntries(obj);
2418
+ if (constructor === Set)
2419
+ o[VALUE] = [...obj];
2420
+ return o;
2421
+ }
2422
+ return JSON.stringify(visit(data));
2423
+ }
2424
+ fromJSON(json) {
2425
+ return JSON.parse(json, (key, value) => {
2426
+ if (value && typeof value === "object" && !Array.isArray(value)) {
2427
+ const { [META]: clazz, [VALUE]: val, ...rest } = value;
2428
+ const constructor = this.classes[clazz];
2429
+ if (constructor) {
2430
+ return Object.assign(Object.create(constructor.prototype), rest);
2431
+ }
2432
+ if (clazz === "Date")
2433
+ return new Date(val);
2434
+ if (clazz === "Set")
2435
+ return new Set(val);
2436
+ if (clazz === "Map")
2437
+ return new Map(Object.entries(val));
2438
+ if (clazz === "bigint")
2439
+ return BigInt(val);
2440
+ if (clazz === "undefined")
2441
+ return void 0;
2442
+ return rest;
2443
+ }
2444
+ return value;
2445
+ });
2446
+ }
2447
+ }
2448
+ const defaultSerializer = new Serializer();
2449
+ const serialize = (data) => {
2450
+ return defaultSerializer.toJSON(data);
2451
+ };
2452
+ const deserialize = (json) => {
2453
+ return defaultSerializer.fromJSON(json);
2454
+ };
2455
+
2456
+ function buildWorkerRunner(config) {
2457
+ return function xataWorker(name, _worker) {
2458
+ return async (...args) => {
2459
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2460
+ const result = await fetch(url, {
2461
+ method: "POST",
2462
+ headers: { "Content-Type": "application/json" },
2463
+ body: serialize({ args })
2464
+ });
2465
+ const text = await result.text();
2466
+ return deserialize(text);
2467
+ };
2468
+ };
2469
+ }
2470
+
1849
2471
  class XataError extends Error {
1850
2472
  constructor(message, status) {
1851
2473
  super(message);
@@ -1861,10 +2483,12 @@ exports.PAGINATION_MAX_OFFSET = PAGINATION_MAX_OFFSET;
1861
2483
  exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
1862
2484
  exports.Page = Page;
1863
2485
  exports.Query = Query;
2486
+ exports.RecordArray = RecordArray;
1864
2487
  exports.Repository = Repository;
1865
2488
  exports.RestRepository = RestRepository;
1866
2489
  exports.SchemaPlugin = SchemaPlugin;
1867
2490
  exports.SearchPlugin = SearchPlugin;
2491
+ exports.Serializer = Serializer;
1868
2492
  exports.SimpleCache = SimpleCache;
1869
2493
  exports.XataApiClient = XataApiClient;
1870
2494
  exports.XataApiPlugin = XataApiPlugin;
@@ -1873,12 +2497,18 @@ exports.XataPlugin = XataPlugin;
1873
2497
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
1874
2498
  exports.addGitBranchesEntry = addGitBranchesEntry;
1875
2499
  exports.addTableColumn = addTableColumn;
2500
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
1876
2501
  exports.buildClient = buildClient;
2502
+ exports.buildWorkerRunner = buildWorkerRunner;
1877
2503
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
1878
2504
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
2505
+ exports.compareBranchSchemas = compareBranchSchemas;
2506
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
2507
+ exports.compareMigrationRequest = compareMigrationRequest;
1879
2508
  exports.contains = contains;
1880
2509
  exports.createBranch = createBranch;
1881
2510
  exports.createDatabase = createDatabase;
2511
+ exports.createMigrationRequest = createMigrationRequest;
1882
2512
  exports.createTable = createTable;
1883
2513
  exports.createUserAPIKey = createUserAPIKey;
1884
2514
  exports.createWorkspace = createWorkspace;
@@ -1890,7 +2520,9 @@ exports.deleteTable = deleteTable;
1890
2520
  exports.deleteUser = deleteUser;
1891
2521
  exports.deleteUserAPIKey = deleteUserAPIKey;
1892
2522
  exports.deleteWorkspace = deleteWorkspace;
2523
+ exports.deserialize = deserialize;
1893
2524
  exports.endsWith = endsWith;
2525
+ exports.equals = equals;
1894
2526
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
1895
2527
  exports.exists = exists;
1896
2528
  exports.ge = ge;
@@ -1900,13 +2532,17 @@ exports.getBranchList = getBranchList;
1900
2532
  exports.getBranchMetadata = getBranchMetadata;
1901
2533
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
1902
2534
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
2535
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
1903
2536
  exports.getBranchStats = getBranchStats;
1904
2537
  exports.getColumn = getColumn;
1905
2538
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
1906
2539
  exports.getCurrentBranchName = getCurrentBranchName;
1907
2540
  exports.getDatabaseList = getDatabaseList;
2541
+ exports.getDatabaseMetadata = getDatabaseMetadata;
1908
2542
  exports.getDatabaseURL = getDatabaseURL;
1909
2543
  exports.getGitBranchesMapping = getGitBranchesMapping;
2544
+ exports.getMigrationRequest = getMigrationRequest;
2545
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
1910
2546
  exports.getRecord = getRecord;
1911
2547
  exports.getTableColumns = getTableColumns;
1912
2548
  exports.getTableSchema = getTableSchema;
@@ -1915,6 +2551,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
1915
2551
  exports.getWorkspace = getWorkspace;
1916
2552
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
1917
2553
  exports.getWorkspacesList = getWorkspacesList;
2554
+ exports.greaterEquals = greaterEquals;
2555
+ exports.greaterThan = greaterThan;
2556
+ exports.greaterThanEquals = greaterThanEquals;
1918
2557
  exports.gt = gt;
1919
2558
  exports.gte = gte;
1920
2559
  exports.includes = includes;
@@ -1925,29 +2564,42 @@ exports.insertRecord = insertRecord;
1925
2564
  exports.insertRecordWithID = insertRecordWithID;
1926
2565
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
1927
2566
  exports.is = is;
2567
+ exports.isCursorPaginationOptions = isCursorPaginationOptions;
1928
2568
  exports.isIdentifiable = isIdentifiable;
1929
2569
  exports.isNot = isNot;
1930
2570
  exports.isXataRecord = isXataRecord;
1931
2571
  exports.le = le;
2572
+ exports.lessEquals = lessEquals;
2573
+ exports.lessThan = lessThan;
2574
+ exports.lessThanEquals = lessThanEquals;
2575
+ exports.listMigrationRequests = listMigrationRequests;
2576
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
1932
2577
  exports.lt = lt;
1933
2578
  exports.lte = lte;
2579
+ exports.mergeMigrationRequest = mergeMigrationRequest;
1934
2580
  exports.notExists = notExists;
1935
2581
  exports.operationsByTag = operationsByTag;
1936
2582
  exports.pattern = pattern;
2583
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
1937
2584
  exports.queryTable = queryTable;
1938
2585
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
1939
2586
  exports.removeWorkspaceMember = removeWorkspaceMember;
1940
2587
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
1941
2588
  exports.resolveBranch = resolveBranch;
1942
2589
  exports.searchBranch = searchBranch;
2590
+ exports.searchTable = searchTable;
2591
+ exports.serialize = serialize;
1943
2592
  exports.setTableSchema = setTableSchema;
1944
2593
  exports.startsWith = startsWith;
1945
2594
  exports.updateBranchMetadata = updateBranchMetadata;
2595
+ exports.updateBranchSchema = updateBranchSchema;
1946
2596
  exports.updateColumn = updateColumn;
2597
+ exports.updateMigrationRequest = updateMigrationRequest;
1947
2598
  exports.updateRecordWithID = updateRecordWithID;
1948
2599
  exports.updateTable = updateTable;
1949
2600
  exports.updateUser = updateUser;
1950
2601
  exports.updateWorkspace = updateWorkspace;
2602
+ exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
1951
2603
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
1952
2604
  exports.upsertRecordWithID = upsertRecordWithID;
1953
2605
  //# sourceMappingURL=index.cjs.map