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