@xata.io/client 0.8.2 → 0.8.3

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