@xata.io/client 0.0.0-alpha.vf0f8e71 → 0.0.0-alpha.vf0fa187

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