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

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 +164 -0
  3. package/README.md +271 -1
  4. package/Usage.md +395 -0
  5. package/dist/index.cjs +2204 -0
  6. package/dist/index.cjs.map +1 -0
  7. package/dist/index.d.ts +3795 -6
  8. package/dist/index.mjs +2083 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/package.json +14 -6
  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.mjs ADDED
@@ -0,0 +1,2083 @@
1
+ function notEmpty(value) {
2
+ return value !== null && value !== void 0;
3
+ }
4
+ function compact(arr) {
5
+ return arr.filter(notEmpty);
6
+ }
7
+ function isObject(value) {
8
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
9
+ }
10
+ function isDefined(value) {
11
+ return value !== null && value !== void 0;
12
+ }
13
+ function isString(value) {
14
+ return isDefined(value) && typeof value === "string";
15
+ }
16
+ function toBase64(value) {
17
+ try {
18
+ return btoa(value);
19
+ } catch (err) {
20
+ const buf = Buffer;
21
+ return buf.from(value).toString("base64");
22
+ }
23
+ }
24
+
25
+ function getEnvironment() {
26
+ try {
27
+ if (isObject(process) && isObject(process.env)) {
28
+ return {
29
+ apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
30
+ databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
31
+ branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
32
+ envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
33
+ fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
34
+ };
35
+ }
36
+ } catch (err) {
37
+ }
38
+ try {
39
+ if (isObject(Deno) && isObject(Deno.env)) {
40
+ return {
41
+ apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
42
+ databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
43
+ branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
44
+ envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
45
+ fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
46
+ };
47
+ }
48
+ } catch (err) {
49
+ }
50
+ return {
51
+ apiKey: getGlobalApiKey(),
52
+ databaseURL: getGlobalDatabaseURL(),
53
+ branch: getGlobalBranch(),
54
+ envBranch: void 0,
55
+ fallbackBranch: getGlobalFallbackBranch()
56
+ };
57
+ }
58
+ function getGlobalApiKey() {
59
+ try {
60
+ return XATA_API_KEY;
61
+ } catch (err) {
62
+ return void 0;
63
+ }
64
+ }
65
+ function getGlobalDatabaseURL() {
66
+ try {
67
+ return XATA_DATABASE_URL;
68
+ } catch (err) {
69
+ return void 0;
70
+ }
71
+ }
72
+ function getGlobalBranch() {
73
+ try {
74
+ return XATA_BRANCH;
75
+ } catch (err) {
76
+ return void 0;
77
+ }
78
+ }
79
+ function getGlobalFallbackBranch() {
80
+ try {
81
+ return XATA_FALLBACK_BRANCH;
82
+ } catch (err) {
83
+ return void 0;
84
+ }
85
+ }
86
+ async function getGitBranch() {
87
+ const cmd = ["git", "branch", "--show-current"];
88
+ const nodeModule = ["child", "process"].join("_");
89
+ try {
90
+ if (typeof require === "function") {
91
+ return require(nodeModule).execSync(cmd.join(" "), { encoding: "utf-8" }).trim();
92
+ }
93
+ const { execSync } = await import(nodeModule);
94
+ return execSync(cmd.join(" "), { encoding: "utf-8" }).toString().trim();
95
+ } catch (err) {
96
+ }
97
+ try {
98
+ if (isObject(Deno)) {
99
+ const process2 = Deno.run({ cmd, stdout: "piped", stderr: "piped" });
100
+ return new TextDecoder().decode(await process2.output()).trim();
101
+ }
102
+ } catch (err) {
103
+ }
104
+ }
105
+
106
+ function getAPIKey() {
107
+ try {
108
+ const { apiKey } = getEnvironment();
109
+ return apiKey;
110
+ } catch (err) {
111
+ return void 0;
112
+ }
113
+ }
114
+
115
+ function getFetchImplementation(userFetch) {
116
+ const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
117
+ const fetchImpl = userFetch ?? globalFetch;
118
+ if (!fetchImpl) {
119
+ throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
120
+ }
121
+ return fetchImpl;
122
+ }
123
+
124
+ const VERSION = "0.0.0-alpha.vfbac5b5";
125
+
126
+ class ErrorWithCause extends Error {
127
+ constructor(message, options) {
128
+ super(message, options);
129
+ }
130
+ }
131
+ class FetcherError extends ErrorWithCause {
132
+ constructor(status, data, requestId) {
133
+ super(getMessage(data));
134
+ this.status = status;
135
+ this.errors = isBulkError(data) ? data.errors : void 0;
136
+ this.requestId = requestId;
137
+ if (data instanceof Error) {
138
+ this.stack = data.stack;
139
+ this.cause = data.cause;
140
+ }
141
+ }
142
+ toString() {
143
+ const error = super.toString();
144
+ return `[${this.status}] (${this.requestId ?? "Unknown"}): ${error}`;
145
+ }
146
+ }
147
+ function isBulkError(error) {
148
+ return isObject(error) && Array.isArray(error.errors);
149
+ }
150
+ function isErrorWithMessage(error) {
151
+ return isObject(error) && isString(error.message);
152
+ }
153
+ function getMessage(data) {
154
+ if (data instanceof Error) {
155
+ return data.message;
156
+ } else if (isString(data)) {
157
+ return data;
158
+ } else if (isErrorWithMessage(data)) {
159
+ return data.message;
160
+ } else if (isBulkError(data)) {
161
+ return "Bulk operation failed";
162
+ } else {
163
+ return "Unexpected error";
164
+ }
165
+ }
166
+
167
+ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
168
+ const cleanQueryParams = Object.entries(queryParams).reduce((acc, [key, value]) => {
169
+ if (value === void 0 || value === null)
170
+ return acc;
171
+ return { ...acc, [key]: value };
172
+ }, {});
173
+ const query = new URLSearchParams(cleanQueryParams).toString();
174
+ const queryString = query.length > 0 ? `?${query}` : "";
175
+ return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
176
+ };
177
+ function buildBaseUrl({
178
+ path,
179
+ workspacesApiUrl,
180
+ apiUrl,
181
+ pathParams
182
+ }) {
183
+ if (!pathParams?.workspace)
184
+ return `${apiUrl}${path}`;
185
+ const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
186
+ return url.replace("{workspaceId}", pathParams.workspace);
187
+ }
188
+ function hostHeader(url) {
189
+ const pattern = /.*:\/\/(?<host>[^/]+).*/;
190
+ const { groups } = pattern.exec(url) ?? {};
191
+ return groups?.host ? { Host: groups.host } : {};
192
+ }
193
+ async function fetch$1({
194
+ url: path,
195
+ method,
196
+ body,
197
+ headers,
198
+ pathParams,
199
+ queryParams,
200
+ fetchImpl,
201
+ apiKey,
202
+ apiUrl,
203
+ workspacesApiUrl
204
+ }) {
205
+ const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
206
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
207
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
208
+ const response = await fetchImpl(url, {
209
+ method: method.toUpperCase(),
210
+ body: body ? JSON.stringify(body) : void 0,
211
+ headers: {
212
+ "Content-Type": "application/json",
213
+ "User-Agent": `Xata client-ts/${VERSION}`,
214
+ ...headers,
215
+ ...hostHeader(fullUrl),
216
+ Authorization: `Bearer ${apiKey}`
217
+ }
218
+ });
219
+ if (response.status === 204) {
220
+ return {};
221
+ }
222
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
223
+ try {
224
+ const jsonResponse = await response.json();
225
+ if (response.ok) {
226
+ return jsonResponse;
227
+ }
228
+ throw new FetcherError(response.status, jsonResponse, requestId);
229
+ } catch (error) {
230
+ throw new FetcherError(response.status, error, requestId);
231
+ }
232
+ }
233
+
234
+ const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
235
+ const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
236
+ const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
237
+ const getUserAPIKeys = (variables) => fetch$1({
238
+ url: "/user/keys",
239
+ method: "get",
240
+ ...variables
241
+ });
242
+ const createUserAPIKey = (variables) => fetch$1({
243
+ url: "/user/keys/{keyName}",
244
+ method: "post",
245
+ ...variables
246
+ });
247
+ const deleteUserAPIKey = (variables) => fetch$1({
248
+ url: "/user/keys/{keyName}",
249
+ method: "delete",
250
+ ...variables
251
+ });
252
+ const createWorkspace = (variables) => fetch$1({
253
+ url: "/workspaces",
254
+ method: "post",
255
+ ...variables
256
+ });
257
+ const getWorkspacesList = (variables) => fetch$1({
258
+ url: "/workspaces",
259
+ method: "get",
260
+ ...variables
261
+ });
262
+ const getWorkspace = (variables) => fetch$1({
263
+ url: "/workspaces/{workspaceId}",
264
+ method: "get",
265
+ ...variables
266
+ });
267
+ const updateWorkspace = (variables) => fetch$1({
268
+ url: "/workspaces/{workspaceId}",
269
+ method: "put",
270
+ ...variables
271
+ });
272
+ const deleteWorkspace = (variables) => fetch$1({
273
+ url: "/workspaces/{workspaceId}",
274
+ method: "delete",
275
+ ...variables
276
+ });
277
+ const getWorkspaceMembersList = (variables) => fetch$1({
278
+ url: "/workspaces/{workspaceId}/members",
279
+ method: "get",
280
+ ...variables
281
+ });
282
+ const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
283
+ const removeWorkspaceMember = (variables) => fetch$1({
284
+ url: "/workspaces/{workspaceId}/members/{userId}",
285
+ method: "delete",
286
+ ...variables
287
+ });
288
+ const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
289
+ const cancelWorkspaceMemberInvite = (variables) => fetch$1({
290
+ url: "/workspaces/{workspaceId}/invites/{inviteId}",
291
+ method: "delete",
292
+ ...variables
293
+ });
294
+ const resendWorkspaceMemberInvite = (variables) => fetch$1({
295
+ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
296
+ method: "post",
297
+ ...variables
298
+ });
299
+ const acceptWorkspaceMemberInvite = (variables) => fetch$1({
300
+ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
301
+ method: "post",
302
+ ...variables
303
+ });
304
+ const getDatabaseList = (variables) => fetch$1({
305
+ url: "/dbs",
306
+ method: "get",
307
+ ...variables
308
+ });
309
+ const getBranchList = (variables) => fetch$1({
310
+ url: "/dbs/{dbName}",
311
+ method: "get",
312
+ ...variables
313
+ });
314
+ const createDatabase = (variables) => fetch$1({
315
+ url: "/dbs/{dbName}",
316
+ method: "put",
317
+ ...variables
318
+ });
319
+ const deleteDatabase = (variables) => fetch$1({
320
+ url: "/dbs/{dbName}",
321
+ method: "delete",
322
+ ...variables
323
+ });
324
+ const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
325
+ const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
326
+ const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
327
+ const resolveBranch = (variables) => fetch$1({
328
+ url: "/dbs/{dbName}/resolveBranch",
329
+ method: "get",
330
+ ...variables
331
+ });
332
+ const getBranchDetails = (variables) => fetch$1({
333
+ url: "/db/{dbBranchName}",
334
+ method: "get",
335
+ ...variables
336
+ });
337
+ const createBranch = (variables) => fetch$1({
338
+ url: "/db/{dbBranchName}",
339
+ method: "put",
340
+ ...variables
341
+ });
342
+ const deleteBranch = (variables) => fetch$1({
343
+ url: "/db/{dbBranchName}",
344
+ method: "delete",
345
+ ...variables
346
+ });
347
+ const updateBranchMetadata = (variables) => fetch$1({
348
+ url: "/db/{dbBranchName}/metadata",
349
+ method: "put",
350
+ ...variables
351
+ });
352
+ const getBranchMetadata = (variables) => fetch$1({
353
+ url: "/db/{dbBranchName}/metadata",
354
+ method: "get",
355
+ ...variables
356
+ });
357
+ const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
358
+ const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
359
+ const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
360
+ const getBranchStats = (variables) => fetch$1({
361
+ url: "/db/{dbBranchName}/stats",
362
+ method: "get",
363
+ ...variables
364
+ });
365
+ const createTable = (variables) => fetch$1({
366
+ url: "/db/{dbBranchName}/tables/{tableName}",
367
+ method: "put",
368
+ ...variables
369
+ });
370
+ const deleteTable = (variables) => fetch$1({
371
+ url: "/db/{dbBranchName}/tables/{tableName}",
372
+ method: "delete",
373
+ ...variables
374
+ });
375
+ const updateTable = (variables) => fetch$1({
376
+ url: "/db/{dbBranchName}/tables/{tableName}",
377
+ method: "patch",
378
+ ...variables
379
+ });
380
+ const getTableSchema = (variables) => fetch$1({
381
+ url: "/db/{dbBranchName}/tables/{tableName}/schema",
382
+ method: "get",
383
+ ...variables
384
+ });
385
+ const setTableSchema = (variables) => fetch$1({
386
+ url: "/db/{dbBranchName}/tables/{tableName}/schema",
387
+ method: "put",
388
+ ...variables
389
+ });
390
+ const getTableColumns = (variables) => fetch$1({
391
+ url: "/db/{dbBranchName}/tables/{tableName}/columns",
392
+ method: "get",
393
+ ...variables
394
+ });
395
+ const addTableColumn = (variables) => fetch$1({
396
+ url: "/db/{dbBranchName}/tables/{tableName}/columns",
397
+ method: "post",
398
+ ...variables
399
+ });
400
+ const getColumn = (variables) => fetch$1({
401
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
402
+ method: "get",
403
+ ...variables
404
+ });
405
+ const deleteColumn = (variables) => fetch$1({
406
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
407
+ method: "delete",
408
+ ...variables
409
+ });
410
+ const updateColumn = (variables) => fetch$1({
411
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
412
+ method: "patch",
413
+ ...variables
414
+ });
415
+ const insertRecord = (variables) => fetch$1({
416
+ url: "/db/{dbBranchName}/tables/{tableName}/data",
417
+ method: "post",
418
+ ...variables
419
+ });
420
+ const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
421
+ const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
422
+ const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
423
+ const deleteRecord = (variables) => fetch$1({
424
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
425
+ method: "delete",
426
+ ...variables
427
+ });
428
+ const getRecord = (variables) => fetch$1({
429
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
430
+ method: "get",
431
+ ...variables
432
+ });
433
+ const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
434
+ const queryTable = (variables) => fetch$1({
435
+ url: "/db/{dbBranchName}/tables/{tableName}/query",
436
+ method: "post",
437
+ ...variables
438
+ });
439
+ const searchTable = (variables) => fetch$1({
440
+ url: "/db/{dbBranchName}/tables/{tableName}/search",
441
+ method: "post",
442
+ ...variables
443
+ });
444
+ const searchBranch = (variables) => fetch$1({
445
+ url: "/db/{dbBranchName}/search",
446
+ method: "post",
447
+ ...variables
448
+ });
449
+ const operationsByTag = {
450
+ users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
451
+ workspaces: {
452
+ createWorkspace,
453
+ getWorkspacesList,
454
+ getWorkspace,
455
+ updateWorkspace,
456
+ deleteWorkspace,
457
+ getWorkspaceMembersList,
458
+ updateWorkspaceMemberRole,
459
+ removeWorkspaceMember,
460
+ inviteWorkspaceMember,
461
+ cancelWorkspaceMemberInvite,
462
+ resendWorkspaceMemberInvite,
463
+ acceptWorkspaceMemberInvite
464
+ },
465
+ database: {
466
+ getDatabaseList,
467
+ createDatabase,
468
+ deleteDatabase,
469
+ getGitBranchesMapping,
470
+ addGitBranchesEntry,
471
+ removeGitBranchesEntry,
472
+ resolveBranch
473
+ },
474
+ branch: {
475
+ getBranchList,
476
+ getBranchDetails,
477
+ createBranch,
478
+ deleteBranch,
479
+ updateBranchMetadata,
480
+ getBranchMetadata,
481
+ getBranchMigrationHistory,
482
+ executeBranchMigrationPlan,
483
+ getBranchMigrationPlan,
484
+ getBranchStats
485
+ },
486
+ table: {
487
+ createTable,
488
+ deleteTable,
489
+ updateTable,
490
+ getTableSchema,
491
+ setTableSchema,
492
+ getTableColumns,
493
+ addTableColumn,
494
+ getColumn,
495
+ deleteColumn,
496
+ updateColumn
497
+ },
498
+ records: {
499
+ insertRecord,
500
+ insertRecordWithID,
501
+ updateRecordWithID,
502
+ upsertRecordWithID,
503
+ deleteRecord,
504
+ getRecord,
505
+ bulkInsertTableRecords,
506
+ queryTable,
507
+ searchTable,
508
+ searchBranch
509
+ }
510
+ };
511
+
512
+ function getHostUrl(provider, type) {
513
+ if (isValidAlias(provider)) {
514
+ return providers[provider][type];
515
+ } else if (isValidBuilder(provider)) {
516
+ return provider[type];
517
+ }
518
+ throw new Error("Invalid API provider");
519
+ }
520
+ const providers = {
521
+ production: {
522
+ main: "https://api.xata.io",
523
+ workspaces: "https://{workspaceId}.xata.sh"
524
+ },
525
+ staging: {
526
+ main: "https://staging.xatabase.co",
527
+ workspaces: "https://{workspaceId}.staging.xatabase.co"
528
+ }
529
+ };
530
+ function isValidAlias(alias) {
531
+ return isString(alias) && Object.keys(providers).includes(alias);
532
+ }
533
+ function isValidBuilder(builder) {
534
+ return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
535
+ }
536
+
537
+ var __accessCheck$7 = (obj, member, msg) => {
538
+ if (!member.has(obj))
539
+ throw TypeError("Cannot " + msg);
540
+ };
541
+ var __privateGet$7 = (obj, member, getter) => {
542
+ __accessCheck$7(obj, member, "read from private field");
543
+ return getter ? getter.call(obj) : member.get(obj);
544
+ };
545
+ var __privateAdd$7 = (obj, member, value) => {
546
+ if (member.has(obj))
547
+ throw TypeError("Cannot add the same private member more than once");
548
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
549
+ };
550
+ var __privateSet$7 = (obj, member, value, setter) => {
551
+ __accessCheck$7(obj, member, "write to private field");
552
+ setter ? setter.call(obj, value) : member.set(obj, value);
553
+ return value;
554
+ };
555
+ var _extraProps, _namespaces;
556
+ class XataApiClient {
557
+ constructor(options = {}) {
558
+ __privateAdd$7(this, _extraProps, void 0);
559
+ __privateAdd$7(this, _namespaces, {});
560
+ const provider = options.host ?? "production";
561
+ const apiKey = options?.apiKey ?? getAPIKey();
562
+ if (!apiKey) {
563
+ throw new Error("Could not resolve a valid apiKey");
564
+ }
565
+ __privateSet$7(this, _extraProps, {
566
+ apiUrl: getHostUrl(provider, "main"),
567
+ workspacesApiUrl: getHostUrl(provider, "workspaces"),
568
+ fetchImpl: getFetchImplementation(options.fetch),
569
+ apiKey
570
+ });
571
+ }
572
+ get user() {
573
+ if (!__privateGet$7(this, _namespaces).user)
574
+ __privateGet$7(this, _namespaces).user = new UserApi(__privateGet$7(this, _extraProps));
575
+ return __privateGet$7(this, _namespaces).user;
576
+ }
577
+ get workspaces() {
578
+ if (!__privateGet$7(this, _namespaces).workspaces)
579
+ __privateGet$7(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$7(this, _extraProps));
580
+ return __privateGet$7(this, _namespaces).workspaces;
581
+ }
582
+ get databases() {
583
+ if (!__privateGet$7(this, _namespaces).databases)
584
+ __privateGet$7(this, _namespaces).databases = new DatabaseApi(__privateGet$7(this, _extraProps));
585
+ return __privateGet$7(this, _namespaces).databases;
586
+ }
587
+ get branches() {
588
+ if (!__privateGet$7(this, _namespaces).branches)
589
+ __privateGet$7(this, _namespaces).branches = new BranchApi(__privateGet$7(this, _extraProps));
590
+ return __privateGet$7(this, _namespaces).branches;
591
+ }
592
+ get tables() {
593
+ if (!__privateGet$7(this, _namespaces).tables)
594
+ __privateGet$7(this, _namespaces).tables = new TableApi(__privateGet$7(this, _extraProps));
595
+ return __privateGet$7(this, _namespaces).tables;
596
+ }
597
+ get records() {
598
+ if (!__privateGet$7(this, _namespaces).records)
599
+ __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
600
+ return __privateGet$7(this, _namespaces).records;
601
+ }
602
+ }
603
+ _extraProps = new WeakMap();
604
+ _namespaces = new WeakMap();
605
+ class UserApi {
606
+ constructor(extraProps) {
607
+ this.extraProps = extraProps;
608
+ }
609
+ getUser() {
610
+ return operationsByTag.users.getUser({ ...this.extraProps });
611
+ }
612
+ updateUser(user) {
613
+ return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
614
+ }
615
+ deleteUser() {
616
+ return operationsByTag.users.deleteUser({ ...this.extraProps });
617
+ }
618
+ getUserAPIKeys() {
619
+ return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
620
+ }
621
+ createUserAPIKey(keyName) {
622
+ return operationsByTag.users.createUserAPIKey({
623
+ pathParams: { keyName },
624
+ ...this.extraProps
625
+ });
626
+ }
627
+ deleteUserAPIKey(keyName) {
628
+ return operationsByTag.users.deleteUserAPIKey({
629
+ pathParams: { keyName },
630
+ ...this.extraProps
631
+ });
632
+ }
633
+ }
634
+ class WorkspaceApi {
635
+ constructor(extraProps) {
636
+ this.extraProps = extraProps;
637
+ }
638
+ createWorkspace(workspaceMeta) {
639
+ return operationsByTag.workspaces.createWorkspace({
640
+ body: workspaceMeta,
641
+ ...this.extraProps
642
+ });
643
+ }
644
+ getWorkspacesList() {
645
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
646
+ }
647
+ getWorkspace(workspaceId) {
648
+ return operationsByTag.workspaces.getWorkspace({
649
+ pathParams: { workspaceId },
650
+ ...this.extraProps
651
+ });
652
+ }
653
+ updateWorkspace(workspaceId, workspaceMeta) {
654
+ return operationsByTag.workspaces.updateWorkspace({
655
+ pathParams: { workspaceId },
656
+ body: workspaceMeta,
657
+ ...this.extraProps
658
+ });
659
+ }
660
+ deleteWorkspace(workspaceId) {
661
+ return operationsByTag.workspaces.deleteWorkspace({
662
+ pathParams: { workspaceId },
663
+ ...this.extraProps
664
+ });
665
+ }
666
+ getWorkspaceMembersList(workspaceId) {
667
+ return operationsByTag.workspaces.getWorkspaceMembersList({
668
+ pathParams: { workspaceId },
669
+ ...this.extraProps
670
+ });
671
+ }
672
+ updateWorkspaceMemberRole(workspaceId, userId, role) {
673
+ return operationsByTag.workspaces.updateWorkspaceMemberRole({
674
+ pathParams: { workspaceId, userId },
675
+ body: { role },
676
+ ...this.extraProps
677
+ });
678
+ }
679
+ removeWorkspaceMember(workspaceId, userId) {
680
+ return operationsByTag.workspaces.removeWorkspaceMember({
681
+ pathParams: { workspaceId, userId },
682
+ ...this.extraProps
683
+ });
684
+ }
685
+ inviteWorkspaceMember(workspaceId, email, role) {
686
+ return operationsByTag.workspaces.inviteWorkspaceMember({
687
+ pathParams: { workspaceId },
688
+ body: { email, role },
689
+ ...this.extraProps
690
+ });
691
+ }
692
+ cancelWorkspaceMemberInvite(workspaceId, inviteId) {
693
+ return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
694
+ pathParams: { workspaceId, inviteId },
695
+ ...this.extraProps
696
+ });
697
+ }
698
+ resendWorkspaceMemberInvite(workspaceId, inviteId) {
699
+ return operationsByTag.workspaces.resendWorkspaceMemberInvite({
700
+ pathParams: { workspaceId, inviteId },
701
+ ...this.extraProps
702
+ });
703
+ }
704
+ acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
705
+ return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
706
+ pathParams: { workspaceId, inviteKey },
707
+ ...this.extraProps
708
+ });
709
+ }
710
+ }
711
+ class DatabaseApi {
712
+ constructor(extraProps) {
713
+ this.extraProps = extraProps;
714
+ }
715
+ getDatabaseList(workspace) {
716
+ return operationsByTag.database.getDatabaseList({
717
+ pathParams: { workspace },
718
+ ...this.extraProps
719
+ });
720
+ }
721
+ createDatabase(workspace, dbName, options = {}) {
722
+ return operationsByTag.database.createDatabase({
723
+ pathParams: { workspace, dbName },
724
+ body: options,
725
+ ...this.extraProps
726
+ });
727
+ }
728
+ deleteDatabase(workspace, dbName) {
729
+ return operationsByTag.database.deleteDatabase({
730
+ pathParams: { workspace, dbName },
731
+ ...this.extraProps
732
+ });
733
+ }
734
+ getGitBranchesMapping(workspace, dbName) {
735
+ return operationsByTag.database.getGitBranchesMapping({
736
+ pathParams: { workspace, dbName },
737
+ ...this.extraProps
738
+ });
739
+ }
740
+ addGitBranchesEntry(workspace, dbName, body) {
741
+ return operationsByTag.database.addGitBranchesEntry({
742
+ pathParams: { workspace, dbName },
743
+ body,
744
+ ...this.extraProps
745
+ });
746
+ }
747
+ removeGitBranchesEntry(workspace, dbName, gitBranch) {
748
+ return operationsByTag.database.removeGitBranchesEntry({
749
+ pathParams: { workspace, dbName },
750
+ queryParams: { gitBranch },
751
+ ...this.extraProps
752
+ });
753
+ }
754
+ resolveBranch(workspace, dbName, gitBranch, fallbackBranch) {
755
+ return operationsByTag.database.resolveBranch({
756
+ pathParams: { workspace, dbName },
757
+ queryParams: { gitBranch, fallbackBranch },
758
+ ...this.extraProps
759
+ });
760
+ }
761
+ }
762
+ class BranchApi {
763
+ constructor(extraProps) {
764
+ this.extraProps = extraProps;
765
+ }
766
+ getBranchList(workspace, dbName) {
767
+ return operationsByTag.branch.getBranchList({
768
+ pathParams: { workspace, dbName },
769
+ ...this.extraProps
770
+ });
771
+ }
772
+ getBranchDetails(workspace, database, branch) {
773
+ return operationsByTag.branch.getBranchDetails({
774
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
775
+ ...this.extraProps
776
+ });
777
+ }
778
+ createBranch(workspace, database, branch, from, options = {}) {
779
+ return operationsByTag.branch.createBranch({
780
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
781
+ queryParams: isString(from) ? { from } : void 0,
782
+ body: options,
783
+ ...this.extraProps
784
+ });
785
+ }
786
+ deleteBranch(workspace, database, branch) {
787
+ return operationsByTag.branch.deleteBranch({
788
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
789
+ ...this.extraProps
790
+ });
791
+ }
792
+ updateBranchMetadata(workspace, database, branch, metadata = {}) {
793
+ return operationsByTag.branch.updateBranchMetadata({
794
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
795
+ body: metadata,
796
+ ...this.extraProps
797
+ });
798
+ }
799
+ getBranchMetadata(workspace, database, branch) {
800
+ return operationsByTag.branch.getBranchMetadata({
801
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
802
+ ...this.extraProps
803
+ });
804
+ }
805
+ getBranchMigrationHistory(workspace, database, branch, options = {}) {
806
+ return operationsByTag.branch.getBranchMigrationHistory({
807
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
808
+ body: options,
809
+ ...this.extraProps
810
+ });
811
+ }
812
+ executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
813
+ return operationsByTag.branch.executeBranchMigrationPlan({
814
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
815
+ body: migrationPlan,
816
+ ...this.extraProps
817
+ });
818
+ }
819
+ getBranchMigrationPlan(workspace, database, branch, schema) {
820
+ return operationsByTag.branch.getBranchMigrationPlan({
821
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
822
+ body: schema,
823
+ ...this.extraProps
824
+ });
825
+ }
826
+ getBranchStats(workspace, database, branch) {
827
+ return operationsByTag.branch.getBranchStats({
828
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
829
+ ...this.extraProps
830
+ });
831
+ }
832
+ }
833
+ class TableApi {
834
+ constructor(extraProps) {
835
+ this.extraProps = extraProps;
836
+ }
837
+ createTable(workspace, database, branch, tableName) {
838
+ return operationsByTag.table.createTable({
839
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
840
+ ...this.extraProps
841
+ });
842
+ }
843
+ deleteTable(workspace, database, branch, tableName) {
844
+ return operationsByTag.table.deleteTable({
845
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
846
+ ...this.extraProps
847
+ });
848
+ }
849
+ updateTable(workspace, database, branch, tableName, options) {
850
+ return operationsByTag.table.updateTable({
851
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
852
+ body: options,
853
+ ...this.extraProps
854
+ });
855
+ }
856
+ getTableSchema(workspace, database, branch, tableName) {
857
+ return operationsByTag.table.getTableSchema({
858
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
859
+ ...this.extraProps
860
+ });
861
+ }
862
+ setTableSchema(workspace, database, branch, tableName, options) {
863
+ return operationsByTag.table.setTableSchema({
864
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
865
+ body: options,
866
+ ...this.extraProps
867
+ });
868
+ }
869
+ getTableColumns(workspace, database, branch, tableName) {
870
+ return operationsByTag.table.getTableColumns({
871
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
872
+ ...this.extraProps
873
+ });
874
+ }
875
+ addTableColumn(workspace, database, branch, tableName, column) {
876
+ return operationsByTag.table.addTableColumn({
877
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
878
+ body: column,
879
+ ...this.extraProps
880
+ });
881
+ }
882
+ getColumn(workspace, database, branch, tableName, columnName) {
883
+ return operationsByTag.table.getColumn({
884
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
885
+ ...this.extraProps
886
+ });
887
+ }
888
+ deleteColumn(workspace, database, branch, tableName, columnName) {
889
+ return operationsByTag.table.deleteColumn({
890
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
891
+ ...this.extraProps
892
+ });
893
+ }
894
+ updateColumn(workspace, database, branch, tableName, columnName, options) {
895
+ return operationsByTag.table.updateColumn({
896
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
897
+ body: options,
898
+ ...this.extraProps
899
+ });
900
+ }
901
+ }
902
+ class RecordsApi {
903
+ constructor(extraProps) {
904
+ this.extraProps = extraProps;
905
+ }
906
+ insertRecord(workspace, database, branch, tableName, record) {
907
+ return operationsByTag.records.insertRecord({
908
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
909
+ body: record,
910
+ ...this.extraProps
911
+ });
912
+ }
913
+ insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
914
+ return operationsByTag.records.insertRecordWithID({
915
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
916
+ queryParams: options,
917
+ body: record,
918
+ ...this.extraProps
919
+ });
920
+ }
921
+ updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
922
+ return operationsByTag.records.updateRecordWithID({
923
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
924
+ queryParams: options,
925
+ body: record,
926
+ ...this.extraProps
927
+ });
928
+ }
929
+ upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
930
+ return operationsByTag.records.upsertRecordWithID({
931
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
932
+ queryParams: options,
933
+ body: record,
934
+ ...this.extraProps
935
+ });
936
+ }
937
+ deleteRecord(workspace, database, branch, tableName, recordId) {
938
+ return operationsByTag.records.deleteRecord({
939
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
940
+ ...this.extraProps
941
+ });
942
+ }
943
+ getRecord(workspace, database, branch, tableName, recordId, options = {}) {
944
+ return operationsByTag.records.getRecord({
945
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
946
+ ...this.extraProps
947
+ });
948
+ }
949
+ bulkInsertTableRecords(workspace, database, branch, tableName, records) {
950
+ return operationsByTag.records.bulkInsertTableRecords({
951
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
952
+ body: { records },
953
+ ...this.extraProps
954
+ });
955
+ }
956
+ queryTable(workspace, database, branch, tableName, query) {
957
+ return operationsByTag.records.queryTable({
958
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
959
+ body: query,
960
+ ...this.extraProps
961
+ });
962
+ }
963
+ searchTable(workspace, database, branch, tableName, query) {
964
+ return operationsByTag.records.searchTable({
965
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
966
+ body: query,
967
+ ...this.extraProps
968
+ });
969
+ }
970
+ searchBranch(workspace, database, branch, query) {
971
+ return operationsByTag.records.searchBranch({
972
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
973
+ body: query,
974
+ ...this.extraProps
975
+ });
976
+ }
977
+ }
978
+
979
+ class XataApiPlugin {
980
+ async build(options) {
981
+ const { fetchImpl, apiKey } = await options.getFetchProps();
982
+ return new XataApiClient({ fetch: fetchImpl, apiKey });
983
+ }
984
+ }
985
+
986
+ class XataPlugin {
987
+ }
988
+
989
+ var __accessCheck$6 = (obj, member, msg) => {
990
+ if (!member.has(obj))
991
+ throw TypeError("Cannot " + msg);
992
+ };
993
+ var __privateGet$6 = (obj, member, getter) => {
994
+ __accessCheck$6(obj, member, "read from private field");
995
+ return getter ? getter.call(obj) : member.get(obj);
996
+ };
997
+ var __privateAdd$6 = (obj, member, value) => {
998
+ if (member.has(obj))
999
+ throw TypeError("Cannot add the same private member more than once");
1000
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1001
+ };
1002
+ var __privateSet$6 = (obj, member, value, setter) => {
1003
+ __accessCheck$6(obj, member, "write to private field");
1004
+ setter ? setter.call(obj, value) : member.set(obj, value);
1005
+ return value;
1006
+ };
1007
+ var _query, _page;
1008
+ class Page {
1009
+ constructor(query, meta, records = []) {
1010
+ __privateAdd$6(this, _query, void 0);
1011
+ __privateSet$6(this, _query, query);
1012
+ this.meta = meta;
1013
+ this.records = new RecordArray(this, records);
1014
+ }
1015
+ async nextPage(size, offset) {
1016
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, after: this.meta.page.cursor } });
1017
+ }
1018
+ async previousPage(size, offset) {
1019
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, before: this.meta.page.cursor } });
1020
+ }
1021
+ async firstPage(size, offset) {
1022
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, first: this.meta.page.cursor } });
1023
+ }
1024
+ async lastPage(size, offset) {
1025
+ return __privateGet$6(this, _query).getPaginated({ pagination: { size, offset, last: this.meta.page.cursor } });
1026
+ }
1027
+ hasNextPage() {
1028
+ return this.meta.page.more;
1029
+ }
1030
+ }
1031
+ _query = new WeakMap();
1032
+ const PAGINATION_MAX_SIZE = 200;
1033
+ const PAGINATION_DEFAULT_SIZE = 20;
1034
+ const PAGINATION_MAX_OFFSET = 800;
1035
+ const PAGINATION_DEFAULT_OFFSET = 0;
1036
+ function isCursorPaginationOptions(options) {
1037
+ return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
1038
+ }
1039
+ const _RecordArray = class extends Array {
1040
+ constructor(...args) {
1041
+ super(..._RecordArray.parseConstructorParams(...args));
1042
+ __privateAdd$6(this, _page, void 0);
1043
+ __privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
1044
+ }
1045
+ static parseConstructorParams(...args) {
1046
+ if (args.length === 1 && typeof args[0] === "number") {
1047
+ return new Array(args[0]);
1048
+ }
1049
+ if (args.length <= 2 && isObject(args[0]?.meta) && Array.isArray(args[1] ?? [])) {
1050
+ const result = args[1] ?? args[0].records ?? [];
1051
+ return new Array(...result);
1052
+ }
1053
+ return new Array(...args);
1054
+ }
1055
+ toArray() {
1056
+ return new Array(...this);
1057
+ }
1058
+ map(callbackfn, thisArg) {
1059
+ return this.toArray().map(callbackfn, thisArg);
1060
+ }
1061
+ async nextPage(size, offset) {
1062
+ const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1063
+ return new _RecordArray(newPage);
1064
+ }
1065
+ async previousPage(size, offset) {
1066
+ const newPage = await __privateGet$6(this, _page).previousPage(size, offset);
1067
+ return new _RecordArray(newPage);
1068
+ }
1069
+ async firstPage(size, offset) {
1070
+ const newPage = await __privateGet$6(this, _page).firstPage(size, offset);
1071
+ return new _RecordArray(newPage);
1072
+ }
1073
+ async lastPage(size, offset) {
1074
+ const newPage = await __privateGet$6(this, _page).lastPage(size, offset);
1075
+ return new _RecordArray(newPage);
1076
+ }
1077
+ hasNextPage() {
1078
+ return __privateGet$6(this, _page).meta.page.more;
1079
+ }
1080
+ };
1081
+ let RecordArray = _RecordArray;
1082
+ _page = new WeakMap();
1083
+
1084
+ var __accessCheck$5 = (obj, member, msg) => {
1085
+ if (!member.has(obj))
1086
+ throw TypeError("Cannot " + msg);
1087
+ };
1088
+ var __privateGet$5 = (obj, member, getter) => {
1089
+ __accessCheck$5(obj, member, "read from private field");
1090
+ return getter ? getter.call(obj) : member.get(obj);
1091
+ };
1092
+ var __privateAdd$5 = (obj, member, value) => {
1093
+ if (member.has(obj))
1094
+ throw TypeError("Cannot add the same private member more than once");
1095
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1096
+ };
1097
+ var __privateSet$5 = (obj, member, value, setter) => {
1098
+ __accessCheck$5(obj, member, "write to private field");
1099
+ setter ? setter.call(obj, value) : member.set(obj, value);
1100
+ return value;
1101
+ };
1102
+ var _table$1, _repository, _data;
1103
+ const _Query = class {
1104
+ constructor(repository, table, data, rawParent) {
1105
+ __privateAdd$5(this, _table$1, void 0);
1106
+ __privateAdd$5(this, _repository, void 0);
1107
+ __privateAdd$5(this, _data, { filter: {} });
1108
+ this.meta = { page: { cursor: "start", more: true } };
1109
+ this.records = new RecordArray(this, []);
1110
+ __privateSet$5(this, _table$1, table);
1111
+ if (repository) {
1112
+ __privateSet$5(this, _repository, repository);
1113
+ } else {
1114
+ __privateSet$5(this, _repository, this);
1115
+ }
1116
+ const parent = cleanParent(data, rawParent);
1117
+ __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
1118
+ __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
1119
+ __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
1120
+ __privateGet$5(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
1121
+ __privateGet$5(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
1122
+ __privateGet$5(this, _data).sort = data.sort ?? parent?.sort;
1123
+ __privateGet$5(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
1124
+ __privateGet$5(this, _data).pagination = data.pagination ?? parent?.pagination;
1125
+ __privateGet$5(this, _data).cache = data.cache ?? parent?.cache;
1126
+ this.any = this.any.bind(this);
1127
+ this.all = this.all.bind(this);
1128
+ this.not = this.not.bind(this);
1129
+ this.filter = this.filter.bind(this);
1130
+ this.sort = this.sort.bind(this);
1131
+ this.none = this.none.bind(this);
1132
+ Object.defineProperty(this, "table", { enumerable: false });
1133
+ Object.defineProperty(this, "repository", { enumerable: false });
1134
+ }
1135
+ getQueryOptions() {
1136
+ return __privateGet$5(this, _data);
1137
+ }
1138
+ key() {
1139
+ const { columns = [], filter = {}, sort = [], pagination = {} } = __privateGet$5(this, _data);
1140
+ const key = JSON.stringify({ columns, filter, sort, pagination });
1141
+ return toBase64(key);
1142
+ }
1143
+ any(...queries) {
1144
+ const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
1145
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $any } }, __privateGet$5(this, _data));
1146
+ }
1147
+ all(...queries) {
1148
+ const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
1149
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1150
+ }
1151
+ not(...queries) {
1152
+ const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
1153
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $not } }, __privateGet$5(this, _data));
1154
+ }
1155
+ none(...queries) {
1156
+ const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
1157
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $none } }, __privateGet$5(this, _data));
1158
+ }
1159
+ filter(a, b) {
1160
+ if (arguments.length === 1) {
1161
+ const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1162
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1163
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1164
+ } else {
1165
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1166
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1167
+ }
1168
+ }
1169
+ sort(column, direction) {
1170
+ const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1171
+ const sort = [...originalSort, { column, direction }];
1172
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
1173
+ }
1174
+ select(columns) {
1175
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { columns }, __privateGet$5(this, _data));
1176
+ }
1177
+ getPaginated(options = {}) {
1178
+ const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
1179
+ return __privateGet$5(this, _repository).query(query);
1180
+ }
1181
+ async *[Symbol.asyncIterator]() {
1182
+ for await (const [record] of this.getIterator({ batchSize: 1 })) {
1183
+ yield record;
1184
+ }
1185
+ }
1186
+ async *getIterator(options = {}) {
1187
+ const { batchSize = 1 } = options;
1188
+ let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
1189
+ let more = page.hasNextPage();
1190
+ yield page.records;
1191
+ while (more) {
1192
+ page = await page.nextPage();
1193
+ more = page.hasNextPage();
1194
+ yield page.records;
1195
+ }
1196
+ }
1197
+ async getMany(options = {}) {
1198
+ const page = await this.getPaginated(options);
1199
+ if (page.hasNextPage() && options.pagination?.size === void 0) {
1200
+ console.trace("Calling getMany does not return all results. Paginate to get all results or call getAll.");
1201
+ }
1202
+ return page.records;
1203
+ }
1204
+ async getAll(options = {}) {
1205
+ const { batchSize = PAGINATION_MAX_SIZE, ...rest } = options;
1206
+ const results = [];
1207
+ for await (const page of this.getIterator({ ...rest, batchSize })) {
1208
+ results.push(...page);
1209
+ }
1210
+ return results;
1211
+ }
1212
+ async getFirst(options = {}) {
1213
+ const records = await this.getMany({ ...options, pagination: { size: 1 } });
1214
+ return records[0] ?? null;
1215
+ }
1216
+ cache(ttl) {
1217
+ return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { cache: ttl }, __privateGet$5(this, _data));
1218
+ }
1219
+ nextPage(size, offset) {
1220
+ return this.firstPage(size, offset);
1221
+ }
1222
+ previousPage(size, offset) {
1223
+ return this.firstPage(size, offset);
1224
+ }
1225
+ firstPage(size, offset) {
1226
+ return this.getPaginated({ pagination: { size, offset } });
1227
+ }
1228
+ lastPage(size, offset) {
1229
+ return this.getPaginated({ pagination: { size, offset, before: "end" } });
1230
+ }
1231
+ hasNextPage() {
1232
+ return this.meta.page.more;
1233
+ }
1234
+ };
1235
+ let Query = _Query;
1236
+ _table$1 = new WeakMap();
1237
+ _repository = new WeakMap();
1238
+ _data = new WeakMap();
1239
+ function cleanParent(data, parent) {
1240
+ if (isCursorPaginationOptions(data.pagination)) {
1241
+ return { ...parent, sorting: void 0, filter: void 0 };
1242
+ }
1243
+ return parent;
1244
+ }
1245
+
1246
+ function isIdentifiable(x) {
1247
+ return isObject(x) && isString(x?.id);
1248
+ }
1249
+ function isXataRecord(x) {
1250
+ const record = x;
1251
+ const metadata = record?.getMetadata();
1252
+ return isIdentifiable(x) && isObject(metadata) && typeof metadata.version === "number";
1253
+ }
1254
+
1255
+ function isSortFilterString(value) {
1256
+ return isString(value);
1257
+ }
1258
+ function isSortFilterBase(filter) {
1259
+ return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
1260
+ }
1261
+ function isSortFilterObject(filter) {
1262
+ return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
1263
+ }
1264
+ function buildSortFilter(filter) {
1265
+ if (isSortFilterString(filter)) {
1266
+ return { [filter]: "asc" };
1267
+ } else if (Array.isArray(filter)) {
1268
+ return filter.map((item) => buildSortFilter(item));
1269
+ } else if (isSortFilterBase(filter)) {
1270
+ return filter;
1271
+ } else if (isSortFilterObject(filter)) {
1272
+ return { [filter.column]: filter.direction ?? "asc" };
1273
+ } else {
1274
+ throw new Error(`Invalid sort filter: ${filter}`);
1275
+ }
1276
+ }
1277
+
1278
+ var __accessCheck$4 = (obj, member, msg) => {
1279
+ if (!member.has(obj))
1280
+ throw TypeError("Cannot " + msg);
1281
+ };
1282
+ var __privateGet$4 = (obj, member, getter) => {
1283
+ __accessCheck$4(obj, member, "read from private field");
1284
+ return getter ? getter.call(obj) : member.get(obj);
1285
+ };
1286
+ var __privateAdd$4 = (obj, member, value) => {
1287
+ if (member.has(obj))
1288
+ throw TypeError("Cannot add the same private member more than once");
1289
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1290
+ };
1291
+ var __privateSet$4 = (obj, member, value, setter) => {
1292
+ __accessCheck$4(obj, member, "write to private field");
1293
+ setter ? setter.call(obj, value) : member.set(obj, value);
1294
+ return value;
1295
+ };
1296
+ var __privateMethod$2 = (obj, member, method) => {
1297
+ __accessCheck$4(obj, member, "access private method");
1298
+ return method;
1299
+ };
1300
+ var _table, _getFetchProps, _cache, _schemaTables$2, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
1301
+ class Repository extends Query {
1302
+ }
1303
+ class RestRepository extends Query {
1304
+ constructor(options) {
1305
+ super(null, options.table, {});
1306
+ __privateAdd$4(this, _insertRecordWithoutId);
1307
+ __privateAdd$4(this, _insertRecordWithId);
1308
+ __privateAdd$4(this, _bulkInsertTableRecords);
1309
+ __privateAdd$4(this, _updateRecordWithID);
1310
+ __privateAdd$4(this, _upsertRecordWithID);
1311
+ __privateAdd$4(this, _deleteRecord);
1312
+ __privateAdd$4(this, _invalidateCache);
1313
+ __privateAdd$4(this, _setCacheRecord);
1314
+ __privateAdd$4(this, _getCacheRecord);
1315
+ __privateAdd$4(this, _setCacheQuery);
1316
+ __privateAdd$4(this, _getCacheQuery);
1317
+ __privateAdd$4(this, _getSchemaTables$1);
1318
+ __privateAdd$4(this, _table, void 0);
1319
+ __privateAdd$4(this, _getFetchProps, void 0);
1320
+ __privateAdd$4(this, _cache, void 0);
1321
+ __privateAdd$4(this, _schemaTables$2, void 0);
1322
+ __privateSet$4(this, _table, options.table);
1323
+ __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1324
+ this.db = options.db;
1325
+ __privateSet$4(this, _cache, options.pluginOptions.cache);
1326
+ __privateSet$4(this, _schemaTables$2, options.schemaTables);
1327
+ }
1328
+ async create(a, b) {
1329
+ if (Array.isArray(a)) {
1330
+ if (a.length === 0)
1331
+ return [];
1332
+ const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1333
+ await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1334
+ return records;
1335
+ }
1336
+ if (isString(a) && isObject(b)) {
1337
+ if (a === "")
1338
+ throw new Error("The id can't be empty");
1339
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1340
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1341
+ return record;
1342
+ }
1343
+ if (isObject(a) && isString(a.id)) {
1344
+ if (a.id === "")
1345
+ throw new Error("The id can't be empty");
1346
+ const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1347
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1348
+ return record;
1349
+ }
1350
+ if (isObject(a)) {
1351
+ const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1352
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1353
+ return record;
1354
+ }
1355
+ throw new Error("Invalid arguments for create method");
1356
+ }
1357
+ async read(a) {
1358
+ if (Array.isArray(a)) {
1359
+ if (a.length === 0)
1360
+ return [];
1361
+ const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1362
+ return this.getAll({ filter: { id: { $any: ids } } });
1363
+ }
1364
+ const id = isString(a) ? a : a.id;
1365
+ if (isString(id)) {
1366
+ const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
1367
+ if (cacheRecord)
1368
+ return cacheRecord;
1369
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1370
+ try {
1371
+ const response = await getRecord({
1372
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1373
+ ...fetchProps
1374
+ });
1375
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1376
+ return initObject(this.db, schemaTables, __privateGet$4(this, _table), response);
1377
+ } catch (e) {
1378
+ if (isObject(e) && e.status === 404) {
1379
+ return null;
1380
+ }
1381
+ throw e;
1382
+ }
1383
+ }
1384
+ }
1385
+ async update(a, b) {
1386
+ if (Array.isArray(a)) {
1387
+ if (a.length === 0)
1388
+ return [];
1389
+ if (a.length > 100) {
1390
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1391
+ }
1392
+ return Promise.all(a.map((object) => this.update(object)));
1393
+ }
1394
+ if (isString(a) && isObject(b)) {
1395
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1396
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1397
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1398
+ return record;
1399
+ }
1400
+ if (isObject(a) && isString(a.id)) {
1401
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1402
+ const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1403
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1404
+ return record;
1405
+ }
1406
+ throw new Error("Invalid arguments for update method");
1407
+ }
1408
+ async createOrUpdate(a, b) {
1409
+ if (Array.isArray(a)) {
1410
+ if (a.length === 0)
1411
+ return [];
1412
+ if (a.length > 100) {
1413
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1414
+ }
1415
+ return Promise.all(a.map((object) => this.createOrUpdate(object)));
1416
+ }
1417
+ if (isString(a) && isObject(b)) {
1418
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1419
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1420
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1421
+ return record;
1422
+ }
1423
+ if (isObject(a) && isString(a.id)) {
1424
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1425
+ const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1426
+ await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1427
+ return record;
1428
+ }
1429
+ throw new Error("Invalid arguments for createOrUpdate method");
1430
+ }
1431
+ async delete(a) {
1432
+ if (Array.isArray(a)) {
1433
+ if (a.length === 0)
1434
+ return;
1435
+ if (a.length > 100) {
1436
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1437
+ }
1438
+ await Promise.all(a.map((id) => this.delete(id)));
1439
+ return;
1440
+ }
1441
+ if (isString(a)) {
1442
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1443
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1444
+ return;
1445
+ }
1446
+ if (isObject(a) && isString(a.id)) {
1447
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1448
+ await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1449
+ return;
1450
+ }
1451
+ throw new Error("Invalid arguments for delete method");
1452
+ }
1453
+ async search(query, options = {}) {
1454
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1455
+ const { records } = await searchTable({
1456
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1457
+ body: {
1458
+ query,
1459
+ fuzziness: options.fuzziness,
1460
+ highlight: options.highlight,
1461
+ filter: options.filter
1462
+ },
1463
+ ...fetchProps
1464
+ });
1465
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1466
+ return records.map((item) => initObject(this.db, schemaTables, __privateGet$4(this, _table), item));
1467
+ }
1468
+ async query(query) {
1469
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1470
+ if (cacheQuery)
1471
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1472
+ const data = query.getQueryOptions();
1473
+ const body = {
1474
+ filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1475
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1476
+ page: data.pagination,
1477
+ columns: data.columns
1478
+ };
1479
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1480
+ const { meta, records: objects } = await queryTable({
1481
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1482
+ body,
1483
+ ...fetchProps
1484
+ });
1485
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1486
+ const records = objects.map((record) => initObject(this.db, schemaTables, __privateGet$4(this, _table), record));
1487
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1488
+ return new Page(query, meta, records);
1489
+ }
1490
+ }
1491
+ _table = new WeakMap();
1492
+ _getFetchProps = new WeakMap();
1493
+ _cache = new WeakMap();
1494
+ _schemaTables$2 = new WeakMap();
1495
+ _insertRecordWithoutId = new WeakSet();
1496
+ insertRecordWithoutId_fn = async function(object) {
1497
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1498
+ const record = transformObjectLinks(object);
1499
+ const response = await insertRecord({
1500
+ pathParams: {
1501
+ workspace: "{workspaceId}",
1502
+ dbBranchName: "{dbBranch}",
1503
+ tableName: __privateGet$4(this, _table)
1504
+ },
1505
+ body: record,
1506
+ ...fetchProps
1507
+ });
1508
+ const finalObject = await this.read(response.id);
1509
+ if (!finalObject) {
1510
+ throw new Error("The server failed to save the record");
1511
+ }
1512
+ return finalObject;
1513
+ };
1514
+ _insertRecordWithId = new WeakSet();
1515
+ insertRecordWithId_fn = async function(recordId, object) {
1516
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1517
+ const record = transformObjectLinks(object);
1518
+ const response = await insertRecordWithID({
1519
+ pathParams: {
1520
+ workspace: "{workspaceId}",
1521
+ dbBranchName: "{dbBranch}",
1522
+ tableName: __privateGet$4(this, _table),
1523
+ recordId
1524
+ },
1525
+ body: record,
1526
+ queryParams: { createOnly: true },
1527
+ ...fetchProps
1528
+ });
1529
+ const finalObject = await this.read(response.id);
1530
+ if (!finalObject) {
1531
+ throw new Error("The server failed to save the record");
1532
+ }
1533
+ return finalObject;
1534
+ };
1535
+ _bulkInsertTableRecords = new WeakSet();
1536
+ bulkInsertTableRecords_fn = async function(objects) {
1537
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1538
+ const records = objects.map((object) => transformObjectLinks(object));
1539
+ const { recordIDs } = await bulkInsertTableRecords({
1540
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1541
+ body: { records },
1542
+ ...fetchProps
1543
+ });
1544
+ const finalObjects = await this.read(recordIDs);
1545
+ if (finalObjects.length !== objects.length) {
1546
+ throw new Error("The server failed to save some records");
1547
+ }
1548
+ const dictionary = finalObjects.reduce((acc, object) => {
1549
+ acc[object.id] = object;
1550
+ return acc;
1551
+ }, {});
1552
+ return recordIDs.map((id) => dictionary[id]);
1553
+ };
1554
+ _updateRecordWithID = new WeakSet();
1555
+ updateRecordWithID_fn = async function(recordId, object) {
1556
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1557
+ const record = transformObjectLinks(object);
1558
+ const response = await updateRecordWithID({
1559
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1560
+ body: record,
1561
+ ...fetchProps
1562
+ });
1563
+ const item = await this.read(response.id);
1564
+ if (!item)
1565
+ throw new Error("The server failed to save the record");
1566
+ return item;
1567
+ };
1568
+ _upsertRecordWithID = new WeakSet();
1569
+ upsertRecordWithID_fn = async function(recordId, object) {
1570
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1571
+ const response = await upsertRecordWithID({
1572
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1573
+ body: object,
1574
+ ...fetchProps
1575
+ });
1576
+ const item = await this.read(response.id);
1577
+ if (!item)
1578
+ throw new Error("The server failed to save the record");
1579
+ return item;
1580
+ };
1581
+ _deleteRecord = new WeakSet();
1582
+ deleteRecord_fn = async function(recordId) {
1583
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1584
+ await deleteRecord({
1585
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1586
+ ...fetchProps
1587
+ });
1588
+ };
1589
+ _invalidateCache = new WeakSet();
1590
+ invalidateCache_fn = async function(recordId) {
1591
+ await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1592
+ const cacheItems = await __privateGet$4(this, _cache).getAll();
1593
+ const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1594
+ for (const [key, value] of queries) {
1595
+ const ids = getIds(value);
1596
+ if (ids.includes(recordId))
1597
+ await __privateGet$4(this, _cache).delete(key);
1598
+ }
1599
+ };
1600
+ _setCacheRecord = new WeakSet();
1601
+ setCacheRecord_fn = async function(record) {
1602
+ if (!__privateGet$4(this, _cache).cacheRecords)
1603
+ return;
1604
+ await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1605
+ };
1606
+ _getCacheRecord = new WeakSet();
1607
+ getCacheRecord_fn = async function(recordId) {
1608
+ if (!__privateGet$4(this, _cache).cacheRecords)
1609
+ return null;
1610
+ return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1611
+ };
1612
+ _setCacheQuery = new WeakSet();
1613
+ setCacheQuery_fn = async function(query, meta, records) {
1614
+ await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
1615
+ };
1616
+ _getCacheQuery = new WeakSet();
1617
+ getCacheQuery_fn = async function(query) {
1618
+ const key = `query_${__privateGet$4(this, _table)}:${query.key()}`;
1619
+ const result = await __privateGet$4(this, _cache).get(key);
1620
+ if (!result)
1621
+ return null;
1622
+ const { cache: ttl = __privateGet$4(this, _cache).defaultQueryTTL } = query.getQueryOptions();
1623
+ if (ttl < 0)
1624
+ return null;
1625
+ const hasExpired = result.date.getTime() + ttl < Date.now();
1626
+ return hasExpired ? null : result;
1627
+ };
1628
+ _getSchemaTables$1 = new WeakSet();
1629
+ getSchemaTables_fn$1 = async function() {
1630
+ if (__privateGet$4(this, _schemaTables$2))
1631
+ return __privateGet$4(this, _schemaTables$2);
1632
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1633
+ const { schema } = await getBranchDetails({
1634
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1635
+ ...fetchProps
1636
+ });
1637
+ __privateSet$4(this, _schemaTables$2, schema.tables);
1638
+ return schema.tables;
1639
+ };
1640
+ const transformObjectLinks = (object) => {
1641
+ return Object.entries(object).reduce((acc, [key, value]) => {
1642
+ if (key === "xata")
1643
+ return acc;
1644
+ return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1645
+ }, {});
1646
+ };
1647
+ const initObject = (db, schemaTables, table, object) => {
1648
+ const result = {};
1649
+ const { xata, ...rest } = object ?? {};
1650
+ Object.assign(result, rest);
1651
+ const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
1652
+ if (!columns)
1653
+ console.error(`Table ${table} not found in schema`);
1654
+ for (const column of columns ?? []) {
1655
+ const value = result[column.name];
1656
+ switch (column.type) {
1657
+ case "datetime": {
1658
+ const date = value !== void 0 ? new Date(value) : void 0;
1659
+ if (date && isNaN(date.getTime())) {
1660
+ console.error(`Failed to parse date ${value} for field ${column.name}`);
1661
+ } else if (date) {
1662
+ result[column.name] = date;
1663
+ }
1664
+ break;
1665
+ }
1666
+ case "link": {
1667
+ const linkTable = column.link?.table;
1668
+ if (!linkTable) {
1669
+ console.error(`Failed to parse link for field ${column.name}`);
1670
+ } else if (isObject(value)) {
1671
+ result[column.name] = initObject(db, schemaTables, linkTable, value);
1672
+ }
1673
+ break;
1674
+ }
1675
+ }
1676
+ }
1677
+ result.read = function() {
1678
+ return db[table].read(result["id"]);
1679
+ };
1680
+ result.update = function(data) {
1681
+ return db[table].update(result["id"], data);
1682
+ };
1683
+ result.delete = function() {
1684
+ return db[table].delete(result["id"]);
1685
+ };
1686
+ result.getMetadata = function() {
1687
+ return xata;
1688
+ };
1689
+ for (const prop of ["read", "update", "delete", "getMetadata"]) {
1690
+ Object.defineProperty(result, prop, { enumerable: false });
1691
+ }
1692
+ Object.freeze(result);
1693
+ return result;
1694
+ };
1695
+ function getIds(value) {
1696
+ if (Array.isArray(value)) {
1697
+ return value.map((item) => getIds(item)).flat();
1698
+ }
1699
+ if (!isObject(value))
1700
+ return [];
1701
+ const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1702
+ return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1703
+ }
1704
+
1705
+ var __accessCheck$3 = (obj, member, msg) => {
1706
+ if (!member.has(obj))
1707
+ throw TypeError("Cannot " + msg);
1708
+ };
1709
+ var __privateGet$3 = (obj, member, getter) => {
1710
+ __accessCheck$3(obj, member, "read from private field");
1711
+ return getter ? getter.call(obj) : member.get(obj);
1712
+ };
1713
+ var __privateAdd$3 = (obj, member, value) => {
1714
+ if (member.has(obj))
1715
+ throw TypeError("Cannot add the same private member more than once");
1716
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1717
+ };
1718
+ var __privateSet$3 = (obj, member, value, setter) => {
1719
+ __accessCheck$3(obj, member, "write to private field");
1720
+ setter ? setter.call(obj, value) : member.set(obj, value);
1721
+ return value;
1722
+ };
1723
+ var _map;
1724
+ class SimpleCache {
1725
+ constructor(options = {}) {
1726
+ __privateAdd$3(this, _map, void 0);
1727
+ __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1728
+ this.capacity = options.max ?? 500;
1729
+ this.cacheRecords = options.cacheRecords ?? true;
1730
+ this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1731
+ }
1732
+ async getAll() {
1733
+ return Object.fromEntries(__privateGet$3(this, _map));
1734
+ }
1735
+ async get(key) {
1736
+ return __privateGet$3(this, _map).get(key) ?? null;
1737
+ }
1738
+ async set(key, value) {
1739
+ await this.delete(key);
1740
+ __privateGet$3(this, _map).set(key, value);
1741
+ if (__privateGet$3(this, _map).size > this.capacity) {
1742
+ const leastRecentlyUsed = __privateGet$3(this, _map).keys().next().value;
1743
+ await this.delete(leastRecentlyUsed);
1744
+ }
1745
+ }
1746
+ async delete(key) {
1747
+ __privateGet$3(this, _map).delete(key);
1748
+ }
1749
+ async clear() {
1750
+ return __privateGet$3(this, _map).clear();
1751
+ }
1752
+ }
1753
+ _map = new WeakMap();
1754
+
1755
+ const gt = (value) => ({ $gt: value });
1756
+ const ge = (value) => ({ $ge: value });
1757
+ const gte = (value) => ({ $ge: value });
1758
+ const lt = (value) => ({ $lt: value });
1759
+ const lte = (value) => ({ $le: value });
1760
+ const le = (value) => ({ $le: value });
1761
+ const exists = (column) => ({ $exists: column });
1762
+ const notExists = (column) => ({ $notExists: column });
1763
+ const startsWith = (value) => ({ $startsWith: value });
1764
+ const endsWith = (value) => ({ $endsWith: value });
1765
+ const pattern = (value) => ({ $pattern: value });
1766
+ const is = (value) => ({ $is: value });
1767
+ const isNot = (value) => ({ $isNot: value });
1768
+ const contains = (value) => ({ $contains: value });
1769
+ const includes = (value) => ({ $includes: value });
1770
+ const includesAll = (value) => ({ $includesAll: value });
1771
+ const includesNone = (value) => ({ $includesNone: value });
1772
+ const includesAny = (value) => ({ $includesAny: value });
1773
+
1774
+ var __accessCheck$2 = (obj, member, msg) => {
1775
+ if (!member.has(obj))
1776
+ throw TypeError("Cannot " + msg);
1777
+ };
1778
+ var __privateGet$2 = (obj, member, getter) => {
1779
+ __accessCheck$2(obj, member, "read from private field");
1780
+ return getter ? getter.call(obj) : member.get(obj);
1781
+ };
1782
+ var __privateAdd$2 = (obj, member, value) => {
1783
+ if (member.has(obj))
1784
+ throw TypeError("Cannot add the same private member more than once");
1785
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1786
+ };
1787
+ var __privateSet$2 = (obj, member, value, setter) => {
1788
+ __accessCheck$2(obj, member, "write to private field");
1789
+ setter ? setter.call(obj, value) : member.set(obj, value);
1790
+ return value;
1791
+ };
1792
+ var _tables, _schemaTables$1;
1793
+ class SchemaPlugin extends XataPlugin {
1794
+ constructor(schemaTables) {
1795
+ super();
1796
+ __privateAdd$2(this, _tables, {});
1797
+ __privateAdd$2(this, _schemaTables$1, void 0);
1798
+ __privateSet$2(this, _schemaTables$1, schemaTables);
1799
+ }
1800
+ build(pluginOptions) {
1801
+ const db = new Proxy({}, {
1802
+ get: (_target, table) => {
1803
+ if (!isString(table))
1804
+ throw new Error("Invalid table name");
1805
+ if (__privateGet$2(this, _tables)[table] === void 0) {
1806
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
1807
+ }
1808
+ return __privateGet$2(this, _tables)[table];
1809
+ }
1810
+ });
1811
+ const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
1812
+ for (const table of tableNames) {
1813
+ db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1814
+ }
1815
+ return db;
1816
+ }
1817
+ }
1818
+ _tables = new WeakMap();
1819
+ _schemaTables$1 = new WeakMap();
1820
+
1821
+ var __accessCheck$1 = (obj, member, msg) => {
1822
+ if (!member.has(obj))
1823
+ throw TypeError("Cannot " + msg);
1824
+ };
1825
+ var __privateGet$1 = (obj, member, getter) => {
1826
+ __accessCheck$1(obj, member, "read from private field");
1827
+ return getter ? getter.call(obj) : member.get(obj);
1828
+ };
1829
+ var __privateAdd$1 = (obj, member, value) => {
1830
+ if (member.has(obj))
1831
+ throw TypeError("Cannot add the same private member more than once");
1832
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1833
+ };
1834
+ var __privateSet$1 = (obj, member, value, setter) => {
1835
+ __accessCheck$1(obj, member, "write to private field");
1836
+ setter ? setter.call(obj, value) : member.set(obj, value);
1837
+ return value;
1838
+ };
1839
+ var __privateMethod$1 = (obj, member, method) => {
1840
+ __accessCheck$1(obj, member, "access private method");
1841
+ return method;
1842
+ };
1843
+ var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
1844
+ class SearchPlugin extends XataPlugin {
1845
+ constructor(db, schemaTables) {
1846
+ super();
1847
+ this.db = db;
1848
+ __privateAdd$1(this, _search);
1849
+ __privateAdd$1(this, _getSchemaTables);
1850
+ __privateAdd$1(this, _schemaTables, void 0);
1851
+ __privateSet$1(this, _schemaTables, schemaTables);
1852
+ }
1853
+ build({ getFetchProps }) {
1854
+ return {
1855
+ all: async (query, options = {}) => {
1856
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1857
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1858
+ return records.map((record) => {
1859
+ const { table = "orphan" } = record.xata;
1860
+ return { table, record: initObject(this.db, schemaTables, table, record) };
1861
+ });
1862
+ },
1863
+ byTable: async (query, options = {}) => {
1864
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1865
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1866
+ return records.reduce((acc, record) => {
1867
+ const { table = "orphan" } = record.xata;
1868
+ const items = acc[table] ?? [];
1869
+ const item = initObject(this.db, schemaTables, table, record);
1870
+ return { ...acc, [table]: [...items, item] };
1871
+ }, {});
1872
+ }
1873
+ };
1874
+ }
1875
+ }
1876
+ _schemaTables = new WeakMap();
1877
+ _search = new WeakSet();
1878
+ search_fn = async function(query, options, getFetchProps) {
1879
+ const fetchProps = await getFetchProps();
1880
+ const { tables, fuzziness, highlight } = options ?? {};
1881
+ const { records } = await searchBranch({
1882
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1883
+ body: { tables, query, fuzziness, highlight },
1884
+ ...fetchProps
1885
+ });
1886
+ return records;
1887
+ };
1888
+ _getSchemaTables = new WeakSet();
1889
+ getSchemaTables_fn = async function(getFetchProps) {
1890
+ if (__privateGet$1(this, _schemaTables))
1891
+ return __privateGet$1(this, _schemaTables);
1892
+ const fetchProps = await getFetchProps();
1893
+ const { schema } = await getBranchDetails({
1894
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1895
+ ...fetchProps
1896
+ });
1897
+ __privateSet$1(this, _schemaTables, schema.tables);
1898
+ return schema.tables;
1899
+ };
1900
+
1901
+ const isBranchStrategyBuilder = (strategy) => {
1902
+ return typeof strategy === "function";
1903
+ };
1904
+
1905
+ async function getCurrentBranchName(options) {
1906
+ const { branch, envBranch } = getEnvironment();
1907
+ if (branch) {
1908
+ const details = await getDatabaseBranch(branch, options);
1909
+ if (details)
1910
+ return branch;
1911
+ console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
1912
+ }
1913
+ const gitBranch = envBranch || await getGitBranch();
1914
+ return resolveXataBranch(gitBranch, options);
1915
+ }
1916
+ async function getCurrentBranchDetails(options) {
1917
+ const branch = await getCurrentBranchName(options);
1918
+ return getDatabaseBranch(branch, options);
1919
+ }
1920
+ async function resolveXataBranch(gitBranch, options) {
1921
+ const databaseURL = options?.databaseURL || getDatabaseURL();
1922
+ const apiKey = options?.apiKey || getAPIKey();
1923
+ if (!databaseURL)
1924
+ throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1925
+ if (!apiKey)
1926
+ throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1927
+ const [protocol, , host, , dbName] = databaseURL.split("/");
1928
+ const [workspace] = host.split(".");
1929
+ const { fallbackBranch } = getEnvironment();
1930
+ const { branch } = await resolveBranch({
1931
+ apiKey,
1932
+ apiUrl: databaseURL,
1933
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
1934
+ workspacesApiUrl: `${protocol}//${host}`,
1935
+ pathParams: { dbName, workspace },
1936
+ queryParams: { gitBranch, fallbackBranch }
1937
+ });
1938
+ return branch;
1939
+ }
1940
+ async function getDatabaseBranch(branch, options) {
1941
+ const databaseURL = options?.databaseURL || getDatabaseURL();
1942
+ const apiKey = options?.apiKey || getAPIKey();
1943
+ if (!databaseURL)
1944
+ throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1945
+ if (!apiKey)
1946
+ throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1947
+ const [protocol, , host, , database] = databaseURL.split("/");
1948
+ const [workspace] = host.split(".");
1949
+ const dbBranchName = `${database}:${branch}`;
1950
+ try {
1951
+ return await getBranchDetails({
1952
+ apiKey,
1953
+ apiUrl: databaseURL,
1954
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
1955
+ workspacesApiUrl: `${protocol}//${host}`,
1956
+ pathParams: { dbBranchName, workspace }
1957
+ });
1958
+ } catch (err) {
1959
+ if (isObject(err) && err.status === 404)
1960
+ return null;
1961
+ throw err;
1962
+ }
1963
+ }
1964
+ function getDatabaseURL() {
1965
+ try {
1966
+ const { databaseURL } = getEnvironment();
1967
+ return databaseURL;
1968
+ } catch (err) {
1969
+ return void 0;
1970
+ }
1971
+ }
1972
+
1973
+ var __accessCheck = (obj, member, msg) => {
1974
+ if (!member.has(obj))
1975
+ throw TypeError("Cannot " + msg);
1976
+ };
1977
+ var __privateGet = (obj, member, getter) => {
1978
+ __accessCheck(obj, member, "read from private field");
1979
+ return getter ? getter.call(obj) : member.get(obj);
1980
+ };
1981
+ var __privateAdd = (obj, member, value) => {
1982
+ if (member.has(obj))
1983
+ throw TypeError("Cannot add the same private member more than once");
1984
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1985
+ };
1986
+ var __privateSet = (obj, member, value, setter) => {
1987
+ __accessCheck(obj, member, "write to private field");
1988
+ setter ? setter.call(obj, value) : member.set(obj, value);
1989
+ return value;
1990
+ };
1991
+ var __privateMethod = (obj, member, method) => {
1992
+ __accessCheck(obj, member, "access private method");
1993
+ return method;
1994
+ };
1995
+ const buildClient = (plugins) => {
1996
+ var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1997
+ return _a = class {
1998
+ constructor(options = {}, schemaTables) {
1999
+ __privateAdd(this, _parseOptions);
2000
+ __privateAdd(this, _getFetchProps);
2001
+ __privateAdd(this, _evaluateBranch);
2002
+ __privateAdd(this, _branch, void 0);
2003
+ const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
2004
+ const pluginOptions = {
2005
+ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
2006
+ cache: safeOptions.cache
2007
+ };
2008
+ const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2009
+ const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
2010
+ this.db = db;
2011
+ this.search = search;
2012
+ for (const [key, namespace] of Object.entries(plugins ?? {})) {
2013
+ if (namespace === void 0)
2014
+ continue;
2015
+ const result = namespace.build(pluginOptions);
2016
+ if (result instanceof Promise) {
2017
+ void result.then((namespace2) => {
2018
+ this[key] = namespace2;
2019
+ });
2020
+ } else {
2021
+ this[key] = result;
2022
+ }
2023
+ }
2024
+ }
2025
+ }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2026
+ const fetch = getFetchImplementation(options?.fetch);
2027
+ const databaseURL = options?.databaseURL || getDatabaseURL();
2028
+ const apiKey = options?.apiKey || getAPIKey();
2029
+ const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
2030
+ const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
2031
+ if (!databaseURL || !apiKey) {
2032
+ throw new Error("Options databaseURL and apiKey are required");
2033
+ }
2034
+ return { fetch, databaseURL, apiKey, branch, cache };
2035
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
2036
+ fetch,
2037
+ apiKey,
2038
+ databaseURL,
2039
+ branch
2040
+ }) {
2041
+ const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
2042
+ if (!branchValue)
2043
+ throw new Error("Unable to resolve branch value");
2044
+ return {
2045
+ fetchImpl: fetch,
2046
+ apiKey,
2047
+ apiUrl: "",
2048
+ workspacesApiUrl: (path, params) => {
2049
+ const hasBranch = params.dbBranchName ?? params.branch;
2050
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2051
+ return databaseURL + newPath;
2052
+ }
2053
+ };
2054
+ }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2055
+ if (__privateGet(this, _branch))
2056
+ return __privateGet(this, _branch);
2057
+ if (param === void 0)
2058
+ return void 0;
2059
+ const strategies = Array.isArray(param) ? [...param] : [param];
2060
+ const evaluateBranch = async (strategy) => {
2061
+ return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
2062
+ };
2063
+ for await (const strategy of strategies) {
2064
+ const branch = await evaluateBranch(strategy);
2065
+ if (branch) {
2066
+ __privateSet(this, _branch, branch);
2067
+ return branch;
2068
+ }
2069
+ }
2070
+ }, _a;
2071
+ };
2072
+ class BaseClient extends buildClient() {
2073
+ }
2074
+
2075
+ class XataError extends Error {
2076
+ constructor(message, status) {
2077
+ super(message);
2078
+ this.status = status;
2079
+ }
2080
+ }
2081
+
2082
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
2083
+ //# sourceMappingURL=index.mjs.map