@xata.io/client 0.0.0-alpha.vf4b92f1 → 0.0.0-alpha.vf4e6746

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,6 +1,26 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
3
+ const defaultTrace = async (_name, fn, _options) => {
4
+ return await fn({
5
+ setAttributes: () => {
6
+ return;
7
+ }
8
+ });
9
+ };
10
+ const TraceAttributes = {
11
+ KIND: "xata.trace.kind",
12
+ VERSION: "xata.sdk.version",
13
+ TABLE: "xata.table",
14
+ HTTP_REQUEST_ID: "http.request_id",
15
+ HTTP_STATUS_CODE: "http.status_code",
16
+ HTTP_HOST: "http.host",
17
+ HTTP_SCHEME: "http.scheme",
18
+ HTTP_USER_AGENT: "http.user_agent",
19
+ HTTP_METHOD: "http.method",
20
+ HTTP_URL: "http.url",
21
+ HTTP_ROUTE: "http.route",
22
+ HTTP_TARGET: "http.target"
23
+ };
4
24
 
5
25
  function notEmpty(value) {
6
26
  return value !== null && value !== void 0;
@@ -11,43 +31,156 @@ function compact(arr) {
11
31
  function isObject(value) {
12
32
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
13
33
  }
34
+ function isDefined(value) {
35
+ return value !== null && value !== void 0;
36
+ }
14
37
  function isString(value) {
15
- return value !== void 0 && value !== null && typeof value === "string";
38
+ return isDefined(value) && typeof value === "string";
39
+ }
40
+ function isStringArray(value) {
41
+ return isDefined(value) && Array.isArray(value) && value.every(isString);
42
+ }
43
+ function isNumber(value) {
44
+ return isDefined(value) && typeof value === "number";
45
+ }
46
+ function parseNumber(value) {
47
+ if (isNumber(value)) {
48
+ return value;
49
+ }
50
+ if (isString(value)) {
51
+ const parsed = Number(value);
52
+ if (!Number.isNaN(parsed)) {
53
+ return parsed;
54
+ }
55
+ }
56
+ return void 0;
16
57
  }
17
58
  function toBase64(value) {
18
59
  try {
19
60
  return btoa(value);
20
61
  } catch (err) {
21
- return Buffer.from(value).toString("base64");
62
+ const buf = Buffer;
63
+ return buf.from(value).toString("base64");
22
64
  }
23
65
  }
66
+ function deepMerge(a, b) {
67
+ const result = { ...a };
68
+ for (const [key, value] of Object.entries(b)) {
69
+ if (isObject(value) && isObject(result[key])) {
70
+ result[key] = deepMerge(result[key], value);
71
+ } else {
72
+ result[key] = value;
73
+ }
74
+ }
75
+ return result;
76
+ }
77
+ function chunk(array, chunkSize) {
78
+ const result = [];
79
+ for (let i = 0; i < array.length; i += chunkSize) {
80
+ result.push(array.slice(i, i + chunkSize));
81
+ }
82
+ return result;
83
+ }
84
+ async function timeout(ms) {
85
+ return new Promise((resolve) => setTimeout(resolve, ms));
86
+ }
24
87
 
25
- function getEnvVariable(name) {
88
+ function getEnvironment() {
89
+ try {
90
+ if (isDefined(process) && isDefined(process.env)) {
91
+ return {
92
+ apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
93
+ databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
94
+ branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
95
+ envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
96
+ fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
97
+ };
98
+ }
99
+ } catch (err) {
100
+ }
101
+ try {
102
+ if (isObject(Deno) && isObject(Deno.env)) {
103
+ return {
104
+ apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
105
+ databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
106
+ branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
107
+ envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
108
+ fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
109
+ };
110
+ }
111
+ } catch (err) {
112
+ }
113
+ return {
114
+ apiKey: getGlobalApiKey(),
115
+ databaseURL: getGlobalDatabaseURL(),
116
+ branch: getGlobalBranch(),
117
+ envBranch: void 0,
118
+ fallbackBranch: getGlobalFallbackBranch()
119
+ };
120
+ }
121
+ function getEnableBrowserVariable() {
26
122
  try {
27
- if (isObject(process) && isString(process?.env?.[name])) {
28
- return process.env[name];
123
+ if (isObject(process) && isObject(process.env) && process.env.XATA_ENABLE_BROWSER !== void 0) {
124
+ return process.env.XATA_ENABLE_BROWSER === "true";
29
125
  }
30
126
  } catch (err) {
31
127
  }
32
128
  try {
33
- if (isObject(Deno) && isString(Deno?.env?.get(name))) {
34
- return Deno.env.get(name);
129
+ if (isObject(Deno) && isObject(Deno.env) && Deno.env.get("XATA_ENABLE_BROWSER") !== void 0) {
130
+ return Deno.env.get("XATA_ENABLE_BROWSER") === "true";
35
131
  }
36
132
  } catch (err) {
37
133
  }
134
+ try {
135
+ return XATA_ENABLE_BROWSER === true || XATA_ENABLE_BROWSER === "true";
136
+ } catch (err) {
137
+ return void 0;
138
+ }
139
+ }
140
+ function getGlobalApiKey() {
141
+ try {
142
+ return XATA_API_KEY;
143
+ } catch (err) {
144
+ return void 0;
145
+ }
146
+ }
147
+ function getGlobalDatabaseURL() {
148
+ try {
149
+ return XATA_DATABASE_URL;
150
+ } catch (err) {
151
+ return void 0;
152
+ }
153
+ }
154
+ function getGlobalBranch() {
155
+ try {
156
+ return XATA_BRANCH;
157
+ } catch (err) {
158
+ return void 0;
159
+ }
160
+ }
161
+ function getGlobalFallbackBranch() {
162
+ try {
163
+ return XATA_FALLBACK_BRANCH;
164
+ } catch (err) {
165
+ return void 0;
166
+ }
38
167
  }
39
168
  async function getGitBranch() {
169
+ const cmd = ["git", "branch", "--show-current"];
170
+ const fullCmd = cmd.join(" ");
171
+ const nodeModule = ["child", "process"].join("_");
172
+ const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
40
173
  try {
41
- return require("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
174
+ if (typeof require === "function") {
175
+ return require(nodeModule).execSync(fullCmd, execOptions).trim();
176
+ }
177
+ const { execSync } = await import(nodeModule);
178
+ return execSync(fullCmd, execOptions).toString().trim();
42
179
  } catch (err) {
43
180
  }
44
181
  try {
45
182
  if (isObject(Deno)) {
46
- const process2 = Deno.run({
47
- cmd: ["git", "branch", "--show-current"],
48
- stdout: "piped",
49
- stderr: "piped"
50
- });
183
+ const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
51
184
  return new TextDecoder().decode(await process2.output()).trim();
52
185
  }
53
186
  } catch (err) {
@@ -56,31 +189,135 @@ async function getGitBranch() {
56
189
 
57
190
  function getAPIKey() {
58
191
  try {
59
- return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
192
+ const { apiKey } = getEnvironment();
193
+ return apiKey;
60
194
  } catch (err) {
61
195
  return void 0;
62
196
  }
63
197
  }
64
198
 
199
+ var __accessCheck$8 = (obj, member, msg) => {
200
+ if (!member.has(obj))
201
+ throw TypeError("Cannot " + msg);
202
+ };
203
+ var __privateGet$8 = (obj, member, getter) => {
204
+ __accessCheck$8(obj, member, "read from private field");
205
+ return getter ? getter.call(obj) : member.get(obj);
206
+ };
207
+ var __privateAdd$8 = (obj, member, value) => {
208
+ if (member.has(obj))
209
+ throw TypeError("Cannot add the same private member more than once");
210
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
211
+ };
212
+ var __privateSet$8 = (obj, member, value, setter) => {
213
+ __accessCheck$8(obj, member, "write to private field");
214
+ setter ? setter.call(obj, value) : member.set(obj, value);
215
+ return value;
216
+ };
217
+ var __privateMethod$4 = (obj, member, method) => {
218
+ __accessCheck$8(obj, member, "access private method");
219
+ return method;
220
+ };
221
+ var _fetch, _queue, _concurrency, _enqueue, enqueue_fn;
65
222
  function getFetchImplementation(userFetch) {
66
223
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
67
224
  const fetchImpl = userFetch ?? globalFetch;
68
225
  if (!fetchImpl) {
69
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
226
+ throw new Error(
227
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
228
+ );
70
229
  }
71
230
  return fetchImpl;
72
231
  }
232
+ class ApiRequestPool {
233
+ constructor(concurrency = 10) {
234
+ __privateAdd$8(this, _enqueue);
235
+ __privateAdd$8(this, _fetch, void 0);
236
+ __privateAdd$8(this, _queue, void 0);
237
+ __privateAdd$8(this, _concurrency, void 0);
238
+ __privateSet$8(this, _queue, []);
239
+ __privateSet$8(this, _concurrency, concurrency);
240
+ this.running = 0;
241
+ this.started = 0;
242
+ }
243
+ setFetch(fetch2) {
244
+ __privateSet$8(this, _fetch, fetch2);
245
+ }
246
+ getFetch() {
247
+ if (!__privateGet$8(this, _fetch)) {
248
+ throw new Error("Fetch not set");
249
+ }
250
+ return __privateGet$8(this, _fetch);
251
+ }
252
+ request(url, options) {
253
+ const start = new Date();
254
+ const fetch2 = this.getFetch();
255
+ const runRequest = async (stalled = false) => {
256
+ const response = await fetch2(url, options);
257
+ if (response.status === 429) {
258
+ const rateLimitReset = parseNumber(response.headers?.get("x-ratelimit-reset")) ?? 1;
259
+ await timeout(rateLimitReset * 1e3);
260
+ return await runRequest(true);
261
+ }
262
+ if (stalled) {
263
+ const stalledTime = new Date().getTime() - start.getTime();
264
+ console.warn(`A request to Xata hit your workspace limits, was retried and stalled for ${stalledTime}ms`);
265
+ }
266
+ return response;
267
+ };
268
+ return __privateMethod$4(this, _enqueue, enqueue_fn).call(this, async () => {
269
+ return await runRequest();
270
+ });
271
+ }
272
+ }
273
+ _fetch = new WeakMap();
274
+ _queue = new WeakMap();
275
+ _concurrency = new WeakMap();
276
+ _enqueue = new WeakSet();
277
+ enqueue_fn = function(task) {
278
+ const promise = new Promise((resolve) => __privateGet$8(this, _queue).push(resolve)).finally(() => {
279
+ this.started--;
280
+ this.running++;
281
+ }).then(() => task()).finally(() => {
282
+ this.running--;
283
+ const next = __privateGet$8(this, _queue).shift();
284
+ if (next !== void 0) {
285
+ this.started++;
286
+ next();
287
+ }
288
+ });
289
+ if (this.running + this.started < __privateGet$8(this, _concurrency)) {
290
+ const next = __privateGet$8(this, _queue).shift();
291
+ if (next !== void 0) {
292
+ this.started++;
293
+ next();
294
+ }
295
+ }
296
+ return promise;
297
+ };
73
298
 
74
- class FetcherError extends Error {
75
- constructor(status, data) {
299
+ const VERSION = "0.0.0-alpha.vf4e6746";
300
+
301
+ class ErrorWithCause extends Error {
302
+ constructor(message, options) {
303
+ super(message, options);
304
+ }
305
+ }
306
+ class FetcherError extends ErrorWithCause {
307
+ constructor(status, data, requestId) {
76
308
  super(getMessage(data));
77
309
  this.status = status;
78
310
  this.errors = isBulkError(data) ? data.errors : void 0;
311
+ this.requestId = requestId;
79
312
  if (data instanceof Error) {
80
313
  this.stack = data.stack;
81
314
  this.cause = data.cause;
82
315
  }
83
316
  }
317
+ toString() {
318
+ const error = super.toString();
319
+ return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
320
+ }
84
321
  }
85
322
  function isBulkError(error) {
86
323
  return isObject(error) && Array.isArray(error.errors);
@@ -102,21 +339,33 @@ function getMessage(data) {
102
339
  }
103
340
  }
104
341
 
342
+ const pool = new ApiRequestPool();
105
343
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
106
- const query = new URLSearchParams(queryParams).toString();
344
+ const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
345
+ if (value === void 0 || value === null)
346
+ return acc;
347
+ return { ...acc, [key]: value };
348
+ }, {});
349
+ const query = new URLSearchParams(cleanQueryParams).toString();
107
350
  const queryString = query.length > 0 ? `?${query}` : "";
108
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
351
+ const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
352
+ return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
353
+ }, {});
354
+ return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
109
355
  };
110
356
  function buildBaseUrl({
357
+ endpoint,
111
358
  path,
112
359
  workspacesApiUrl,
113
360
  apiUrl,
114
- pathParams
361
+ pathParams = {}
115
362
  }) {
116
- if (!pathParams?.workspace)
117
- return `${apiUrl}${path}`;
118
- const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
119
- return url.replace("{workspaceId}", pathParams.workspace);
363
+ if (endpoint === "dataPlane") {
364
+ const url = isString(workspacesApiUrl) ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
365
+ const urlWithWorkspace = isString(pathParams.workspace) ? url.replace("{workspaceId}", String(pathParams.workspace)) : url;
366
+ return isString(pathParams.region) ? urlWithWorkspace.replace("{region}", String(pathParams.region)) : urlWithWorkspace;
367
+ }
368
+ return `${apiUrl}${path}`;
120
369
  }
121
370
  function hostHeader(url) {
122
371
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -132,255 +381,236 @@ async function fetch$1({
132
381
  queryParams,
133
382
  fetchImpl,
134
383
  apiKey,
384
+ endpoint,
135
385
  apiUrl,
136
- workspacesApiUrl
386
+ workspacesApiUrl,
387
+ trace,
388
+ signal,
389
+ clientID,
390
+ sessionID,
391
+ fetchOptions = {}
137
392
  }) {
138
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
139
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
140
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
141
- const response = await fetchImpl(url, {
142
- method: method.toUpperCase(),
143
- body: body ? JSON.stringify(body) : void 0,
144
- headers: {
145
- "Content-Type": "application/json",
146
- ...headers,
147
- ...hostHeader(fullUrl),
148
- Authorization: `Bearer ${apiKey}`
149
- }
150
- });
151
- if (response.status === 204) {
152
- return {};
153
- }
393
+ pool.setFetch(fetchImpl);
394
+ return await trace(
395
+ `${method.toUpperCase()} ${path}`,
396
+ async ({ setAttributes }) => {
397
+ const baseUrl = buildBaseUrl({ endpoint, path, workspacesApiUrl, pathParams, apiUrl });
398
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
399
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
400
+ setAttributes({
401
+ [TraceAttributes.HTTP_URL]: url,
402
+ [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
403
+ });
404
+ const response = await pool.request(url, {
405
+ ...fetchOptions,
406
+ method: method.toUpperCase(),
407
+ body: body ? JSON.stringify(body) : void 0,
408
+ headers: {
409
+ "Content-Type": "application/json",
410
+ "User-Agent": `Xata client-ts/${VERSION}`,
411
+ "X-Xata-Client-ID": clientID ?? "",
412
+ "X-Xata-Session-ID": sessionID ?? "",
413
+ ...headers,
414
+ ...hostHeader(fullUrl),
415
+ Authorization: `Bearer ${apiKey}`
416
+ },
417
+ signal
418
+ });
419
+ const { host, protocol } = parseUrl(response.url);
420
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
421
+ setAttributes({
422
+ [TraceAttributes.KIND]: "http",
423
+ [TraceAttributes.HTTP_REQUEST_ID]: requestId,
424
+ [TraceAttributes.HTTP_STATUS_CODE]: response.status,
425
+ [TraceAttributes.HTTP_HOST]: host,
426
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
427
+ });
428
+ if (response.status === 204) {
429
+ return {};
430
+ }
431
+ if (response.status === 429) {
432
+ throw new FetcherError(response.status, "Rate limit exceeded", requestId);
433
+ }
434
+ try {
435
+ const jsonResponse = await response.json();
436
+ if (response.ok) {
437
+ return jsonResponse;
438
+ }
439
+ throw new FetcherError(response.status, jsonResponse, requestId);
440
+ } catch (error) {
441
+ throw new FetcherError(response.status, error, requestId);
442
+ }
443
+ },
444
+ { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
445
+ );
446
+ }
447
+ function parseUrl(url) {
154
448
  try {
155
- const jsonResponse = await response.json();
156
- if (response.ok) {
157
- return jsonResponse;
158
- }
159
- throw new FetcherError(response.status, jsonResponse);
449
+ const { host, protocol } = new URL(url);
450
+ return { host, protocol };
160
451
  } catch (error) {
161
- throw new FetcherError(response.status, error);
452
+ return {};
162
453
  }
163
454
  }
164
455
 
165
- const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
166
- const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
167
- const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
168
- const getUserAPIKeys = (variables) => fetch$1({
169
- url: "/user/keys",
170
- method: "get",
171
- ...variables
172
- });
173
- const createUserAPIKey = (variables) => fetch$1({
174
- url: "/user/keys/{keyName}",
175
- method: "post",
176
- ...variables
177
- });
178
- const deleteUserAPIKey = (variables) => fetch$1({
179
- url: "/user/keys/{keyName}",
180
- method: "delete",
181
- ...variables
182
- });
183
- const createWorkspace = (variables) => fetch$1({
184
- url: "/workspaces",
185
- method: "post",
186
- ...variables
187
- });
188
- const getWorkspacesList = (variables) => fetch$1({
189
- url: "/workspaces",
190
- method: "get",
191
- ...variables
192
- });
193
- const getWorkspace = (variables) => fetch$1({
194
- url: "/workspaces/{workspaceId}",
195
- method: "get",
196
- ...variables
197
- });
198
- const updateWorkspace = (variables) => fetch$1({
199
- url: "/workspaces/{workspaceId}",
200
- method: "put",
201
- ...variables
202
- });
203
- const deleteWorkspace = (variables) => fetch$1({
204
- url: "/workspaces/{workspaceId}",
205
- method: "delete",
206
- ...variables
207
- });
208
- const getWorkspaceMembersList = (variables) => fetch$1({
209
- url: "/workspaces/{workspaceId}/members",
210
- method: "get",
211
- ...variables
212
- });
213
- const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
214
- const removeWorkspaceMember = (variables) => fetch$1({
215
- url: "/workspaces/{workspaceId}/members/{userId}",
216
- method: "delete",
217
- ...variables
218
- });
219
- const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
220
- const cancelWorkspaceMemberInvite = (variables) => fetch$1({
221
- url: "/workspaces/{workspaceId}/invites/{inviteId}",
222
- method: "delete",
223
- ...variables
224
- });
225
- const resendWorkspaceMemberInvite = (variables) => fetch$1({
226
- url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
227
- method: "post",
228
- ...variables
229
- });
230
- const acceptWorkspaceMemberInvite = (variables) => fetch$1({
231
- url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
232
- method: "post",
233
- ...variables
234
- });
235
- const getDatabaseList = (variables) => fetch$1({
236
- url: "/dbs",
237
- method: "get",
238
- ...variables
239
- });
240
- const getBranchList = (variables) => fetch$1({
456
+ const dataPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "dataPlane" });
457
+
458
+ const dEPRECATEDgetDatabaseList = (variables, signal) => dataPlaneFetch({ url: "/dbs", method: "get", ...variables, signal });
459
+ const getBranchList = (variables, signal) => dataPlaneFetch({
241
460
  url: "/dbs/{dbName}",
242
461
  method: "get",
243
- ...variables
244
- });
245
- const createDatabase = (variables) => fetch$1({
246
- url: "/dbs/{dbName}",
247
- method: "put",
248
- ...variables
249
- });
250
- const deleteDatabase = (variables) => fetch$1({
251
- url: "/dbs/{dbName}",
252
- method: "delete",
253
- ...variables
462
+ ...variables,
463
+ signal
254
464
  });
255
- const getBranchDetails = (variables) => fetch$1({
465
+ const dEPRECATEDcreateDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "put", ...variables, signal });
466
+ const dEPRECATEDdeleteDatabase = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}", method: "delete", ...variables, signal });
467
+ const dEPRECATEDgetDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "get", ...variables, signal });
468
+ const dEPRECATEDupdateDatabaseMetadata = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables, signal });
469
+ const getBranchDetails = (variables, signal) => dataPlaneFetch({
256
470
  url: "/db/{dbBranchName}",
257
471
  method: "get",
258
- ...variables
472
+ ...variables,
473
+ signal
259
474
  });
260
- const createBranch = (variables) => fetch$1({
261
- url: "/db/{dbBranchName}",
262
- method: "put",
263
- ...variables
264
- });
265
- const deleteBranch = (variables) => fetch$1({
475
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
476
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
266
477
  url: "/db/{dbBranchName}",
267
478
  method: "delete",
268
- ...variables
479
+ ...variables,
480
+ signal
269
481
  });
270
- const updateBranchMetadata = (variables) => fetch$1({
482
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
271
483
  url: "/db/{dbBranchName}/metadata",
272
484
  method: "put",
273
- ...variables
485
+ ...variables,
486
+ signal
274
487
  });
275
- const getBranchMetadata = (variables) => fetch$1({
488
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
276
489
  url: "/db/{dbBranchName}/metadata",
277
490
  method: "get",
278
- ...variables
491
+ ...variables,
492
+ signal
279
493
  });
280
- const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
281
- const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
282
- const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
283
- const getBranchStats = (variables) => fetch$1({
494
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
284
495
  url: "/db/{dbBranchName}/stats",
285
496
  method: "get",
286
- ...variables
497
+ ...variables,
498
+ signal
499
+ });
500
+ const getGitBranchesMapping = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables, signal });
501
+ const addGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables, signal });
502
+ const removeGitBranchesEntry = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables, signal });
503
+ const resolveBranch = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/resolveBranch", method: "get", ...variables, signal });
504
+ const getBranchMigrationHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables, signal });
505
+ const getBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables, signal });
506
+ const executeBranchMigrationPlan = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables, signal });
507
+ const branchTransaction = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/transaction", method: "post", ...variables, signal });
508
+ const queryMigrationRequests = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables, signal });
509
+ const createMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations", method: "post", ...variables, signal });
510
+ const getMigrationRequest = (variables, signal) => dataPlaneFetch({
511
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
512
+ method: "get",
513
+ ...variables,
514
+ signal
515
+ });
516
+ const updateMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables, signal });
517
+ const listMigrationRequestsCommits = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables, signal });
518
+ const compareMigrationRequest = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables, signal });
519
+ const getMigrationRequestIsMerged = (variables, signal) => dataPlaneFetch({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables, signal });
520
+ const mergeMigrationRequest = (variables, signal) => dataPlaneFetch({
521
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
522
+ method: "post",
523
+ ...variables,
524
+ signal
287
525
  });
