@xata.io/client 0.0.0-alpha.vedf1c64 → 0.0.0-alpha.vf170c2c
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 +0 -7
- package/dist/index.cjs +86 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +86 -85
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
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));
|
|
@@ -1542,6 +1465,84 @@ const isBranchStrategyBuilder = (strategy) => {
|
|
|
1542
1465
|
return typeof strategy === "function";
|
|
1543
1466
|
};
|
|
1544
1467
|
|
|
1468
|
+
const envBranchNames = [
|
|
1469
|
+
"XATA_BRANCH",
|
|
1470
|
+
"VERCEL_GIT_COMMIT_REF",
|
|
1471
|
+
"CF_PAGES_BRANCH",
|
|
1472
|
+
"BRANCH"
|
|
1473
|
+
];
|
|
1474
|
+
const defaultBranch = "main";
|
|
1475
|
+
async function getCurrentBranchName(options) {
|
|
1476
|
+
const env = await getBranchByEnvVariable();
|
|
1477
|
+
if (env)
|
|
1478
|
+
return env;
|
|
1479
|
+
const branch = await getGitBranch();
|
|
1480
|
+
if (!branch)
|
|
1481
|
+
return defaultBranch;
|
|
1482
|
+
const details = await getDatabaseBranch(branch, options);
|
|
1483
|
+
if (details)
|
|
1484
|
+
return branch;
|
|
1485
|
+
return defaultBranch;
|
|
1486
|
+
}
|
|
1487
|
+
async function getCurrentBranchDetails(options) {
|
|
1488
|
+
const env = await getBranchByEnvVariable();
|
|
1489
|
+
if (env)
|
|
1490
|
+
return getDatabaseBranch(env, options);
|
|
1491
|
+
const branch = await getGitBranch();
|
|
1492
|
+
if (!branch)
|
|
1493
|
+
return getDatabaseBranch(defaultBranch, options);
|
|
1494
|
+
const details = await getDatabaseBranch(branch, options);
|
|
1495
|
+
if (details)
|
|
1496
|
+
return details;
|
|
1497
|
+
return getDatabaseBranch(defaultBranch, options);
|
|
1498
|
+
}
|
|
1499
|
+
async function getDatabaseBranch(branch, options) {
|
|
1500
|
+
const databaseURL = options?.databaseURL || getDatabaseURL();
|
|
1501
|
+
const apiKey = options?.apiKey || getAPIKey();
|
|
1502
|
+
if (!databaseURL)
|
|
1503
|
+
throw new Error("A databaseURL was not defined. Either set the XATA_DATABASE_URL env variable or pass the argument explicitely");
|
|
1504
|
+
if (!apiKey)
|
|
1505
|
+
throw new Error("An API key was not defined. Either set the XATA_API_KEY env variable or pass the argument explicitely");
|
|
1506
|
+
const [protocol, , host, , database] = databaseURL.split("/");
|
|
1507
|
+
const [workspace] = host.split(".");
|
|
1508
|
+
const dbBranchName = `${database}:${branch}`;
|
|
1509
|
+
try {
|
|
1510
|
+
return await getBranchDetails({
|
|
1511
|
+
apiKey,
|
|
1512
|
+
apiUrl: databaseURL,
|
|
1513
|
+
fetchImpl: getFetchImplementation(options?.fetchImpl),
|
|
1514
|
+
workspacesApiUrl: `${protocol}//${host}`,
|
|
1515
|
+
pathParams: {
|
|
1516
|
+
dbBranchName,
|
|
1517
|
+
workspace
|
|
1518
|
+
}
|
|
1519
|
+
});
|
|
1520
|
+
} catch (err) {
|
|
1521
|
+
if (isObject(err) && err.status === 404)
|
|
1522
|
+
return null;
|
|
1523
|
+
throw err;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
function getBranchByEnvVariable() {
|
|
1527
|
+
for (const name of envBranchNames) {
|
|
1528
|
+
const value = getEnvVariable(name);
|
|
1529
|
+
if (value) {
|
|
1530
|
+
return value;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
try {
|
|
1534
|
+
return XATA_BRANCH;
|
|
1535
|
+
} catch (err) {
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
function getDatabaseURL() {
|
|
1539
|
+
try {
|
|
1540
|
+
return getEnvVariable("XATA_DATABASE_URL") ?? XATA_DATABASE_URL;
|
|
1541
|
+
} catch (err) {
|
|
1542
|
+
return void 0;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1545
1546
|
var __accessCheck = (obj, member, msg) => {
|
|
1546
1547
|
if (!member.has(obj))
|
|
1547
1548
|
throw TypeError("Cannot " + msg);
|