@xata.io/client 0.0.0-alpha.vf89b33e → 0.0.0-alpha.vf8f3b02

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,36 +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";
45
+ }
46
+ function toBase64(value) {
47
+ try {
48
+ return btoa(value);
49
+ } catch (err) {
50
+ const buf = Buffer;
51
+ return buf.from(value).toString("base64");
52
+ }
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;
16
64
  }
17
65
 
18
- function getEnvVariable(name) {
66
+ function getEnvironment() {
19
67
  try {
20
- if (isObject(process) && isString(process?.env?.[name])) {
21
- 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
+ };
22
76
  }
23
77
  } catch (err) {
24
78
  }
25
79
  try {
26
- if (isObject(Deno) && isString(Deno?.env?.get(name))) {
27
- 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
+ };
28
88
  }
29
89
  } catch (err) {
30
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";
103
+ }
104
+ } catch (err) {
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
+ }
31
145
  }
32
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"] };
33
151
  try {
34
- return require("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
152
+ if (typeof require === "function") {
153
+ return require(nodeModule).execSync(fullCmd, execOptions).trim();
154
+ }
155
+ const { execSync } = await import(nodeModule);
156
+ return execSync(fullCmd, execOptions).toString().trim();
35
157
  } catch (err) {
36
158
  }
37
159
  try {
38
160
  if (isObject(Deno)) {
39
- const process2 = Deno.run({
40
- cmd: ["git", "branch", "--show-current"],
41
- stdout: "piped",
42
- stderr: "piped"
43
- });
161
+ const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
44
162
  return new TextDecoder().decode(await process2.output()).trim();
45
163
  }
46
164
  } catch (err) {
@@ -49,7 +167,8 @@ async function getGitBranch() {
49
167
 
50
168
  function getAPIKey() {
51
169
  try {
52
- return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
170
+ const { apiKey } = getEnvironment();
171
+ return apiKey;
53
172
  } catch (err) {
54
173
  return void 0;
55
174
  }
@@ -59,21 +178,35 @@ function getFetchImplementation(userFetch) {
59
178
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
60
179
  const fetchImpl = userFetch ?? globalFetch;
61
180
  if (!fetchImpl) {
62
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
181
+ throw new Error(
182
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
183
+ );
63
184
  }
64
185
  return fetchImpl;
65
186
  }
66
187
 
67
- class FetcherError extends Error {
68
- constructor(status, data) {
188
+ const VERSION = "0.0.0-alpha.vf8f3b02";
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) {
69
197
  super(getMessage(data));
70
198
  this.status = status;
71
199
  this.errors = isBulkError(data) ? data.errors : void 0;
200
+ this.requestId = requestId;
72
201
  if (data instanceof Error) {
73
202
  this.stack = data.stack;
74
203
  this.cause = data.cause;
75
204
  }
76
205
  }
206
+ toString() {
207
+ const error = super.toString();
208
+ return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
209
+ }
77
210
  }
78
211
  function isBulkError(error) {
79
212
  return isObject(error) && Array.isArray(error.errors);
@@ -96,20 +229,31 @@ function getMessage(data) {
96
229
  }
97
230
 
98
231
  const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
99
- 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();
100
238
  const queryString = query.length > 0 ? `?${query}` : "";
101
- 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;
102
243
  };
103
244
  function buildBaseUrl({
245
+ endpoint,
104
246
  path,
105
247
  workspacesApiUrl,
106
248
  apiUrl,
107
- pathParams
249
+ pathParams = {}
108
250
  }) {
109
- if (!pathParams?.workspace)
110
- return `${apiUrl}${path}`;
111
- const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
112
- return url.replace("{workspaceId}", pathParams.workspace);
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}`;
113
257
  }
114
258
  function hostHeader(url) {
115
259
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -125,255 +269,232 @@ async function fetch$1({
125
269
  queryParams,
126
270
  fetchImpl,
127
271
  apiKey,
272
+ endpoint,
128
273
  apiUrl,
129
- workspacesApiUrl
274
+ workspacesApiUrl,
275
+ trace,
276
+ signal,
277
+ clientID,
278
+ sessionID,
279
+ fetchOptions = {}
130
280
  }) {
131
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
132
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
133
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
134
- const response = await fetchImpl(url, {
135
- method: method.toUpperCase(),
136
- body: body ? JSON.stringify(body) : void 0,
137
- headers: {
138
- "Content-Type": "application/json",
139
- ...headers,
140
- ...hostHeader(fullUrl),
141
- Authorization: `Bearer ${apiKey}`
142
- }
143
- });
144
- if (response.status === 204) {
145
- return {};
146
- }
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) {
147
332
  try {
148
- const jsonResponse = await response.json();
149
- if (response.ok) {
150
- return jsonResponse;
151
- }
152
- throw new FetcherError(response.status, jsonResponse);
333
+ const { host, protocol } = new URL(url);
334
+ return { host, protocol };
153
335
  } catch (error) {
154
- throw new FetcherError(response.status, error);
336
+ return {};
155
337
  }
156
338
  }
157
339
 
158
- const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
159
- const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
160
- const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
161
- const getUserAPIKeys = (variables) => fetch$1({
162
- url: "/user/keys",
163
- method: "get",
164
- ...variables
165
- });
166
- const createUserAPIKey = (variables) => fetch$1({
167
- url: "/user/keys/{keyName}",
168
- method: "post",
169
- ...variables
170
- });
171
- const deleteUserAPIKey = (variables) => fetch$1({
172
- url: "/user/keys/{keyName}",
173
- method: "delete",
174
- ...variables
175
- });
176
- const createWorkspace = (variables) => fetch$1({
177
- url: "/workspaces",
178
- method: "post",
179
- ...variables
180
- });
181
- const getWorkspacesList = (variables) => fetch$1({
182
- url: "/workspaces",
183
- method: "get",
184
- ...variables
185
- });
186
- const getWorkspace = (variables) => fetch$1({
187
- url: "/workspaces/{workspaceId}",
188
- method: "get",
189
- ...variables
190
- });
191
- const updateWorkspace = (variables) => fetch$1({
192
- url: "/workspaces/{workspaceId}",
193
- method: "put",
194
- ...variables
195
- });
196
- const deleteWorkspace = (variables) => fetch$1({
197
- url: "/workspaces/{workspaceId}",
198
- method: "delete",
199
- ...variables
200
- });
201
- const getWorkspaceMembersList = (variables) => fetch$1({
202
- url: "/workspaces/{workspaceId}/members",
203
- method: "get",
204
- ...variables
205
- });
206
- const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
207
- const removeWorkspaceMember = (variables) => fetch$1({
208
- url: "/workspaces/{workspaceId}/members/{userId}",
209
- method: "delete",
210
- ...variables
211
- });
212
- const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
213
- const cancelWorkspaceMemberInvite = (variables) => fetch$1({
214
- url: "/workspaces/{workspaceId}/invites/{inviteId}",
215
- method: "delete",
216
- ...variables
217
- });
218
- const resendWorkspaceMemberInvite = (variables) => fetch$1({
219
- url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
220
- method: "post",
221
- ...variables
222
- });
223
- const acceptWorkspaceMemberInvite = (variables) => fetch$1({
224
- url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
225
- method: "post",
226
- ...variables
227
- });
228
- const getDatabaseList = (variables) => fetch$1({
229
- url: "/dbs",
230
- method: "get",
231
- ...variables
232
- });
233
- const getBranchList = (variables) => fetch$1({
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({
234
344
  url: "/dbs/{dbName}",
235
345
  method: "get",
236
- ...variables
237
- });
238
- const createDatabase = (variables) => fetch$1({
239
- url: "/dbs/{dbName}",
240
- method: "put",
241
- ...variables
242
- });
243
- const deleteDatabase = (variables) => fetch$1({
244
- url: "/dbs/{dbName}",
245
- method: "delete",
246
- ...variables
346
+ ...variables,
347
+ signal
247
348
  });
248
- 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({
249
354
  url: "/db/{dbBranchName}",
250
355
  method: "get",
251
- ...variables
356
+ ...variables,
357
+ signal
252
358
  });
253
- const createBranch = (variables) => fetch$1({
254
- url: "/db/{dbBranchName}",
255
- method: "put",
256
- ...variables
257
- });
258
- const deleteBranch = (variables) => fetch$1({
359
+ const createBranch = (variables, signal) => dataPlaneFetch({ url: "/db/{dbBranchName}", method: "put", ...variables, signal });
360
+ const deleteBranch = (variables, signal) => dataPlaneFetch({
259
361
  url: "/db/{dbBranchName}",
260
362
  method: "delete",
261
- ...variables
363
+ ...variables,
364
+ signal
262
365
  });
263
- const updateBranchMetadata = (variables) => fetch$1({
366
+ const updateBranchMetadata = (variables, signal) => dataPlaneFetch({
264
367
  url: "/db/{dbBranchName}/metadata",
265
368
  method: "put",
266
- ...variables
369
+ ...variables,
370
+ signal
267
371
  });
268
- const getBranchMetadata = (variables) => fetch$1({
372
+ const getBranchMetadata = (variables, signal) => dataPlaneFetch({
269
373
  url: "/db/{dbBranchName}/metadata",
270
374
  method: "get",
271
- ...variables
375
+ ...variables,
376
+ signal
272
377
  });
273
- const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
274
- const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
275
- const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
276
- const getBranchStats = (variables) => fetch$1({
378
+ const getBranchStats = (variables, signal) => dataPlaneFetch({
277
379
  url: "/db/{dbBranchName}/stats",
278
380
  method: "get",
279
- ...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
399
+ });
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
280
409
  });
281
- const createTable = (variables) => fetch$1({
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({
282
417
  url: "/db/{dbBranchName}/tables/{tableName}",
283
418
  method: "put",
284
- ...variables
419
+ ...variables,
420
+ signal
285
421
  });
286
- const deleteTable = (variables) => fetch$1({
422
+ const deleteTable = (variables, signal) => dataPlaneFetch({
287
423
  url: "/db/{dbBranchName}/tables/{tableName}",
288
424
  method: "delete",
289
- ...variables
290
- });
291
- const updateTable = (variables) => fetch$1({
292
- url: "/db/{dbBranchName}/tables/{tableName}",
293
- method: "patch",
294
- ...variables
425
+ ...variables,
426
+ signal
295
427
  });
296
- 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({
297
430
  url: "/db/{dbBranchName}/tables/{tableName}/schema",
298
431
  method: "get",
299
- ...variables
300
- });
301
- const setTableSchema = (variables) => fetch$1({
302
- url: "/db/{dbBranchName}/tables/{tableName}/schema",
303
- method: "put",
304
- ...variables
432
+ ...variables,
433
+ signal
305
434
  });
306
- 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({
307
437
  url: "/db/{dbBranchName}/tables/{tableName}/columns",
308
438
  method: "get",
309
- ...variables
439
+ ...variables,
440
+ signal
310
441
  });
311
- const addTableColumn = (variables) => fetch$1({
312
- url: "/db/{dbBranchName}/tables/{tableName}/columns",
313
- method: "post",
314
- ...variables
315
- });
316
- 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({
317
446
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
318
447
  method: "get",
319
- ...variables
448
+ ...variables,
449
+ signal
320
450
  });
321
- const deleteColumn = (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({
322
453
  url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
323
454
  method: "delete",
324
- ...variables
455
+ ...variables,
456
+ signal
325
457
  });
326
- const updateColumn = (variables) => fetch$1({
327
- url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
328
- method: "patch",
329
- ...variables
330
- });
331
- const insertRecord = (variables) => fetch$1({
332
- url: "/db/{dbBranchName}/tables/{tableName}/data",
333
- method: "post",
334
- ...variables
335
- });
336
- const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
337
- const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
338
- const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
339
- const deleteRecord = (variables) => fetch$1({
340
- url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
341
- method: "delete",
342
- ...variables
343
- });
344
- 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({
345
460
  url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
346
461
  method: "get",
347
- ...variables
462
+ ...variables,
463
+ signal
348
464
  });
349
- const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
350
- 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({
351
471
  url: "/db/{dbBranchName}/tables/{tableName}/query",
352
472
  method: "post",
353
- ...variables
473
+ ...variables,
474
+ signal
354
475
  });
355
- const searchBranch = (variables) => fetch$1({
476
+ const searchBranch = (variables, signal) => dataPlaneFetch({
356
477
  url: "/db/{dbBranchName}/search",
357
478
  method: "post",
358
- ...variables
479
+ ...variables,
480
+ signal
359
481
  });
360
- const operationsByTag = {
361
- users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
362
- workspaces: {
363
- createWorkspace,
364
- getWorkspacesList,
365
- getWorkspace,
366
- updateWorkspace,
367
- deleteWorkspace,
368
- getWorkspaceMembersList,
369
- updateWorkspaceMemberRole,
370
- removeWorkspaceMember,
371
- inviteWorkspaceMember,
372
- cancelWorkspaceMemberInvite,
373
- resendWorkspaceMemberInvite,
374
- acceptWorkspaceMemberInvite
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 = {
491
+ database: {
492
+ dEPRECATEDgetDatabaseList,
493
+ dEPRECATEDcreateDatabase,
494
+ dEPRECATEDdeleteDatabase,
495
+ dEPRECATEDgetDatabaseMetadata,
496
+ dEPRECATEDupdateDatabaseMetadata
375
497
  },
376
- database: { getDatabaseList, createDatabase, deleteDatabase },
377
498
  branch: {
378
499
  getBranchList,
379
500
  getBranchDetails,
@@ -381,10 +502,42 @@ const operationsByTag = {
381
502
  deleteBranch,
382
503
  updateBranchMetadata,
383
504
  getBranchMetadata,
505
+ getBranchStats,
506
+ getGitBranchesMapping,
507
+ addGitBranchesEntry,
508
+ removeGitBranchesEntry,
509
+ resolveBranch
510
+ },
511
+ migrations: {
384
512
  getBranchMigrationHistory,
385
- executeBranchMigrationPlan,
386
513
  getBranchMigrationPlan,
387
- 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
388
541
  },
389
542
  table: {
390
543
  createTable,
@@ -395,26 +548,150 @@ const operationsByTag = {
395
548
  getTableColumns,
396
549
  addTableColumn,
397
550
  getColumn,
398
- deleteColumn,
399
- updateColumn
551
+ updateColumn,
552
+ deleteColumn
400
553
  },
401
- records: {
402
- insertRecord,
403
- insertRecordWithID,
404
- updateRecordWithID,
405
- upsertRecordWithID,
406
- deleteRecord,
407
- getRecord,
408
- bulkInsertTableRecords,
409
- queryTable,
410
- 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
411
686
  }
412
687
  };
413
688
 
689
+ const operationsByTag = deepMerge(operationsByTag$2, operationsByTag$1);
690
+
414
691
  function getHostUrl(provider, type) {
415
- if (isValidAlias(provider)) {
692
+ if (isHostProviderAlias(provider)) {
416
693
  return providers[provider][type];
417
- } else if (isValidBuilder(provider)) {
694
+ } else if (isHostProviderBuilder(provider)) {
418
695
  return provider[type];
419
696
  }
420
697
  throw new Error("Invalid API provider");
@@ -422,84 +699,130 @@ function getHostUrl(provider, type) {
422
699
  const providers = {
423
700
  production: {
424
701
  main: "https://api.xata.io",
425
- workspaces: "https://{workspaceId}.xata.sh"
702
+ workspaces: "https://{workspaceId}.{region}.xata.sh"
426
703
  },
427
704
  staging: {
428
705
  main: "https://staging.xatabase.co",
429
- workspaces: "https://{workspaceId}.staging.xatabase.co"
706
+ workspaces: "https://{workspaceId}.staging.{region}.xatabase.co"
430
707
  }
431
708
  };
432
- function isValidAlias(alias) {
709
+ function isHostProviderAlias(alias) {
433
710
  return isString(alias) && Object.keys(providers).includes(alias);
434
711
  }
435
- function isValidBuilder(builder) {
712
+ function isHostProviderBuilder(builder) {
436
713
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
437
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
+ }
438
734
 
439
- var __accessCheck$6 = (obj, member, msg) => {
735
+ var __accessCheck$7 = (obj, member, msg) => {
440
736
  if (!member.has(obj))
441
737
  throw TypeError("Cannot " + msg);
442
738
  };
443
- var __privateGet$5 = (obj, member, getter) => {
444
- __accessCheck$6(obj, member, "read from private field");
739
+ var __privateGet$7 = (obj, member, getter) => {
740
+ __accessCheck$7(obj, member, "read from private field");
445
741
  return getter ? getter.call(obj) : member.get(obj);
446
742
  };
447
- var __privateAdd$6 = (obj, member, value) => {
743
+ var __privateAdd$7 = (obj, member, value) => {
448
744
  if (member.has(obj))
449
745
  throw TypeError("Cannot add the same private member more than once");
450
746
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
451
747
  };
452
- var __privateSet$4 = (obj, member, value, setter) => {
453
- __accessCheck$6(obj, member, "write to private field");
748
+ var __privateSet$7 = (obj, member, value, setter) => {
749
+ __accessCheck$7(obj, member, "write to private field");
454
750
  setter ? setter.call(obj, value) : member.set(obj, value);
455
751
  return value;
456
752
  };
457
753
  var _extraProps, _namespaces;
458
754
  class XataApiClient {
459
755
  constructor(options = {}) {
460
- __privateAdd$6(this, _extraProps, void 0);
461
- __privateAdd$6(this, _namespaces, {});
756
+ __privateAdd$7(this, _extraProps, void 0);
757
+ __privateAdd$7(this, _namespaces, {});
462
758
  const provider = options.host ?? "production";
463
- const apiKey = options?.apiKey ?? getAPIKey();
759
+ const apiKey = options.apiKey ?? getAPIKey();
760
+ const trace = options.trace ?? defaultTrace;
464
761
  if (!apiKey) {
465
762
  throw new Error("Could not resolve a valid apiKey");
466
763
  }
467
- __privateSet$4(this, _extraProps, {
764
+ __privateSet$7(this, _extraProps, {
468
765
  apiUrl: getHostUrl(provider, "main"),
469
766
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
470
767
  fetchImpl: getFetchImplementation(options.fetch),
471
- apiKey
768
+ apiKey,
769
+ trace
472
770
  });
473
771
  }
474
772
  get user() {
475
- if (!__privateGet$5(this, _namespaces).user)
476
- __privateGet$5(this, _namespaces).user = new UserApi(__privateGet$5(this, _extraProps));
477
- return __privateGet$5(this, _namespaces).user;
773
+ if (!__privateGet$7(this, _namespaces).user)
774
+ __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
775
+ return __privateGet$7(this, _namespaces).user;
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;
478
781
  }
479
782
  get workspaces() {
480
- if (!__privateGet$5(this, _namespaces).workspaces)
481
- __privateGet$5(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$5(this, _extraProps));
482
- return __privateGet$5(this, _namespaces).workspaces;
783
+ if (!__privateGet$7(this, _namespaces).workspaces)
784
+ __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
785
+ return __privateGet$7(this, _namespaces).workspaces;
483
786
  }
484
- get databases() {
485
- if (!__privateGet$5(this, _namespaces).databases)
486
- __privateGet$5(this, _namespaces).databases = new DatabaseApi(__privateGet$5(this, _extraProps));
487
- return __privateGet$5(this, _namespaces).databases;
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;
488
796
  }
489
797
  get branches() {
490
- if (!__privateGet$5(this, _namespaces).branches)
491
- __privateGet$5(this, _namespaces).branches = new BranchApi(__privateGet$5(this, _extraProps));
492
- return __privateGet$5(this, _namespaces).branches;
798
+ if (!__privateGet$7(this, _namespaces).branches)
799
+ __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
800
+ return __privateGet$7(this, _namespaces).branches;
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;
493
811
  }
494
812
  get tables() {
495
- if (!__privateGet$5(this, _namespaces).tables)
496
- __privateGet$5(this, _namespaces).tables = new TableApi(__privateGet$5(this, _extraProps));
497
- return __privateGet$5(this, _namespaces).tables;
813
+ if (!__privateGet$7(this, _namespaces).tables)
814
+ __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
815
+ return __privateGet$7(this, _namespaces).tables;
498
816
  }
499
817
  get records() {
500
- if (!__privateGet$5(this, _namespaces).records)
501
- __privateGet$5(this, _namespaces).records = new RecordsApi(__privateGet$5(this, _extraProps));
502
- return __privateGet$5(this, _namespaces).records;
818
+ if (!__privateGet$7(this, _namespaces).records)
819
+ __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
820
+ return __privateGet$7(this, _namespaces).records;
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;
503
826
  }
504
827
  }
505
828
  _extraProps = new WeakMap();
@@ -511,24 +834,29 @@ class UserApi {
511
834
  getUser() {
512
835
  return operationsByTag.users.getUser({ ...this.extraProps });
513
836
  }
514
- updateUser(user) {
837
+ updateUser({ user }) {
515
838
  return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
516
839
  }
517
840
  deleteUser() {
518
841
  return operationsByTag.users.deleteUser({ ...this.extraProps });
519
842
  }
843
+ }
844
+ class AuthenticationApi {
845
+ constructor(extraProps) {
846
+ this.extraProps = extraProps;
847
+ }
520
848
  getUserAPIKeys() {
521
- return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
849
+ return operationsByTag.authentication.getUserAPIKeys({ ...this.extraProps });
522
850
  }
523
- createUserAPIKey(keyName) {
524
- return operationsByTag.users.createUserAPIKey({
525
- pathParams: { keyName },
851
+ createUserAPIKey({ name }) {
852
+ return operationsByTag.authentication.createUserAPIKey({
853
+ pathParams: { keyName: name },
526
854
  ...this.extraProps
527
855
  });
528
856
  }
529
- deleteUserAPIKey(keyName) {
530
- return operationsByTag.users.deleteUserAPIKey({
531
- pathParams: { keyName },
857
+ deleteUserAPIKey({ name }) {
858
+ return operationsByTag.authentication.deleteUserAPIKey({
859
+ pathParams: { keyName: name },
532
860
  ...this.extraProps
533
861
  });
534
862
  }
@@ -537,99 +865,114 @@ class WorkspaceApi {
537
865
  constructor(extraProps) {
538
866
  this.extraProps = extraProps;
539
867
  }
540
- createWorkspace(workspaceMeta) {
868
+ getWorkspacesList() {
869
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
870
+ }
871
+ createWorkspace({ data }) {
541
872
  return operationsByTag.workspaces.createWorkspace({
542
- body: workspaceMeta,
873
+ body: data,
543
874
  ...this.extraProps
544
875
  });
545
876
  }
546
- getWorkspacesList() {
547
- return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
548
- }
549
- getWorkspace(workspaceId) {
877
+ getWorkspace({ workspace }) {
550
878
  return operationsByTag.workspaces.getWorkspace({
551
- pathParams: { workspaceId },
879
+ pathParams: { workspaceId: workspace },
552
880
  ...this.extraProps
553
881
  });
554
882
  }
555
- updateWorkspace(workspaceId, workspaceMeta) {
883
+ updateWorkspace({
884
+ workspace,
885
+ update
886
+ }) {
556
887
  return operationsByTag.workspaces.updateWorkspace({
557
- pathParams: { workspaceId },
558
- body: workspaceMeta,
888
+ pathParams: { workspaceId: workspace },
889
+ body: update,
559
890
  ...this.extraProps
560
891
  });
561
892
  }
562
- deleteWorkspace(workspaceId) {
893
+ deleteWorkspace({ workspace }) {
563
894
  return operationsByTag.workspaces.deleteWorkspace({
564
- pathParams: { workspaceId },
895
+ pathParams: { workspaceId: workspace },
565
896
  ...this.extraProps
566
897
  });
567
898
  }
568
- getWorkspaceMembersList(workspaceId) {
899
+ getWorkspaceMembersList({ workspace }) {
569
900
  return operationsByTag.workspaces.getWorkspaceMembersList({
570
- pathParams: { workspaceId },
901
+ pathParams: { workspaceId: workspace },
571
902
  ...this.extraProps
572
903
  });
573
904
  }
574
- updateWorkspaceMemberRole(workspaceId, userId, role) {
905
+ updateWorkspaceMemberRole({
906
+ workspace,
907
+ user,
908
+ role
909
+ }) {
575
910
  return operationsByTag.workspaces.updateWorkspaceMemberRole({
576
- pathParams: { workspaceId, userId },
911
+ pathParams: { workspaceId: workspace, userId: user },
577
912
  body: { role },
578
913
  ...this.extraProps
579
914
  });
580
915
  }
581
- removeWorkspaceMember(workspaceId, userId) {
916
+ removeWorkspaceMember({
917
+ workspace,
918
+ user
919
+ }) {
582
920
  return operationsByTag.workspaces.removeWorkspaceMember({
583
- pathParams: { workspaceId, userId },
921
+ pathParams: { workspaceId: workspace, userId: user },
584
922
  ...this.extraProps
585
923
  });
586
924
  }
587
- inviteWorkspaceMember(workspaceId, email, role) {
588
- return operationsByTag.workspaces.inviteWorkspaceMember({
589
- pathParams: { workspaceId },
590
- body: { email, role },
591
- ...this.extraProps
592
- });
593
- }
594
- cancelWorkspaceMemberInvite(workspaceId, inviteId) {
595
- return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
596
- pathParams: { workspaceId, inviteId },
597
- ...this.extraProps
598
- });
925
+ }
926
+ class InvitesApi {
927
+ constructor(extraProps) {
928
+ this.extraProps = extraProps;
599
929
  }
600
- resendWorkspaceMemberInvite(workspaceId, inviteId) {
601
- return operationsByTag.workspaces.resendWorkspaceMemberInvite({
602
- pathParams: { workspaceId, inviteId },
930
+ inviteWorkspaceMember({
931
+ workspace,
932
+ email,
933
+ role
934
+ }) {
935
+ return operationsByTag.invites.inviteWorkspaceMember({
936
+ pathParams: { workspaceId: workspace },
937
+ body: { email, role },
603
938
  ...this.extraProps
604
939
  });
605
940
  }
606
- acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
607
- return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
608
- pathParams: { workspaceId, inviteKey },
941
+ updateWorkspaceMemberInvite({
942
+ workspace,
943
+ invite,
944
+ role
945
+ }) {
946
+ return operationsByTag.invites.updateWorkspaceMemberInvite({
947
+ pathParams: { workspaceId: workspace, inviteId: invite },
948
+ body: { role },
609
949
  ...this.extraProps
610
950
  });
611
951
  }
612
- }
613
- class DatabaseApi {
614
- constructor(extraProps) {
615
- this.extraProps = extraProps;
616
- }
617
- getDatabaseList(workspace) {
618
- return operationsByTag.database.getDatabaseList({
619
- pathParams: { workspace },
952
+ cancelWorkspaceMemberInvite({
953
+ workspace,
954
+ invite
955
+ }) {
956
+ return operationsByTag.invites.cancelWorkspaceMemberInvite({
957
+ pathParams: { workspaceId: workspace, inviteId: invite },
620
958
  ...this.extraProps
621
959
  });
622
960
  }
623
- createDatabase(workspace, dbName, options = {}) {
624
- return operationsByTag.database.createDatabase({
625
- pathParams: { workspace, dbName },
626
- body: options,
961
+ acceptWorkspaceMemberInvite({
962
+ workspace,
963
+ key
964
+ }) {
965
+ return operationsByTag.invites.acceptWorkspaceMemberInvite({
966
+ pathParams: { workspaceId: workspace, inviteKey: key },
627
967
  ...this.extraProps
628
968
  });
629
969
  }
630
- deleteDatabase(workspace, dbName) {
631
- return operationsByTag.database.deleteDatabase({
632
- pathParams: { workspace, dbName },
970
+ resendWorkspaceMemberInvite({
971
+ workspace,
972
+ invite
973
+ }) {
974
+ return operationsByTag.invites.resendWorkspaceMemberInvite({
975
+ pathParams: { workspaceId: workspace, inviteId: invite },
633
976
  ...this.extraProps
634
977
  });
635
978
  }
@@ -638,69 +981,132 @@ class BranchApi {
638
981
  constructor(extraProps) {
639
982
  this.extraProps = extraProps;
640
983
  }
641
- getBranchList(workspace, dbName) {
984
+ getBranchList({
985
+ workspace,
986
+ region,
987
+ database
988
+ }) {
642
989
  return operationsByTag.branch.getBranchList({
643
- pathParams: { workspace, dbName },
990
+ pathParams: { workspace, region, dbName: database },
644
991
  ...this.extraProps
645
992
  });
646
993
  }
647
- getBranchDetails(workspace, database, branch) {
994
+ getBranchDetails({
995
+ workspace,
996
+ region,
997
+ database,
998
+ branch
999
+ }) {
648
1000
  return operationsByTag.branch.getBranchDetails({
649
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1001
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
650
1002
  ...this.extraProps
651
1003
  });
652
1004
  }
653
- createBranch(workspace, database, branch, from = "", options = {}) {
1005
+ createBranch({
1006
+ workspace,
1007
+ region,
1008
+ database,
1009
+ branch,
1010
+ from,
1011
+ metadata
1012
+ }) {
654
1013
  return operationsByTag.branch.createBranch({
655
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
656
- queryParams: { from },
657
- body: options,
1014
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1015
+ body: { from, metadata },
658
1016
  ...this.extraProps
659
1017
  });
660
1018
  }
661
- deleteBranch(workspace, database, branch) {
1019
+ deleteBranch({
1020
+ workspace,
1021
+ region,
1022
+ database,
1023
+ branch
1024
+ }) {
662
1025
  return operationsByTag.branch.deleteBranch({
663
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1026
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
664
1027
  ...this.extraProps
665
1028
  });
666
1029
  }
667
- updateBranchMetadata(workspace, database, branch, metadata = {}) {
1030
+ updateBranchMetadata({
1031
+ workspace,
1032
+ region,
1033
+ database,
1034
+ branch,
1035
+ metadata
1036
+ }) {
668
1037
  return operationsByTag.branch.updateBranchMetadata({
669
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1038
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
670
1039
  body: metadata,
671
1040
  ...this.extraProps
672
1041
  });
673
1042
  }
674
- getBranchMetadata(workspace, database, branch) {
1043
+ getBranchMetadata({
1044
+ workspace,
1045
+ region,
1046
+ database,
1047
+ branch
1048
+ }) {
675
1049
  return operationsByTag.branch.getBranchMetadata({
676
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1050
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
1051
+ ...this.extraProps
1052
+ });
1053
+ }
1054
+ getBranchStats({
1055
+ workspace,
1056
+ region,
1057
+ database,
1058
+ branch
1059
+ }) {
1060
+ return operationsByTag.branch.getBranchStats({
1061
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}` },
677
1062
  ...this.extraProps
678
1063
  });
679
1064
  }