288
- const createTable = (variables) => fetch$1({
526
+ const getBranchSchemaHistory = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables, signal });
527
+ const compareBranchWithUserSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables, signal });
528
+ const compareBranchSchemas = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables, signal });
529
+ const updateBranchSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/update", method: "post", ...variables, signal });
530
+ const previewBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables, signal });
531
+ const applyBranchSchemaEdit = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables, signal });
532
+ const createTable = (variables, signal) => dataPlaneFetch({
289
533
  url: "/db/{dbBranchName}/tables/{tableName}",
290
534
  method: "put",
291
- ...variables
535
+ ...variables,
536
+ signal
292
537
  });
293
- const deleteTable = (variables) => fetch$1({
538
+ const deleteTable = (variables, signal) => dataPlaneFetch({
294
539
  url: "/db/{dbBranchName}/tables/{tableName}",
295
540
  method: "delete",
296
- ...variables
297
- });
298
- const updateTable = (variables) => fetch$1({
299
- url: "/db/{dbBranchName}/tables/{tableName}",
300
- method: "patch",
301
- ...variables
541
+ ...variables,
542
+ signal
302
543
  });
303
- const getTableSchema = (variables) => fetch$1({
544
+ const updateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}", method: "patch", ...variables, signal });
545
+ const getTableSchema = (variables, signal) => dataPlaneFetch({
304
546
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
305
547
  method: "get",
306
- ...variables
307
- });
308
- const setTableSchema = (variables) => fetch$1({
309
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
310
- method: "put",
311
- ...variables
548
+ ...variables,
549
+ signal
312
550
  });
313
- const getTableColumns = (variables) => fetch$1({
551
+ const setTableSchema = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/schema", method: "put", ...variables, signal });
552
+ const getTableColumns = (variables, signal) => dataPlaneFetch({
314
553
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
315
554
  method: "get",
316
- ...variables
555
+ ...variables,
556
+ signal
317
557
  });
318
- const addTableColumn = (variables) => fetch$1({
319
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
320
- method: "post",
321
- ...variables
322
- });
323
- const getColumn = (variables) => fetch$1({
558
+ const addTableColumn = (variables, signal) => dataPlaneFetch(
559
+ { url: "/db/{dbBranchName}/tables/{tableName}/columns", method: "post", ...variables, signal }
560
+ );
561
+ const getColumn = (variables, signal) => dataPlaneFetch({
324
562
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
325
563
  method: "get",
326
- ...variables
564
+ ...variables,
565
+ signal
327
566
  });
328
- const deleteColumn = (variables) => fetch$1({
567
+ const updateColumn = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}", method: "patch", ...variables, signal });
568
+ const deleteColumn = (variables, signal) => dataPlaneFetch({
329
569
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
330
570
  method: "delete",
331
- ...variables
571
+ ...variables,
572
+ signal
332
573
  });
333
- const updateColumn = (variables) => fetch$1({
334
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
335
- method: "patch",
336
- ...variables
337
- });
338
- const insertRecord = (variables) => fetch$1({
339
- url: "/db/{dbBranchName}/tables/{tableName}/data",
340
- method: "post",
341
- ...variables
342
- });
343
- const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
344
- const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
345
- const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
346
- const deleteRecord = (variables) => fetch$1({
347
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
348
- method: "delete",
349
- ...variables
350
- });
351
- const getRecord = (variables) => fetch$1({
574
+ const insertRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables, signal });
575
+ const getRecord = (variables, signal) => dataPlaneFetch({
352
576
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
353
577
  method: "get",
354
- ...variables
578
+ ...variables,
579
+ signal
355
580
  });
356
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
357
- const queryTable = (variables) => fetch$1({
581
+ const insertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables, signal });
582
+ const updateRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables, signal });
583
+ const upsertRecordWithID = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables, signal });
584
+ const deleteRecord = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "delete", ...variables, signal });
585
+ const bulkInsertTableRecords = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables, signal });
586
+ const queryTable = (variables, signal) => dataPlaneFetch({
358
587
  url: "/db/{dbBranchName}/tables/{tableName}/query",
359
588
  method: "post",
360
- ...variables
589
+ ...variables,
590
+ signal
361
591
  });
