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