@xata.io/client 0.0.0-alpha.vfd071d9 → 0.0.0-alpha.vfd68d20

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