362
- const searchBranch = (variables) => fetch$1({
592
+ const searchBranch = (variables, signal) => dataPlaneFetch({
363
593
  url: "/db/{dbBranchName}/search",
364
594
  method: "post",
365
- ...variables
595
+ ...variables,
596
+ signal
366
597
  });
367
- const operationsByTag = {
368
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
369
- workspaces: {
370
- createWorkspace,
371
- getWorkspacesList,
372
- getWorkspace,
373
- updateWorkspace,
374
- deleteWorkspace,
375
- getWorkspaceMembersList,
376
- updateWorkspaceMemberRole,
377
- removeWorkspaceMember,
378
- inviteWorkspaceMember,
379
- cancelWorkspaceMemberInvite,
380
- resendWorkspaceMemberInvite,
381
- acceptWorkspaceMemberInvite
598
+ const searchTable = (variables, signal) => dataPlaneFetch({
599
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
600
+ method: "post",
601
+ ...variables,
602
+ signal
603
+ });
604
+ const summarizeTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/summarize", method: "post", ...variables, signal });
605
+ const aggregateTable = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}/tables/{tableName}/aggregate", method: "post", ...variables, signal });
606
+ const operationsByTag$2 = {
607
+ database: {
608
+ dEPRECATEDgetDatabaseList,
609
+ dEPRECATEDcreateDatabase,
610
+ dEPRECATEDdeleteDatabase,
611
+ dEPRECATEDgetDatabaseMetadata,
612
+ dEPRECATEDupdateDatabaseMetadata
382
613
  },
383
- database: { getDatabaseList, createDatabase, deleteDatabase },
384
614
  branch: {
385
615
  getBranchList,
386
616
  getBranchDetails,
@@ -388,10 +618,42 @@ const operationsByTag = {
388
618
  deleteBranch,
389
619
  updateBranchMetadata,
390
620
  getBranchMetadata,
621
+ getBranchStats,
622
+ getGitBranchesMapping,
623
+ addGitBranchesEntry,
624
+ removeGitBranchesEntry,
625
+ resolveBranch
626
+ },
627
+ migrations: {
391
628
  getBranchMigrationHistory,
392
- executeBranchMigrationPlan,
393
629
  getBranchMigrationPlan,
394
- getBranchStats
630
+ executeBranchMigrationPlan,
631
+ getBranchSchemaHistory,
632
+ compareBranchWithUserSchema,
633
+ compareBranchSchemas,
634
+ updateBranchSchema,
635
+ previewBranchSchemaEdit,
636
+ applyBranchSchemaEdit
637
+ },
638
+ records: {
639
+ branchTransaction,
640
+ insertRecord,
641
+ getRecord,
642
+ insertRecordWithID,
643
+ updateRecordWithID,
644
+ upsertRecordWithID,
645
+ deleteRecord,
646
+ bulkInsertTableRecords
647
+ },
648
+ migrationRequests: {
649
+ queryMigrationRequests,
650
+ createMigrationRequest,
651
+ getMigrationRequest,
652
+ updateMigrationRequest,
653
+ listMigrationRequestsCommits,
654
+ compareMigrationRequest,
655
+ getMigrationRequestIsMerged,
656
+ mergeMigrationRequest
395
657
  },
396
658
  table: {
397
659
  createTable,
@@ -402,26 +664,150 @@ const operationsByTag = {
402
664
  getTableColumns,
403
665
  addTableColumn,
404
666
  getColumn,
405
- deleteColumn,
406
- updateColumn
667
+ updateColumn,
668
+ deleteColumn
407
669
  },
408
- records: {
409
- insertRecord,
410
- insertRecordWithID,
411
- updateRecordWithID,
412
- upsertRecordWithID,
413
- deleteRecord,
414
- getRecord,
415
- bulkInsertTableRecords,
416
- queryTable,
417
- searchBranch
670
+ searchAndFilter: { queryTable, searchBranch, searchTable, summarizeTable, aggregateTable }
671
+ };
672
+
673
+ const controlPlaneFetch = async (options) => fetch$1({ ...options, endpoint: "controlPlane" });
674
+
675
+ const getUser = (variables, signal) => controlPlaneFetch({
676
+ url: "/user",
677
+ method: "get",
678
+ ...variables,
679
+ signal
680
+ });
681
+ const updateUser = (variables, signal) => controlPlaneFetch({
682
+ url: "/user",
683
+ method: "put",
684
+ ...variables,
685
+ signal
686
+ });
687
+ const deleteUser = (variables, signal) => controlPlaneFetch({
688
+ url: "/user",
689
+ method: "delete",
690
+ ...variables,
691
+ signal
692
+ });
693
+ const getUserAPIKeys = (variables, signal) => controlPlaneFetch({
694
+ url: "/user/keys",
695
+ method: "get",
696
+ ...variables,
697
+ signal
698
+ });
699
+ const createUserAPIKey = (variables, signal) => controlPlaneFetch({
700
+ url: "/user/keys/{keyName}",
701
+ method: "post",
702
+ ...variables,
703
+ signal
704
+ });
705
+ const deleteUserAPIKey = (variables, signal) => controlPlaneFetch({
706
+ url: "/user/keys/{keyName}",
707
+ method: "delete",
708
+ ...variables,
709
+ signal
710
+ });
711
+ const getWorkspacesList = (variables, signal) => controlPlaneFetch({
712
+ url: "/workspaces",
713
+ method: "get",
714
+ ...variables,
715
+ signal
716
+ });
717
+ const createWorkspace = (variables, signal) => controlPlaneFetch({
718
+ url: "/workspaces",
719
+ method: "post",
720
+ ...variables,
721
+ signal
722
+ });
723
+ const getWorkspace = (variables, signal) => controlPlaneFetch({
724
+ url: "/workspaces/{workspaceId}",
725
+ method: "get",
726
+ ...variables,
727
+ signal
728
+ });
729
+ const updateWorkspace = (variables, signal) => controlPlaneFetch({
730
+ url: "/workspaces/{workspaceId}",
731
+ method: "put",
732
+ ...variables,
733
+ signal
734
+ });
735
+ const deleteWorkspace = (variables, signal) => controlPlaneFetch({
736
+ url: "/workspaces/{workspaceId}",
737
+ method: "delete",
738
+ ...variables,
739
+ signal
740
+ });
741
+ const getWorkspaceMembersList = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members", method: "get", ...variables, signal });
742
+ const updateWorkspaceMemberRole = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables, signal });
743
+ const removeWorkspaceMember = (variables, signal) => controlPlaneFetch({
744
+ url: "/workspaces/{workspaceId}/members/{userId}",
745
+ method: "delete",
746
+ ...variables,
747
+ signal
748
+ });
749
+ const inviteWorkspaceMember = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables, signal });
750
+ const updateWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables, signal });
751
+ const cancelWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "delete", ...variables, signal });
752
+ const acceptWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept", method: "post", ...variables, signal });
753
+ const resendWorkspaceMemberInvite = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend", method: "post", ...variables, signal });
754
+ const getDatabaseList = (variables, signal) => controlPlaneFetch({
755
+ url: "/workspaces/{workspaceId}/dbs",
756
+ method: "get",
757
+ ...variables,
758
+ signal
759
+ });
760
+ const createDatabase = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "put", ...variables, signal });
761
+ const deleteDatabase = (variables, signal) => controlPlaneFetch({
762
+ url: "/workspaces/{workspaceId}/dbs/{dbName}",
763
+ method: "delete",
764
+ ...variables,
765
+ signal
766
+ });
767
+ const getDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "get", ...variables, signal });
768
+ const updateDatabaseMetadata = (variables, signal) => controlPlaneFetch({ url: "/workspaces/{workspaceId}/dbs/{dbName}", method: "patch", ...variables, signal });
769
+ const listRegions = (variables, signal) => controlPlaneFetch({
770
+ url: "/workspaces/{workspaceId}/regions",
771
+ method: "get",
772
+ ...variables,
773
+ signal
774
+ });
775
+ const operationsByTag$1 = {
776
+ users: { getUser, updateUser, deleteUser },
777
+ authentication: { getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
778
+ workspaces: {
779
+ getWorkspacesList,
780
+ createWorkspace,
781
+ getWorkspace,
782
+ updateWorkspace,
783
+ deleteWorkspace,
784
+ getWorkspaceMembersList,
785
+ updateWorkspaceMemberRole,
786
+ removeWorkspaceMember
787
+ },
788
+ invites: {
789
+ inviteWorkspaceMember,
790
+ updateWorkspaceMemberInvite,
791
+ cancelWorkspaceMemberInvite,
792
+ acceptWorkspaceMemberInvite,
793
+ resendWorkspaceMemberInvite
794
+ },
795
+ databases: {
796
+ getDatabaseList,
797
+ createDatabase,
798
+ deleteDatabase,
799
+ getDatabaseMetadata,
800
+ updateDatabaseMetadata,
801
+ listRegions
418
802
  }
419
803
  };
420
804
 
805
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
806
+
421
807
  function getHostUrl(provider, type) {
422
- if (isValidAlias(provider)) {
808
+ if (isHostProviderAlias(provider)) {
423
809
  return providers[provider][type];
424
- } else if (isValidBuilder(provider)) {
810
+ } else if (isHostProviderBuilder(provider)) {
425
811
  return provider[type];
426
812
  }
427
813
  throw new Error("Invalid API provider");
@@ -429,25 +815,44 @@ function getHostUrl(provider, type) {
429
815
  const providers = {
430
816
  production: {
431
817
  main: "https://api.xata.io",
432
- workspaces: "https://{workspaceId}.xata.sh"
818
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
433
819
  },
434
820
  staging: {
435
821
  main: "https://staging.xatabase.co",
436
- workspaces: "https://{workspaceId}.staging.xatabase.co"
822
+ workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
437
823
  }
438
824
  };
439
- function isValidAlias(alias) {
825
+ function isHostProviderAlias(alias) {
440
826
  return isString(alias) && Object.keys(providers).includes(alias);
441
827
  }
442
- function isValidBuilder(builder) {
828
+ function isHostProviderBuilder(builder) {
443
829
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
444
830
  }
831
+ function parseProviderString(provider = "production") {
832
+ if (isHostProviderAlias(provider)) {
833
+ return provider;
834
+ }
835
+ const [main, workspaces] = provider.split(",");
836
+ if (!main || !workspaces)
837
+ return null;
838
+ return { main, workspaces };
839
+ }
840
+ function parseWorkspacesUrlParts(url) {
841
+ if (!isString(url))
842
+ return null;
843
+ const regex = /(?:https:\/\/)?([^.]+)(?:\.([^.]+))?\.xata\.sh.*/;
844
+ const regexStaging = /(?:https:\/\/)?([^.]+)\.staging(?:\.([^.]+))?\.xatabase\.co.*/;
845
+ const match = url.match(regex) || url.match(regexStaging);
846
+ if (!match)
847
+ return null;
848
+ return { workspace: match[1], region: match[2] ?? "eu-west-1" };
849
+ }
445
850
 
446
851
  var __accessCheck$7 = (obj, member, msg) => {
447
852
  if (!member.has(obj))
448
853
  throw TypeError("Cannot " + msg);
449
854
  };
450
- var __privateGet$6 = (obj, member, getter) => {
855
+ var __privateGet$7 = (obj, member, getter) => {
451
856
  __accessCheck$7(obj, member, "read from private field");
452
857
  return getter ? getter.call(obj) : member.get(obj);
453
858
  };
@@ -456,7 +861,7 @@ var __privateAdd$7 = (obj, member, value) => {
456
861
  throw TypeError("Cannot add the same private member more than once");
457
862
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
458
863
  };
459
- var __privateSet$5 = (obj, member, value, setter) => {
864
+ var __privateSet$7 = (obj, member, value, setter) => {
460
865
  __accessCheck$7(obj, member, "write to private field");
461
866
  setter ? setter.call(obj, value) : member.set(obj, value);
462
867
  return value;
@@ -467,46 +872,73 @@ class XataApiClient {
467
872
  __privateAdd$7(this, _extraProps, void 0);
468
873
  __privateAdd$7(this, _namespaces, {});
469
874
  const provider = options.host ?? "production";
470
- const apiKey = options?.apiKey ?? getAPIKey();
875
+ const apiKey = options.apiKey ?? getAPIKey();
876
+ const trace = options.trace ?? defaultTrace;
471
877
  if (!apiKey) {
472
878
  throw new Error("Could not resolve a valid apiKey");
473
879
  }
474
- __privateSet$5(this, _extraProps, {
880
+ __privateSet$7(this, _extraProps, {
475
881
  apiUrl: getHostUrl(provider, "main"),
476
882
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
477
883
  fetchImpl: getFetchImplementation(options.fetch),
478
- apiKey
884
+ apiKey,
885
+ trace
479
886
  });
480
887
  }
481
888
  get user() {
482
- if (!__privateGet$6(this, _namespaces).user)
483
- __privateGet$6(this, _namespaces).user = new UserApi(__privateGet$6(this, _extraProps));
484
- return __privateGet$6(this, _namespaces).user;
889
+ if (!__privateGet$7(this, _namespaces).user)
890
+ __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
891
+ return __privateGet$7(this, _namespaces).user;
892
+ }
893
+ get authentication() {
894
+ if (!__privateGet$7(this, _namespaces).authentication)
895
+ __privateGet$7(this, _namespaces).authentication = new AuthenticationApi(__privateGet$7(this, _extraProps));
896
+ return __privateGet$7(this, _namespaces).authentication;
485
897
  }
486
898
  get workspaces() {
487
- if (!__privateGet$6(this, _namespaces).workspaces)
488
- __privateGet$6(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$6(this, _extraProps));
489
- return __privateGet$6(this, _namespaces).workspaces;
899
+ if (!__privateGet$7(this, _namespaces).workspaces)
900
+ __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
901
+ return __privateGet$7(this, _namespaces).workspaces;
490
902
  }
491
- get databases() {
492
- if (!__privateGet$6(this, _namespaces).databases)
493
- __privateGet$6(this, _namespaces).databases = new DatabaseApi(__privateGet$6(this, _extraProps));
494
- return __privateGet$6(this, _namespaces).databases;
903
+ get invites() {
904
+ if (!__privateGet$7(this, _namespaces).invites)
905
+ __privateGet$7(this, _namespaces).invites = new InvitesApi(__privateGet$7(this, _extraProps));
906
+ return __privateGet$7(this, _namespaces).invites;
907
+ }
908
+ get database() {
909
+ if (!__privateGet$7(this, _namespaces).database)
910
+ __privateGet$7(this, _namespaces).database = new DatabaseApi(__privateGet$7(this, _extraProps));
911
+ return __privateGet$7(this, _namespaces).database;
495
912
  }
496
913
  get branches() {
497
- if (!__privateGet$6(this, _namespaces).branches)
498
- __privateGet$6(this, _namespaces).branches = new BranchApi(__privateGet$6(this, _extraProps));
499
- return __privateGet$6(this, _namespaces).branches;
914
+ if (!__privateGet$7(this, _namespaces).branches)
915
+ __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
916
+ return __privateGet$7(this, _namespaces).branches;
917
+ }
918
+ get migrations() {
919
+ if (!__privateGet$7(this, _namespaces).migrations)
920
+ __privateGet$7(this, _namespaces).migrations = new MigrationsApi(__privateGet$7(this, _extraProps));
921
+ return __privateGet$7(this, _namespaces).migrations;
922
+ }
923
+ get migrationRequests() {
924
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
925
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
926
+ return __privateGet$7(this, _namespaces).migrationRequests;
500
927
  }
501
928
  get tables() {
502
- if (!__privateGet$6(this, _namespaces).tables)
503
- __privateGet$6(this, _namespaces).tables = new TableApi(__privateGet$6(this, _extraProps));
504
- return __privateGet$6(this, _namespaces).tables;
929
+ if (!__privateGet$7(this, _namespaces).tables)
930
+ __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
931
+ return __privateGet$7(this, _namespaces).tables;
505
932
  }
506
933
  get records() {
507
- if (!__privateGet$6(this, _namespaces).records)
508
- __privateGet$6(this, _namespaces).records = new RecordsApi(__privateGet$6(this, _extraProps));
509
- return __privateGet$6(this, _namespaces).records;
934
+ if (!__privateGet$7(this, _namespaces).records)
935
+ __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
936
+ return __privateGet$7(this, _namespaces).records;
937
+ }
938
+ get searchAndFilter() {
939
+ if (!__privateGet$7(this, _namespaces).searchAndFilter)
940
+ __privateGet$7(this, _namespaces).searchAndFilter = new SearchAndFilterApi(__privateGet$7(this, _extraProps));
941
+ return __privateGet$7(this, _namespaces).searchAndFilter;
510
942
  }
511
943
  }
512
944
  _extraProps = new WeakMap();
@@ -518,24 +950,29 @@ class UserApi {
518
950
  getUser() {
519
951
  return operationsByTag.users.getUser({ ...this.extraProps });
520
952
  }
521
- updateUser(user) {
953
+ updateUser({ user }) {
522
954
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
523
955
  }
524
956
  deleteUser() {
525
957
  return operationsByTag.users.deleteUser({ ...this.extraProps });
526
958
  }
959
+ }
960
+ class AuthenticationApi {
961
+ constructor(extraProps) {
962
+ this.extraProps = extraProps;
963
+ }
527
964
  getUserAPIKeys() {
528
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
965
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
529
966
  }
530
- createUserAPIKey(keyName) {
531
- return operationsByTag.users.createUserAPIKey({
532
- pathParams: { keyName },
967
+ createUserAPIKey({ name }) {
968
+ return operationsByTag.authentication.createUserAPIKey({
969
+ pathParams: { keyName: name },
533
970
  ...this.extraProps
534
971
  });
535
972
  }
536
- deleteUserAPIKey(keyName) {
537
- return operationsByTag.users.deleteUserAPIKey({
538
- pathParams: { keyName },
973
+ deleteUserAPIKey({ name }) {
974
+ return operationsByTag.authentication.deleteUserAPIKey({
975
+ pathParams: { keyName: name },
539
976
  ...this.extraProps
540
977
  });
541
978
  }
@@ -544,99 +981,114 @@ class WorkspaceApi {
544
981
  constructor(extraProps) {
545
982
  this.extraProps = extraProps;
546
983
  }
547
- createWorkspace(workspaceMeta) {
984
+ getWorkspacesList() {
985
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
986
+ }
987
+ createWorkspace({ data }) {
548
988
  return operationsByTag.workspaces.createWorkspace({
549
- body: workspaceMeta,
989
+ body: data,
550
990
  ...this.extraProps
551
991
  });
552
992
  }
553
- getWorkspacesList() {
554
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
555
- }
556
- getWorkspace(workspaceId) {
993
+ getWorkspace({ workspace }) {
557
994
  return operationsByTag.workspaces.getWorkspace({
558
- pathParams: { workspaceId },
995
+ pathParams: { workspaceId: workspace },
559
996
  ...this.extraProps
560
997
  });
561
998
  }
562
- updateWorkspace(workspaceId, workspaceMeta) {
999
+ updateWorkspace({
1000
+ workspace,
1001
+ update
1002
+ }) {
563
1003
  return operationsByTag.workspaces.updateWorkspace({
564
- pathParams: { workspaceId },
565
- body: workspaceMeta,
1004
+ pathParams: { workspaceId: workspace },
1005
+ body: update,
566
1006
  ...this.extraProps
567
1007
  });
568
1008
  }
569
- deleteWorkspace(workspaceId) {
1009
+ deleteWorkspace({ workspace }) {
570
1010
  return operationsByTag.workspaces.deleteWorkspace({
571
- pathParams: { workspaceId },
1011
+ pathParams: { workspaceId: workspace },
572
1012
  ...this.extraProps
573
1013
  });
574
1014
  }
575
- getWorkspaceMembersList(workspaceId) {
1015
+ getWorkspaceMembersList({ workspace }) {
576
1016
  return operationsByTag.workspaces.getWorkspaceMembersList({
577
- pathParams: { workspaceId },
1017
+ pathParams: { workspaceId: workspace },
578
1018
  ...this.extraProps
579
1019
  });
580
1020
  }
581
- updateWorkspaceMemberRole(workspaceId, userId, role) {
1021
+ updateWorkspaceMemberRole({
1022
+ workspace,
1023
+ user,
1024
+ role
1025
+ }) {
582
1026
  return operationsByTag.workspaces.updateWorkspaceMemberRole({
583
- pathParams: { workspaceId, userId },
1027
+ pathParams: { workspaceId: workspace, userId: user },
584
1028
  body: { role },
585
1029
  ...this.extraProps
586
1030
  });
587
1031
  }
588
- removeWorkspaceMember(workspaceId, userId) {
1032
+ removeWorkspaceMember({
1033
+ workspace,
1034
+ user
1035
+ }) {
589
1036
  return operationsByTag.workspaces.removeWorkspaceMember({
590
- pathParams: { workspaceId, userId },
591
- ...this.extraProps
592
- });
593
- }
594
- inviteWorkspaceMember(workspaceId, email, role) {
595
- return operationsByTag.workspaces.inviteWorkspaceMember({
596
- pathParams: { workspaceId },
597
- body: { email, role },
1037
+ pathParams: { workspaceId: workspace, userId: user },
598
1038
  ...this.extraProps
599
1039
  });
600
1040
  }
601
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
602
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
603
- pathParams: { workspaceId, inviteId },
604
- ...this.extraProps
605
- });
1041
+ }
1042
+ class InvitesApi {
1043
+ constructor(extraProps) {
1044
+ this.extraProps = extraProps;
606
1045
  }
607
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
608
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
609
- pathParams: { workspaceId, inviteId },
1046
+ inviteWorkspaceMember({
1047
+ workspace,
1048
+ email,
1049
+ role
1050
+ }) {
1051
+ return operationsByTag.invites.inviteWorkspaceMember({
1052
+ pathParams: { workspaceId: workspace },
1053
+ body: { email, role },
610
1054
  ...this.extraProps
611
1055
  });
612
1056
  }
613
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
614
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
615
- pathParams: { workspaceId, inviteKey },
1057
+ updateWorkspaceMemberInvite({
1058
+ workspace,
1059
+ invite,
1060
+ role
1061
+ }) {
1062
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
1063
+ pathParams: { workspaceId: workspace, inviteId: invite },
1064
+ body: { role },
616
1065
  ...this.extraProps
617
1066
  });
618
1067
  }
619
- }
620
- class DatabaseApi {
621
- constructor(extraProps) {
622
- this.extraProps = extraProps;
623
- }
624
- getDatabaseList(workspace) {
625
- return operationsByTag.database.getDatabaseList({
626
- pathParams: { workspace },
1068
+ cancelWorkspaceMemberInvite({
1069
+ workspace,
1070
+ invite
1071
+ }) {
1072
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
1073
+ pathParams: { workspaceId: workspace, inviteId: invite },
627
1074
  ...this.extraProps
628
1075
  });
629
1076
  }
630
- createDatabase(workspace, dbName, options = {}) {
631
- return operationsByTag.database.createDatabase({
632
- pathParams: { workspace, dbName },
633
- body: options,
1077
+ acceptWorkspaceMemberInvite({
1078
+ workspace,
1079
+ key
1080
+ }) {
1081
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
1082
+ pathParams: { workspaceId: workspace, inviteKey: key },
634
1083
  ...this.extraProps
635
1084
  });
636
1085
  }
637
- deleteDatabase(workspace, dbName) {
638
- return operationsByTag.database.deleteDatabase({
639
- pathParams: { workspace, dbName },
1086
+ resendWorkspaceMemberInvite({
1087
+ workspace,
1088
+ invite
1089
+ }) {
1090
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
1091
+ pathParams: { workspaceId: workspace, inviteId: invite },
640
1092
  ...this.extraProps
641
1093
  });
642
1094
  }
@@ -645,69 +1097,132 @@ class BranchApi {
645
1097
  constructor(extraProps) {
646
1098
  this.extraProps = extraProps;
647
1099
  }
648
- getBranchList(workspace, dbName) {
1100
+ getBranchList({
1101
+ workspace,
1102
+ region,
1103
+ database
1104
+ }) {
649
1105
  return operationsByTag.branch.getBranchList({
650
- pathParams: { workspace, dbName },
1106
+ pathParams: { workspace, region, dbName: database },
651
1107
  ...this.extraProps
652
1108
  });
653
1109
  }
654
- getBranchDetails(workspace, database, branch) {
1110
+ getBranchDetails({
1111
+ workspace,
1112
+ region,
1113
+ database,
1114
+ branch
1115
+ }) {
655
1116
  return operationsByTag.branch.getBranchDetails({
656
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1117
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
657
1118
  ...this.extraProps
658
1119
  });
659
1120
  }
660
- createBranch(workspace, database, branch, from = "", options = {}) {
1121
+ createBranch({
1122
+ workspace,
1123
+ region,
1124
+ database,
1125
+ branch,
1126
+ from,
1127
+ metadata
1128
+ }) {
661
1129
  return operationsByTag.branch.createBranch({
662
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
663
- queryParams: { from },
664
- body: options,
1130
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1131
+ body: { from, metadata },
665
1132
  ...this.extraProps
666
1133
  });
667
1134
  }
668
- deleteBranch(workspace, database, branch) {
1135
+ deleteBranch({
1136
+ workspace,
1137
+ region,
1138
+ database,
1139
+ branch
1140
+ }) {
669
1141
  return operationsByTag.branch.deleteBranch({
670
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1142
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
671
1143
  ...this.extraProps
672
1144
  });
673
1145
  }
674
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
1146
+ updateBranchMetadata({
1147
+ workspace,
1148
+ region,
1149
+ database,
1150
+ branch,
1151
+ metadata
1152
+ }) {
675
1153
  return operationsByTag.branch.updateBranchMetadata({
676
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1154
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
677
1155
  body: metadata,
678
1156
  ...this.extraProps
679
1157
  });
680
1158
  }
681
- getBranchMetadata(workspace, database, branch) {
1159
+ getBranchMetadata({
1160
+ workspace,
1161
+ region,
1162
+ database,
1163
+ branch
1164
+ }) {
682
1165
  return operationsByTag.branch.getBranchMetadata({
683
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1166
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
684
1167
  ...this.extraProps
685
1168
  });
686
1169
  }
687
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
688
- return operationsByTag.branch.getBranchMigrationHistory({
689
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
690
- body: options,
1170
+ getBranchStats({
1171
+ workspace,
1172
+ region,
1173
+ database,
1174
+ branch
1175
+ }) {
1176
+ return operationsByTag.branch.getBranchStats({
1177
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
691
1178
  ...this.extraProps
692
1179
  });
693
1180
  }
694
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
695
- return operationsByTag.branch.executeBranchMigrationPlan({
696
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
697
- body: migrationPlan,
1181
+ getGitBranchesMapping({
1182
+ workspace,
1183
+ region,
1184
+ database
1185
+ }) {
1186
+ return operationsByTag.branch.getGitBranchesMapping({
1187
+ pathParams: { workspace, region, dbName: database },
698
1188
  ...this.extraProps
699
1189
  });
700
1190
  }
701
- getBranchMigrationPlan(workspace, database, branch, schema) {
702
- return operationsByTag.branch.getBranchMigrationPlan({
703
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
704
- body: schema,
1191
+ addGitBranchesEntry({
1192
+ workspace,
1193
+ region,
1194
+ database,
1195
+ gitBranch,
1196
+ xataBranch
1197
+ }) {
1198
+ return operationsByTag.branch.addGitBranchesEntry({
1199
+ pathParams: { workspace, region, dbName: database },
1200
+ body: { gitBranch, xataBranch },
705
1201
  ...this.extraProps
706
1202
  });
707
1203
  }
708
- getBranchStats(workspace, database, branch) {
709
- return operationsByTag.branch.getBranchStats({
710
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1204
+ removeGitBranchesEntry({
1205
+ workspace,
1206
+ region,
1207
+ database,
1208
+ gitBranch
1209
+ }) {
1210
+ return operationsByTag.branch.removeGitBranchesEntry({
1211
+ pathParams: { workspace, region, dbName: database },
1212
+ queryParams: { gitBranch },
1213
+ ...this.extraProps
1214
+ });
1215
+ }
1216
+ resolveBranch({
1217
+ workspace,
1218
+ region,
1219
+ database,
1220
+ gitBranch,
1221
+ fallbackBranch
1222
+ }) {
1223
+ return operationsByTag.branch.resolveBranch({
1224
+ pathParams: { workspace, region, dbName: database },
1225
+ queryParams: { gitBranch, fallbackBranch },
711
1226
  ...this.extraProps
712
1227
  });
713
1228
  }
@@ -716,67 +1231,134 @@ class TableApi {
716
1231
  constructor(extraProps) {
717
1232
  this.extraProps = extraProps;
718
1233
  }
719
- createTable(workspace, database, branch, tableName) {
1234
+ createTable({
1235
+ workspace,
1236
+ region,
1237
+ database,
1238
+ branch,
1239
+ table
1240
+ }) {
720
1241
  return operationsByTag.table.createTable({
721
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1242
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
722
1243
  ...this.extraProps
723
1244
  });
724
1245
  }
725
- deleteTable(workspace, database, branch, tableName) {
1246
+ deleteTable({
1247
+ workspace,
1248
+ region,
1249
+ database,
1250
+ branch,
1251
+ table
1252
+ }) {
726
1253
  return operationsByTag.table.deleteTable({
727
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1254
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
728
1255
  ...this.extraProps
729
1256
  });
730
1257
  }
731
- updateTable(workspace, database, branch, tableName, options) {
1258
+ updateTable({
1259
+ workspace,
1260
+ region,
1261
+ database,
1262
+ branch,
1263
+ table,
1264
+ update
1265
+ }) {
732
1266
  return operationsByTag.table.updateTable({
733
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
734
- body: options,
1267
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1268
+ body: update,
735
1269
  ...this.extraProps
736
1270
  });
737
1271
  }
738
- getTableSchema(workspace, database, branch, tableName) {
1272
+ getTableSchema({
1273
+ workspace,
1274
+ region,
1275
+ database,
1276
+ branch,
1277
+ table
1278
+ }) {
739
1279
  return operationsByTag.table.getTableSchema({
740
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1280
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
741
1281
  ...this.extraProps
742
1282
  });
743
1283
  }
744
- setTableSchema(workspace, database, branch, tableName, options) {
1284
+ setTableSchema({
1285
+ workspace,
1286
+ region,
1287
+ database,
1288
+ branch,
1289
+ table,
1290
+ schema
1291
+ }) {
745
1292
  return operationsByTag.table.setTableSchema({
746
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
747
- body: options,
1293
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1294
+ body: schema,
748
1295
  ...this.extraProps
749
1296
  });
750
1297
  }
751
- getTableColumns(workspace, database, branch, tableName) {
1298
+ getTableColumns({
1299
+ workspace,
1300
+ region,
1301
+ database,
1302
+ branch,
1303
+ table
1304
+ }) {
752
1305
  return operationsByTag.table.getTableColumns({
753
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1306
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
754
1307
  ...this.extraProps
755
1308
  });
756
1309
  }
757
- addTableColumn(workspace, database, branch, tableName, column) {
1310
+ addTableColumn({
1311
+ workspace,
1312
+ region,
1313
+ database,
1314
+ branch,
1315
+ table,
1316
+ column
1317
+ }) {
758
1318
  return operationsByTag.table.addTableColumn({
759
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1319
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
760
1320
  body: column,
761
1321
  ...this.extraProps
762
1322
  });
763
1323
  }
764
- getColumn(workspace, database, branch, tableName, columnName) {
1324
+ getColumn({
1325
+ workspace,
1326
+ region,
1327
+ database,
1328
+ branch,
1329
+ table,
1330
+ column
1331
+ }) {
765
1332
  return operationsByTag.table.getColumn({
766
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1333
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
767
1334
  ...this.extraProps
768
1335
  });
769
1336
  }
770
- deleteColumn(workspace, database, branch, tableName, columnName) {
771
- return operationsByTag.table.deleteColumn({
772
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1337
+ updateColumn({
1338
+ workspace,
1339
+ region,
1340
+ database,
1341
+ branch,
1342
+ table,
1343
+ column,
1344
+ update
1345
+ }) {
1346
+ return operationsByTag.table.updateColumn({
1347
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
1348
+ body: update,
773
1349
  ...this.extraProps
774
1350
  });
775
1351
  }
776
- updateColumn(workspace, database, branch, tableName, columnName, options) {
777
- return operationsByTag.table.updateColumn({
778
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
779
- body: options,
1352
+ deleteColumn({
1353
+ workspace,
1354
+ region,
1355
+ database,
1356
+ branch,
1357
+ table,
1358
+ column
1359
+ }) {
1360
+ return operationsByTag.table.deleteColumn({
1361
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
780
1362
  ...this.extraProps
781
1363
  });
782
1364
  }
@@ -785,67 +1367,511 @@ class RecordsApi {
785
1367
  constructor(extraProps) {
786
1368
  this.extraProps = extraProps;
787
1369
  }
788
- insertRecord(workspace, database, branch, tableName, record) {
1370
+ insertRecord({
1371
+ workspace,
1372
+ region,
1373
+ database,
1374
+ branch,
1375
+ table,
1376
+ record,
1377
+ columns
1378
+ }) {
789
1379
  return operationsByTag.records.insertRecord({
790
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1380
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1381
+ queryParams: { columns },
791
1382
  body: record,
792
1383
  ...this.extraProps
793
1384
  });
794
1385
  }
795
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1386
+ getRecord({
1387
+ workspace,
1388
+ region,
1389
+ database,
1390
+ branch,
1391
+ table,
1392
+ id,
1393
+ columns
1394
+ }) {
1395
+ return operationsByTag.records.getRecord({
1396
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1397
+ queryParams: { columns },
1398
+ ...this.extraProps
1399
+ });
1400
+ }
1401
+ insertRecordWithID({
1402
+ workspace,
1403
+ region,
1404
+ database,
1405
+ branch,
1406
+ table,
1407
+ id,
1408
+ record,
1409
+ columns,
1410
+ createOnly,
1411
+ ifVersion
1412
+ }) {
796
1413
  return operationsByTag.records.insertRecordWithID({
797
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
798
- queryParams: options,
1414
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1415
+ queryParams: { columns, createOnly, ifVersion },
799
1416
  body: record,
800
1417
  ...this.extraProps
801
1418
  });
802
1419
  }
803
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1420
+ updateRecordWithID({
1421
+ workspace,
1422
+ region,
1423
+ database,
1424
+ branch,
1425
+ table,
1426
+ id,
1427
+ record,
1428
+ columns,
1429
+ ifVersion
1430
+ }) {
804
1431
  return operationsByTag.records.updateRecordWithID({
805
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
806
- queryParams: options,
1432
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1433
+ queryParams: { columns, ifVersion },
807
1434
  body: record,
808
1435
  ...this.extraProps
809
1436
  });
810
1437
  }
811
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1438
+ upsertRecordWithID({
1439
+ workspace,
1440
+ region,
1441
+ database,
1442
+ branch,
1443
+ table,
1444
+ id,
1445
+ record,
1446
+ columns,
1447
+ ifVersion
1448
+ }) {
812
1449
  return operationsByTag.records.upsertRecordWithID({
813
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
814
- queryParams: options,
1450
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1451
+ queryParams: { columns, ifVersion },
815
1452
  body: record,
816
1453
  ...this.extraProps
817
1454
  });
818
1455
  }
819
- deleteRecord(workspace, database, branch, tableName, recordId) {
1456
+ deleteRecord({
1457
+ workspace,
1458
+ region,
1459
+ database,
1460
+ branch,
1461
+ table,
1462
+ id,
1463
+ columns
1464
+ }) {
820
1465
  return operationsByTag.records.deleteRecord({
821
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1466
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1467
+ queryParams: { columns },
822
1468
  ...this.extraProps
823
1469
  });
824
1470
  }
825
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
826
- return operationsByTag.records.getRecord({
827
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1471
+ bulkInsertTableRecords({
1472
+ workspace,
1473
+ region,
1474
+ database,
1475
+ branch,
1476
+ table,
1477
+ records,
1478
+ columns
1479
+ }) {
1480
+ return operationsByTag.records.bulkInsertTableRecords({
1481
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1482
+ queryParams: { columns },
1483
+ body: { records },
828
1484
  ...this.extraProps
829
1485
  });
830
1486
  }
831
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
832
- return operationsByTag.records.bulkInsertTableRecords({
833
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
834
- body: { records },
1487
+ branchTransaction({
1488
+ workspace,
1489
+ region,
1490
+ database,
1491
+ branch,
1492
+ operations
1493
+ }) {
1494
+ return operationsByTag.records.branchTransaction({
1495
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1496
+ body: { operations },
835
1497
  ...this.extraProps
836
1498
  });
837
1499
  }
838
- queryTable(workspace, database, branch, tableName, query) {
839
- return operationsByTag.records.queryTable({
840
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
841
- body: query,
1500
+ }
1501
+ class SearchAndFilterApi {
1502
+ constructor(extraProps) {
1503
+ this.extraProps = extraProps;
1504
+ }
1505
+ queryTable({
1506
+ workspace,
1507
+ region,
1508
+ database,
1509
+ branch,
1510
+ table,
1511
+ filter,
1512
+ sort,
1513
+ page,
1514
+ columns,
1515
+ consistency
1516
+ }) {
1517
+ return operationsByTag.searchAndFilter.queryTable({
1518
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1519
+ body: { filter, sort, page, columns, consistency },
842
1520
  ...this.extraProps
843
1521
  });
844
1522
  }
845
- searchBranch(workspace, database, branch, query) {
846
- return operationsByTag.records.searchBranch({
847
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
848
- body: query,
1523
+ searchTable({
1524
+ workspace,
1525
+ region,
1526
+ database,
1527
+ branch,
1528
+ table,
1529
+ query,
1530
+ fuzziness,
1531
+ target,
1532
+ prefix,
1533
+ filter,
1534
+ highlight,
1535
+ boosters
1536
+ }) {
1537
+ return operationsByTag.searchAndFilter.searchTable({
1538
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1539
+ body: { query, fuzziness, target, prefix, filter, highlight, boosters },
1540
+ ...this.extraProps
1541
+ });
1542
+ }
1543
+ searchBranch({
1544
+ workspace,
1545
+ region,
1546
+ database,
1547
+ branch,
1548
+ tables,
1549
+ query,
1550
+ fuzziness,
1551
+ prefix,
1552
+ highlight
1553
+ }) {
1554
+ return operationsByTag.searchAndFilter.searchBranch({
1555
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1556
+ body: { tables, query, fuzziness, prefix, highlight },
1557
+ ...this.extraProps
1558
+ });
1559
+ }
1560
+ summarizeTable({
1561
+ workspace,
1562
+ region,
1563
+ database,
1564
+ branch,
1565
+ table,
1566
+ filter,
1567
+ columns,
1568
+ summaries,
1569
+ sort,
1570
+ summariesFilter,
1571
+ page,
1572
+ consistency
1573
+ }) {
1574
+ return operationsByTag.searchAndFilter.summarizeTable({
1575
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1576
+ body: { filter, columns, summaries, sort, summariesFilter, page, consistency },
1577
+ ...this.extraProps
1578
+ });
1579
+ }
1580
+ aggregateTable({
1581
+ workspace,
1582
+ region,
1583
+ database,
1584
+ branch,
1585
+ table,
1586
+ filter,
1587
+ aggs
1588
+ }) {
1589
+ return operationsByTag.searchAndFilter.aggregateTable({
1590
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1591
+ body: { filter, aggs },
1592
+ ...this.extraProps
1593
+ });
1594
+ }
1595
+ }
1596
+ class MigrationRequestsApi {
1597
+ constructor(extraProps) {
1598
+ this.extraProps = extraProps;
1599
+ }
1600
+ queryMigrationRequests({
1601
+ workspace,
1602
+ region,
1603
+ database,
1604
+ filter,
1605
+ sort,
1606
+ page,
1607
+ columns
1608
+ }) {
1609
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1610
+ pathParams: { workspace, region, dbName: database },
1611
+ body: { filter, sort, page, columns },
1612
+ ...this.extraProps
1613
+ });
1614
+ }
1615
+ createMigrationRequest({
1616
+ workspace,
1617
+ region,
1618
+ database,
1619
+ migration
1620
+ }) {
1621
+ return operationsByTag.migrationRequests.createMigrationRequest({
1622
+ pathParams: { workspace, region, dbName: database },
1623
+ body: migration,
1624
+ ...this.extraProps
1625
+ });
1626
+ }
1627
+ getMigrationRequest({
1628
+ workspace,
1629
+ region,
1630
+ database,
1631
+ migrationRequest
1632
+ }) {
1633
+ return operationsByTag.migrationRequests.getMigrationRequest({
1634
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1635
+ ...this.extraProps
1636
+ });
1637
+ }
1638
+ updateMigrationRequest({
1639
+ workspace,
1640
+ region,
1641
+ database,
1642
+ migrationRequest,
1643
+ update
1644
+ }) {
1645
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1646
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1647
+ body: update,
1648
+ ...this.extraProps
1649
+ });
1650
+ }
1651
+ listMigrationRequestsCommits({
1652
+ workspace,
1653
+ region,
1654
+ database,
1655
+ migrationRequest,
1656
+ page
1657
+ }) {
1658
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1659
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1660
+ body: { page },
1661
+ ...this.extraProps
1662
+ });
1663
+ }
1664
+ compareMigrationRequest({
1665
+ workspace,
1666
+ region,
1667
+ database,
1668
+ migrationRequest
1669
+ }) {
1670
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1671
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1672
+ ...this.extraProps
1673
+ });
1674
+ }
1675
+ getMigrationRequestIsMerged({
1676
+ workspace,
1677
+ region,
1678
+ database,
1679
+ migrationRequest
1680
+ }) {
1681
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1682
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1683
+ ...this.extraProps
1684
+ });
1685
+ }
1686
+ mergeMigrationRequest({
1687
+ workspace,
1688
+ region,
1689
+ database,
1690
+ migrationRequest
1691
+ }) {
1692
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1693
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
1694
+ ...this.extraProps
1695
+ });
1696
+ }
1697
+ }
1698
+ class MigrationsApi {
1699
+ constructor(extraProps) {
1700
+ this.extraProps = extraProps;
1701
+ }
1702
+ getBranchMigrationHistory({
1703
+ workspace,
1704
+ region,
1705
+ database,
1706
+ branch,
1707
+ limit,
1708
+ startFrom
1709
+ }) {
1710
+ return operationsByTag.migrations.getBranchMigrationHistory({
1711
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1712
+ body: { limit, startFrom },
1713
+ ...this.extraProps
1714
+ });
1715
+ }
1716
+ getBranchMigrationPlan({
1717
+ workspace,
1718
+ region,
1719
+ database,
1720
+ branch,
1721
+ schema
1722
+ }) {
1723
+ return operationsByTag.migrations.getBranchMigrationPlan({
1724
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1725
+ body: schema,
1726
+ ...this.extraProps
1727
+ });
1728
+ }
1729
+ executeBranchMigrationPlan({
1730
+ workspace,
1731
+ region,
1732
+ database,
1733
+ branch,
1734
+ plan
1735
+ }) {
1736
+ return operationsByTag.migrations.executeBranchMigrationPlan({
1737
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1738
+ body: plan,
1739
+ ...this.extraProps
1740
+ });
1741
+ }
1742
+ getBranchSchemaHistory({
1743
+ workspace,
1744
+ region,
1745
+ database,
1746
+ branch,
1747
+ page
1748
+ }) {
1749
+ return operationsByTag.migrations.getBranchSchemaHistory({
1750
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1751
+ body: { page },
1752
+ ...this.extraProps
1753
+ });
1754
+ }
1755
+ compareBranchWithUserSchema({
1756
+ workspace,
1757
+ region,
1758
+ database,
1759
+ branch,
1760
+ schema
1761
+ }) {
1762
+ return operationsByTag.migrations.compareBranchWithUserSchema({
1763
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1764
+ body: { schema },
1765
+ ...this.extraProps
1766
+ });
1767
+ }
1768
+ compareBranchSchemas({
1769
+ workspace,
1770
+ region,
1771
+ database,
1772
+ branch,
1773
+ compare,
1774
+ schema
1775
+ }) {
1776
+ return operationsByTag.migrations.compareBranchSchemas({
1777
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, branchName: compare },
1778
+ body: { schema },
1779
+ ...this.extraProps
1780
+ });
1781
+ }
1782
+ updateBranchSchema({
1783
+ workspace,
1784
+ region,
1785
+ database,
1786
+ branch,
1787
+ migration
1788
+ }) {
1789
+ return operationsByTag.migrations.updateBranchSchema({
1790
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1791
+ body: migration,
1792
+ ...this.extraProps
1793
+ });
1794
+ }
1795
+ previewBranchSchemaEdit({
1796
+ workspace,
1797
+ region,
1798
+ database,
1799
+ branch,
1800
+ data
1801
+ }) {
1802
+ return operationsByTag.migrations.previewBranchSchemaEdit({
1803
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1804
+ body: data,
1805
+ ...this.extraProps
1806
+ });
1807
+ }
1808
+ applyBranchSchemaEdit({
1809
+ workspace,
1810
+ region,
1811
+ database,
1812
+ branch,
1813
+ edits
1814
+ }) {
1815
+ return operationsByTag.migrations.applyBranchSchemaEdit({
1816
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1817
+ body: { edits },
1818
+ ...this.extraProps
1819
+ });
1820
+ }
1821
+ }
1822
+ class DatabaseApi {
1823
+ constructor(extraProps) {
1824
+ this.extraProps = extraProps;
1825
+ }
1826
+ getDatabaseList({ workspace }) {
1827
+ return operationsByTag.databases.getDatabaseList({
1828
+ pathParams: { workspaceId: workspace },
1829
+ ...this.extraProps
1830
+ });
1831
+ }
1832
+ createDatabase({
1833
+ workspace,
1834
+ database,
1835
+ data
1836
+ }) {
1837
+ return operationsByTag.databases.createDatabase({
1838
+ pathParams: { workspaceId: workspace, dbName: database },
1839
+ body: data,
1840
+ ...this.extraProps
1841
+ });
1842
+ }
1843
+ deleteDatabase({
1844
+ workspace,
1845
+ database
1846
+ }) {
1847
+ return operationsByTag.databases.deleteDatabase({
1848
+ pathParams: { workspaceId: workspace, dbName: database },
1849
+ ...this.extraProps
1850
+ });
1851
+ }
1852
+ getDatabaseMetadata({
1853
+ workspace,
1854
+ database
1855
+ }) {
1856
+ return operationsByTag.databases.getDatabaseMetadata({
1857
+ pathParams: { workspaceId: workspace, dbName: database },
1858
+ ...this.extraProps
1859
+ });
1860
+ }
1861
+ updateDatabaseMetadata({
1862
+ workspace,
1863
+ database,
1864
+ metadata
1865
+ }) {
1866
+ return operationsByTag.databases.updateDatabaseMetadata({
1867
+ pathParams: { workspaceId: workspace, dbName: database },
1868
+ body: metadata,
1869
+ ...this.extraProps
1870
+ });
1871
+ }
1872
+ listRegions({ workspace }) {
1873
+ return operationsByTag.databases.listRegions({
1874
+ pathParams: { workspaceId: workspace },
849
1875
  ...this.extraProps
850
1876
  });
851
1877
  }
@@ -861,11 +1887,25 @@ class XataApiPlugin {
861
1887
  class XataPlugin {
862
1888
  }
863
1889
 
1890
+ function generateUUID() {
1891
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
1892
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
1893
+ return v.toString(16);
1894
+ });
1895
+ }
1896
+
1897
+ function cleanFilter(filter) {
1898
+ if (!filter)
1899
+ return void 0;
1900
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1901
+ return values.length > 0 ? filter : void 0;
1902
+ }
1903
+
864
1904
  var __accessCheck$6 = (obj, member, msg) => {
865
1905
  if (!member.has(obj))
866
1906
  throw TypeError("Cannot " + msg);
867
1907
  };
868
- var __privateGet$5 = (obj, member, getter) => {
1908
+ var __privateGet$6 = (obj, member, getter) => {
869
1909
  __accessCheck$6(obj, member, "read from private field");
870
1910
  return getter ? getter.call(obj) : member.get(obj);
871
1911
  };
@@ -874,30 +1914,30 @@ var __privateAdd$6 = (obj, member, value) => {
874
1914
  throw TypeError("Cannot add the same private member more than once");
875
1915
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
876
1916
  };
877
- var __privateSet$4 = (obj, member, value, setter) => {
1917
+ var __privateSet$6 = (obj, member, value, setter) => {
878
1918
  __accessCheck$6(obj, member, "write to private field");
879
1919
  setter ? setter.call(obj, value) : member.set(obj, value);
880
1920
  return value;
881
1921
  };
882
- var _query;
1922
+ var _query, _page;
883
1923
  class Page {
884
1924
  constructor(query, meta, records = []) {
885
1925
  __privateAdd$6(this, _query, void 0);
886
- __privateSet$4(this, _query, query);
1926
+ __privateSet$6(this, _query, query);
887
1927
  this.meta = meta;
888
- this.records = records;
1928
+ this.records = new RecordArray(this, records);
889
1929
  }
890
1930
  async nextPage(size, offset) {
891
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
1931
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
892
1932
  }
893
1933
  async previousPage(size, offset) {
894
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
1934
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
895
1935
  }
896
- async firstPage(size, offset) {
897
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
1936
+ async startPage(size, offset) {
1937
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, start: this.meta.page.cursor } });
898
1938
  }
899
- async lastPage(size, offset) {
900
- return __privateGet$5(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
1939
+ async endPage(size, offset) {
1940
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, end: this.meta.page.cursor } });
901
1941
  }
902
1942
  hasNextPage() {
903
1943
  return this.meta.page.more;
@@ -905,15 +1945,62 @@ class Page {
905
1945
  }
906
1946
  _query = new WeakMap();
907
1947
  const PAGINATION_MAX_SIZE = 200;
908
- const PAGINATION_DEFAULT_SIZE = 200;
1948
+ const PAGINATION_DEFAULT_SIZE = 20;
909
1949
  const PAGINATION_MAX_OFFSET = 800;
910
1950
  const PAGINATION_DEFAULT_OFFSET = 0;
1951
+ function isCursorPaginationOptions(options) {
1952
+ return isDefined(options) && (isDefined(options.start) || isDefined(options.end) || isDefined(options.after) || isDefined(options.before));
1953
+ }
1954
+ const _RecordArray = class extends Array {
1955
+ constructor(...args) {
1956
+ super(..._RecordArray.parseConstructorParams(...args));
1957
+ __privateAdd$6(this, _page, void 0);
1958
+ __privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
1959
+ }
1960
+ static parseConstructorParams(...args) {
1961
+ if (args.length === 1 && typeof args[0] === "number") {
1962
+ return new Array(args[0]);
1963
+ }
1964
+ if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
1965
+ const result = args[1] ?? args[0].records ?? [];
1966
+ return new Array(...result);
1967
+ }
1968
+ return new Array(...args);
1969
+ }
1970
+ toArray() {
1971
+ return new Array(...this);
1972
+ }
1973
+ map(callbackfn, thisArg) {
1974
+ return this.toArray().map(callbackfn, thisArg);
1975
+ }
1976
+ async nextPage(size, offset) {
1977
+ const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1978
+ return new _RecordArray(newPage);
1979
+ }
1980
+ async previousPage(size, offset) {
1981
+ const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1982
+ return new _RecordArray(newPage);
1983
+ }
1984
+ async startPage(size, offset) {
1985
+ const newPage = await __privateGet$6(this, _page).startPage(size, offset);
1986
+ return new _RecordArray(newPage);
1987
+ }
1988
+ async endPage(size, offset) {
1989
+ const newPage = await __privateGet$6(this, _page).endPage(size, offset);
1990
+ return new _RecordArray(newPage);
1991
+ }
1992
+ hasNextPage() {
1993
+ return __privateGet$6(this, _page).meta.page.more;
1994
+ }
1995
+ };
1996
+ let RecordArray = _RecordArray;
1997
+ _page = new WeakMap();
911
1998
 
912
1999
  var __accessCheck$5 = (obj, member, msg) => {
913
2000
  if (!member.has(obj))
914
2001
  throw TypeError("Cannot " + msg);
915
2002
  };
916
- var __privateGet$4 = (obj, member, getter) => {
2003
+ var __privateGet$5 = (obj, member, getter) => {
917
2004
  __accessCheck$5(obj, member, "read from private field");
918
2005
  return getter ? getter.call(obj) : member.get(obj);
919
2006
  };
@@ -922,34 +2009,41 @@ var __privateAdd$5 = (obj, member, value) => {
922
2009
  throw TypeError("Cannot add the same private member more than once");
923
2010
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
924
2011
  };
925
- var __privateSet$3 = (obj, member, value, setter) => {
2012
+ var __privateSet$5 = (obj, member, value, setter) => {
926
2013
  __accessCheck$5(obj, member, "write to private field");
927
2014
  setter ? setter.call(obj, value) : member.set(obj, value);
928
2015
  return value;
929
2016
  };
930
- var _table$1, _repository, _data;
2017
+ var __privateMethod$3 = (obj, member, method) => {
2018
+ __accessCheck$5(obj, member, "access private method");
2019
+ return method;
2020
+ };
2021
+ var _table$1, _repository, _data, _cleanFilterConstraint, cleanFilterConstraint_fn;
931
2022
  const _Query = class {
932
- constructor(repository, table, data, parent) {
2023
+ constructor(repository, table, data, rawParent) {
2024
+ __privateAdd$5(this, _cleanFilterConstraint);
933
2025
  __privateAdd$5(this, _table$1, void 0);
934
2026
  __privateAdd$5(this, _repository, void 0);
935
2027
  __privateAdd$5(this, _data, { filter: {} });
936
2028
  this.meta = { page: { cursor: "start", more: true } };
937
- this.records = [];
938
- __privateSet$3(this, _table$1, table);
2029
+ this.records = new RecordArray(this, []);
2030
+ __privateSet$5(this, _table$1, table);
939
2031
  if (repository) {
940
- __privateSet$3(this, _repository, repository);
2032
+ __privateSet$5(this, _repository, repository);
941
2033
  } else {
942
- __privateSet$3(this, _repository, this);
2034
+ __privateSet$5(this, _repository, this);
943
2035
  }
944
- __privateGet$4(this, _data).filter = data.filter ?? parent?.filter ?? {};
945
- __privateGet$4(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
946
- __privateGet$4(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
947
- __privateGet$4(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
948
- __privateGet$4(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
949
- __privateGet$4(this, _data).sort = data.sort ?? parent?.sort;
950
- __privateGet$4(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
951
- __privateGet$4(this, _data).page = data.page ?? parent?.page;
952
- __privateGet$4(this, _data).cache = data.cache ?? parent?.cache;
2036
+ const parent = cleanParent(data, rawParent);
2037
+ __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
2038
+ __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
2039
+ __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
2040
+ __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
2041
+ __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
2042
+ __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
2043
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
2044
+ __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
2045
+ __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
2046
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
953
2047
  this.any = this.any.bind(this);
954
2048
  this.all = this.all.bind(this);
955
2049
  this.not = this.not.bind(this);
@@ -960,95 +2054,133 @@ const _Query = class {
960
2054
  Object.defineProperty(this, "repository", { enumerable: false });
961
2055
  }
962
2056
  getQueryOptions() {
963
- return __privateGet$4(this, _data);
2057
+ return __privateGet$5(this, _data);
964
2058
  }
965
2059
  key() {
966
- const { columns = [], filter = {}, sort = [], page = {} } = __privateGet$4(this, _data);
967
- const key = JSON.stringify({ columns, filter, sort, page });
2060
+ const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
2061
+ const key = JSON.stringify({ columns, filter, sort, pagination });
968
2062
  return toBase64(key);
969
2063
  }
970
2064
  any(...queries) {
971
2065
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
972
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $any } }, __privateGet$4(this, _data));
2066
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
973
2067
  }
974
2068
  all(...queries) {
975
2069
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
976
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
2070
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
977
2071
  }
978
2072
  not(...queries) {
979
2073
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
980
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $not } }, __privateGet$4(this, _data));
2074
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
981
2075
  }
982
2076
  none(...queries) {
983
2077
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
984
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $none } }, __privateGet$4(this, _data));
2078
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
985
2079
  }
986
2080
  filter(a, b) {
987
2081
  if (arguments.length === 1) {
988
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
989
- const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat(constraints));
990
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
2082
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
2083
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
2084
+ }));
2085
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
2086
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
991
2087
  } else {
992
- const $all = compact([__privateGet$4(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
993
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { filter: { $all } }, __privateGet$4(this, _data));
2088
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, a, b) }] : void 0;
2089
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
2090
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
994
2091
  }
995
2092
  }
996
- sort(column, direction) {
997
- const originalSort = [__privateGet$4(this, _data).sort ?? []].flat();
2093
+ sort(column, direction = "asc") {
2094
+ const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
998
2095
  const sort = [...originalSort, { column, direction }];
999
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { sort }, __privateGet$4(this, _data));
2096
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
1000
2097
  }
1001
2098
  select(columns) {
1002
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { columns }, __privateGet$4(this, _data));
2099
+ return new _Query(
2100
+ __privateGet$5(this, _repository),
2101
+ __privateGet$5(this, _table$1),
2102
+ { columns },
2103
+ __privateGet$5(this, _data)
2104
+ );
1003
2105
  }
1004
2106
  getPaginated(options = {}) {
1005
- const query = new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), options, __privateGet$4(this, _data));
1006
- return __privateGet$4(this, _repository).query(query);
2107
+ const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
2108
+ return __privateGet$5(this, _repository).query(query);
1007
2109
  }
1008
2110
  async *[Symbol.asyncIterator]() {
1009
- for await (const [record] of this.getIterator(1)) {
2111
+ for await (const [record] of this.getIterator({ batchSize: 1 })) {
1010
2112
  yield record;
1011
2113
  }
1012
2114
  }
1013
- async *getIterator(chunk, options = {}) {
1014
- let offset = 0;
1015
- let end = false;
1016
- while (!end) {
1017
- const { records, meta } = await this.getPaginated({ ...options, page: { size: chunk, offset } });
1018
- yield records;
1019
- offset += chunk;
1020
- end = !meta.page.more;
2115
+ async *getIterator(options = {}) {
2116
+ const { batchSize = 1 } = options;
2117
+ let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
2118
+ let more = page.hasNextPage();
2119
+ yield page.records;
2120
+ while (more) {
2121
+ page = await page.nextPage();
2122
+ more = page.hasNextPage();
2123
+ yield page.records;
1021
2124
  }
1022
2125
  }
1023
2126
  async getMany(options = {}) {
1024
- const { records } = await this.getPaginated(options);
1025
- return records;
2127
+ const { pagination = {}, ...rest } = options;
2128
+ const { size = PAGINATION_DEFAULT_SIZE, offset } = pagination;
2129
+ const batchSize = size <= PAGINATION_MAX_SIZE ? size : PAGINATION_MAX_SIZE;
2130
+ let page = await this.getPaginated({ ...rest, pagination: { size: batchSize, offset } });
2131
+ const results = [...page.records];
2132
+ while (page.hasNextPage() && results.length < size) {
2133
+ page = await page.nextPage();
2134
+ results.push(...page.records);
2135
+ }
2136
+ if (page.hasNextPage() && options.pagination?.size === void 0) {
2137
+ console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
2138
+ }
2139
+ const array = new RecordArray(page, results.slice(0, size));
2140
+ return array;
1026
2141
  }
1027
- async getAll(chunk = PAGINATION_MAX_SIZE, options = {}) {
2142
+ async getAll(options = {}) {
2143
+ const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
1028
2144
  const results = [];
1029
- for await (const page of this.getIterator(chunk, options)) {
2145
+ for await (const page of this.getIterator({ ...rest, batchSize })) {
1030
2146
  results.push(...page);
1031
2147
  }
1032
2148
  return results;
1033
2149
  }
1034
2150
  async getFirst(options = {}) {
1035
- const records = await this.getMany({ ...options, page: { size: 1 } });
1036
- return records[0] || null;
2151
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
2152
+ return records[0] ?? null;
2153
+ }
2154
+ async getFirstOrThrow(options = {}) {
2155
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
2156
+ if (records[0] === void 0)
2157
+ throw new Error("No results found.");
2158
+ return records[0];
2159
+ }
2160
+ async summarize(params = {}) {
2161
+ const { summaries, summariesFilter, ...options } = params;
2162
+ const query = new _Query(
2163
+ __privateGet$5(this, _repository),
2164
+ __privateGet$5(this, _table$1),
2165
+ options,
2166
+ __privateGet$5(this, _data)
2167
+ );
2168
+ return __privateGet$5(this, _repository).summarizeTable(query, summaries, summariesFilter);
1037
2169
  }
1038
2170
  cache(ttl) {
1039
- return new _Query(__privateGet$4(this, _repository), __privateGet$4(this, _table$1), { cache: ttl }, __privateGet$4(this, _data));
2171
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1040
2172
  }
1041
2173
  nextPage(size, offset) {
1042
- return this.firstPage(size, offset);
2174
+ return this.startPage(size, offset);
1043
2175
  }
1044
2176
  previousPage(size, offset) {
1045
- return this.firstPage(size, offset);
2177
+ return this.startPage(size, offset);
1046
2178
  }
1047
- firstPage(size, offset) {
1048
- return this.getPaginated({ page: { size, offset } });
2179
+ startPage(size, offset) {
2180
+ return this.getPaginated({ pagination: { size, offset } });
1049
2181
  }
1050
- lastPage(size, offset) {
1051
- return this.getPaginated({ page: { size, offset, before: "end" } });
2182
+ endPage(size, offset) {
2183
+ return this.getPaginated({ pagination: { size, offset, before: "end" } });
1052
2184
  }
1053
2185
  hasNextPage() {
1054
2186
  return this.meta.page.more;
@@ -1058,12 +2190,31 @@ let Query = _Query;
1058
2190
  _table$1 = new WeakMap();
1059
2191
  _repository = new WeakMap();
1060
2192
  _data = new WeakMap();
2193
+ _cleanFilterConstraint = new WeakSet();
2194
+ cleanFilterConstraint_fn = function(column, value) {
2195
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
2196
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
2197
+ return { $includes: value };
2198
+ }
2199
+ if (columnType === "link" && isObject(value) && isString(value.id)) {
2200
+ return value.id;
2201
+ }
2202
+ return value;
2203
+ };
2204
+ function cleanParent(data, parent) {
2205
+ if (isCursorPaginationOptions(data.pagination)) {
2206
+ return { ...parent, sort: void 0, filter: void 0 };
2207
+ }
2208
+ return parent;
2209
+ }
1061
2210
 
1062
2211
  function isIdentifiable(x) {
1063
2212
  return isObject(x) && isString(x?.id);
1064
2213
  }
1065
2214
  function isXataRecord(x) {
1066
- return isIdentifiable(x) && typeof x?.xata === "object" && typeof x?.xata?.version === "number";
2215
+ const record = x;
2216
+ const metadata = record?.getMetadata();
2217
+ return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
1067
2218
  }
1068
2219
 
1069
2220
  function isSortFilterString(value) {
@@ -1093,7 +2244,7 @@ var __accessCheck$4 = (obj, member, msg) => {
1093
2244
  if (!member.has(obj))
1094
2245
  throw TypeError("Cannot " + msg);
1095
2246
  };
1096
- var __privateGet$3 = (obj, member, getter) => {
2247
+ var __privateGet$4 = (obj, member, getter) => {
1097
2248
  __accessCheck$4(obj, member, "read from private field");
1098
2249
  return getter ? getter.call(obj) : member.get(obj);
1099
2250
  };
@@ -1102,7 +2253,7 @@ var __privateAdd$4 = (obj, member, value) => {
1102
2253
  throw TypeError("Cannot add the same private member more than once");
1103
2254
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1104
2255
  };
1105
- var __privateSet$2 = (obj, member, value, setter) => {
2256
+ var __privateSet$4 = (obj, member, value, setter) => {
1106
2257
  __accessCheck$4(obj, member, "write to private field");
1107
2258
  setter ? setter.call(obj, value) : member.set(obj, value);
1108
2259
  return value;
@@ -1111,304 +2262,593 @@ var __privateMethod$2 = (obj, member, method) => {
1111
2262
  __accessCheck$4(obj, member, "access private method");
1112
2263
  return method;
1113
2264
  };
1114
- var _table, _links, _getFetchProps, _cache, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn;
2265
+ var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _insertRecords, insertRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _updateRecords, updateRecords_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _deleteRecords, deleteRecords_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
2266
+ const BULK_OPERATION_MAX_SIZE = 1e3;
1115
2267
  class Repository extends Query {
1116
2268
  }
1117
2269
  class RestRepository extends Query {
1118
2270
  constructor(options) {
1119
- super(null, options.table, {});
2271
+ super(
2272
+ null,
2273
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
2274
+ {}
2275
+ );
1120
2276
  __privateAdd$4(this, _insertRecordWithoutId);
1121
2277
  __privateAdd$4(this, _insertRecordWithId);
1122
- __privateAdd$4(this, _bulkInsertTableRecords);
2278
+ __privateAdd$4(this, _insertRecords);
1123
2279
  __privateAdd$4(this, _updateRecordWithID);
2280
+ __privateAdd$4(this, _updateRecords);
1124
2281
  __privateAdd$4(this, _upsertRecordWithID);
1125
2282
  __privateAdd$4(this, _deleteRecord);
1126
- __privateAdd$4(this, _invalidateCache);
1127
- __privateAdd$4(this, _setCacheRecord);
1128
- __privateAdd$4(this, _getCacheRecord);
2283
+ __privateAdd$4(this, _deleteRecords);
1129
2284
  __privateAdd$4(this, _setCacheQuery);
1130
2285
  __privateAdd$4(this, _getCacheQuery);
2286
+ __privateAdd$4(this, _getSchemaTables$1);
1131
2287
  __privateAdd$4(this, _table, void 0);
1132
- __privateAdd$4(this, _links, void 0);
1133
2288
  __privateAdd$4(this, _getFetchProps, void 0);
2289
+ __privateAdd$4(this, _db, void 0);
1134
2290
  __privateAdd$4(this, _cache, void 0);
1135
- __privateSet$2(this, _table, options.table);
1136
- __privateSet$2(this, _links, options.links ?? {});
1137
- __privateSet$2(this, _getFetchProps, options.pluginOptions.getFetchProps);
1138
- this.db = options.db;
1139
- __privateSet$2(this, _cache, options.pluginOptions.cache);
1140
- }
1141
- async create(a, b) {
1142
- if (Array.isArray(a)) {
1143
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1144
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1145
- return records;
1146
- }
1147
- if (isString(a) && isObject(b)) {
1148
- if (a === "")
1149
- throw new Error("The id can't be empty");
1150
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1151
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1152
- return record;
1153
- }
1154
- if (isObject(a) && isString(a.id)) {
1155
- if (a.id === "")
1156
- throw new Error("The id can't be empty");
1157
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1158
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1159
- return record;
1160
- }
1161
- if (isObject(a)) {
1162
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1163
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1164
- return record;
1165
- }
1166
- throw new Error("Invalid arguments for create method");
1167
- }
1168
- async read(recordId) {
1169
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1170
- if (cacheRecord)
1171
- return cacheRecord;
1172
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1173
- try {
1174
- const response = await getRecord({
1175
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1176
- ...fetchProps
2291
+ __privateAdd$4(this, _schemaTables$2, void 0);
2292
+ __privateAdd$4(this, _trace, void 0);
2293
+ __privateSet$4(this, _table, options.table);
2294
+ __privateSet$4(this, _db, options.db);
2295
+ __privateSet$4(this, _cache, options.pluginOptions.cache);
2296
+ __privateSet$4(this, _schemaTables$2, options.schemaTables);
2297
+ __privateSet$4(this, _getFetchProps, async () => {
2298
+ const props = await options.pluginOptions.getFetchProps();
2299
+ return { ...props, sessionID: generateUUID() };
2300
+ });
2301
+ const trace = options.pluginOptions.trace ?? defaultTrace;
2302
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
2303
+ return trace(name, fn, {
2304
+ ...options2,
2305
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
2306
+ [TraceAttributes.KIND]: "sdk-operation",
2307
+ [TraceAttributes.VERSION]: VERSION
1177
2308
  });
1178
- return initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), response);
1179
- } catch (e) {
1180
- if (isObject(e) && e.status === 404) {
1181
- return null;
2309
+ });
2310
+ }
2311
+ async create(a, b, c, d) {
2312
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
2313
+ const ifVersion = parseIfVersion(b, c, d);
2314
+ if (Array.isArray(a)) {
2315
+ if (a.length === 0)
2316
+ return [];
2317
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: true });
2318
+ const columns = isStringArray(b) ? b : ["*"];
2319
+ const result = await this.read(ids, columns);
2320
+ return result;
1182
2321
  }
1183
- throw e;
1184
- }
2322
+ if (isString(a) && isObject(b)) {
2323
+ if (a === "")
2324
+ throw new Error("The id can't be empty");
2325
+ const columns = isStringArray(c) ? c : void 0;
2326
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: true, ifVersion });
2327
+ }
2328
+ if (isObject(a) && isString(a.id)) {
2329
+ if (a.id === "")
2330
+ throw new Error("The id can't be empty");
2331
+ const columns = isStringArray(b) ? b : void 0;
2332
+ return await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: true, ifVersion });
2333
+ }
2334
+ if (isObject(a)) {
2335
+ const columns = isStringArray(b) ? b : void 0;
2336
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
2337
+ }
2338
+ throw new Error("Invalid arguments for create method");
2339
+ });
1185
2340
  }
1186
- async update(a, b) {
1187
- if (Array.isArray(a)) {
1188
- if (a.length > 100) {
1189
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2341
+ async read(a, b) {
2342
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
2343
+ const columns = isStringArray(b) ? b : ["*"];
2344
+ if (Array.isArray(a)) {
2345
+ if (a.length === 0)
2346
+ return [];
2347
+ const ids = a.map((item) => extractId(item));
2348
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
2349
+ const dictionary = finalObjects.reduce((acc, object) => {
2350
+ acc[object.id] = object;
2351
+ return acc;
2352
+ }, {});
2353
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1190
2354
  }
1191
- return Promise.all(a.map((object) => this.update(object)));
1192
- }
1193
- if (isString(a) && isObject(b)) {
1194
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1195
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1196
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1197
- return record;
1198
- }
1199
- if (isObject(a) && isString(a.id)) {
1200
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1201
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1202
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1203
- return record;
1204
- }
1205
- throw new Error("Invalid arguments for update method");
2355
+ const id = extractId(a);
2356
+ if (id) {
2357
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2358
+ try {
2359
+ const response = await getRecord({
2360
+ pathParams: {
2361
+ workspace: "{workspaceId}",
2362
+ dbBranchName: "{dbBranch}",
2363
+ region: "{region}",
2364
+ tableName: __privateGet$4(this, _table),
2365
+ recordId: id
2366
+ },
2367
+ queryParams: { columns },
2368
+ ...fetchProps
2369
+ });
2370
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2371
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2372
+ } catch (e) {
2373
+ if (isObject(e) && e.status === 404) {
2374
+ return null;
2375
+ }
2376
+ throw e;
2377
+ }
2378
+ }
2379
+ return null;
2380
+ });
1206
2381
  }
1207
- async createOrUpdate(a, b) {
1208
- if (Array.isArray(a)) {
1209
- if (a.length > 100) {
1210
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
2382
+ async readOrThrow(a, b) {
2383
+ return __privateGet$4(this, _trace).call(this, "readOrThrow", async () => {
2384
+ const result = await this.read(a, b);
2385
+ if (Array.isArray(result)) {
2386
+ const missingIds = compact(
2387
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2388
+ );
2389
+ if (missingIds.length > 0) {
2390
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2391
+ }
2392
+ return result;
1211
2393
  }
1212
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1213
- }
1214
- if (isString(a) && isObject(b)) {
1215
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1216
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1217
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1218
- return record;
1219
- }
1220
- if (isObject(a) && isString(a.id)) {
1221
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1222
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1223
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1224
- return record;
1225
- }
1226
- throw new Error("Invalid arguments for createOrUpdate method");
2394
+ if (result === null) {
2395
+ const id = extractId(a) ?? "unknown";
2396
+ throw new Error(`Record with id ${id} not found`);
2397
+ }
2398
+ return result;
2399
+ });
1227
2400
  }
1228
- async delete(a) {
1229
- if (Array.isArray(a)) {
1230
- if (a.length > 100) {
1231
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
2401
+ async update(a, b, c, d) {
2402
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
2403
+ const ifVersion = parseIfVersion(b, c, d);
2404
+ if (Array.isArray(a)) {
2405
+ if (a.length === 0)
2406
+ return [];
2407
+ const existing = await this.read(a, ["id"]);
2408
+ const updates = a.filter((_item, index) => existing[index] !== null);
2409
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, updates, {
2410
+ ifVersion,
2411
+ upsert: false
2412
+ });
2413
+ const columns = isStringArray(b) ? b : ["*"];
2414
+ const result = await this.read(a, columns);
2415
+ return result;
1232
2416
  }
1233
- await Promise.all(a.map((id) => this.delete(id)));
1234
- return;
1235
- }
1236
- if (isString(a)) {
1237
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1238
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1239
- return;
1240
- }
1241
- if (isObject(a) && isString(a.id)) {
1242
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1243
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1244
- return;
1245
- }
1246
- throw new Error("Invalid arguments for delete method");
2417
+ if (isString(a) && isObject(b)) {
2418
+ const columns = isStringArray(c) ? c : void 0;
2419
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2420
+ }
2421
+ if (isObject(a) && isString(a.id)) {
2422
+ const columns = isStringArray(b) ? b : void 0;
2423
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2424
+ }
2425
+ throw new Error("Invalid arguments for update method");
2426
+ });
2427
+ }
2428
+ async updateOrThrow(a, b, c, d) {
2429
+ return __privateGet$4(this, _trace).call(this, "updateOrThrow", async () => {
2430
+ const result = await this.update(a, b, c, d);
2431
+ if (Array.isArray(result)) {
2432
+ const missingIds = compact(
2433
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2434
+ );
2435
+ if (missingIds.length > 0) {
2436
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2437
+ }
2438
+ return result;
2439
+ }
2440
+ if (result === null) {
2441
+ const id = extractId(a) ?? "unknown";
2442
+ throw new Error(`Record with id ${id} not found`);
2443
+ }
2444
+ return result;
2445
+ });
2446
+ }
2447
+ async createOrUpdate(a, b, c, d) {
2448
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
2449
+ const ifVersion = parseIfVersion(b, c, d);
2450
+ if (Array.isArray(a)) {
2451
+ if (a.length === 0)
2452
+ return [];
2453
+ await __privateMethod$2(this, _updateRecords, updateRecords_fn).call(this, a, {
2454
+ ifVersion,
2455
+ upsert: true
2456
+ });
2457
+ const columns = isStringArray(b) ? b : ["*"];
2458
+ const result = await this.read(a, columns);
2459
+ return result;
2460
+ }
2461
+ if (isString(a) && isObject(b)) {
2462
+ const columns = isStringArray(c) ? c : void 0;
2463
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns, { ifVersion });
2464
+ }
2465
+ if (isObject(a) && isString(a.id)) {
2466
+ const columns = isStringArray(c) ? c : void 0;
2467
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns, { ifVersion });
2468
+ }
2469
+ throw new Error("Invalid arguments for createOrUpdate method");
2470
+ });
2471
+ }
2472
+ async createOrReplace(a, b, c, d) {
2473
+ return __privateGet$4(this, _trace).call(this, "createOrReplace", async () => {
2474
+ const ifVersion = parseIfVersion(b, c, d);
2475
+ if (Array.isArray(a)) {
2476
+ if (a.length === 0)
2477
+ return [];
2478
+ const ids = await __privateMethod$2(this, _insertRecords, insertRecords_fn).call(this, a, { ifVersion, createOnly: false });
2479
+ const columns = isStringArray(b) ? b : ["*"];
2480
+ const result = await this.read(ids, columns);
2481
+ return result;
2482
+ }
2483
+ if (isString(a) && isObject(b)) {
2484
+ const columns = isStringArray(c) ? c : void 0;
2485
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns, { createOnly: false, ifVersion });
2486
+ }
2487
+ if (isObject(a) && isString(a.id)) {
2488
+ const columns = isStringArray(c) ? c : void 0;
2489
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns, { createOnly: false, ifVersion });
2490
+ }
2491
+ throw new Error("Invalid arguments for createOrReplace method");
2492
+ });
2493
+ }
2494
+ async delete(a, b) {
2495
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
2496
+ if (Array.isArray(a)) {
2497
+ if (a.length === 0)
2498
+ return [];
2499
+ const ids = a.map((o) => {
2500
+ if (isString(o))
2501
+ return o;
2502
+ if (isString(o.id))
2503
+ return o.id;
2504
+ throw new Error("Invalid arguments for delete method");
2505
+ });
2506
+ const columns = isStringArray(b) ? b : ["*"];
2507
+ const result = await this.read(a, columns);
2508
+ await __privateMethod$2(this, _deleteRecords, deleteRecords_fn).call(this, ids);
2509
+ return result;
2510
+ }
2511
+ if (isString(a)) {
2512
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
2513
+ }
2514
+ if (isObject(a) && isString(a.id)) {
2515
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
2516
+ }
2517
+ throw new Error("Invalid arguments for delete method");
2518
+ });
2519
+ }
2520
+ async deleteOrThrow(a, b) {
2521
+ return __privateGet$4(this, _trace).call(this, "deleteOrThrow", async () => {
2522
+ const result = await this.delete(a, b);
2523
+ if (Array.isArray(result)) {
2524
+ const missingIds = compact(
2525
+ a.filter((_item, index) => result[index] === null).map((item) => extractId(item))
2526
+ );
2527
+ if (missingIds.length > 0) {
2528
+ throw new Error(`Could not find records with ids: ${missingIds.join(", ")}`);
2529
+ }
2530
+ return result;
2531
+ } else if (result === null) {
2532
+ const id = extractId(a) ?? "unknown";
2533
+ throw new Error(`Record with id ${id} not found`);
2534
+ }
2535
+ return result;
2536
+ });
1247
2537
  }
1248
2538
  async search(query, options = {}) {
1249
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1250
- const { records } = await searchBranch({
1251
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1252
- body: { tables: [__privateGet$3(this, _table)], query, fuzziness: options.fuzziness },
1253
- ...fetchProps
2539
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
2540
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2541
+ const { records } = await searchTable({
2542
+ pathParams: {
2543
+ workspace: "{workspaceId}",
2544
+ dbBranchName: "{dbBranch}",
2545
+ region: "{region}",
2546
+ tableName: __privateGet$4(this, _table)
2547
+ },
2548
+ body: {
2549
+ query,
2550
+ fuzziness: options.fuzziness,
2551
+ prefix: options.prefix,
2552
+ highlight: options.highlight,
2553
+ filter: options.filter,
2554
+ boosters: options.boosters
2555
+ },
2556
+ ...fetchProps
2557
+ });
2558
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2559
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
2560
+ });
2561
+ }
2562
+ async aggregate(aggs, filter) {
2563
+ return __privateGet$4(this, _trace).call(this, "aggregate", async () => {
2564
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2565
+ const result = await aggregateTable({
2566
+ pathParams: {
2567
+ workspace: "{workspaceId}",
2568
+ dbBranchName: "{dbBranch}",
2569
+ region: "{region}",
2570
+ tableName: __privateGet$4(this, _table)
2571
+ },
2572
+ body: { aggs, filter },
2573
+ ...fetchProps
2574
+ });
2575
+ return result;
1254
2576
  });
1255
- return records.map((item) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), item));
1256
2577
  }
1257
2578
  async query(query) {
1258
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1259
- if (cacheQuery)
1260
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1261
- const data = query.getQueryOptions();
1262
- const body = {
1263
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1264
- sort: data.sort ? buildSortFilter(data.sort) : void 0,
1265
- page: data.page,
1266
- columns: data.columns
1267
- };
1268
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1269
- const { meta, records: objects } = await queryTable({
1270
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1271
- body,
1272
- ...fetchProps
2579
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
2580
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
2581
+ if (cacheQuery)
2582
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
2583
+ const data = query.getQueryOptions();
2584
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2585
+ const { meta, records: objects } = await queryTable({
2586
+ pathParams: {
2587
+ workspace: "{workspaceId}",
2588
+ dbBranchName: "{dbBranch}",
2589
+ region: "{region}",
2590
+ tableName: __privateGet$4(this, _table)
2591
+ },
2592
+ body: {
2593
+ filter: cleanFilter(data.filter),
2594
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2595
+ page: data.pagination,
2596
+ columns: data.columns ?? ["*"]
2597
+ },
2598
+ fetchOptions: data.fetchOptions,
2599
+ ...fetchProps
2600
+ });
2601
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2602
+ const records = objects.map(
2603
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
2604
+ );
2605
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
2606
+ return new Page(query, meta, records);
2607
+ });
2608
+ }
2609
+ async summarizeTable(query, summaries, summariesFilter) {
2610
+ return __privateGet$4(this, _trace).call(this, "summarize", async () => {
2611
+ const data = query.getQueryOptions();
2612
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2613
+ const result = await summarizeTable({
2614
+ pathParams: {
2615
+ workspace: "{workspaceId}",
2616
+ dbBranchName: "{dbBranch}",
2617
+ region: "{region}",
2618
+ tableName: __privateGet$4(this, _table)
2619
+ },
2620
+ body: {
2621
+ filter: cleanFilter(data.filter),
2622
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
2623
+ columns: data.columns,
2624
+ page: data.pagination?.size !== void 0 ? { size: data.pagination?.size } : void 0,
2625
+ summaries,
2626
+ summariesFilter
2627
+ },
2628
+ ...fetchProps
2629
+ });
2630
+ return result;
1273
2631
  });
1274
- const records = objects.map((record) => initObject(this.db, __privateGet$3(this, _links), __privateGet$3(this, _table), record));
1275
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1276
- return new Page(query, meta, records);
1277
2632
  }
1278
2633
  }
1279
2634
  _table = new WeakMap();
1280
- _links = new WeakMap();
1281
2635
  _getFetchProps = new WeakMap();
2636
+ _db = new WeakMap();
1282
2637
  _cache = new WeakMap();
2638
+ _schemaTables$2 = new WeakMap();
2639
+ _trace = new WeakMap();
1283
2640
  _insertRecordWithoutId = new WeakSet();
1284
- insertRecordWithoutId_fn = async function(object) {
1285
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
2641
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2642
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1286
2643
  const record = transformObjectLinks(object);
1287
2644
  const response = await insertRecord({
1288
2645
  pathParams: {
1289
2646
  workspace: "{workspaceId}",
1290
2647
  dbBranchName: "{dbBranch}",
1291
- tableName: __privateGet$3(this, _table)
2648
+ region: "{region}",
2649
+ tableName: __privateGet$4(this, _table)
1292
2650
  },
2651
+ queryParams: { columns },
1293
2652
  body: record,
1294
2653
  ...fetchProps
1295
2654
  });
1296
- const finalObject = await this.read(response.id);
1297
- if (!finalObject) {
1298
- throw new Error("The server failed to save the record");
1299
- }
1300
- return finalObject;
2655
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2656
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1301
2657
  };
1302
2658
  _insertRecordWithId = new WeakSet();
1303
- insertRecordWithId_fn = async function(recordId, object) {
1304
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
2659
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2660
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1305
2661
  const record = transformObjectLinks(object);
1306
2662
  const response = await insertRecordWithID({
1307
2663
  pathParams: {
1308
2664
  workspace: "{workspaceId}",
1309
2665
  dbBranchName: "{dbBranch}",
1310
- tableName: __privateGet$3(this, _table),
2666
+ region: "{region}",
2667
+ tableName: __privateGet$4(this, _table),
1311
2668
  recordId
1312
2669
  },
1313
2670
  body: record,
1314
- queryParams: { createOnly: true },
1315
- ...fetchProps
1316
- });
1317
- const finalObject = await this.read(response.id);
1318
- if (!finalObject) {
1319
- throw new Error("The server failed to save the record");
1320
- }
1321
- return finalObject;
1322
- };
1323
- _bulkInsertTableRecords = new WeakSet();
1324
- bulkInsertTableRecords_fn = async function(objects) {
1325
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1326
- const records = objects.map((object) => transformObjectLinks(object));
1327
- const response = await bulkInsertTableRecords({
1328
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table) },
1329
- body: { records },
2671
+ queryParams: { createOnly, columns, ifVersion },
1330
2672
  ...fetchProps
1331
2673
  });
1332
- const finalObjects = await this.any(...response.recordIDs.map((id) => this.filter("id", id))).getAll();
1333
- if (finalObjects.length !== objects.length) {
1334
- throw new Error("The server failed to save some records");
2674
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2675
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2676
+ };
2677
+ _insertRecords = new WeakSet();
2678
+ insertRecords_fn = async function(objects, { createOnly, ifVersion }) {
2679
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2680
+ const chunkedOperations = chunk(
2681
+ objects.map((object) => ({
2682
+ insert: { table: __privateGet$4(this, _table), record: transformObjectLinks(object), createOnly, ifVersion }
2683
+ })),
2684
+ BULK_OPERATION_MAX_SIZE
2685
+ );
2686
+ const ids = [];
2687
+ for (const operations of chunkedOperations) {
2688
+ const { results } = await branchTransaction({
2689
+ pathParams: {
2690
+ workspace: "{workspaceId}",
2691
+ dbBranchName: "{dbBranch}",
2692
+ region: "{region}"
2693
+ },
2694
+ body: { operations },
2695
+ ...fetchProps
2696
+ });
2697
+ for (const result of results) {
2698
+ if (result.operation === "insert") {
2699
+ ids.push(result.id);
2700
+ } else {
2701
+ ids.push(null);
2702
+ }
2703
+ }
1335
2704
  }
1336
- return finalObjects;
2705
+ return ids;
1337
2706
  };
1338
2707
  _updateRecordWithID = new WeakSet();
1339
- updateRecordWithID_fn = async function(recordId, object) {
1340
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1341
- const record = transformObjectLinks(object);
1342
- const response = await updateRecordWithID({
1343
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1344
- body: record,
1345
- ...fetchProps
1346
- });
1347
- const item = await this.read(response.id);
1348
- if (!item)
1349
- throw new Error("The server failed to save the record");
1350
- return item;
2708
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2709
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2710
+ const { id: _id, ...record } = transformObjectLinks(object);
2711
+ try {
2712
+ const response = await updateRecordWithID({
2713
+ pathParams: {
2714
+ workspace: "{workspaceId}",
2715
+ dbBranchName: "{dbBranch}",
2716
+ region: "{region}",
2717
+ tableName: __privateGet$4(this, _table),
2718
+ recordId
2719
+ },
2720
+ queryParams: { columns, ifVersion },
2721
+ body: record,
2722
+ ...fetchProps
2723
+ });
2724
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2725
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2726
+ } catch (e) {
2727
+ if (isObject(e) && e.status === 404) {
2728
+ return null;
2729
+ }
2730
+ throw e;
2731
+ }
2732
+ };
2733
+ _updateRecords = new WeakSet();
2734
+ updateRecords_fn = async function(objects, { ifVersion, upsert }) {
2735
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2736
+ const chunkedOperations = chunk(
2737
+ objects.map(({ id, ...object }) => ({
2738
+ update: { table: __privateGet$4(this, _table), id, ifVersion, upsert, fields: transformObjectLinks(object) }
2739
+ })),
2740
+ BULK_OPERATION_MAX_SIZE
2741
+ );
2742
+ const ids = [];
2743
+ for (const operations of chunkedOperations) {
2744
+ const { results } = await branchTransaction({
2745
+ pathParams: {
2746
+ workspace: "{workspaceId}",
2747
+ dbBranchName: "{dbBranch}",
2748
+ region: "{region}"
2749
+ },
2750
+ body: { operations },
2751
+ ...fetchProps
2752
+ });
2753
+ for (const result of results) {
2754
+ if (result.operation === "update") {
2755
+ ids.push(result.id);
2756
+ } else {
2757
+ ids.push(null);
2758
+ }
2759
+ }
2760
+ }
2761
+ return ids;
1351
2762
  };
1352
2763
  _upsertRecordWithID = new WeakSet();
1353
- upsertRecordWithID_fn = async function(recordId, object) {
1354
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
2764
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2765
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1355
2766
  const response = await upsertRecordWithID({
1356
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
2767
+ pathParams: {
2768
+ workspace: "{workspaceId}",
2769
+ dbBranchName: "{dbBranch}",
2770
+ region: "{region}",
2771
+ tableName: __privateGet$4(this, _table),
2772
+ recordId
2773
+ },
2774
+ queryParams: { columns, ifVersion },
1357
2775
  body: object,
1358
2776
  ...fetchProps
1359
2777
  });
1360
- const item = await this.read(response.id);
1361
- if (!item)
1362
- throw new Error("The server failed to save the record");
1363
- return item;
2778
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2779
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1364
2780
  };
1365
2781
  _deleteRecord = new WeakSet();
1366
- deleteRecord_fn = async function(recordId) {
1367
- const fetchProps = await __privateGet$3(this, _getFetchProps).call(this);
1368
- await deleteRecord({
1369
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$3(this, _table), recordId },
1370
- ...fetchProps
1371
- });
2782
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2783
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2784
+ try {
2785
+ const response = await deleteRecord({
2786
+ pathParams: {
2787
+ workspace: "{workspaceId}",
2788
+ dbBranchName: "{dbBranch}",
2789
+ region: "{region}",
2790
+ tableName: __privateGet$4(this, _table),
2791
+ recordId
2792
+ },
2793
+ queryParams: { columns },
2794
+ ...fetchProps
2795
+ });
2796
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
2797
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
2798
+ } catch (e) {
2799
+ if (isObject(e) && e.status === 404) {
2800
+ return null;
2801
+ }
2802
+ throw e;
2803
+ }
1372
2804
  };
1373
- _invalidateCache = new WeakSet();
1374
- invalidateCache_fn = async function(recordId) {
1375
- await __privateGet$3(this, _cache).delete(`rec_${__privateGet$3(this, _table)}:${recordId}`);
1376
- const cacheItems = await __privateGet$3(this, _cache).getAll();
1377
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1378
- for (const [key, value] of queries) {
1379
- const ids = getIds(value);
1380
- if (ids.includes(recordId))
1381
- await __privateGet$3(this, _cache).delete(key);
1382
- }
1383
- };
1384
- _setCacheRecord = new WeakSet();
1385
- setCacheRecord_fn = async function(record) {
1386
- if (!__privateGet$3(this, _cache).cacheRecords)
1387
- return;
1388
- await __privateGet$3(this, _cache).set(`rec_${__privateGet$3(this, _table)}:${record.id}`, record);
1389
- };
1390
- _getCacheRecord = new WeakSet();
1391
- getCacheRecord_fn = async function(recordId) {
1392
- if (!__privateGet$3(this, _cache).cacheRecords)
1393
- return null;
1394
- return __privateGet$3(this, _cache).get(`rec_${__privateGet$3(this, _table)}:${recordId}`);
2805
+ _deleteRecords = new WeakSet();
2806
+ deleteRecords_fn = async function(recordIds) {
2807
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2808
+ const chunkedOperations = chunk(
2809
+ recordIds.map((id) => ({ delete: { table: __privateGet$4(this, _table), id } })),
2810
+ BULK_OPERATION_MAX_SIZE
2811
+ );
2812
+ for (const operations of chunkedOperations) {
2813
+ await branchTransaction({
2814
+ pathParams: {
2815
+ workspace: "{workspaceId}",
2816
+ dbBranchName: "{dbBranch}",
2817
+ region: "{region}"
2818
+ },
2819
+ body: { operations },
2820
+ ...fetchProps
2821
+ });
2822
+ }
1395
2823
  };
1396
2824
  _setCacheQuery = new WeakSet();
1397
2825
  setCacheQuery_fn = async function(query, meta, records) {
1398
- await __privateGet$3(this, _cache).set(`query_${__privateGet$3(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2826
+ await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1399
2827
  };
1400
2828
  _getCacheQuery = new WeakSet();
1401
2829
  getCacheQuery_fn = async function(query) {
1402
- const key = `query_${__privateGet$3(this, _table)}:${query.key()}`;
1403
- const result = await __privateGet$3(this, _cache).get(key);
2830
+ const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2831
+ const result = await __privateGet$4(this, _cache).get(key);
1404
2832
  if (!result)
1405
2833
  return null;
1406
- const { cache: ttl = __privateGet$3(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1407
- if (!ttl || ttl < 0)
1408
- return result;
2834
+ const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
2835
+ if (ttl < 0)
2836
+ return null;
1409
2837
  const hasExpired = result.date.getTime() + ttl < Date.now();
1410
2838
  return hasExpired ? null : result;
1411
2839
  };
2840
+ _getSchemaTables$1 = new WeakSet();
2841
+ getSchemaTables_fn$1 = async function() {
2842
+ if (__privateGet$4(this, _schemaTables$2))
2843
+ return __privateGet$4(this, _schemaTables$2);
2844
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2845
+ const { schema } = await getBranchDetails({
2846
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2847
+ ...fetchProps
2848
+ });
2849
+ __privateSet$4(this, _schemaTables$2, schema.tables);
2850
+ return schema.tables;
2851
+ };
1412
2852
  const transformObjectLinks = (object) => {
1413
2853
  return Object.entries(object).reduce((acc, [key, value]) => {
1414
2854
  if (key === "xata")
@@ -1416,47 +2856,111 @@ const transformObjectLinks = (object) => {
1416
2856
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1417
2857
  }, {});
1418
2858
  };
1419
- const initObject = (db, links, table, object) => {
2859
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
1420
2860
  const result = {};
1421
- Object.assign(result, object);
1422
- const tableLinks = links[table] || [];
1423
- for (const link of tableLinks) {
1424
- const [field, linkTable] = link;
1425
- const value = result[field];
1426
- if (value && isObject(value)) {
1427
- result[field] = initObject(db, links, linkTable, value);
2861
+ const { xata, ...rest } = object ?? {};
2862
+ Object.assign(result, rest);
2863
+ const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2864
+ if (!columns)
2865
+ console.error(`Table ${table} not found in schema`);
2866
+ for (const column of columns ?? []) {
2867
+ if (!isValidColumn(selectedColumns, column))
2868
+ continue;
2869
+ const value = result[column.name];
2870
+ switch (column.type) {
2871
+ case "datetime": {
2872
+ const date = value !== void 0 ? new Date(value) : null;
2873
+ if (date !== null && isNaN(date.getTime())) {
2874
+ console.error(`Failed to parse date ${value} for field ${column.name}`);
2875
+ } else {
2876
+ result[column.name] = date;
2877
+ }
2878
+ break;
2879
+ }
2880
+ case "link": {
2881
+ const linkTable = column.link?.table;
2882
+ if (!linkTable) {
2883
+ console.error(`Failed to parse link for field ${column.name}`);
2884
+ } else if (isObject(value)) {
2885
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2886
+ if (item === column.name) {
2887
+ return [...acc, "*"];
2888
+ }
2889
+ if (item.startsWith(`${column.name}.`)) {
2890
+ const [, ...path] = item.split(".");
2891
+ return [...acc, path.join(".")];
2892
+ }
2893
+ return acc;
2894
+ }, []);
2895
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2896
+ } else {
2897
+ result[column.name] = null;
2898
+ }
2899
+ break;
2900
+ }
2901
+ default:
2902
+ result[column.name] = value ?? null;
2903
+ if (column.notNull === true && value === null) {
2904
+ console.error(`Parse error, column ${column.name} is non nullable and value resolves null`);
2905
+ }
2906
+ break;
1428
2907
  }
1429
2908
  }
1430
- result.read = function() {
1431
- return db[table].read(result["id"]);
2909
+ result.read = function(columns2) {
2910
+ return db[table].read(result["id"], columns2);
2911
+ };
2912
+ result.update = function(data, b, c) {
2913
+ const columns2 = isStringArray(b) ? b : ["*"];
2914
+ const ifVersion = parseIfVersion(b, c);
2915
+ return db[table].update(result["id"], data, columns2, { ifVersion });
1432
2916
  };
1433
- result.update = function(data) {
1434
- return db[table].update(result["id"], data);
2917
+ result.replace = function(data, b, c) {
2918
+ const columns2 = isStringArray(b) ? b : ["*"];
2919
+ const ifVersion = parseIfVersion(b, c);
2920
+ return db[table].createOrReplace(result["id"], data, columns2, { ifVersion });
1435
2921
  };
1436
2922
  result.delete = function() {
1437
2923
  return db[table].delete(result["id"]);
1438
2924
  };
1439
- for (const prop of ["read", "update", "delete"]) {
2925
+ result.getMetadata = function() {
2926
+ return xata;
2927
+ };
2928
+ for (const prop of ["read", "update", "replace", "delete", "getMetadata"]) {
1440
2929
  Object.defineProperty(result, prop, { enumerable: false });
1441
2930
  }
1442
2931
  Object.freeze(result);
1443
2932
  return result;
1444
2933
  };
1445
- function getIds(value) {
1446
- if (Array.isArray(value)) {
1447
- return value.map((item) => getIds(item)).flat();
2934
+ function extractId(value) {
2935
+ if (isString(value))
2936
+ return value;
2937
+ if (isObject(value) && isString(value.id))
2938
+ return value.id;
2939
+ return void 0;
2940
+ }
2941
+ function isValidColumn(columns, column) {
2942
+ if (columns.includes("*"))
2943
+ return true;
2944
+ if (column.type === "link") {
2945
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2946
+ return linkColumns.length > 0;
2947
+ }
2948
+ return columns.includes(column.name);
2949
+ }
2950
+ function parseIfVersion(...args) {
2951
+ for (const arg of args) {
2952
+ if (isObject(arg) && isNumber(arg.ifVersion)) {
2953
+ return arg.ifVersion;
2954
+ }
1448
2955
  }
1449
- if (!isObject(value))
1450
- return [];
1451
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1452
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
2956
+ return void 0;
1453
2957
  }
1454
2958
 
1455
2959
  var __accessCheck$3 = (obj, member, msg) => {
1456
2960
  if (!member.has(obj))
1457
2961
  throw TypeError("Cannot " + msg);
1458
2962
  };
1459
- var __privateGet$2 = (obj, member, getter) => {
2963
+ var __privateGet$3 = (obj, member, getter) => {
1460
2964
  __accessCheck$3(obj, member, "read from private field");
1461
2965
  return getter ? getter.call(obj) : member.get(obj);
1462
2966
  };
@@ -1465,7 +2969,7 @@ var __privateAdd$3 = (obj, member, value) => {
1465
2969
  throw TypeError("Cannot add the same private member more than once");
1466
2970
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1467
2971
  };
1468
- var __privateSet$1 = (obj, member, value, setter) => {
2972
+ var __privateSet$3 = (obj, member, value, setter) => {
1469
2973
  __accessCheck$3(obj, member, "write to private field");
1470
2974
  setter ? setter.call(obj, value) : member.set(obj, value);
1471
2975
  return value;
@@ -1474,46 +2978,52 @@ var _map;
1474
2978
  class SimpleCache {
1475
2979
  constructor(options = {}) {
1476
2980
  __privateAdd$3(this, _map, void 0);
1477
- __privateSet$1(this, _map, /* @__PURE__ */ new Map());
2981
+ __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1478
2982
  this.capacity = options.max ?? 500;
1479
- this.cacheRecords = options.cacheRecords ?? true;
1480
2983
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1481
2984
  }
1482
2985
  async getAll() {
1483
- return Object.fromEntries(__privateGet$2(this, _map));
2986
+ return Object.fromEntries(__privateGet$3(this, _map));
1484
2987
  }
1485
2988
  async get(key) {
1486
- return __privateGet$2(this, _map).get(key) ?? null;
2989
+ return __privateGet$3(this, _map).get(key) ?? null;
1487
2990
  }
1488
2991
  async set(key, value) {
1489
2992
  await this.delete(key);
1490
- __privateGet$2(this, _map).set(key, value);
1491
- if (__privateGet$2(this, _map).size > this.capacity) {
1492
- const leastRecentlyUsed = __privateGet$2(this, _map).keys().next().value;
2993
+ __privateGet$3(this, _map).set(key, value);
2994
+ if (__privateGet$3(this, _map).size > this.capacity) {
2995
+ const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
1493
2996
  await this.delete(leastRecentlyUsed);
1494
2997
  }
1495
2998
  }
1496
2999
  async delete(key) {
1497
- __privateGet$2(this, _map).delete(key);
3000
+ __privateGet$3(this, _map).delete(key);
1498
3001
  }
1499
3002
  async clear() {
1500
- return __privateGet$2(this, _map).clear();
3003
+ return __privateGet$3(this, _map).clear();
1501
3004
  }
1502
3005
  }
1503
3006
  _map = new WeakMap();
1504
3007
 
1505
- const gt = (value) => ({ $gt: value });
1506
- const ge = (value) => ({ $ge: value });
1507
- const gte = (value) => ({ $ge: value });
1508
- const lt = (value) => ({ $lt: value });
1509
- const lte = (value) => ({ $le: value });
1510
- const le = (value) => ({ $le: value });
3008
+ const greaterThan = (value) => ({ $gt: value });
3009
+ const gt = greaterThan;
3010
+ const greaterThanEquals = (value) => ({ $ge: value });
3011
+ const greaterEquals = greaterThanEquals;
3012
+ const gte = greaterThanEquals;
3013
+ const ge = greaterThanEquals;
3014
+ const lessThan = (value) => ({ $lt: value });
3015
+ const lt = lessThan;
3016
+ const lessThanEquals = (value) => ({ $le: value });
3017
+ const lessEquals = lessThanEquals;
3018
+ const lte = lessThanEquals;
3019
+ const le = lessThanEquals;
1511
3020
  const exists = (column) => ({ $exists: column });
1512
3021
  const notExists = (column) => ({ $notExists: column });
1513
3022
  const startsWith = (value) => ({ $startsWith: value });
1514
3023
  const endsWith = (value) => ({ $endsWith: value });
1515
3024
  const pattern = (value) => ({ $pattern: value });
1516
3025
  const is = (value) => ({ $is: value });
3026
+ const equals = is;
1517
3027
  const isNot = (value) => ({ $isNot: value });
1518
3028
  const contains = (value) => ({ $contains: value });
1519
3029
  const includes = (value) => ({ $includes: value });
@@ -1525,7 +3035,7 @@ var __accessCheck$2 = (obj, member, msg) => {
1525
3035
  if (!member.has(obj))
1526
3036
  throw TypeError("Cannot " + msg);
1527
3037
  };
1528
- var __privateGet$1 = (obj, member, getter) => {
3038
+ var __privateGet$2 = (obj, member, getter) => {
1529
3039
  __accessCheck$2(obj, member, "read from private field");
1530
3040
  return getter ? getter.call(obj) : member.get(obj);
1531
3041
  };
@@ -1534,143 +3044,210 @@ var __privateAdd$2 = (obj, member, value) => {
1534
3044
  throw TypeError("Cannot add the same private member more than once");
1535
3045
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1536
3046
  };
1537
- var _tables;
3047
+ var __privateSet$2 = (obj, member, value, setter) => {
3048
+ __accessCheck$2(obj, member, "write to private field");
3049
+ setter ? setter.call(obj, value) : member.set(obj, value);
3050
+ return value;
3051
+ };
3052
+ var _tables, _schemaTables$1;
1538
3053
  class SchemaPlugin extends XataPlugin {
1539
- constructor(links, tableNames) {
3054
+ constructor(schemaTables) {
1540
3055
  super();
1541
- this.links = links;
1542
- this.tableNames = tableNames;
1543
3056
  __privateAdd$2(this, _tables, {});
3057
+ __privateAdd$2(this, _schemaTables$1, void 0);
3058
+ __privateSet$2(this, _schemaTables$1, schemaTables);
1544
3059
  }
1545
3060
  build(pluginOptions) {
1546
- const links = this.links;
1547
- const db = new Proxy({}, {
1548
- get: (_target, table) => {
1549
- if (!isString(table))
1550
- throw new Error("Invalid table name");
1551
- if (!__privateGet$1(this, _tables)[table]) {
1552
- __privateGet$1(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, links });
3061
+ const db = new Proxy(
3062
+ {},
3063
+ {
3064
+ get: (_target, table) => {
3065
+ if (!isString(table))
3066
+ throw new Error("Invalid table name");
3067
+ if (__privateGet$2(this, _tables)[table] === void 0) {
3068
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
3069
+ }
3070
+ return __privateGet$2(this, _tables)[table];
1553
3071
  }
1554
- return __privateGet$1(this, _tables)[table];
1555
3072
  }
1556
- });
1557
- for (const table of this.tableNames ?? []) {
1558
- db[table] = new RestRepository({ db, pluginOptions, table, links });
3073
+ );
3074
+ const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
3075
+ for (const table of tableNames) {
3076
+ db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1559
3077
  }
1560
3078
  return db;
1561
3079
  }
1562
3080
  }
1563
3081
  _tables = new WeakMap();
3082
+ _schemaTables$1 = new WeakMap();
1564
3083
 
1565
3084
  var __accessCheck$1 = (obj, member, msg) => {
1566
3085
  if (!member.has(obj))
1567
3086
  throw TypeError("Cannot " + msg);
1568
3087
  };
3088
+ var __privateGet$1 = (obj, member, getter) => {
3089
+ __accessCheck$1(obj, member, "read from private field");
3090
+ return getter ? getter.call(obj) : member.get(obj);
3091
+ };
1569
3092
  var __privateAdd$1 = (obj, member, value) => {
1570
3093
  if (member.has(obj))
1571
3094
  throw TypeError("Cannot add the same private member more than once");
1572
3095
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1573
3096
  };
3097
+ var __privateSet$1 = (obj, member, value, setter) => {
3098
+ __accessCheck$1(obj, member, "write to private field");
3099
+ setter ? setter.call(obj, value) : member.set(obj, value);
3100
+ return value;
3101
+ };
1574
3102
  var __privateMethod$1 = (obj, member, method) => {
1575
3103
  __accessCheck$1(obj, member, "access private method");
1576
3104
  return method;
1577
3105
  };
1578
- var _search, search_fn;
3106
+ var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
1579
3107
  class SearchPlugin extends XataPlugin {
1580
- constructor(db, links) {
3108
+ constructor(db, schemaTables) {
1581
3109
  super();
1582
3110
  this.db = db;
1583
- this.links = links;
1584
3111
  __privateAdd$1(this, _search);
3112
+ __privateAdd$1(this, _getSchemaTables);
3113
+ __privateAdd$1(this, _schemaTables, void 0);
3114
+ __privateSet$1(this, _schemaTables, schemaTables);
1585
3115
  }
1586
3116
  build({ getFetchProps }) {
1587
3117
  return {
1588
3118
  all: async (query, options = {}) => {
1589
3119
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3120
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1590
3121
  return records.map((record) => {
1591
3122
  const { table = "orphan" } = record.xata;
1592
- return { table, record: initObject(this.db, this.links, table, record) };
3123
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1593
3124
  });
1594
3125
  },
1595
3126
  byTable: async (query, options = {}) => {
1596
3127
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
3128
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1597
3129
  return records.reduce((acc, record) => {
1598
3130
  const { table = "orphan" } = record.xata;
1599
3131
  const items = acc[table] ?? [];
1600
- const item = initObject(this.db, this.links, table, record);
3132
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1601
3133
  return { ...acc, [table]: [...items, item] };
1602
3134
  }, {});
1603
3135
  }
1604
3136
  };
1605
3137
  }
1606
3138
  }
3139
+ _schemaTables = new WeakMap();
1607
3140
  _search = new WeakSet();
1608
3141
  search_fn = async function(query, options, getFetchProps) {
1609
3142
  const fetchProps = await getFetchProps();
1610
- const { tables, fuzziness } = options ?? {};
3143
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1611
3144
  const { records } = await searchBranch({
1612
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1613
- body: { tables, query, fuzziness },
3145
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3146
+ body: { tables, query, fuzziness, prefix, highlight },
1614
3147
  ...fetchProps
1615
3148
  });
1616
3149
  return records;
1617
3150
  };
3151
+ _getSchemaTables = new WeakSet();
3152
+ getSchemaTables_fn = async function(getFetchProps) {
3153
+ if (__privateGet$1(this, _schemaTables))
3154
+ return __privateGet$1(this, _schemaTables);
3155
+ const fetchProps = await getFetchProps();
3156
+ const { schema } = await getBranchDetails({
3157
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3158
+ ...fetchProps
3159
+ });
3160
+ __privateSet$1(this, _schemaTables, schema.tables);
3161
+ return schema.tables;
3162
+ };
3163
+
3164
+ class TransactionPlugin extends XataPlugin {
3165
+ build({ getFetchProps }) {
3166
+ return {
3167
+ run: async (operations) => {
3168
+ const fetchProps = await getFetchProps();
3169
+ const response = await branchTransaction({
3170
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
3171
+ body: { operations },
3172
+ ...fetchProps
3173
+ });
3174
+ return response;
3175
+ }
3176
+ };
3177
+ }
3178
+ }
1618
3179
 
1619
3180
  const isBranchStrategyBuilder = (strategy) => {
1620
3181
  return typeof strategy === "function";
1621
3182
  };
1622
3183
 
1623
- const envBranchNames = [
1624
- "XATA_BRANCH",
1625
- "VERCEL_GIT_COMMIT_REF",
1626
- "CF_PAGES_BRANCH",
1627
- "BRANCH"
1628
- ];
1629
- const defaultBranch = "main";
1630
3184
  async function getCurrentBranchName(options) {
1631
- const env = await getBranchByEnvVariable();
1632
- if (env)
1633
- return env;
1634
- const branch = await getGitBranch();
1635
- if (!branch)
1636
- return defaultBranch;
1637
- const details = await getDatabaseBranch(branch, options);
1638
- if (details)
1639
- return branch;
1640
- return defaultBranch;
3185
+ const { branch, envBranch } = getEnvironment();
3186
+ if (branch) {
3187
+ const details = await getDatabaseBranch(branch, options);
3188
+ if (details)
3189
+ return branch;
3190
+ console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
3191
+ }
3192
+ const gitBranch = envBranch || await getGitBranch();
3193
+ return resolveXataBranch(gitBranch, options);
1641
3194
  }
1642
3195
  async function getCurrentBranchDetails(options) {
1643
- const env = await getBranchByEnvVariable();
1644
- if (env)
1645
- return getDatabaseBranch(env, options);
1646
- const branch = await getGitBranch();
1647
- if (!branch)
1648
- return getDatabaseBranch(defaultBranch, options);
1649
- const details = await getDatabaseBranch(branch, options);
1650
- if (details)
1651
- return details;
1652
- return getDatabaseBranch(defaultBranch, options);
3196
+ const branch = await getCurrentBranchName(options);
3197
+ return getDatabaseBranch(branch, options);
3198
+ }
3199
+ async function resolveXataBranch(gitBranch, options) {
3200
+ const databaseURL = options?.databaseURL || getDatabaseURL();
3201
+ const apiKey = options?.apiKey || getAPIKey();
3202
+ if (!databaseURL)
3203
+ throw new Error(
3204
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3205
+ );
3206
+ if (!apiKey)
3207
+ throw new Error(
3208
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3209
+ );
3210
+ const [protocol, , host, , dbName] = databaseURL.split("/");
3211
+ const urlParts = parseWorkspacesUrlParts(host);
3212
+ if (!urlParts)
3213
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3214
+ const { workspace, region } = urlParts;
3215
+ const { fallbackBranch } = getEnvironment();
3216
+ const { branch } = await resolveBranch({
3217
+ apiKey,
3218
+ apiUrl: databaseURL,
3219
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
3220
+ workspacesApiUrl: `${protocol}//${host}`,
3221
+ pathParams: { dbName, workspace, region },
3222
+ queryParams: { gitBranch, fallbackBranch },
3223
+ trace: defaultTrace
3224
+ });
3225
+ return branch;
1653
3226
  }
1654
3227
  async function getDatabaseBranch(branch, options) {
1655
3228
  const databaseURL = options?.databaseURL || getDatabaseURL();
1656
3229
  const apiKey = options?.apiKey || getAPIKey();
1657
3230
  if (!databaseURL)
1658
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
3231
+ throw new Error(
3232
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
3233
+ );
1659
3234
  if (!apiKey)
1660
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
3235
+ throw new Error(
3236
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
3237
+ );
1661
3238
  const [protocol, , host, , database] = databaseURL.split("/");
1662
- const [workspace] = host.split(".");
1663
- const dbBranchName = `${database}:${branch}`;
3239
+ const urlParts = parseWorkspacesUrlParts(host);
3240
+ if (!urlParts)
3241
+ throw new Error(`Unable to parse workspace and region: ${databaseURL}`);
3242
+ const { workspace, region } = urlParts;
1664
3243
  try {
1665
3244
  return await getBranchDetails({
1666
3245
  apiKey,
1667
3246
  apiUrl: databaseURL,
1668
3247
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1669
3248
  workspacesApiUrl: `${protocol}//${host}`,
1670
- pathParams: {
1671
- dbBranchName,
1672
- workspace
1673
- }
3249
+ pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3250
+ trace: defaultTrace
1674
3251
  });
1675
3252
  } catch (err) {
1676
3253
  if (isObject(err) && err.status === 404)
@@ -1678,21 +3255,10 @@ async function getDatabaseBranch(branch, options) {
1678
3255
  throw err;
1679
3256
  }
1680
3257
  }
1681
- function getBranchByEnvVariable() {
1682
- for (const name of envBranchNames) {
1683
- const value = getEnvVariable(name);
1684
- if (value) {
1685
- return value;
1686
- }
1687
- }
1688
- try {
1689
- return XATA_BRANCH;
1690
- } catch (err) {
1691
- }
1692
- }
1693
3258
  function getDatabaseURL() {
1694
3259
  try {
1695
- return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
3260
+ const { databaseURL } = getEnvironment();
3261
+ return databaseURL;
1696
3262
  } catch (err) {
1697
3263
  return void 0;
1698
3264
  }
@@ -1721,24 +3287,29 @@ var __privateMethod = (obj, member, method) => {
1721
3287
  return method;
1722
3288
  };
1723
3289
  const buildClient = (plugins) => {
1724
- var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
3290
+ var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1725
3291
  return _a = class {
1726
- constructor(options = {}, links, tables) {
3292
+ constructor(options = {}, schemaTables) {
1727
3293
  __privateAdd(this, _parseOptions);
1728
3294
  __privateAdd(this, _getFetchProps);
1729
3295
  __privateAdd(this, _evaluateBranch);
1730
3296
  __privateAdd(this, _branch, void 0);
3297
+ __privateAdd(this, _options, void 0);
1731
3298
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
3299
+ __privateSet(this, _options, safeOptions);
1732
3300
  const pluginOptions = {
1733
3301
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1734
- cache: safeOptions.cache
3302
+ cache: safeOptions.cache,
3303
+ trace: safeOptions.trace
1735
3304
  };
1736
- const db = new SchemaPlugin(links, tables).build(pluginOptions);
1737
- const search = new SearchPlugin(db, links ?? {}).build(pluginOptions);
3305
+ const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3306
+ const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
3307
+ const transactions = new TransactionPlugin().build(pluginOptions);
1738
3308
  this.db = db;
1739
3309
  this.search = search;
3310
+ this.transactions = transactions;
1740
3311
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1741
- if (!namespace)
3312
+ if (namespace === void 0)
1742
3313
  continue;
1743
3314
  const result = namespace.build(pluginOptions);
1744
3315
  if (result instanceof Promise) {
@@ -1750,22 +3321,33 @@ const buildClient = (plugins) => {
1750
3321
  }
1751
3322
  }
1752
3323
  }
1753
- }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3324
+ async getConfig() {
3325
+ const databaseURL = __privateGet(this, _options).databaseURL;
3326
+ const branch = await __privateGet(this, _options).branch();
3327
+ return { databaseURL, branch };
3328
+ }
3329
+ }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
3330
+ const enableBrowser = options?.enableBrowser ?? getEnableBrowserVariable() ?? false;
3331
+ const isBrowser = typeof window !== "undefined";
3332
+ if (isBrowser && !enableBrowser) {
3333
+ throw new Error(
3334
+ "You are trying to use Xata from the browser, which is potentially a non-secure environment. If you understand the security concerns, such as leaking your credentials, pass `enableBrowser: true` to the client options to remove this error."
3335
+ );
3336
+ }
1754
3337
  const fetch = getFetchImplementation(options?.fetch);
1755
3338
  const databaseURL = options?.databaseURL || getDatabaseURL();
1756
3339
  const apiKey = options?.apiKey || getAPIKey();
1757
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
1758
- const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1759
- if (!databaseURL || !apiKey) {
1760
- throw new Error("Options databaseURL and apiKey are required");
3340
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
3341
+ const trace = options?.trace ?? defaultTrace;
3342
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
3343
+ if (!apiKey) {
3344
+ throw new Error("Option apiKey is required");
1761
3345
  }
1762
- return { fetch, databaseURL, apiKey, branch, cache };
1763
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1764
- fetch,
1765
- apiKey,
1766
- databaseURL,
1767
- branch
1768
- }) {
3346
+ if (!databaseURL) {
3347
+ throw new Error("Option databaseURL is required");
3348
+ }
3349
+ return { fetch, databaseURL, apiKey, branch, cache, trace, clientID: generateUUID(), enableBrowser };
3350
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace, clientID }) {
1769
3351
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
1770
3352
  if (!branchValue)
1771
3353
  throw new Error("Unable to resolve branch value");
@@ -1775,14 +3357,16 @@ const buildClient = (plugins) => {
1775
3357
  apiUrl: "",
1776
3358
  workspacesApiUrl: (path, params) => {
1777
3359
  const hasBranch = params.dbBranchName ?? params.branch;
1778
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
3360
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
1779
3361
  return databaseURL + newPath;
1780
- }
3362
+ },
3363
+ trace,
3364
+ clientID
1781
3365
  };
1782
3366
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
1783
3367
  if (__privateGet(this, _branch))
1784
3368
  return __privateGet(this, _branch);
1785
- if (!param)
3369
+ if (param === void 0)
1786
3370
  return void 0;
1787
3371
  const strategies = Array.isArray(param) ? [...param] : [param];
1788
3372
  const evaluateBranch = async (strategy) => {
@@ -1800,6 +3384,88 @@ const buildClient = (plugins) => {
1800
3384
  class BaseClient extends buildClient() {
1801
3385
  }
1802
3386
 
3387
+ const META = "__";
3388
+ const VALUE = "___";
3389
+ class Serializer {
3390
+ constructor() {
3391
+ this.classes = {};
3392
+ }
3393
+ add(clazz) {
3394
+ this.classes[clazz.name] = clazz;
3395
+ }
3396
+ toJSON(data) {
3397
+ function visit(obj) {
3398
+ if (Array.isArray(obj))
3399
+ return obj.map(visit);
3400
+ const type = typeof obj;
3401
+ if (type === "undefined")
3402
+ return { [META]: "undefined" };
3403
+ if (type === "bigint")
3404
+ return { [META]: "bigint", [VALUE]: obj.toString() };
3405
+ if (obj === null || type !== "object")
3406
+ return obj;
3407
+ const constructor = obj.constructor;
3408
+ const o = { [META]: constructor.name };
3409
+ for (const [key, value] of Object.entries(obj)) {
3410
+ o[key] = visit(value);
3411
+ }
3412
+ if (constructor === Date)
3413
+ o[VALUE] = obj.toISOString();
3414
+ if (constructor === Map)
3415
+ o[VALUE] = Object.fromEntries(obj);
3416
+ if (constructor === Set)
3417
+ o[VALUE] = [...obj];
3418
+ return o;
3419
+ }
3420
+ return JSON.stringify(visit(data));
3421
+ }
3422
+ fromJSON(json) {
3423
+ return JSON.parse(json, (key, value) => {
3424
+ if (value && typeof value === "object" && !Array.isArray(value)) {
3425
+ const { [META]: clazz, [VALUE]: val, ...rest } = value;
3426
+ const constructor = this.classes[clazz];
3427
+ if (constructor) {
3428
+ return Object.assign(Object.create(constructor.prototype), rest);
3429
+ }
3430
+ if (clazz === "Date")
3431
+ return new Date(val);
3432
+ if (clazz === "Set")
3433
+ return new Set(val);
3434
+ if (clazz === "Map")
3435
+ return new Map(Object.entries(val));
3436
+ if (clazz === "bigint")
3437
+ return BigInt(val);
3438
+ if (clazz === "undefined")
3439
+ return void 0;
3440
+ return rest;
3441
+ }
3442
+ return value;
3443
+ });
3444
+ }
3445
+ }
3446
+ const defaultSerializer = new Serializer();
3447
+ const serialize = (data) => {
3448
+ return defaultSerializer.toJSON(data);
3449
+ };
3450
+ const deserialize = (json) => {
3451
+ return defaultSerializer.fromJSON(json);
3452
+ };
3453
+
3454
+ function buildWorkerRunner(config) {
3455
+ return function xataWorker(name, _worker) {
3456
+ return async (...args) => {
3457
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
3458
+ const result = await fetch(url, {
3459
+ method: "POST",
3460
+ headers: { "Content-Type": "application/json" },
3461
+ body: serialize({ args })
3462
+ });
3463
+ const text = await result.text();
3464
+ return deserialize(text);
3465
+ };
3466
+ };
3467
+ }
3468
+
1803
3469
  class XataError extends Error {
1804
3470
  constructor(message, status) {
1805
3471
  super(message);
@@ -1815,26 +3481,42 @@ exports.PAGINATION_MAX_OFFSET = PAGINATION_MAX_OFFSET;
1815
3481
  exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
1816
3482
  exports.Page = Page;
1817
3483
  exports.Query = Query;
3484
+ exports.RecordArray = RecordArray;
1818
3485
  exports.Repository = Repository;
1819
3486
  exports.RestRepository = RestRepository;
1820
3487
  exports.SchemaPlugin = SchemaPlugin;
1821
3488
  exports.SearchPlugin = SearchPlugin;
3489
+ exports.Serializer = Serializer;
1822
3490
  exports.SimpleCache = SimpleCache;
1823
3491
  exports.XataApiClient = XataApiClient;
1824
3492
  exports.XataApiPlugin = XataApiPlugin;
1825
3493
  exports.XataError = XataError;
1826
3494
  exports.XataPlugin = XataPlugin;
1827
3495
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
3496
+ exports.addGitBranchesEntry = addGitBranchesEntry;
1828
3497
  exports.addTableColumn = addTableColumn;
3498
+ exports.aggregateTable = aggregateTable;
3499
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3500
+ exports.branchTransaction = branchTransaction;
1829
3501
  exports.buildClient = buildClient;
3502
+ exports.buildWorkerRunner = buildWorkerRunner;
1830
3503
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
1831
3504
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
3505
+ exports.compareBranchSchemas = compareBranchSchemas;
3506
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3507
+ exports.compareMigrationRequest = compareMigrationRequest;
1832
3508
  exports.contains = contains;
1833
3509
  exports.createBranch = createBranch;
1834
3510
  exports.createDatabase = createDatabase;
3511
+ exports.createMigrationRequest = createMigrationRequest;
1835
3512
  exports.createTable = createTable;
1836
3513
  exports.createUserAPIKey = createUserAPIKey;
1837
3514
  exports.createWorkspace = createWorkspace;
3515
+ exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
3516
+ exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
3517
+ exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
3518
+ exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
3519
+ exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
1838
3520
  exports.deleteBranch = deleteBranch;
1839
3521
  exports.deleteColumn = deleteColumn;
1840
3522
  exports.deleteDatabase = deleteDatabase;
@@ -1843,7 +3525,9 @@ exports.deleteTable = deleteTable;
1843
3525
  exports.deleteUser = deleteUser;
1844
3526
  exports.deleteUserAPIKey = deleteUserAPIKey;
1845
3527
  exports.deleteWorkspace = deleteWorkspace;
3528
+ exports.deserialize = deserialize;
1846
3529
  exports.endsWith = endsWith;
3530
+ exports.equals = equals;
1847
3531
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
1848
3532
  exports.exists = exists;
1849
3533
  exports.ge = ge;
@@ -1853,12 +3537,18 @@ exports.getBranchList = getBranchList;
1853
3537
  exports.getBranchMetadata = getBranchMetadata;
1854
3538
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
1855
3539
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
3540
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
1856
3541
  exports.getBranchStats = getBranchStats;
1857
3542
  exports.getColumn = getColumn;
1858
3543
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
1859
3544
  exports.getCurrentBranchName = getCurrentBranchName;
1860
3545
  exports.getDatabaseList = getDatabaseList;
3546
+ exports.getDatabaseMetadata = getDatabaseMetadata;
1861
3547
  exports.getDatabaseURL = getDatabaseURL;
3548
+ exports.getGitBranchesMapping = getGitBranchesMapping;
3549
+ exports.getHostUrl = getHostUrl;
3550
+ exports.getMigrationRequest = getMigrationRequest;
3551
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
1862
3552
  exports.getRecord = getRecord;
1863
3553
  exports.getTableColumns = getTableColumns;
1864
3554
  exports.getTableSchema = getTableSchema;
@@ -1867,6 +3557,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
1867
3557
  exports.getWorkspace = getWorkspace;
1868
3558
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
1869
3559
  exports.getWorkspacesList = getWorkspacesList;
3560
+ exports.greaterEquals = greaterEquals;
3561
+ exports.greaterThan = greaterThan;
3562
+ exports.greaterThanEquals = greaterThanEquals;
1870
3563
  exports.gt = gt;
1871
3564
  exports.gte = gte;
1872
3565
  exports.includes = includes;
@@ -1877,27 +3570,49 @@ exports.insertRecord = insertRecord;
1877
3570
  exports.insertRecordWithID = insertRecordWithID;
1878
3571
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
1879
3572
  exports.is = is;
3573
+ exports.isCursorPaginationOptions = isCursorPaginationOptions;
3574
+ exports.isHostProviderAlias = isHostProviderAlias;
3575
+ exports.isHostProviderBuilder = isHostProviderBuilder;
1880
3576
  exports.isIdentifiable = isIdentifiable;
1881
3577
  exports.isNot = isNot;
1882
3578
  exports.isXataRecord = isXataRecord;
1883
3579
  exports.le = le;
3580
+ exports.lessEquals = lessEquals;
3581
+ exports.lessThan = lessThan;
3582
+ exports.lessThanEquals = lessThanEquals;
3583
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3584
+ exports.listRegions = listRegions;
1884
3585
  exports.lt = lt;
1885
3586
  exports.lte = lte;
3587
+ exports.mergeMigrationRequest = mergeMigrationRequest;
1886
3588
  exports.notExists = notExists;
1887
3589
  exports.operationsByTag = operationsByTag;
3590
+ exports.parseProviderString = parseProviderString;
3591
+ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
1888
3592
  exports.pattern = pattern;
3593
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3594
+ exports.queryMigrationRequests = queryMigrationRequests;
1889
3595
  exports.queryTable = queryTable;
3596
+ exports.removeGitBranchesEntry = removeGitBranchesEntry;
1890
3597
  exports.removeWorkspaceMember = removeWorkspaceMember;
1891
3598
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
3599
+ exports.resolveBranch = resolveBranch;
1892
3600
  exports.searchBranch = searchBranch;
3601
+ exports.searchTable = searchTable;
3602
+ exports.serialize = serialize;
1893
3603
  exports.setTableSchema = setTableSchema;
1894
3604
  exports.startsWith = startsWith;
3605
+ exports.summarizeTable = summarizeTable;
1895
3606
  exports.updateBranchMetadata = updateBranchMetadata;
3607
+ exports.updateBranchSchema = updateBranchSchema;
1896
3608
  exports.updateColumn = updateColumn;
3609
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
3610
+ exports.updateMigrationRequest = updateMigrationRequest;
1897
3611
  exports.updateRecordWithID = updateRecordWithID;
1898
3612
  exports.updateTable = updateTable;
1899
3613
  exports.updateUser = updateUser;
1900
3614
  exports.updateWorkspace = updateWorkspace;
3615
+ exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
1901
3616
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
1902
3617
  exports.upsertRecordWithID = upsertRecordWithID;
1903
3618
  //# sourceMappingURL=index.cjs.map