680
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
681
- return operationsByTag.branch.getBranchMigrationHistory({
682
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
683
- body: options,
1065
+ getGitBranchesMapping({
1066
+ workspace,
1067
+ region,
1068
+ database
1069
+ }) {
1070
+ return operationsByTag.branch.getGitBranchesMapping({
1071
+ pathParams: { workspace, region, dbName: database },
684
1072
  ...this.extraProps
685
1073
  });
686
1074
  }
687
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
688
- return operationsByTag.branch.executeBranchMigrationPlan({
689
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
690
- body: migrationPlan,
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 },
691
1085
  ...this.extraProps
692
1086
  });
693
1087
  }
694
- getBranchMigrationPlan(workspace, database, branch, schema) {
695
- return operationsByTag.branch.getBranchMigrationPlan({
696
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
697
- body: schema,
1088
+ removeGitBranchesEntry({
1089
+ workspace,
1090
+ region,
1091
+ database,
1092
+ gitBranch
1093
+ }) {
1094
+ return operationsByTag.branch.removeGitBranchesEntry({
1095
+ pathParams: { workspace, region, dbName: database },
1096
+ queryParams: { gitBranch },
698
1097
  ...this.extraProps
699
1098
  });
700
1099
  }
701
- getBranchStats(workspace, database, branch) {
702
- return operationsByTag.branch.getBranchStats({
703
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
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 },
704
1110
  ...this.extraProps
705
1111
  });
706
1112
  }
@@ -709,67 +1115,134 @@ class TableApi {
709
1115
  constructor(extraProps) {
710
1116
  this.extraProps = extraProps;
711
1117
  }
712
- createTable(workspace, database, branch, tableName) {
1118
+ createTable({
1119
+ workspace,
1120
+ region,
1121
+ database,
1122
+ branch,
1123
+ table
1124
+ }) {
713
1125
  return operationsByTag.table.createTable({
714
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1126
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
715
1127
  ...this.extraProps
716
1128
  });
717
1129
  }
718
- deleteTable(workspace, database, branch, tableName) {
1130
+ deleteTable({
1131
+ workspace,
1132
+ region,
1133
+ database,
1134
+ branch,
1135
+ table
1136
+ }) {
719
1137
  return operationsByTag.table.deleteTable({
720
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1138
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
721
1139
  ...this.extraProps
722
1140
  });
723
1141
  }
724
- updateTable(workspace, database, branch, tableName, options) {
1142
+ updateTable({
1143
+ workspace,
1144
+ region,
1145
+ database,
1146
+ branch,
1147
+ table,
1148
+ update
1149
+ }) {
725
1150
  return operationsByTag.table.updateTable({
726
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
727
- body: options,
1151
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1152
+ body: update,
728
1153
  ...this.extraProps
729
1154
  });
730
1155
  }
731
- getTableSchema(workspace, database, branch, tableName) {
1156
+ getTableSchema({
1157
+ workspace,
1158
+ region,
1159
+ database,
1160
+ branch,
1161
+ table
1162
+ }) {
732
1163
  return operationsByTag.table.getTableSchema({
733
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1164
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
734
1165
  ...this.extraProps
735
1166
  });
736
1167
  }
737
- setTableSchema(workspace, database, branch, tableName, options) {
1168
+ setTableSchema({
1169
+ workspace,
1170
+ region,
1171
+ database,
1172
+ branch,
1173
+ table,
1174
+ schema
1175
+ }) {
738
1176
  return operationsByTag.table.setTableSchema({
739
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
740
- body: options,
1177
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1178
+ body: schema,
741
1179
  ...this.extraProps
742
1180
  });
743
1181
  }
744
- getTableColumns(workspace, database, branch, tableName) {
1182
+ getTableColumns({
1183
+ workspace,
1184
+ region,
1185
+ database,
1186
+ branch,
1187
+ table
1188
+ }) {
745
1189
  return operationsByTag.table.getTableColumns({
746
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1190
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
747
1191
  ...this.extraProps
748
1192
  });
749
1193
  }
750
- addTableColumn(workspace, database, branch, tableName, column) {
1194
+ addTableColumn({
1195
+ workspace,
1196
+ region,
1197
+ database,
1198
+ branch,
1199
+ table,
1200
+ column
1201
+ }) {
751
1202
  return operationsByTag.table.addTableColumn({
752
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1203
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
753
1204
  body: column,
754
1205
  ...this.extraProps
755
1206
  });
756
1207
  }
757
- getColumn(workspace, database, branch, tableName, columnName) {
1208
+ getColumn({
1209
+ workspace,
1210
+ region,
1211
+ database,
1212
+ branch,
1213
+ table,
1214
+ column
1215
+ }) {
758
1216
  return operationsByTag.table.getColumn({
759
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
1217
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, columnName: column },
760
1218
  ...this.extraProps
761
1219
  });
762
1220
  }
763
- deleteColumn(workspace, database, branch, tableName, columnName) {
764
- return operationsByTag.table.deleteColumn({
765
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
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,
766
1233
  ...this.extraProps
767
1234
  });
768
1235
  }
769
- updateColumn(workspace, database, branch, tableName, columnName, options) {
770
- return operationsByTag.table.updateColumn({
771
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
772
- body: options,
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 },
773
1246
  ...this.extraProps
774
1247
  });
775
1248
  }
@@ -778,67 +1251,498 @@ class RecordsApi {
778
1251
  constructor(extraProps) {
779
1252
  this.extraProps = extraProps;
780
1253
  }
781
- insertRecord(workspace, database, branch, tableName, record) {
1254
+ insertRecord({
1255
+ workspace,
1256
+ region,
1257
+ database,
1258
+ branch,
1259
+ table,
1260
+ record,
1261
+ columns
1262
+ }) {
782
1263
  return operationsByTag.records.insertRecord({
783
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1264
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table },
1265
+ queryParams: { columns },
784
1266
  body: record,
785
1267
  ...this.extraProps
786
1268
  });
787
1269
  }
788
- insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
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 },
1282
+ ...this.extraProps
1283
+ });
1284
+ }
1285
+ insertRecordWithID({
1286
+ workspace,
1287
+ region,
1288
+ database,
1289
+ branch,
1290
+ table,
1291
+ id,
1292
+ record,
1293
+ columns,
1294
+ createOnly,
1295
+ ifVersion
1296
+ }) {
789
1297
  return operationsByTag.records.insertRecordWithID({
790
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
791
- queryParams: options,
1298
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1299
+ queryParams: { columns, createOnly, ifVersion },
792
1300
  body: record,
793
1301
  ...this.extraProps
794
1302
  });
795
1303
  }
796
- updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1304
+ updateRecordWithID({
1305
+ workspace,
1306
+ region,
1307
+ database,
1308
+ branch,
1309
+ table,
1310
+ id,
1311
+ record,
1312
+ columns,
1313
+ ifVersion
1314
+ }) {
797
1315
  return operationsByTag.records.updateRecordWithID({
798
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
799
- queryParams: options,
1316
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1317
+ queryParams: { columns, ifVersion },
800
1318
  body: record,
801
1319
  ...this.extraProps
802
1320
  });
803
1321
  }
804
- upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
1322
+ upsertRecordWithID({
1323
+ workspace,
1324
+ region,
1325
+ database,
1326
+ branch,
1327
+ table,
1328
+ id,
1329
+ record,
1330
+ columns,
1331
+ ifVersion
1332
+ }) {
805
1333
  return operationsByTag.records.upsertRecordWithID({
806
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
807
- queryParams: options,
1334
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1335
+ queryParams: { columns, ifVersion },
808
1336
  body: record,
809
1337
  ...this.extraProps
810
1338
  });
811
1339
  }
812
- deleteRecord(workspace, database, branch, tableName, recordId) {
1340
+ deleteRecord({
1341
+ workspace,
1342
+ region,
1343
+ database,
1344
+ branch,
1345
+ table,
1346
+ id,
1347
+ columns
1348
+ }) {
813
1349
  return operationsByTag.records.deleteRecord({
814
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1350
+ pathParams: { workspace, region, dbBranchName: `${database}:${branch}`, tableName: table, recordId: id },
1351
+ queryParams: { columns },
815
1352
  ...this.extraProps
816
1353
  });
817
1354
  }
818
- getRecord(workspace, database, branch, tableName, recordId, options = {}) {
819
- return operationsByTag.records.getRecord({
820
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
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 },
821
1368
  ...this.extraProps
822
1369
  });
823
1370
  }
824
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
825
- return operationsByTag.records.bulkInsertTableRecords({
826
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
827
- body: { records },
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 },
828
1532
  ...this.extraProps
829
1533
  });
830
1534
  }
831
- queryTable(workspace, database, branch, tableName, query) {
832
- return operationsByTag.records.queryTable({
833
- pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
834
- body: query,
1535
+ compareMigrationRequest({
1536
+ workspace,
1537
+ region,
1538
+ database,
1539
+ migrationRequest
1540
+ }) {
1541
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1542
+ pathParams: { workspace, region, dbName: database, mrNumber: migrationRequest },
835
1543
  ...this.extraProps
836
1544
  });
837
1545
  }
838
- searchBranch(workspace, database, branch, query) {
839
- return operationsByTag.records.searchBranch({
840
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
841
- body: query,
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,
1597
+ ...this.extraProps
1598
+ });
1599
+ }
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,
1610
+ ...this.extraProps
1611
+ });
1612
+ }
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 },
1623
+ ...this.extraProps
1624
+ });
1625
+ }
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 },
1636
+ ...this.extraProps
1637
+ });
1638
+ }
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 },
1650
+ ...this.extraProps
1651
+ });
1652
+ }
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,
1663
+ ...this.extraProps
1664
+ });
1665
+ }
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,
1676
+ ...this.extraProps
1677
+ });
1678
+ }
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 },
1689
+ ...this.extraProps
1690
+ });
1691
+ }
1692
+ }
1693
+ class DatabaseApi {
1694
+ constructor(extraProps) {
1695
+ this.extraProps = extraProps;
1696
+ }
1697
+ getDatabaseList({ workspace }) {
1698
+ return operationsByTag.databases.getDatabaseList({
1699
+ pathParams: { workspaceId: workspace },
1700
+ ...this.extraProps
1701
+ });
1702
+ }
1703
+ createDatabase({
1704
+ workspace,
1705
+ database,
1706
+ data
1707
+ }) {
1708
+ return operationsByTag.databases.createDatabase({
1709
+ pathParams: { workspaceId: workspace, dbName: database },
1710
+ body: data,
1711
+ ...this.extraProps
1712
+ });
1713
+ }
1714
+ deleteDatabase({
1715
+ workspace,
1716
+ database
1717
+ }) {
1718
+ return operationsByTag.databases.deleteDatabase({
1719
+ pathParams: { workspaceId: workspace, dbName: database },
1720
+ ...this.extraProps
1721
+ });
1722
+ }
1723
+ getDatabaseMetadata({
1724
+ workspace,
1725
+ database
1726
+ }) {
1727
+ return operationsByTag.databases.getDatabaseMetadata({
1728
+ pathParams: { workspaceId: workspace, dbName: database },
1729
+ ...this.extraProps
1730
+ });
1731
+ }
1732
+ updateDatabaseMetadata({
1733
+ workspace,
1734
+ database,
1735
+ metadata
1736
+ }) {
1737
+ return operationsByTag.databases.updateDatabaseMetadata({
1738
+ pathParams: { workspaceId: workspace, dbName: database },
1739
+ body: metadata,
1740
+ ...this.extraProps
1741
+ });
1742
+ }
1743
+ listRegions({ workspace }) {
1744
+ return operationsByTag.databases.listRegions({
1745
+ pathParams: { workspaceId: workspace },
842
1746
  ...this.extraProps
843
1747
  });
844
1748
  }
@@ -854,94 +1758,163 @@ class XataApiPlugin {
854
1758
  class XataPlugin {
855
1759
  }
856
1760
 
857
- var __accessCheck$5 = (obj, member, msg) => {
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
+
1775
+ var __accessCheck$6 = (obj, member, msg) => {
858
1776
  if (!member.has(obj))
859
1777
  throw TypeError("Cannot " + msg);
860
1778
  };
861
- var __privateGet$4 = (obj, member, getter) => {
862
- __accessCheck$5(obj, member, "read from private field");
1779
+ var __privateGet$6 = (obj, member, getter) => {
1780
+ __accessCheck$6(obj, member, "read from private field");
863
1781
  return getter ? getter.call(obj) : member.get(obj);
864
1782
  };
865
- var __privateAdd$5 = (obj, member, value) => {
1783
+ var __privateAdd$6 = (obj, member, value) => {
866
1784
  if (member.has(obj))
867
1785
  throw TypeError("Cannot add the same private member more than once");
868
1786
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
869
1787
  };
870
- var __privateSet$3 = (obj, member, value, setter) => {
871
- __accessCheck$5(obj, member, "write to private field");
1788
+ var __privateSet$6 = (obj, member, value, setter) => {
1789
+ __accessCheck$6(obj, member, "write to private field");
872
1790
  setter ? setter.call(obj, value) : member.set(obj, value);
873
1791
  return value;
874
1792
  };
875
- var _query;
1793
+ var _query, _page;
876
1794
  class Page {
877
1795
  constructor(query, meta, records = []) {
878
- __privateAdd$5(this, _query, void 0);
879
- __privateSet$3(this, _query, query);
1796
+ __privateAdd$6(this, _query, void 0);
1797
+ __privateSet$6(this, _query, query);
880
1798
  this.meta = meta;
881
- this.records = records;
1799
+ this.records = new RecordArray(this, records);
882
1800
  }
883
1801
  async nextPage(size, offset) {
884
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
1802
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
885
1803
  }
886
1804
  async previousPage(size, offset) {
887
- return __privateGet$4(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
1805
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
888
1806
  }
889
- async firstPage(size, offset) {
890
- return __privateGet$4(this, _query).getPaginated({ page: { 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 } });
891
1809
  }
892
- async lastPage(size, offset) {
893
- return __privateGet$4(this, _query).getPaginated({ page: { 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 } });
894
1812
  }
895
1813
  hasNextPage() {
896
1814
  return this.meta.page.more;
897
1815
  }
898
- }
899
- _query = new WeakMap();
900
- const PAGINATION_MAX_SIZE = 200;
901
- const PAGINATION_DEFAULT_SIZE = 200;
902
- const PAGINATION_MAX_OFFSET = 800;
903
- const PAGINATION_DEFAULT_OFFSET = 0;
1816
+ }
1817
+ _query = new WeakMap();
1818
+ const PAGINATION_MAX_SIZE = 200;
1819
+ const PAGINATION_DEFAULT_SIZE = 20;
1820
+ const PAGINATION_MAX_OFFSET = 800;
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();
904
1869
 
905
- var __accessCheck$4 = (obj, member, msg) => {
1870
+ var __accessCheck$5 = (obj, member, msg) => {
906
1871
  if (!member.has(obj))
907
1872
  throw TypeError("Cannot " + msg);
908
1873
  };
909
- var __privateGet$3 = (obj, member, getter) => {
910
- __accessCheck$4(obj, member, "read from private field");
1874
+ var __privateGet$5 = (obj, member, getter) => {
1875
+ __accessCheck$5(obj, member, "read from private field");
911
1876
  return getter ? getter.call(obj) : member.get(obj);
912
1877
  };
913
- var __privateAdd$4 = (obj, member, value) => {
1878
+ var __privateAdd$5 = (obj, member, value) => {
914
1879
  if (member.has(obj))
915
1880
  throw TypeError("Cannot add the same private member more than once");
916
1881
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
917
1882
  };
918
- var __privateSet$2 = (obj, member, value, setter) => {
919
- __accessCheck$4(obj, member, "write to private field");
1883
+ var __privateSet$5 = (obj, member, value, setter) => {
1884
+ __accessCheck$5(obj, member, "write to private field");
920
1885
  setter ? setter.call(obj, value) : member.set(obj, value);
921
1886
  return value;
922
1887
  };
923
- 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;
924
1893
  const _Query = class {
925
- constructor(repository, table, data, parent) {
926
- __privateAdd$4(this, _table$1, void 0);
927
- __privateAdd$4(this, _repository, void 0);
928
- __privateAdd$4(this, _data, { filter: {} });
1894
+ constructor(repository, table, data, rawParent) {
1895
+ __privateAdd$5(this, _cleanFilterConstraint);
1896
+ __privateAdd$5(this, _table$1, void 0);
1897
+ __privateAdd$5(this, _repository, void 0);
1898
+ __privateAdd$5(this, _data, { filter: {} });
929
1899
  this.meta = { page: { cursor: "start", more: true } };
930
- this.records = [];
931
- __privateSet$2(this, _table$1, table);
1900
+ this.records = new RecordArray(this, []);
1901
+ __privateSet$5(this, _table$1, table);
932
1902
  if (repository) {
933
- __privateSet$2(this, _repository, repository);
1903
+ __privateSet$5(this, _repository, repository);
934
1904
  } else {
935
- __privateSet$2(this, _repository, this);
1905
+ __privateSet$5(this, _repository, this);
936
1906
  }
937
- __privateGet$3(this, _data).filter = data.filter ?? parent?.filter ?? {};
938
- __privateGet$3(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
939
- __privateGet$3(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
940
- __privateGet$3(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
941
- __privateGet$3(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
942
- __privateGet$3(this, _data).sort = data.sort ?? parent?.sort;
943
- __privateGet$3(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
944
- __privateGet$3(this, _data).page = data.page ?? parent?.page;
1907
+ const parent = cleanParent(data, rawParent);
1908
+ __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
1909
+ __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
1910
+ __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
1911
+ __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1912
+ __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1913
+ __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1914
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns;
1915
+ __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1916
+ __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1917
+ __privateGet$5(this, _data).fetchOptions = data.fetchOptions ?? parent?.fetchOptions;
945
1918
  this.any = this.any.bind(this);
946
1919
  this.all = this.all.bind(this);
947
1920
  this.not = this.not.bind(this);
@@ -952,87 +1925,133 @@ const _Query = class {
952
1925
  Object.defineProperty(this, "repository", { enumerable: false });
953
1926
  }
954
1927
  getQueryOptions() {
955
- return __privateGet$3(this, _data);
1928
+ return __privateGet$5(this, _data);
1929
+ }
1930
+ key() {
1931
+ const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
1932
+ const key = JSON.stringify({ columns, filter, sort, pagination });
1933
+ return toBase64(key);
956
1934
  }
957
1935
  any(...queries) {
958
1936
  const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
959
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $any } }, __privateGet$3(this, _data));
1937
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
960
1938
  }
961
1939
  all(...queries) {
962
1940
  const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
963
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
1941
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
964
1942
  }
965
1943
  not(...queries) {
966
1944
  const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
967
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $not } }, __privateGet$3(this, _data));
1945
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
968
1946
  }
969
1947
  none(...queries) {
970
1948
  const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
971
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $none } }, __privateGet$3(this, _data));
1949
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
972
1950
  }
973
1951
  filter(a, b) {
974
1952
  if (arguments.length === 1) {
975
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
976
- const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
977
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
1953
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({
1954
+ [column]: __privateMethod$3(this, _cleanFilterConstraint, cleanFilterConstraint_fn).call(this, column, constraint)
1955
+ }));
1956
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1957
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
978
1958
  } else {
979
- const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
980
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
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));
1961
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
981
1962
  }
982
1963
  }
983
- sort(column, direction) {
984
- const originalSort = [__privateGet$3(this, _data).sort ?? []].flat();
1964
+ sort(column, direction = "asc") {
1965
+ const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
985
1966
  const sort = [...originalSort, { column, direction }];
986
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { sort }, __privateGet$3(this, _data));
1967
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
987
1968
  }
988
1969
  select(columns) {
989
- return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { columns }, __privateGet$3(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
+ );
990
1976
  }
991
1977
  getPaginated(options = {}) {
992
- const query = new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), options, __privateGet$3(this, _data));
993
- return __privateGet$3(this, _repository).query(query);
1978
+ const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
1979
+ return __privateGet$5(this, _repository).query(query);
994
1980
  }
995
1981
  async *[Symbol.asyncIterator]() {
996
- for await (const [record] of this.getIterator(1)) {
1982
+ for await (const [record] of this.getIterator({ batchSize: 1 })) {
997
1983
  yield record;
998
1984
  }
999
1985
  }
1000
- async *getIterator(chunk, options = {}) {
1001
- let offset = 0;
1002
- let end = false;
1003
- while (!end) {
1004
- const { records, meta } = await this.getPaginated({ ...options, page: { size: chunk, offset } });
1005
- yield records;
1006
- offset += chunk;
1007
- end = !meta.page.more;
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;
1008
1995
  }
1009
1996
  }
1010
1997
  async getMany(options = {}) {
1011
- const { records } = await this.getPaginated(options);
1012
- 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;
1013
2012
  }
1014
- async getAll(chunk = PAGINATION_MAX_SIZE, options = {}) {
2013
+ async getAll(options = {}) {
2014
+ const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
1015
2015
  const results = [];
1016
- for await (const page of this.getIterator(chunk, options)) {
2016
+ for await (const page of this.getIterator({ ...rest, batchSize })) {
1017
2017
  results.push(...page);
1018
2018
  }
1019
2019
  return results;
1020
2020
  }
1021
- async getOne(options = {}) {
1022
- const records = await this.getMany({ ...options, page: { size: 1 } });
1023
- return records[0] || null;
2021
+ async getFirst(options = {}) {
2022
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
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);
2040
+ }
2041
+ cache(ttl) {
2042
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1024
2043
  }
1025
2044
  nextPage(size, offset) {
1026
- return this.firstPage(size, offset);
2045
+ return this.startPage(size, offset);
1027
2046
  }
1028
2047
  previousPage(size, offset) {
1029
- return this.firstPage(size, offset);
2048
+ return this.startPage(size, offset);
1030
2049
  }
1031
- firstPage(size, offset) {
1032
- return this.getPaginated({ page: { size, offset } });
2050
+ startPage(size, offset) {
2051
+ return this.getPaginated({ pagination: { size, offset } });
1033
2052
  }
1034
- lastPage(size, offset) {
1035
- return this.getPaginated({ page: { size, offset, before: "end" } });
2053
+ endPage(size, offset) {
2054
+ return this.getPaginated({ pagination: { size, offset, before: "end" } });
1036
2055
  }
1037
2056
  hasNextPage() {
1038
2057
  return this.meta.page.more;
@@ -1042,12 +2061,31 @@ let Query = _Query;
1042
2061
  _table$1 = new WeakMap();
1043
2062
  _repository = new WeakMap();
1044
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
+ }
1045
2081
 
1046
2082
  function isIdentifiable(x) {
1047
2083
  return isObject(x) && isString(x?.id);
1048
2084
  }
1049
2085
  function isXataRecord(x) {
1050
- 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";
1051
2089
  }
1052
2090
 
1053
2091
  function isSortFilterString(value) {
@@ -1073,249 +2111,536 @@ function buildSortFilter(filter) {
1073
2111
  }
1074
2112
  }
1075
2113
 
1076
- var __accessCheck$3 = (obj, member, msg) => {
2114
+ var __accessCheck$4 = (obj, member, msg) => {
1077
2115
  if (!member.has(obj))
1078
2116
  throw TypeError("Cannot " + msg);
1079
2117
  };
1080
- var __privateGet$2 = (obj, member, getter) => {
1081
- __accessCheck$3(obj, member, "read from private field");
2118
+ var __privateGet$4 = (obj, member, getter) => {
2119
+ __accessCheck$4(obj, member, "read from private field");
1082
2120
  return getter ? getter.call(obj) : member.get(obj);
1083
2121
  };
1084
- var __privateAdd$3 = (obj, member, value) => {
2122
+ var __privateAdd$4 = (obj, member, value) => {
1085
2123
  if (member.has(obj))
1086
2124
  throw TypeError("Cannot add the same private member more than once");
1087
2125
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1088
2126
  };
1089
- var __privateSet$1 = (obj, member, value, setter) => {
1090
- __accessCheck$3(obj, member, "write to private field");
2127
+ var __privateSet$4 = (obj, member, value, setter) => {
2128
+ __accessCheck$4(obj, member, "write to private field");
1091
2129
  setter ? setter.call(obj, value) : member.set(obj, value);
1092
2130
  return value;
1093
2131
  };
1094
2132
  var __privateMethod$2 = (obj, member, method) => {
1095
- __accessCheck$3(obj, member, "access private method");
2133
+ __accessCheck$4(obj, member, "access private method");
1096
2134
  return method;
1097
2135
  };
1098
- var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn;
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;
1099
2137
  class Repository extends Query {
1100
2138
  }
1101
2139
  class RestRepository extends Query {
1102
2140
  constructor(options) {
1103
- super(null, options.table, {});
1104
- __privateAdd$3(this, _insertRecordWithoutId);
1105
- __privateAdd$3(this, _insertRecordWithId);
1106
- __privateAdd$3(this, _bulkInsertTableRecords);
1107
- __privateAdd$3(this, _updateRecordWithID);
1108
- __privateAdd$3(this, _upsertRecordWithID);
1109
- __privateAdd$3(this, _deleteRecord);
1110
- __privateAdd$3(this, _table, void 0);
1111
- __privateAdd$3(this, _links, void 0);
1112
- __privateAdd$3(this, _getFetchProps, void 0);
1113
- __privateSet$1(this, _table, options.table);
1114
- __privateSet$1(this, _links, options.links ?? {});
1115
- __privateSet$1(this, _getFetchProps, options.getFetchProps);
1116
- this.db = options.db;
1117
- }
1118
- async create(a, b) {
1119
- if (Array.isArray(a)) {
1120
- return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1121
- }
1122
- if (isString(a) && isObject(b)) {
1123
- if (a === "")
1124
- throw new Error("The id can't be empty");
1125
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1126
- }
1127
- if (isObject(a) && isString(a.id)) {
1128
- if (a.id === "")
1129
- throw new Error("The id can't be empty");
1130
- return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1131
- }
1132
- if (isObject(a)) {
1133
- return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1134
- }
1135
- throw new Error("Invalid arguments for create method");
1136
- }
1137
- async read(recordId) {
1138
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1139
- try {
1140
- const response = await getRecord({
1141
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1142
- ...fetchProps
2141
+ super(
2142
+ null,
2143
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
2144
+ {}
2145
+ );
2146
+ __privateAdd$4(this, _insertRecordWithoutId);
2147
+ __privateAdd$4(this, _insertRecordWithId);
2148
+ __privateAdd$4(this, _bulkInsertTableRecords);
2149
+ __privateAdd$4(this, _updateRecordWithID);
2150
+ __privateAdd$4(this, _upsertRecordWithID);
2151
+ __privateAdd$4(this, _deleteRecord);
2152
+ __privateAdd$4(this, _setCacheQuery);
2153
+ __privateAdd$4(this, _getCacheQuery);
2154
+ __privateAdd$4(this, _getSchemaTables$1);
2155
+ __privateAdd$4(this, _table, void 0);
2156
+ __privateAdd$4(this, _getFetchProps, void 0);
2157
+ __privateAdd$4(this, _db, void 0);
2158
+ __privateAdd$4(this, _cache, void 0);
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
1143
2176
  });
1144
- return initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), response);
1145
- } catch (e) {
1146
- if (isObject(e) && e.status === 404) {
1147
- return null;
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);
1148
2187
  }
1149
- throw e;
1150
- }
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
+ });
1151
2206
  }
1152
- async update(a, b) {
1153
- if (Array.isArray(a)) {
1154
- if (a.length > 100) {
1155
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
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);
1156
2220
  }
1157
- return Promise.all(a.map((object) => this.update(object)));
1158
- }
1159
- if (isString(a) && isObject(b)) {
1160
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1161
- }
1162
- if (isObject(a) && isString(a.id)) {
1163
- return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1164
- }
1165
- throw new Error("Invalid arguments for update method");
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
+ });
2247
+ }
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;
2259
+ }
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
+ });
1166
2266
  }
1167
- async createOrUpdate(a, b) {
1168
- if (Array.isArray(a)) {
1169
- if (a.length > 100) {
1170
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
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)));
1171
2278
  }
1172
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1173
- }
1174
- if (isString(a) && isObject(b)) {
1175
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1176
- }
1177
- if (isObject(a) && isString(a.id)) {
1178
- return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1179
- }
1180
- throw new Error("Invalid arguments for createOrUpdate method");
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
+ });
1181
2289
  }
