@xata.io/client 0.0.0-alpha.vee88fdc → 0.0.0-alpha.vf2043e7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.8.4
4
+
5
+ ### Patch Changes
6
+
7
+ - dd958a4: Fix search results return type
8
+ - f5ec686: Make XataApiClientOptions optional
9
+
3
10
  ## 0.8.3
4
11
 
5
12
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -47,6 +47,14 @@ async function getGitBranch() {
47
47
  }
48
48
  }
49
49
 
50
+ function getAPIKey() {
51
+ try {
52
+ return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
53
+ } catch (err) {
54
+ return void 0;
55
+ }
56
+ }
57
+
50
58
  function getFetchImplementation(userFetch) {
51
59
  const globalFetch = typeof fetch !== "undefined" ? fetch : void 0;
52
60
  const fetchImpl = userFetch ?? globalFetch;
@@ -56,91 +64,6 @@ function getFetchImplementation(userFetch) {
56
64
  return fetchImpl;
57
65
  }
58
66
 
59
- const envBranchNames = [
60
- "XATA_BRANCH",
61
- "VERCEL_GIT_COMMIT_REF",
62
- "CF_PAGES_BRANCH",
63
- "BRANCH"
64
- ];
65
- const defaultBranch = "main";
66
- async function getCurrentBranchName(options) {
67
- const env = await getBranchByEnvVariable();
68
- if (env)
69
- return env;
70
- const branch = await getGitBranch();
71
- if (!branch)
72
- return defaultBranch;
73
- const details = await getDatabaseBranch(branch, options);
74
- if (details)
75
- return branch;
76
- return defaultBranch;
77
- }
78
- async function getCurrentBranchDetails(options) {
79
- const env = await getBranchByEnvVariable();
80
- if (env)
81
- return getDatabaseBranch(env, options);
82
- const branch = await getGitBranch();
83
- if (!branch)
84
- return getDatabaseBranch(defaultBranch, options);
85
- const details = await getDatabaseBranch(branch, options);
86
- if (details)
87
- return details;
88
- return getDatabaseBranch(defaultBranch, options);
89
- }
90
- async function getDatabaseBranch(branch, options) {
91
- const databaseURL = options?.databaseURL || getDatabaseURL();
92
- const apiKey = options?.apiKey || getAPIKey();
93
- if (!databaseURL)
94
- throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
95
- if (!apiKey)
96
- throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
97
- const [protocol, , host, , database] = databaseURL.split("/");
98
- const [workspace] = host.split(".");
99
- const dbBranchName = `${database}:${branch}`;
100
- try {
101
- return await getBranchDetails({
102
- apiKey,
103
- apiUrl: databaseURL,
104
- fetchImpl: getFetchImplementation(options?.fetchImpl),
105
- workspacesApiUrl: `${protocol}//${host}`,
106
- pathParams: {
107
- dbBranchName,
108
- workspace
109
- }
110
- });
111
- } catch (err) {
112
- if (isObject(err) && err.status === 404)
113
- return null;
114
- throw err;
115
- }
116
- }
117
- function getBranchByEnvVariable() {
118
- for (const name of envBranchNames) {
119
- const value = getEnvVariable(name);
120
- if (value) {
121
- return value;
122
- }
123
- }
124
- try {
125
- return XATA_BRANCH;
126
- } catch (err) {
127
- }
128
- }
129
- function getDatabaseURL() {
130
- try {
131
- return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
132
- } catch (err) {
133
- return void 0;
134
- }
135
- }
136
- function getAPIKey() {
137
- try {
138
- return getEnvVariable("XATA_API_KEY") ?? XATA_API_KEY;
139
- } catch (err) {
140
- return void 0;
141
- }
142
- }
143
-
144
67
  class FetcherError extends Error {
145
68
  constructor(status, data) {
146
69
  super(getMessage(data));
@@ -1462,9 +1385,10 @@ var __privateAdd$2 = (obj, member, value) => {
1462
1385
  };
1463
1386
  var _tables;
1464
1387
  class SchemaPlugin extends XataPlugin {
1465
- constructor(links) {
1388
+ constructor(links, tableNames) {
1466
1389
  super();
1467
1390
  this.links = links;
1391
+ this.tableNames = tableNames;
1468
1392
  __privateAdd$2(this, _tables, {});
1469
1393
  }
1470
1394
  build(options) {
@@ -1479,6 +1403,9 @@ class SchemaPlugin extends XataPlugin {
1479
1403
  return __privateGet$1(this, _tables)[table];
1480
1404
  }
1481
1405
  });
1406
+ for (const table of this.tableNames ?? []) {
1407
+ db[table] = new RestRepository({ db, getFetchProps, table, links });
1408
+ }
1482
1409
  return db;
1483
1410
  }
1484
1411
  }
@@ -1542,6 +1469,84 @@ const isBranchStrategyBuilder = (strategy) => {
1542
1469
  return typeof strategy === "function";
1543
1470
  };
1544
1471
 
1472
+ const envBranchNames = [
1473
+ "XATA_BRANCH",
1474
+ "VERCEL_GIT_COMMIT_REF",
1475
+ "CF_PAGES_BRANCH",
1476
+ "BRANCH"
1477
+ ];
1478
+ const defaultBranch = "main";
1479
+ async function getCurrentBranchName(options) {
1480
+ const env = await getBranchByEnvVariable();
1481
+ if (env)
1482
+ return env;
1483
+ const branch = await getGitBranch();
1484
+ if (!branch)
1485
+ return defaultBranch;
1486
+ const details = await getDatabaseBranch(branch, options);
1487
+ if (details)
1488
+ return branch;
1489
+ return defaultBranch;
1490
+ }
1491
+ async function getCurrentBranchDetails(options) {
1492
+ const env = await getBranchByEnvVariable();
1493
+ if (env)
1494
+ return getDatabaseBranch(env, options);
1495
+ const branch = await getGitBranch();
1496
+ if (!branch)
1497
+ return getDatabaseBranch(defaultBranch, options);
1498
+ const details = await getDatabaseBranch(branch, options);
1499
+ if (details)
1500
+ return details;
1501
+ return getDatabaseBranch(defaultBranch, options);
1502
+ }
1503
+ async function getDatabaseBranch(branch, options) {
1504
+ const databaseURL = options?.databaseURL || getDatabaseURL();
1505
+ const apiKey = options?.apiKey || getAPIKey();
1506
+ if (!databaseURL)
1507
+ throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
1508
+ if (!apiKey)
1509
+ throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
1510
+ const [protocol, , host, , database] = databaseURL.split("/");
1511
+ const [workspace] = host.split(".");
1512
+ const dbBranchName = `${database}:${branch}`;
1513
+ try {
1514
+ return await getBranchDetails({
1515
+ apiKey,
1516
+ apiUrl: databaseURL,
1517
+ fetchImpl: getFetchImplementation(options?.fetchImpl),
1518
+ workspacesApiUrl: `${protocol}//${host}`,
1519
+ pathParams: {
1520
+ dbBranchName,
1521
+ workspace
1522
+ }
1523
+ });
1524
+ } catch (err) {
1525
+ if (isObject(err) && err.status === 404)
1526
+ return null;
1527
+ throw err;
1528
+ }
1529
+ }
1530
+ function getBranchByEnvVariable() {
1531
+ for (const name of envBranchNames) {
1532
+ const value = getEnvVariable(name);
1533
+ if (value) {
1534
+ return value;
1535
+ }
1536
+ }
1537
+ try {
1538
+ return XATA_BRANCH;
1539
+ } catch (err) {
1540
+ }
1541
+ }
1542
+ function getDatabaseURL() {
1543
+ try {
1544
+ return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
1545
+ } catch (err) {
1546
+ return void 0;
1547
+ }
1548
+ }
1549
+
1545
1550
  var __accessCheck = (obj, member, msg) => {
1546
1551
  if (!member.has(obj))
1547
1552
  throw TypeError("Cannot " + msg);
@@ -1567,13 +1572,13 @@ var __privateMethod = (obj, member, method) => {
1567
1572
  const buildClient = (plugins) => {
1568
1573
  var _branch, _parseOptions, parseOptions_fn, _getFetchProps, getFetchProps_fn, _evaluateBranch, evaluateBranch_fn, _a;
1569
1574
  return _a = class {
1570
- constructor(options = {}, links) {
1575
+ constructor(options = {}, links, tables) {
1571
1576
  __privateAdd(this, _parseOptions);
1572
1577
  __privateAdd(this, _getFetchProps);
1573
1578
  __privateAdd(this, _evaluateBranch);
1574
1579
  __privateAdd(this, _branch, void 0);
1575
1580
  const safeOptions = __privateMethod(this, _parseOptions, parseOptions_fn).call(this, options);
1576
- const db = new SchemaPlugin(links).build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1581
+ const db = new SchemaPlugin(links, tables).build({ getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions) });
1577
1582
  const search = new SearchPlugin(db, links ?? {}).build({
1578
1583
  getFetchProps: () => __privateMethod(this, _getFetchProps, getFetchProps_fn).call(this, safeOptions)
1579
1584
  });