@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.js
CHANGED
|
@@ -804,7 +804,7 @@ var getCookieCache = async (request, config) => {
|
|
|
804
804
|
|
|
805
805
|
// package.json
|
|
806
806
|
var package_default = {
|
|
807
|
-
version: "2.
|
|
807
|
+
version: "2.9.0"
|
|
808
808
|
};
|
|
809
809
|
|
|
810
810
|
// src/sdk-version.ts
|
|
@@ -817,6 +817,7 @@ function buildSdkHeaderValue(sdkName) {
|
|
|
817
817
|
var DEFAULT_CLIENT = "railway_direct";
|
|
818
818
|
var SDK_NAME = "xylex-group/athena";
|
|
819
819
|
var SDK_HEADER_VALUE = buildSdkHeaderValue(SDK_NAME);
|
|
820
|
+
var NO_CACHE_HEADER_VALUE = "no-cache";
|
|
820
821
|
function parseResponseBody(rawText, contentType) {
|
|
821
822
|
if (!rawText) {
|
|
822
823
|
return { parsed: null, parseFailed: false };
|
|
@@ -835,6 +836,9 @@ function parseResponseBody(rawText, contentType) {
|
|
|
835
836
|
function normalizeHeaderValue(value) {
|
|
836
837
|
return value ? value : void 0;
|
|
837
838
|
}
|
|
839
|
+
function isCacheControlHeaderName(name) {
|
|
840
|
+
return name.toLowerCase() === "cache-control";
|
|
841
|
+
}
|
|
838
842
|
function resolveHeaderValue(headers, candidates) {
|
|
839
843
|
for (const candidate of candidates) {
|
|
840
844
|
const direct = normalizeHeaderValue(headers[candidate]);
|
|
@@ -993,6 +997,7 @@ function buildRpcGetEndpoint(payload) {
|
|
|
993
997
|
}
|
|
994
998
|
function buildHeaders(config, options) {
|
|
995
999
|
const mergedStripNulls = options?.stripNulls ?? true;
|
|
1000
|
+
const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
|
|
996
1001
|
const extraHeaders = {
|
|
997
1002
|
...config.headers ?? {},
|
|
998
1003
|
...options?.headers ?? {}
|
|
@@ -1046,11 +1051,15 @@ function buildHeaders(config, options) {
|
|
|
1046
1051
|
const athenaClientKeys = ["x-athena-client", "X-Athena-Client"];
|
|
1047
1052
|
Object.entries(extraHeaders).forEach(([key, value]) => {
|
|
1048
1053
|
if (athenaClientKeys.includes(key)) return;
|
|
1054
|
+
if (forceNoCache && isCacheControlHeaderName(key)) return;
|
|
1049
1055
|
const normalized = normalizeHeaderValue(value);
|
|
1050
1056
|
if (normalized) {
|
|
1051
1057
|
headers[key] = normalized;
|
|
1052
1058
|
}
|
|
1053
1059
|
});
|
|
1060
|
+
if (forceNoCache) {
|
|
1061
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE;
|
|
1062
|
+
}
|
|
1054
1063
|
return headers;
|
|
1055
1064
|
}
|
|
1056
1065
|
function toInvalidUrlResponse(error, endpoint, method) {
|
|
@@ -1511,6 +1520,45 @@ function identifier(...segments) {
|
|
|
1511
1520
|
return new SqlIdentifierPath(expandedSegments);
|
|
1512
1521
|
}
|
|
1513
1522
|
|
|
1523
|
+
// src/auth/limits.ts
|
|
1524
|
+
var ATHENA_AUTH_MAX_ADMIN_JSON_BYTES = 32 * 1024;
|
|
1525
|
+
var ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH = 8;
|
|
1526
|
+
var ATHENA_AUTH_MAX_TEMPLATE_VARIABLES = 64;
|
|
1527
|
+
var ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH = 128;
|
|
1528
|
+
var ATHENA_AUTH_ADMIN_LIMITS = {
|
|
1529
|
+
maxAdminJsonBytes: ATHENA_AUTH_MAX_ADMIN_JSON_BYTES,
|
|
1530
|
+
maxAdminJsonDepth: ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH,
|
|
1531
|
+
maxTemplateVariables: ATHENA_AUTH_MAX_TEMPLATE_VARIABLES,
|
|
1532
|
+
maxTemplateVariableLength: ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH
|
|
1533
|
+
};
|
|
1534
|
+
function describeTemplateVariableTarget(target) {
|
|
1535
|
+
const normalized = target?.trim();
|
|
1536
|
+
return normalized && normalized.length > 0 ? normalized : "Athena auth admin email template variables";
|
|
1537
|
+
}
|
|
1538
|
+
function assertAthenaAuthTemplateVariables(variables, target) {
|
|
1539
|
+
const label = describeTemplateVariableTarget(target);
|
|
1540
|
+
if (!Array.isArray(variables)) {
|
|
1541
|
+
throw new Error(`${label} must be an array of strings.`);
|
|
1542
|
+
}
|
|
1543
|
+
if (variables.length > ATHENA_AUTH_MAX_TEMPLATE_VARIABLES) {
|
|
1544
|
+
throw new Error(
|
|
1545
|
+
`${label} cannot contain more than ${ATHENA_AUTH_MAX_TEMPLATE_VARIABLES} entries.`
|
|
1546
|
+
);
|
|
1547
|
+
}
|
|
1548
|
+
variables.forEach((variable, index) => {
|
|
1549
|
+
if (typeof variable !== "string") {
|
|
1550
|
+
throw new Error(
|
|
1551
|
+
`${label} must contain only strings. Received ${typeof variable} at index ${index}.`
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
if (variable.length > ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH) {
|
|
1555
|
+
throw new Error(
|
|
1556
|
+
`${label} cannot contain entries longer than ${ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH} characters. Received ${variable.length} characters at index ${index}.`
|
|
1557
|
+
);
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1514
1562
|
// src/auth/react-email.ts
|
|
1515
1563
|
var reactEmailRenderModulePromise;
|
|
1516
1564
|
function isRecord2(value) {
|
|
@@ -1740,6 +1788,7 @@ async function resolveReactEmailPayloadFields(input, fields, options) {
|
|
|
1740
1788
|
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
1741
1789
|
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
1742
1790
|
var SDK_HEADER_VALUE2 = buildSdkHeaderValue(SDK_NAME2);
|
|
1791
|
+
var NO_CACHE_HEADER_VALUE2 = "no-cache";
|
|
1743
1792
|
function normalizeBaseUrl(baseUrl) {
|
|
1744
1793
|
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
1745
1794
|
}
|
|
@@ -1749,6 +1798,9 @@ function isRecord3(value) {
|
|
|
1749
1798
|
function normalizeHeaderValue2(value) {
|
|
1750
1799
|
return value ? value : void 0;
|
|
1751
1800
|
}
|
|
1801
|
+
function isCacheControlHeaderName2(name) {
|
|
1802
|
+
return name.toLowerCase() === "cache-control";
|
|
1803
|
+
}
|
|
1752
1804
|
function parseResponseBody2(rawText, contentType) {
|
|
1753
1805
|
if (!rawText) {
|
|
1754
1806
|
return { parsed: null, parseFailed: false };
|
|
@@ -1804,6 +1856,54 @@ function mergeCallOptions(base, override) {
|
|
|
1804
1856
|
}
|
|
1805
1857
|
};
|
|
1806
1858
|
}
|
|
1859
|
+
function toSessionGuardFailure(sessionResult) {
|
|
1860
|
+
if (sessionResult.status === 401 || sessionResult.data == null) {
|
|
1861
|
+
return {
|
|
1862
|
+
ok: false,
|
|
1863
|
+
reason: "unauthorized",
|
|
1864
|
+
status: 401,
|
|
1865
|
+
error: sessionResult.error ?? "Unauthorized",
|
|
1866
|
+
sessionResult
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
return {
|
|
1870
|
+
ok: false,
|
|
1871
|
+
reason: "upstream_error",
|
|
1872
|
+
status: sessionResult.status,
|
|
1873
|
+
error: sessionResult.error ?? "Failed to resolve current session",
|
|
1874
|
+
sessionResult
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
function toPermissionGuardFailure(permissionResult, sessionResult) {
|
|
1878
|
+
if (permissionResult.status === 401) {
|
|
1879
|
+
return {
|
|
1880
|
+
ok: false,
|
|
1881
|
+
reason: "unauthorized",
|
|
1882
|
+
status: 401,
|
|
1883
|
+
error: permissionResult.error ?? "Unauthorized",
|
|
1884
|
+
sessionResult,
|
|
1885
|
+
permissionResult
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
if (permissionResult.status === 403) {
|
|
1889
|
+
return {
|
|
1890
|
+
ok: false,
|
|
1891
|
+
reason: "forbidden",
|
|
1892
|
+
status: 403,
|
|
1893
|
+
error: permissionResult.error ?? "Forbidden",
|
|
1894
|
+
sessionResult,
|
|
1895
|
+
permissionResult
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
return {
|
|
1899
|
+
ok: false,
|
|
1900
|
+
reason: "upstream_error",
|
|
1901
|
+
status: permissionResult.status,
|
|
1902
|
+
error: permissionResult.error ?? "Failed to resolve permission check",
|
|
1903
|
+
sessionResult,
|
|
1904
|
+
permissionResult
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1807
1907
|
function extractFetchOptions(input) {
|
|
1808
1908
|
if (!input) {
|
|
1809
1909
|
return {
|
|
@@ -1819,6 +1919,7 @@ function extractFetchOptions(input) {
|
|
|
1819
1919
|
};
|
|
1820
1920
|
}
|
|
1821
1921
|
function buildHeaders2(config, options) {
|
|
1922
|
+
const forceNoCache = Boolean(config.forceNoCache || options?.forceNoCache);
|
|
1822
1923
|
const headers = {
|
|
1823
1924
|
"Content-Type": "application/json",
|
|
1824
1925
|
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
@@ -1832,16 +1933,30 @@ function buildHeaders2(config, options) {
|
|
|
1832
1933
|
if (bearerToken) {
|
|
1833
1934
|
headers.Authorization = `Bearer ${bearerToken}`;
|
|
1834
1935
|
}
|
|
1936
|
+
const cookie = options?.cookie ?? config.cookie;
|
|
1937
|
+
if (cookie) {
|
|
1938
|
+
headers.Cookie = cookie;
|
|
1939
|
+
}
|
|
1940
|
+
const sessionToken = options?.sessionToken ?? config.sessionToken;
|
|
1941
|
+
if (sessionToken) {
|
|
1942
|
+
headers["X-Athena-Auth-Session-Token"] = sessionToken;
|
|
1943
|
+
}
|
|
1835
1944
|
const mergedExtraHeaders = {
|
|
1836
1945
|
...config.headers ?? {},
|
|
1837
1946
|
...options?.headers ?? {}
|
|
1838
1947
|
};
|
|
1839
1948
|
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
1949
|
+
if (forceNoCache && isCacheControlHeaderName2(key)) {
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1840
1952
|
const normalized = normalizeHeaderValue2(value);
|
|
1841
1953
|
if (normalized) {
|
|
1842
1954
|
headers[key] = normalized;
|
|
1843
1955
|
}
|
|
1844
1956
|
});
|
|
1957
|
+
if (forceNoCache) {
|
|
1958
|
+
headers["Cache-Control"] = NO_CACHE_HEADER_VALUE2;
|
|
1959
|
+
}
|
|
1845
1960
|
return headers;
|
|
1846
1961
|
}
|
|
1847
1962
|
function appendQueryParam(searchParams, key, value) {
|
|
@@ -2106,7 +2221,91 @@ function createAuthClient(config = {}) {
|
|
|
2106
2221
|
htmlField: "htmlTemplate",
|
|
2107
2222
|
textField: "textTemplate",
|
|
2108
2223
|
variablesField: "variables"
|
|
2109
|
-
}, withReactEmailRoute(route))
|
|
2224
|
+
}, withReactEmailRoute(route)).then((payload) => {
|
|
2225
|
+
if ("variables" in payload && payload.variables !== void 0 && payload.variables !== null) {
|
|
2226
|
+
assertAthenaAuthTemplateVariables(
|
|
2227
|
+
payload.variables,
|
|
2228
|
+
`${route} variables`
|
|
2229
|
+
);
|
|
2230
|
+
}
|
|
2231
|
+
return payload;
|
|
2232
|
+
});
|
|
2233
|
+
const requireSession = async (input, options) => {
|
|
2234
|
+
const sessionInput = input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0;
|
|
2235
|
+
const sessionResult = await getGeneric(
|
|
2236
|
+
"/get-session",
|
|
2237
|
+
sessionInput,
|
|
2238
|
+
options
|
|
2239
|
+
);
|
|
2240
|
+
if (!sessionResult.ok || sessionResult.data == null) {
|
|
2241
|
+
return toSessionGuardFailure(sessionResult);
|
|
2242
|
+
}
|
|
2243
|
+
return {
|
|
2244
|
+
ok: true,
|
|
2245
|
+
session: sessionResult.data
|
|
2246
|
+
};
|
|
2247
|
+
};
|
|
2248
|
+
const getUser = async (input, options) => {
|
|
2249
|
+
const sessionResult = await getGeneric(
|
|
2250
|
+
"/get-session",
|
|
2251
|
+
input,
|
|
2252
|
+
options
|
|
2253
|
+
);
|
|
2254
|
+
if (!sessionResult.ok) {
|
|
2255
|
+
return {
|
|
2256
|
+
...sessionResult,
|
|
2257
|
+
data: null
|
|
2258
|
+
};
|
|
2259
|
+
}
|
|
2260
|
+
return {
|
|
2261
|
+
...sessionResult,
|
|
2262
|
+
data: {
|
|
2263
|
+
user: sessionResult.data?.user ?? null
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
};
|
|
2267
|
+
const requirePermission = async (endpoint, input, options) => {
|
|
2268
|
+
const sessionGuard = await requireSession(
|
|
2269
|
+
input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0,
|
|
2270
|
+
options
|
|
2271
|
+
);
|
|
2272
|
+
if (!sessionGuard.ok) {
|
|
2273
|
+
return sessionGuard;
|
|
2274
|
+
}
|
|
2275
|
+
const permissionResult = await postGeneric(
|
|
2276
|
+
endpoint,
|
|
2277
|
+
input,
|
|
2278
|
+
options
|
|
2279
|
+
);
|
|
2280
|
+
if (!permissionResult.ok) {
|
|
2281
|
+
return toPermissionGuardFailure(permissionResult, {
|
|
2282
|
+
ok: true,
|
|
2283
|
+
status: 200,
|
|
2284
|
+
data: sessionGuard.session,
|
|
2285
|
+
error: null,
|
|
2286
|
+
errorDetails: null,
|
|
2287
|
+
raw: sessionGuard.session
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
if (!permissionResult.data?.success) {
|
|
2291
|
+
return {
|
|
2292
|
+
ok: false,
|
|
2293
|
+
reason: "forbidden",
|
|
2294
|
+
status: 403,
|
|
2295
|
+
error: permissionResult.data?.error ?? "Forbidden",
|
|
2296
|
+
sessionResult: {
|
|
2297
|
+
ok: true,
|
|
2298
|
+
status: 200,
|
|
2299
|
+
data: sessionGuard.session,
|
|
2300
|
+
error: null,
|
|
2301
|
+
errorDetails: null,
|
|
2302
|
+
raw: sessionGuard.session
|
|
2303
|
+
},
|
|
2304
|
+
permissionResult
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
return sessionGuard;
|
|
2308
|
+
};
|
|
2110
2309
|
const listUserEmailsWithFallback = async (input, options) => {
|
|
2111
2310
|
const primary = await getWithQuery(
|
|
2112
2311
|
"/email/list",
|
|
@@ -2268,6 +2467,7 @@ function createAuthClient(config = {}) {
|
|
|
2268
2467
|
input,
|
|
2269
2468
|
options
|
|
2270
2469
|
),
|
|
2470
|
+
requirePermission: (input, options) => requirePermission("/organization/has-permission", input, options),
|
|
2271
2471
|
invitation: {
|
|
2272
2472
|
cancel: (input, options) => executePostWithCompatibleInput(
|
|
2273
2473
|
resolvedConfig,
|
|
@@ -2463,6 +2663,8 @@ function createAuthClient(config = {}) {
|
|
|
2463
2663
|
};
|
|
2464
2664
|
const auth = {
|
|
2465
2665
|
getSession: (input, options) => getGeneric("/get-session", input, options),
|
|
2666
|
+
getUser,
|
|
2667
|
+
requireSession,
|
|
2466
2668
|
signOut,
|
|
2467
2669
|
forgetPassword: (input, options) => postGeneric("/forget-password", input, options),
|
|
2468
2670
|
resetPassword: authResetPassword,
|
|
@@ -2557,6 +2759,7 @@ function createAuthClient(config = {}) {
|
|
|
2557
2759
|
}
|
|
2558
2760
|
},
|
|
2559
2761
|
hasPermission: (input, options) => postGeneric("/admin/has-permission", input, options),
|
|
2762
|
+
requirePermission: (input, options) => requirePermission("/admin/has-permission", input, options),
|
|
2560
2763
|
apiKey: {
|
|
2561
2764
|
create: (input, options) => postGeneric("/admin/api-key/create", input, options)
|
|
2562
2765
|
},
|
|
@@ -2708,6 +2911,8 @@ function createAuthClient(config = {}) {
|
|
|
2708
2911
|
input,
|
|
2709
2912
|
options
|
|
2710
2913
|
),
|
|
2914
|
+
getUser,
|
|
2915
|
+
requireSession,
|
|
2711
2916
|
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
2712
2917
|
resolvedConfig,
|
|
2713
2918
|
{ endpoint: "/list-sessions", method: "GET" },
|
|
@@ -5463,6 +5668,9 @@ var AthenaClientBuilderImpl = class {
|
|
|
5463
5668
|
apiKey;
|
|
5464
5669
|
backendConfig = DEFAULT_BACKEND;
|
|
5465
5670
|
clientName;
|
|
5671
|
+
defaultUserId;
|
|
5672
|
+
defaultOrganizationId;
|
|
5673
|
+
forceNoCacheEnabled = false;
|
|
5466
5674
|
defaultHeaders;
|
|
5467
5675
|
authConfig;
|
|
5468
5676
|
dbUrlOverride;
|
|
@@ -5511,6 +5719,15 @@ var AthenaClientBuilderImpl = class {
|
|
|
5511
5719
|
if (options.client !== void 0) {
|
|
5512
5720
|
this.clientName = options.client;
|
|
5513
5721
|
}
|
|
5722
|
+
if (options.userId !== void 0) {
|
|
5723
|
+
this.defaultUserId = options.userId;
|
|
5724
|
+
}
|
|
5725
|
+
if (options.organizationId !== void 0) {
|
|
5726
|
+
this.defaultOrganizationId = options.organizationId;
|
|
5727
|
+
}
|
|
5728
|
+
if (options.forceNoCache !== void 0) {
|
|
5729
|
+
this.forceNoCacheEnabled = options.forceNoCache;
|
|
5730
|
+
}
|
|
5514
5731
|
if (options.backend !== void 0) {
|
|
5515
5732
|
this.backendConfig = toBackendConfig(options.backend);
|
|
5516
5733
|
}
|
|
@@ -5565,6 +5782,9 @@ var AthenaClientBuilderImpl = class {
|
|
|
5565
5782
|
url: this.rootUrl,
|
|
5566
5783
|
key: this.apiKey,
|
|
5567
5784
|
client: this.clientName,
|
|
5785
|
+
userId: this.defaultUserId,
|
|
5786
|
+
organizationId: this.defaultOrganizationId,
|
|
5787
|
+
forceNoCache: this.forceNoCacheEnabled,
|
|
5568
5788
|
backend: this.backendConfig,
|
|
5569
5789
|
headers: this.defaultHeaders,
|
|
5570
5790
|
db: this.dbUrlOverride ? { url: this.dbUrlOverride } : void 0,
|
|
@@ -8107,6 +8327,83 @@ function createQueryBuilder(client, formatGatewayResult, experimental, tracer) {
|
|
|
8107
8327
|
);
|
|
8108
8328
|
};
|
|
8109
8329
|
}
|
|
8330
|
+
var ATHENA_ENV_URL_KEYS = ["ATHENA_URL", "NEXT_PUBLIC_ATHENA_URL"];
|
|
8331
|
+
var ATHENA_ENV_GATEWAY_URL_KEYS = [
|
|
8332
|
+
"ATHENA_DB_URL",
|
|
8333
|
+
"ATHENA_GATEWAY_URL",
|
|
8334
|
+
"NEXT_PUBLIC_ATHENA_DB_API_URL"
|
|
8335
|
+
];
|
|
8336
|
+
var ATHENA_ENV_AUTH_URL_KEYS = ["ATHENA_AUTH_URL", "NEXT_PUBLIC_ATHENA_AUTH_URL"];
|
|
8337
|
+
var ATHENA_ENV_STORAGE_URL_KEYS = ["ATHENA_STORAGE_URL", "NEXT_PUBLIC_ATHENA_STORAGE_URL"];
|
|
8338
|
+
var ATHENA_ENV_KEY_KEYS = [
|
|
8339
|
+
"ATHENA_API_KEY",
|
|
8340
|
+
"NEXT_PUBLIC_ATHENA_API_KEY",
|
|
8341
|
+
"ATHENA_GATEWAY_API_KEY",
|
|
8342
|
+
"X_API_KEY"
|
|
8343
|
+
];
|
|
8344
|
+
var ATHENA_ENV_CLIENT_KEYS = ["ATHENA_CLIENT", "NEXT_PUBLIC_ATHENA_CLIENT"];
|
|
8345
|
+
function normalizeOptionalString(value) {
|
|
8346
|
+
if (typeof value !== "string") {
|
|
8347
|
+
return void 0;
|
|
8348
|
+
}
|
|
8349
|
+
const normalizedValue = value.trim();
|
|
8350
|
+
return normalizedValue ? normalizedValue : void 0;
|
|
8351
|
+
}
|
|
8352
|
+
function readFirstEnvValue(env, keys) {
|
|
8353
|
+
for (const key of keys) {
|
|
8354
|
+
const value = normalizeOptionalString(env[key]);
|
|
8355
|
+
if (value) {
|
|
8356
|
+
return value;
|
|
8357
|
+
}
|
|
8358
|
+
}
|
|
8359
|
+
return void 0;
|
|
8360
|
+
}
|
|
8361
|
+
function readHeaderBagValue(headers, targetKey) {
|
|
8362
|
+
if (!headers) {
|
|
8363
|
+
return void 0;
|
|
8364
|
+
}
|
|
8365
|
+
if (typeof headers.get === "function") {
|
|
8366
|
+
return normalizeOptionalString(headers.get(targetKey));
|
|
8367
|
+
}
|
|
8368
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
8369
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
8370
|
+
if (key.toLowerCase() !== normalizedTargetKey) {
|
|
8371
|
+
continue;
|
|
8372
|
+
}
|
|
8373
|
+
if (typeof value === "string") {
|
|
8374
|
+
return normalizeOptionalString(value);
|
|
8375
|
+
}
|
|
8376
|
+
return void 0;
|
|
8377
|
+
}
|
|
8378
|
+
return void 0;
|
|
8379
|
+
}
|
|
8380
|
+
function resolveSessionContextOptions(session, options) {
|
|
8381
|
+
const sessionToken = normalizeOptionalString(session?.session?.token);
|
|
8382
|
+
const requestCookie = readHeaderBagValue(options?.requestHeaders, "cookie") ?? readHeaderBagValue(options?.headers, "cookie");
|
|
8383
|
+
const authInput = options?.auth;
|
|
8384
|
+
const resolvedUserId = options?.userId !== void 0 ? options.userId : session?.user?.id;
|
|
8385
|
+
const resolvedOrganizationId = options?.organizationId !== void 0 ? options.organizationId : session?.session?.activeOrganizationId;
|
|
8386
|
+
const resolvedBearerToken = authInput?.bearerToken !== void 0 ? authInput.bearerToken : sessionToken;
|
|
8387
|
+
const resolvedSessionToken = authInput?.sessionToken !== void 0 ? authInput.sessionToken : sessionToken;
|
|
8388
|
+
const resolvedCookie = authInput?.cookie !== void 0 ? authInput.cookie : requestCookie;
|
|
8389
|
+
const auth = authInput !== void 0 || resolvedBearerToken !== void 0 || resolvedSessionToken !== void 0 || resolvedCookie !== void 0 ? {
|
|
8390
|
+
...authInput ?? {},
|
|
8391
|
+
...resolvedBearerToken !== void 0 ? { bearerToken: resolvedBearerToken } : {},
|
|
8392
|
+
...resolvedSessionToken !== void 0 ? { sessionToken: resolvedSessionToken } : {},
|
|
8393
|
+
...resolvedCookie !== void 0 ? { cookie: resolvedCookie } : {},
|
|
8394
|
+
headers: authInput?.headers ? { ...authInput.headers } : void 0
|
|
8395
|
+
} : void 0;
|
|
8396
|
+
if (resolvedUserId === void 0 && resolvedOrganizationId === void 0 && options?.forceNoCache === void 0 && !options?.headers && !auth) {
|
|
8397
|
+
return void 0;
|
|
8398
|
+
}
|
|
8399
|
+
return {
|
|
8400
|
+
userId: resolvedUserId,
|
|
8401
|
+
organizationId: resolvedOrganizationId,
|
|
8402
|
+
forceNoCache: options?.forceNoCache,
|
|
8403
|
+
headers: options?.headers ? { ...options.headers } : void 0,
|
|
8404
|
+
auth
|
|
8405
|
+
};
|
|
8406
|
+
}
|
|
8110
8407
|
function resolveClientServiceBaseUrl(value, label) {
|
|
8111
8408
|
if (value === void 0 || value === null) {
|
|
8112
8409
|
return void 0;
|
|
@@ -8149,6 +8446,87 @@ function resolveRequiredClientApiKey(value) {
|
|
|
8149
8446
|
}
|
|
8150
8447
|
return normalizedValue;
|
|
8151
8448
|
}
|
|
8449
|
+
function hasHeaderIgnoreCase(headers, targetKey) {
|
|
8450
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
8451
|
+
return Object.keys(headers).some((key) => key.toLowerCase() === normalizedTargetKey);
|
|
8452
|
+
}
|
|
8453
|
+
function mergeClientHeaders(current, next) {
|
|
8454
|
+
if (!current && !next) {
|
|
8455
|
+
return void 0;
|
|
8456
|
+
}
|
|
8457
|
+
return {
|
|
8458
|
+
...current ?? {},
|
|
8459
|
+
...next ?? {}
|
|
8460
|
+
};
|
|
8461
|
+
}
|
|
8462
|
+
function mergeDefinedObject(current, next) {
|
|
8463
|
+
if (!current && !next) {
|
|
8464
|
+
return void 0;
|
|
8465
|
+
}
|
|
8466
|
+
const merged = {
|
|
8467
|
+
...current ?? {}
|
|
8468
|
+
};
|
|
8469
|
+
const mutableMerged = merged;
|
|
8470
|
+
for (const [key, value] of Object.entries(next ?? {})) {
|
|
8471
|
+
if (value !== void 0) {
|
|
8472
|
+
mutableMerged[key] = value;
|
|
8473
|
+
}
|
|
8474
|
+
}
|
|
8475
|
+
return merged;
|
|
8476
|
+
}
|
|
8477
|
+
function mergeAuthClientOptions(current, next) {
|
|
8478
|
+
const merged = mergeDefinedObject(current, next);
|
|
8479
|
+
if (!merged) {
|
|
8480
|
+
return void 0;
|
|
8481
|
+
}
|
|
8482
|
+
const mergedHeaders = mergeClientHeaders(current?.headers, next?.headers);
|
|
8483
|
+
if (mergedHeaders) {
|
|
8484
|
+
merged.headers = mergedHeaders;
|
|
8485
|
+
}
|
|
8486
|
+
return merged;
|
|
8487
|
+
}
|
|
8488
|
+
function mergeServiceUrlOverrides(current, next) {
|
|
8489
|
+
return mergeDefinedObject(current, next);
|
|
8490
|
+
}
|
|
8491
|
+
function toClientContextOverrides(context) {
|
|
8492
|
+
if (!context) {
|
|
8493
|
+
return void 0;
|
|
8494
|
+
}
|
|
8495
|
+
return {
|
|
8496
|
+
userId: context.userId,
|
|
8497
|
+
organizationId: context.organizationId,
|
|
8498
|
+
forceNoCache: context.forceNoCache,
|
|
8499
|
+
headers: context.headers,
|
|
8500
|
+
auth: context.auth ? {
|
|
8501
|
+
...context.auth,
|
|
8502
|
+
headers: context.auth.headers ? { ...context.auth.headers } : void 0
|
|
8503
|
+
} : void 0
|
|
8504
|
+
};
|
|
8505
|
+
}
|
|
8506
|
+
function mergeClientOverrideOptions(base, overrides) {
|
|
8507
|
+
if (!overrides) {
|
|
8508
|
+
return {
|
|
8509
|
+
...base,
|
|
8510
|
+
headers: base.headers ? { ...base.headers } : void 0,
|
|
8511
|
+
auth: base.auth ? {
|
|
8512
|
+
...base.auth,
|
|
8513
|
+
headers: base.auth.headers ? { ...base.auth.headers } : void 0
|
|
8514
|
+
} : void 0,
|
|
8515
|
+
db: base.db ? { ...base.db } : void 0,
|
|
8516
|
+
gateway: base.gateway ? { ...base.gateway } : void 0,
|
|
8517
|
+
storage: base.storage ? { ...base.storage } : void 0
|
|
8518
|
+
};
|
|
8519
|
+
}
|
|
8520
|
+
const merged = mergeDefinedObject(base, overrides) ?? { ...base };
|
|
8521
|
+
return {
|
|
8522
|
+
...merged,
|
|
8523
|
+
headers: mergeClientHeaders(base.headers, overrides.headers),
|
|
8524
|
+
auth: mergeAuthClientOptions(base.auth, overrides.auth),
|
|
8525
|
+
db: mergeServiceUrlOverrides(base.db, overrides.db),
|
|
8526
|
+
gateway: mergeServiceUrlOverrides(base.gateway, overrides.gateway),
|
|
8527
|
+
storage: mergeServiceUrlOverrides(base.storage, overrides.storage)
|
|
8528
|
+
};
|
|
8529
|
+
}
|
|
8152
8530
|
function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
8153
8531
|
if (!auth && defaultBaseUrl === void 0) {
|
|
8154
8532
|
return void 0;
|
|
@@ -8158,6 +8536,8 @@ function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
|
8158
8536
|
baseUrl,
|
|
8159
8537
|
apiKey,
|
|
8160
8538
|
bearerToken,
|
|
8539
|
+
cookie,
|
|
8540
|
+
sessionToken,
|
|
8161
8541
|
...rest
|
|
8162
8542
|
} = auth ?? {};
|
|
8163
8543
|
const normalized = {
|
|
@@ -8176,6 +8556,12 @@ function normalizeAuthClientConfig(auth, defaultBaseUrl) {
|
|
|
8176
8556
|
if (typeof bearerToken === "string") {
|
|
8177
8557
|
normalized.bearerToken = bearerToken;
|
|
8178
8558
|
}
|
|
8559
|
+
if (typeof cookie === "string") {
|
|
8560
|
+
normalized.cookie = cookie;
|
|
8561
|
+
}
|
|
8562
|
+
if (typeof sessionToken === "string") {
|
|
8563
|
+
normalized.sessionToken = sessionToken;
|
|
8564
|
+
}
|
|
8179
8565
|
return normalized;
|
|
8180
8566
|
}
|
|
8181
8567
|
function resolveCreateClientConfig(config) {
|
|
@@ -8189,6 +8575,9 @@ function resolveCreateClientConfig(config) {
|
|
|
8189
8575
|
baseUrl: resolvedUrls.dbUrl,
|
|
8190
8576
|
apiKey: resolveRequiredClientApiKey(config.key),
|
|
8191
8577
|
client: resolveOptionalClientName(config.client),
|
|
8578
|
+
userId: config.userId,
|
|
8579
|
+
organizationId: config.organizationId,
|
|
8580
|
+
forceNoCache: config.forceNoCache,
|
|
8192
8581
|
backend: toBackendConfig(config.backend),
|
|
8193
8582
|
headers: config.headers,
|
|
8194
8583
|
auth: config.auth,
|
|
@@ -8197,23 +8586,39 @@ function resolveCreateClientConfig(config) {
|
|
|
8197
8586
|
experimental: config.experimental
|
|
8198
8587
|
};
|
|
8199
8588
|
}
|
|
8200
|
-
function
|
|
8589
|
+
function createClientFromInput(sourceConfig) {
|
|
8590
|
+
return createClientFromConfig(resolveCreateClientConfig(sourceConfig), sourceConfig);
|
|
8591
|
+
}
|
|
8592
|
+
function createClientFromConfig(config, sourceConfig) {
|
|
8593
|
+
const normalizedAuthConfig = normalizeAuthClientConfig(config.auth, config.authUrl);
|
|
8201
8594
|
const gatewayHeaders = {
|
|
8202
8595
|
...config.headers ?? {}
|
|
8203
8596
|
};
|
|
8204
|
-
if (
|
|
8205
|
-
gatewayHeaders["X-Athena-Auth-Bearer-Token"] =
|
|
8597
|
+
if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Bearer-Token")) {
|
|
8598
|
+
gatewayHeaders["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
|
|
8599
|
+
}
|
|
8600
|
+
if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(gatewayHeaders, "Cookie")) {
|
|
8601
|
+
gatewayHeaders.Cookie = normalizedAuthConfig.cookie;
|
|
8602
|
+
}
|
|
8603
|
+
if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(gatewayHeaders, "X-Athena-Auth-Session-Token")) {
|
|
8604
|
+
gatewayHeaders["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
|
|
8206
8605
|
}
|
|
8207
8606
|
const gateway = createAthenaGatewayClient({
|
|
8208
8607
|
baseUrl: config.baseUrl,
|
|
8209
8608
|
apiKey: config.apiKey,
|
|
8210
8609
|
client: config.client,
|
|
8610
|
+
userId: config.userId,
|
|
8611
|
+
organizationId: config.organizationId,
|
|
8612
|
+
forceNoCache: config.forceNoCache,
|
|
8211
8613
|
backend: config.backend,
|
|
8212
8614
|
headers: gatewayHeaders
|
|
8213
8615
|
});
|
|
8214
8616
|
const formatGatewayResult = createResultFormatter(config.experimental);
|
|
8215
8617
|
const queryTracer = createQueryTracer(config.experimental);
|
|
8216
|
-
const auth = createAuthClient(
|
|
8618
|
+
const auth = createAuthClient({
|
|
8619
|
+
...normalizedAuthConfig ?? {},
|
|
8620
|
+
...config.forceNoCache ? { forceNoCache: true } : {}
|
|
8621
|
+
});
|
|
8217
8622
|
function from(tableOrModel, options) {
|
|
8218
8623
|
if (isAthenaModelTarget(tableOrModel)) {
|
|
8219
8624
|
if (options?.schema !== void 0) {
|
|
@@ -8261,17 +8666,45 @@ function createClientFromConfig(config) {
|
|
|
8261
8666
|
queryTracer
|
|
8262
8667
|
);
|
|
8263
8668
|
const db = createDbModule({ from, rpc, query });
|
|
8669
|
+
const withContext = (context) => createClientFromInput(
|
|
8670
|
+
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
8671
|
+
);
|
|
8672
|
+
const withSession = (session, options) => createClientFromInput(
|
|
8673
|
+
mergeClientOverrideOptions(
|
|
8674
|
+
sourceConfig,
|
|
8675
|
+
toClientContextOverrides(resolveSessionContextOptions(session, options))
|
|
8676
|
+
)
|
|
8677
|
+
);
|
|
8678
|
+
const authWithOptions = (options) => createClientFromInput(mergeClientOverrideOptions(sourceConfig, options));
|
|
8264
8679
|
const sdkClient = {
|
|
8265
8680
|
from,
|
|
8266
8681
|
db,
|
|
8267
8682
|
rpc,
|
|
8268
8683
|
query,
|
|
8269
8684
|
verifyConnection: gateway.verifyConnection,
|
|
8270
|
-
auth: auth.auth
|
|
8685
|
+
auth: auth.auth,
|
|
8686
|
+
withContext,
|
|
8687
|
+
withSession,
|
|
8688
|
+
withOptions: authWithOptions
|
|
8271
8689
|
};
|
|
8272
8690
|
if (config.experimental?.athenaStorageBackend) {
|
|
8691
|
+
const storageWithContext = (context) => createClientFromInput(
|
|
8692
|
+
mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
|
|
8693
|
+
);
|
|
8694
|
+
const storageWithSession = (session, options) => createClientFromInput(
|
|
8695
|
+
mergeClientOverrideOptions(
|
|
8696
|
+
sourceConfig,
|
|
8697
|
+
toClientContextOverrides(resolveSessionContextOptions(session, options))
|
|
8698
|
+
)
|
|
8699
|
+
);
|
|
8700
|
+
const storageWithOptions = (options) => createClientFromInput(
|
|
8701
|
+
mergeClientOverrideOptions(sourceConfig, options)
|
|
8702
|
+
);
|
|
8273
8703
|
const storageClient = {
|
|
8274
8704
|
...sdkClient,
|
|
8705
|
+
withContext: storageWithContext,
|
|
8706
|
+
withSession: storageWithSession,
|
|
8707
|
+
withOptions: storageWithOptions,
|
|
8275
8708
|
storage: createStorageModule(gateway, {
|
|
8276
8709
|
...config.experimental.storage,
|
|
8277
8710
|
...config.storageUrl ? {
|
|
@@ -8287,38 +8720,42 @@ function createClientFromConfig(config) {
|
|
|
8287
8720
|
var AthenaClient = class {
|
|
8288
8721
|
/** Create a fluent builder for a strongly-typed Athena SDK client. */
|
|
8289
8722
|
static builder() {
|
|
8290
|
-
return createAthenaClientBuilder((config) =>
|
|
8291
|
-
}
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
const url =
|
|
8295
|
-
const gatewayUrl =
|
|
8296
|
-
const authUrl =
|
|
8297
|
-
const storageUrl =
|
|
8298
|
-
const key =
|
|
8723
|
+
return createAthenaClientBuilder((config) => createClientFromInput(config));
|
|
8724
|
+
}
|
|
8725
|
+
static fromEnvironment(options = {}) {
|
|
8726
|
+
const env = options.env ?? process.env;
|
|
8727
|
+
const url = options.url ?? readFirstEnvValue(env, ATHENA_ENV_URL_KEYS);
|
|
8728
|
+
const gatewayUrl = options.gatewayUrl ?? readFirstEnvValue(env, ATHENA_ENV_GATEWAY_URL_KEYS);
|
|
8729
|
+
const authUrl = options.authUrl ?? readFirstEnvValue(env, ATHENA_ENV_AUTH_URL_KEYS);
|
|
8730
|
+
const storageUrl = options.storageUrl ?? readFirstEnvValue(env, ATHENA_ENV_STORAGE_URL_KEYS);
|
|
8731
|
+
const key = options.key ?? readFirstEnvValue(env, ATHENA_ENV_KEY_KEYS);
|
|
8732
|
+
const client = options.client ?? readFirstEnvValue(env, ATHENA_ENV_CLIENT_KEYS);
|
|
8299
8733
|
if (!url && !gatewayUrl || !key) {
|
|
8300
8734
|
throw new Error(
|
|
8301
|
-
"
|
|
8735
|
+
"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."
|
|
8302
8736
|
);
|
|
8303
8737
|
}
|
|
8738
|
+
const { env: _env, ...clientOptions } = options;
|
|
8304
8739
|
return createClient({
|
|
8740
|
+
...clientOptions,
|
|
8305
8741
|
url,
|
|
8306
8742
|
gatewayUrl,
|
|
8307
8743
|
authUrl,
|
|
8308
8744
|
storageUrl,
|
|
8309
|
-
key
|
|
8745
|
+
key,
|
|
8746
|
+
client
|
|
8310
8747
|
});
|
|
8311
8748
|
}
|
|
8312
8749
|
};
|
|
8313
8750
|
function createClient(configOrUrl, apiKey, options) {
|
|
8314
8751
|
if (typeof configOrUrl === "string" || configOrUrl === null || configOrUrl === void 0) {
|
|
8315
|
-
return
|
|
8752
|
+
return createClientFromInput({
|
|
8316
8753
|
url: configOrUrl,
|
|
8317
8754
|
key: apiKey ?? "",
|
|
8318
8755
|
...options
|
|
8319
|
-
})
|
|
8756
|
+
});
|
|
8320
8757
|
}
|
|
8321
|
-
return
|
|
8758
|
+
return createClientFromInput(configOrUrl);
|
|
8322
8759
|
}
|
|
8323
8760
|
|
|
8324
8761
|
// src/gateway/types.ts
|
|
@@ -8684,6 +9121,9 @@ function createColumnsBuilder(name, mappedName, schemaName, columns) {
|
|
|
8684
9121
|
resolveTableTarget(name, mappedName, normalizedSchemaName);
|
|
8685
9122
|
return createColumnsBuilder(name, mappedName, normalizedSchemaName, columns);
|
|
8686
9123
|
},
|
|
9124
|
+
withoutPrimaryKey() {
|
|
9125
|
+
return finalizeTable(name, mappedName, schemaName, columns, []);
|
|
9126
|
+
},
|
|
8687
9127
|
primaryKey(...keys) {
|
|
8688
9128
|
return finalizeTable(name, mappedName, schemaName, columns, keys);
|
|
8689
9129
|
}
|
|
@@ -8735,6 +9175,59 @@ var TenantHeaderMapper = class {
|
|
|
8735
9175
|
return Object.keys(headers).length > 0 ? headers : void 0;
|
|
8736
9176
|
}
|
|
8737
9177
|
};
|
|
9178
|
+
function normalizeOptionalString2(value) {
|
|
9179
|
+
if (typeof value !== "string") {
|
|
9180
|
+
return void 0;
|
|
9181
|
+
}
|
|
9182
|
+
const normalizedValue = value.trim();
|
|
9183
|
+
return normalizedValue ? normalizedValue : void 0;
|
|
9184
|
+
}
|
|
9185
|
+
function readHeaderBagValue2(headers, targetKey) {
|
|
9186
|
+
if (!headers) {
|
|
9187
|
+
return void 0;
|
|
9188
|
+
}
|
|
9189
|
+
if (typeof headers.get === "function") {
|
|
9190
|
+
return normalizeOptionalString2(headers.get(targetKey));
|
|
9191
|
+
}
|
|
9192
|
+
const normalizedTargetKey = targetKey.toLowerCase();
|
|
9193
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
9194
|
+
if (key.toLowerCase() !== normalizedTargetKey) {
|
|
9195
|
+
continue;
|
|
9196
|
+
}
|
|
9197
|
+
if (typeof value === "string") {
|
|
9198
|
+
return normalizeOptionalString2(value);
|
|
9199
|
+
}
|
|
9200
|
+
return void 0;
|
|
9201
|
+
}
|
|
9202
|
+
return void 0;
|
|
9203
|
+
}
|
|
9204
|
+
function resolveSessionContextOptions2(session, options) {
|
|
9205
|
+
const sessionToken = normalizeOptionalString2(session?.session?.token);
|
|
9206
|
+
const requestCookie = readHeaderBagValue2(options?.requestHeaders, "cookie") ?? readHeaderBagValue2(options?.headers, "cookie");
|
|
9207
|
+
const authInput = options?.auth;
|
|
9208
|
+
const resolvedUserId = options?.userId !== void 0 ? options.userId : session?.user?.id;
|
|
9209
|
+
const resolvedOrganizationId = options?.organizationId !== void 0 ? options.organizationId : session?.session?.activeOrganizationId;
|
|
9210
|
+
const resolvedBearerToken = authInput?.bearerToken !== void 0 ? authInput.bearerToken : sessionToken;
|
|
9211
|
+
const resolvedSessionToken = authInput?.sessionToken !== void 0 ? authInput.sessionToken : sessionToken;
|
|
9212
|
+
const resolvedCookie = authInput?.cookie !== void 0 ? authInput.cookie : requestCookie;
|
|
9213
|
+
const auth = authInput !== void 0 || resolvedBearerToken !== void 0 || resolvedSessionToken !== void 0 || resolvedCookie !== void 0 ? {
|
|
9214
|
+
...authInput ?? {},
|
|
9215
|
+
...resolvedBearerToken !== void 0 ? { bearerToken: resolvedBearerToken } : {},
|
|
9216
|
+
...resolvedSessionToken !== void 0 ? { sessionToken: resolvedSessionToken } : {},
|
|
9217
|
+
...resolvedCookie !== void 0 ? { cookie: resolvedCookie } : {},
|
|
9218
|
+
headers: authInput?.headers ? { ...authInput.headers } : void 0
|
|
9219
|
+
} : void 0;
|
|
9220
|
+
if (resolvedUserId === void 0 && resolvedOrganizationId === void 0 && options?.forceNoCache === void 0 && !options?.headers && !auth) {
|
|
9221
|
+
return void 0;
|
|
9222
|
+
}
|
|
9223
|
+
return {
|
|
9224
|
+
userId: resolvedUserId,
|
|
9225
|
+
organizationId: resolvedOrganizationId,
|
|
9226
|
+
forceNoCache: options?.forceNoCache,
|
|
9227
|
+
headers: options?.headers ? { ...options.headers } : void 0,
|
|
9228
|
+
auth
|
|
9229
|
+
};
|
|
9230
|
+
}
|
|
8738
9231
|
var RegistryNavigator = class {
|
|
8739
9232
|
constructor(registry) {
|
|
8740
9233
|
this.registry = registry;
|
|
@@ -8786,12 +9279,22 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
8786
9279
|
backend: input.options?.backend,
|
|
8787
9280
|
client: input.options?.client,
|
|
8788
9281
|
headers: input.options?.headers,
|
|
9282
|
+
forceNoCache: input.options?.forceNoCache,
|
|
9283
|
+
userId: input.options?.userId,
|
|
9284
|
+
organizationId: input.options?.organizationId,
|
|
9285
|
+
auth: input.options?.auth,
|
|
9286
|
+
tenantKeyMap,
|
|
9287
|
+
tenantContext,
|
|
8789
9288
|
experimental: input.options?.experimental
|
|
8790
9289
|
};
|
|
8791
9290
|
this.baseClient = createClient(this.url, this.apiKey, {
|
|
8792
9291
|
backend: this.clientOptions.backend,
|
|
8793
9292
|
client: this.clientOptions.client,
|
|
8794
9293
|
headers: this.tenantHeaderMapper.apply(this.clientOptions.headers, tenantContext),
|
|
9294
|
+
forceNoCache: this.clientOptions.forceNoCache,
|
|
9295
|
+
userId: this.clientOptions.userId,
|
|
9296
|
+
organizationId: this.clientOptions.organizationId,
|
|
9297
|
+
auth: this.clientOptions.auth,
|
|
8795
9298
|
experimental: this.clientOptions.experimental
|
|
8796
9299
|
});
|
|
8797
9300
|
this.db = this.baseClient.db;
|
|
@@ -8809,6 +9312,40 @@ var TypedAthenaClientImpl = class _TypedAthenaClientImpl {
|
|
|
8809
9312
|
verifyConnection(options) {
|
|
8810
9313
|
return this.baseClient.verifyConnection(options);
|
|
8811
9314
|
}
|
|
9315
|
+
withContext(context) {
|
|
9316
|
+
const headers = {
|
|
9317
|
+
...this.clientOptions.headers ?? {},
|
|
9318
|
+
...context?.headers ?? {}
|
|
9319
|
+
};
|
|
9320
|
+
const auth = this.clientOptions.auth || context?.auth ? {
|
|
9321
|
+
...this.clientOptions.auth ?? {},
|
|
9322
|
+
...context?.auth ?? {},
|
|
9323
|
+
headers: this.clientOptions.auth?.headers || context?.auth?.headers ? {
|
|
9324
|
+
...this.clientOptions.auth?.headers ?? {},
|
|
9325
|
+
...context?.auth?.headers ?? {}
|
|
9326
|
+
} : void 0
|
|
9327
|
+
} : void 0;
|
|
9328
|
+
return new _TypedAthenaClientImpl({
|
|
9329
|
+
registry: this.registry,
|
|
9330
|
+
url: this.url,
|
|
9331
|
+
apiKey: this.apiKey,
|
|
9332
|
+
options: {
|
|
9333
|
+
...this.clientOptions,
|
|
9334
|
+
headers: Object.keys(headers).length > 0 ? headers : void 0,
|
|
9335
|
+
auth,
|
|
9336
|
+
tenantKeyMap: this.tenantKeyMap,
|
|
9337
|
+
tenantContext: {
|
|
9338
|
+
...this.tenantContext
|
|
9339
|
+
},
|
|
9340
|
+
...context?.userId !== void 0 ? { userId: context.userId } : {},
|
|
9341
|
+
...context?.organizationId !== void 0 ? { organizationId: context.organizationId } : {},
|
|
9342
|
+
...context?.forceNoCache !== void 0 ? { forceNoCache: context.forceNoCache } : {}
|
|
9343
|
+
}
|
|
9344
|
+
});
|
|
9345
|
+
}
|
|
9346
|
+
withSession(session, options) {
|
|
9347
|
+
return this.withContext(resolveSessionContextOptions2(session, options));
|
|
9348
|
+
}
|
|
8812
9349
|
withTenantContext(context) {
|
|
8813
9350
|
return new _TypedAthenaClientImpl({
|
|
8814
9351
|
registry: this.registry,
|
|
@@ -9304,6 +9841,77 @@ function resolveProviderSchemas(providerConfig) {
|
|
|
9304
9841
|
return [...DEFAULT_POSTGRES_SCHEMAS];
|
|
9305
9842
|
}
|
|
9306
9843
|
|
|
9844
|
+
// src/generator/table-selection.ts
|
|
9845
|
+
function normalizeTableSelector(value) {
|
|
9846
|
+
const trimmed = value.trim();
|
|
9847
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
9848
|
+
}
|
|
9849
|
+
function normalizeTableSelection(value) {
|
|
9850
|
+
if (typeof value === "string") {
|
|
9851
|
+
return Array.from(
|
|
9852
|
+
new Set(
|
|
9853
|
+
value.split(",").map(normalizeTableSelector).filter((entry) => Boolean(entry))
|
|
9854
|
+
)
|
|
9855
|
+
);
|
|
9856
|
+
}
|
|
9857
|
+
if (Array.isArray(value)) {
|
|
9858
|
+
return Array.from(
|
|
9859
|
+
new Set(
|
|
9860
|
+
value.map((entry) => typeof entry === "string" ? normalizeTableSelector(entry) : void 0).filter((entry) => Boolean(entry))
|
|
9861
|
+
)
|
|
9862
|
+
);
|
|
9863
|
+
}
|
|
9864
|
+
return [];
|
|
9865
|
+
}
|
|
9866
|
+
function matchesTableSelector(schemaName, tableName, selector) {
|
|
9867
|
+
const separatorIndex = selector.indexOf(".");
|
|
9868
|
+
if (separatorIndex < 0) {
|
|
9869
|
+
return tableName === selector;
|
|
9870
|
+
}
|
|
9871
|
+
const selectorSchema = selector.slice(0, separatorIndex).trim();
|
|
9872
|
+
const selectorTable = selector.slice(separatorIndex + 1).trim();
|
|
9873
|
+
return selectorSchema === schemaName && selectorTable === tableName;
|
|
9874
|
+
}
|
|
9875
|
+
function shouldKeepTable(schemaName, tableName, filter) {
|
|
9876
|
+
const included = filter.includeTables.length === 0 || filter.includeTables.some((selector) => matchesTableSelector(schemaName, tableName, selector));
|
|
9877
|
+
if (!included) {
|
|
9878
|
+
return false;
|
|
9879
|
+
}
|
|
9880
|
+
return !filter.excludeTables.some((selector) => matchesTableSelector(schemaName, tableName, selector));
|
|
9881
|
+
}
|
|
9882
|
+
function hasTableFilters(filter) {
|
|
9883
|
+
return filter.includeTables.length > 0 || filter.excludeTables.length > 0;
|
|
9884
|
+
}
|
|
9885
|
+
function filterIntrospectionSnapshot(snapshot, filter) {
|
|
9886
|
+
if (!hasTableFilters(filter)) {
|
|
9887
|
+
return snapshot;
|
|
9888
|
+
}
|
|
9889
|
+
const schemas = {};
|
|
9890
|
+
for (const [schemaName, schema] of Object.entries(snapshot.schemas)) {
|
|
9891
|
+
const tables = Object.fromEntries(
|
|
9892
|
+
Object.entries(schema.tables).filter(([tableName]) => shouldKeepTable(schemaName, tableName, filter))
|
|
9893
|
+
);
|
|
9894
|
+
if (Object.keys(tables).length === 0) {
|
|
9895
|
+
continue;
|
|
9896
|
+
}
|
|
9897
|
+
schemas[schemaName] = {
|
|
9898
|
+
...schema,
|
|
9899
|
+
tables
|
|
9900
|
+
};
|
|
9901
|
+
}
|
|
9902
|
+
if (Object.keys(schemas).length === 0) {
|
|
9903
|
+
const includeLabel = filter.includeTables.length > 0 ? ` includeTables=${filter.includeTables.join(", ")}` : "";
|
|
9904
|
+
const excludeLabel = filter.excludeTables.length > 0 ? ` excludeTables=${filter.excludeTables.join(", ")}` : "";
|
|
9905
|
+
throw new Error(
|
|
9906
|
+
`Generator table filters matched no tables after schema selection.${includeLabel}${excludeLabel}`
|
|
9907
|
+
);
|
|
9908
|
+
}
|
|
9909
|
+
return {
|
|
9910
|
+
...snapshot,
|
|
9911
|
+
schemas
|
|
9912
|
+
};
|
|
9913
|
+
}
|
|
9914
|
+
|
|
9307
9915
|
// src/generator/config.ts
|
|
9308
9916
|
var POSTGRES_PROTOCOLS = /* @__PURE__ */ new Set(["postgres:", "postgresql:"]);
|
|
9309
9917
|
var DEFAULT_CONFIG_CANDIDATES = [
|
|
@@ -9314,13 +9922,20 @@ var DEFAULT_CONFIG_CANDIDATES = [
|
|
|
9314
9922
|
".athena.config.ts",
|
|
9315
9923
|
".athena.config.js"
|
|
9316
9924
|
];
|
|
9317
|
-
var
|
|
9925
|
+
var LEGACY_DEFAULT_TARGETS = {
|
|
9318
9926
|
model: "athena/models/{schema_kebab}/{model_kebab}.ts",
|
|
9319
9927
|
schema: "athena/schemas/{schema_kebab}.ts",
|
|
9320
9928
|
database: "athena/relations.ts",
|
|
9321
9929
|
registry: "athena/config.ts"
|
|
9322
9930
|
};
|
|
9323
|
-
var
|
|
9931
|
+
var ATHENA_DIRECT_TARGETS = {
|
|
9932
|
+
model: "athena/models/{schema_kebab}/{model_kebab}.ts",
|
|
9933
|
+
schema: "athena/schemas/{schema_kebab}.ts",
|
|
9934
|
+
database: "athena/relations.ts",
|
|
9935
|
+
registry: "athena/registry.generated.ts"
|
|
9936
|
+
};
|
|
9937
|
+
var DEFAULT_OUTPUT_FORMAT = "table-builder";
|
|
9938
|
+
var DEFAULT_OUTPUT_PRESET = "athena-direct";
|
|
9324
9939
|
var DEFAULT_NAMING = {
|
|
9325
9940
|
modelType: "pascal",
|
|
9326
9941
|
modelConst: "camel",
|
|
@@ -9339,6 +9954,10 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
|
|
|
9339
9954
|
var DEFAULT_INTERNAL_CONFIG = {
|
|
9340
9955
|
schemaVersion: 1
|
|
9341
9956
|
};
|
|
9957
|
+
var DEFAULT_FILTER_CONFIG = {
|
|
9958
|
+
includeTables: [],
|
|
9959
|
+
excludeTables: []
|
|
9960
|
+
};
|
|
9342
9961
|
var PROJECT_ENV_FILENAMES = [".env", ".env.local"];
|
|
9343
9962
|
var DIRECT_CONNECTION_STRING_ENV_KEYS = [
|
|
9344
9963
|
"ATHENA_GENERATOR_PG_URL",
|
|
@@ -9357,10 +9976,13 @@ var GATEWAY_API_KEY_ENV_KEYS = [
|
|
|
9357
9976
|
];
|
|
9358
9977
|
var GENERATOR_SCHEMA_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMAS"];
|
|
9359
9978
|
var OUTPUT_FORMAT_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_FORMAT"];
|
|
9979
|
+
var OUTPUT_PRESET_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_PRESET"];
|
|
9360
9980
|
var MODEL_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_TARGET"];
|
|
9361
9981
|
var SCHEMA_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMA_TARGET"];
|
|
9362
9982
|
var DATABASE_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_DATABASE_TARGET"];
|
|
9363
9983
|
var REGISTRY_TARGET_ENV_KEYS = ["ATHENA_GENERATOR_REGISTRY_TARGET"];
|
|
9984
|
+
var TABLES_ENV_KEYS = ["ATHENA_GENERATOR_TABLES"];
|
|
9985
|
+
var EXCLUDE_TABLES_ENV_KEYS = ["ATHENA_GENERATOR_EXCLUDE_TABLES"];
|
|
9364
9986
|
var PLACEHOLDER_MAP_ENV_KEYS = ["ATHENA_GENERATOR_PLACEHOLDER_MAP"];
|
|
9365
9987
|
var MODEL_TYPE_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_TYPE", "ATHENA_GENERATOR_MODEL_STYLE"];
|
|
9366
9988
|
var MODEL_CONST_ENV_KEYS = ["ATHENA_GENERATOR_MODEL_CONST"];
|
|
@@ -9375,7 +9997,12 @@ var SCYLLA_PROVIDER_CONTRACTS_ENV_KEYS = ["ATHENA_GENERATOR_SCYLLA_PROVIDER_CONT
|
|
|
9375
9997
|
var ENV_ONLY_CONFIG_PATH = "[environment defaults]";
|
|
9376
9998
|
var NAMING_STYLE_VALUES = ["preserve", "camel", "pascal", "snake", "kebab"];
|
|
9377
9999
|
var OUTPUT_FORMAT_VALUES = ["define-model", "table-builder"];
|
|
10000
|
+
var OUTPUT_PRESET_VALUES = ["legacy", "athena-direct"];
|
|
9378
10001
|
var BACKEND_TYPE_VALUES = ["athena", "postgrest", "postgresql", "scylladb"];
|
|
10002
|
+
var OUTPUT_PRESET_TARGETS = {
|
|
10003
|
+
legacy: LEGACY_DEFAULT_TARGETS,
|
|
10004
|
+
"athena-direct": ATHENA_DIRECT_TARGETS
|
|
10005
|
+
};
|
|
9379
10006
|
function normalizeRawEnvValue(rawValue) {
|
|
9380
10007
|
if (rawValue.startsWith('"') && rawValue.endsWith('"') && rawValue.length >= 2) {
|
|
9381
10008
|
const inner = rawValue.slice(1, -1);
|
|
@@ -9511,7 +10138,7 @@ function deriveDatabaseNameFromConnectionString(connectionString) {
|
|
|
9511
10138
|
return void 0;
|
|
9512
10139
|
}
|
|
9513
10140
|
}
|
|
9514
|
-
function
|
|
10141
|
+
function normalizeOptionalString3(value, fallbackKeys) {
|
|
9515
10142
|
if (typeof value === "string") {
|
|
9516
10143
|
const trimmed = value.trim();
|
|
9517
10144
|
if (trimmed.length > 0) {
|
|
@@ -9521,7 +10148,7 @@ function normalizeOptionalString(value, fallbackKeys) {
|
|
|
9521
10148
|
return resolveFallbackValue(fallbackKeys);
|
|
9522
10149
|
}
|
|
9523
10150
|
function normalizeRequiredString(value, fieldLabel, fallbackKeys) {
|
|
9524
|
-
const resolved =
|
|
10151
|
+
const resolved = normalizeOptionalString3(value, fallbackKeys);
|
|
9525
10152
|
if (resolved) {
|
|
9526
10153
|
return resolved;
|
|
9527
10154
|
}
|
|
@@ -9582,11 +10209,19 @@ function normalizeExperimentalFlags(input) {
|
|
|
9582
10209
|
)
|
|
9583
10210
|
};
|
|
9584
10211
|
}
|
|
10212
|
+
function normalizeFilterConfig(input) {
|
|
10213
|
+
return {
|
|
10214
|
+
includeTables: normalizeTableSelection(input?.includeTables),
|
|
10215
|
+
excludeTables: normalizeTableSelection(input?.excludeTables)
|
|
10216
|
+
};
|
|
10217
|
+
}
|
|
9585
10218
|
function normalizeOutputConfig(output) {
|
|
10219
|
+
const preset = output?.preset ?? DEFAULT_OUTPUT_PRESET;
|
|
9586
10220
|
return {
|
|
9587
10221
|
format: output?.format ?? DEFAULT_OUTPUT_FORMAT,
|
|
10222
|
+
preset,
|
|
9588
10223
|
targets: {
|
|
9589
|
-
...
|
|
10224
|
+
...OUTPUT_PRESET_TARGETS[preset],
|
|
9590
10225
|
...output?.targets ?? {}
|
|
9591
10226
|
},
|
|
9592
10227
|
placeholderMap: {
|
|
@@ -9601,7 +10236,7 @@ function normalizeProviderConfig(provider) {
|
|
|
9601
10236
|
"provider.connectionString",
|
|
9602
10237
|
DIRECT_CONNECTION_STRING_ENV_KEYS
|
|
9603
10238
|
);
|
|
9604
|
-
const database =
|
|
10239
|
+
const database = normalizeOptionalString3(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? deriveDatabaseNameFromConnectionString(connectionString);
|
|
9605
10240
|
return {
|
|
9606
10241
|
...provider,
|
|
9607
10242
|
connectionString: applyPostgresPasswordFallback(connectionString),
|
|
@@ -9620,7 +10255,7 @@ function normalizeProviderConfig(provider) {
|
|
|
9620
10255
|
"provider.apiKey",
|
|
9621
10256
|
GATEWAY_API_KEY_ENV_KEYS
|
|
9622
10257
|
);
|
|
9623
|
-
const database =
|
|
10258
|
+
const database = normalizeOptionalString3(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? "postgres";
|
|
9624
10259
|
return {
|
|
9625
10260
|
...provider,
|
|
9626
10261
|
gatewayUrl,
|
|
@@ -9635,7 +10270,7 @@ function normalizeProviderConfig(provider) {
|
|
|
9635
10270
|
"Generator config is missing provider.contactPoints for scylla direct mode."
|
|
9636
10271
|
);
|
|
9637
10272
|
}
|
|
9638
|
-
const keyspace =
|
|
10273
|
+
const keyspace = normalizeOptionalString3(provider.keyspace, []);
|
|
9639
10274
|
if (!keyspace) {
|
|
9640
10275
|
throw new Error(
|
|
9641
10276
|
"Generator config is missing provider.keyspace for scylla direct mode."
|
|
@@ -9646,7 +10281,7 @@ function normalizeProviderConfig(provider) {
|
|
|
9646
10281
|
mode: "direct",
|
|
9647
10282
|
contactPoints: provider.contactPoints.slice(),
|
|
9648
10283
|
keyspace,
|
|
9649
|
-
datacenter:
|
|
10284
|
+
datacenter: normalizeOptionalString3(provider.datacenter, [])
|
|
9650
10285
|
};
|
|
9651
10286
|
}
|
|
9652
10287
|
return provider;
|
|
@@ -9666,6 +10301,10 @@ function normalizeGeneratorConfig(input) {
|
|
|
9666
10301
|
...DEFAULT_NAMING,
|
|
9667
10302
|
...input.naming ?? {}
|
|
9668
10303
|
},
|
|
10304
|
+
filter: {
|
|
10305
|
+
...DEFAULT_FILTER_CONFIG,
|
|
10306
|
+
...normalizeFilterConfig(input.filter)
|
|
10307
|
+
},
|
|
9669
10308
|
features: normalizeFeatureFlags(input.features),
|
|
9670
10309
|
experimental: normalizeExperimentalFlags(input.experimental),
|
|
9671
10310
|
internal: {
|
|
@@ -9729,16 +10368,18 @@ function importConfigModule(moduleSpecifier) {
|
|
|
9729
10368
|
}
|
|
9730
10369
|
function buildEnvironmentOutputConfig() {
|
|
9731
10370
|
const format = resolveOptionalOneOf(OUTPUT_FORMAT_ENV_KEYS, OUTPUT_FORMAT_VALUES);
|
|
10371
|
+
const preset = resolveOptionalOneOf(OUTPUT_PRESET_ENV_KEYS, OUTPUT_PRESET_VALUES);
|
|
9732
10372
|
const modelTarget = resolveFallbackValue(MODEL_TARGET_ENV_KEYS);
|
|
9733
10373
|
const schemaTarget = resolveFallbackValue(SCHEMA_TARGET_ENV_KEYS);
|
|
9734
10374
|
const databaseTarget = resolveFallbackValue(DATABASE_TARGET_ENV_KEYS);
|
|
9735
10375
|
const registryTarget = resolveFallbackValue(REGISTRY_TARGET_ENV_KEYS);
|
|
9736
10376
|
const placeholderMap = resolveOptionalJson(PLACEHOLDER_MAP_ENV_KEYS);
|
|
9737
|
-
if (format === void 0 && modelTarget === void 0 && schemaTarget === void 0 && databaseTarget === void 0 && registryTarget === void 0 && placeholderMap === void 0) {
|
|
10377
|
+
if (format === void 0 && preset === void 0 && modelTarget === void 0 && schemaTarget === void 0 && databaseTarget === void 0 && registryTarget === void 0 && placeholderMap === void 0) {
|
|
9738
10378
|
return void 0;
|
|
9739
10379
|
}
|
|
9740
10380
|
return {
|
|
9741
10381
|
format,
|
|
10382
|
+
preset,
|
|
9742
10383
|
targets: {
|
|
9743
10384
|
...modelTarget ? { model: modelTarget } : {},
|
|
9744
10385
|
...schemaTarget ? { schema: schemaTarget } : {},
|
|
@@ -9748,6 +10389,17 @@ function buildEnvironmentOutputConfig() {
|
|
|
9748
10389
|
placeholderMap
|
|
9749
10390
|
};
|
|
9750
10391
|
}
|
|
10392
|
+
function buildEnvironmentFilterConfig() {
|
|
10393
|
+
const includeTables = resolveFallbackValue(TABLES_ENV_KEYS);
|
|
10394
|
+
const excludeTables = resolveFallbackValue(EXCLUDE_TABLES_ENV_KEYS);
|
|
10395
|
+
if (includeTables === void 0 && excludeTables === void 0) {
|
|
10396
|
+
return void 0;
|
|
10397
|
+
}
|
|
10398
|
+
return {
|
|
10399
|
+
...includeTables !== void 0 ? { includeTables } : {},
|
|
10400
|
+
...excludeTables !== void 0 ? { excludeTables } : {}
|
|
10401
|
+
};
|
|
10402
|
+
}
|
|
9751
10403
|
function buildEnvironmentNamingConfig() {
|
|
9752
10404
|
const modelType = resolveOptionalOneOf(MODEL_TYPE_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
9753
10405
|
const modelConst = resolveOptionalOneOf(MODEL_CONST_ENV_KEYS, NAMING_STYLE_VALUES);
|
|
@@ -9794,7 +10446,7 @@ function buildEnvironmentProviderConfig() {
|
|
|
9794
10446
|
kind: "postgres",
|
|
9795
10447
|
mode: "direct",
|
|
9796
10448
|
connectionString: directConnectionString,
|
|
9797
|
-
database:
|
|
10449
|
+
database: normalizeOptionalString3(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
9798
10450
|
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS))
|
|
9799
10451
|
};
|
|
9800
10452
|
}
|
|
@@ -9807,7 +10459,7 @@ function buildEnvironmentProviderConfig() {
|
|
|
9807
10459
|
mode: "gateway",
|
|
9808
10460
|
gatewayUrl,
|
|
9809
10461
|
apiKey,
|
|
9810
|
-
database:
|
|
10462
|
+
database: normalizeOptionalString3(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
9811
10463
|
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS)),
|
|
9812
10464
|
backend
|
|
9813
10465
|
};
|
|
@@ -9823,6 +10475,7 @@ function createEnvironmentGeneratorConfig() {
|
|
|
9823
10475
|
provider,
|
|
9824
10476
|
output: buildEnvironmentOutputConfig(),
|
|
9825
10477
|
naming: buildEnvironmentNamingConfig(),
|
|
10478
|
+
filter: buildEnvironmentFilterConfig(),
|
|
9826
10479
|
features: buildEnvironmentFeatureFlags(),
|
|
9827
10480
|
experimental: buildEnvironmentExperimentalFlags()
|
|
9828
10481
|
};
|
|
@@ -10308,7 +10961,7 @@ ${schemaEntries}
|
|
|
10308
10961
|
content
|
|
10309
10962
|
};
|
|
10310
10963
|
}
|
|
10311
|
-
function renderRegistryArtifact(registryPath, databasePath, databaseConstName, registryConstName, databaseName, generatedAt, outputFormat, schemaVersion) {
|
|
10964
|
+
function renderRegistryArtifact(registryPath, databasePath, databaseConstName, registryConstName, databaseName, generatedAt, outputPreset, outputFormat, schemaVersion) {
|
|
10312
10965
|
const databaseImportPath = toModuleImportPath(registryPath, databasePath);
|
|
10313
10966
|
const content = `import { defineRegistry } from '@xylex-group/athena'
|
|
10314
10967
|
import { ${databaseConstName} } from '${databaseImportPath}'
|
|
@@ -10317,6 +10970,7 @@ export const __athena_schema_meta = {
|
|
|
10317
10970
|
schemaVersion: ${schemaVersion},
|
|
10318
10971
|
generatedAt: ${escapeStringLiteral(generatedAt)},
|
|
10319
10972
|
database: ${escapeStringLiteral(databaseName)},
|
|
10973
|
+
outputPreset: ${escapeStringLiteral(outputPreset)},
|
|
10320
10974
|
outputFormat: ${escapeStringLiteral(outputFormat)},
|
|
10321
10975
|
} as const
|
|
10322
10976
|
|
|
@@ -10486,6 +11140,7 @@ function composeGeneratorArtifacts(input) {
|
|
|
10486
11140
|
toSafeIdentifier("registry", config.naming.registryConst, "registry"),
|
|
10487
11141
|
databaseName,
|
|
10488
11142
|
snapshot.generatedAt,
|
|
11143
|
+
config.output.preset,
|
|
10489
11144
|
config.output.format,
|
|
10490
11145
|
config.internal.schemaVersion
|
|
10491
11146
|
)
|
|
@@ -10591,7 +11246,7 @@ export const ${descriptor.tableConstName} = table(${escapeStringLiteral(descript
|
|
|
10591
11246
|
.columns({
|
|
10592
11247
|
${columnLines}
|
|
10593
11248
|
})
|
|
10594
|
-
.primaryKey(${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")})
|
|
11249
|
+
${descriptor.table.primaryKey.length > 0 ? `.primaryKey(${descriptor.table.primaryKey.map((value) => escapeStringLiteral(value)).join(", ")})` : ".withoutPrimaryKey()"}
|
|
10595
11250
|
${relationsAssignment ? `${relationsAssignment}` : ""}
|
|
10596
11251
|
export type ${descriptor.rowTypeName} = RowOf<typeof ${descriptor.tableConstName}>
|
|
10597
11252
|
export type ${descriptor.insertTypeName} = InsertOf<typeof ${descriptor.tableConstName}>
|
|
@@ -10688,11 +11343,12 @@ ${nullableLines}
|
|
|
10688
11343
|
}
|
|
10689
11344
|
function generateArtifactsFromSnapshot(snapshot, config) {
|
|
10690
11345
|
const normalizedConfig = "internal" in config ? config : normalizeGeneratorConfig(config);
|
|
11346
|
+
const filteredSnapshot = filterIntrospectionSnapshot(snapshot, normalizedConfig.filter);
|
|
10691
11347
|
if (normalizedConfig.output.format === "table-builder") {
|
|
10692
|
-
return generateTableBuilderArtifactsFromSnapshot(
|
|
11348
|
+
return generateTableBuilderArtifactsFromSnapshot(filteredSnapshot, normalizedConfig);
|
|
10693
11349
|
}
|
|
10694
11350
|
return composeGeneratorArtifacts({
|
|
10695
|
-
snapshot,
|
|
11351
|
+
snapshot: filteredSnapshot,
|
|
10696
11352
|
config: normalizedConfig,
|
|
10697
11353
|
createModelDescriptor({ providerName, databaseName, schemaName, tableName, table: table2 }) {
|
|
10698
11354
|
const modelConstName = toSafeIdentifier(
|
|
@@ -10722,7 +11378,7 @@ function generateArtifactsFromSnapshot(snapshot, config) {
|
|
|
10722
11378
|
table: table2
|
|
10723
11379
|
};
|
|
10724
11380
|
},
|
|
10725
|
-
renderModelArtifact: (descriptor) => renderModelArtifact2(
|
|
11381
|
+
renderModelArtifact: (descriptor) => renderModelArtifact2(filteredSnapshot.database, descriptor, normalizedConfig)
|
|
10726
11382
|
});
|
|
10727
11383
|
}
|
|
10728
11384
|
|
|
@@ -10842,16 +11498,25 @@ async function fileExists(path) {
|
|
|
10842
11498
|
}
|
|
10843
11499
|
async function writeArtifacts(files, cwd) {
|
|
10844
11500
|
const writtenFiles = [];
|
|
11501
|
+
const skippedFiles = [];
|
|
10845
11502
|
for (const file of files) {
|
|
10846
11503
|
const absolutePath = resolve(cwd, file.path);
|
|
10847
11504
|
if (!canOverwriteArtifact(file) && await fileExists(absolutePath)) {
|
|
11505
|
+
skippedFiles.push({
|
|
11506
|
+
kind: file.kind,
|
|
11507
|
+
path: file.path,
|
|
11508
|
+
reason: "protected-existing-file"
|
|
11509
|
+
});
|
|
10848
11510
|
continue;
|
|
10849
11511
|
}
|
|
10850
11512
|
await mkdir(dirname(absolutePath), { recursive: true });
|
|
10851
11513
|
await writeFile(absolutePath, file.content, "utf8");
|
|
10852
11514
|
writtenFiles.push(file.path);
|
|
10853
11515
|
}
|
|
10854
|
-
return
|
|
11516
|
+
return {
|
|
11517
|
+
writtenFiles,
|
|
11518
|
+
skippedFiles
|
|
11519
|
+
};
|
|
10855
11520
|
}
|
|
10856
11521
|
async function runSchemaGenerator(options = {}) {
|
|
10857
11522
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -10865,12 +11530,13 @@ async function runSchemaGenerator(options = {}) {
|
|
|
10865
11530
|
schemas: resolveProviderSchemas(config.provider)
|
|
10866
11531
|
});
|
|
10867
11532
|
const generated = generateArtifactsFromSnapshot(snapshot, config);
|
|
10868
|
-
const
|
|
11533
|
+
const writeResult = options.dryRun ? { writtenFiles: [], skippedFiles: [] } : await writeArtifacts(generated.files, cwd);
|
|
10869
11534
|
return {
|
|
10870
11535
|
...generated,
|
|
10871
11536
|
configPath,
|
|
10872
11537
|
config,
|
|
10873
|
-
writtenFiles
|
|
11538
|
+
writtenFiles: writeResult.writtenFiles,
|
|
11539
|
+
skippedFiles: writeResult.skippedFiles
|
|
10874
11540
|
};
|
|
10875
11541
|
}
|
|
10876
11542
|
|
|
@@ -11301,6 +11967,6 @@ function athenaAuth(config) {
|
|
|
11301
11967
|
return auth;
|
|
11302
11968
|
}
|
|
11303
11969
|
|
|
11304
|
-
export { ATHENA_AUTH_BASE_ERROR_CODES, AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, athenaAuth, boolean, coerceInt, createAthenaStorageError, createAuthClient, createAuthReactEmailInput, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, enumeration, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, getAthenaDebugAst, identifier, isAthenaGatewayError, isOk, json, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, number, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, string, table, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
|
|
11970
|
+
export { ATHENA_AUTH_ADMIN_LIMITS, ATHENA_AUTH_BASE_ERROR_CODES, ATHENA_AUTH_MAX_ADMIN_JSON_BYTES, ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH, ATHENA_AUTH_MAX_TEMPLATE_VARIABLES, ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH, AthenaClient, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_POSTGRES_SCHEMAS, assertInt, athenaAuth, boolean, coerceInt, createAthenaStorageError, createAuthClient, createAuthReactEmailInput, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createTypedClient, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, enumeration, filterIntrospectionSnapshot, findGeneratorConfigPath, generateArtifactsFromSnapshot, generatorEnv, getAthenaDebugAst, identifier, isAthenaGatewayError, isOk, json, loadGeneratorConfig, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeGeneratorConfig, normalizeSchemaSelection, normalizeTableSelection, number, parseBooleanFlag2 as parseBooleanFlag, renderAthenaReactEmail, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, runSchemaGenerator, storageSdkManifest, string, table, toModelFormDefaults, toModelPayload, unwrap, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
|
|
11305
11971
|
//# sourceMappingURL=index.js.map
|
|
11306
11972
|
//# sourceMappingURL=index.js.map
|