1182
- async delete(recordId) {
1183
- if (Array.isArray(recordId)) {
1184
- if (recordId.length > 100) {
1185
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
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;
1186
2301
  }
1187
- await Promise.all(recordId.map((id) => this.delete(id)));
1188
- return;
1189
- }
1190
- if (isString(recordId)) {
1191
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId);
1192
- return;
1193
- }
1194
- if (isObject(recordId) && isString(recordId.id)) {
1195
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId.id);
1196
- return;
1197
- }
1198
- throw new Error("Invalid arguments for delete method");
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
+ });
1199
2388
  }
1200
2389
  async search(query, options = {}) {
1201
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1202
- const { records } = await searchBranch({
1203
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1204
- body: { tables: [__privateGet$2(this, _table)], query, fuzziness: options.fuzziness },
1205
- ...fetchProps
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;
1206
2427
  });
1207
- return records.map((item) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), item));
1208
2428
  }
1209
2429
  async query(query) {
1210
- const data = query.getQueryOptions();
1211
- const body = {
1212
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1213
- sort: data.sort ? buildSortFilter(data.sort) : void 0,
1214
- page: data.page,
1215
- columns: data.columns
1216
- };
1217
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1218
- const { meta, records: objects } = await queryTable({
1219
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1220
- body,
1221
- ...fetchProps
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;
1222
2482
  });
1223
- const records = objects.map((record) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), record));
1224
- return new Page(query, meta, records);
1225
2483
  }
