@xata.io/client 0.8.1 → 0.8.4

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 (68) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/index.cjs +1744 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +3246 -7
  5. package/dist/index.mjs +1649 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +9 -5
  8. package/rollup.config.js +29 -0
  9. package/tsconfig.json +5 -4
  10. package/dist/api/client.d.ts +0 -95
  11. package/dist/api/client.js +0 -251
  12. package/dist/api/components.d.ts +0 -1437
  13. package/dist/api/components.js +0 -998
  14. package/dist/api/fetcher.d.ts +0 -40
  15. package/dist/api/fetcher.js +0 -79
  16. package/dist/api/index.d.ts +0 -13
  17. package/dist/api/index.js +0 -40
  18. package/dist/api/parameters.d.ts +0 -16
  19. package/dist/api/parameters.js +0 -2
  20. package/dist/api/providers.d.ts +0 -8
  21. package/dist/api/providers.js +0 -30
  22. package/dist/api/responses.d.ts +0 -50
  23. package/dist/api/responses.js +0 -2
  24. package/dist/api/schemas.d.ts +0 -311
  25. package/dist/api/schemas.js +0 -2
  26. package/dist/client.d.ts +0 -27
  27. package/dist/client.js +0 -131
  28. package/dist/index.js +0 -30
  29. package/dist/plugins.d.ts +0 -7
  30. package/dist/plugins.js +0 -6
  31. package/dist/schema/filters.d.ts +0 -96
  32. package/dist/schema/filters.js +0 -2
  33. package/dist/schema/filters.spec.d.ts +0 -1
  34. package/dist/schema/filters.spec.js +0 -177
  35. package/dist/schema/index.d.ts +0 -23
  36. package/dist/schema/index.js +0 -50
  37. package/dist/schema/operators.d.ts +0 -74
  38. package/dist/schema/operators.js +0 -93
  39. package/dist/schema/pagination.d.ts +0 -83
  40. package/dist/schema/pagination.js +0 -93
  41. package/dist/schema/query.d.ts +0 -118
  42. package/dist/schema/query.js +0 -242
  43. package/dist/schema/record.d.ts +0 -66
  44. package/dist/schema/record.js +0 -13
  45. package/dist/schema/repository.d.ts +0 -135
  46. package/dist/schema/repository.js +0 -283
  47. package/dist/schema/selection.d.ts +0 -25
  48. package/dist/schema/selection.js +0 -2
  49. package/dist/schema/selection.spec.d.ts +0 -1
  50. package/dist/schema/selection.spec.js +0 -204
  51. package/dist/schema/sorting.d.ts +0 -22
  52. package/dist/schema/sorting.js +0 -35
  53. package/dist/schema/sorting.spec.d.ts +0 -1
  54. package/dist/schema/sorting.spec.js +0 -11
  55. package/dist/search/index.d.ts +0 -34
  56. package/dist/search/index.js +0 -55
  57. package/dist/util/branches.d.ts +0 -5
  58. package/dist/util/branches.js +0 -7
  59. package/dist/util/config.d.ts +0 -11
  60. package/dist/util/config.js +0 -121
  61. package/dist/util/environment.d.ts +0 -5
  62. package/dist/util/environment.js +0 -68
  63. package/dist/util/fetch.d.ts +0 -2
  64. package/dist/util/fetch.js +0 -13
  65. package/dist/util/lang.d.ts +0 -5
  66. package/dist/util/lang.js +0 -22
  67. package/dist/util/types.d.ts +0 -25
  68. package/dist/util/types.js +0 -2
