@xylex-group/athena 2.8.2 → 2.9.0
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/README.md +154 -64
- package/dist/browser.cjs +636 -21
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +8 -7
- package/dist/browser.d.ts +8 -7
- package/dist/browser.js +630 -22
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +591 -29
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -3
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +591 -29
- package/dist/cli/index.js.map +1 -1
- package/dist/{model-form-Cx3wtvi8.d.ts → client-CfAE_QOj.d.cts} +101 -97
- package/dist/{model-form-_ugfOXao.d.cts → client-D6EIJdQS.d.ts} +101 -97
- package/dist/index.cjs +714 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +708 -42
- package/dist/index.js.map +1 -1
- package/dist/model-form-ByvyyvxB.d.ts +96 -0
- package/dist/model-form-DACdBLYG.d.cts +96 -0
- package/dist/next/client.cjs +7875 -0
- package/dist/next/client.cjs.map +1 -0
- package/dist/next/client.d.cts +25 -0
- package/dist/next/client.d.ts +25 -0
- package/dist/next/client.js +7873 -0
- package/dist/next/client.js.map +1 -0
- package/dist/next/server.cjs +7993 -0
- package/dist/next/server.cjs.map +1 -0
- package/dist/next/server.d.cts +52 -0
- package/dist/next/server.d.ts +52 -0
- package/dist/next/server.js +7990 -0
- package/dist/next/server.js.map +1 -0
- package/dist/{pipeline-BtD-Uo5X.d.cts → pipeline-CmUZsXsi.d.cts} +1 -1
- package/dist/{pipeline-yCIZNJHE.d.ts → pipeline-DZMsPxUg.d.ts} +1 -1
- package/dist/{react-email-CiiSVa9F.d.cts → react-email-BvJ3fj_F.d.cts} +35 -5
- package/dist/{react-email-WN8UU3AL.d.ts → react-email-PLAJuZuO.d.ts} +35 -5
- package/dist/react.cjs +30 -1
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +39 -10
- package/dist/react.d.ts +39 -10
- package/dist/react.js +30 -2
- package/dist/react.js.map +1 -1
- package/dist/shared-BW6hoLBY.d.cts +33 -0
- package/dist/shared-BiJvoURI.d.ts +33 -0
- package/dist/{types-g8G6J0xE.d.cts → types-BeZIHduP.d.cts} +2 -1
- package/dist/{types-g8G6J0xE.d.ts → types-BeZIHduP.d.ts} +2 -1
- package/dist/{types-C2kiTt6-.d.ts → types-C-YvfgYh.d.cts} +26 -2
- package/dist/{types-89EfjLjV.d.cts → types-CRjDwmtJ.d.ts} +26 -2
- package/package.json +32 -14
package/dist/index.cjs
CHANGED
|
@@ -806,7 +806,7 @@ var getCookieCache = async (request, config) => {
|
|
|
806
806
|
|
|
807
807
|
// package.json
|
|
808
808
|
var package_default = {
|
|
809
|
-
version: "2.
|
|
809
|
+
version: "2.9.0"
|
|
810
810
|
};
|
|
811
811
|
|
|
812
812
|
// src/sdk-version.ts
|
|
@@ -819,6 +819,7 @@ function buildSdkHeaderValue(sdkName) {
|
|
|
819
819
|
var DEFAULT_CLIENT = "railway_direct";
|
|
820
820
|
var SDK_NAME = "xylex-group/athena";
|
|
821
821
|
var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
|
|
822
|
+
var NO_CACHE_HEADER_VALUE = "no-cache";
|
|
822
823
|
function parseResponseBody(rawText, contentType) {
|
|
823
824
|
if (!rawText) {
|
|
824
825
|
return { parsed: null, parseFailed: false };
|
|
@@ -837,6 +838,9 @@ function parseResponseBody(rawText, contentType) {
|
|
|
837
838
|
function normalizeHeaderValue(value) {
|
|
838
839
|
return value ? value : void 0;
|
|
839
840
|
}
|
|
841
|
+
function isCacheControlHeaderName(name) {
|
|
842
|
+
return name.toLowerCase() === "cache-control";
|
|
843
|
+
}
|
|
840
844
|
function resolveHeaderValue(headers, candidates) {
|
|
841
845
|
for (const candidate of candidates) {
|
|
842
846
|
const direct = normalizeHeaderValue(headers[candidate]);
|
|
@@ -995,6 +999,7 @@ function buildRpcGetEndpoint(payload) {
|
|
|
995
999
|
}
|
|
996
1000
|
function buildHeaders(config, options) {
|
|
997
1001
|
const mergedStripNulls = options?.stripNulls ?? true;
|
|
1002
|
+
const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
|
|
998
1003
|
const extraHeaders = {
|
|
999
1004
|
...config.headers ?? {},
|
|
1000
1005
|
...options?.headers ?? {}
|
|
@@ -1048,11 +1053,15 @@ function buildHeaders(config, options) {
|
|
|
1048
1053
|
const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
|
|
1049
1054
|
Object.entries(extraHeaders).forEach(([key, value]) => {
|
|
1050
1055
|
if (athenaClientKeys.includes(key)) return;
|
|
1056
|
+
if (forceNoCache && isCacheControlHeaderName(key)) return;
|
|
1051
1057
|
const normalized = normalizeHeaderValue(value);
|
|
1052
1058
|
if (normalized) {
|
|
1053
1059
|
headers[key] = normalized;
|
|
1054
1060
|
}
|
|
1055
1061
|
});
|
|
1062
|
+
if (forceNoCache) {
|
|
1063
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
|
|
1064
|
+
}
|
|
1056
1065
|
return headers;
|
|
1057
1066
|
}
|
|
1058
1067
|
function toInvalidUrlResponse(error, endpoint, method) {
|
|
@@ -1513,6 +1522,45 @@ function identifier(...segments) {
|
|
|
1513
1522
|
return new SqlIdentifierPath(expandedSegments);
|
|
1514
1523
|
}
|
|
1515
1524
|
|
|
1525
|
+
// src/auth/limits.ts
|
|
1526
|
+
var ATHENA_AUTH_MAX_ADMIN_JSON_BYTES = 32 * 1024;
|
|
1527
|
+
var ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH = 8;
|
|
1528
|
+
var ATHENA_AUTH_MAX_TEMPLATE_VARIABLES = 64;
|
|
1529
|
+
var ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH = 128;
|
|
1530
|
+
var ATHENA_AUTH_ADMIN_LIMITS = {
|
|
1531
|
+
maxAdminJsonBytes: ATHENA_AUTH_MAX_ADMIN_JSON_BYTES,
|
|
1532
|
+
maxAdminJsonDepth: ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH,
|
|
1533
|
+
maxTemplateVariables: ATHENA_AUTH_MAX_TEMPLATE_VARIABLES,
|
|
1534
|
+
maxTemplateVariableLength: ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH
|
|
1535
|
+
};
|
|
1536
|
+
function describeTemplateVariableTarget(target) {
|
|
1537
|
+
const normalized = target?.trim();
|
|
1538
|
+
return normalized && normalized.length > 0 ? normalized : "Athena auth admin email template variables";
|
|
1539
|
+
}
|
|
1540
|
+
function assertAthenaAuthTemplateVariables(variables, target) {
|
|
1541
|
+
const label = describeTemplateVariableTarget(target);
|
|
1542
|
+
if (!Array.isArray(variables)) {
|
|
1543
|
+
throw new Error(`${label} must be an array of strings.`);
|
|
1544
|
+
}
|
|
1545
|
+
if (variables.length > ATHENA_AUTH_MAX_TEMPLATE_VARIABLES) {
|
|
1546
|
+
throw new Error(
|
|
1547
|
+
`${label} cannot contain more than ${ATHENA_AUTH_MAX_TEMPLATE_VARIABLES} entries.`
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
variables.forEach((variable, index) => {
|
|
1551
|
+
if (typeof variable !== "string") {
|
|
1552
|
+
throw new Error(
|
|
1553
|
+
`${label} must contain only strings. Received ${typeof variable} at index ${index}.`
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
if (variable.length > ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH) {
|
|
1557
|
+
throw new Error(
|
|
1558
|
+
`${label} cannot contain entries longer than ${ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH} characters. Received ${variable.length} characters at index ${index}.`
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1516
1564
|
// src/auth/react-email.ts
|
|
1517
1565
|
var reactEmailRenderModulePromise;
|
|
1518
1566
|
function isRecord2(value) {
|
|
@@ -1742,6 +1790,7 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
|
|
|
1742
1790
|
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
1743
1791
|
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
1744
1792
|
var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
|
|
1793
|
+
var NO_CACHE_HEADER_VALUE2 = "no-cache";
|
|
1745
1794
|
function normalizeBaseUrl(baseUrl) {
|
|
1746
1795
|
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
1747
1796
|
}
|
|
@@ -1751,6 +1800,9 @@ function isRecord3(value) {
|
|
|
1751
1800
|
function normalizeHeaderValue2(value) {
|
|
1752
1801
|
return value ? value : void 0;
|
|
1753
1802
|
}
|
|
1803
|
+
function isCacheControlHeaderName2(name) {
|
|
1804
|
+
return name.toLowerCase() === "cache-control";
|
|
1805
|
+
}
|
|
1754
1806
|
function parseResponseBody2(rawText, contentType) {
|
|
1755
1807
|
if (!rawText) {
|
|
1756
1808
|
return { parsed: null, parseFailed: false };
|
|
@@ -1806,6 +1858,54 @@ function mergeCallOptions(base, override) {
|
|
|
1806
1858
|
}
|
|
1807
1859
|
};
|
|
1808
1860
|
}
|
|
1861
|
+
function toSessionGuardFailure(sessionResult) {
|
|
1862
|
+
if (sessionResult.status === 401 || sessionResult.data == null) {
|
|
1863
|
+
return {
|
|
1864
|
+
ok: false,
|
|
1865
|
+
reason: "unauthorized",
|
|
1866
|
+
status: 401,
|
|
1867
|
+
error: sessionResult.error ?? "Unauthorized",
|
|
1868
|
+
sessionResult
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
return {
|
|
1872
|
+
ok: false,
|
|
1873
|
+
reason: "upstream_error",
|
|
1874
|
+
status: sessionResult.status,
|
|
1875
|
+
error: sessionResult.error ?? "Failed to resolve current session",
|
|
1876
|
+
sessionResult
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
function toPermissionGuardFailure(permissionResult, sessionResult) {
|
|
1880
|
+
if (permissionResult.status === 401) {
|
|
1881
|
+
return {
|
|
1882
|
+
ok: false,
|
|
1883
|
+
reason: "unauthorized",
|
|
1884
|
+
status: 401,
|
|
1885
|
+
error: permissionResult.error ?? "Unauthorized",
|
|
1886
|
+
sessionResult,
|
|
1887
|
+
permissionResult
|
|
1888
|
+
};
|
|
1889
|
+
}
|
|
1890
|
+
if (permissionResult.status === 403) {
|
|
1891
|
+
return {
|
|
1892
|
+
ok: false,
|
|
1893
|
+
reason: "forbidden",
|
|
1894
|
+
status: 403,
|
|
1895
|
+
error: permissionResult.error ?? "Forbidden",
|
|
1896
|
+
sessionResult,
|
|
1897
|
+
permissionResult
|
|
1898
|
+
};
|
|
1899
|
+
}
|
|
1900
|
+
return {
|
|
1901
|
+
ok: false,
|
|
1902
|
+
reason: "upstream_error",
|
|
1903
|
+
status: permissionResult.status,
|
|
1904
|
+
error: permissionResult.error ?? "Failed to resolve permission check",
|
|
1905
|
+
sessionResult,
|
|
1906
|
+
permissionResult
|
|
1907
|
+
};
|
|
1908
|
+
}
|
|
1809
1909
|
function extractFetchOptions(input) {
|
|
1810
1910
|
if (!input) {
|
|
1811
1911
|
return {
|
|
@@ -1821,6 +1921,7 @@ function extractFetchOptions(input) {
|
|
|
1821
1921
|
};
|
|
1822
1922
|
}
|
|
1823
1923
|
function buildHeaders2(config, options) {
|
|
1924
|
+
const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
|
|
1824
1925
|
const headers = {
|
|
1825
1926
|
"Content-Type": "application/json",
|
|
1826
1927
|
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
@@ -1834,16 +1935,30 @@ function buildHeaders2(config, options) {
|
|
|
1834
1935
|
if (bearerToken) {
|
|
1835
1936
|
headers.Authorization = `Bearer ${bearerToken}`;
|
|
1836
1937
|
}
|
|
1938
|
+
const cookie = options?.cookie ?? config.cookie;
|
|
1939
|
+
if (cookie) {
|
|
1940
|
+
headers.Cookie = cookie;
|
|
1941
|
+
}
|
|
1942
|
+
const sessionToken = options?.sessionToken ?? config.sessionToken;
|
|
1943
|
+
if (sessionToken) {
|
|
1944
|
+
headers["X-Athena-Auth-Session-Token"] = sessionToken;
|
|
1945
|
+
}
|
|
1837
1946
|
const mergedExtraHeaders = {
|
|
1838
1947
|
...config.headers ?? {},
|
|
1839
1948
|
...options?.headers ?? {}
|
|
1840
1949
|
};
|
|
1841
1950
|
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
1951
|
+
if (forceNoCache && isCacheControlHeaderName2(key)) {
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1842
1954
|
const normalized = normalizeHeaderValue2(value);
|
|
1843
1955
|
if (normalized) {
|
|
1844
1956
|
headers[key] = normalized;
|
|
1845
1957
|
}
|
|
1846
1958
|
});
|
|
1959
|
+
if (forceNoCache) {
|
|
1960
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
|
|
1961
|
+
}
|
|
1847
1962
|
return headers;
|
|
1848
1963
|
}
|
|
1849
1964
|
function appendQueryParam(searchParams, key, value) {
|
|
@@ -2108,7 +2223,91 @@ function createAuthClient(config = {}) {
|
|
|
2108
2223
|
htmlField: "htmlTemplate",
|
|
2109
2224
|
textField: "textTemplate",
|
|
2110
2225
|
variablesField: "variables"
|
|
2111
|
-
}, withReactEmailRoute(route))
|
|
2226
|
+
}, withReactEmailRoute(route)).then((payload) => {
|
|
2227
|
+
if ("variables" in payload && payload.variables !== void 0 && payload.variables !== null) {
|
|
2228
|
+
assertAthenaAuthTemplateVariables(
|
|
2229
|
+
payload.variables,
|
|
2230
|
+
`${route} variables`
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
return payload;
|
|
2234
|
+
});
|
|
2235
|
+
const requireSession = async (input, options) => {
|
|
2236
|
+
const sessionInput = input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0;
|
|
2237
|
+
const sessionResult = await getGeneric(
|
|
2238
|
+
"/get-session",
|
|
2239
|
+
sessionInput,
|
|
2240
|
+
options
|
|
2241
|
+
);
|
|
2242
|
+
if (!sessionResult.ok || sessionResult.data == null) {
|
|
2243
|
+
return toSessionGuardFailure(sessionResult);
|
|
2244
|
+
}
|
|
2245
|
+
return {
|
|
2246
|
+
ok: true,
|
|
2247
|
+
session: sessionResult.data
|
|
2248
|
+
};
|
|
2249
|
+
};
|
|
2250
|
+
const getUser = async (input, options) => {
|
|
2251
|
+
const sessionResult = await getGeneric(
|
|
2252
|
+
"/get-session",
|
|
2253
|
+
input,
|
|
2254
|
+
options
|
|
2255
|
+
);
|
|
2256
|
+
if (!sessionResult.ok) {
|
|
2257
|
+
return {
|
|
2258
|
+
...sessionResult,
|
|
2259
|
+
data: null
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
return {
|
|
2263
|
+
...sessionResult,
|
|
2264
|
+
data: {
|
|
2265
|
+
user: sessionResult.data?.user ?? null
|
|
2266
|
+
}
|
|
2267
|
+
};
|
|
2268
|
+
};
|
|
2269
|
+
const requirePermission = async (endpoint, input, options) => {
|
|
2270
|
+
const sessionGuard = await requireSession(
|
|
2271
|
+
input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0,
|
|
2272
|
+
options
|
|
2273
|
+
);
|
|
2274
|
+
if (!sessionGuard.ok) {
|
|
2275
|
+
return sessionGuard;
|
|
2276
|
+
}
|
|
2277
|
+
const permissionResult = await postGeneric(
|
|
2278
|
+
endpoint,
|
|
2279
|
+
input,
|
|
2280
|
+
options
|
|
2281
|
+
);
|
|
2282
|
+
if (!permissionResult.ok) {
|
|
2283
|
+
return toPermissionGuardFailure(permissionResult, {
|
|
2284
|
+
ok: true,
|
|
2285
|
+
status: 200,
|
|
2286
|
+
data: sessionGuard.session,
|
|
2287
|
+
error: null,
|
|
2288
|
+
errorDetails: null,
|
|
2289
|
+
raw: sessionGuard.session
|
|
2290
|
+
});
|
|
2291
|
+
}
|
|
2292
|
+
if (!permissionResult.data?.success) {
|
|
2293
|
+
return {
|
|
2294
|
+
ok: false,
|
|
2295
|
+
reason: "forbidden",
|
|
2296
|
+
status: 403,
|
|
2297
|
+
error: permissionResult.data?.error ?? "Forbidden",
|
|
2298
|
+
sessionResult: {
|
|
2299
|
+
ok: true,
|
|
2300
|
+
status: 200,
|
|
2301
|
+
data: sessionGuard.session,
|
|
2302
|
+
error: null,
|
|
2303
|
+
errorDetails: null,
|
|
2304
|
+
raw: sessionGuard.session
|
|
2305
|
+
},
|
|
2306
|
+
permissionResult
|
|
2307
|
+
};
|
|
2308
|
+
}
|
|
2309
|
+
return sessionGuard;
|
|
2310
|
+
};
|
|
2112
2311
|
const listUserEmailsWithFallback = async (input, options) => {
|
|
2113
2312
|
const primary = await getWithQuery(
|
|
2114
2313
|
"/email/list",
|
|
@@ -2270,6 +2469,7 @@ function createAuthClient(config = {}) {
|
|
|
2270
2469
|
input,
|
|
2271
2470
|
options
|
|
2272
2471
|
),
|
|
2472
|
+
requirePermission: (input, options) => requirePermission("/organization/has-permission", input, options),
|
|
2273
2473
|
invitation: {
|
|
2274
2474
|
cancel: (input, options) => executePostWithCompatibleInput(
|
|
2275
2475
|
resolvedConfig,
|
|
@@ -2465,6 +2665,8 @@ function createAuthClient(config = {}) {
|
|
|
2465
2665
|
};
|
|
2466
2666
|
const auth = {
|
|
2467
2667
|
getSession: (input, options) => getGeneric("/get-session", input, options),
|
|
2668
|
+
getUser,
|
|
2669
|
+
requireSession,
|
|
2468
2670
|
signOut,
|
|
2469
2671
|
forgetPassword: (input, options) => postGeneric("/forget-password", input, options),
|
|
2470
2672
|
resetPassword: authResetPassword,
|
|
@@ -2559,6 +2761,7 @@ function createAuthClient(config = {}) {
|
|
|
2559
2761
|
}
|
|
2560
2762
|
},
|
|
2561
2763
|
hasPermission: (input, options) => postGeneric("/admin/has-permission", input, options),
|
|
2764
|
+
requirePermission: (input, options) => requirePermission("/admin/has-permission", input, options),
|
|
2562
2765
|
apiKey: {
|
|
2563
2766
|
create: (input, options) => postGeneric("/admin/api-key/create", input, options)
|
|
2564
2767
|
},
|
|
@@ -2710,6 +2913,8 @@ function createAuthClient(config = {}) {
|
|
|
2710
2913
|
input,
|
|
2711
2914
|
options
|
|
2712
2915
|
),
|
|
2916
|
+
getUser,
|
|
2917
|
+
requireSession,
|
|
2713
2918
|
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
2714
2919
|
resolvedConfig,
|
|
2715
2920
|
{ endpoint: "/list-sessions", method: "GET" },
|
|
@@ -5465,6 +5670,9 @@ var AthenaClientBuilderImpl = class {
|
|
|
5465
5670
|
apiKey;
|
|
5466
5671
|
backendConfig = DEFAULT_BACKEND;
|
|
5467
5672
|
clientName;
|
|
5673
|
+
defaultUserId;
|
|
5674
|
+
defaultOrganizationId;
|
|
5675
|
+
forceNoCacheEnabled = false;
|
|
5468
5676
|
defaultHeaders;
|
|
5469
5677
|
authConfig;
|
|
5470
5678
|
dbUrlOverride;
|
|
@@ -5513,6 +5721,15 @@ var AthenaClientBuilderImpl = class {
|
|
|
5513
5721
|
if (options.client !== void 0) {
|
|
5514
5722
|
this.clientName = options.client;
|
|
5515
5723
|
}
|
|
5724
|
+
if (options.userId !== void 0) {
|
|
5725
|
+
this.defaultUserId = options.userId;
|
|
5726
|
+
}
|
|
5727
|
+
if (options.organizationId !== void 0) {
|
|
5728
|
+
this.defaultOrganizationId = options.organizationId;
|
|
5729
|
+
}
|
|
5730
|
+
if (options.forceNoCache !== void 0) {
|
|
5731
|
+
this.forceNoCacheEnabled = options.forceNoCache;
|
|
5732
|
+
}
|
|
5516
5733
|
if (options.backend !== void 0) {
|
|
5517
5734
|
this.backendConfig = toBackendConfig(options.backend);
|
|
5518
5735
|
}
|
|
@@ -5567,6 +5784,9 @@ var AthenaClientBuilderImpl = class {
|
|
|
5567
5784
|
url: this.rootUrl,
|
|
5568
5785
|
key: this.apiKey,
|
|
5569
5786
|
client: this.clientName,
|
|
5787
|
+
userId: this.defaultUserId,
|
|
5788
|
+
organizationId: this.defaultOrganizationId,
|
|
5789
|
+
forceNoCache: this.forceNoCacheEnabled,
|
|
5570
5790
|
backend: this.backendConfig,
|
|
5571
5791
|
headers: this.defaultHeaders,
|
|
5572
5792
|
db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
|
|
@@ -8109,6 +8329,83 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
|
8109
8329
|
);
|
|
8110
8330
|
};
|
|
8111
8331
|
}
|
|
8332
|
+
var ATHENA_ENV_URL_KEYS = ["ATHENA_URL", "NEXT_PUBLIC_ATHENA_URL"];
|
|
8333
|
+
var ATHENA_ENV_GATEWAY_URL_KEYS = [
|
|
8334
|
+
"ATHENA_DB_URL",
|
|
8335
|
+
"ATHENA_GATEWAY_URL",
|
|
8336
|
+
"NEXT_PUBLIC_ATHENA_DB_API_URL"
|
|
8337
|
+
];
|
|
8338
|
+
var ATHENA_ENV_AUTH_URL_KEYS = ["ATHENA_AUTH_URL", "NEXT_PUBLIC_ATHENA_AUTH_URL"];
|
|
8339
|
+
var ATHENA_ENV_STORAGE_URL_KEYS = ["ATHENA_STORAGE_URL", "NEXT_PUBLIC_ATHENA_STORAGE_URL"];
|
|
8340
|
+
var ATHENA_ENV_KEY_KEYS = [
|
|
8341
|
+
"ATHENA_API_KEY",
|
|
8342
|
+
"NEXT_PUBLIC_ATHENA_API_KEY",
|
|
8343
|
+
"ATHENA_GATEWAY_API_KEY",
|
|
8344
|
+
"X_API_KEY"
|
|
8345
|
+
];
|
|
8346
|
+
var ATHENA_ENV_CLIENT_KEYS = ["ATHENA_CLIENT", "NEXT_PUBLIC_ATHENA_CLIENT"];
|
|
8347
|
+
function normalizeOptionalString(value) {
|
|
8348
|
+
if (typeof value !== "string") {
|
|
8349
|
+
return void 0;
|
|
8350
|
+
}
|
|
8351
|
+
const normalizedValue = value.trim();
|
|
8352
|
+
return normalizedValue ? normalizedValue : void 0;
|
|
8353
|
+
}
|
|
8354
|
+
function readFirstEnvValue(env, keys) {
|
|
8355
|
+
for (const key of keys) {
|
|
8356
|
+
const value = normalizeOptionalString(env[key]);
|
|
8357
|
+
if (value) {
|
|
8358
|
+
return value;
|
|
8359
|
+
}
|
|
8360
|
+
}
|
|
8361
|
+
return void 0;
|
|
8362
|
+
}
|
|
8363
|
+
function readHeaderBagValue(headers, targetKey) {
|
|
8364
|
+
if (!headers) {
|
|
8365
|
+
return void 0;
|
|
8366
|
+
}
|
|
8367
|
+
if (typeof headers.get === "function") {
|
|
8368
|
+
return normalizeOptionalString(headers.get(targetKey));
|
|
8369
|
+
}
|
|
8370
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
8371
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
8372
|
+
if (key.toLowerCase() !== normalizedTargetKey) {
|
|
8373
|
+
continue;
|
|
8374
|
+
}
|
|
8375
|
+
if (typeof value === "string") {
|
|
8376
|
+
return normalizeOptionalString(value);
|
|
8377
|
+
}
|
|
8378
|
+
return void 0;
|
|
8379
|
+
}
|
|
8380
|
+
return void 0;
|
|
8381
|
+
}
|
|
8382
|
+
function resolveSessionContextOptions(session, options) {
|
|
8383
|
+
const sessionToken = normalizeOptionalString(session?.session?.token);
|
|
8384
|
+
const requestCookie = readHeaderBagValue(options?.requestHeaders, "cookie") ?? readHeaderBagValue(options?.headers, "cookie");
|
|
8385
|
+
const authInput = options?.auth;
|
|
8386
|
+
const resolvedUserId = options?.userId !== void 0 ? options.userId : session?.user?.id;
|
|
8387
|
+
const resolvedOrganizationId = options?.organizationId !== void 0 ? options.organizationId : session?.session?.activeOrganizationId;
|
|
8388
|
+
const resolvedBearerToken = authInput?.bearerToken !== void 0 ? authInput.bearerToken : sessionToken;
|
|
8389
|
+
const resolvedSessionToken = authInput?.sessionToken !== void 0 ? authInput.sessionToken : sessionToken;
|
|
8390
|
+
const resolvedCookie = authInput?.cookie !== void 0 ? authInput.cookie : requestCookie;
|
|
8391
|
+
const auth = authInput !== void 0 || resolvedBearerToken !== void 0 || resolvedSessionToken !== void 0 || resolvedCookie !== void 0 ? {
|
|
8392
|
+
...authInput ?? {},
|
|
8393
|
+
...resolvedBearerToken !== void 0 ? { bearerToken: resolvedBearerToken } : {},
|
|
8394
|
+
...resolvedSessionToken !== void 0 ? { sessionToken: resolvedSessionToken } : {},
|
|
8395
|
+
...resolvedCookie !== void 0 ? { cookie: resolvedCookie } : {},
|
|
8396
|
+
headers: authInput?.headers ? { ...authInput.headers } : void 0
|
|
8397
|
+
} : void 0;
|
|
8398
|
+
if (resolvedUserId === void 0 && resolvedOrganizationId === void 0 && options?.forceNoCache === void 0 && !options?.headers && !auth) {
|
|
8399
|
+
return void 0;
|
|
8400
|
+
}
|
|
8401
|
+
return {
|
|
8402
|
+
userId: resolvedUserId,
|
|
8403
|
+
organizationId: resolvedOrganizationId,
|
|
8404
|
+
forceNoCache: options?.forceNoCache,
|
|
8405
|
+
headers: options?.headers ? { ...options.headers } : void 0,
|
|
8406
|
+
auth
|
|
8407
|
+
};
|
|
8408
|
+
}
|
|
8112
8409
|
function resolveClientServiceBaseUrl(value, label) {
|
|
8113
8410
|
if (value === void 0 || value === null) {
|
|
8114
8411
|
return void 0;
|
|
@@ -8151,6 +8448,87 @@ function resolveRequiredClientApiKey(value) {
|
|
|
8151
8448
|
}
|
|
8152
8449
|
return normalizedValue;
|
|
8153
8450
|
}
|
|
8451
|
+
function hasHeaderIgnoreCase(headers, targetKey) {
|
|
8452
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
8453
|
+
return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
|
|
8454
|
+
}
|
|
8455
|
+
function mergeClientHeaders(current, next) {
|
|
8456
|
+
if (!current && !next) {
|
|
8457
|
+
return void 0;
|
|
8458
|
+
}
|
|
8459
|
+
return {
|
|
8460
|
+
...current ?? {},
|
|
8461
|
+
...next ?? {}
|
|
8462
|
+
};
|
|
8463
|
+
}
|
|
8464
|
+
function mergeDefinedObject(current, next) {
|
|
8465
|
+
if (!current && !next) {
|
|
8466
|
+
return void 0;
|
|
8467
|
+
}
|
|
8468
|
+
const merged = {
|
|
8469
|
+
...current ?? {}
|
|
8470
|
+
};
|
|
8471
|
+
const mutableMerged = merged;
|
|
8472
|
+
for (const [key, value] of Object.entries(next ?? {})) {
|
|
8473
|
+
if (value !== void 0) {
|
|
8474
|
+
mutableMerged[key] = value;
|
|
8475
|
+
}
|
|
8476
|
+
}
|
|
8477
|
+
return merged;
|
|
8478
|
+
}
|
|
8479
|
+
function mergeAuthClientOptions(current, next) {
|
|
8480
|
+
const merged = mergeDefinedObject(current, next);
|
|
8481
|
+
if (!merged) {
|
|
8482
|
+
return void 0;
|
|
8483
|
+
}
|
|
8484
|
+
const mergedHeaders = mergeClientHeaders(current?.headers, next?.headers);
|
|
8485
|
+
if (mergedHeaders) {
|
|
8486
|
+
merged.headers = mergedHeaders;
|
|
8487
|
+
}
|
|
8488
|
+
return merged;
|
|
8489
|
+
}
|
|
8490
|
+
function mergeServiceUrlOverrides(current, next) {
|
|
8491
|
+
return mergeDefinedObject(current, next);
|
|
8492
|
+
}
|
|
8493
|
+
function toClientContextOverrides(context) {
|
|
8494
|
+
if (!context) {
|
|
8495
|
+
return void 0;
|
|
8496
|
+
}
|
|
8497
|
+
return {
|
|
8498
|
+
userId: context.userId,
|
|
8499
|
+
organizationId: context.organizationId,
|
|
8500
|
+
forceNoCache: context.forceNoCache,
|
|
8501
|
+
headers: context.headers,
|
|
8502
|
+
auth: context.auth ? {
|
|
8503
|
+
...context.auth,
|
|
8504
|
+
headers: context.auth.headers ? { ...context.auth.headers } : void 0
|
|
8505
|
+
} : void 0
|
|
8506
|
+
};
|
|
8507
|
+
}
|
|
8508
|
+
function mergeClientOverrideOptions(base, overrides) {
|
|
8509
|
+
if (!overrides) {
|
|
8510
|
+
return {
|
|
8511
|
+
...base,
|
|
8512
|
+
headers: base.headers ? { ...base.headers } : void 0,
|
|
8513
|
+
auth: base.auth ? {
|
|
8514
|
+
...base.auth,
|
|
8515
|
+
headers: base.auth.headers ? { ...base.auth.headers } : void 0
|
|
8516
|
+
} : void 0,
|
|
8517
|
+
db: base.db ? { ...base.db } : void 0,
|
|
8518
|
+
gateway: base.gateway ? { ...base.gateway } : void 0,
|
|
8519
|
+
storage: base.storage ? { ...base.storage } : void 0
|
|
8520
|
+
};
|
|
8521
|
+
}
|
|
8522
|
+
const merged = mergeDefinedObject(base, overrides) ?? { ...base };
|
|
8523
|
+
return {
|
|
8524
|
+
...merged,
|
|
8525
|
+
headers: mergeClientHeaders(base.headers, overrides.headers),
|
|
8526
|
+
auth: mergeAuthClientOptions(base.auth, overrides.auth),
|
|
8527
|
+
db: mergeServiceUrlOverrides(base.db, overrides.db),
|
|
8528
|
+
gateway: mergeServiceUrlOverrides(base.gateway, overrides.gateway),
|
|
8529
|
+
storage: mergeServiceUrlOverrides(base.storage, overrides.storage)
|
|
8530
|
+
};
|
|
8531
|
+
}
|
|
8154
8532
|
function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
8155
8533
|
if (!auth && defaultBaseUrl === void 0) {
|
|
8156
8534
|
return void 0;
|
|
@@ -8160,6 +8538,8 @@ function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
|
8160
8538
|
baseUrl,
|
|
8161
8539
|
apiKey,
|
|
8162
8540
|
bearerToken,
|
|
8541
|
+
cookie,
|
|
8542
|
+
sessionToken,
|
|
8163
8543
|
...rest
|
|
8164
8544
|
} = auth ?? {};
|
|
8165
8545
|
const normalized = {
|
|
@@ -8178,6 +8558,12 @@ function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
|
8178
8558
|
if (typeof bearerToken === "string") {
|
|
8179
8559
|
normalized.bearerToken = bearerToken;
|
|
8180
8560
|
}
|
|
8561
|
+
if (typeof cookie === "string") {
|
|
8562
|
+
normalized.cookie = cookie;
|
|
8563
|
+
}
|
|
8564
|
+
if (typeof sessionToken === "string") {
|
|
8565
|
+
normalized.sessionToken = sessionToken;
|
|
8566
|
+
}
|
|
8181
8567
|
return normalized;
|
|
8182
8568
|
}
|
|
8183
8569
|
function resolveCreateClientConfig(config) {
|
|
@@ -8191,6 +8577,9 @@ function resolveCreateClientConfig(config) {
|
|
|
8191
8577
|
baseUrl: resolvedUrls.dbUrl,
|
|
8192
8578
|
apiKey: resolveRequiredClientApiKey(config.key),
|
|
8193
8579
|
client: resolveOptionalClientName(config.client),
|
|
8580
|
+
userId: config.userId,
|
|
8581
|
+
organizationId: config.organizationId,
|
|
8582
|
+
forceNoCache: config.forceNoCache,
|
|
8194
8583
|
backend: toBackendConfig(config.backend),
|
|
8195
8584
|
headers: config.headers,
|
|
8196
8585
|
auth: config.auth,
|
|
@@ -8199,23 +8588,39 @@ function resolveCreateClientConfig(config) {
|
|
|
8199
8588
|
experimental: config.experimental
|
|
8200
8589
|
};
|
|
8201
8590
|
}
|
|
8202
|
-
function
|
|
8591
|
+
function createClientFromInput(sourceConfig) {
|
|
8592
|
+
return createClientFromConfig(resolveCreateClientConfig(sourceConfig), sourceConfig);
|
|
8593
|
+
}
|
|
8594
|
+
function createClientFromConfig(config, sourceConfig) {
|
|
8595
|
+
const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
|
|
8203
8596
|
const gatewayHeaders = {
|
|
8204
8597
|
...config.headers ?? {}
|
|
8205
8598
|
};
|
|
8206
|
-
if (
|
|
8207
|
-
gatewayHeaders["X-Athena-Auth-Bearer-Token"] =
|
|
8599
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
|
|
8600
|
+
gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
|
|
8601
|
+
}
|
|
8602
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
|
|
8603
|
+
gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
|
|
8604
|
+
}
|
|
8605
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
|
|
8606
|
+
gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
8208
8607
|
}
|
|
8209
8608
|
const gateway = createAthenaGatewayClient({
|
|
8210
8609
|
baseUrl: config.baseUrl,
|
|
8211
8610
|
apiKey: config.apiKey,
|
|
8212
8611
|
client: config.client,
|
|
8612
|
+
userId: config.userId,
|
|
8613
|
+
organizationId: config.organizationId,
|
|
8614
|
+
forceNoCache: config.forceNoCache,
|
|
8213
8615
|
backend: config.backend,
|
|
8214
8616
|
headers: gatewayHeaders
|
|
8215
8617
|
});
|
|
8216
8618
|
const formatGatewayResult = createResultFormatter(config.experimental);
|
|
8217
8619
|
const queryTracer = createQueryTracer(config.experimental);
|
|
8218
|
-
const auth = createAuthClient(
|
|
8620
|
+
const auth = createAuthClient({
|
|
8621
|
+
...normalizedAuthConfig ?? {},
|
|
8622
|
+
...config.forceNoCache ? { forceNoCache: true } : {}
|
|
8623
|
+
});
|
|
8219
8624
|
function from(tableOrModel, options) {
|
|
8220
8625
|
if (isAthenaModelTarget(tableOrModel)) {
|
|
8221
8626
|
if (options?.schema !== void 0) {
|
|
@@ -8263,17 +8668,45 @@ function createClientFromConfig(config) {
|
|
|
8263
8668
|
queryTracer
|
|
8264
8669
|
);
|
|
8265
8670
|
const db = createDbModule({ from, rpc, query });
|
|
8671
|
+
const withContext = (context) => createClientFromInput(
|
|
8672
|
+
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
8673
|
+
);
|
|
8674
|
+
const withSession = (session, options) => createClientFromInput(
|
|
8675
|
+
mergeClientOverrideOptions(
|
|
8676
|
+
sourceConfig,
|
|
8677
|
+
toClientContextOverrides(resolveSessionContextOptions(session, options))
|
|
8678
|
+
)
|
|
8679
|
+
);
|
|
8680
|
+
const authWithOptions = (options) => createClientFromInput(mergeClientOverrideOptions(sourceConfig, options));
|
|
8266
8681
|
const sdkClient = {
|
|
8267
8682
|
from,
|
|
8268
8683
|
db,
|
|
8269
8684
|
rpc,
|
|
8270
8685
|
query,
|
|
8271
8686
|
verifyConnection: gateway.verifyConnection,
|
|
8272
|
-
auth: auth.auth
|
|
8687
|
+
auth: auth.auth,
|
|
8688
|
+
withContext,
|
|
8689
|
+
withSession,
|
|
8690
|
+
withOptions: authWithOptions
|
|
8273
8691
|
};
|
|
8274
8692
|
if (config.experimental?.athenaStorageBackend) {
|
|
8693
|
+
const storageWithContext = (context) => createClientFromInput(
|
|
8694
|
+
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
8695
|
+
);
|
|
8696
|
+
const storageWithSession = (session, options) => createClientFromInput(
|
|
8697
|
+
mergeClientOverrideOptions(
|
|
8698
|
+
sourceConfig,
|
|
8699
|
+
toClientContextOverrides(resolveSessionContextOptions(session, options))
|
|
8700
|
+
)
|
|
8701
|
+
);
|
|
8702
|
+
const storageWithOptions = (options) => createClientFromInput(
|
|
8703
|
+
mergeClientOverrideOptions(sourceConfig, options)
|
|
8704
|
+
);
|
|
8275
8705
|
const storageClient = {
|
|
8276
8706
|
...sdkClient,
|
|
8707
|
+
withContext: storageWithContext,
|
|
8708
|
+
withSession: storageWithSession,
|
|
8709
|
+
withOptions: storageWithOptions,
|
|
8277
8710
|
storage: createStorageModule(gateway, {
|
|
8278
8711
|
...config.experimental.storage,
|
|
8279
8712
|
...config.storageUrl ? {
|
|
@@ -8289,38 +8722,42 @@ function createClientFromConfig(config) {
|
|
|
8289
8722
|
var AthenaClient = class {
|
|
8290
8723
|
/** Create a fluent builder for a strongly-typed Athena SDK client. */
|
|
8291
8724
|
static builder() {
|
|
8292
|
-
return createAthenaClientBuilder((config) =>
|
|
8293
|
-
}
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
const url =
|
|
8297
|
-
const gatewayUrl =
|
|
8298
|
-
const authUrl =
|
|
8299
|
-
const storageUrl =
|
|
8300
|
-
const key =
|
|
8725
|
+
return createAthenaClientBuilder((config) => createClientFromInput(config));
|
|
8726
|
+
}
|
|
8727
|
+
static fromEnvironment(options = {}) {
|
|
8728
|
+
const env = options.env ?? process.env;
|
|
8729
|
+
const url = options.url ?? readFirstEnvValue(env, ATHENA_ENV_URL_KEYS);
|
|
8730
|
+
const gatewayUrl = options.gatewayUrl ?? readFirstEnvValue(env, ATHENA_ENV_GATEWAY_URL_KEYS);
|
|
8731
|
+
const authUrl = options.authUrl ?? readFirstEnvValue(env, ATHENA_ENV_AUTH_URL_KEYS);
|
|
8732
|
+
const storageUrl = options.storageUrl ?? readFirstEnvValue(env, ATHENA_ENV_STORAGE_URL_KEYS);
|
|
8733
|
+
const key = options.key ?? readFirstEnvValue(env, ATHENA_ENV_KEY_KEYS);
|
|
8734
|
+
const client = options.client ?? readFirstEnvValue(env, ATHENA_ENV_CLIENT_KEYS);
|
|
8301
8735
|
if (!url && !gatewayUrl || !key) {
|
|
8302
8736
|
throw new Error(
|
|
8303
|
-
"
|
|
8737
|
+
"AthenaClient.fromEnvironment() requires an API key plus a public or gateway URL. Supported aliases include ATHENA_API_KEY, NEXT_PUBLIC_ATHENA_API_KEY, ATHENA_GATEWAY_API_KEY, X_API_KEY, ATHENA_URL, NEXT_PUBLIC_ATHENA_URL, ATHENA_GATEWAY_URL, and ATHENA_DB_URL."
|
|
8304
8738
|
);
|
|
8305
8739
|
}
|
|
8740
|
+
const { env: _env, ...clientOptions } = options;
|
|
8306
8741
|
return createClient({
|
|
8742
|
+
...clientOptions,
|
|
8307
8743
|
url,
|
|
8308
8744
|
gatewayUrl,
|
|
8309
8745
|
authUrl,
|
|
8310
8746
|
storageUrl,
|
|
8311
|
-
key
|
|
8747
|
+
key,
|
|
8748
|
+
client
|
|
8312
8749
|
});
|
|
8313
8750
|
}
|
|
8314
8751
|
};
|
|
8315
8752
|
function createClient(configOrUrl, apiKey, options) {
|
|
8316
8753
|
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
8317
|
-
return
|
|
8754
|
+
return createClientFromInput({
|
|
8318
8755
|
url: configOrUrl,
|
|
8319
8756
|
key: apiKey ?? "",
|
|
8320
8757
|
...options
|
|
8321
|
-
})
|
|
8758
|
+
});
|
|
8322
8759
|
}
|
|
8323
|
-
return
|
|
8760
|
+
return createClientFromInput(configOrUrl);
|
|
8324
8761
|
}
|
|
8325
8762
|
|
|
8326
8763
|
// src/gateway/types.ts
|
|
@@ -8686,6 +9123,9 @@ function createColumnsBuilder(name, mappedName, schemaName, columns) {
|
|
|
8686
9123
|
resolveTableTarget(name, mappedName, normalizedSchemaName);
|
|
8687
9124
|
return createColumnsBuilder(name, mappedName, normalizedSchemaName, columns);
|
|
8688
9125
|
},
|
|
9126
|
+
withoutPrimaryKey() {
|
|
9127
|
+
return finalizeTable(name, mappedName, schemaName, columns, []);
|
|
9128
|
+
},
|
|
8689
9129
|
primaryKey(...keys) {
|
|
8690
9130
|
return finalizeTable(name, mappedName, schemaName, columns, keys);
|
|
8691
9131
|
}
|
|
@@ -8737,6 +9177,59 @@ var TenantHeaderMapper = class {
|
|
|
8737
9177
|
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
8738
9178
|
}
|
|
8739
9179
|
};
|
|
9180
|
+
function normalizeOptionalString2(value) {
|
|
9181
|
+
if (typeof value !== "string") {
|
|
9182
|
+
return void 0;
|
|
9183
|
+
}
|
|
9184
|
+
const normalizedValue = value.trim();
|
|
9185
|
+
return normalizedValue ? normalizedValue : void 0;
|
|
9186
|
+
}
|
|
9187
|
+
function readHeaderBagValue2(headers, targetKey) {
|
|
9188
|
+
if (!headers) {
|
|
9189
|
+
return void 0;
|
|
9190
|
+
}
|
|
9191
|
+
if (typeof headers.get === "function") {
|
|
9192
|
+
return normalizeOptionalString2(headers.get(targetKey));
|
|
9193
|
+
}
|
|
9194
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
9195
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
9196
|
+
if (key.toLowerCase() !== normalizedTargetKey) {
|
|
9197
|
+
continue;
|
|
9198
|
+
}
|
|
9199
|
+
if (typeof value === "string") {
|
|
9200
|
+
return normalizeOptionalString2(value);
|
|
9201
|
+
}
|
|
9202
|
+
return void 0;
|
|
9203
|
+
}
|
|
9204
|
+
return void 0;
|
|
9205
|
+
}
|
|
9206
|
+
function resolveSessionContextOptions2(session, options) {
|
|
9207
|
+
const sessionToken = normalizeOptionalString2(session?.session?.token);
|
|
9208
|
+
const requestCookie = readHeaderBagValue2(options?.requestHeaders, "cookie") ?? readHeaderBagValue2(options?.headers, "cookie");
|
|
9209
|
+
const authInput = options?.auth;
|
|
9210
|
+
const resolvedUserId = options?.userId !== void 0 ? options.userId : session?.user?.id;
|
|
9211
|
+
const resolvedOrganizationId = options?.organizationId !== void 0 ? options.organizationId : session?.session?.activeOrganizationId;
|
|
9212
|
+
const resolvedBearerToken = authInput?.bearerToken !== void 0 ? authInput.bearerToken : sessionToken;
|
|
9213
|
+
const resolvedSessionToken = authInput?.sessionToken !== void 0 ? authInput.sessionToken : sessionToken;
|
|
9214
|
+
const resolvedCookie = authInput?.cookie !== void 0 ? authInput.cookie : requestCookie;
|
|
9215
|
+
const auth = authInput !== void 0 || resolvedBearerToken !== void 0 || resolvedSessionToken !== void 0 || resolvedCookie !== void 0 ? {
|
|
9216
|
+
...authInput ?? {},
|
|
9217
|
+
...resolvedBearerToken !== void 0 ? { bearerToken: resolvedBearerToken } : {},
|
|
9218
|
+
...resolvedSessionToken !== void 0 ? { sessionToken: resolvedSessionToken } : {},
|
|
9219
|
+
...resolvedCookie !== void 0 ? { cookie: resolvedCookie } : {},
|
|
9220
|
+
headers: authInput?.headers ? { ...authInput.headers } : void 0
|
|
9221
|
+
} : void 0;
|
|
9222
|
+
if (resolvedUserId === void 0 && resolvedOrganizationId === void 0 && options?.forceNoCache === void 0 && !options?.headers && !auth) {
|
|
9223
|
+
return void 0;
|
|
9224
|
+
}
|
|
9225
|
+
return {
|
|
9226
|
+
userId: resolvedUserId,
|
|
9227
|
+
organizationId: resolvedOrganizationId,
|
|
9228
|
+
forceNoCache: options?.forceNoCache,
|
|
9229
|
+
headers: options?.headers ? { ...options.headers } : void 0,
|
|
9230
|
+
auth
|
|
9231
|
+
};
|
|
9232
|
+
}
|
|
8740
9233
|
var RegistryNavigator = class {
|
|
8741
9234
|
constructor(registry) {
|
|
8742
9235
|
this.registry = registry;
|
|
@@ -8788,12 +9281,22 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
8788
9281
|
backend: input.options?.backend,
|
|
8789
9282
|
client: input.options?.client,
|
|
8790
9283
|
headers: input.options?.headers,
|
|
9284
|
+
forceNoCache: input.options?.forceNoCache,
|
|
9285
|
+
userId: input.options?.userId,
|
|
9286
|
+
organizationId: input.options?.organizationId,
|
|
9287
|
+
auth: input.options?.auth,
|
|
9288
|
+
tenantKeyMap,
|
|
9289
|
+
tenantContext,
|
|
8791
9290
|
experimental: input.options?.experimental
|
|
8792
9291
|
};
|
|
8793
9292
|
this.baseClient = createClient(this.url, this.apiKey, {
|
|
8794
9293
|
backend: this.clientOptions.backend,
|
|
8795
9294
|
client: this.clientOptions.client,
|
|
8796
9295
|
headers: this.tenantHeaderMapper.apply(this.clientOptions.headers, tenantContext),
|
|
9296
|
+
forceNoCache: this.clientOptions.forceNoCache,
|
|
9297
|
+
userId: this.clientOptions.userId,
|
|
9298
|
+
organizationId: this.clientOptions.organizationId,
|
|
9299
|
+
auth: this.clientOptions.auth,
|
|
8797
9300
|
experimental: this.clientOptions.experimental
|
|
8798
9301
|
});
|
|
8799
9302
|
this.db = this.baseClient.db;
|
|
@@ -8811,6 +9314,40 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
8811
9314
|
verifyConnection(options) {
|
|
8812
9315
|
return this.baseClient.verifyConnection(options);
|
|
8813
9316
|
}
|
|
9317
|
+
withContext(context) {
|
|
9318
|
+
const headers = {
|
|
9319
|
+
...this.clientOptions.headers ?? {},
|
|
9320
|
+
...context?.headers ?? {}
|
|
9321
|
+
};
|
|
9322
|
+
const auth = this.clientOptions.auth || context?.auth ? {
|
|
9323
|
+
...this.clientOptions.auth ?? {},
|
|
9324
|
+
...context?.auth ?? {},
|
|
9325
|
+
headers: this.clientOptions.auth?.headers || context?.auth?.headers ? {
|
|
9326
|
+
...this.clientOptions.auth?.headers ?? {},
|
|
9327
|
+
...context?.auth?.headers ?? {}
|
|
9328
|
+
} : void 0
|
|
9329
|
+
} : void 0;
|
|
9330
|
+
return new _TypedAthenaClientImpl({
|
|
9331
|
+
registry: this.registry,
|
|
9332
|
+
url: this.url,
|
|
9333
|
+
apiKey: this.apiKey,
|
|
9334
|
+
options: {
|
|
9335
|
+
...this.clientOptions,
|
|
9336
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0,
|
|
9337
|
+
auth,
|
|
9338
|
+
tenantKeyMap: this.tenantKeyMap,
|
|
9339
|
+
tenantContext: {
|
|
9340
|
+
...this.tenantContext
|
|
9341
|
+
},
|
|
9342
|
+
...context?.userId !== void 0 ? { userId: context.userId } : {},
|
|
9343
|
+
...context?.organizationId !== void 0 ? { organizationId: context.organizationId } : {},
|
|
9344
|
+
...context?.forceNoCache !== void 0 ? { forceNoCache: context.forceNoCache } : {}
|
|
9345
|
+
}
|
|
9346
|
+
});
|
|
9347
|
+
}
|
|
9348
|
+
withSession(session, options) {
|
|
9349
|
+
return this.withContext(resolveSessionContextOptions2(session, options));
|
|
9350
|
+
}
|
|
8814
9351
|
withTenantContext(context) {
|
|
8815
9352
|
return new _TypedAthenaClientImpl({
|
|
8816
9353
|
registry: this.registry,
|
|
@@ -9306,6 +9843,77 @@ function resolveProviderSchemas(providerConfig) {
|
|
|
9306
9843
|
return [...DEFAULT_POSTGRES_SCHEMAS];
|
|
9307
9844
|
}
|
|
9308
9845
|
|
|
9846
|
+
// src/generator/table-selection.ts
|
|
9847
|
+
function normalizeTableSelector(value) {
|
|
9848
|
+
const trimmed = value.trim();
|
|
9849
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
9850
|
+
}
|
|
9851
|
+
function normalizeTableSelection(value) {
|
|
9852
|
+
if (typeof value === "string") {
|
|
9853
|
+
return Array.from(
|
|
9854
|
+
new Set(
|
|
9855
|
+
value.split(",").map(normalizeTableSelector).filter((entry) => Boolean(entry))
|
|
9856
|
+
)
|
|
9857
|
+
);
|
|
9858
|
+
}
|
|
9859
|
+
if (Array.isArray(value)) {
|
|
9860
|
+
return Array.from(
|
|
9861
|
+
new Set(
|
|
9862
|
+
value.map((entry) => typeof entry === "string" ? normalizeTableSelector(entry) : void 0).filter((entry) => Boolean(entry))
|
|
9863
|
+
)
|
|
9864
|
+
);
|
|
9865
|
+
}
|
|
9866
|
+
return [];
|
|
9867
|
+
}
|
|
9868
|
+
function matchesTableSelector(schemaName, tableName, selector) {
|
|
9869
|
+
const separatorIndex = selector.indexOf(".");
|
|
9870
|
+
if (separatorIndex < 0) {
|
|
9871
|
+
return tableName === selector;
|
|
9872
|
+
}
|
|
9873
|
+
const selectorSchema = selector.slice(0, separatorIndex).trim();
|
|
9874
|
+
const selectorTable = selector.slice(separatorIndex + 1).trim();
|
|
9875
|
+
return selectorSchema === schemaName && selectorTable === tableName;
|
|
9876
|
+
}
|
|
9877
|
+
function shouldKeepTable(schemaName, tableName, filter) {
|
|
9878
|
+
const included = filter.includeTables.length === 0 || filter.includeTables.some((selector) => matchesTableSelector(schemaName, tableName, selector));
|
|
9879
|
+
if (!included) {
|
|
9880
|
+
return false;
|
|
9881
|
+
}
|
|
9882
|
+
return !filter.excludeTables.some((selector) => matchesTableSelector(schemaName, tableName, selector));
|
|
9883
|
+
}
|
|
9884
|
+
function hasTableFilters(filter) {
|
|
9885
|
+
return filter.includeTables.length > 0 || filter.excludeTables.length > 0;
|
|
9886
|
+
}
|
|
9887
|
+
function filterIntrospectionSnapshot(snapshot, filter) {
|
|
9888
|
+
if (!hasTableFilters(filter)) {
|
|
9889
|
+
return snapshot;
|
|
9890
|
+
}
|
|
9891
|
+
const schemas = {};
|
|
9892
|
+
for (const [schemaName, schema] of Object.entries(snapshot.schemas)) {
|
|
9893
|
+
const tables = Object.fromEntries(
|
|
9894
|
+
Object.entries(schema.tables).filter(([tableName]) => shouldKeepTable(schemaName, tableName, filter))
|
|
9895
|
+
);
|
|
9896
|
+
if (Object.keys(tables).length === 0) {
|
|
9897
|
+
continue;
|
|
9898
|
+
}
|
|
9899
|
+
schemas[schemaName] = {
|
|
9900
|
+
...schema,
|
|
9901
|
+
tables
|
|
9902
|
+
};
|
|
9903
|
+
}
|
|
9904
|
+
if (Object.keys(schemas).length === 0) {
|
|
9905
|
+
const includeLabel = filter.includeTables.length > 0 ? ` includeTables=${filter.includeTables.join(", ")}` : "";
|
|
9906
|
+
const excludeLabel = filter.excludeTables.length > 0 ? ` excludeTables=${filter.excludeTables.join(", ")}` : "";
|
|
9907
|
+
throw new Error(
|
|
9908
|
+
`Generator table filters matched no tables after schema selection.${includeLabel}${excludeLabel}`
|
|
9909
|
+
);
|
|
9910
|
+
}
|
|
9911
|
+
return {
|
|
9912
|
+
...snapshot,
|
|
9913
|
+
schemas
|
|
9914
|
+
};
|
|
9915
|
+
}
|
|
9916
|
+
|
|
9309
9917
|
// src/generator/config.ts
|
|
9310
9918
|
var POSTGRES_PROTOCOLS = /* @__PURE__ */ new Set(["postgres:", "postgresql:"]);
|
|
9311
9919
|
var DEFAULT_CONFIG_CANDIDATES = [
|
|
@@ -9316,13 +9924,20 @@ var DEFAULT_CONFIG_CANDIDATES = [
|
|
|
9316
9924
|
".athena.config.ts",
|
|
9317
9925
|
".athena.config.js"
|
|
9318
9926
|
];
|
|
9319
|
-
var
|
|
9927
|
+
var LEGACY_DEFAULT_TARGETS = {
|
|
9320
9928
|
model: "athena/models/{schema_kebab}/{model_kebab}.ts",
|
|
9321
9929
|
schema: "athena/schemas/{schema_kebab}.ts",
|
|
9322
9930
|
database: "athena/relations.ts",
|
|
9323
9931
|
registry: "athena/config.ts"
|
|
9324
9932
|
};
|
|
9325
|
-
var
|
|
9933
|
+
var ATHENA_DIRECT_TARGETS = {
|
|
9934
|
+
model: "athena/models/{schema_kebab}/{model_kebab}.ts",
|
|
9935
|
+
schema: "athena/schemas/{schema_kebab}.ts",
|
|
9936
|
+
database: "athena/relations.ts",
|
|
9937
|
+
registry: "athena/registry.generated.ts"
|
|
9938
|
+
};
|
|
9939
|
+
var DEFAULT_OUTPUT_FORMAT = "table-builder";
|
|
9940
|
+
var DEFAULT_OUTPUT_PRESET = "athena-direct";
|
|
9326
9941
|
var DEFAULT_NAMING = {
|
|
9327
9942
|
modelType: "pascal",
|
|
9328
9943
|
modelConst: "camel",
|
|
@@ -9341,6 +9956,10 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
|
|
|
9341
9956
|
var DEFAULT_INTERNAL_CONFIG = {
|
|
9342
9957
|
schemaVersion: 1
|
|
9343
9958
|
};
|
|
9959
|
+
var DEFAULT_FILTER_CONFIG = {
|
|
9960
|
+
includeTables: [],
|
|
9961
|
+
excludeTables: []
|
|
9962
|
+
};
|
|
9344
9963
|
var PROJECT_ENV_FILENAMES = [".env", ".env.local"];
|
|
9345
9964
|
var DIRECT_CONNECTION_STRING_ENV_KEYS = [
|
|
9346
9965
|
"ATHENA_GENERATOR_PG_URL",
|
|
@@ -9359,10 +9978,13 @@ var GATEWAY_API_KEY_ENV_KEYS = [
|
|
|
9359
9978
|
];
|
|
9360
9979
|
var GENERATOR_SCHEMA_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMAS"];
|
|
9361
9980
|
var OUTPUT_FORMAT_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_FORMAT"];
|
|
9981
|
+
var OUTPUT_PRESET_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_PRESET"];
|
|
9362
9982
|
var MODEL_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_TARGET"];
|
|
9363
9983
|
var SCHEMA_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMA_TARGET"];
|
|
9364
9984
|
var DATABASE_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_DATABASE_TARGET"];
|
|
9365
9985
|
var REGISTRY_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_REGISTRY_TARGET"];
|
|
9986
|
+
var TABLES_ENV_KEYS = ["ATHENA_GENERATOR_TABLES"];
|
|
9987
|
+
var EXCLUDE_TABLES_ENV_KEYS = ["ATHENA_GENERATOR_EXCLUDE_TABLES"];
|
|
9366
9988
|
var PLACEHOLDER_MAP_ENV_KEYS = ["ATHENA_GENERATOR_PLACEHOLDER_MAP"];
|
|
9367
9989
|
var MODEL_TYPE_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_TYPE", "ATHENA_GENERATOR_MODEL_STYLE"];
|
|
9368
9990
|
var MODEL_CONST_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_CONST"];
|
|
@@ -9377,7 +9999,12 @@ var SCYLLA_PROVIDER_CONTRACTS_ENV_KEYS = ["ATHENA_GENERATOR_SCYLLA_PROVIDER_CONT
|
|
|
9377
9999
|
var ENV_ONLY_CONFIG_PATH = "[environment defaults]";
|
|
9378
10000
|
var NAMING_STYLE_VALUES = ["preserve", "camel", "pascal", "snake", "kebab"];
|
|
9379
10001
|
var OUTPUT_FORMAT_VALUES = ["define-model", "table-builder"];
|
|
10002
|
+
var OUTPUT_PRESET_VALUES = ["legacy", "athena-direct"];
|
|
9380
10003
|
var BACKEND_TYPE_VALUES = ["athena", "postgrest", "postgresql", "scylladb"];
|
|
10004
|
+
var OUTPUT_PRESET_TARGETS = {
|
|
10005
|
+
legacy: LEGACY_DEFAULT_TARGETS,
|
|
10006
|
+
"athena-direct": ATHENA_DIRECT_TARGETS
|
|
10007
|
+
};
|
|
9381
10008
|
function normalizeRawEnvValue(rawValue) {
|
|
9382
10009
|
if (rawValue.startsWith('"') && rawValue.endsWith('"') && rawValue.length >= 2) {
|
|
9383
10010
|
const inner = rawValue.slice(1, -1);
|
|
@@ -9513,7 +10140,7 @@ function deriveDatabaseNameFromConnectionString(connectionString) {
|
|
|
9513
10140
|
return void 0;
|
|
9514
10141
|
}
|
|
9515
10142
|
}
|
|
9516
|
-
function
|
|
10143
|
+
function normalizeOptionalString3(value, fallbackKeys) {
|
|
9517
10144
|
if (typeof value === "string") {
|
|
9518
10145
|
const trimmed = value.trim();
|
|
9519
10146
|
if (trimmed.length > 0) {
|
|
@@ -9523,7 +10150,7 @@ function normalizeOptionalString(value, fallbackKeys) {
|
|
|
9523
10150
|
return resolveFallbackValue(fallbackKeys);
|
|
9524
10151
|
}
|
|
9525
10152
|
function normalizeRequiredString(value, fieldLabel, fallbackKeys) {
|
|
9526
|
-
const resolved =
|
|
10153
|
+
const resolved = normalizeOptionalString3(value, fallbackKeys);
|
|
9527
10154
|
if (resolved) {
|
|
9528
10155
|
return resolved;
|
|
9529
10156
|
}
|
|
@@ -9584,11 +10211,19 @@ function normalizeExperimentalFlags(input) {
|
|
|
9584
10211
|
)
|
|
9585
10212
|
};
|
|
9586
10213
|
}
|
|
10214
|
+
function normalizeFilterConfig(input) {
|
|
10215
|
+
return {
|
|
10216
|
+
includeTables: normalizeTableSelection(input?.includeTables),
|
|
10217
|
+
excludeTables: normalizeTableSelection(input?.excludeTables)
|
|
10218
|
+
};
|
|
10219
|
+
}
|
|
9587
10220
|
function normalizeOutputConfig(output) {
|
|
10221
|
+
const preset = output?.preset ?? DEFAULT_OUTPUT_PRESET;
|
|
9588
10222
|
return {
|
|
9589
10223
|
format: output?.format ?? DEFAULT_OUTPUT_FORMAT,
|
|
10224
|
+
preset,
|
|
9590
10225
|
targets: {
|
|
9591
|
-
...
|
|
10226
|
+
...OUTPUT_PRESET_TARGETS[preset],
|
|
9592
10227
|
...output?.targets ?? {}
|
|
9593
10228
|
},
|
|
9594
10229
|
placeholderMap: {
|
|
@@ -9603,7 +10238,7 @@ function normalizeProviderConfig(provider) {
|
|
|
9603
10238
|
"provider.connectionString",
|
|
9604
10239
|
DIRECT_CONNECTION_STRING_ENV_KEYS
|
|
9605
10240
|
);
|
|
9606
|
-
const database =
|
|
10241
|
+
const database = normalizeOptionalString3(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? deriveDatabaseNameFromConnectionString(connectionString);
|
|
9607
10242
|
return {
|
|
9608
10243
|
...provider,
|
|
9609
10244
|
connectionString: applyPostgresPasswordFallback(connectionString),
|
|
@@ -9622,7 +10257,7 @@ function normalizeProviderConfig(provider) {
|
|
|
9622
10257
|
"provider.apiKey",
|
|
9623
10258
|
GATEWAY_API_KEY_ENV_KEYS
|
|
9624
10259
|
);
|
|
9625
|
-
const database =
|
|
10260
|
+
const database = normalizeOptionalString3(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? "postgres";
|
|
9626
10261
|
return {
|
|
9627
10262
|
...provider,
|
|
9628
10263
|
gatewayUrl,
|
|
@@ -9637,7 +10272,7 @@ function normalizeProviderConfig(provider) {
|
|
|
9637
10272
|
"Generator config is missing provider.contactPoints for scylla direct mode."
|
|
9638
10273
|
);
|
|
9639
10274
|
}
|
|
9640
|
-
const keyspace =
|
|
10275
|
+
const keyspace = normalizeOptionalString3(provider.keyspace, []);
|
|
9641
10276
|
if (!keyspace) {
|
|
9642
10277
|
throw new Error(
|
|
9643
10278
|
"Generator config is missing provider.keyspace for scylla direct mode."
|
|
@@ -9648,7 +10283,7 @@ function normalizeProviderConfig(provider) {
|
|
|
9648
10283
|
mode: "direct",
|
|
9649
10284
|
contactPoints: provider.contactPoints.slice(),
|
|
9650
10285
|
keyspace,
|
|
9651
|
-
datacenter:
|
|
10286
|
+
datacenter: normalizeOptionalString3(provider.datacenter, [])
|
|
9652
10287
|
};
|
|
9653
10288
|
}
|
|
9654
10289
|
return provider;
|
|
@@ -9668,6 +10303,10 @@ function normalizeGeneratorConfig(input) {
|
|
|
9668
10303
|
...DEFAULT_NAMING,
|
|
9669
10304
|
...input.naming ?? {}
|
|
9670
10305
|
},
|
|
10306
|
+
filter: {
|
|
10307
|
+
...DEFAULT_FILTER_CONFIG,
|
|
10308
|
+
...normalizeFilterConfig(input.filter)
|
|
10309
|
+
},
|
|
9671
10310
|
features: normalizeFeatureFlags(input.features),
|
|
9672
10311
|
experimental: normalizeExperimentalFlags(input.experimental),
|
|
9673
10312
|
internal: {
|
|
@@ -9731,16 +10370,18 @@ function importConfigModule(moduleSpecifier) {
|
|
|
9731
10370
|
}
|
|
9732
10371
|
function buildEnvironmentOutputConfig() {
|
|
9733
10372
|
const format = resolveOptionalOneOf(OUTPUT_FORMAT_ENV_KEYS, OUTPUT_FORMAT_VALUES);
|
|
10373
|
+
const preset = resolveOptionalOneOf(OUTPUT_PRESET_ENV_KEYS, OUTPUT_PRESET_VALUES);
|
|
9734
10374
|
const modelTarget = resolveFallbackValue(MODEL_TARGET_ENV_KEYS);
|
|
9735
10375
|
const schemaTarget = resolveFallbackValue(SCHEMA_TARGET_ENV_KEYS);
|
|
9736
10376
|
const databaseTarget = resolveFallbackValue(DATABASE_TARGET_ENV_KEYS);
|
|
9737
10377
|
const registryTarget = resolveFallbackValue(REGISTRY_TARGET_ENV_KEYS);
|
|
9738
10378
|
const placeholderMap = resolveOptionalJson(PLACEHOLDER_MAP_ENV_KEYS);
|
|
9739
|
-
if (format === void 0 && modelTarget === void 0 && schemaTarget === void 0 && databaseTarget === void 0 && registryTarget === void 0 && placeholderMap === void 0) {
|
|
10379
|
+
if (format === void 0 && preset === void 0 && modelTarget === void 0 && schemaTarget === void 0 && databaseTarget === void 0 && registryTarget === void 0 && placeholderMap === void 0) {
|
|
9740
10380
|
return void 0;
|
|
9741
10381
|
}
|
|
9742
10382
|
return {
|
|
9743
10383
|
format,
|
|
10384
|
+
preset,
|
|
9744
10385
|
targets: {
|
|
9745
10386
|
...modelTarget ? { model: modelTarget } : {},
|
|
9746
10387
|
...schemaTarget ? { schema: schemaTarget } : {},
|
|
@@ -9750,6 +10391,17 @@ function buildEnvironmentOutputConfig() {
|
|
|
9750
10391
|
placeholderMap
|
|
9751
10392
|
};
|
|
9752
10393
|
}
|
|
10394
|
+
function buildEnvironmentFilterConfig() {
|
|
10395
|
+
const includeTables = resolveFallbackValue(TABLES_ENV_KEYS);
|
|
10396
|
+
const excludeTables = resolveFallbackValue(EXCLUDE_TABLES_ENV_KEYS);
|
|
10397
|
+
if (includeTables === void 0 && excludeTables === void 0) {
|
|
10398
|
+
return void 0;
|
|
10399
|
+
}
|
|
10400
|
+
return {
|
|
10401
|
+
...includeTables !== void 0 ? { includeTables } : {},
|
|
10402
|
+
...excludeTables !== void 0 ? { excludeTables } : {}
|
|
10403
|
+
};
|
|
10404
|
+
}
|
|
9753
10405
|
function buildEnvironmentNamingConfig() {
|
|
9754
10406
|
const modelType = resolveOptionalOneOf(MODEL_TYPE_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
9755
10407
|
const modelConst = resolveOptionalOneOf(MODEL_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
@@ -9796,7 +10448,7 @@ function buildEnvironmentProviderConfig() {
|
|
|
9796
10448
|
kind: "postgres",
|
|
9797
10449
|
mode: "direct",
|
|
9798
10450
|
connectionString: directConnectionString,
|
|
9799
|
-
database:
|
|
10451
|
+
database: normalizeOptionalString3(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
9800
10452
|
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS))
|
|
9801
10453
|
};
|
|
9802
10454
|
}
|
|
@@ -9809,7 +10461,7 @@ function buildEnvironmentProviderConfig() {
|
|
|
9809
10461
|
mode: "gateway",
|
|
9810
10462
|
gatewayUrl,
|
|
9811
10463
|
apiKey,
|
|
9812
|
-
database:
|
|
10464
|
+
database: normalizeOptionalString3(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
9813
10465
|
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS)),
|
|
9814
10466
|
backend
|
|
9815
10467
|
};
|
|
@@ -9825,6 +10477,7 @@ function createEnvironmentGeneratorConfig() {
|
|
|
9825
10477
|
provider,
|
|
9826
10478
|
output: buildEnvironmentOutputConfig(),
|
|
9827
10479
|
naming: buildEnvironmentNamingConfig(),
|
|
10480
|
+
filter: buildEnvironmentFilterConfig(),
|
|
9828
10481
|
features: buildEnvironmentFeatureFlags(),
|
|
9829
10482
|
experimental: buildEnvironmentExperimentalFlags()
|
|
9830
10483
|
};
|
|
@@ -10310,7 +10963,7 @@ ${schemaEntries}
|
|
|
10310
10963
|
content
|
|
10311
10964
|
};
|
|
10312
10965
|
}
|
|
10313
|
-
function renderRegistryArtifact(registryPath, databasePath, databaseConstName, registryConstName, databaseName, generatedAt, outputFormat, schemaVersion) {
|
|
10966
|
+
function renderRegistryArtifact(registryPath, databasePath, databaseConstName, registryConstName, databaseName, generatedAt, outputPreset, outputFormat, schemaVersion) {
|
|
10314
10967
|
const databaseImportPath = toModuleImportPath(registryPath, databasePath);
|
|
10315
10968
|
const content = `import { defineRegistry } from '@xylex-group/athena'
|
|
10316
10969
|
import { ${databaseConstName} } from '${databaseImportPath}'
|
|
@@ -10319,6 +10972,7 @@ export const __athena_schema_meta = {
|
|
|
10319
10972
|
schemaVersion: ${schemaVersion},
|
|
10320
10973
|
generatedAt: ${escapeStringLiteral(generatedAt)},
|
|
10321
10974
|
database: ${escapeStringLiteral(databaseName)},
|
|
10975
|
+
outputPreset: ${escapeStringLiteral(outputPreset)},
|
|
10322
10976
|
outputFormat: ${escapeStringLiteral(outputFormat)},
|
|
10323
10977
|
} as const
|
|
10324
10978
|
|
|
@@ -10488,6 +11142,7 @@ function composeGeneratorArtifacts(input) {
|
|
|
10488
11142
|
toSafeIdentifier("registry", config.naming.registryConst, "registry"),
|
|
10489
11143
|
databaseName,
|
|
10490
11144
|
snapshot.generatedAt,
|
|
11145
|
+
config.output.preset,
|
|
10491
11146
|
config.output.format,
|
|
10492
11147
|
config.internal.schemaVersion
|
|
10493
11148
|
)
|
|
@@ -10593,7 +11248,7 @@ export const ${descriptor.tableConstName} = table(${escapeStringLiteral(descript
|
|
|
10593
11248
|
.columns({
|
|
10594
11249
|
${columnLines}
|
|
10595
11250
|
})
|
|
10596
|
-
.primaryKey(${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")})
|
|
11251
|
+
${descriptor.table.primaryKey.length > 0 ? `.primaryKey(${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")})` : ".withoutPrimaryKey()"}
|
|
10597
11252
|
${relationsAssignment ? `${relationsAssignment}` : ""}
|
|
10598
11253
|
export type ${descriptor.rowTypeName} = RowOf<typeof ${descriptor.tableConstName}>
|
|
10599
11254
|
export type ${descriptor.insertTypeName} = InsertOf<typeof ${descriptor.tableConstName}>
|
|
@@ -10690,11 +11345,12 @@ ${nullableLines}
|
|
|
10690
11345
|
}
|
|
10691
11346
|
function generateArtifactsFromSnapshot(snapshot, config) {
|
|
10692
11347
|
const normalizedConfig = "internal" in config ? config : normalizeGeneratorConfig(config);
|
|
11348
|
+
const filteredSnapshot = filterIntrospectionSnapshot(snapshot, normalizedConfig.filter);
|
|
10693
11349
|
if (normalizedConfig.output.format === "table-builder") {
|
|
10694
|
-
return generateTableBuilderArtifactsFromSnapshot(
|
|
11350
|
+
return generateTableBuilderArtifactsFromSnapshot(filteredSnapshot, normalizedConfig);
|
|
10695
11351
|
}
|
|
10696
11352
|
return composeGeneratorArtifacts({
|
|
10697
|
-
snapshot,
|
|
11353
|
+
snapshot: filteredSnapshot,
|
|
10698
11354
|
config: normalizedConfig,
|
|
10699
11355
|
createModelDescriptor({ providerName, databaseName, schemaName, tableName, table: table2 }) {
|
|
10700
11356
|
const modelConstName = toSafeIdentifier(
|
|
@@ -10724,7 +11380,7 @@ function generateArtifactsFromSnapshot(snapshot, config) {
|
|
|
10724
11380
|
table: table2
|
|
10725
11381
|
};
|
|
10726
11382
|
},
|
|
10727
|
-
renderModelArtifact: (descriptor) => renderModelArtifact2(
|
|
11383
|
+
renderModelArtifact: (descriptor) => renderModelArtifact2(filteredSnapshot.database, descriptor, normalizedConfig)
|
|
10728
11384
|
});
|
|
10729
11385
|
}
|
|
10730
11386
|
|
|
@@ -10844,16 +11500,25 @@ async function fileExists(path) {
|
|
|
10844
11500
|
}
|
|
10845
11501
|
async function writeArtifacts(files, cwd) {
|
|
10846
11502
|
const writtenFiles = [];
|
|
11503
|
+
const skippedFiles = [];
|
|
10847
11504
|
for (const file of files) {
|
|
10848
11505
|
const absolutePath = path.resolve(cwd, file.path);
|
|
10849
11506
|
if (!canOverwriteArtifact(file) && await fileExists(absolutePath)) {
|
|
11507
|
+
skippedFiles.push({
|
|
11508
|
+
kind: file.kind,
|
|
11509
|
+
path: file.path,
|
|
11510
|
+
reason: "protected-existing-file"
|
|
11511
|
+
});
|
|
10850
11512
|
continue;
|
|
10851
11513
|
}
|
|
10852
11514
|
await promises.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
10853
11515
|
await promises.writeFile(absolutePath, file.content, "utf8");
|
|
10854
11516
|
writtenFiles.push(file.path);
|
|
10855
11517
|
}
|
|
10856
|
-
return
|
|
11518
|
+
return {
|
|
11519
|
+
writtenFiles,
|
|
11520
|
+
skippedFiles
|
|
11521
|
+
};
|
|
10857
11522
|
}
|
|
10858
11523
|
async function runSchemaGenerator(options = {}) {
|
|
10859
11524
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -10867,12 +11532,13 @@ async function runSchemaGenerator(options = {}) {
|
|
|
10867
11532
|
schemas: resolveProviderSchemas(config.provider)
|
|
10868
11533
|
});
|
|
10869
11534
|
const generated = generateArtifactsFromSnapshot(snapshot, config);
|
|
10870
|
-
const
|
|
11535
|
+
const writeResult = options.dryRun ? { writtenFiles: [], skippedFiles: [] } : await writeArtifacts(generated.files, cwd);
|
|
10871
11536
|
return {
|
|
10872
11537
|
...generated,
|
|
10873
11538
|
configPath,
|
|
10874
11539
|
config,
|
|
10875
|
-
writtenFiles
|
|
11540
|
+
writtenFiles: writeResult.writtenFiles,
|
|
11541
|
+
skippedFiles: writeResult.skippedFiles
|
|
10876
11542
|
};
|
|
10877
11543
|
}
|
|
10878
11544
|
|
|
@@ -11303,7 +11969,12 @@ function athenaAuth(config) {
|
|
|
11303
11969
|
return auth;
|
|
11304
11970
|
}
|
|
11305
11971
|
|
|
11972
|
+
exports.ATHENA_AUTH_ADMIN_LIMITS = ATHENA_AUTH_ADMIN_LIMITS;
|
|
11306
11973
|
exports.ATHENA_AUTH_BASE_ERROR_CODES = ATHENA_AUTH_BASE_ERROR_CODES;
|
|
11974
|
+
exports.ATHENA_AUTH_MAX_ADMIN_JSON_BYTES = ATHENA_AUTH_MAX_ADMIN_JSON_BYTES;
|
|
11975
|
+
exports.ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH = ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH;
|
|
11976
|
+
exports.ATHENA_AUTH_MAX_TEMPLATE_VARIABLES = ATHENA_AUTH_MAX_TEMPLATE_VARIABLES;
|
|
11977
|
+
exports.ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH = ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH;
|
|
11307
11978
|
exports.AthenaClient = AthenaClient;
|
|
11308
11979
|
exports.AthenaError = AthenaError;
|
|
11309
11980
|
exports.AthenaErrorCategory = AthenaErrorCategory;
|
|
@@ -11333,6 +12004,7 @@ exports.defineModel = defineModel;
|
|
|
11333
12004
|
exports.defineRegistry = defineRegistry;
|
|
11334
12005
|
exports.defineSchema = defineSchema;
|
|
11335
12006
|
exports.enumeration = enumeration;
|
|
12007
|
+
exports.filterIntrospectionSnapshot = filterIntrospectionSnapshot;
|
|
11336
12008
|
exports.findGeneratorConfigPath = findGeneratorConfigPath;
|
|
11337
12009
|
exports.generateArtifactsFromSnapshot = generateArtifactsFromSnapshot;
|
|
11338
12010
|
exports.generatorEnv = generatorEnv;
|
|
@@ -11346,6 +12018,7 @@ exports.normalizeAthenaError = normalizeAthenaError;
|
|
|
11346
12018
|
exports.normalizeAthenaGatewayBaseUrl = normalizeAthenaGatewayBaseUrl;
|
|
11347
12019
|
exports.normalizeGeneratorConfig = normalizeGeneratorConfig;
|
|
11348
12020
|
exports.normalizeSchemaSelection = normalizeSchemaSelection;
|
|
12021
|
+
exports.normalizeTableSelection = normalizeTableSelection;
|
|
11349
12022
|
exports.number = number;
|
|
11350
12023
|
exports.parseBooleanFlag = parseBooleanFlag2;
|
|
11351
12024
|
exports.renderAthenaReactEmail = renderAthenaReactEmail;
|