1226
2484
  }
1227
2485
  _table = new WeakMap();
1228
- _links = new WeakMap();
1229
2486
  _getFetchProps = new WeakMap();
2487
+ _db = new WeakMap();
2488
+ _cache = new WeakMap();
2489
+ _schemaTables$2 = new WeakMap();
2490
+ _trace = new WeakMap();
1230
2491
  _insertRecordWithoutId = new WeakSet();
1231
- insertRecordWithoutId_fn = async function(object) {
1232
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
2492
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
2493
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1233
2494
  const record = transformObjectLinks(object);
1234
2495
  const response = await insertRecord({
1235
2496
  pathParams: {
1236
2497
  workspace: "{workspaceId}",
1237
2498
  dbBranchName: "{dbBranch}",
1238
- tableName: __privateGet$2(this, _table)
2499
+ region: "{region}",
2500
+ tableName: __privateGet$4(this, _table)
1239
2501
  },
2502
+ queryParams: { columns },
1240
2503
  body: record,
1241
2504
  ...fetchProps
1242
2505
  });
1243
- const finalObject = await this.read(response.id);
1244
- if (!finalObject) {
1245
- throw new Error("The server failed to save the record");
1246
- }
1247
- return finalObject;
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);
1248
2508
  };
1249
2509
  _insertRecordWithId = new WeakSet();
