@xata.io/client 0.0.0-alpha.vf2043e7 → 0.0.0-alpha.vf20a10c

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