@xata.io/client 0.0.0-alpha.vfb85b8b → 0.0.0-alpha.vfba793c

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