1250
- insertRecordWithId_fn = async function(recordId, object) {
1251
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
2510
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"], { createOnly, ifVersion }) {
2511
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1252
2512
  const record = transformObjectLinks(object);
1253
2513
  const response = await insertRecordWithID({
1254
2514
  pathParams: {
1255
2515
  workspace: "{workspaceId}",
1256
2516
  dbBranchName: "{dbBranch}",
1257
- tableName: __privateGet$2(this, _table),
2517
+ region: "{region}",
2518
+ tableName: __privateGet$4(this, _table),
1258
2519
  recordId
1259
2520
  },
1260
2521
  body: record,
1261
- queryParams: { createOnly: true },
2522
+ queryParams: { createOnly, columns, ifVersion },
1262
2523
  ...fetchProps
1263
2524
  });
1264
- const finalObject = await this.read(response.id);
1265
- if (!finalObject) {
1266
- throw new Error("The server failed to save the record");
1267
- }
1268
- return finalObject;
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);
1269
2527
  };
1270
2528
  _bulkInsertTableRecords = new WeakSet();
1271
- bulkInsertTableRecords_fn = async function(objects) {
1272
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
2529
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
2530
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1273
2531
  const records = objects.map((object) => transformObjectLinks(object));
1274
2532
  const response = await bulkInsertTableRecords({
1275
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
2533
+ pathParams: {
2534
+ workspace: "{workspaceId}",
2535
+ dbBranchName: "{dbBranch}",
2536
+ region: "{region}",
2537
+ tableName: __privateGet$4(this, _table)
2538
+ },
2539
+ queryParams: { columns },
1276
2540
  body: { records },
1277
2541
  ...fetchProps
1278
2542
  });
1279
- const finalObjects = await this.any(...response.recordIDs.map((id) => this.filter("id", id))).getAll();
1280
- if (finalObjects.length !== objects.length) {
1281
- throw new Error("The server failed to save some records");
2543
+ if (!isResponseWithRecords(response)) {
2544
+ throw new Error("Request included columns but server didn't include them");
1282
2545
  }
1283
- 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));
1284
2548
  };
