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