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