@xata.io/client 0.0.0-alpha.vf45a2df → 0.0.0-alpha.vf4752f8

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.
package/dist/index.mjs CHANGED
@@ -1,3 +1,25 @@
1
+ const defaultTrace = async (_name, fn, _options) => {
2
+ return await fn({
3
+ setAttributes: () => {
4
+ return;
5
+ }
6
+ });
7
+ };
8
+ const TraceAttributes = {
9
+ KIND: "xata.trace.kind",
10
+ VERSION: "xata.sdk.version",
11
+ TABLE: "xata.table",
12
+ HTTP_REQUEST_ID: "http.request_id",
13
+ HTTP_STATUS_CODE: "http.status_code",
14
+ HTTP_HOST: "http.host",
15
+ HTTP_SCHEME: "http.scheme",
16
+ HTTP_USER_AGENT: "http.user_agent",
17
+ HTTP_METHOD: "http.method",
18
+ HTTP_URL: "http.url",
19
+ HTTP_ROUTE: "http.route",
20
+ HTTP_TARGET: "http.target"
21
+ };
22
+
1
23
  function notEmpty(value) {
2
24
  return value !== null && value !== void 0;
3
25
  }
@@ -13,6 +35,9 @@ function isDefined(value) {
13
35
  function isString(value) {
14
36
  return isDefined(value) && typeof value === "string";
15
37
  }
38
+ function isStringArray(value) {
39
+ return isDefined(value) && Array.isArray(value) && value.every(isString);
40
+ }
16
41
  function toBase64(value) {
17
42
  try {
18
43
  return btoa(value);
@@ -22,35 +47,83 @@ function toBase64(value) {
22
47
  }
23
48
  }
24
49
 
25
- function getEnvVariable(name) {
50
+ function getEnvironment() {
26
51
  try {
27
- if (isObject(process) && isString(process?.env?.[name])) {
28
- return process.env[name];
52
+ if (isObject(process) && isObject(process.env)) {
53
+ return {
54
+ apiKey: process.env.XATA_API_KEY ?? getGlobalApiKey(),
55
+ databaseURL: process.env.XATA_DATABASE_URL ?? getGlobalDatabaseURL(),
56
+ branch: process.env.XATA_BRANCH ?? getGlobalBranch(),
57
+ envBranch: process.env.VERCEL_GIT_COMMIT_REF ?? process.env.CF_PAGES_BRANCH ?? process.env.BRANCH,
58
+ fallbackBranch: process.env.XATA_FALLBACK_BRANCH ?? getGlobalFallbackBranch()
59
+ };
29
60
  }
30
61
  } catch (err) {
31
62
  }
32
63
  try {
33
- if (isObject(Deno) && isString(Deno?.env?.get(name))) {
34
- return Deno.env.get(name);
64
+ if (isObject(Deno) && isObject(Deno.env)) {
65
+ return {
66
+ apiKey: Deno.env.get("XATA_API_KEY") ?? getGlobalApiKey(),
67
+ databaseURL: Deno.env.get("XATA_DATABASE_URL") ?? getGlobalDatabaseURL(),
68
+ branch: Deno.env.get("XATA_BRANCH") ?? getGlobalBranch(),
69
+ envBranch: Deno.env.get("VERCEL_GIT_COMMIT_REF") ?? Deno.env.get("CF_PAGES_BRANCH") ?? Deno.env.get("BRANCH"),
70
+ fallbackBranch: Deno.env.get("XATA_FALLBACK_BRANCH") ?? getGlobalFallbackBranch()
71
+ };
35
72
  }
36
73
  } catch (err) {
37
74
  }
75
+ return {
76
+ apiKey: getGlobalApiKey(),
77
+ databaseURL: getGlobalDatabaseURL(),
78
+ branch: getGlobalBranch(),
79
+ envBranch: void 0,
80
+ fallbackBranch: getGlobalFallbackBranch()
81
+ };
82
+ }
83
+ function getGlobalApiKey() {
84
+ try {
85
+ return XATA_API_KEY;
86
+ } catch (err) {
87
+ return void 0;
88
+ }
89
+ }
90
+ function getGlobalDatabaseURL() {
91
+ try {
92
+ return XATA_DATABASE_URL;
93
+ } catch (err) {
94
+ return void 0;
95
+ }
96
+ }
97
+ function getGlobalBranch() {
98
+ try {
99
+ return XATA_BRANCH;
100
+ } catch (err) {
101
+ return void 0;
102
+ }
103
+ }
104
+ function getGlobalFallbackBranch() {
105
+ try {
106
+ return XATA_FALLBACK_BRANCH;
107
+ } catch (err) {
108
+ return void 0;
109
+ }
38
110
  }
39
111
  async function getGitBranch() {
112
+ const cmd = ["git", "branch", "--show-current"];
113
+ const fullCmd = cmd.join(" ");
114
+ const nodeModule = ["child", "process"].join("_");
115
+ const execOptions = { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] };
40
116
  try {
41
117
  if (typeof require === "function") {
42
- const req = require;
43
- return req("child_process").execSync("git branch --show-current", { encoding: "utf-8" }).trim();
118
+ return require(nodeModule).execSync(fullCmd, execOptions).trim();
44
119
  }
120
+ const { execSync } = await import(nodeModule);
121
+ return execSync(fullCmd, execOptions).toString().trim();
45
122
  } catch (err) {
46
123
  }
47
124
  try {
48
125
  if (isObject(Deno)) {
49
- const process2 = Deno.run({
50
- cmd: ["git", "branch", "--show-current"],
51
- stdout: "piped",
52
- stderr: "piped"
53
- });
126
+ const process2 = Deno.run({ cmd, stdout: "piped", stderr: "null" });
54
127
  return new TextDecoder().decode(await process2.output()).trim();
55
128
  }
56
129
  } catch (err) {
@@ -59,7 +132,8 @@ async function getGitBranch() {
59
132
 
60
133
  function getAPIKey() {
61
134
  try {
62
- return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
135
+ const { apiKey } = getEnvironment();
136
+ return apiKey;
63
137
  } catch (err) {
64
138
  return void 0;
65
139
  }
@@ -69,12 +143,14 @@ function getFetchImplementation(userFetch) {
69
143
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
70
144
  const fetchImpl = userFetch ?? globalFetch;
71
145
  if (!fetchImpl) {
72
- throw new Error(`The \`fetch\` option passed to the Xata client is resolving to a falsy value and may not be correctly imported.`);
146
+ throw new Error(
147
+ `Couldn't find \`fetch\`. Install a fetch implementation such as \`node-fetch\` and pass it explicitly.`
148
+ );
73
149
  }
74
150
  return fetchImpl;
75
151
  }
76
152
 
77
- const VERSION = "0.0.0-alpha.vf45a2df";
153
+ const VERSION = "0.0.0-alpha.vf4752f8";
78
154
 
79
155
  class ErrorWithCause extends Error {
80
156
  constructor(message, options) {
@@ -125,7 +201,10 @@ const resolveUrl = (url, queryParams = {}, pathParams = {}) => {
125
201
  }, {});
126
202
  const query = new URLSearchParams(cleanQueryParams).toString();
127
203
  const queryString = query.length > 0 ? `?${query}` : "";
128
- return url.replace(/\{\w*\}/g, (key) => pathParams[key.slice(1, -1)]) + queryString;
204
+ const cleanPathParams = Object.entries(pathParams).reduce((acc, [key, value]) => {
205
+ return { ...acc, [key]: encodeURIComponent(String(value ?? "")).replace("%3A", ":") };
206
+ }, {});
207
+ return url.replace(/\{\w*\}/g, (key) => cleanPathParams[key.slice(1, -1)]) + queryString;
129
208
  };
130
209
  function buildBaseUrl({
131
210
  path,
@@ -133,10 +212,10 @@ function buildBaseUrl({
133
212
  apiUrl,
134
213
  pathParams
135
214
  }) {
136
- if (!pathParams?.workspace)
215
+ if (pathParams?.workspace === void 0)
137
216
  return `${apiUrl}${path}`;
138
217
  const url = typeof workspacesApiUrl === "string" ? `${workspacesApiUrl}${path}` : workspacesApiUrl(path, pathParams);
139
- return url.replace("{workspaceId}", pathParams.workspace);
218
+ return url.replace("{workspaceId}", String(pathParams.workspace));
140
219
  }
141
220
  function hostHeader(url) {
142
221
  const pattern = /.*:\/\/(?<host>[^/]+).*/;
@@ -153,34 +232,61 @@ async function fetch$1({
153
232
  fetchImpl,
154
233
  apiKey,
155
234
  apiUrl,
156
- workspacesApiUrl
235
+ workspacesApiUrl,
236
+ trace
157
237
  }) {
158
- const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
159
- const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
160
- const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
161
- const response = await fetchImpl(url, {
162
- method: method.toUpperCase(),
163
- body: body ? JSON.stringify(body) : void 0,
164
- headers: {
165
- "Content-Type": "application/json",
166
- "User-Agent": `Xata client-ts/${VERSION}`,
167
- ...headers,
168
- ...hostHeader(fullUrl),
169
- Authorization: `Bearer ${apiKey}`
170
- }
171
- });
172
- if (response.status === 204) {
173
- return {};
174
- }
175
- const requestId = response.headers?.get("x-request-id") ?? void 0;
238
+ return trace(
239
+ `${method.toUpperCase()} ${path}`,
240
+ async ({ setAttributes }) => {
241
+ const baseUrl = buildBaseUrl({ path, workspacesApiUrl, pathParams, apiUrl });
242
+ const fullUrl = resolveUrl(baseUrl, queryParams, pathParams);
243
+ const url = fullUrl.includes("localhost") ? fullUrl.replace(/^[^.]+\./, "http://") : fullUrl;
244
+ setAttributes({
245
+ [TraceAttributes.HTTP_URL]: url,
246
+ [TraceAttributes.HTTP_TARGET]: resolveUrl(path, queryParams, pathParams)
247
+ });
248
+ const response = await fetchImpl(url, {
249
+ method: method.toUpperCase(),
250
+ body: body ? JSON.stringify(body) : void 0,
251
+ headers: {
252
+ "Content-Type": "application/json",
253
+ "User-Agent": `Xata client-ts/${VERSION}`,
254
+ ...headers,
255
+ ...hostHeader(fullUrl),
256
+ Authorization: `Bearer ${apiKey}`
257
+ }
258
+ });
259
+ if (response.status === 204) {
260
+ return {};
261
+ }
262
+ const { host, protocol } = parseUrl(response.url);
263
+ const requestId = response.headers?.get("x-request-id") ?? void 0;
264
+ setAttributes({
265
+ [TraceAttributes.KIND]: "http",
266
+ [TraceAttributes.HTTP_REQUEST_ID]: requestId,
267
+ [TraceAttributes.HTTP_STATUS_CODE]: response.status,
268
+ [TraceAttributes.HTTP_HOST]: host,
269
+ [TraceAttributes.HTTP_SCHEME]: protocol?.replace(":", "")
270
+ });
271
+ try {
272
+ const jsonResponse = await response.json();
273
+ if (response.ok) {
274
+ return jsonResponse;
275
+ }
276
+ throw new FetcherError(response.status, jsonResponse, requestId);
277
+ } catch (error) {
278
+ throw new FetcherError(response.status, error, requestId);
279
+ }
280
+ },
281
+ { [TraceAttributes.HTTP_METHOD]: method.toUpperCase(), [TraceAttributes.HTTP_ROUTE]: path }
282
+ );
283
+ }
284
+ function parseUrl(url) {
176
285
  try {
177
- const jsonResponse = await response.json();
178
- if (response.ok) {
179
- return jsonResponse;
180
- }
181
- throw new FetcherError(response.status, jsonResponse, requestId);
286
+ const { host, protocol } = new URL(url);
287
+ return { host, protocol };
182
288
  } catch (error) {
183
- throw new FetcherError(response.status, error, requestId);
289
+ return {};
184
290
  }
185
291
  }
186
292
 
@@ -239,6 +345,7 @@ const removeWorkspaceMember = (variables) => fetch$1({
239
345
  ...variables
240
346
  });
241
347
  const inviteWorkspaceMember = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites", method: "post", ...variables });
348
+ const updateWorkspaceMemberInvite = (variables) => fetch$1({ url: "/workspaces/{workspaceId}/invites/{inviteId}", method: "patch", ...variables });
242
349
  const cancelWorkspaceMemberInvite = (variables) => fetch$1({
243
350
  url: "/workspaces/{workspaceId}/invites/{inviteId}",
244
351
  method: "delete",
@@ -274,6 +381,12 @@ const deleteDatabase = (variables) => fetch$1({
274
381
  method: "delete",
275
382
  ...variables
276
383
  });
384
+ const getDatabaseMetadata = (variables) => fetch$1({
385
+ url: "/dbs/{dbName}/metadata",
386
+ method: "get",
387
+ ...variables
388
+ });
389
+ const patchDatabaseMetadata = (variables) => fetch$1({ url: "/dbs/{dbName}/metadata", method: "patch", ...variables });
277
390
  const getGitBranchesMapping = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "get", ...variables });
278
391
  const addGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "post", ...variables });
279
392
  const removeGitBranchesEntry = (variables) => fetch$1({ url: "/dbs/{dbName}/gitBranches", method: "delete", ...variables });
@@ -282,16 +395,28 @@ const resolveBranch = (variables) => fetch$1({
282
395
  method: "get",
283
396
  ...variables
284
397
  });
285
- const getBranchDetails = (variables) => fetch$1({
286
- url: "/db/{dbBranchName}",
398
+ const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
399
+ const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
400
+ const getMigrationRequest = (variables) => fetch$1({
401
+ url: "/dbs/{dbName}/migrations/{mrNumber}",
287
402
  method: "get",
288
403
  ...variables
289
404
  });
290
- const createBranch = (variables) => fetch$1({
405
+ const updateMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}", method: "patch", ...variables });
406
+ const listMigrationRequestsCommits = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/commits", method: "post", ...variables });
407
+ const compareMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/compare", method: "post", ...variables });
408
+ const getMigrationRequestIsMerged = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/{mrNumber}/merge", method: "get", ...variables });
409
+ const mergeMigrationRequest = (variables) => fetch$1({
410
+ url: "/dbs/{dbName}/migrations/{mrNumber}/merge",
411
+ method: "post",
412
+ ...variables
413
+ });
414
+ const getBranchDetails = (variables) => fetch$1({
291
415
  url: "/db/{dbBranchName}",
292
- method: "put",
416
+ method: "get",
293
417
  ...variables
294
418
  });
419
+ const createBranch = (variables) => fetch$1({ url: "/db/{dbBranchName}", method: "put", ...variables });
295
420
  const deleteBranch = (variables) => fetch$1({
296
421
  url: "/db/{dbBranchName}",
297
422
  method: "delete",
@@ -310,6 +435,16 @@ const getBranchMetadata = (variables) => fetch$1({
310
435
  const getBranchMigrationHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations", method: "get", ...variables });
311
436
  const executeBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/execute", method: "post", ...variables });
312
437
  const getBranchMigrationPlan = (variables) => fetch$1({ url: "/db/{dbBranchName}/migrations/plan", method: "post", ...variables });
438
+ const compareBranchWithUserSchema = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare", method: "post", ...variables });
439
+ const compareBranchSchemas = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/compare/{branchName}", method: "post", ...variables });
440
+ const updateBranchSchema = (variables) => fetch$1({
441
+ url: "/db/{dbBranchName}/schema/update",
442
+ method: "post",
443
+ ...variables
444
+ });
445
+ const previewBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/preview", method: "post", ...variables });
446
+ const applyBranchSchemaEdit = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/apply", method: "post", ...variables });
447
+ const getBranchSchemaHistory = (variables) => fetch$1({ url: "/db/{dbBranchName}/schema/history", method: "post", ...variables });
313
448
  const getBranchStats = (variables) => fetch$1({
314
449
  url: "/db/{dbBranchName}/stats",
315
450
  method: "get",
@@ -365,11 +500,7 @@ const updateColumn = (variables) => fetch$1({
365
500
  method: "patch",
366
501
  ...variables
367
502
  });
368
- const insertRecord = (variables) => fetch$1({
369
- url: "/db/{dbBranchName}/tables/{tableName}/data",
370
- method: "post",
371
- ...variables
372
- });
503
+ const insertRecord = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data", method: "post", ...variables });
373
504
  const insertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "put", ...variables });
374
505
  const updateRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "patch", ...variables });
375
506
  const upsertRecordWithID = (variables) => fetch$1({ url: "/db/{dbBranchName}/tables/{tableName}/data/{recordId}", method: "post", ...variables });
@@ -411,6 +542,7 @@ const operationsByTag = {
411
542
  updateWorkspaceMemberRole,
412
543
  removeWorkspaceMember,
413
544
  inviteWorkspaceMember,
545
+ updateWorkspaceMemberInvite,
414
546
  cancelWorkspaceMemberInvite,
415
547
  resendWorkspaceMemberInvite,
416
548
  acceptWorkspaceMemberInvite
@@ -419,6 +551,8 @@ const operationsByTag = {
419
551
  getDatabaseList,
420
552
  createDatabase,
421
553
  deleteDatabase,
554
+ getDatabaseMetadata,
555
+ patchDatabaseMetadata,
422
556
  getGitBranchesMapping,
423
557
  addGitBranchesEntry,
424
558
  removeGitBranchesEntry,
@@ -431,10 +565,28 @@ const operationsByTag = {
431
565
  deleteBranch,
432
566
  updateBranchMetadata,
433
567
  getBranchMetadata,
568
+ getBranchStats
569
+ },
570
+ migrationRequests: {
571
+ listMigrationRequests,
572
+ createMigrationRequest,
573
+ getMigrationRequest,
574
+ updateMigrationRequest,
575
+ listMigrationRequestsCommits,
576
+ compareMigrationRequest,
577
+ getMigrationRequestIsMerged,
578
+ mergeMigrationRequest
579
+ },
580
+ branchSchema: {
434
581
  getBranchMigrationHistory,
435
582
  executeBranchMigrationPlan,
436
583
  getBranchMigrationPlan,
437
- getBranchStats
584
+ compareBranchWithUserSchema,
585
+ compareBranchSchemas,
586
+ updateBranchSchema,
587
+ previewBranchSchemaEdit,
588
+ applyBranchSchemaEdit,
589
+ getBranchSchemaHistory
438
590
  },
439
591
  table: {
440
592
  createTable,
@@ -463,9 +615,9 @@ const operationsByTag = {
463
615
  };
464
616
 
465
617
  function getHostUrl(provider, type) {
466
- if (isValidAlias(provider)) {
618
+ if (isHostProviderAlias(provider)) {
467
619
  return providers[provider][type];
468
- } else if (isValidBuilder(provider)) {
620
+ } else if (isHostProviderBuilder(provider)) {
469
621
  return provider[type];
470
622
  }
471
623
  throw new Error("Invalid API provider");
@@ -480,10 +632,10 @@ const providers = {
480
632
  workspaces: "https://{workspaceId}.staging.xatabase.co"
481
633
  }
482
634
  };
483
- function isValidAlias(alias) {
635
+ function isHostProviderAlias(alias) {
484
636
  return isString(alias) && Object.keys(providers).includes(alias);
485
637
  }
486
- function isValidBuilder(builder) {
638
+ function isHostProviderBuilder(builder) {
487
639
  return isObject(builder) && isString(builder.main) && isString(builder.workspaces);
488
640
  }
489
641
 
@@ -500,7 +652,7 @@ var __privateAdd$7 = (obj, member, value) => {
500
652
  throw TypeError("Cannot add the same private member more than once");
501
653
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
502
654
  };
503
- var __privateSet$6 = (obj, member, value, setter) => {
655
+ var __privateSet$7 = (obj, member, value, setter) => {
504
656
  __accessCheck$7(obj, member, "write to private field");
505
657
  setter ? setter.call(obj, value) : member.set(obj, value);
506
658
  return value;
@@ -511,15 +663,17 @@ class XataApiClient {
511
663
  __privateAdd$7(this, _extraProps, void 0);
512
664
  __privateAdd$7(this, _namespaces, {});
513
665
  const provider = options.host ?? "production";
514
- const apiKey = options?.apiKey ?? getAPIKey();
666
+ const apiKey = options.apiKey ?? getAPIKey();
667
+ const trace = options.trace ?? defaultTrace;
515
668
  if (!apiKey) {
516
669
  throw new Error("Could not resolve a valid apiKey");
517
670
  }
518
- __privateSet$6(this, _extraProps, {
671
+ __privateSet$7(this, _extraProps, {
519
672
  apiUrl: getHostUrl(provider, "main"),
520
673
  workspacesApiUrl: getHostUrl(provider, "workspaces"),
521
674
  fetchImpl: getFetchImplementation(options.fetch),
522
- apiKey
675
+ apiKey,
676
+ trace
523
677
  });
524
678
  }
525
679
  get user() {
@@ -552,6 +706,16 @@ class XataApiClient {
552
706
  __privateGet$7(this, _namespaces).records = new RecordsApi(__privateGet$7(this, _extraProps));
553
707
  return __privateGet$7(this, _namespaces).records;
554
708
  }
709
+ get migrationRequests() {
710
+ if (!__privateGet$7(this, _namespaces).migrationRequests)
711
+ __privateGet$7(this, _namespaces).migrationRequests = new MigrationRequestsApi(__privateGet$7(this, _extraProps));
712
+ return __privateGet$7(this, _namespaces).migrationRequests;
713
+ }
714
+ get branchSchema() {
715
+ if (!__privateGet$7(this, _namespaces).branchSchema)
716
+ __privateGet$7(this, _namespaces).branchSchema = new BranchSchemaApi(__privateGet$7(this, _extraProps));
717
+ return __privateGet$7(this, _namespaces).branchSchema;
718
+ }
555
719
  }
556
720
  _extraProps = new WeakMap();
557
721
  _namespaces = new WeakMap();
@@ -642,6 +806,13 @@ class WorkspaceApi {
642
806
  ...this.extraProps
643
807
  });
644
808
  }
809
+ updateWorkspaceMemberInvite(workspaceId, inviteId, role) {
810
+ return operationsByTag.workspaces.updateWorkspaceMemberInvite({
811
+ pathParams: { workspaceId, inviteId },
812
+ body: { role },
813
+ ...this.extraProps
814
+ });
815
+ }
645
816
  cancelWorkspaceMemberInvite(workspaceId, inviteId) {
646
817
  return operationsByTag.workspaces.cancelWorkspaceMemberInvite({
647
818
  pathParams: { workspaceId, inviteId },
@@ -684,6 +855,12 @@ class DatabaseApi {
684
855
  ...this.extraProps
685
856
  });
686
857
  }
858
+ getDatabaseMetadata(workspace, dbName) {
859
+ return operationsByTag.database.getDatabaseMetadata({
860
+ pathParams: { workspace, dbName },
861
+ ...this.extraProps
862
+ });
863
+ }
687
864
  getGitBranchesMapping(workspace, dbName) {
688
865
  return operationsByTag.database.getGitBranchesMapping({
689
866
  pathParams: { workspace, dbName },
@@ -755,27 +932,6 @@ class BranchApi {
755
932
  ...this.extraProps
756
933
  });
757
934
  }
758
- getBranchMigrationHistory(workspace, database, branch, options = {}) {
759
- return operationsByTag.branch.getBranchMigrationHistory({
760
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
761
- body: options,
762
- ...this.extraProps
763
- });
764
- }
765
- executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
766
- return operationsByTag.branch.executeBranchMigrationPlan({
767
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
768
- body: migrationPlan,
769
- ...this.extraProps
770
- });
771
- }
772
- getBranchMigrationPlan(workspace, database, branch, schema) {
773
- return operationsByTag.branch.getBranchMigrationPlan({
774
- pathParams: { workspace, dbBranchName: `${database}:${branch}` },
775
- body: schema,
776
- ...this.extraProps
777
- });
778
- }
779
935
  getBranchStats(workspace, database, branch) {
780
936
  return operationsByTag.branch.getBranchStats({
781
937
  pathParams: { workspace, dbBranchName: `${database}:${branch}` },
@@ -856,9 +1012,10 @@ class RecordsApi {
856
1012
  constructor(extraProps) {
857
1013
  this.extraProps = extraProps;
858
1014
  }
859
- insertRecord(workspace, database, branch, tableName, record) {
1015
+ insertRecord(workspace, database, branch, tableName, record, options = {}) {
860
1016
  return operationsByTag.records.insertRecord({
861
1017
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1018
+ queryParams: options,
862
1019
  body: record,
863
1020
  ...this.extraProps
864
1021
  });
@@ -887,21 +1044,24 @@ class RecordsApi {
887
1044
  ...this.extraProps
888
1045
  });
889
1046
  }
890
- deleteRecord(workspace, database, branch, tableName, recordId) {
1047
+ deleteRecord(workspace, database, branch, tableName, recordId, options = {}) {
891
1048
  return operationsByTag.records.deleteRecord({
892
1049
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1050
+ queryParams: options,
893
1051
  ...this.extraProps
894
1052
  });
895
1053
  }
896
1054
  getRecord(workspace, database, branch, tableName, recordId, options = {}) {
897
1055
  return operationsByTag.records.getRecord({
898
1056
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName, recordId },
1057
+ queryParams: options,
899
1058
  ...this.extraProps
900
1059
  });
901
1060
  }
902
- bulkInsertTableRecords(workspace, database, branch, tableName, records) {
1061
+ bulkInsertTableRecords(workspace, database, branch, tableName, records, options = {}) {
903
1062
  return operationsByTag.records.bulkInsertTableRecords({
904
1063
  pathParams: { workspace, dbBranchName: `${database}:${branch}`, tableName },
1064
+ queryParams: options,
905
1065
  body: { records },
906
1066
  ...this.extraProps
907
1067
  });
@@ -928,6 +1088,131 @@ class RecordsApi {
928
1088
  });
929
1089
  }
930
1090
  }
1091
+ class MigrationRequestsApi {
1092
+ constructor(extraProps) {
1093
+ this.extraProps = extraProps;
1094
+ }
1095
+ listMigrationRequests(workspace, database, options = {}) {
1096
+ return operationsByTag.migrationRequests.listMigrationRequests({
1097
+ pathParams: { workspace, dbName: database },
1098
+ body: options,
1099
+ ...this.extraProps
1100
+ });
1101
+ }
1102
+ createMigrationRequest(workspace, database, options) {
1103
+ return operationsByTag.migrationRequests.createMigrationRequest({
1104
+ pathParams: { workspace, dbName: database },
1105
+ body: options,
1106
+ ...this.extraProps
1107
+ });
1108
+ }
1109
+ getMigrationRequest(workspace, database, migrationRequest) {
1110
+ return operationsByTag.migrationRequests.getMigrationRequest({
1111
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1112
+ ...this.extraProps
1113
+ });
1114
+ }
1115
+ updateMigrationRequest(workspace, database, migrationRequest, options) {
1116
+ return operationsByTag.migrationRequests.updateMigrationRequest({
1117
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1118
+ body: options,
1119
+ ...this.extraProps
1120
+ });
1121
+ }
1122
+ listMigrationRequestsCommits(workspace, database, migrationRequest, options = {}) {
1123
+ return operationsByTag.migrationRequests.listMigrationRequestsCommits({
1124
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1125
+ body: options,
1126
+ ...this.extraProps
1127
+ });
1128
+ }
1129
+ compareMigrationRequest(workspace, database, migrationRequest) {
1130
+ return operationsByTag.migrationRequests.compareMigrationRequest({
1131
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1132
+ ...this.extraProps
1133
+ });
1134
+ }
1135
+ getMigrationRequestIsMerged(workspace, database, migrationRequest) {
1136
+ return operationsByTag.migrationRequests.getMigrationRequestIsMerged({
1137
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1138
+ ...this.extraProps
1139
+ });
1140
+ }
1141
+ mergeMigrationRequest(workspace, database, migrationRequest) {
1142
+ return operationsByTag.migrationRequests.mergeMigrationRequest({
1143
+ pathParams: { workspace, dbName: database, mrNumber: migrationRequest },
1144
+ ...this.extraProps
1145
+ });
1146
+ }
1147
+ }
1148
+ class BranchSchemaApi {
1149
+ constructor(extraProps) {
1150
+ this.extraProps = extraProps;
1151
+ }
1152
+ getBranchMigrationHistory(workspace, database, branch, options = {}) {
1153
+ return operationsByTag.branchSchema.getBranchMigrationHistory({
1154
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1155
+ body: options,
1156
+ ...this.extraProps
1157
+ });
1158
+ }
1159
+ executeBranchMigrationPlan(workspace, database, branch, migrationPlan) {
1160
+ return operationsByTag.branchSchema.executeBranchMigrationPlan({
1161
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1162
+ body: migrationPlan,
1163
+ ...this.extraProps
1164
+ });
1165
+ }
1166
+ getBranchMigrationPlan(workspace, database, branch, schema) {
1167
+ return operationsByTag.branchSchema.getBranchMigrationPlan({
1168
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1169
+ body: schema,
1170
+ ...this.extraProps
1171
+ });
1172
+ }
1173
+ compareBranchWithUserSchema(workspace, database, branch, schema) {
1174
+ return operationsByTag.branchSchema.compareBranchWithUserSchema({
1175
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1176
+ body: { schema },
1177
+ ...this.extraProps
1178
+ });
1179
+ }
1180
+ compareBranchSchemas(workspace, database, branch, branchName, schema) {
1181
+ return operationsByTag.branchSchema.compareBranchSchemas({
1182
+ pathParams: { workspace, dbBranchName: `${database}:${branch}`, branchName },
1183
+ body: { schema },
1184
+ ...this.extraProps
1185
+ });
1186
+ }
1187
+ updateBranchSchema(workspace, database, branch, migration) {
1188
+ return operationsByTag.branchSchema.updateBranchSchema({
1189
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1190
+ body: migration,
1191
+ ...this.extraProps
1192
+ });
1193
+ }
1194
+ previewBranchSchemaEdit(workspace, database, branch, migration) {
1195
+ return operationsByTag.branchSchema.previewBranchSchemaEdit({
1196
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1197
+ body: migration,
1198
+ ...this.extraProps
1199
+ });
1200
+ }
1201
+ applyBranchSchemaEdit(workspace, database, branch, edits) {
1202
+ return operationsByTag.branchSchema.applyBranchSchemaEdit({
1203
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1204
+ body: { edits },
1205
+ ...this.extraProps
1206
+ });
1207
+ }
1208
+ getBranchSchemaHistory(workspace, database, branch, options = {}) {
1209
+ return operationsByTag.branchSchema.getBranchSchemaHistory({
1210
+ pathParams: { workspace, dbBranchName: `${database}:${branch}` },
1211
+ body: options,
1212
+ ...this.extraProps
1213
+ });
1214
+ }
1215
+ }
931
1216
 
932
1217
  class XataApiPlugin {
933
1218
  async build(options) {
@@ -952,7 +1237,7 @@ var __privateAdd$6 = (obj, member, value) => {
952
1237
  throw TypeError("Cannot add the same private member more than once");
953
1238
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
954
1239
  };
955
- var __privateSet$5 = (obj, member, value, setter) => {
1240
+ var __privateSet$6 = (obj, member, value, setter) => {
956
1241
  __accessCheck$6(obj, member, "write to private field");
957
1242
  setter ? setter.call(obj, value) : member.set(obj, value);
958
1243
  return value;
@@ -961,7 +1246,7 @@ var _query, _page;
961
1246
  class Page {
962
1247
  constructor(query, meta, records = []) {
963
1248
  __privateAdd$6(this, _query, void 0);
964
- __privateSet$5(this, _query, query);
1249
+ __privateSet$6(this, _query, query);
965
1250
  this.meta = meta;
966
1251
  this.records = new RecordArray(this, records);
967
1252
  }
@@ -990,10 +1275,10 @@ function isCursorPaginationOptions(options) {
990
1275
  return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
991
1276
  }
992
1277
  const _RecordArray = class extends Array {
993
- constructor(page, overrideRecords) {
994
- super(..._RecordArray.parseConstructorParams(page, overrideRecords));
1278
+ constructor(...args) {
1279
+ super(..._RecordArray.parseConstructorParams(...args));
995
1280
  __privateAdd$6(this, _page, void 0);
996
- __privateSet$5(this, _page, page);
1281
+ __privateSet$6(this, _page, isObject(args[0]?.meta) ? args[0] : { meta: { page: { cursor: "", more: false } }, records: [] });
997
1282
  }
998
1283
  static parseConstructorParams(...args) {
999
1284
  if (args.length === 1 && typeof args[0] === "number") {
@@ -1005,6 +1290,12 @@ const _RecordArray = class extends Array {
1005
1290
  }
1006
1291
  return new Array(...args);
1007
1292
  }
1293
+ toArray() {
1294
+ return new Array(...this);
1295
+ }
1296
+ map(callbackfn, thisArg) {
1297
+ return this.toArray().map(callbackfn, thisArg);
1298
+ }
1008
1299
  async nextPage(size, offset) {
1009
1300
  const newPage = await __privateGet$6(this, _page).nextPage(size, offset);
1010
1301
  return new _RecordArray(newPage);
@@ -1041,7 +1332,7 @@ var __privateAdd$5 = (obj, member, value) => {
1041
1332
  throw TypeError("Cannot add the same private member more than once");
1042
1333
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1043
1334
  };
1044
- var __privateSet$4 = (obj, member, value, setter) => {
1335
+ var __privateSet$5 = (obj, member, value, setter) => {
1045
1336
  __accessCheck$5(obj, member, "write to private field");
1046
1337
  setter ? setter.call(obj, value) : member.set(obj, value);
1047
1338
  return value;
@@ -1054,11 +1345,11 @@ const _Query = class {
1054
1345
  __privateAdd$5(this, _data, { filter: {} });
1055
1346
  this.meta = { page: { cursor: "start", more: true } };
1056
1347
  this.records = new RecordArray(this, []);
1057
- __privateSet$4(this, _table$1, table);
1348
+ __privateSet$5(this, _table$1, table);
1058
1349
  if (repository) {
1059
- __privateSet$4(this, _repository, repository);
1350
+ __privateSet$5(this, _repository, repository);
1060
1351
  } else {
1061
- __privateSet$4(this, _repository, this);
1352
+ __privateSet$5(this, _repository, this);
1062
1353
  }
1063
1354
  const parent = cleanParent(data, rawParent);
1064
1355
  __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
@@ -1105,21 +1396,34 @@ const _Query = class {
1105
1396
  }
1106
1397
  filter(a, b) {
1107
1398
  if (arguments.length === 1) {
1108
- const constraints = Object.entries(a).map(([column, constraint]) => ({ [column]: constraint }));
1399
+ const constraints = Object.entries(a ?? {}).map(([column, constraint]) => ({ [column]: constraint }));
1109
1400
  const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1110
1401
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1111
1402
  } else {
1112
- const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat([{ [a]: b }]));
1403
+ const constraints = isDefined(a) && isDefined(b) ? [{ [a]: this.defaultFilter(a, b) }] : void 0;
1404
+ const $all = compact([__privateGet$5(this, _data).filter?.$all].flat().concat(constraints));
1113
1405
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { filter: { $all } }, __privateGet$5(this, _data));
1114
1406
  }
1115
1407
  }
1116
- sort(column, direction) {
1408
+ defaultFilter(column, value) {
1409
+ const columnType = __privateGet$5(this, _table$1).schema?.columns.find(({ name }) => name === column)?.type;
1410
+ if (columnType === "multiple" && (isString(value) || isStringArray(value))) {
1411
+ return { $includes: value };
1412
+ }
1413
+ return value;
1414
+ }
1415
+ sort(column, direction = "asc") {
1117
1416
  const originalSort = [__privateGet$5(this, _data).sort ?? []].flat();
1118
1417
  const sort = [...originalSort, { column, direction }];
1119
1418
  return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { sort }, __privateGet$5(this, _data));
1120
1419
  }
1121
1420
  select(columns) {
1122
- return new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), { columns }, __privateGet$5(this, _data));
1421
+ return new _Query(
1422
+ __privateGet$5(this, _repository),
1423
+ __privateGet$5(this, _table$1),
1424
+ { columns },
1425
+ __privateGet$5(this, _data)
1426
+ );
1123
1427
  }
1124
1428
  getPaginated(options = {}) {
1125
1429
  const query = new _Query(__privateGet$5(this, _repository), __privateGet$5(this, _table$1), options, __privateGet$5(this, _data));
@@ -1235,7 +1539,7 @@ var __privateAdd$4 = (obj, member, value) => {
1235
1539
  throw TypeError("Cannot add the same private member more than once");
1236
1540
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1237
1541
  };
1238
- var __privateSet$3 = (obj, member, value, setter) => {
1542
+ var __privateSet$4 = (obj, member, value, setter) => {
1239
1543
  __accessCheck$4(obj, member, "write to private field");
1240
1544
  setter ? setter.call(obj, value) : member.set(obj, value);
1241
1545
  return value;
@@ -1244,202 +1548,228 @@ var __privateMethod$2 = (obj, member, method) => {
1244
1548
  __accessCheck$4(obj, member, "access private method");
1245
1549
  return method;
1246
1550
  };
1247
- var _table, _getFetchProps, _cache, _schema$1, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _invalidateCache, invalidateCache_fn, _setCacheRecord, setCacheRecord_fn, _getCacheRecord, getCacheRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchema$1, getSchema_fn$1;
1551
+ var _table, _getFetchProps, _db, _cache, _schemaTables$2, _trace, _insertRecordWithoutId, insertRecordWithoutId_fn, _insertRecordWithId, insertRecordWithId_fn, _bulkInsertTableRecords, bulkInsertTableRecords_fn, _updateRecordWithID, updateRecordWithID_fn, _upsertRecordWithID, upsertRecordWithID_fn, _deleteRecord, deleteRecord_fn, _setCacheQuery, setCacheQuery_fn, _getCacheQuery, getCacheQuery_fn, _getSchemaTables$1, getSchemaTables_fn$1;
1248
1552
  class Repository extends Query {
1249
1553
  }
1250
1554
  class RestRepository extends Query {
1251
1555
  constructor(options) {
1252
- super(null, options.table, {});
1556
+ super(
1557
+ null,
1558
+ { name: options.table, schema: options.schemaTables?.find((table) => table.name === options.table) },
1559
+ {}
1560
+ );
1253
1561
  __privateAdd$4(this, _insertRecordWithoutId);
1254
1562
  __privateAdd$4(this, _insertRecordWithId);
1255
1563
  __privateAdd$4(this, _bulkInsertTableRecords);
1256
1564
  __privateAdd$4(this, _updateRecordWithID);
1257
1565
  __privateAdd$4(this, _upsertRecordWithID);
1258
1566
  __privateAdd$4(this, _deleteRecord);
1259
- __privateAdd$4(this, _invalidateCache);
1260
- __privateAdd$4(this, _setCacheRecord);
1261
- __privateAdd$4(this, _getCacheRecord);
1262
1567
  __privateAdd$4(this, _setCacheQuery);
1263
1568
  __privateAdd$4(this, _getCacheQuery);
1264
- __privateAdd$4(this, _getSchema$1);
1569
+ __privateAdd$4(this, _getSchemaTables$1);
1265
1570
  __privateAdd$4(this, _table, void 0);
1266
1571
  __privateAdd$4(this, _getFetchProps, void 0);
1572
+ __privateAdd$4(this, _db, void 0);
1267
1573
  __privateAdd$4(this, _cache, void 0);
1268
- __privateAdd$4(this, _schema$1, void 0);
1269
- __privateSet$3(this, _table, options.table);
1270
- __privateSet$3(this, _getFetchProps, options.pluginOptions.getFetchProps);
1271
- this.db = options.db;
1272
- __privateSet$3(this, _cache, options.pluginOptions.cache);
1273
- }
1274
- async create(a, b) {
1275
- if (Array.isArray(a)) {
1276
- if (a.length === 0)
1277
- return [];
1278
- const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1279
- await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1280
- return records;
1281
- }
1282
- if (isString(a) && isObject(b)) {
1283
- if (a === "")
1284
- throw new Error("The id can't be empty");
1285
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b);
1286
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1287
- return record;
1288
- }
1289
- if (isObject(a) && isString(a.id)) {
1290
- if (a.id === "")
1291
- throw new Error("The id can't be empty");
1292
- const record = await __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 });
1293
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1294
- return record;
1295
- }
1296
- if (isObject(a)) {
1297
- const record = await __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a);
1298
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1299
- return record;
1300
- }
1301
- throw new Error("Invalid arguments for create method");
1302
- }
1303
- async read(a) {
1304
- if (Array.isArray(a)) {
1305
- if (a.length === 0)
1306
- return [];
1307
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1308
- return this.getAll({ filter: { id: { $any: ids } } });
1309
- }
1310
- const id = isString(a) ? a : a.id;
1311
- if (isString(id)) {
1312
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, id);
1313
- if (cacheRecord)
1314
- return cacheRecord;
1315
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1316
- try {
1317
- const response = await getRecord({
1318
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: id },
1319
- ...fetchProps
1320
- });
1321
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1322
- return initObject(this.db, schema, __privateGet$4(this, _table), response);
1323
- } catch (e) {
1324
- if (isObject(e) && e.status === 404) {
1325
- return null;
1574
+ __privateAdd$4(this, _schemaTables$2, void 0);
1575
+ __privateAdd$4(this, _trace, void 0);
1576
+ __privateSet$4(this, _table, options.table);
1577
+ __privateSet$4(this, _getFetchProps, options.pluginOptions.getFetchProps);
1578
+ __privateSet$4(this, _db, options.db);
1579
+ __privateSet$4(this, _cache, options.pluginOptions.cache);
1580
+ __privateSet$4(this, _schemaTables$2, options.schemaTables);
1581
+ const trace = options.pluginOptions.trace ?? defaultTrace;
1582
+ __privateSet$4(this, _trace, async (name, fn, options2 = {}) => {
1583
+ return trace(name, fn, {
1584
+ ...options2,
1585
+ [TraceAttributes.TABLE]: __privateGet$4(this, _table),
1586
+ [TraceAttributes.KIND]: "sdk-operation",
1587
+ [TraceAttributes.VERSION]: VERSION
1588
+ });
1589
+ });
1590
+ }
1591
+ async create(a, b, c) {
1592
+ return __privateGet$4(this, _trace).call(this, "create", async () => {
1593
+ if (Array.isArray(a)) {
1594
+ if (a.length === 0)
1595
+ return [];
1596
+ const columns = isStringArray(b) ? b : void 0;
1597
+ return __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a, columns);
1598
+ }
1599
+ if (isString(a) && isObject(b)) {
1600
+ if (a === "")
1601
+ throw new Error("The id can't be empty");
1602
+ const columns = isStringArray(c) ? c : void 0;
1603
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a, b, columns);
1604
+ }
1605
+ if (isObject(a) && isString(a.id)) {
1606
+ if (a.id === "")
1607
+ throw new Error("The id can't be empty");
1608
+ const columns = isStringArray(b) ? b : void 0;
1609
+ return __privateMethod$2(this, _insertRecordWithId, insertRecordWithId_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1610
+ }
1611
+ if (isObject(a)) {
1612
+ const columns = isStringArray(b) ? b : void 0;
1613
+ return __privateMethod$2(this, _insertRecordWithoutId, insertRecordWithoutId_fn).call(this, a, columns);
1614
+ }
1615
+ throw new Error("Invalid arguments for create method");
1616
+ });
1617
+ }
1618
+ async read(a, b) {
1619
+ return __privateGet$4(this, _trace).call(this, "read", async () => {
1620
+ const columns = isStringArray(b) ? b : ["*"];
1621
+ if (Array.isArray(a)) {
1622
+ if (a.length === 0)
1623
+ return [];
1624
+ const ids = a.map((item) => extractId(item));
1625
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
1626
+ const dictionary = finalObjects.reduce((acc, object) => {
1627
+ acc[object.id] = object;
1628
+ return acc;
1629
+ }, {});
1630
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1631
+ }
1632
+ const id = extractId(a);
1633
+ if (id) {
1634
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1635
+ try {
1636
+ const response = await getRecord({
1637
+ pathParams: {
1638
+ workspace: "{workspaceId}",
1639
+ dbBranchName: "{dbBranch}",
1640
+ tableName: __privateGet$4(this, _table),
1641
+ recordId: id
1642
+ },
1643
+ queryParams: { columns },
1644
+ ...fetchProps
1645
+ });
1646
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1647
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1648
+ } catch (e) {
1649
+ if (isObject(e) && e.status === 404) {
1650
+ return null;
1651
+ }
1652
+ throw e;
1326
1653
  }
1327
- throw e;
1328
1654
  }
1329
- }
1655
+ return null;
1656
+ });
1330
1657
  }
1331
- async update(a, b) {
1332
- if (Array.isArray(a)) {
1333
- if (a.length === 0)
1334
- return [];
1335
- if (a.length > 100) {
1336
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1658
+ async update(a, b, c) {
1659
+ return __privateGet$4(this, _trace).call(this, "update", async () => {
1660
+ if (Array.isArray(a)) {
1661
+ if (a.length === 0)
1662
+ return [];
1663
+ if (a.length > 100) {
1664
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1665
+ }
1666
+ const columns = isStringArray(b) ? b : ["*"];
1667
+ return Promise.all(a.map((object) => this.update(object, columns)));
1337
1668
  }
1338
- return Promise.all(a.map((object) => this.update(object)));
1339
- }
1340
- if (isString(a) && isObject(b)) {
1341
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1342
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b);
1343
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1344
- return record;
1345
- }
1346
- if (isObject(a) && isString(a.id)) {
1347
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1348
- const record = await __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1349
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1350
- return record;
1351
- }
1352
- throw new Error("Invalid arguments for update method");
1353
- }
1354
- async createOrUpdate(a, b) {
1355
- if (Array.isArray(a)) {
1356
- if (a.length === 0)
1357
- return [];
1358
- if (a.length > 100) {
1359
- console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1669
+ if (isString(a) && isObject(b)) {
1670
+ const columns = isStringArray(c) ? c : void 0;
1671
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a, b, columns);
1360
1672
  }
1361
- return Promise.all(a.map((object) => this.createOrUpdate(object)));
1362
- }
1363
- if (isString(a) && isObject(b)) {
1364
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1365
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b);
1366
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1367
- return record;
1368
- }
1369
- if (isObject(a) && isString(a.id)) {
1370
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1371
- const record = await __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 });
1372
- await __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record);
1373
- return record;
1374
- }
1375
- throw new Error("Invalid arguments for createOrUpdate method");
1376
- }
1377
- async delete(a) {
1378
- if (Array.isArray(a)) {
1379
- if (a.length === 0)
1380
- return;
1381
- if (a.length > 100) {
1382
- console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1673
+ if (isObject(a) && isString(a.id)) {
1674
+ const columns = isStringArray(b) ? b : void 0;
1675
+ return __privateMethod$2(this, _updateRecordWithID, updateRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1383
1676
  }
1384
- await Promise.all(a.map((id) => this.delete(id)));
1385
- return;
1386
- }
1387
- if (isString(a)) {
1388
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1389
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a);
1390
- return;
1391
- }
1392
- if (isObject(a) && isString(a.id)) {
1393
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1394
- await __privateMethod$2(this, _invalidateCache, invalidateCache_fn).call(this, a.id);
1395
- return;
1396
- }
1397
- throw new Error("Invalid arguments for delete method");
1677
+ throw new Error("Invalid arguments for update method");
1678
+ });
1679
+ }
1680
+ async createOrUpdate(a, b, c) {
1681
+ return __privateGet$4(this, _trace).call(this, "createOrUpdate", async () => {
1682
+ if (Array.isArray(a)) {
1683
+ if (a.length === 0)
1684
+ return [];
1685
+ if (a.length > 100) {
1686
+ console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1687
+ }
1688
+ const columns = isStringArray(b) ? b : ["*"];
1689
+ return Promise.all(a.map((object) => this.createOrUpdate(object, columns)));
1690
+ }
1691
+ if (isString(a) && isObject(b)) {
1692
+ const columns = isStringArray(c) ? c : void 0;
1693
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a, b, columns);
1694
+ }
1695
+ if (isObject(a) && isString(a.id)) {
1696
+ const columns = isStringArray(c) ? c : void 0;
1697
+ return __privateMethod$2(this, _upsertRecordWithID, upsertRecordWithID_fn).call(this, a.id, { ...a, id: void 0 }, columns);
1698
+ }
1699
+ throw new Error("Invalid arguments for createOrUpdate method");
1700
+ });
1701
+ }
1702
+ async delete(a, b) {
1703
+ return __privateGet$4(this, _trace).call(this, "delete", async () => {
1704
+ if (Array.isArray(a)) {
1705
+ if (a.length === 0)
1706
+ return [];
1707
+ if (a.length > 100) {
1708
+ console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1709
+ }
1710
+ return Promise.all(a.map((id) => this.delete(id, b)));
1711
+ }
1712
+ if (isString(a)) {
1713
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1714
+ }
1715
+ if (isObject(a) && isString(a.id)) {
1716
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1717
+ }
1718
+ throw new Error("Invalid arguments for delete method");
1719
+ });
1398
1720
  }
1399
1721
  async search(query, options = {}) {
1400
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1401
- const { records } = await searchTable({
1402
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1403
- body: {
1404
- query,
1405
- fuzziness: options.fuzziness,
1406
- highlight: options.highlight,
1407
- filter: options.filter
1408
- },
1409
- ...fetchProps
1722
+ return __privateGet$4(this, _trace).call(this, "search", async () => {
1723
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1724
+ const { records } = await searchTable({
1725
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1726
+ body: {
1727
+ query,
1728
+ fuzziness: options.fuzziness,
1729
+ prefix: options.prefix,
1730
+ highlight: options.highlight,
1731
+ filter: options.filter,
1732
+ boosters: options.boosters
1733
+ },
1734
+ ...fetchProps
1735
+ });
1736
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1737
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1410
1738
  });
1411
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1412
- return records.map((item) => initObject(this.db, schema, __privateGet$4(this, _table), item));
1413
1739
  }
1414
1740
  async query(query) {
1415
- const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1416
- if (cacheQuery)
1417
- return new Page(query, cacheQuery.meta, cacheQuery.records);
1418
- const data = query.getQueryOptions();
1419
- const body = {
1420
- filter: Object.values(data.filter ?? {}).some(Boolean) ? data.filter : void 0,
1421
- sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1422
- page: data.pagination,
1423
- columns: data.columns
1424
- };
1425
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1426
- const { meta, records: objects } = await queryTable({
1427
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1428
- body,
1429
- ...fetchProps
1741
+ return __privateGet$4(this, _trace).call(this, "query", async () => {
1742
+ const cacheQuery = await __privateMethod$2(this, _getCacheQuery, getCacheQuery_fn).call(this, query);
1743
+ if (cacheQuery)
1744
+ return new Page(query, cacheQuery.meta, cacheQuery.records);
1745
+ const data = query.getQueryOptions();
1746
+ const body = {
1747
+ filter: cleanFilter(data.filter),
1748
+ sort: data.sort !== void 0 ? buildSortFilter(data.sort) : void 0,
1749
+ page: data.pagination,
1750
+ columns: data.columns
1751
+ };
1752
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1753
+ const { meta, records: objects } = await queryTable({
1754
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1755
+ body,
1756
+ ...fetchProps
1757
+ });
1758
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1759
+ const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1760
+ await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1761
+ return new Page(query, meta, records);
1430
1762
  });
1431
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1432
- const records = objects.map((record) => initObject(this.db, schema, __privateGet$4(this, _table), record));
1433
- await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1434
- return new Page(query, meta, records);
1435
1763
  }
1436
1764
  }
1437
1765
  _table = new WeakMap();
1438
1766
  _getFetchProps = new WeakMap();
1767
+ _db = new WeakMap();
1439
1768
  _cache = new WeakMap();
1440
- _schema$1 = new WeakMap();
1769
+ _schemaTables$2 = new WeakMap();
1770
+ _trace = new WeakMap();
1441
1771
  _insertRecordWithoutId = new WeakSet();
1442
- insertRecordWithoutId_fn = async function(object) {
1772
+ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1443
1773
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1444
1774
  const record = transformObjectLinks(object);
1445
1775
  const response = await insertRecord({
@@ -1448,17 +1778,15 @@ insertRecordWithoutId_fn = async function(object) {
1448
1778
  dbBranchName: "{dbBranch}",
1449
1779
  tableName: __privateGet$4(this, _table)
1450
1780
  },
1781
+ queryParams: { columns },
1451
1782
  body: record,
1452
1783
  ...fetchProps
1453
1784
  });
1454
- const finalObject = await this.read(response.id);
1455
- if (!finalObject) {
1456
- throw new Error("The server failed to save the record");
1457
- }
1458
- return finalObject;
1785
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1786
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1459
1787
  };
1460
1788
  _insertRecordWithId = new WeakSet();
1461
- insertRecordWithId_fn = async function(recordId, object) {
1789
+ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1462
1790
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1463
1791
  const record = transformObjectLinks(object);
1464
1792
  const response = await insertRecordWithID({
@@ -1469,92 +1797,78 @@ insertRecordWithId_fn = async function(recordId, object) {
1469
1797
  recordId
1470
1798
  },
1471
1799
  body: record,
1472
- queryParams: { createOnly: true },
1800
+ queryParams: { createOnly: true, columns },
1473
1801
  ...fetchProps
1474
1802
  });
1475
- const finalObject = await this.read(response.id);
1476
- if (!finalObject) {
1477
- throw new Error("The server failed to save the record");
1478
- }
1479
- return finalObject;
1803
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1804
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1480
1805
  };
1481
1806
  _bulkInsertTableRecords = new WeakSet();
1482
- bulkInsertTableRecords_fn = async function(objects) {
1807
+ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1483
1808
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1484
1809
  const records = objects.map((object) => transformObjectLinks(object));
1485
- const { recordIDs } = await bulkInsertTableRecords({
1810
+ const response = await bulkInsertTableRecords({
1486
1811
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table) },
1812
+ queryParams: { columns },
1487
1813
  body: { records },
1488
1814
  ...fetchProps
1489
1815
  });
1490
- const finalObjects = await this.read(recordIDs);
1491
- if (finalObjects.length !== objects.length) {
1492
- throw new Error("The server failed to save some records");
1816
+ if (!isResponseWithRecords(response)) {
1817
+ throw new Error("Request included columns but server didn't include them");
1493
1818
  }
1494
- const dictionary = finalObjects.reduce((acc, object) => {
1495
- acc[object.id] = object;
1496
- return acc;
1497
- }, {});
1498
- return recordIDs.map((id) => dictionary[id]);
1819
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1820
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1499
1821
  };
1500
1822
  _updateRecordWithID = new WeakSet();
1501
- updateRecordWithID_fn = async function(recordId, object) {
1823
+ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1502
1824
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1503
1825
  const record = transformObjectLinks(object);
1504
- const response = await updateRecordWithID({
1505
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1506
- body: record,
1507
- ...fetchProps
1508
- });
1509
- const item = await this.read(response.id);
1510
- if (!item)
1511
- throw new Error("The server failed to save the record");
1512
- return item;
1826
+ try {
1827
+ const response = await updateRecordWithID({
1828
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1829
+ queryParams: { columns },
1830
+ body: record,
1831
+ ...fetchProps
1832
+ });
1833
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1834
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1835
+ } catch (e) {
1836
+ if (isObject(e) && e.status === 404) {
1837
+ return null;
1838
+ }
1839
+ throw e;
1840
+ }
1513
1841
  };
1514
1842
  _upsertRecordWithID = new WeakSet();
1515
- upsertRecordWithID_fn = async function(recordId, object) {
1843
+ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1516
1844
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1517
1845
  const response = await upsertRecordWithID({
1518
1846
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1847
+ queryParams: { columns },
1519
1848
  body: object,
1520
1849
  ...fetchProps
1521
1850
  });
1522
- const item = await this.read(response.id);
1523
- if (!item)
1524
- throw new Error("The server failed to save the record");
1525
- return item;
1851
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1852
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1526
1853
  };
1527
1854
  _deleteRecord = new WeakSet();
1528
- deleteRecord_fn = async function(recordId) {
1855
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1529
1856
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1530
- await deleteRecord({
1531
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1532
- ...fetchProps
1533
- });
1534
- };
1535
- _invalidateCache = new WeakSet();
1536
- invalidateCache_fn = async function(recordId) {
1537
- await __privateGet$4(this, _cache).delete(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1538
- const cacheItems = await __privateGet$4(this, _cache).getAll();
1539
- const queries = Object.entries(cacheItems).filter(([key]) => key.startsWith("query_"));
1540
- for (const [key, value] of queries) {
1541
- const ids = getIds(value);
1542
- if (ids.includes(recordId))
1543
- await __privateGet$4(this, _cache).delete(key);
1857
+ try {
1858
+ const response = await deleteRecord({
1859
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1860
+ queryParams: { columns },
1861
+ ...fetchProps
1862
+ });
1863
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1864
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1865
+ } catch (e) {
1866
+ if (isObject(e) && e.status === 404) {
1867
+ return null;
1868
+ }
1869
+ throw e;
1544
1870
  }
1545
1871
  };
1546
- _setCacheRecord = new WeakSet();
1547
- setCacheRecord_fn = async function(record) {
1548
- if (!__privateGet$4(this, _cache).cacheRecords)
1549
- return;
1550
- await __privateGet$4(this, _cache).set(`rec_${__privateGet$4(this, _table)}:${record.id}`, record);
1551
- };
1552
- _getCacheRecord = new WeakSet();
1553
- getCacheRecord_fn = async function(recordId) {
1554
- if (!__privateGet$4(this, _cache).cacheRecords)
1555
- return null;
1556
- return __privateGet$4(this, _cache).get(`rec_${__privateGet$4(this, _table)}:${recordId}`);
1557
- };
1558
1872
  _setCacheQuery = new WeakSet();
1559
1873
  setCacheQuery_fn = async function(query, meta, records) {
1560
1874
  await __privateGet$4(this, _cache).set(`query_${__privateGet$4(this, _table)}:${query.key()}`, { date: new Date(), meta, records });
@@ -1571,17 +1885,17 @@ getCacheQuery_fn = async function(query) {
1571
1885
  const hasExpired = result.date.getTime() + ttl < Date.now();
1572
1886
  return hasExpired ? null : result;
1573
1887
  };
1574
- _getSchema$1 = new WeakSet();
1575
- getSchema_fn$1 = async function() {
1576
- if (__privateGet$4(this, _schema$1))
1577
- return __privateGet$4(this, _schema$1);
1888
+ _getSchemaTables$1 = new WeakSet();
1889
+ getSchemaTables_fn$1 = async function() {
1890
+ if (__privateGet$4(this, _schemaTables$2))
1891
+ return __privateGet$4(this, _schemaTables$2);
1578
1892
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1579
1893
  const { schema } = await getBranchDetails({
1580
1894
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1581
1895
  ...fetchProps
1582
1896
  });
1583
- __privateSet$3(this, _schema$1, schema);
1584
- return schema;
1897
+ __privateSet$4(this, _schemaTables$2, schema.tables);
1898
+ return schema.tables;
1585
1899
  };
1586
1900
  const transformObjectLinks = (object) => {
1587
1901
  return Object.entries(object).reduce((acc, [key, value]) => {
@@ -1590,11 +1904,11 @@ const transformObjectLinks = (object) => {
1590
1904
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
1591
1905
  }, {});
1592
1906
  };
1593
- const initObject = (db, schema, table, object) => {
1907
+ const initObject = (db, schemaTables, table, object) => {
1594
1908
  const result = {};
1595
1909
  const { xata, ...rest } = object ?? {};
1596
1910
  Object.assign(result, rest);
1597
- const { columns } = schema.tables.find(({ name }) => name === table) ?? {};
1911
+ const { columns } = schemaTables.find(({ name }) => name === table) ?? {};
1598
1912
  if (!columns)
1599
1913
  console.error(`Table ${table} not found in schema`);
1600
1914
  for (const column of columns ?? []) {
@@ -1614,17 +1928,17 @@ const initObject = (db, schema, table, object) => {
1614
1928
  if (!linkTable) {
1615
1929
  console.error(`Failed to parse link for field ${column.name}`);
1616
1930
  } else if (isObject(value)) {
1617
- result[column.name] = initObject(db, schema, linkTable, value);
1931
+ result[column.name] = initObject(db, schemaTables, linkTable, value);
1618
1932
  }
1619
1933
  break;
1620
1934
  }
1621
1935
  }
1622
1936
  }
1623
- result.read = function() {
1624
- return db[table].read(result["id"]);
1937
+ result.read = function(columns2) {
1938
+ return db[table].read(result["id"], columns2);
1625
1939
  };
1626
- result.update = function(data) {
1627
- return db[table].update(result["id"], data);
1940
+ result.update = function(data, columns2) {
1941
+ return db[table].update(result["id"], data, columns2);
1628
1942
  };
1629
1943
  result.delete = function() {
1630
1944
  return db[table].delete(result["id"]);
@@ -1638,14 +1952,21 @@ const initObject = (db, schema, table, object) => {
1638
1952
  Object.freeze(result);
1639
1953
  return result;
1640
1954
  };
1641
- function getIds(value) {
1642
- if (Array.isArray(value)) {
1643
- return value.map((item) => getIds(item)).flat();
1644
- }
1645
- if (!isObject(value))
1646
- return [];
1647
- const nestedIds = Object.values(value).map((item) => getIds(item)).flat();
1648
- return isString(value.id) ? [value.id, ...nestedIds] : nestedIds;
1955
+ function isResponseWithRecords(value) {
1956
+ return isObject(value) && Array.isArray(value.records);
1957
+ }
1958
+ function extractId(value) {
1959
+ if (isString(value))
1960
+ return value;
1961
+ if (isObject(value) && isString(value.id))
1962
+ return value.id;
1963
+ return void 0;
1964
+ }
1965
+ function cleanFilter(filter) {
1966
+ if (!filter)
1967
+ return void 0;
1968
+ const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
1969
+ return values.length > 0 ? filter : void 0;
1649
1970
  }
1650
1971
 
1651
1972
  var __accessCheck$3 = (obj, member, msg) => {
@@ -1661,7 +1982,7 @@ var __privateAdd$3 = (obj, member, value) => {
1661
1982
  throw TypeError("Cannot add the same private member more than once");
1662
1983
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1663
1984
  };
1664
- var __privateSet$2 = (obj, member, value, setter) => {
1985
+ var __privateSet$3 = (obj, member, value, setter) => {
1665
1986
  __accessCheck$3(obj, member, "write to private field");
1666
1987
  setter ? setter.call(obj, value) : member.set(obj, value);
1667
1988
  return value;
@@ -1670,9 +1991,8 @@ var _map;
1670
1991
  class SimpleCache {
1671
1992
  constructor(options = {}) {
1672
1993
  __privateAdd$3(this, _map, void 0);
1673
- __privateSet$2(this, _map, /* @__PURE__ */ new Map());
1994
+ __privateSet$3(this, _map, /* @__PURE__ */ new Map());
1674
1995
  this.capacity = options.max ?? 500;
1675
- this.cacheRecords = options.cacheRecords ?? true;
1676
1996
  this.defaultQueryTTL = options.defaultQueryTTL ?? 60 * 1e3;
1677
1997
  }
1678
1998
  async getAll() {
@@ -1698,18 +2018,25 @@ class SimpleCache {
1698
2018
  }
1699
2019
  _map = new WeakMap();
1700
2020
 
1701
- const gt = (value) => ({ $gt: value });
1702
- const ge = (value) => ({ $ge: value });
1703
- const gte = (value) => ({ $ge: value });
1704
- const lt = (value) => ({ $lt: value });
1705
- const lte = (value) => ({ $le: value });
1706
- const le = (value) => ({ $le: value });
2021
+ const greaterThan = (value) => ({ $gt: value });
2022
+ const gt = greaterThan;
2023
+ const greaterThanEquals = (value) => ({ $ge: value });
2024
+ const greaterEquals = greaterThanEquals;
2025
+ const gte = greaterThanEquals;
2026
+ const ge = greaterThanEquals;
2027
+ const lessThan = (value) => ({ $lt: value });
2028
+ const lt = lessThan;
2029
+ const lessThanEquals = (value) => ({ $le: value });
2030
+ const lessEquals = lessThanEquals;
2031
+ const lte = lessThanEquals;
2032
+ const le = lessThanEquals;
1707
2033
  const exists = (column) => ({ $exists: column });
1708
2034
  const notExists = (column) => ({ $notExists: column });
1709
2035
  const startsWith = (value) => ({ $startsWith: value });
1710
2036
  const endsWith = (value) => ({ $endsWith: value });
1711
2037
  const pattern = (value) => ({ $pattern: value });
1712
2038
  const is = (value) => ({ $is: value });
2039
+ const equals = is;
1713
2040
  const isNot = (value) => ({ $isNot: value });
1714
2041
  const contains = (value) => ({ $contains: value });
1715
2042
  const includes = (value) => ({ $includes: value });
@@ -1730,31 +2057,42 @@ var __privateAdd$2 = (obj, member, value) => {
1730
2057
  throw TypeError("Cannot add the same private member more than once");
1731
2058
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
1732
2059
  };
1733
- var _tables;
2060
+ var __privateSet$2 = (obj, member, value, setter) => {
2061
+ __accessCheck$2(obj, member, "write to private field");
2062
+ setter ? setter.call(obj, value) : member.set(obj, value);
2063
+ return value;
2064
+ };
2065
+ var _tables, _schemaTables$1;
1734
2066
  class SchemaPlugin extends XataPlugin {
1735
- constructor(tableNames) {
2067
+ constructor(schemaTables) {
1736
2068
  super();
1737
- this.tableNames = tableNames;
1738
2069
  __privateAdd$2(this, _tables, {});
2070
+ __privateAdd$2(this, _schemaTables$1, void 0);
2071
+ __privateSet$2(this, _schemaTables$1, schemaTables);
1739
2072
  }
1740
2073
  build(pluginOptions) {
1741
- const db = new Proxy({}, {
1742
- get: (_target, table) => {
1743
- if (!isString(table))
1744
- throw new Error("Invalid table name");
1745
- if (__privateGet$2(this, _tables)[table] === void 0) {
1746
- __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table });
2074
+ const db = new Proxy(
2075
+ {},
2076
+ {
2077
+ get: (_target, table) => {
2078
+ if (!isString(table))
2079
+ throw new Error("Invalid table name");
2080
+ if (__privateGet$2(this, _tables)[table] === void 0) {
2081
+ __privateGet$2(this, _tables)[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
2082
+ }
2083
+ return __privateGet$2(this, _tables)[table];
1747
2084
  }
1748
- return __privateGet$2(this, _tables)[table];
1749
2085
  }
1750
- });
1751
- for (const table of this.tableNames ?? []) {
1752
- db[table] = new RestRepository({ db, pluginOptions, table });
2086
+ );
2087
+ const tableNames = __privateGet$2(this, _schemaTables$1)?.map(({ name }) => name) ?? [];
2088
+ for (const table of tableNames) {
2089
+ db[table] = new RestRepository({ db, pluginOptions, table, schemaTables: __privateGet$2(this, _schemaTables$1) });
1753
2090
  }
1754
2091
  return db;
1755
2092
  }
1756
2093
  }
1757
2094
  _tables = new WeakMap();
2095
+ _schemaTables$1 = new WeakMap();
1758
2096
 
1759
2097
  var __accessCheck$1 = (obj, member, msg) => {
1760
2098
  if (!member.has(obj))
@@ -1778,82 +2116,77 @@ var __privateMethod$1 = (obj, member, method) => {
1778
2116
  __accessCheck$1(obj, member, "access private method");
1779
2117
  return method;
1780
2118
  };
1781
- var _schema, _search, search_fn, _getSchema, getSchema_fn;
2119
+ var _schemaTables, _search, search_fn, _getSchemaTables, getSchemaTables_fn;
1782
2120
  class SearchPlugin extends XataPlugin {
1783
- constructor(db) {
2121
+ constructor(db, schemaTables) {
1784
2122
  super();
1785
2123
  this.db = db;
1786
2124
  __privateAdd$1(this, _search);
1787
- __privateAdd$1(this, _getSchema);
1788
- __privateAdd$1(this, _schema, void 0);
2125
+ __privateAdd$1(this, _getSchemaTables);
2126
+ __privateAdd$1(this, _schemaTables, void 0);
2127
+ __privateSet$1(this, _schemaTables, schemaTables);
1789
2128
  }
1790
2129
  build({ getFetchProps }) {
1791
2130
  return {
1792
2131
  all: async (query, options = {}) => {
1793
2132
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1794
- const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
2133
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1795
2134
  return records.map((record) => {
1796
2135
  const { table = "orphan" } = record.xata;
1797
- return { table, record: initObject(this.db, schema, table, record) };
2136
+ return { table, record: initObject(this.db, schemaTables, table, record) };
1798
2137
  });
1799
2138
  },
1800
2139
  byTable: async (query, options = {}) => {
1801
2140
  const records = await __privateMethod$1(this, _search, search_fn).call(this, query, options, getFetchProps);
1802
- const schema = await __privateMethod$1(this, _getSchema, getSchema_fn).call(this, getFetchProps);
2141
+ const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
1803
2142
  return records.reduce((acc, record) => {
1804
2143
  const { table = "orphan" } = record.xata;
1805
2144
  const items = acc[table] ?? [];
1806
- const item = initObject(this.db, schema, table, record);
2145
+ const item = initObject(this.db, schemaTables, table, record);
1807
2146
  return { ...acc, [table]: [...items, item] };
1808
2147
  }, {});
1809
2148
  }
1810
2149
  };
1811
2150
  }
1812
2151
  }
1813
- _schema = new WeakMap();
2152
+ _schemaTables = new WeakMap();
1814
2153
  _search = new WeakSet();
1815
2154
  search_fn = async function(query, options, getFetchProps) {
1816
2155
  const fetchProps = await getFetchProps();
1817
- const { tables, fuzziness, highlight } = options ?? {};
2156
+ const { tables, fuzziness, highlight, prefix } = options ?? {};
1818
2157
  const { records } = await searchBranch({
1819
2158
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1820
- body: { tables, query, fuzziness, highlight },
2159
+ body: { tables, query, fuzziness, prefix, highlight },
1821
2160
  ...fetchProps
1822
2161
  });
1823
2162
  return records;
1824
2163
  };
1825
- _getSchema = new WeakSet();
1826
- getSchema_fn = async function(getFetchProps) {
1827
- if (__privateGet$1(this, _schema))
1828
- return __privateGet$1(this, _schema);
2164
+ _getSchemaTables = new WeakSet();
2165
+ getSchemaTables_fn = async function(getFetchProps) {
2166
+ if (__privateGet$1(this, _schemaTables))
2167
+ return __privateGet$1(this, _schemaTables);
1829
2168
  const fetchProps = await getFetchProps();
1830
2169
  const { schema } = await getBranchDetails({
1831
2170
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1832
2171
  ...fetchProps
1833
2172
  });
1834
- __privateSet$1(this, _schema, schema);
1835
- return schema;
2173
+ __privateSet$1(this, _schemaTables, schema.tables);
2174
+ return schema.tables;
1836
2175
  };
1837
2176
 
1838
2177
  const isBranchStrategyBuilder = (strategy) => {
1839
2178
  return typeof strategy === "function";
1840
2179
  };
1841
2180
 
1842
- const envBranchNames = [
1843
- "XATA_BRANCH",
1844
- "VERCEL_GIT_COMMIT_REF",
1845
- "CF_PAGES_BRANCH",
1846
- "BRANCH"
1847
- ];
1848
2181
  async function getCurrentBranchName(options) {
1849
- const env = getBranchByEnvVariable();
1850
- if (env) {
1851
- const details = await getDatabaseBranch(env, options);
2182
+ const { branch, envBranch } = getEnvironment();
2183
+ if (branch) {
2184
+ const details = await getDatabaseBranch(branch, options);
1852
2185
  if (details)
1853
- return env;
1854
- console.warn(`Branch ${env} not found in Xata. Ignoring...`);
2186
+ return branch;
2187
+ console.warn(`Branch ${branch} not found in Xata. Ignoring...`);
1855
2188
  }
1856
- const gitBranch = await getGitBranch();
2189
+ const gitBranch = envBranch || await getGitBranch();
1857
2190
  return resolveXataBranch(gitBranch, options);
1858
2191
  }
1859
2192
  async function getCurrentBranchDetails(options) {
@@ -1864,18 +2197,24 @@ async function resolveXataBranch(gitBranch, options) {
1864
2197
  const databaseURL = options?.databaseURL || getDatabaseURL();
1865
2198
  const apiKey = options?.apiKey || getAPIKey();
1866
2199
  if (!databaseURL)
1867
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
2200
+ throw new Error(
2201
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2202
+ );
1868
2203
  if (!apiKey)
1869
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
2204
+ throw new Error(
2205
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2206
+ );
1870
2207
  const [protocol, , host, , dbName] = databaseURL.split("/");
1871
2208
  const [workspace] = host.split(".");
2209
+ const { fallbackBranch } = getEnvironment();
1872
2210
  const { branch } = await resolveBranch({
1873
2211
  apiKey,
1874
2212
  apiUrl: databaseURL,
1875
2213
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1876
2214
  workspacesApiUrl: `${protocol}//${host}`,
1877
2215
  pathParams: { dbName, workspace },
1878
- queryParams: { gitBranch, fallbackBranch: getEnvVariable("XATA_FALLBACK_BRANCH") }
2216
+ queryParams: { gitBranch, fallbackBranch },
2217
+ trace: defaultTrace
1879
2218
  });
1880
2219
  return branch;
1881
2220
  }
@@ -1883,9 +2222,13 @@ async function getDatabaseBranch(branch, options) {
1883
2222
  const databaseURL = options?.databaseURL || getDatabaseURL();
1884
2223
  const apiKey = options?.apiKey || getAPIKey();
1885
2224
  if (!databaseURL)
1886
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
2225
+ throw new Error(
2226
+ "A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely"
2227
+ );
1887
2228
  if (!apiKey)
1888
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
2229
+ throw new Error(
2230
+ "An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely"
2231
+ );
1889
2232
  const [protocol, , host, , database] = databaseURL.split("/");
1890
2233
  const [workspace] = host.split(".");
1891
2234
  const dbBranchName = `${database}:${branch}`;
@@ -1895,7 +2238,8 @@ async function getDatabaseBranch(branch, options) {
1895
2238
  apiUrl: databaseURL,
1896
2239
  fetchImpl: getFetchImplementation(options?.fetchImpl),
1897
2240
  workspacesApiUrl: `${protocol}//${host}`,
1898
- pathParams: { dbBranchName, workspace }
2241
+ pathParams: { dbBranchName, workspace },
2242
+ trace: defaultTrace
1899
2243
  });
1900
2244
  } catch (err) {
1901
2245
  if (isObject(err) && err.status === 404)
@@ -1903,21 +2247,10 @@ async function getDatabaseBranch(branch, options) {
1903
2247
  throw err;
1904
2248
  }
1905
2249
  }
1906
- function getBranchByEnvVariable() {
1907
- for (const name of envBranchNames) {
1908
- const value = getEnvVariable(name);
1909
- if (value) {
1910
- return value;
1911
- }
1912
- }
1913
- try {
1914
- return XATA_BRANCH;
1915
- } catch (err) {
1916
- }
1917
- }
1918
2250
  function getDatabaseURL() {
1919
2251
  try {
1920
- return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
2252
+ const { databaseURL } = getEnvironment();
2253
+ return databaseURL;
1921
2254
  } catch (err) {
1922
2255
  return void 0;
1923
2256
  }
@@ -1946,20 +2279,23 @@ var __privateMethod = (obj, member, method) => {
1946
2279
  return method;
1947
2280
  };
1948
2281
  const buildClient = (plugins) => {
1949
- var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
2282
+ var _branch, _options, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1950
2283
  return _a = class {
1951
- constructor(options = {}, tables) {
2284
+ constructor(options = {}, schemaTables) {
1952
2285
  __privateAdd(this, _parseOptions);
1953
2286
  __privateAdd(this, _getFetchProps);
1954
2287
  __privateAdd(this, _evaluateBranch);
1955
2288
  __privateAdd(this, _branch, void 0);
2289
+ __privateAdd(this, _options, void 0);
1956
2290
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
2291
+ __privateSet(this, _options, safeOptions);
1957
2292
  const pluginOptions = {
1958
2293
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions),
1959
- cache: safeOptions.cache
2294
+ cache: safeOptions.cache,
2295
+ trace: safeOptions.trace
1960
2296
  };
1961
- const db = new SchemaPlugin(tables).build(pluginOptions);
1962
- const search = new SearchPlugin(db).build(pluginOptions);
2297
+ const db = new SchemaPlugin(schemaTables).build(pluginOptions);
2298
+ const search = new SearchPlugin(db, schemaTables).build(pluginOptions);
1963
2299
  this.db = db;
1964
2300
  this.search = search;
1965
2301
  for (const [key, namespace] of Object.entries(plugins ?? {})) {
@@ -1975,22 +2311,26 @@ const buildClient = (plugins) => {
1975
2311
  }
1976
2312
  }
1977
2313
  }
1978
- }, _branch = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
2314
+ async getConfig() {
2315
+ const databaseURL = __privateGet(this, _options).databaseURL;
2316
+ const branch = await __privateGet(this, _options).branch();
2317
+ return { databaseURL, branch };
2318
+ }
2319
+ }, _branch = new WeakMap(), _options = new WeakMap(), _parseOptions = new WeakSet(), parseOptions_fn = function(options) {
1979
2320
  const fetch = getFetchImplementation(options?.fetch);
1980
2321
  const databaseURL = options?.databaseURL || getDatabaseURL();
1981
2322
  const apiKey = options?.apiKey || getAPIKey();
1982
- const cache = options?.cache ?? new SimpleCache({ cacheRecords: false, defaultQueryTTL: 0 });
2323
+ const cache = options?.cache ?? new SimpleCache({ defaultQueryTTL: 0 });
2324
+ const trace = options?.trace ?? defaultTrace;
1983
2325
  const branch = async () => options?.branch !== void 0 ? await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, options.branch) : await getCurrentBranchName({ apiKey, databaseURL, fetchImpl: options?.fetch });
1984
- if (!databaseURL || !apiKey) {
1985
- throw new Error("Options databaseURL and apiKey are required");
2326
+ if (!apiKey) {
2327
+ throw new Error("Option apiKey is required");
1986
2328
  }
1987
- return { fetch, databaseURL, apiKey, branch, cache };
1988
- }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({
1989
- fetch,
1990
- apiKey,
1991
- databaseURL,
1992
- branch
1993
- }) {
2329
+ if (!databaseURL) {
2330
+ throw new Error("Option databaseURL is required");
2331
+ }
2332
+ return { fetch, databaseURL, apiKey, branch, cache, trace };
2333
+ }, _getFetchProps = new WeakSet(), getFetchProps_fn = async function({ fetch, apiKey, databaseURL, branch, trace }) {
1994
2334
  const branchValue = await __privateMethod(this, _evaluateBranch, evaluateBranch_fn).call(this, branch);
1995
2335
  if (!branchValue)
1996
2336
  throw new Error("Unable to resolve branch value");
@@ -2000,9 +2340,10 @@ const buildClient = (plugins) => {
2000
2340
  apiUrl: "",
2001
2341
  workspacesApiUrl: (path, params) => {
2002
2342
  const hasBranch = params.dbBranchName ?? params.branch;
2003
- const newPath = path.replace(/^\/db\/[^/]+/, hasBranch ? `:${branchValue}` : "");
2343
+ const newPath = path.replace(/^\/db\/[^/]+/, hasBranch !== void 0 ? `:${branchValue}` : "");
2004
2344
  return databaseURL + newPath;
2005
- }
2345
+ },
2346
+ trace
2006
2347
  };
2007
2348
  }, _evaluateBranch = new WeakSet(), evaluateBranch_fn = async function(param) {
2008
2349
  if (__privateGet(this, _branch))
@@ -2025,6 +2366,88 @@ const buildClient = (plugins) => {
2025
2366
  class BaseClient extends buildClient() {
2026
2367
  }
2027
2368
 
2369
+ const META = "__";
2370
+ const VALUE = "___";
2371
+ class Serializer {
2372
+ constructor() {
2373
+ this.classes = {};
2374
+ }
2375
+ add(clazz) {
2376
+ this.classes[clazz.name] = clazz;
2377
+ }
2378
+ toJSON(data) {
2379
+ function visit(obj) {
2380
+ if (Array.isArray(obj))
2381
+ return obj.map(visit);
2382
+ const type = typeof obj;
2383
+ if (type === "undefined")
2384
+ return { [META]: "undefined" };
2385
+ if (type === "bigint")
2386
+ return { [META]: "bigint", [VALUE]: obj.toString() };
2387
+ if (obj === null || type !== "object")
2388
+ return obj;
2389
+ const constructor = obj.constructor;
2390
+ const o = { [META]: constructor.name };
2391
+ for (const [key, value] of Object.entries(obj)) {
2392
+ o[key] = visit(value);
2393
+ }
2394
+ if (constructor === Date)
2395
+ o[VALUE] = obj.toISOString();
2396
+ if (constructor === Map)
2397
+ o[VALUE] = Object.fromEntries(obj);
2398
+ if (constructor === Set)
2399
+ o[VALUE] = [...obj];
2400
+ return o;
2401
+ }
2402
+ return JSON.stringify(visit(data));
2403
+ }
2404
+ fromJSON(json) {
2405
+ return JSON.parse(json, (key, value) => {
2406
+ if (value && typeof value === "object" && !Array.isArray(value)) {
2407
+ const { [META]: clazz, [VALUE]: val, ...rest } = value;
2408
+ const constructor = this.classes[clazz];
2409
+ if (constructor) {
2410
+ return Object.assign(Object.create(constructor.prototype), rest);
2411
+ }
2412
+ if (clazz === "Date")
2413
+ return new Date(val);
2414
+ if (clazz === "Set")
2415
+ return new Set(val);
2416
+ if (clazz === "Map")
2417
+ return new Map(Object.entries(val));
2418
+ if (clazz === "bigint")
2419
+ return BigInt(val);
2420
+ if (clazz === "undefined")
2421
+ return void 0;
2422
+ return rest;
2423
+ }
2424
+ return value;
2425
+ });
2426
+ }
2427
+ }
2428
+ const defaultSerializer = new Serializer();
2429
+ const serialize = (data) => {
2430
+ return defaultSerializer.toJSON(data);
2431
+ };
2432
+ const deserialize = (json) => {
2433
+ return defaultSerializer.fromJSON(json);
2434
+ };
2435
+
2436
+ function buildWorkerRunner(config) {
2437
+ return function xataWorker(name, _worker) {
2438
+ return async (...args) => {
2439
+ const url = process.env.NODE_ENV === "development" ? `http://localhost:64749/${name}` : `https://dispatcher.xata.workers.dev/${config.workspace}/${config.worker}/${name}`;
2440
+ const result = await fetch(url, {
2441
+ method: "POST",
2442
+ headers: { "Content-Type": "application/json" },
2443
+ body: serialize({ args })
2444
+ });
2445
+ const text = await result.text();
2446
+ return deserialize(text);
2447
+ };
2448
+ };
2449
+ }
2450
+
2028
2451
  class XataError extends Error {
2029
2452
  constructor(message, status) {
2030
2453
  super(message);
@@ -2032,5 +2455,5 @@ class XataError extends Error {
2032
2455
  }
2033
2456
  }
2034
2457
 
2035
- export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, buildClient, bulkInsertTableRecords, cancelWorkspaceMemberInvite, contains, createBranch, createDatabase, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, endsWith, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseURL, getGitBranchesMapping, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lt, lte, notExists, operationsByTag, pattern, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, setTableSchema, startsWith, updateBranchMetadata, updateColumn, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberRole, upsertRecordWithID };
2458
+ export { BaseClient, operationsByTag as Operations, PAGINATION_DEFAULT_OFFSET, PAGINATION_DEFAULT_SIZE, PAGINATION_MAX_OFFSET, PAGINATION_MAX_SIZE, Page, Query, RecordArray, Repository, RestRepository, SchemaPlugin, SearchPlugin, Serializer, SimpleCache, XataApiClient, XataApiPlugin, XataError, XataPlugin, acceptWorkspaceMemberInvite, addGitBranchesEntry, addTableColumn, applyBranchSchemaEdit, buildClient, buildWorkerRunner, bulkInsertTableRecords, cancelWorkspaceMemberInvite, compareBranchSchemas, compareBranchWithUserSchema, compareMigrationRequest, contains, createBranch, createDatabase, createMigrationRequest, createTable, createUserAPIKey, createWorkspace, deleteBranch, deleteColumn, deleteDatabase, deleteRecord, deleteTable, deleteUser, deleteUserAPIKey, deleteWorkspace, deserialize, endsWith, equals, executeBranchMigrationPlan, exists, ge, getAPIKey, getBranchDetails, getBranchList, getBranchMetadata, getBranchMigrationHistory, getBranchMigrationPlan, getBranchSchemaHistory, getBranchStats, getColumn, getCurrentBranchDetails, getCurrentBranchName, getDatabaseList, getDatabaseMetadata, getDatabaseURL, getGitBranchesMapping, getMigrationRequest, getMigrationRequestIsMerged, getRecord, getTableColumns, getTableSchema, getUser, getUserAPIKeys, getWorkspace, getWorkspaceMembersList, getWorkspacesList, greaterEquals, greaterThan, greaterThanEquals, gt, gte, includes, includesAll, includesAny, includesNone, insertRecord, insertRecordWithID, inviteWorkspaceMember, is, isCursorPaginationOptions, isIdentifiable, isNot, isXataRecord, le, lessEquals, lessThan, lessThanEquals, listMigrationRequests, listMigrationRequestsCommits, lt, lte, mergeMigrationRequest, notExists, operationsByTag, patchDatabaseMetadata, pattern, previewBranchSchemaEdit, queryTable, removeGitBranchesEntry, removeWorkspaceMember, resendWorkspaceMemberInvite, resolveBranch, searchBranch, searchTable, serialize, setTableSchema, startsWith, updateBranchMetadata, updateBranchSchema, updateColumn, updateMigrationRequest, updateRecordWithID, updateTable, updateUser, updateWorkspace, updateWorkspaceMemberInvite, updateWorkspaceMemberRole, upsertRecordWithID };
2036
2459
  //# sourceMappingURL=index.mjs.map