@xata.io/client 0.0.0-alpha.vf38f30b → 0.0.0-alpha.vf4752f8

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