@xata.io/client 0.0.0-alpha.vf2043e7 → 0.0.0-alpha.vf217b0e

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