1285
2549
  _updateRecordWithID = new WeakSet();
1286
- updateRecordWithID_fn = async function(recordId, object) {
1287
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
2550
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2551
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1288
2552
  const record = transformObjectLinks(object);
1289
- const response = await updateRecordWithID({
1290
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1291
- body: record,
1292
- ...fetchProps
1293
- });
1294
- const item = await this.read(response.id);
1295
- if (!item)
1296
- throw new Error("The server failed to save the record");
1297
- return item;
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
+ }
1298
2574
  };
1299
2575
  _upsertRecordWithID = new WeakSet();
1300
- upsertRecordWithID_fn = async function(recordId, object) {
1301
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
2576
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"], { ifVersion }) {
2577
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1302
2578
  const response = await upsertRecordWithID({
1303
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(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 },
1304
2587
  body: object,
1305
2588
  ...fetchProps
1306
2589
  });
1307
- const item = await this.read(response.id);
1308
- if (!item)
1309
- throw new Error("The server failed to save the record");
1310
- return item;
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);
1311
2592
  };
1312
2593
  _deleteRecord = new WeakSet();
1313
- deleteRecord_fn = async function(recordId) {
1314
- const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1315
- await deleteRecord({
1316
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
2594
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
2595
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
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;
2615
+ }
2616
+ };
2617
+ _setCacheQuery = new WeakSet();
2618
+ setCacheQuery_fn = async function(query, meta, records) {
2619
+ await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
2620
+ };
2621
+ _getCacheQuery = new WeakSet();
2622
+ getCacheQuery_fn = async function(query) {
2623
+ const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
2624
+ const result = await __privateGet$4(this, _cache).get(key);
2625
+ if (!result)
2626
+ return null;
2627
+ const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
2628
+ if (ttl < 0)
2629
+ return null;
2630
+ const hasExpired = result.date.getTime() + ttl < Date.now();
2631
+ return hasExpired ? null : result;
2632
+ };
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);
2637
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
2638
+ const { schema } = await getBranchDetails({
2639
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
1317
2640
  ...fetchProps
1318
2641
  });
2642
+ __privateSet$4(this, _schemaTables$2, schema.tables);
2643
+ return schema.tables;
1319
2644
  };
1320
2645
  const transformObjectLinks = (object) => {
1321
2646
  return Object.entries(object).reduce((acc, [key, value]) => {
@@ -1324,45 +2649,177 @@ const transformObjectLinks = (object) => {
1324
2649
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1325
2650
  }, {});
1326
2651
  };
1327
- const initObject = (db, links, table, object) => {
2652
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
1328
2653
  const result = {};
1329
- Object.assign(result, object);
1330
- const tableLinks = links[table] || [];
1331
- for (const link of tableLinks) {
1332
- const [field, linkTable] = link;
1333
- const value = result[field];
1334
- if (value && isObject(value)) {
1335
- result[field] = initObject(db, links, linkTable, value);
2654
+ const { xata, ...rest } = object ?? {};
2655
+ Object.assign(result, rest);
2656
+ const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
2657
+ if (!columns)
2658
+ console.error(`Table ${table} not found in schema`);
2659
+ for (const column of columns ?? []) {
2660
+ if (!isValidColumn(selectedColumns, column))
2661
+ continue;
2662
+ const value = result[column.name];
2663
+ switch (column.type) {
2664
+ case "datetime": {
2665
+ const date = value !== void 0 ? new Date(value) : void 0;
2666
+ if (date && isNaN(date.getTime())) {
2667
+ console.error(`Failed to parse date ${value} for field ${column.name}`);
2668
+ } else if (date) {
2669
+ result[column.name] = date;
2670
+ }
2671
+ break;
2672
+ }
2673
+ case "link": {
2674
+ const linkTable = column.link?.table;
2675
+ if (!linkTable) {
2676
+ console.error(`Failed to parse link for field ${column.name}`);
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;
2691
+ }
2692
+ break;
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;
1336
2700
  }
1337
2701
  }
1338
- result.read = function() {
1339
- return db[table].read(result["id"]);
2702
+ result.read = function(columns2) {
2703
+ return db[table].read(result["id"], columns2);
1340
2704
  };
1341
- result.update = function(data) {
1342
- return db[table].update(result["id"], data);
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 });
2709
+ };
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 });
1343
2714
  };
1344
2715
  result.delete = function() {
1345
2716
  return db[table].delete(result["id"]);
1346
2717
  };
1347
- 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"]) {
1348
2722
  Object.defineProperty(result, prop, { enumerable: false });
1349
2723
  }
1350
2724
  Object.freeze(result);
1351
2725
  return result;
