@xata.io/client 0.0.0-alpha.vf6d8daa → 0.0.0-alpha.vf6f217e

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