package/dist/index.mjs ADDED
@@ -0,0 +1,1649 @@
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 isString(value) {
11
+ return value !== void 0 && value !== null && typeof value === "string";
12
+ }
13
+
14
+ function getEnvVariable(name) {
15
+ try {
16
+ if (isObject(process) && isString(process?.env?.[name])) {
17
+ return process.env[name];
18
+ }
19
+ } catch (err) {
20
+ }
21
+ try {
22
+ if (isObject(Deno) && isString(Deno?.env?.get(name))) {
23
+ return Deno.env.get(name);
24
+ }
25
+ } catch (err) {
26
+ }
27
+ }
28
+ async function getGitBranch() {
29
+ try {
30
+ return require("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
31
+ } catch (err) {
32
+ }
33
+ try {
34
+ if (isObject(Deno)) {
35
+ const process2 = Deno.run({
36
+ cmd: ["git", "branch", "--show-current"],
37
+ stdout: "piped",
38
+ stderr: "piped"
39
+ });
40
+ return new TextDecoder().decode(await process2.output()).trim();
41
+ }
42
+ } catch (err) {
43
+ }
44
+ }
45
+
46
+ function getAPIKey() {
47
+ try {
48
+ return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
49
+ } catch (err) {
50
+ return void 0;
51
+ }
52
+ }
53
+
54
+ function getFetchImplementation(userFetch) {
55
+ const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
56
+ const fetchImpl = userFetch ?? globalFetch;
57
+ if (!fetchImpl) {
58
+ throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
59
+ }
60
+ return fetchImpl;
61
+ }
62
+
63
+ class FetcherError extends Error {
64
+ constructor(status, data) {
65
+ super(getMessage(data));
66
+ this.status = status;
67
+ this.errors = isBulkError(data) ? data.errors : void 0;
68
+ if (data instanceof Error) {
69
+ this.stack = data.stack;
70
+ this.cause = data.cause;
71
+ }
72
+ }
73
+ }
74
+ function isBulkError(error) {
75
+ return isObject(error) && Array.isArray(error.errors);
76
+ }
77
+ function isErrorWithMessage(error) {
78
+ return isObject(error) && isString(error.message);
79
+ }
80
+ function getMessage(data) {
81
+ if (data instanceof Error) {
82
+ return data.message;
83
+ } else if (isString(data)) {
84
+ return data;
85
+ } else if (isErrorWithMessage(data)) {
86
+ return data.message;
87
+ } else if (isBulkError(data)) {
88
+ return "Bulk operation failed";
89
+ } else {
90
+ return "Unexpected error";
91
+ }
92
+ }
93
+
94
+ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
95
+ const query = new URLSearchParams(queryParams).toString();
96
+ const queryString = query.length > 0 ? `?${query}` : "";
97
+ return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
98
+ };
99
+ function buildBaseUrl({
100
+ path,
101
+ workspacesApiUrl,
102
+ apiUrl,
103
+ pathParams
104
+ }) {
105
+ if (!pathParams?.workspace)
106
+ return `${apiUrl}${path}`;
107
+ const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
108
+ return url.replace("{workspaceId}", pathParams.workspace);
109
+ }
110
+ function hostHeader(url) {
111
+ const pattern = /.*:\/\/(?<host>[^/]+).*/;
112
+ const { groups } = pattern.exec(url) ?? {};
113
+ return groups?.host ? { Host: groups.host } : {};
114
+ }
115
+ async function fetch$1({
116
+ url: path,
117
+ method,
118
+ body,
119
+ headers,
120
+ pathParams,
121
+ queryParams,
122
+ fetchImpl,
123
+ apiKey,
124
+ apiUrl,
125
+ workspacesApiUrl
126
+ }) {
127
+ const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
128
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
129
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
130
+ const response = await fetchImpl(url, {
131
+ method: method.toUpperCase(),
132
+ body: body ? JSON.stringify(body) : void 0,
133
+ headers: {
134
+ "Content-Type": "application/json",
135
+ ...headers,
136
+ ...hostHeader(fullUrl),
137
+ Authorization: `Bearer ${apiKey}`
138
+ }
139
+ });
140
+ if (response.status === 204) {
141
+ return {};
142
+ }
143
+ try {
144
+ const jsonResponse = await response.json();
145
+ if (response.ok) {
146
+ return jsonResponse;
147
+ }
148
+ throw new FetcherError(response.status, jsonResponse);
149
+ } catch (error) {
150
+ throw new FetcherError(response.status, error);
151
+ }
152
+ }
153
+
154
+ const getUser = (variables) => fetch$1({ url: "/user", method: "get", ...variables });
155
+ const updateUser = (variables) => fetch$1({ url: "/user", method: "put", ...variables });
156
+ const deleteUser = (variables) => fetch$1({ url: "/user", method: "delete", ...variables });
157
+ const getUserAPIKeys = (variables) => fetch$1({
158
+ url: "/user/keys",
159
+ method: "get",
160
+ ...variables
161
+ });
162
+ const createUserAPIKey = (variables) => fetch$1({
163
+ url: "/user/keys/{keyName}",
164
+ method: "post",
165
+ ...variables
166
+ });
167
+ const deleteUserAPIKey = (variables) => fetch$1({
168
+ url: "/user/keys/{keyName}",
169
+ method: "delete",
170
+ ...variables
171
+ });
172
+ const createWorkspace = (variables) => fetch$1({
173
+ url: "/workspaces",
174
+ method: "post",
175
+ ...variables
176
+ });
177
+ const getWorkspacesList = (variables) => fetch$1({
178
+ url: "/workspaces",
179
+ method: "get",
180
+ ...variables
181
+ });
182
+ const getWorkspace = (variables) => fetch$1({
183
+ url: "/workspaces/{workspaceId}",
184
+ method: "get",
185
+ ...variables
186
+ });
187
+ const updateWorkspace = (variables) => fetch$1({
188
+ url: "/workspaces/{workspaceId}",
189
+ method: "put",
190
+ ...variables
191
+ });
192
+ const deleteWorkspace = (variables) => fetch$1({
193
+ url: "/workspaces/{workspaceId}",
194
+ method: "delete",
195
+ ...variables
196
+ });
197
+ const getWorkspaceMembersList = (variables) => fetch$1({
198
+ url: "/workspaces/{workspaceId}/members",
199
+ method: "get",
200
+ ...variables
201
+ });
202
+ const updateWorkspaceMemberRole = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/members/{userId}", method: "put", ...variables });
203
+ const removeWorkspaceMember = (variables) => fetch$1({
204
+ url: "/workspaces/{workspaceId}/members/{userId}",
205
+ method: "delete",
206
+ ...variables
207
+ });
208
+ const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
209
+ const cancelWorkspaceMemberInvite = (variables) => fetch$1({
210
+ url: "/workspaces/{workspaceId}/invites/{inviteId}",
211
+ method: "delete",
212
+ ...variables
213
+ });
214
+ const resendWorkspaceMemberInvite = (variables) => fetch$1({
215
+ url: "/workspaces/{workspaceId}/invites/{inviteId}/resend",
216
+ method: "post",
217
+ ...variables
218
+ });
219
+ const acceptWorkspaceMemberInvite = (variables) => fetch$1({
220
+ url: "/workspaces/{workspaceId}/invites/{inviteKey}/accept",
221
+ method: "post",
222
+ ...variables
223
+ });
224
+ const getDatabaseList = (variables) => fetch$1({
225
+ url: "/dbs",
226
+ method: "get",
227
+ ...variables
228
+ });
229
+ const getBranchList = (variables) => fetch$1({
230
+ url: "/dbs/{dbName}",
231
+ method: "get",
232
+ ...variables
233
+ });
234
+ const createDatabase = (variables) => fetch$1({
235
+ url: "/dbs/{dbName}",
236
+ method: "put",
237
+ ...variables
238
+ });
239
+ const deleteDatabase = (variables) => fetch$1({
240
+ url: "/dbs/{dbName}",
241
+ method: "delete",
242
+ ...variables
243
+ });
244
+ const getBranchDetails = (variables) => fetch$1({
245
+ url: "/db/{dbBranchName}",
246
+ method: "get",
247
+ ...variables
248
+ });
249
+ const createBranch = (variables) => fetch$1({
250
+ url: "/db/{dbBranchName}",
251
+ method: "put",
252
+ ...variables
253
+ });
254
+ const deleteBranch = (variables) => fetch$1({
255
+ url: "/db/{dbBranchName}",
256
+ method: "delete",
257
+ ...variables
258
+ });
259
+ const updateBranchMetadata = (variables) => fetch$1({
260
+ url: "/db/{dbBranchName}/metadata",
261
+ method: "put",
262
+ ...variables
263
+ });
264
+ const getBranchMetadata = (variables) => fetch$1({
265
+ url: "/db/{dbBranchName}/metadata",
266
+ method: "get",
267
+ ...variables
268
+ });
269
+ const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
270
+ const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
271
+ const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
272
+ const getBranchStats = (variables) => fetch$1({
273
+ url: "/db/{dbBranchName}/stats",
274
+ method: "get",
275
+ ...variables
276
+ });
277
+ const createTable = (variables) => fetch$1({
278
+ url: "/db/{dbBranchName}/tables/{tableName}",
279
+ method: "put",
280
+ ...variables
281
+ });
282
+ const deleteTable = (variables) => fetch$1({
283
+ url: "/db/{dbBranchName}/tables/{tableName}",
284
+ method: "delete",
285
+ ...variables
286
+ });
287
+ const updateTable = (variables) => fetch$1({
288
+ url: "/db/{dbBranchName}/tables/{tableName}",
289
+ method: "patch",
290
+ ...variables
291
+ });
292
+ const getTableSchema = (variables) => fetch$1({
293
+ url: "/db/{dbBranchName}/tables/{tableName}/schema",
294
+ method: "get",
295
+ ...variables
296
+ });
297
+ const setTableSchema = (variables) => fetch$1({
298
+ url: "/db/{dbBranchName}/tables/{tableName}/schema",
299
+ method: "put",
300
+ ...variables
301
+ });
302
+ const getTableColumns = (variables) => fetch$1({
303
+ url: "/db/{dbBranchName}/tables/{tableName}/columns",
304
+ method: "get",
305
+ ...variables
306
+ });
307
+ const addTableColumn = (variables) => fetch$1({
308
+ url: "/db/{dbBranchName}/tables/{tableName}/columns",
309
+ method: "post",
310
+ ...variables
311
+ });
312
+ const getColumn = (variables) => fetch$1({
313
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
314
+ method: "get",
315
+ ...variables
316
+ });
317
+ const deleteColumn = (variables) => fetch$1({
318
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
319
+ method: "delete",
320
+ ...variables
321
+ });
322
+ const updateColumn = (variables) => fetch$1({
323
+ url: "/db/{dbBranchName}/tables/{tableName}/columns/{columnName}",
324
+ method: "patch",
325
+ ...variables
326
+ });
327
+ const insertRecord = (variables) => fetch$1({
328
+ url: "/db/{dbBranchName}/tables/{tableName}/data",
329
+ method: "post",
330
+ ...variables
331
+ });
332
+ const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
333
+ const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
334
+ const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
335
+ const deleteRecord = (variables) => fetch$1({
336
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
337
+ method: "delete",
338
+ ...variables
339
+ });
340
+ const getRecord = (variables) => fetch$1({
341
+ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}",
342
+ method: "get",
343
+ ...variables
344
+ });
345
+ const bulkInsertTableRecords = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/bulk", method: "post", ...variables });
346
+ const queryTable = (variables) => fetch$1({
347
+ url: "/db/{dbBranchName}/tables/{tableName}/query",
348
+ method: "post",
349
+ ...variables
350
+ });
351
+ const searchBranch = (variables) => fetch$1({
352
+ url: "/db/{dbBranchName}/search",
353
+ method: "post",
354
+ ...variables
355
+ });
356
+ const operationsByTag = {
357
+ users: { getUser, updateUser, deleteUser, getUserAPIKeys, createUserAPIKey, deleteUserAPIKey },
358
+ workspaces: {
359
+ createWorkspace,
360
+ getWorkspacesList,
361
+ getWorkspace,
362
+ updateWorkspace,
363
+ deleteWorkspace,
364
+ getWorkspaceMembersList,
365
+ updateWorkspaceMemberRole,
366
+ removeWorkspaceMember,
367
+ inviteWorkspaceMember,
368
+ cancelWorkspaceMemberInvite,
369
+ resendWorkspaceMemberInvite,
370
+ acceptWorkspaceMemberInvite
371
+ },
372
+ database: { getDatabaseList, createDatabase, deleteDatabase },
373
+ branch: {
374
+ getBranchList,
375
+ getBranchDetails,
376
+ createBranch,
377
+ deleteBranch,
378
+ updateBranchMetadata,
379
+ getBranchMetadata,
380
+ getBranchMigrationHistory,
381
+ executeBranchMigrationPlan,
382
+ getBranchMigrationPlan,
383
+ getBranchStats
384
+ },
385
+ table: {
386
+ createTable,
387
+ deleteTable,
388
+ updateTable,
389
+ getTableSchema,
390
+ setTableSchema,
391
+ getTableColumns,
392
+ addTableColumn,
393
+ getColumn,
394
+ deleteColumn,
395
+ updateColumn
396
+ },
397
+ records: {
398
+ insertRecord,
399
+ insertRecordWithID,
400
+ updateRecordWithID,
401
+ upsertRecordWithID,
402
+ deleteRecord,
403
+ getRecord,
404
+ bulkInsertTableRecords,
405
+ queryTable,
406
+ searchBranch
407
+ }
408
+ };
409
+
410
+ function getHostUrl(provider, type) {
411
+ if (isValidAlias(provider)) {
412
+ return providers[provider][type];
413
+ } else if (isValidBuilder(provider)) {
414
+ return provider[type];
415
+ }
416
+ throw new Error("Invalid API provider");
417
+ }
418
+ const providers = {
419
+ production: {
420
+ main: "https://api.xata.io",
421
+ workspaces: "https://{workspaceId}.xata.sh"
422
+ },
423
+ staging: {
424
+ main: "https://staging.xatabase.co",
425
+ workspaces: "https://{workspaceId}.staging.xatabase.co"
426
+ }
427
+ };
428
+ function isValidAlias(alias) {
429
+ return isString(alias) && Object.keys(providers).includes(alias);
430
+ }
431
+ function isValidBuilder(builder) {
432
+ return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
433
+ }
434
+
435
+ var __accessCheck$6 = (obj, member, msg) => {
436
+ if (!member.has(obj))
437
+ throw TypeError("Cannot " + msg);
438
+ };
439
+ var __privateGet$5 = (obj, member, getter) => {
440
+ __accessCheck$6(obj, member, "read from private field");
441
+ return getter ? getter.call(obj) : member.get(obj);
442
+ };
443
+ var __privateAdd$6 = (obj, member, value) => {
444
+ if (member.has(obj))
445
+ throw TypeError("Cannot add the same private member more than once");
446
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
447
+ };
448
+ var __privateSet$4 = (obj, member, value, setter) => {
449
+ __accessCheck$6(obj, member, "write to private field");
450
+ setter ? setter.call(obj, value) : member.set(obj, value);
451
+ return value;
452
+ };
453
+ var _extraProps, _namespaces;
454
+ class XataApiClient {
455
+ constructor(options = {}) {
456
+ __privateAdd$6(this, _extraProps, void 0);
457
+ __privateAdd$6(this, _namespaces, {});
458
+ const provider = options.host ?? "production";
459
+ const apiKey = options?.apiKey ?? getAPIKey();
460
+ if (!apiKey) {
461
+ throw new Error("Could not resolve a valid apiKey");
462
+ }
463
+ __privateSet$4(this, _extraProps, {
464
+ apiUrl: getHostUrl(provider, "main"),
465
+ workspacesApiUrl: getHostUrl(provider, "workspaces"),
466
+ fetchImpl: getFetchImplementation(options.fetch),
467
+ apiKey
468
+ });
469
+ }
470
+ get user() {
471
+ if (!__privateGet$5(this, _namespaces).user)
472
+ __privateGet$5(this, _namespaces).user = new UserApi(__privateGet$5(this, _extraProps));
473
+ return __privateGet$5(this, _namespaces).user;
474
+ }
475
+ get workspaces() {
476
+ if (!__privateGet$5(this, _namespaces).workspaces)
477
+ __privateGet$5(this, _namespaces).workspaces = new WorkspaceApi(__privateGet$5(this, _extraProps));
478
+ return __privateGet$5(this, _namespaces).workspaces;
479
+ }
480
+ get databases() {
481
+ if (!__privateGet$5(this, _namespaces).databases)
482
+ __privateGet$5(this, _namespaces).databases = new DatabaseApi(__privateGet$5(this, _extraProps));
483
+ return __privateGet$5(this, _namespaces).databases;
484
+ }
485
+ get branches() {
486
+ if (!__privateGet$5(this, _namespaces).branches)
487
+ __privateGet$5(this, _namespaces).branches = new BranchApi(__privateGet$5(this, _extraProps));
488
+ return __privateGet$5(this, _namespaces).branches;
489
+ }
490
+ get tables() {
491
+ if (!__privateGet$5(this, _namespaces).tables)
492
+ __privateGet$5(this, _namespaces).tables = new TableApi(__privateGet$5(this, _extraProps));
493
+ return __privateGet$5(this, _namespaces).tables;
494
+ }
495
+ get records() {
496
+ if (!__privateGet$5(this, _namespaces).records)
497
+ __privateGet$5(this, _namespaces).records = new RecordsApi(__privateGet$5(this, _extraProps));
498
+ return __privateGet$5(this, _namespaces).records;
499
+ }
500
+ }
501
+ _extraProps = new WeakMap();
502
+ _namespaces = new WeakMap();
503
+ class UserApi {
504
+ constructor(extraProps) {
505
+ this.extraProps = extraProps;
506
+ }
507
+ getUser() {
508
+ return operationsByTag.users.getUser({ ...this.extraProps });
509
+ }
510
+ updateUser(user) {
511
+ return operationsByTag.users.updateUser({ body: user, ...this.extraProps });
512
+ }
513
+ deleteUser() {
514
+ return operationsByTag.users.deleteUser({ ...this.extraProps });
515
+ }
516
+ getUserAPIKeys() {
517
+ return operationsByTag.users.getUserAPIKeys({ ...this.extraProps });
518
+ }
519
+ createUserAPIKey(keyName) {
520
+ return operationsByTag.users.createUserAPIKey({
521
+ pathParams: { keyName },
522
+ ...this.extraProps
523
+ });
524
+ }
525
+ deleteUserAPIKey(keyName) {
526
+ return operationsByTag.users.deleteUserAPIKey({
527
+ pathParams: { keyName },
528
+ ...this.extraProps
529
+ });
530
+ }
531
+ }
532
+ class WorkspaceApi {
533
+ constructor(extraProps) {
534
+ this.extraProps = extraProps;
535
+ }
536
+ createWorkspace(workspaceMeta) {
537
+ return operationsByTag.workspaces.createWorkspace({
538
+ body: workspaceMeta,
539
+ ...this.extraProps
540
+ });
541
+ }
542
+ getWorkspacesList() {
543
+ return operationsByTag.workspaces.getWorkspacesList({ ...this.extraProps });
544
+ }
545
+ getWorkspace(workspaceId) {
546
+ return operationsByTag.workspaces.getWorkspace({
547
+ pathParams: { workspaceId },
548
+ ...this.extraProps
549
+ });
550
+ }
551
+ updateWorkspace(workspaceId, workspaceMeta) {
552
+ return operationsByTag.workspaces.updateWorkspace({
553
+ pathParams: { workspaceId },
554
+ body: workspaceMeta,
555
+ ...this.extraProps
556
+ });
557
+ }
558
+ deleteWorkspace(workspaceId) {
559
+ return operationsByTag.workspaces.deleteWorkspace({
560
+ pathParams: { workspaceId },
561
+ ...this.extraProps
562
+ });
563
+ }
564
+ getWorkspaceMembersList(workspaceId) {
565
+ return operationsByTag.workspaces.getWorkspaceMembersList({
566
+ pathParams: { workspaceId },
567
+ ...this.extraProps
568
+ });
569
+ }
570
+ updateWorkspaceMemberRole(workspaceId, userId, role) {
571
+ return operationsByTag.workspaces.updateWorkspaceMemberRole({
572
+ pathParams: { workspaceId, userId },
573
+ body: { role },
574
+ ...this.extraProps
575
+ });
576
+ }
577
+ removeWorkspaceMember(workspaceId, userId) {
578
+ return operationsByTag.workspaces.removeWorkspaceMember({
579
+ pathParams: { workspaceId, userId },
580
+ ...this.extraProps
581
+ });
582
+ }
583
+ inviteWorkspaceMember(workspaceId, email, role) {
584
+ return operationsByTag.workspaces.inviteWorkspaceMember({
585
+ pathParams: { workspaceId },
586
+ body: { email, role },
587
+ ...this.extraProps
588
+ });
589
+ }
590
+ cancelWorkspaceMemberInvite(workspaceId, inviteId) {
591
+ return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
592
+ pathParams: { workspaceId, inviteId },
593
+ ...this.extraProps
594
+ });
595
+ }
596
+ resendWorkspaceMemberInvite(workspaceId, inviteId) {
597
+ return operationsByTag.workspaces.resendWorkspaceMemberInvite({
598
+ pathParams: { workspaceId, inviteId },
599
+ ...this.extraProps
600
+ });
601
+ }
602
+ acceptWorkspaceMemberInvite(workspaceId, inviteKey) {
603
+ return operationsByTag.workspaces.acceptWorkspaceMemberInvite({
604
+ pathParams: { workspaceId, inviteKey },
605
+ ...this.extraProps
606
+ });
607
+ }
608
+ }
609
+ class DatabaseApi {
610
+ constructor(extraProps) {
611
+ this.extraProps = extraProps;
612
+ }
613
+ getDatabaseList(workspace) {
614
+ return operationsByTag.database.getDatabaseList({
615
+ pathParams: { workspace },
616
+ ...this.extraProps
617
+ });
618
+ }
619
+ createDatabase(workspace, dbName, options = {}) {
620
+ return operationsByTag.database.createDatabase({
621
+ pathParams: { workspace, dbName },
622
+ body: options,
623
+ ...this.extraProps
624
+ });
625
+ }
626
+ deleteDatabase(workspace, dbName) {
627
+ return operationsByTag.database.deleteDatabase({
628
+ pathParams: { workspace, dbName },
629
+ ...this.extraProps
630
+ });
631
+ }
632
+ }
633
+ class BranchApi {
634
+ constructor(extraProps) {
635
+ this.extraProps = extraProps;
636
+ }
637
+ getBranchList(workspace, dbName) {
638
+ return operationsByTag.branch.getBranchList({
639
+ pathParams: { workspace, dbName },
640
+ ...this.extraProps
641
+ });
642
+ }
643
+ getBranchDetails(workspace, database, branch) {
644
+ return operationsByTag.branch.getBranchDetails({
645
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
646
+ ...this.extraProps
647
+ });
648
+ }
649
+ createBranch(workspace, database, branch, from = "", options = {}) {
650
+ return operationsByTag.branch.createBranch({
651
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
652
+ queryParams: { from },
653
+ body: options,
654
+ ...this.extraProps
655
+ });
656
+ }
657
+ deleteBranch(workspace, database, branch) {
658
+ return operationsByTag.branch.deleteBranch({
659
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
660
+ ...this.extraProps
661
+ });
662
+ }
663
+ updateBranchMetadata(workspace, database, branch, metadata = {}) {
664
+ return operationsByTag.branch.updateBranchMetadata({
665
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
666
+ body: metadata,
667
+ ...this.extraProps
668
+ });
669
+ }
670
+ getBranchMetadata(workspace, database, branch) {
671
+ return operationsByTag.branch.getBranchMetadata({
672
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
673
+ ...this.extraProps
674
+ });
675
+ }
676
+ getBranchMigrationHistory(workspace, database, branch, options = {}) {
677
+ return operationsByTag.branch.getBranchMigrationHistory({
678
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
679
+ body: options,
680
+ ...this.extraProps
681
+ });
682
+ }
683
+ executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
684
+ return operationsByTag.branch.executeBranchMigrationPlan({
685
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
686
+ body: migrationPlan,
687
+ ...this.extraProps
688
+ });
689
+ }
690
+ getBranchMigrationPlan(workspace, database, branch, schema) {
691
+ return operationsByTag.branch.getBranchMigrationPlan({
692
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
693
+ body: schema,
694
+ ...this.extraProps
695
+ });
696
+ }
697
+ getBranchStats(workspace, database, branch) {
698
+ return operationsByTag.branch.getBranchStats({
699
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
700
+ ...this.extraProps
701
+ });
702
+ }
703
+ }
704
+ class TableApi {
705
+ constructor(extraProps) {
706
+ this.extraProps = extraProps;
707
+ }
708
+ createTable(workspace, database, branch, tableName) {
709
+ return operationsByTag.table.createTable({
710
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
711
+ ...this.extraProps
712
+ });
713
+ }
714
+ deleteTable(workspace, database, branch, tableName) {
715
+ return operationsByTag.table.deleteTable({
716
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
717
+ ...this.extraProps
718
+ });
719
+ }
720
+ updateTable(workspace, database, branch, tableName, options) {
721
+ return operationsByTag.table.updateTable({
722
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
723
+ body: options,
724
+ ...this.extraProps
725
+ });
726
+ }
727
+ getTableSchema(workspace, database, branch, tableName) {
728
+ return operationsByTag.table.getTableSchema({
729
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
730
+ ...this.extraProps
731
+ });
732
+ }
733
+ setTableSchema(workspace, database, branch, tableName, options) {
734
+ return operationsByTag.table.setTableSchema({
735
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
736
+ body: options,
737
+ ...this.extraProps
738
+ });
739
+ }
740
+ getTableColumns(workspace, database, branch, tableName) {
741
+ return operationsByTag.table.getTableColumns({
742
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
743
+ ...this.extraProps
744
+ });
745
+ }
746
+ addTableColumn(workspace, database, branch, tableName, column) {
747
+ return operationsByTag.table.addTableColumn({
748
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
749
+ body: column,
750
+ ...this.extraProps
751
+ });
752
+ }
753
+ getColumn(workspace, database, branch, tableName, columnName) {
754
+ return operationsByTag.table.getColumn({
755
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
756
+ ...this.extraProps
757
+ });
758
+ }
759
+ deleteColumn(workspace, database, branch, tableName, columnName) {
760
+ return operationsByTag.table.deleteColumn({
761
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
762
+ ...this.extraProps
763
+ });
764
+ }
765
+ updateColumn(workspace, database, branch, tableName, columnName, options) {
766
+ return operationsByTag.table.updateColumn({
767
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, columnName },
768
+ body: options,
769
+ ...this.extraProps
770
+ });
771
+ }
772
+ }
773
+ class RecordsApi {
774
+ constructor(extraProps) {
775
+ this.extraProps = extraProps;
776
+ }
777
+ insertRecord(workspace, database, branch, tableName, record) {
778
+ return operationsByTag.records.insertRecord({
779
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
780
+ body: record,
781
+ ...this.extraProps
782
+ });
783
+ }
784
+ insertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
785
+ return operationsByTag.records.insertRecordWithID({
786
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
787
+ queryParams: options,
788
+ body: record,
789
+ ...this.extraProps
790
+ });
791
+ }
792
+ updateRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
793
+ return operationsByTag.records.updateRecordWithID({
794
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
795
+ queryParams: options,
796
+ body: record,
797
+ ...this.extraProps
798
+ });
799
+ }
800
+ upsertRecordWithID(workspace, database, branch, tableName, recordId, record, options = {}) {
801
+ return operationsByTag.records.upsertRecordWithID({
802
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
803
+ queryParams: options,
804
+ body: record,
805
+ ...this.extraProps
806
+ });
807
+ }
808
+ deleteRecord(workspace, database, branch, tableName, recordId) {
809
+ return operationsByTag.records.deleteRecord({
810
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
811
+ ...this.extraProps
812
+ });
813
+ }
814
+ getRecord(workspace, database, branch, tableName, recordId, options = {}) {
815
+ return operationsByTag.records.getRecord({
816
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
817
+ ...this.extraProps
818
+ });
819
+ }
820
+ bulkInsertTableRecords(workspace, database, branch, tableName, records) {
821
+ return operationsByTag.records.bulkInsertTableRecords({
822
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
823
+ body: { records },
824
+ ...this.extraProps
825
+ });
826
+ }
827
+ queryTable(workspace, database, branch, tableName, query) {
828
+ return operationsByTag.records.queryTable({
829
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
830
+ body: query,
831
+ ...this.extraProps
832
+ });
833
+ }
834
+ searchBranch(workspace, database, branch, query) {
835
+ return operationsByTag.records.searchBranch({
836
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
837
+ body: query,
838
+ ...this.extraProps
839
+ });
840
+ }
841
+ }
842
+
843
+ class XataApiPlugin {
844
+ async build(options) {
845
+ const { fetchImpl, apiKey } = await options.getFetchProps();
846
+ return new XataApiClient({ fetch: fetchImpl, apiKey });
847
+ }
848
+ }
849
+
850
+ class XataPlugin {
851
+ }
852
+
853
+ var __accessCheck$5 = (obj, member, msg) => {
854
+ if (!member.has(obj))
855
+ throw TypeError("Cannot " + msg);
856
+ };
857
+ var __privateGet$4 = (obj, member, getter) => {
858
+ __accessCheck$5(obj, member, "read from private field");
859
+ return getter ? getter.call(obj) : member.get(obj);
860
+ };
861
+ var __privateAdd$5 = (obj, member, value) => {
862
+ if (member.has(obj))
863
+ throw TypeError("Cannot add the same private member more than once");
864
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
865
+ };
866
+ var __privateSet$3 = (obj, member, value, setter) => {
867
+ __accessCheck$5(obj, member, "write to private field");
868
+ setter ? setter.call(obj, value) : member.set(obj, value);
869
+ return value;
870
+ };
871
+ var _query;
872
+ class Page {
873
+ constructor(query, meta, records = []) {
874
+ __privateAdd$5(this, _query, void 0);
875
+ __privateSet$3(this, _query, query);
876
+ this.meta = meta;
877
+ this.records = records;
878
+ }
879
+ async nextPage(size, offset) {
880
+ return __privateGet$4(this, _query).getPaginated({ page: { size, offset, after: this.meta.page.cursor } });
881
+ }
882
+ async previousPage(size, offset) {
883
+ return __privateGet$4(this, _query).getPaginated({ page: { size, offset, before: this.meta.page.cursor } });
884
+ }
885
+ async firstPage(size, offset) {
886
+ return __privateGet$4(this, _query).getPaginated({ page: { size, offset, first: this.meta.page.cursor } });
887
+ }
888
+ async lastPage(size, offset) {
889
+ return __privateGet$4(this, _query).getPaginated({ page: { size, offset, last: this.meta.page.cursor } });
890
+ }
891
+ hasNextPage() {
892
+ return this.meta.page.more;
893
+ }
894
+ }
895
+ _query = new WeakMap();
896
+ const PAGINATION_MAX_SIZE = 200;
897
+ const PAGINATION_DEFAULT_SIZE = 200;
898
+ const PAGINATION_MAX_OFFSET = 800;
899
+ const PAGINATION_DEFAULT_OFFSET = 0;
900
+
901
+ var __accessCheck$4 = (obj, member, msg) => {
902
+ if (!member.has(obj))
903
+ throw TypeError("Cannot " + msg);
904
+ };
905
+ var __privateGet$3 = (obj, member, getter) => {
906
+ __accessCheck$4(obj, member, "read from private field");
907
+ return getter ? getter.call(obj) : member.get(obj);
908
+ };
909
+ var __privateAdd$4 = (obj, member, value) => {
910
+ if (member.has(obj))
911
+ throw TypeError("Cannot add the same private member more than once");
912
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
913
+ };
914
+ var __privateSet$2 = (obj, member, value, setter) => {
915
+ __accessCheck$4(obj, member, "write to private field");
916
+ setter ? setter.call(obj, value) : member.set(obj, value);
917
+ return value;
918
+ };
919
+ var _table$1, _repository, _data;
920
+ const _Query = class {
921
+ constructor(repository, table, data, parent) {
922
+ __privateAdd$4(this, _table$1, void 0);
923
+ __privateAdd$4(this, _repository, void 0);
924
+ __privateAdd$4(this, _data, { filter: {} });
925
+ this.meta = { page: { cursor: "start", more: true } };
926
+ this.records = [];
927
+ __privateSet$2(this, _table$1, table);
928
+ if (repository) {
929
+ __privateSet$2(this, _repository, repository);
930
+ } else {
931
+ __privateSet$2(this, _repository, this);
932
+ }
933
+ __privateGet$3(this, _data).filter = data.filter ?? parent?.filter ?? {};
934
+ __privateGet$3(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
935
+ __privateGet$3(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
936
+ __privateGet$3(this, _data).filter.$not = data.filter?.$not ?? parent?.filter?.$not;
937
+ __privateGet$3(this, _data).filter.$none = data.filter?.$none ?? parent?.filter?.$none;
938
+ __privateGet$3(this, _data).sort = data.sort ?? parent?.sort;
939
+ __privateGet$3(this, _data).columns = data.columns ?? parent?.columns ?? ["*"];
940
+ __privateGet$3(this, _data).page = data.page ?? parent?.page;
941
+ this.any = this.any.bind(this);
942
+ this.all = this.all.bind(this);
943
+ this.not = this.not.bind(this);
944
+ this.filter = this.filter.bind(this);
945
+ this.sort = this.sort.bind(this);
946
+ this.none = this.none.bind(this);
947
+ Object.defineProperty(this, "table", { enumerable: false });
948
+ Object.defineProperty(this, "repository", { enumerable: false });
949
+ }
950
+ getQueryOptions() {
951
+ return __privateGet$3(this, _data);
952
+ }
953
+ any(...queries) {
954
+ const $any = queries.map((query) => query.getQueryOptions().filter ?? {});
955
+ return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $any } }, __privateGet$3(this, _data));
956
+ }
957
+ all(...queries) {
958
+ const $all = queries.map((query) => query.getQueryOptions().filter ?? {});
959
+ return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
960
+ }
961
+ not(...queries) {
962
+ const $not = queries.map((query) => query.getQueryOptions().filter ?? {});
963
+ return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $not } }, __privateGet$3(this, _data));
964
+ }
965
+ none(...queries) {
966
+ const $none = queries.map((query) => query.getQueryOptions().filter ?? {});
967
+ return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $none } }, __privateGet$3(this, _data));
968
+ }
969
+ filter(a, b) {
970
+ if (arguments.length === 1) {
971
+ const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
972
+ const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat(constraints));
973
+ return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
974
+ } else {
975
+ const $all = compact([__privateGet$3(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
976
+ return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { filter: { $all } }, __privateGet$3(this, _data));
977
+ }
978
+ }
979
+ sort(column, direction) {
980
+ const originalSort = [__privateGet$3(this, _data).sort ?? []].flat();
981
+ const sort = [...originalSort, { column, direction }];
982
+ return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { sort }, __privateGet$3(this, _data));
983
+ }
984
+ select(columns) {
985
+ return new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), { columns }, __privateGet$3(this, _data));
986
+ }
987
+ getPaginated(options = {}) {
988
+ const query = new _Query(__privateGet$3(this, _repository), __privateGet$3(this, _table$1), options, __privateGet$3(this, _data));
989
+ return __privateGet$3(this, _repository).query(query);
990
+ }
991
+ async *[Symbol.asyncIterator]() {
992
+ for await (const [record] of this.getIterator(1)) {
993
+ yield record;
994
+ }
995
+ }
996
+ async *getIterator(chunk, options = {}) {
997
+ let offset = 0;
998
+ let end = false;
999
+ while (!end) {
1000
+ const { records, meta } = await this.getPaginated({ ...options, page: { size: chunk, offset } });
1001
+ yield records;
1002
+ offset += chunk;
1003
+ end = !meta.page.more;
1004
+ }
1005
+ }
1006
+ async getMany(options = {}) {
1007
+ const { records } = await this.getPaginated(options);
1008
+ return records;
1009
+ }
1010
+ async getAll(chunk = PAGINATION_MAX_SIZE, options = {}) {
1011
+ const results = [];
1012
+ for await (const page of this.getIterator(chunk, options)) {
1013
+ results.push(...page);
1014
+ }
1015
+ return results;
1016
+ }
1017
+ async getOne(options = {}) {
1018
+ const records = await this.getMany({ ...options, page: { size: 1 } });
1019
+ return records[0] || null;
1020
+ }
1021
+ nextPage(size, offset) {
1022
+ return this.firstPage(size, offset);
1023
+ }
1024
+ previousPage(size, offset) {
1025
+ return this.firstPage(size, offset);
1026
+ }
1027
+ firstPage(size, offset) {
1028
+ return this.getPaginated({ page: { size, offset } });
1029
+ }
1030
+ lastPage(size, offset) {
1031
+ return this.getPaginated({ page: { size, offset, before: "end" } });
1032
+ }
1033
+ hasNextPage() {
1034
+ return this.meta.page.more;
1035
+ }
1036
+ };
1037
+ let Query = _Query;
1038
+ _table$1 = new WeakMap();
1039
+ _repository = new WeakMap();
1040
+ _data = new WeakMap();
1041
+
1042
+ function isIdentifiable(x) {
1043
+ return isObject(x) && isString(x?.id);
1044
+ }
1045
+ function isXataRecord(x) {
1046
+ return isIdentifiable(x) && typeof x?.xata === "object" && typeof x?.xata?.version === "number";
1047
+ }
1048
+
1049
+ function isSortFilterString(value) {
1050
+ return isString(value);
1051
+ }
1052
+ function isSortFilterBase(filter) {
1053
+ return isObject(filter) && Object.values(filter).every((value) => value === "asc" || value === "desc");
1054
+ }
1055
+ function isSortFilterObject(filter) {
1056
+ return isObject(filter) && !isSortFilterBase(filter) && filter.column !== void 0;
1057
+ }
1058
+ function buildSortFilter(filter) {
1059
+ if (isSortFilterString(filter)) {
1060
+ return { [filter]: "asc" };
1061
+ } else if (Array.isArray(filter)) {
1062
+ return filter.map((item) => buildSortFilter(item));
1063
+ } else if (isSortFilterBase(filter)) {
1064
+ return filter;
1065
+ } else if (isSortFilterObject(filter)) {
1066
+ return { [filter.column]: filter.direction ?? "asc" };
1067
+ } else {
1068
+ throw new Error(`Invalid sort filter: ${filter}`);
1069
+ }
1070
+ }
1071
+
1072
+ var __accessCheck$3 = (obj, member, msg) => {
1073
+ if (!member.has(obj))
1074
+ throw TypeError("Cannot " + msg);
1075
+ };
1076
+ var __privateGet$2 = (obj, member, getter) => {
1077
+ __accessCheck$3(obj, member, "read from private field");
1078
+ return getter ? getter.call(obj) : member.get(obj);
1079
+ };
1080
+ var __privateAdd$3 = (obj, member, value) => {
1081
+ if (member.has(obj))
1082
+ throw TypeError("Cannot add the same private member more than once");
1083
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1084
+ };
1085
+ var __privateSet$1 = (obj, member, value, setter) => {
1086
+ __accessCheck$3(obj, member, "write to private field");
1087
+ setter ? setter.call(obj, value) : member.set(obj, value);
1088
+ return value;
1089
+ };
1090
+ var __privateMethod$2 = (obj, member, method) => {
1091
+ __accessCheck$3(obj, member, "access private method");
1092
+ return method;
1093
+ };
1094
+ var _table, _links, _getFetchProps, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn;
1095
+ class Repository extends Query {
1096
+ }
1097
+ class RestRepository extends Query {
1098
+ constructor(options) {
1099
+ super(null, options.table, {});
1100
+ __privateAdd$3(this, _insertRecordWithoutId);
1101
+ __privateAdd$3(this, _insertRecordWithId);
1102
+ __privateAdd$3(this, _bulkInsertTableRecords);
1103
+ __privateAdd$3(this, _updateRecordWithID);
1104
+ __privateAdd$3(this, _upsertRecordWithID);
1105
+ __privateAdd$3(this, _deleteRecord);
1106
+ __privateAdd$3(this, _table, void 0);
1107
+ __privateAdd$3(this, _links, void 0);
1108
+ __privateAdd$3(this, _getFetchProps, void 0);
1109
+ __privateSet$1(this, _table, options.table);
1110
+ __privateSet$1(this, _links, options.links ?? {});
1111
+ __privateSet$1(this, _getFetchProps, options.getFetchProps);
1112
+ this.db = options.db;
1113
+ }
1114
+ async create(a, b) {
1115
+ if (Array.isArray(a)) {
1116
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1117
+ }
1118
+ if (isString(a) && isObject(b)) {
1119
+ if (a === "")
1120
+ throw new Error("The id can't be empty");
1121
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1122
+ }
1123
+ if (isObject(a) && isString(a.id)) {
1124
+ if (a.id === "")
1125
+ throw new Error("The id can't be empty");
1126
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1127
+ }
1128
+ if (isObject(a)) {
1129
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1130
+ }
1131
+ throw new Error("Invalid arguments for create method");
1132
+ }
1133
+ async read(recordId) {
1134
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1135
+ try {
1136
+ const response = await getRecord({
1137
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1138
+ ...fetchProps
1139
+ });
1140
+ return initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), response);
1141
+ } catch (e) {
1142
+ if (isObject(e) && e.status === 404) {
1143
+ return null;
1144
+ }
1145
+ throw e;
1146
+ }
1147
+ }
1148
+ async update(a, b) {
1149
+ if (Array.isArray(a)) {
1150
+ if (a.length > 100) {
1151
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1152
+ }
1153
+ return Promise.all(a.map((object) => this.update(object)));
1154
+ }
1155
+ if (isString(a) && isObject(b)) {
1156
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1157
+ }
1158
+ if (isObject(a) && isString(a.id)) {
1159
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1160
+ }
1161
+ throw new Error("Invalid arguments for update method");
1162
+ }
1163
+ async createOrUpdate(a, b) {
1164
+ if (Array.isArray(a)) {
1165
+ if (a.length > 100) {
1166
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1167
+ }
1168
+ return Promise.all(a.map((object) => this.createOrUpdate(object)));
1169
+ }
1170
+ if (isString(a) && isObject(b)) {
1171
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1172
+ }
1173
+ if (isObject(a) && isString(a.id)) {
1174
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1175
+ }
1176
+ throw new Error("Invalid arguments for createOrUpdate method");
1177
+ }
1178
+ async delete(recordId) {
1179
+ if (Array.isArray(recordId)) {
1180
+ if (recordId.length > 100) {
1181
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1182
+ }
1183
+ await Promise.all(recordId.map((id) => this.delete(id)));
1184
+ return;
1185
+ }
1186
+ if (isString(recordId)) {
1187
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId);
1188
+ return;
1189
+ }
1190
+ if (isObject(recordId) && isString(recordId.id)) {
1191
+ await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, recordId.id);
1192
+ return;
1193
+ }
1194
+ throw new Error("Invalid arguments for delete method");
1195
+ }
1196
+ async search(query, options = {}) {
1197
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1198
+ const { records } = await searchBranch({
1199
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1200
+ body: { tables: [__privateGet$2(this, _table)], query, fuzziness: options.fuzziness },
1201
+ ...fetchProps
1202
+ });
1203
+ return records.map((item) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), item));
1204
+ }
1205
+ async query(query) {
1206
+ const data = query.getQueryOptions();
1207
+ const body = {
1208
+ filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1209
+ sort: data.sort ? buildSortFilter(data.sort) : void 0,
1210
+ page: data.page,
1211
+ columns: data.columns
1212
+ };
1213
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1214
+ const { meta, records: objects } = await queryTable({
1215
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1216
+ body,
1217
+ ...fetchProps
1218
+ });
1219
+ const records = objects.map((record) => initObject(this.db, __privateGet$2(this, _links), __privateGet$2(this, _table), record));
1220
+ return new Page(query, meta, records);
1221
+ }
1222
+ }
1223
+ _table = new WeakMap();
1224
+ _links = new WeakMap();
1225
+ _getFetchProps = new WeakMap();
1226
+ _insertRecordWithoutId = new WeakSet();
1227
+ insertRecordWithoutId_fn = async function(object) {
1228
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1229
+ const record = transformObjectLinks(object);
1230
+ const response = await insertRecord({
1231
+ pathParams: {
1232
+ workspace: "{workspaceId}",
1233
+ dbBranchName: "{dbBranch}",
1234
+ tableName: __privateGet$2(this, _table)
1235
+ },
1236
+ body: record,
1237
+ ...fetchProps
1238
+ });
1239
+ const finalObject = await this.read(response.id);
1240
+ if (!finalObject) {
1241
+ throw new Error("The server failed to save the record");
1242
+ }
1243
+ return finalObject;
1244
+ };
1245
+ _insertRecordWithId = new WeakSet();
1246
+ insertRecordWithId_fn = async function(recordId, object) {
1247
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1248
+ const record = transformObjectLinks(object);
1249
+ const response = await insertRecordWithID({
1250
+ pathParams: {
1251
+ workspace: "{workspaceId}",
1252
+ dbBranchName: "{dbBranch}",
1253
+ tableName: __privateGet$2(this, _table),
1254
+ recordId
1255
+ },
1256
+ body: record,
1257
+ queryParams: { createOnly: true },
1258
+ ...fetchProps
1259
+ });
1260
+ const finalObject = await this.read(response.id);
1261
+ if (!finalObject) {
1262
+ throw new Error("The server failed to save the record");
1263
+ }
1264
+ return finalObject;
1265
+ };
1266
+ _bulkInsertTableRecords = new WeakSet();
1267
+ bulkInsertTableRecords_fn = async function(objects) {
1268
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1269
+ const records = objects.map((object) => transformObjectLinks(object));
1270
+ const response = await bulkInsertTableRecords({
1271
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table) },
1272
+ body: { records },
1273
+ ...fetchProps
1274
+ });
1275
+ const finalObjects = await this.any(...response.recordIDs.map((id) => this.filter("id", id))).getAll();
1276
+ if (finalObjects.length !== objects.length) {
1277
+ throw new Error("The server failed to save some records");
1278
+ }
1279
+ return finalObjects;
1280
+ };
1281
+ _updateRecordWithID = new WeakSet();
1282
+ updateRecordWithID_fn = async function(recordId, object) {
1283
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1284
+ const record = transformObjectLinks(object);
1285
+ const response = await updateRecordWithID({
1286
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1287
+ body: record,
1288
+ ...fetchProps
1289
+ });
1290
+ const item = await this.read(response.id);
1291
+ if (!item)
1292
+ throw new Error("The server failed to save the record");
1293
+ return item;
1294
+ };
1295
+ _upsertRecordWithID = new WeakSet();
1296
+ upsertRecordWithID_fn = async function(recordId, object) {
1297
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1298
+ const response = await upsertRecordWithID({
1299
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1300
+ body: object,
1301
+ ...fetchProps
1302
+ });
1303
+ const item = await this.read(response.id);
1304
+ if (!item)
1305
+ throw new Error("The server failed to save the record");
1306
+ return item;
1307
+ };
1308
+ _deleteRecord = new WeakSet();
1309
+ deleteRecord_fn = async function(recordId) {
1310
+ const fetchProps = await __privateGet$2(this, _getFetchProps).call(this);
1311
+ await deleteRecord({
1312
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$2(this, _table), recordId },
1313
+ ...fetchProps
1314
+ });
1315
+ };
1316
+ const transformObjectLinks = (object) => {
1317
+ return Object.entries(object).reduce((acc, [key, value]) => {
1318
+ if (key === "xata")
1319
+ return acc;
1320
+ return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1321
+ }, {});
1322
+ };
1323
+ const initObject = (db, links, table, object) => {
1324
+ const result = {};
1325
+ Object.assign(result, object);
1326
+ const tableLinks = links[table] || [];
1327
+ for (const link of tableLinks) {
1328
+ const [field, linkTable] = link;
1329
+ const value = result[field];
1330
+ if (value && isObject(value)) {
1331
+ result[field] = initObject(db, links, linkTable, value);
1332
+ }
1333
+ }
1334
+ result.read = function() {
1335
+ return db[table].read(result["id"]);
1336
+ };
1337
+ result.update = function(data) {
1338
+ return db[table].update(result["id"], data);
1339
+ };
1340
+ result.delete = function() {
1341
+ return db[table].delete(result["id"]);
1342
+ };
1343
+ for (const prop of ["read", "update", "delete"]) {
1344
+ Object.defineProperty(result, prop, { enumerable: false });
1345
+ }
1346
+ Object.freeze(result);
1347
+ return result;
1348
+ };
1349
+
1350
+ const gt = (value) => ({ $gt: value });
1351
+ const ge = (value) => ({ $ge: value });
1352
+ const gte = (value) => ({ $ge: value });
1353
+ const lt = (value) => ({ $lt: value });
1354
+ const lte = (value) => ({ $le: value });
1355
+ const le = (value) => ({ $le: value });
1356
+ const exists = (column) => ({ $exists: column });
1357
+ const notExists = (column) => ({ $notExists: column });
1358
+ const startsWith = (value) => ({ $startsWith: value });
1359
+ const endsWith = (value) => ({ $endsWith: value });
1360
+ const pattern = (value) => ({ $pattern: value });
1361
+ const is = (value) => ({ $is: value });
1362
+ const isNot = (value) => ({ $isNot: value });
1363
+ const contains = (value) => ({ $contains: value });
1364
+ const includes = (value) => ({ $includes: value });
1365
+ const includesAll = (value) => ({ $includesAll: value });
1366
+ const includesNone = (value) => ({ $includesNone: value });
1367
+ const includesAny = (value) => ({ $includesAny: value });
1368
+
1369
+ var __accessCheck$2 = (obj, member, msg) => {
1370
+ if (!member.has(obj))
1371
+ throw TypeError("Cannot " + msg);
1372
+ };
1373
+ var __privateGet$1 = (obj, member, getter) => {
1374
+ __accessCheck$2(obj, member, "read from private field");
1375
+ return getter ? getter.call(obj) : member.get(obj);
1376
+ };
1377
+ var __privateAdd$2 = (obj, member, value) => {
1378
+ if (member.has(obj))
1379
+ throw TypeError("Cannot add the same private member more than once");
1380
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1381
+ };
1382
+ var _tables;
1383
+ class SchemaPlugin extends XataPlugin {
1384
+ constructor(links) {
1385
+ super();
1386
+ this.links = links;
1387
+ __privateAdd$2(this, _tables, {});
1388
+ }
1389
+ build(options) {
1390
+ const { getFetchProps } = options;
1391
+ const links = this.links;
1392
+ const db = new Proxy({}, {
1393
+ get: (_target, table) => {
1394
+ if (!isString(table))
1395
+ throw new Error("Invalid table name");
1396
+ if (!__privateGet$1(this, _tables)[table])
1397
+ __privateGet$1(this, _tables)[table] = new RestRepository({ db, getFetchProps, table, links });
1398
+ return __privateGet$1(this, _tables)[table];
1399
+ }
1400
+ });
1401
+ return db;
1402
+ }
1403
+ }
1404
+ _tables = new WeakMap();
1405
+
1406
+ var __accessCheck$1 = (obj, member, msg) => {
1407
+ if (!member.has(obj))
1408
+ throw TypeError("Cannot " + msg);
1409
+ };
1410
+ var __privateAdd$1 = (obj, member, value) => {
1411
+ if (member.has(obj))
1412
+ throw TypeError("Cannot add the same private member more than once");
1413
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1414
+ };
1415
+ var __privateMethod$1 = (obj, member, method) => {
1416
+ __accessCheck$1(obj, member, "access private method");
1417
+ return method;
1418
+ };
1419
+ var _search, search_fn;
1420
+ class SearchPlugin extends XataPlugin {
1421
+ constructor(db, links) {
1422
+ super();
1423
+ this.db = db;
1424
+ this.links = links;
1425
+ __privateAdd$1(this, _search);
1426
+ }
1427
+ build({ getFetchProps }) {
1428
+ return {
1429
+ all: async (query, options = {}) => {
1430
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1431
+ return records.map((record) => {
1432
+ const { table = "orphan" } = record.xata;
1433
+ return { table, record: initObject(this.db, this.links, table, record) };
1434
+ });
1435
+ },
1436
+ byTable: async (query, options = {}) => {
1437
+ const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1438
+ return records.reduce((acc, record) => {
1439
+ const { table = "orphan" } = record.xata;
1440
+ const items = acc[table] ?? [];
1441
+ const item = initObject(this.db, this.links, table, record);
1442
+ return { ...acc, [table]: [...items, item] };
1443
+ }, {});
1444
+ }
1445
+ };
1446
+ }
1447
+ }
1448
+ _search = new WeakSet();
1449
+ search_fn = async function(query, options, getFetchProps) {
1450
+ const fetchProps = await getFetchProps();
1451
+ const { tables, fuzziness } = options ?? {};
1452
+ const { records } = await searchBranch({
1453
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1454
+ body: { tables, query, fuzziness },
1455
+ ...fetchProps
1456
+ });
1457
+ return records;
1458
+ };
1459
+
1460
+ const isBranchStrategyBuilder = (strategy) => {
1461
+ return typeof strategy === "function";
1462
+ };
1463
+
1464
+ const envBranchNames = [
1465
+ "XATA_BRANCH",
1466
+ "VERCEL_GIT_COMMIT_REF",
1467
+ "CF_PAGES_BRANCH",
1468
+ "BRANCH"
1469
+ ];
1470
+ const defaultBranch = "main";
1471
+ async function getCurrentBranchName(options) {
1472
+ const env = await getBranchByEnvVariable();
1473
+ if (env)
1474
+ return env;
1475
+ const branch = await getGitBranch();
1476
+ if (!branch)
1477
+ return defaultBranch;
1478
+ const details = await getDatabaseBranch(branch, options);
1479
+ if (details)
1480
+ return branch;
1481
+ return defaultBranch;
1482
+ }
1483
+ async function getCurrentBranchDetails(options) {
1484
+ const env = await getBranchByEnvVariable();
1485
+ if (env)
1486
+ return getDatabaseBranch(env, options);
1487
+ const branch = await getGitBranch();
1488
+ if (!branch)
1489
+ return getDatabaseBranch(defaultBranch, options);
1490
+ const details = await getDatabaseBranch(branch, options);
1491
+ if (details)
1492
+ return details;
1493
+ return getDatabaseBranch(defaultBranch, options);
1494
+ }
1495
+ async function getDatabaseBranch(branch, options) {
1496
+ const databaseURL = options?.databaseURL || getDatabaseURL();
1497
+ const apiKey = options?.apiKey || getAPIKey();
1498
+ if (!databaseURL)
1499
+ throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1500
+ if (!apiKey)
1501
+ throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1502
+ const [protocol, , host, , database] = databaseURL.split("/");
1503
+ const [workspace] = host.split(".");
1504
+ const dbBranchName = `${database}:${branch}`;
1505
+ try {
1506
+ return await getBranchDetails({
1507
+ apiKey,
1508
+ apiUrl: databaseURL,
1509
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
1510
+ workspacesApiUrl: `${protocol}//${host}`,
1511
+ pathParams: {
1512
+ dbBranchName,
1513
+ workspace
1514
+ }
1515
+ });
1516
+ } catch (err) {
1517
+ if (isObject(err) && err.status === 404)
1518
+ return null;
1519
+ throw err;
1520
+ }
1521
+ }
1522
+ function getBranchByEnvVariable() {
1523
+ for (const name of envBranchNames) {
1524
+ const value = getEnvVariable(name);
1525
+ if (value) {
1526
+ return value;
1527
+ }
1528
+ }
1529
+ try {
1530
+ return XATA_BRANCH;
1531
+ } catch (err) {
1532
+ }
1533
+ }
1534
+ function getDatabaseURL() {
1535
+ try {
1536
+ return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
1537
+ } catch (err) {
1538
+ return void 0;
1539
+ }
1540
+ }
1541
+
1542
+ var __accessCheck = (obj, member, msg) => {
1543
+ if (!member.has(obj))
1544
+ throw TypeError("Cannot " + msg);
1545
+ };
1546
+ var __privateGet = (obj, member, getter) => {
1547
+ __accessCheck(obj, member, "read from private field");
1548
+ return getter ? getter.call(obj) : member.get(obj);
1549
+ };
1550
+ var __privateAdd = (obj, member, value) => {
1551
+ if (member.has(obj))
1552
+ throw TypeError("Cannot add the same private member more than once");
1553
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1554
+ };
1555
+ var __privateSet = (obj, member, value, setter) => {
1556
+ __accessCheck(obj, member, "write to private field");
1557
+ setter ? setter.call(obj, value) : member.set(obj, value);
1558
+ return value;
1559
+ };
1560
+ var __privateMethod = (obj, member, method) => {
1561
+ __accessCheck(obj, member, "access private method");
1562
+ return method;
1563
+ };
1564
+ const buildClient = (plugins) => {
1565
+ var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1566
+ return _a = class {
1567
+ constructor(options = {}, links) {
1568
+ __privateAdd(this, _parseOptions);
1569
+ __privateAdd(this, _getFetchProps);
1570
+ __privateAdd(this, _evaluateBranch);
1571
+ __privateAdd(this, _branch, void 0);
1572
+ const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
1573
+ const db = new SchemaPlugin(links).build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1574
+ const search = new SearchPlugin(db, links ?? {}).build({
1575
+ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions)
1576
+ });
1577
+ this.db = db;
1578
+ this.search = search;
1579
+ for (const [key, namespace] of Object.entries(plugins ?? {})) {
1580
+ if (!namespace)
1581
+ continue;
1582
+ const result = namespace.build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1583
+ if (result instanceof Promise) {
1584
+ void result.then((namespace2) => {
1585
+ this[key] = namespace2;
1586
+ });
1587
+ } else {
1588
+ this[key] = result;
1589
+ }
1590
+ }
1591
+ }
1592
+ }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
1593
+ const fetch = getFetchImplementation(options?.fetch);
1594
+ const databaseURL = options?.databaseURL || getDatabaseURL();
1595
+ const apiKey = options?.apiKey || getAPIKey();
1596
+ const branch = async () => options?.branch ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1597
+ if (!databaseURL || !apiKey) {
1598
+ throw new Error("Options databaseURL and apiKey are required");
1599
+ }
1600
+ return { fetch, databaseURL, apiKey, branch };
1601
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1602
+ fetch,
1603
+ apiKey,
1604
+ databaseURL,
1605
+ branch
1606
+ }) {
1607
+ const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
1608
+ if (!branchValue)
1609
+ throw new Error("Unable to resolve branch value");
1610
+ return {
1611
+ fetchImpl: fetch,
1612
+ apiKey,
1613
+ apiUrl: "",
1614
+ workspacesApiUrl: (path, params) => {
1615
+ const hasBranch = params.dbBranchName ?? params.branch;
1616
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
1617
+ return databaseURL + newPath;
1618
+ }
1619
+ };
1620
+ }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
1621
+ if (__privateGet(this, _branch))
1622
+ return __privateGet(this, _branch);
1623
+ if (!param)
1624
+ return void 0;
1625
+ const strategies = Array.isArray(param) ? [...param] : [param];
1626
+ const evaluateBranch = async (strategy) => {
1627
+ return isBranchStrategyBuilder(strategy) ? await strategy() : strategy;
1628
+ };
1629
+ for await (const strategy of strategies) {
1630
+ const branch = await evaluateBranch(strategy);
1631
+ if (branch) {
1632
+ __privateSet(this, _branch, branch);
1633
+ return branch;
1634
+ }
1635
+ }
1636
+ }, _a;
1637
+ };
1638
+ class BaseClient extends buildClient() {
1639
+ }
1640
+
1641
+ class XataError extends Error {
1642
+ constructor(message, status) {
1643
+ super(message);
1644
+ this.status = status;
1645
+ }
1646
+ }
1647
+
1648
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, Repository, RestRepository, SchemaPlugin, SearchPlugin, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, 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, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeWorkspaceMember, resendWorkspaceMemberInvite, searchBranch, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
1649
+ //# sourceMappingURL=index.mjs.map