1352
2726
  };
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
+ }
2751
+ }
2752
+ return void 0;
2753
+ }
2754
+
2755
+ var __accessCheck$3 = (obj, member, msg) => {
2756
+ if (!member.has(obj))
2757
+ throw TypeError("Cannot " + msg);
2758
+ };
2759
+ var __privateGet$3 = (obj, member, getter) => {
2760
+ __accessCheck$3(obj, member, "read from private field");
2761
+ return getter ? getter.call(obj) : member.get(obj);
2762
+ };
2763
+ var __privateAdd$3 = (obj, member, value) => {
2764
+ if (member.has(obj))
2765
+ throw TypeError("Cannot add the same private member more than once");
2766
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
2767
+ };
2768
+ var __privateSet$3 = (obj, member, value, setter) => {
2769
+ __accessCheck$3(obj, member, "write to private field");
2770
+ setter ? setter.call(obj, value) : member.set(obj, value);
2771
+ return value;
2772
+ };
2773
+ var _map;
2774
+ class SimpleCache {
2775
+ constructor(options = {}) {
2776
+ __privateAdd$3(this, _map, void 0);
2777
+ __privateSet$3(this, _map, /* @__PURE__ */ new Map());
2778
+ this.capacity = options.max ?? 500;
2779
+ this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
2780
+ }
2781
+ async getAll() {
2782
+ return Object.fromEntries(__privateGet$3(this, _map));
2783
+ }
2784
+ async get(key) {
2785
+ return __privateGet$3(this, _map).get(key) ?? null;
2786
+ }
2787
+ async set(key, value) {
2788
+ await this.delete(key);
2789
+ __privateGet$3(this, _map).set(key, value);
2790
+ if (__privateGet$3(this, _map).size > this.capacity) {
2791
+ const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
2792
+ await this.delete(leastRecentlyUsed);
2793
+ }
2794
+ }
2795
+ async delete(key) {
2796
+ __privateGet$3(this, _map).delete(key);
2797
+ }
2798
+ async clear() {
2799
+ return __privateGet$3(this, _map).clear();
2800
+ }
2801
+ }
2802
+ _map = new WeakMap();
1353
2803
 
1354
- const gt = (value) => ({ $gt: value });
1355
- const ge = (value) => ({ $ge: value });
1356
- const gte = (value) => ({ $ge: value });
1357
- const lt = (value) => ({ $lt: value });
1358
- const lte = (value) => ({ $le: value });
1359
- const le = (value) => ({ $le: value });
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;
1360
2816
  const exists = (column) => ({ $exists: column });
1361
2817
  const notExists = (column) => ({ $notExists: column });
1362
2818
  const startsWith = (value) => ({ $startsWith: value });
1363
2819
  const endsWith = (value) => ({ $endsWith: value });
1364
2820
  const pattern = (value) => ({ $pattern: value });
1365
2821
  const is = (value) => ({ $is: value });
2822
+ const equals = is;
1366
2823
  const isNot = (value) => ({ $isNot: value });
1367
2824
  const contains = (value) => ({ $contains: value });
1368
2825
  const includes = (value) => ({ $includes: value });
@@ -1374,7 +2831,7 @@ var __accessCheck$2 = (obj, member, msg) => {
1374
2831
  if (!member.has(obj))
1375
2832
  throw TypeError("Cannot " + msg);
1376
2833
  };
1377
- var __privateGet$1 = (obj, member, getter) => {
2834
+ var __privateGet$2 = (obj, member, getter) => {
1378
2835
  __accessCheck$2(obj, member, "read from private field");
1379
2836
  return getter ? getter.call(obj) : member.get(obj);
1380
2837
  };
@@ -1383,143 +2840,194 @@ var __privateAdd$2 = (obj, member, value) => {
1383
2840
  throw TypeError("Cannot add the same private member more than once");
1384
2841
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1385
2842
  };
1386
- 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;
1387
2849
  class SchemaPlugin extends XataPlugin {
1388
- constructor(links, tableNames) {
2850
+ constructor(schemaTables) {
1389
2851
  super();
1390
- this.links = links;
1391
- this.tableNames = tableNames;
1392
2852
  __privateAdd$2(this, _tables, {});
1393
- }
1394
- build(options) {
1395
- const { getFetchProps } = options;
1396
- const links = this.links;
1397
- const db = new Proxy({}, {
1398
- get: (_target, table) => {
1399
- if (!isString(table))
1400
- throw new Error("Invalid table name");
1401
- if (!__privateGet$1(this, _tables)[table])
1402
- __privateGet$1(this, _tables)[table] = new RestRepository({ db, getFetchProps, table, links });
1403
- return __privateGet$1(this, _tables)[table];
2853
+ __privateAdd$2(this, _schemaTables$1, void 0);
2854
+ __privateSet$2(this, _schemaTables$1, schemaTables);
2855
+ }
2856
+ build(pluginOptions) {
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];
2867
+ }
1404
2868
  }
1405
- });
1406
- for (const table of this.tableNames ?? []) {
1407
- db[table] = new RestRepository({ db, getFetchProps, table, links });
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) });
1408
2873
  }
1409
2874
  return db;
1410
2875
  }
1411
2876
  }
1412
2877
  _tables = new WeakMap();
2878
+ _schemaTables$1 = new WeakMap();
1413
2879
 
1414
2880
  var __accessCheck$1 = (obj, member, msg) => {
1415
2881
  if (!member.has(obj))
1416
2882
  throw TypeError("Cannot " + msg);
1417
2883
  };
2884
+ var __privateGet$1 = (obj, member, getter) => {
2885
+ __accessCheck$1(obj, member, "read from private field");
2886
+ return getter ? getter.call(obj) : member.get(obj);
2887
+ };
1418
2888
  var __privateAdd$1 = (obj, member, value) => {
1419
2889
  if (member.has(obj))
1420
2890
  throw TypeError("Cannot add the same private member more than once");
1421
2891
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1422
2892
  };
2893
+ var __privateSet$1 = (obj, member, value, setter) => {
2894
+ __accessCheck$1(obj, member, "write to private field");
2895
+ setter ? setter.call(obj, value) : member.set(obj, value);
2896
+ return value;
2897
+ };
1423
2898
  var __privateMethod$1 = (obj, member, method) => {
1424
2899
  __accessCheck$1(obj, member, "access private method");
1425
2900
  return method;
1426
2901
  };
1427
- var _search, search_fn;
2902
+ var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
1428
2903
  class SearchPlugin extends XataPlugin {
1429
- constructor(db, links) {
2904
+ constructor(db, schemaTables) {
1430
2905
  super();
1431
2906
  this.db = db;
1432
- this.links = links;
1433
2907
  __privateAdd$1(this, _search);
2908
+ __privateAdd$1(this, _getSchemaTables);
2909
+ __privateAdd$1(this, _schemaTables, void 0);
2910
+ __privateSet$1(this, _schemaTables, schemaTables);
1434
2911
  }
1435
2912
  build({ getFetchProps }) {
1436
2913
  return {
1437
2914
  all: async (query, options = {}) => {
1438
2915
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
2916
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1439
2917
  return records.map((record) => {
1440
2918
  const { table = "orphan" } = record.xata;
1441
- return { table, record: initObject(this.db, this.links, table, record) };
2919
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
1442
2920
  });
1443
2921
  },
1444
2922
  byTable: async (query, options = {}) => {
1445
2923
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
2924
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1446
2925
  return records.reduce((acc, record) => {
1447
2926
  const { table = "orphan" } = record.xata;
1448
2927
  const items = acc[table] ?? [];
1449
- const item = initObject(this.db, this.links, table, record);
2928
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
1450
2929
  return { ...acc, [table]: [...items, item] };
1451
2930
  }, {});
1452
2931
  }
1453
2932
  };
1454
2933
  }
1455
2934
  }
2935
+ _schemaTables = new WeakMap();
1456
2936
  _search = new WeakSet();
1457
2937
  search_fn = async function(query, options, getFetchProps) {
1458
2938
  const fetchProps = await getFetchProps();
1459
- const { tables, fuzziness } = options ?? {};
2939
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1460
2940
  const { records } = await searchBranch({
1461
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1462
- body: { tables, query, fuzziness },
2941
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2942
+ body: { tables, query, fuzziness, prefix, highlight },
1463
2943
  ...fetchProps
1464
2944
  });
1465
2945
  return records;
1466
2946
  };
2947
+ _getSchemaTables = new WeakSet();
2948
+ getSchemaTables_fn = async function(getFetchProps) {
2949
+ if (__privateGet$1(this, _schemaTables))
2950
+ return __privateGet$1(this, _schemaTables);
2951
+ const fetchProps = await getFetchProps();
2952
+ const { schema } = await getBranchDetails({
2953
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", region: "{region}" },
2954
+ ...fetchProps
2955
+ });
2956
+ __privateSet$1(this, _schemaTables, schema.tables);
2957
+ return schema.tables;
2958
+ };
1467
2959
 
1468
2960
  const isBranchStrategyBuilder = (strategy) => {
1469
2961
  return typeof strategy === "function";
1470
2962
  };
1471
2963
 
1472
- const envBranchNames = [
1473
- "XATA_BRANCH",
1474
- "VERCEL_GIT_COMMIT_REF",
1475
- "CF_PAGES_BRANCH",
1476
- "BRANCH"
1477
- ];
1478
- const defaultBranch = "main";
1479
2964
  async function getCurrentBranchName(options) {
1480
- const env = await getBranchByEnvVariable();
1481
- if (env)
1482
- return env;
1483
- const branch = await getGitBranch();
1484
- if (!branch)
1485
- return defaultBranch;
1486
- const details = await getDatabaseBranch(branch, options);
1487
- if (details)
1488
- return branch;
1489
- 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);
1490
2974
  }
1491
2975
  async function getCurrentBranchDetails(options) {
1492
- const env = await getBranchByEnvVariable();
1493
- if (env)
1494
- return getDatabaseBranch(env, options);
1495
- const branch = await getGitBranch();
1496
- if (!branch)
1497
- return getDatabaseBranch(defaultBranch, options);
1498
- const details = await getDatabaseBranch(branch, options);
1499
- if (details)
1500
- return details;
1501
- return getDatabaseBranch(defaultBranch, options);
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;
1502
3006
  }
1503
3007
  async function getDatabaseBranch(branch, options) {
1504
3008
  const databaseURL = options?.databaseURL || getDatabaseURL();
1505
3009
  const apiKey = options?.apiKey || getAPIKey();
1506
3010
  if (!databaseURL)
1507
- 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
+ );
1508
3014
  if (!apiKey)
1509
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
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
+ );
1510
3018
  const [protocol, , host, , database] = databaseURL.split("/");
1511
- const [workspace] = host.split(".");
1512
- 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;
1513
3023
  try {
1514
3024
  return await getBranchDetails({
1515
3025
  apiKey,
1516
3026
  apiUrl: databaseURL,
1517
3027
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1518
3028
  workspacesApiUrl: `${protocol}//${host}`,
1519
- pathParams: {
1520
- dbBranchName,
1521
- workspace
1522
- }
3029
+ pathParams: { dbBranchName: `${database}:${branch}`, workspace, region },
3030
+ trace: defaultTrace
1523
3031
  });
1524
3032
  } catch (err) {
1525
3033
  if (isObject(err) && err.status === 404)
@@ -1527,21 +3035,10 @@ async function getDatabaseBranch(branch, options) {
1527
3035
  throw err;
1528
3036
  }
1529
3037
  }
