@xata.io/client 0.0.0-alpha.vf7b5320 → 0.0.0-alpha.vf7c7a24

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