1530
- function getBranchByEnvVariable() {
1531
- for (const name of envBranchNames) {
1532
- const value = getEnvVariable(name);
1533
- if (value) {
1534
- return value;
1535
- }
1536
- }
1537
- try {
1538
- return XATA_BRANCH;
1539
- } catch (err) {
1540
- }
1541
- }
1542
3038
  function getDatabaseURL() {
1543
3039
  try {
1544
- return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
3040
+ const { databaseURL } = getEnvironment();
3041
+ return databaseURL;
1545
3042
  } catch (err) {
1546
3043
  return void 0;
1547
3044
  }
@@ -1570,24 +3067,29 @@ var __privateMethod = (obj, member, method) => {
1570
3067
  return method;
1571
3068
  };
1572
3069
  const buildClient = (plugins) => {
1573
- 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;
1574
3071
  return _a = class {
1575
- constructor(options = {}, links, tables) {
3072
+ constructor(options = {}, schemaTables) {
1576
3073
  __privateAdd(this, _parseOptions);
1577
3074
  __privateAdd(this, _getFetchProps);
1578
3075
  __privateAdd(this, _evaluateBranch);
1579
3076
  __privateAdd(this, _branch, void 0);
3077
+ __privateAdd(this, _options, void 0);
1580
3078
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
1581
- const db = new SchemaPlugin(links, tables).build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1582
- const search = new SearchPlugin(db, links ?? {}).build({
1583
- getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions)
1584
- });
3079
+ __privateSet(this, _options, safeOptions);
3080
+ const pluginOptions = {
3081
+ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
3082
+ cache: safeOptions.cache,
3083
+ trace: safeOptions.trace
3084
+ };
3085
+ const db = new SchemaPlugin(schemaTables).build(pluginOptions);
3086
+ const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
1585
3087
  this.db = db;
1586
3088
  this.search = search;
1587
3089
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
1588
- if (!namespace)
3090
+ if (namespace === void 0)
1589
3091
  continue;
1590
- const result = namespace.build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
3092
+ const result = namespace.build(pluginOptions);
1591
3093
  if (result instanceof Promise) {
1592
3094
  void result.then((namespace2) => {
1593
3095
  this[key] = namespace2;
@@ -1597,21 +3099,33 @@ const buildClient = (plugins) => {
1597
3099
  }
1598
3100
  }
1599
3101
  }
1600
- }, _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
+ }
1601
3115
  const fetch = getFetchImplementation(options?.fetch);
1602
3116
  const databaseURL = options?.databaseURL || getDatabaseURL();
1603
3117
  const apiKey = options?.apiKey || getAPIKey();
1604
- const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1605
- if (!databaseURL || !apiKey) {
1606
- throw new Error("Options databaseURL and apiKey are required");
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");
1607
3123
  }
1608
- return { fetch, databaseURL, apiKey, branch };
1609
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1610
- fetch,
1611
- apiKey,
1612
- databaseURL,
1613
- branch
1614
- }) {
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 }) {
1615
3129
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
1616
3130
  if (!branchValue)
1617
3131
  throw new Error("Unable to resolve branch value");
@@ -1621,14 +3135,16 @@ const buildClient = (plugins) => {
1621
3135
  apiUrl: "",
1622
3136
  workspacesApiUrl: (path, params) => {
1623
3137
  const hasBranch = params.dbBranchName ?? params.branch;
1624
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
3138
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
1625
3139
  return databaseURL + newPath;
1626
- }
3140
+ },
3141
+ trace,
3142
+ clientID
1627
3143
  };
1628
3144
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
1629
3145
  if (__privateGet(this, _branch))
1630
3146
  return __privateGet(this, _branch);
1631
- if (!param)
3147
+ if (param === void 0)
1632
3148
  return void 0;
1633
3149
  const strategies = Array.isArray(param) ? [...param] : [param];
1634
3150
  const evaluateBranch = async (strategy) => {
@@ -1646,6 +3162,88 @@ const buildClient = (plugins) => {
1646
3162
  class BaseClient extends buildClient() {
1647
3163
  }
1648
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
+
1649
3247
  class XataError extends Error {
1650
3248
  constructor(message, status) {
1651
3249
  super(message);
@@ -1661,25 +3259,42 @@ exports.PAGINATION_MAX_OFFSET = PAGINATION_MAX_OFFSET;
1661
3259
  exports.PAGINATION_MAX_SIZE = PAGINATION_MAX_SIZE;
1662
3260
  exports.Page = Page;
1663
3261
  exports.Query = Query;
3262
+ exports.RecordArray = RecordArray;
1664
3263
  exports.Repository = Repository;
1665
3264
  exports.RestRepository = RestRepository;
1666
3265
  exports.SchemaPlugin = SchemaPlugin;
1667
3266
  exports.SearchPlugin = SearchPlugin;
3267
+ exports.Serializer = Serializer;
3268
+ exports.SimpleCache = SimpleCache;
1668
3269
  exports.XataApiClient = XataApiClient;
1669
3270
  exports.XataApiPlugin = XataApiPlugin;
1670
3271
  exports.XataError = XataError;
1671
3272
  exports.XataPlugin = XataPlugin;
1672
3273
  exports.acceptWorkspaceMemberInvite = acceptWorkspaceMemberInvite;
3274
+ exports.addGitBranchesEntry = addGitBranchesEntry;
1673
3275
  exports.addTableColumn = addTableColumn;
3276
+ exports.aggregateTable = aggregateTable;
3277
+ exports.applyBranchSchemaEdit = applyBranchSchemaEdit;
3278
+ exports.branchTransaction = branchTransaction;
1674
3279
  exports.buildClient = buildClient;
3280
+ exports.buildWorkerRunner = buildWorkerRunner;
1675
3281
  exports.bulkInsertTableRecords = bulkInsertTableRecords;
1676
3282
  exports.cancelWorkspaceMemberInvite = cancelWorkspaceMemberInvite;
3283
+ exports.compareBranchSchemas = compareBranchSchemas;
3284
+ exports.compareBranchWithUserSchema = compareBranchWithUserSchema;
3285
+ exports.compareMigrationRequest = compareMigrationRequest;
1677
3286
  exports.contains = contains;
1678
3287
  exports.createBranch = createBranch;
1679
3288
  exports.createDatabase = createDatabase;
3289
+ exports.createMigrationRequest = createMigrationRequest;
1680
3290
  exports.createTable = createTable;
1681
3291
  exports.createUserAPIKey = createUserAPIKey;
1682
3292
  exports.createWorkspace = createWorkspace;
3293
+ exports.dEPRECATEDcreateDatabase = dEPRECATEDcreateDatabase;
3294
+ exports.dEPRECATEDdeleteDatabase = dEPRECATEDdeleteDatabase;
3295
+ exports.dEPRECATEDgetDatabaseList = dEPRECATEDgetDatabaseList;
3296
+ exports.dEPRECATEDgetDatabaseMetadata = dEPRECATEDgetDatabaseMetadata;
3297
+ exports.dEPRECATEDupdateDatabaseMetadata = dEPRECATEDupdateDatabaseMetadata;
1683
3298
  exports.deleteBranch = deleteBranch;
1684
3299
  exports.deleteColumn = deleteColumn;
1685
3300
  exports.deleteDatabase = deleteDatabase;
@@ -1688,7 +3303,9 @@ exports.deleteTable = deleteTable;
1688
3303
  exports.deleteUser = deleteUser;
1689
3304
  exports.deleteUserAPIKey = deleteUserAPIKey;
1690
3305
  exports.deleteWorkspace = deleteWorkspace;
3306
+ exports.deserialize = deserialize;
1691
3307
  exports.endsWith = endsWith;
3308
+ exports.equals = equals;
1692
3309
  exports.executeBranchMigrationPlan = executeBranchMigrationPlan;
1693
3310
  exports.exists = exists;
1694
3311
  exports.ge = ge;
@@ -1698,12 +3315,18 @@ exports.getBranchList = getBranchList;
1698
3315
  exports.getBranchMetadata = getBranchMetadata;
1699
3316
  exports.getBranchMigrationHistory = getBranchMigrationHistory;
1700
3317
  exports.getBranchMigrationPlan = getBranchMigrationPlan;
3318
+ exports.getBranchSchemaHistory = getBranchSchemaHistory;
1701
3319
  exports.getBranchStats = getBranchStats;
1702
3320
  exports.getColumn = getColumn;
1703
3321
  exports.getCurrentBranchDetails = getCurrentBranchDetails;
1704
3322
  exports.getCurrentBranchName = getCurrentBranchName;
1705
3323
  exports.getDatabaseList = getDatabaseList;
3324
+ exports.getDatabaseMetadata = getDatabaseMetadata;
1706
3325
  exports.getDatabaseURL = getDatabaseURL;
3326
+ exports.getGitBranchesMapping = getGitBranchesMapping;
3327
+ exports.getHostUrl = getHostUrl;
3328
+ exports.getMigrationRequest = getMigrationRequest;
3329
+ exports.getMigrationRequestIsMerged = getMigrationRequestIsMerged;
1707
3330
  exports.getRecord = getRecord;
1708
3331
  exports.getTableColumns = getTableColumns;
1709
3332
  exports.getTableSchema = getTableSchema;
@@ -1712,6 +3335,9 @@ exports.getUserAPIKeys = getUserAPIKeys;
1712
3335
  exports.getWorkspace = getWorkspace;
1713
3336
  exports.getWorkspaceMembersList = getWorkspaceMembersList;
1714
3337
  exports.getWorkspacesList = getWorkspacesList;
3338
+ exports.greaterEquals = greaterEquals;
3339
+ exports.greaterThan = greaterThan;
3340
+ exports.greaterThanEquals = greaterThanEquals;
1715
3341
  exports.gt = gt;
1716
3342
  exports.gte = gte;
1717
3343
  exports.includes = includes;
@@ -1722,27 +3348,49 @@ exports.insertRecord = insertRecord;
1722
3348
  exports.insertRecordWithID = insertRecordWithID;
1723
3349
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
1724
3350
  exports.is = is;
3351
+ exports.isCursorPaginationOptions = isCursorPaginationOptions;
3352
+ exports.isHostProviderAlias = isHostProviderAlias;
3353
+ exports.isHostProviderBuilder = isHostProviderBuilder;
1725
3354
  exports.isIdentifiable = isIdentifiable;
1726
3355
  exports.isNot = isNot;
1727
3356
  exports.isXataRecord = isXataRecord;
1728
3357
  exports.le = le;
3358
+ exports.lessEquals = lessEquals;
3359
+ exports.lessThan = lessThan;
3360
+ exports.lessThanEquals = lessThanEquals;
3361
+ exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
3362
+ exports.listRegions = listRegions;
1729
3363
  exports.lt = lt;
1730
3364
  exports.lte = lte;
3365
+ exports.mergeMigrationRequest = mergeMigrationRequest;
1731
3366
  exports.notExists = notExists;
1732
3367
  exports.operationsByTag = operationsByTag;
3368
+ exports.parseProviderString = parseProviderString;
3369
+ exports.parseWorkspacesUrlParts = parseWorkspacesUrlParts;
1733
3370
  exports.pattern = pattern;
3371
+ exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
3372
+ exports.queryMigrationRequests = queryMigrationRequests;
1734
3373
  exports.queryTable = queryTable;
3374
+ exports.removeGitBranchesEntry = removeGitBranchesEntry;
1735
3375
  exports.removeWorkspaceMember = removeWorkspaceMember;
1736
3376
  exports.resendWorkspaceMemberInvite = resendWorkspaceMemberInvite;
3377
+ exports.resolveBranch = resolveBranch;
1737
3378
  exports.searchBranch = searchBranch;
3379
+ exports.searchTable = searchTable;
3380
+ exports.serialize = serialize;
1738
3381
  exports.setTableSchema = setTableSchema;
1739
3382
  exports.startsWith = startsWith;
3383
+ exports.summarizeTable = summarizeTable;
1740
3384
  exports.updateBranchMetadata = updateBranchMetadata;
3385
+ exports.updateBranchSchema = updateBranchSchema;
1741
3386
  exports.updateColumn = updateColumn;
3387
+ exports.updateDatabaseMetadata = updateDatabaseMetadata;
3388
+ exports.updateMigrationRequest = updateMigrationRequest;
1742
3389
  exports.updateRecordWithID = updateRecordWithID;
1743
3390
  exports.updateTable = updateTable;
1744
3391
  exports.updateUser = updateUser;
1745
3392
  exports.updateWorkspace = updateWorkspace;
3393
+ exports.updateWorkspaceMemberInvite = updateWorkspaceMemberInvite;
1746
3394
  exports.updateWorkspaceMemberRole = updateWorkspaceMemberRole;
1747
3395
  exports.upsertRecordWithID = upsertRecordWithID;
1748
3396
  //# sourceMappingURL=index.cjs.map