@xylex-group/athena 3.1.0 → 3.3.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 +1 -1
- package/dist/admin.cjs +55 -1
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.d.cts +32 -8
- package/dist/admin.d.ts +32 -8
- package/dist/admin.js +54 -2
- package/dist/admin.js.map +1 -1
- package/dist/athena-auth-url-C1FbVmN6.d.cts +200 -0
- package/dist/athena-auth-url-C1FbVmN6.d.ts +200 -0
- package/dist/{athena-request-headers-C7Jy-c_D.d.ts → athena-request-headers-DzimbvOA.d.ts} +48 -200
- package/dist/{athena-request-headers-DujFFyMU.d.cts → athena-request-headers-Lr_m8xCV.d.cts} +48 -200
- package/dist/billing.cjs +1 -1
- package/dist/billing.cjs.map +1 -1
- package/dist/billing.js +1 -1
- package/dist/billing.js.map +1 -1
- package/dist/browser.cjs +602 -16
- 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 +593 -17
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +141 -6
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +141 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/env.cjs +130 -0
- package/dist/env.cjs.map +1 -0
- package/dist/env.d.cts +70 -0
- package/dist/env.d.ts +70 -0
- package/dist/env.js +122 -0
- package/dist/env.js.map +1 -0
- package/dist/index.cjs +624 -19
- 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 +615 -20
- package/dist/index.js.map +1 -1
- package/dist/{model-form-BhWWsA-7.d.cts → model-form-3Gr8rkdT.d.cts} +24 -2
- package/dist/{model-form-BbdzJ9Uh.d.ts → model-form-CotpEL7z.d.ts} +24 -2
- package/dist/{module-xFd7_Igv.d.cts → module-CQmOaDzP.d.cts} +4 -4
- package/dist/{module-DKkJKOuJ.d.ts → module-CWkUTcUc.d.ts} +4 -4
- package/dist/next/client.cjs +123 -7
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.d.cts +4 -3
- package/dist/next/client.d.ts +4 -3
- package/dist/next/client.js +123 -7
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +1130 -364
- package/dist/next/server.cjs.map +1 -1
- package/dist/next/server.d.cts +121 -8
- package/dist/next/server.d.ts +121 -8
- package/dist/next/server.js +1120 -365
- package/dist/next/server.js.map +1 -1
- package/dist/{pipeline-DuKzYGia.d.cts → pipeline-BnRKO_Pd.d.cts} +1 -1
- package/dist/{pipeline-wer2G9xW.d.ts → pipeline-sWCmlFqu.d.ts} +1 -1
- package/dist/{proxy-request-headers-m4D2Tduy.d.ts → proxy-request-headers-CttlcuRb.d.ts} +1 -1
- package/dist/{proxy-request-headers-DGxdoyA0.d.cts → proxy-request-headers-pIBSn1Fw.d.cts} +1 -1
- package/dist/react.cjs +290 -31
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +59 -9
- package/dist/react.d.ts +59 -9
- package/dist/react.js +290 -32
- package/dist/react.js.map +1 -1
- package/dist/schema-handlers-BtT_IQFi.d.cts +138 -0
- package/dist/schema-handlers-VjFDhIMw.d.ts +138 -0
- package/dist/social-providers.d.cts +1 -1
- package/dist/social-providers.d.ts +1 -1
- package/dist/{types-CccOiXPo.d.ts → types-BDX8zS7w.d.ts} +12 -0
- package/dist/{types-AOY-GLu8.d.cts → types-BVKpQmfY.d.cts} +11 -0
- package/dist/{types-AOY-GLu8.d.ts → types-BVKpQmfY.d.ts} +11 -0
- package/dist/{types-1ztXDgPa.d.cts → types-D-Am7YSd.d.cts} +12 -0
- package/dist/utils.cjs +30 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +3 -2
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +30 -1
- package/dist/utils.js.map +1 -1
- package/dist/{v3-client-CWfZHcKL.d.cts → v3-client-G1SLeHRa.d.cts} +23 -1
- package/dist/{v3-client-DZp2NEhK.d.ts → v3-client-ao8BWQ8v.d.ts} +23 -1
- package/package.json +16 -2
package/dist/index.cjs
CHANGED
|
@@ -2009,7 +2009,7 @@ function buildAthenaGatewayUrl(baseUrl, path) {
|
|
|
2009
2009
|
|
|
2010
2010
|
// package.json
|
|
2011
2011
|
var package_default = {
|
|
2012
|
-
version: "3.
|
|
2012
|
+
version: "3.3.0"
|
|
2013
2013
|
};
|
|
2014
2014
|
|
|
2015
2015
|
// src/sdk-version.ts
|
|
@@ -4769,6 +4769,14 @@ function createAuthModule(config = {}, runtimeOptions = {}) {
|
|
|
4769
4769
|
changeEmailVerify: (input, options) => getWithQuery("/change-email/verify", input, options),
|
|
4770
4770
|
deleteUserVerify: (input, options) => getWithQuery("/delete-user/verify", input, options),
|
|
4771
4771
|
changePassword: (input, options) => postGeneric("/change-password", input, options),
|
|
4772
|
+
// Better Auth UI flat method aliases (also nested under session/account/social/user).
|
|
4773
|
+
listSessions: (input, options) => getGeneric("/list-sessions", input, options),
|
|
4774
|
+
revokeSession: sessionRevokeBinding,
|
|
4775
|
+
revokeOtherSessions,
|
|
4776
|
+
listAccounts: (input, options) => getGeneric("/list-accounts", input, options),
|
|
4777
|
+
unlinkAccount: (input, options) => postGeneric("/unlink-account", input, options),
|
|
4778
|
+
linkSocial: (input, options) => postGeneric("/link-social", input, options),
|
|
4779
|
+
updateUser: (input, options) => postGeneric("/update-user", input, options),
|
|
4772
4780
|
user: {
|
|
4773
4781
|
update: (input, options) => postGeneric("/update-user", input, options),
|
|
4774
4782
|
delete: (input, options) => postGeneric("/delete-user", input, options),
|
|
@@ -10578,6 +10586,82 @@ function mergeAthenaRequestContexts(base, override) {
|
|
|
10578
10586
|
};
|
|
10579
10587
|
}
|
|
10580
10588
|
|
|
10589
|
+
// src/diagnostics.ts
|
|
10590
|
+
function readProcessEnv2() {
|
|
10591
|
+
try {
|
|
10592
|
+
return globalThis.process?.env ?? {};
|
|
10593
|
+
} catch {
|
|
10594
|
+
return {};
|
|
10595
|
+
}
|
|
10596
|
+
}
|
|
10597
|
+
function isTruthyEnv(value) {
|
|
10598
|
+
if (!value) return false;
|
|
10599
|
+
const normalized = value.trim().toLowerCase();
|
|
10600
|
+
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
|
|
10601
|
+
}
|
|
10602
|
+
function isQuietAthenaDiagnosticsEnvironment(env = readProcessEnv2()) {
|
|
10603
|
+
const nodeEnv = env.NODE_ENV?.trim().toLowerCase();
|
|
10604
|
+
if (nodeEnv === "production") {
|
|
10605
|
+
return true;
|
|
10606
|
+
}
|
|
10607
|
+
if (isTruthyEnv(env.OPENNEXT_BUILD)) {
|
|
10608
|
+
return true;
|
|
10609
|
+
}
|
|
10610
|
+
const nextPhase = env.NEXT_PHASE?.trim();
|
|
10611
|
+
if (nextPhase === "phase-production-build") {
|
|
10612
|
+
return true;
|
|
10613
|
+
}
|
|
10614
|
+
if (isTruthyEnv(env.CI) && nodeEnv !== "test") {
|
|
10615
|
+
if (nodeEnv === "production" || isTruthyEnv(env.OPENNEXT_BUILD)) {
|
|
10616
|
+
return true;
|
|
10617
|
+
}
|
|
10618
|
+
}
|
|
10619
|
+
return false;
|
|
10620
|
+
}
|
|
10621
|
+
function resolveBooleanFlag(explicit, mode, quiet) {
|
|
10622
|
+
if (typeof explicit === "boolean") {
|
|
10623
|
+
return explicit;
|
|
10624
|
+
}
|
|
10625
|
+
if (mode === true) {
|
|
10626
|
+
return true;
|
|
10627
|
+
}
|
|
10628
|
+
if (mode === false) {
|
|
10629
|
+
return false;
|
|
10630
|
+
}
|
|
10631
|
+
if (mode === "auto") {
|
|
10632
|
+
return false;
|
|
10633
|
+
}
|
|
10634
|
+
return false;
|
|
10635
|
+
}
|
|
10636
|
+
function resolveAthenaClientDiagnostics(input) {
|
|
10637
|
+
const env = input.env ?? readProcessEnv2();
|
|
10638
|
+
const quiet = isQuietAthenaDiagnosticsEnvironment(env);
|
|
10639
|
+
const mode = input.diagnostics;
|
|
10640
|
+
const effectiveMode = mode === "auto" && quiet ? false : mode;
|
|
10641
|
+
const debugAst = resolveBooleanFlag(input.debugAst, effectiveMode);
|
|
10642
|
+
const findManyAst = resolveBooleanFlag(input.findManyAst, effectiveMode);
|
|
10643
|
+
let traceQueries;
|
|
10644
|
+
if (input.traceQueries !== void 0) {
|
|
10645
|
+
if (typeof input.traceQueries === "boolean") {
|
|
10646
|
+
traceQueries = input.traceQueries;
|
|
10647
|
+
} else if (effectiveMode === false || mode === "auto" && quiet) {
|
|
10648
|
+
const enabled = input.traceQueries.enabled;
|
|
10649
|
+
traceQueries = typeof enabled === "boolean" ? enabled ? input.traceQueries : false : false;
|
|
10650
|
+
} else {
|
|
10651
|
+
traceQueries = input.traceQueries;
|
|
10652
|
+
}
|
|
10653
|
+
} else if (effectiveMode === true) {
|
|
10654
|
+
traceQueries = true;
|
|
10655
|
+
} else {
|
|
10656
|
+
traceQueries = false;
|
|
10657
|
+
}
|
|
10658
|
+
return {
|
|
10659
|
+
debugAst,
|
|
10660
|
+
findManyAst,
|
|
10661
|
+
traceQueries
|
|
10662
|
+
};
|
|
10663
|
+
}
|
|
10664
|
+
|
|
10581
10665
|
// src/v3-client.ts
|
|
10582
10666
|
var ENV_URL_KEYS = ["ATHENA_URL", "NEXT_PUBLIC_ATHENA_URL"];
|
|
10583
10667
|
var ENV_DB_URL_KEYS = ["ATHENA_DB_URL", "ATHENA_GATEWAY_URL", "NEXT_PUBLIC_ATHENA_DB_API_URL"];
|
|
@@ -10586,7 +10670,13 @@ var ENV_CHAT_URL_KEYS = ["ATHENA_CHAT_URL", "NEXT_PUBLIC_ATHENA_CHAT_URL"];
|
|
|
10586
10670
|
var ENV_CHAT_WS_URL_KEYS = ["ATHENA_CHAT_WS_URL", "NEXT_PUBLIC_ATHENA_CHAT_WS_URL"];
|
|
10587
10671
|
var ENV_STORAGE_URL_KEYS = ["ATHENA_STORAGE_URL", "NEXT_PUBLIC_ATHENA_STORAGE_URL"];
|
|
10588
10672
|
var ENV_KEY_KEYS = ["ATHENA_API_KEY", "NEXT_PUBLIC_ATHENA_API_KEY", "ATHENA_GATEWAY_API_KEY", "X_API_KEY"];
|
|
10589
|
-
var ENV_CLIENT_KEYS = [
|
|
10673
|
+
var ENV_CLIENT_KEYS = [
|
|
10674
|
+
"ATHENA_CLIENT",
|
|
10675
|
+
"ATHENA_GATEWAY_CLIENT",
|
|
10676
|
+
"ATHENA_GENERATOR_CLIENT",
|
|
10677
|
+
"NEXT_PUBLIC_ATHENA_CLIENT",
|
|
10678
|
+
"NEXT_PUBLIC_ATHENA_GATEWAY_CLIENT"
|
|
10679
|
+
];
|
|
10590
10680
|
var MISSING_DB_SENTINEL = "https://athena.invalid/db";
|
|
10591
10681
|
function readFirstEnv(env, keys) {
|
|
10592
10682
|
for (const key of keys) {
|
|
@@ -10661,6 +10751,13 @@ function createInternalConfig(core) {
|
|
|
10661
10751
|
const { config, urls } = core;
|
|
10662
10752
|
const { url: _authUrl, ...authOptions } = config.auth ?? {};
|
|
10663
10753
|
const { url: _storageUrl, directUpload, ...storageOptions } = config.storage ?? {};
|
|
10754
|
+
const diagnostics = resolveAthenaClientDiagnostics({
|
|
10755
|
+
diagnostics: config.diagnostics,
|
|
10756
|
+
debugAst: config.debugAst,
|
|
10757
|
+
findManyAst: config.findManyAst,
|
|
10758
|
+
traceQueries: config.traceQueries,
|
|
10759
|
+
env: config.env
|
|
10760
|
+
});
|
|
10664
10761
|
return {
|
|
10665
10762
|
baseUrl: urls.db ?? MISSING_DB_SENTINEL,
|
|
10666
10763
|
apiKey: core.key,
|
|
@@ -10677,9 +10774,9 @@ function createInternalConfig(core) {
|
|
|
10677
10774
|
models: config.models,
|
|
10678
10775
|
behavior: {
|
|
10679
10776
|
retryReads: config.retryReads,
|
|
10680
|
-
traceQueries:
|
|
10681
|
-
debugAst:
|
|
10682
|
-
findManyAst:
|
|
10777
|
+
traceQueries: diagnostics.traceQueries,
|
|
10778
|
+
debugAst: diagnostics.debugAst,
|
|
10779
|
+
findManyAst: diagnostics.findManyAst
|
|
10683
10780
|
},
|
|
10684
10781
|
storage: {
|
|
10685
10782
|
...storageOptions,
|
|
@@ -10753,11 +10850,30 @@ function createClientView(core, viewContext) {
|
|
|
10753
10850
|
return resolved.verifyConnection(options);
|
|
10754
10851
|
},
|
|
10755
10852
|
withContext(context) {
|
|
10853
|
+
warnIfEmptyRequestContext(context);
|
|
10756
10854
|
return createClientView(core, mergeAthenaRequestContexts(viewContext, context));
|
|
10757
10855
|
}
|
|
10758
10856
|
};
|
|
10759
10857
|
return Object.freeze(client);
|
|
10760
10858
|
}
|
|
10859
|
+
function isEmptyAthenaRequestContext(context) {
|
|
10860
|
+
if (!context) return true;
|
|
10861
|
+
const hasHeaders = context.headers != null && Object.keys(context.headers).length > 0;
|
|
10862
|
+
return context.userId == null && context.organizationId == null && !normalizeOptionalContextString(context.cookie) && !normalizeOptionalContextString(context.bearerToken) && !normalizeOptionalContextString(context.sessionToken) && !context.forceNoCache && !hasHeaders;
|
|
10863
|
+
}
|
|
10864
|
+
function normalizeOptionalContextString(value) {
|
|
10865
|
+
const trimmed = value?.trim();
|
|
10866
|
+
return trimmed || void 0;
|
|
10867
|
+
}
|
|
10868
|
+
function warnIfEmptyRequestContext(context) {
|
|
10869
|
+
if (!isEmptyAthenaRequestContext(context)) return;
|
|
10870
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") {
|
|
10871
|
+
return;
|
|
10872
|
+
}
|
|
10873
|
+
console.warn(
|
|
10874
|
+
"[athena] withContext({}) has no userId, organizationId, cookie, bearerToken, sessionToken, headers, or forceNoCache. Gateway scope headers will not change. Pass identity fields, or use createAthenaServerClient({ session, scope })."
|
|
10875
|
+
);
|
|
10876
|
+
}
|
|
10761
10877
|
function createClient(config) {
|
|
10762
10878
|
return createClientView(resolveCore(config));
|
|
10763
10879
|
}
|
|
@@ -10996,6 +11112,27 @@ function resolveTotalItemsFromPage({
|
|
|
10996
11112
|
}
|
|
10997
11113
|
return clampAthenaReadQueryTotalItems(exactCount, limit);
|
|
10998
11114
|
}
|
|
11115
|
+
function resolveAthenaReadQueryPageFetch({
|
|
11116
|
+
page,
|
|
11117
|
+
pageSize,
|
|
11118
|
+
limit
|
|
11119
|
+
}) {
|
|
11120
|
+
const safePage = Math.max(1, Math.trunc(page) || 1);
|
|
11121
|
+
const safePageSize = Math.max(1, Math.trunc(pageSize) || 1);
|
|
11122
|
+
if (!limit || limit < 1) {
|
|
11123
|
+
return { page: safePage, pageSize: safePageSize, shouldFetch: true };
|
|
11124
|
+
}
|
|
11125
|
+
const totalCap = Math.trunc(limit);
|
|
11126
|
+
const offset = (safePage - 1) * safePageSize;
|
|
11127
|
+
if (offset >= totalCap) {
|
|
11128
|
+
return { page: safePage, pageSize: safePageSize, shouldFetch: false };
|
|
11129
|
+
}
|
|
11130
|
+
return {
|
|
11131
|
+
page: safePage,
|
|
11132
|
+
pageSize: Math.min(safePageSize, totalCap - offset),
|
|
11133
|
+
shouldFetch: true
|
|
11134
|
+
};
|
|
11135
|
+
}
|
|
10999
11136
|
async function executeAthenaReadQuery({
|
|
11000
11137
|
client,
|
|
11001
11138
|
page,
|
|
@@ -11014,15 +11151,29 @@ async function executeAthenaReadQuery({
|
|
|
11014
11151
|
count: "exact",
|
|
11015
11152
|
head: true
|
|
11016
11153
|
});
|
|
11154
|
+
const pageFetch = resolveAthenaReadQueryPageFetch({
|
|
11155
|
+
limit: query.limit,
|
|
11156
|
+
page,
|
|
11157
|
+
pageSize
|
|
11158
|
+
});
|
|
11159
|
+
if (!pageFetch.shouldFetch) {
|
|
11160
|
+
return {
|
|
11161
|
+
rows: [],
|
|
11162
|
+
totalItems: resolveTotalItemsFromPage({
|
|
11163
|
+
countCandidates: [countResult.count],
|
|
11164
|
+
limit: query.limit,
|
|
11165
|
+
page: pageFetch.page,
|
|
11166
|
+
pageSize,
|
|
11167
|
+
rowCount: 0
|
|
11168
|
+
})
|
|
11169
|
+
};
|
|
11170
|
+
}
|
|
11017
11171
|
if ((query.mode ?? "findMany") === "select") {
|
|
11018
|
-
const selectBuilder =
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
query.orderBy
|
|
11022
|
-
),
|
|
11023
|
-
query.limit
|
|
11172
|
+
const selectBuilder = applyAthenaReadQuerySelectOrder(
|
|
11173
|
+
applyAthenaReadQueryFilters(baseBuilder, query.filters),
|
|
11174
|
+
query.orderBy
|
|
11024
11175
|
);
|
|
11025
|
-
const result2 = await selectBuilder.currentPage(page).pageSize(pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
|
|
11176
|
+
const result2 = await selectBuilder.currentPage(pageFetch.page).pageSize(pageFetch.pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
|
|
11026
11177
|
count: "exact"
|
|
11027
11178
|
});
|
|
11028
11179
|
const rows2 = flattenAthenaReadQueryRows(
|
|
@@ -11036,7 +11187,7 @@ async function executeAthenaReadQuery({
|
|
|
11036
11187
|
totalItems: resolveTotalItemsFromPage({
|
|
11037
11188
|
countCandidates: [countResult.count, result2.count],
|
|
11038
11189
|
limit: query.limit,
|
|
11039
|
-
page,
|
|
11190
|
+
page: pageFetch.page,
|
|
11040
11191
|
pageSize,
|
|
11041
11192
|
rowCount: rows2.length
|
|
11042
11193
|
})
|
|
@@ -11044,12 +11195,11 @@ async function executeAthenaReadQuery({
|
|
|
11044
11195
|
}
|
|
11045
11196
|
const findManyOrderBy = buildAthenaReadQueryFindManyOrderBy(query.orderBy);
|
|
11046
11197
|
const findManyOptions = {
|
|
11047
|
-
...query.limit ? { limit: query.limit } : {},
|
|
11048
11198
|
...findManyOrderBy ? { orderBy: findManyOrderBy } : {},
|
|
11049
11199
|
select: buildAthenaReadQueryFindManySelect(query.columns),
|
|
11050
11200
|
...query.filters?.length ? { where: buildAthenaReadQueryFindManyWhere(query.filters) } : {}
|
|
11051
11201
|
};
|
|
11052
|
-
const result = await baseBuilder.currentPage(page).pageSize(pageSize).findMany(findManyOptions);
|
|
11202
|
+
const result = await baseBuilder.currentPage(pageFetch.page).pageSize(pageFetch.pageSize).findMany(findManyOptions);
|
|
11053
11203
|
const rows = flattenAthenaReadQueryRows(
|
|
11054
11204
|
Array.isArray(result.data) ? result.data : [],
|
|
11055
11205
|
query.columns,
|
|
@@ -11061,7 +11211,7 @@ async function executeAthenaReadQuery({
|
|
|
11061
11211
|
totalItems: resolveTotalItemsFromPage({
|
|
11062
11212
|
countCandidates: [countResult.count, result.count],
|
|
11063
11213
|
limit: query.limit,
|
|
11064
|
-
page,
|
|
11214
|
+
page: pageFetch.page,
|
|
11065
11215
|
pageSize,
|
|
11066
11216
|
rowCount: rows.length
|
|
11067
11217
|
})
|
|
@@ -12062,6 +12212,13 @@ var GATEWAY_API_KEY_ENV_KEYS = [
|
|
|
12062
12212
|
"ATHENA_GATEWAY_API_KEY",
|
|
12063
12213
|
"ATHENA_GENERATOR_API_KEY"
|
|
12064
12214
|
];
|
|
12215
|
+
var GATEWAY_CLIENT_ENV_KEYS = [
|
|
12216
|
+
"ATHENA_CLIENT",
|
|
12217
|
+
"ATHENA_GATEWAY_CLIENT",
|
|
12218
|
+
"ATHENA_GENERATOR_CLIENT",
|
|
12219
|
+
"NEXT_PUBLIC_ATHENA_CLIENT",
|
|
12220
|
+
"NEXT_PUBLIC_ATHENA_GATEWAY_CLIENT"
|
|
12221
|
+
];
|
|
12065
12222
|
var GENERATOR_SCHEMA_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMAS"];
|
|
12066
12223
|
var OUTPUT_FORMAT_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_FORMAT"];
|
|
12067
12224
|
var OUTPUT_PRESET_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_PRESET"];
|
|
@@ -12362,11 +12519,13 @@ function normalizeProviderConfig(provider) {
|
|
|
12362
12519
|
GATEWAY_API_KEY_ENV_KEYS
|
|
12363
12520
|
);
|
|
12364
12521
|
const database = normalizeOptionalString(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? "postgres";
|
|
12522
|
+
const client = normalizeOptionalString(provider.client, GATEWAY_CLIENT_ENV_KEYS);
|
|
12365
12523
|
return {
|
|
12366
12524
|
...provider,
|
|
12367
12525
|
gatewayUrl,
|
|
12368
12526
|
apiKey,
|
|
12369
12527
|
database,
|
|
12528
|
+
...client ? { client } : {},
|
|
12370
12529
|
schemas: normalizeSchemaSelection(provider.schemas)
|
|
12371
12530
|
};
|
|
12372
12531
|
}
|
|
@@ -12560,6 +12719,7 @@ function buildEnvironmentProviderConfig() {
|
|
|
12560
12719
|
const apiKey = resolveFallbackValue(GATEWAY_API_KEY_ENV_KEYS);
|
|
12561
12720
|
if (gatewayUrl && apiKey) {
|
|
12562
12721
|
const backend = resolveOptionalOneOf(GATEWAY_BACKEND_ENV_KEYS, BACKEND_TYPE_VALUES);
|
|
12722
|
+
const client = resolveFallbackValue(GATEWAY_CLIENT_ENV_KEYS);
|
|
12563
12723
|
return {
|
|
12564
12724
|
kind: "postgres",
|
|
12565
12725
|
mode: "gateway",
|
|
@@ -12567,7 +12727,8 @@ function buildEnvironmentProviderConfig() {
|
|
|
12567
12727
|
apiKey,
|
|
12568
12728
|
database: normalizeOptionalString(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
12569
12729
|
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS)),
|
|
12570
|
-
backend
|
|
12730
|
+
backend,
|
|
12731
|
+
...client ? { client } : {}
|
|
12571
12732
|
};
|
|
12572
12733
|
}
|
|
12573
12734
|
return void 0;
|
|
@@ -12711,6 +12872,8 @@ async function discoverGatewaySchemas(config) {
|
|
|
12711
12872
|
const client = createClient({
|
|
12712
12873
|
db: { url: config.gatewayUrl },
|
|
12713
12874
|
key: config.apiKey,
|
|
12875
|
+
client: config.client,
|
|
12876
|
+
env: typeof process !== "undefined" ? process.env : void 0,
|
|
12714
12877
|
backend: {
|
|
12715
12878
|
type: config.backend ?? "postgresql"
|
|
12716
12879
|
}
|
|
@@ -12797,6 +12960,7 @@ function buildGatewayProviderBlock(schemas) {
|
|
|
12797
12960
|
mode: "gateway",
|
|
12798
12961
|
gatewayUrl: generatorEnv("ATHENA_URL"),
|
|
12799
12962
|
apiKey: generatorEnv("ATHENA_API_KEY"),
|
|
12963
|
+
client: generatorEnv("ATHENA_CLIENT", { optional: true }),
|
|
12800
12964
|
database: generatorEnv("ATHENA_GENERATOR_DB", { default: "postgres" }),
|
|
12801
12965
|
schemas: ${formatStringArray(schemas, " ")},
|
|
12802
12966
|
}`;
|
|
@@ -13820,7 +13984,7 @@ function renderModelArtifact(descriptor, config) {
|
|
|
13820
13984
|
const relationsAssignment = config.features.emitRelations && relationEntries.length > 0 ? `
|
|
13821
13985
|
Object.assign(${descriptor.tableConstName}.meta, {
|
|
13822
13986
|
relations: {
|
|
13823
|
-
${relationEntries.map(([
|
|
13987
|
+
${relationEntries.map(([relationKey3, relationValue]) => ` ${renderObjectKey(relationKey3)}: ${renderRelationLiteral(relationValue)}`).join(",\n")}
|
|
13824
13988
|
}
|
|
13825
13989
|
})
|
|
13826
13990
|
` : "";
|
|
@@ -13897,7 +14061,7 @@ function renderModelArtifact2(databaseName, descriptor, config) {
|
|
|
13897
14061
|
const relationEntries = Object.entries(descriptor.table.relations);
|
|
13898
14062
|
const relationBlock = config.features.emitRelations && relationEntries.length > 0 ? `,
|
|
13899
14063
|
relations: {
|
|
13900
|
-
${relationEntries.map(([
|
|
14064
|
+
${relationEntries.map(([relationKey3, relationValue]) => ` ${renderObjectKey(relationKey3)}: ${renderRelationLiteral(relationValue)}`).join(",\n")}
|
|
13901
14065
|
}` : "";
|
|
13902
14066
|
const content = `import { defineModel } from '@xylex-group/athena'
|
|
13903
14067
|
|
|
@@ -14006,6 +14170,11 @@ var AthenaGatewayPostgresIntrospectionProvider = class {
|
|
|
14006
14170
|
this.client = createClient({
|
|
14007
14171
|
db: { url: this.config.gatewayUrl },
|
|
14008
14172
|
key: this.config.apiKey,
|
|
14173
|
+
// Multi-tenant gateways reject DEFAULT_CLIENT; prefer explicit config.
|
|
14174
|
+
// Also pass process.env so ATHENA_CLIENT / ATHENA_GATEWAY_CLIENT still resolve
|
|
14175
|
+
// when the field was not normalized into provider config.
|
|
14176
|
+
client: this.config.client,
|
|
14177
|
+
env: typeof process !== "undefined" ? process.env : void 0,
|
|
14009
14178
|
backend: {
|
|
14010
14179
|
type: this.config.backend ?? "postgresql"
|
|
14011
14180
|
}
|
|
@@ -15486,12 +15655,439 @@ async function ensureActiveOrganization(options) {
|
|
|
15486
15655
|
}
|
|
15487
15656
|
}
|
|
15488
15657
|
|
|
15658
|
+
// src/tables/catalog.ts
|
|
15659
|
+
var POSTGRES_CATALOG_SQL2 = {
|
|
15660
|
+
columns: `
|
|
15661
|
+
SELECT
|
|
15662
|
+
n.nspname AS schema_name,
|
|
15663
|
+
c.relname AS table_name,
|
|
15664
|
+
a.attname AS column_name,
|
|
15665
|
+
format_type(a.atttypid, a.atttypmod) AS data_type,
|
|
15666
|
+
NOT a.attnotnull AS is_nullable
|
|
15667
|
+
FROM pg_attribute a
|
|
15668
|
+
JOIN pg_class c ON c.oid = a.attrelid
|
|
15669
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
15670
|
+
WHERE c.relkind IN ('r', 'p')
|
|
15671
|
+
AND a.attnum > 0
|
|
15672
|
+
AND NOT a.attisdropped
|
|
15673
|
+
AND n.nspname = ANY($1::text[])
|
|
15674
|
+
ORDER BY n.nspname, c.relname, a.attnum;
|
|
15675
|
+
`,
|
|
15676
|
+
foreignKeys: `
|
|
15677
|
+
SELECT
|
|
15678
|
+
sn.nspname AS source_schema,
|
|
15679
|
+
sc.relname AS source_table,
|
|
15680
|
+
con.conname AS constraint_name,
|
|
15681
|
+
ARRAY_AGG(sa.attname ORDER BY cols.ordinality) AS source_columns,
|
|
15682
|
+
tn.nspname AS target_schema,
|
|
15683
|
+
tc.relname AS target_table,
|
|
15684
|
+
ARRAY_AGG(ta.attname ORDER BY cols.ordinality) AS target_columns,
|
|
15685
|
+
EXISTS (
|
|
15686
|
+
SELECT 1
|
|
15687
|
+
FROM pg_constraint uq
|
|
15688
|
+
WHERE uq.conrelid = con.conrelid
|
|
15689
|
+
AND uq.contype IN ('p', 'u')
|
|
15690
|
+
AND uq.conkey = con.conkey
|
|
15691
|
+
) AS source_is_unique
|
|
15692
|
+
FROM pg_constraint con
|
|
15693
|
+
JOIN pg_class sc ON sc.oid = con.conrelid
|
|
15694
|
+
JOIN pg_namespace sn ON sn.oid = sc.relnamespace
|
|
15695
|
+
JOIN pg_class tc ON tc.oid = con.confrelid
|
|
15696
|
+
JOIN pg_namespace tn ON tn.oid = tc.relnamespace
|
|
15697
|
+
JOIN unnest(con.conkey, con.confkey) WITH ORDINALITY AS cols(source_attnum, target_attnum, ordinality) ON TRUE
|
|
15698
|
+
JOIN pg_attribute sa ON sa.attrelid = con.conrelid AND sa.attnum = cols.source_attnum
|
|
15699
|
+
JOIN pg_attribute ta ON ta.attrelid = con.confrelid AND ta.attnum = cols.target_attnum
|
|
15700
|
+
WHERE con.contype = 'f'
|
|
15701
|
+
AND sn.nspname = ANY($1::text[])
|
|
15702
|
+
AND tn.nspname = ANY($1::text[])
|
|
15703
|
+
GROUP BY
|
|
15704
|
+
sn.nspname,
|
|
15705
|
+
sc.relname,
|
|
15706
|
+
con.conname,
|
|
15707
|
+
tn.nspname,
|
|
15708
|
+
tc.relname,
|
|
15709
|
+
con.conkey,
|
|
15710
|
+
con.conrelid
|
|
15711
|
+
ORDER BY sn.nspname, sc.relname, con.conname;
|
|
15712
|
+
`,
|
|
15713
|
+
primaryKeys: `
|
|
15714
|
+
SELECT
|
|
15715
|
+
n.nspname AS schema_name,
|
|
15716
|
+
c.relname AS table_name,
|
|
15717
|
+
ARRAY_AGG(a.attname ORDER BY ck.ordinality) AS columns
|
|
15718
|
+
FROM pg_constraint con
|
|
15719
|
+
JOIN pg_class c ON c.oid = con.conrelid
|
|
15720
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
15721
|
+
JOIN unnest(con.conkey) WITH ORDINALITY AS ck(attnum, ordinality) ON TRUE
|
|
15722
|
+
JOIN pg_attribute a ON a.attrelid = c.oid AND a.attnum = ck.attnum
|
|
15723
|
+
WHERE con.contype = 'p'
|
|
15724
|
+
AND n.nspname = ANY($1::text[])
|
|
15725
|
+
GROUP BY n.nspname, c.relname
|
|
15726
|
+
ORDER BY n.nspname, c.relname;
|
|
15727
|
+
`
|
|
15728
|
+
};
|
|
15729
|
+
function parseAthenaTableSchemaScope(value) {
|
|
15730
|
+
return value.split(",").map((entry) => entry.trim()).filter(
|
|
15731
|
+
(entry, index, values) => entry.length > 0 && values.indexOf(entry) === index
|
|
15732
|
+
);
|
|
15733
|
+
}
|
|
15734
|
+
function escapeSqlLiteral2(value) {
|
|
15735
|
+
return value.replace(/'/g, "''");
|
|
15736
|
+
}
|
|
15737
|
+
function buildSchemaArrayLiteral2(schemas) {
|
|
15738
|
+
const literals = schemas.map((schema) => `'${escapeSqlLiteral2(schema)}'`).join(", ");
|
|
15739
|
+
return `ARRAY[${literals}]`;
|
|
15740
|
+
}
|
|
15741
|
+
function inlineSchemaLiteral2(sql, schemas) {
|
|
15742
|
+
return sql.replace(
|
|
15743
|
+
/\$1::text\[\]/g,
|
|
15744
|
+
`${buildSchemaArrayLiteral2(schemas)}::text[]`
|
|
15745
|
+
);
|
|
15746
|
+
}
|
|
15747
|
+
function buildAthenaTableCatalogQueries(schemas) {
|
|
15748
|
+
return {
|
|
15749
|
+
columns: inlineSchemaLiteral2(POSTGRES_CATALOG_SQL2.columns, schemas),
|
|
15750
|
+
foreignKeys: inlineSchemaLiteral2(POSTGRES_CATALOG_SQL2.foreignKeys, schemas),
|
|
15751
|
+
primaryKeys: inlineSchemaLiteral2(POSTGRES_CATALOG_SQL2.primaryKeys, schemas)
|
|
15752
|
+
};
|
|
15753
|
+
}
|
|
15754
|
+
function tableKey2(schema, table2) {
|
|
15755
|
+
return `${schema}.${table2}`;
|
|
15756
|
+
}
|
|
15757
|
+
function relationKey2(...parts) {
|
|
15758
|
+
const base = parts.join("_").replace(/[^A-Za-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
|
|
15759
|
+
return base.length > 0 ? base : "relation";
|
|
15760
|
+
}
|
|
15761
|
+
function parsePostgresArrayLiteral2(text) {
|
|
15762
|
+
const body = text.slice(1, -1).trim();
|
|
15763
|
+
if (!body) {
|
|
15764
|
+
return [];
|
|
15765
|
+
}
|
|
15766
|
+
const values = [];
|
|
15767
|
+
let current = "";
|
|
15768
|
+
let inQuotes = false;
|
|
15769
|
+
let escaped = false;
|
|
15770
|
+
for (const char of body) {
|
|
15771
|
+
if (escaped) {
|
|
15772
|
+
current += char;
|
|
15773
|
+
escaped = false;
|
|
15774
|
+
continue;
|
|
15775
|
+
}
|
|
15776
|
+
if (char === "\\") {
|
|
15777
|
+
escaped = true;
|
|
15778
|
+
continue;
|
|
15779
|
+
}
|
|
15780
|
+
if (char === '"') {
|
|
15781
|
+
inQuotes = !inQuotes;
|
|
15782
|
+
continue;
|
|
15783
|
+
}
|
|
15784
|
+
if (char === "," && !inQuotes) {
|
|
15785
|
+
values.push(current);
|
|
15786
|
+
current = "";
|
|
15787
|
+
continue;
|
|
15788
|
+
}
|
|
15789
|
+
current += char;
|
|
15790
|
+
}
|
|
15791
|
+
values.push(current);
|
|
15792
|
+
return values.map((value) => value.trim()).filter((value) => value.length > 0);
|
|
15793
|
+
}
|
|
15794
|
+
function coerceStringArray2(value) {
|
|
15795
|
+
if (value == null) {
|
|
15796
|
+
return [];
|
|
15797
|
+
}
|
|
15798
|
+
if (Array.isArray(value)) {
|
|
15799
|
+
return value.map((entry) => entry.trim()).filter(Boolean);
|
|
15800
|
+
}
|
|
15801
|
+
if (typeof value !== "string") {
|
|
15802
|
+
return [];
|
|
15803
|
+
}
|
|
15804
|
+
const trimmedValue = value.trim();
|
|
15805
|
+
if (!trimmedValue) {
|
|
15806
|
+
return [];
|
|
15807
|
+
}
|
|
15808
|
+
if (trimmedValue.startsWith("{") && trimmedValue.endsWith("}")) {
|
|
15809
|
+
return parsePostgresArrayLiteral2(trimmedValue);
|
|
15810
|
+
}
|
|
15811
|
+
return trimmedValue.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
15812
|
+
}
|
|
15813
|
+
function createTableCatalog() {
|
|
15814
|
+
const tables = /* @__PURE__ */ new Map();
|
|
15815
|
+
const ensureTable = (schema, name) => {
|
|
15816
|
+
const id = tableKey2(schema, name);
|
|
15817
|
+
const existingTable = tables.get(id);
|
|
15818
|
+
if (existingTable) {
|
|
15819
|
+
return existingTable;
|
|
15820
|
+
}
|
|
15821
|
+
const nextTable = {
|
|
15822
|
+
columns: [],
|
|
15823
|
+
id,
|
|
15824
|
+
name,
|
|
15825
|
+
primaryKey: [],
|
|
15826
|
+
relationMap: /* @__PURE__ */ new Map(),
|
|
15827
|
+
schema
|
|
15828
|
+
};
|
|
15829
|
+
tables.set(id, nextTable);
|
|
15830
|
+
return nextTable;
|
|
15831
|
+
};
|
|
15832
|
+
const upsertRelation = (table2, key, relation) => {
|
|
15833
|
+
table2.relationMap.set(key, relation);
|
|
15834
|
+
};
|
|
15835
|
+
return {
|
|
15836
|
+
addColumnRows(columnRows) {
|
|
15837
|
+
for (const row of columnRows) {
|
|
15838
|
+
const table2 = ensureTable(row.schema_name, row.table_name);
|
|
15839
|
+
table2.columns.push({
|
|
15840
|
+
dataType: row.data_type,
|
|
15841
|
+
isNullable: row.is_nullable,
|
|
15842
|
+
isPrimaryKey: false,
|
|
15843
|
+
name: row.column_name
|
|
15844
|
+
});
|
|
15845
|
+
}
|
|
15846
|
+
},
|
|
15847
|
+
addForeignKeyRows(foreignKeyRows) {
|
|
15848
|
+
for (const row of foreignKeyRows) {
|
|
15849
|
+
const sourceTable = ensureTable(row.source_schema, row.source_table);
|
|
15850
|
+
const targetTable = ensureTable(row.target_schema, row.target_table);
|
|
15851
|
+
upsertRelation(
|
|
15852
|
+
sourceTable,
|
|
15853
|
+
relationKey2(row.constraint_name, row.target_table),
|
|
15854
|
+
{
|
|
15855
|
+
name: row.constraint_name,
|
|
15856
|
+
targetSchema: row.target_schema,
|
|
15857
|
+
targetTable: row.target_table
|
|
15858
|
+
}
|
|
15859
|
+
);
|
|
15860
|
+
upsertRelation(targetTable, relationKey2(row.source_table), {
|
|
15861
|
+
name: relationKey2(row.source_table, row.constraint_name),
|
|
15862
|
+
targetSchema: row.source_schema,
|
|
15863
|
+
targetTable: row.source_table
|
|
15864
|
+
});
|
|
15865
|
+
}
|
|
15866
|
+
},
|
|
15867
|
+
addManyToManyRows(foreignKeyRows) {
|
|
15868
|
+
const foreignKeysBySourceTable = /* @__PURE__ */ new Map();
|
|
15869
|
+
for (const foreignKey of foreignKeyRows) {
|
|
15870
|
+
const key = tableKey2(foreignKey.source_schema, foreignKey.source_table);
|
|
15871
|
+
const current = foreignKeysBySourceTable.get(key) ?? {
|
|
15872
|
+
foreignKeys: [],
|
|
15873
|
+
schema: foreignKey.source_schema,
|
|
15874
|
+
table: foreignKey.source_table
|
|
15875
|
+
};
|
|
15876
|
+
current.foreignKeys.push(foreignKey);
|
|
15877
|
+
foreignKeysBySourceTable.set(key, current);
|
|
15878
|
+
}
|
|
15879
|
+
for (const candidate of foreignKeysBySourceTable.values()) {
|
|
15880
|
+
const bridgeTable = tables.get(
|
|
15881
|
+
tableKey2(candidate.schema, candidate.table)
|
|
15882
|
+
);
|
|
15883
|
+
if (!bridgeTable || candidate.foreignKeys.length !== 2) {
|
|
15884
|
+
continue;
|
|
15885
|
+
}
|
|
15886
|
+
const combinedForeignColumns = Array.from(
|
|
15887
|
+
new Set(
|
|
15888
|
+
candidate.foreignKeys.flatMap(
|
|
15889
|
+
(foreignKey) => coerceStringArray2(foreignKey.source_columns)
|
|
15890
|
+
)
|
|
15891
|
+
)
|
|
15892
|
+
);
|
|
15893
|
+
if (bridgeTable.primaryKey.length === 0 || combinedForeignColumns.length !== bridgeTable.primaryKey.length || !bridgeTable.primaryKey.every(
|
|
15894
|
+
(column) => combinedForeignColumns.includes(column)
|
|
15895
|
+
)) {
|
|
15896
|
+
continue;
|
|
15897
|
+
}
|
|
15898
|
+
const [firstForeignKey, secondForeignKey] = candidate.foreignKeys;
|
|
15899
|
+
const firstTarget = tables.get(
|
|
15900
|
+
tableKey2(firstForeignKey.target_schema, firstForeignKey.target_table)
|
|
15901
|
+
);
|
|
15902
|
+
const secondTarget = tables.get(
|
|
15903
|
+
tableKey2(
|
|
15904
|
+
secondForeignKey.target_schema,
|
|
15905
|
+
secondForeignKey.target_table
|
|
15906
|
+
)
|
|
15907
|
+
);
|
|
15908
|
+
if (!(firstTarget && secondTarget)) {
|
|
15909
|
+
continue;
|
|
15910
|
+
}
|
|
15911
|
+
upsertRelation(
|
|
15912
|
+
firstTarget,
|
|
15913
|
+
relationKey2(candidate.table, secondForeignKey.target_table),
|
|
15914
|
+
{
|
|
15915
|
+
name: relationKey2(
|
|
15916
|
+
candidate.table,
|
|
15917
|
+
secondForeignKey.constraint_name
|
|
15918
|
+
),
|
|
15919
|
+
targetSchema: secondForeignKey.target_schema,
|
|
15920
|
+
targetTable: secondForeignKey.target_table
|
|
15921
|
+
}
|
|
15922
|
+
);
|
|
15923
|
+
upsertRelation(
|
|
15924
|
+
secondTarget,
|
|
15925
|
+
relationKey2(candidate.table, firstForeignKey.target_table),
|
|
15926
|
+
{
|
|
15927
|
+
name: relationKey2(candidate.table, firstForeignKey.constraint_name),
|
|
15928
|
+
targetSchema: firstForeignKey.target_schema,
|
|
15929
|
+
targetTable: firstForeignKey.target_table
|
|
15930
|
+
}
|
|
15931
|
+
);
|
|
15932
|
+
}
|
|
15933
|
+
},
|
|
15934
|
+
addPrimaryKeyRows(primaryKeyRows) {
|
|
15935
|
+
for (const row of primaryKeyRows) {
|
|
15936
|
+
const table2 = ensureTable(row.schema_name, row.table_name);
|
|
15937
|
+
const primaryKey = coerceStringArray2(row.columns);
|
|
15938
|
+
table2.primaryKey = primaryKey;
|
|
15939
|
+
for (const columnName of primaryKey) {
|
|
15940
|
+
const column = table2.columns.find(
|
|
15941
|
+
(candidate) => candidate.name === columnName
|
|
15942
|
+
);
|
|
15943
|
+
if (column) {
|
|
15944
|
+
column.isPrimaryKey = true;
|
|
15945
|
+
}
|
|
15946
|
+
}
|
|
15947
|
+
}
|
|
15948
|
+
},
|
|
15949
|
+
toResponse(database) {
|
|
15950
|
+
return {
|
|
15951
|
+
database,
|
|
15952
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15953
|
+
tables: [...tables.values()].map((table2) => ({
|
|
15954
|
+
columns: [...table2.columns].sort(
|
|
15955
|
+
(left, right) => left.name.localeCompare(right.name)
|
|
15956
|
+
),
|
|
15957
|
+
id: table2.id,
|
|
15958
|
+
name: table2.name,
|
|
15959
|
+
primaryKey: [...table2.primaryKey],
|
|
15960
|
+
relations: [...table2.relationMap.values()].map((relation) => ({
|
|
15961
|
+
columns: tables.get(
|
|
15962
|
+
tableKey2(relation.targetSchema, relation.targetTable)
|
|
15963
|
+
)?.columns ?? [],
|
|
15964
|
+
name: relation.name,
|
|
15965
|
+
targetSchema: relation.targetSchema,
|
|
15966
|
+
targetTable: relation.targetTable
|
|
15967
|
+
})).sort(
|
|
15968
|
+
(left, right) => left.name.localeCompare(right.name)
|
|
15969
|
+
),
|
|
15970
|
+
schema: table2.schema
|
|
15971
|
+
})).sort(
|
|
15972
|
+
(left, right) => left.id.localeCompare(right.id)
|
|
15973
|
+
)
|
|
15974
|
+
};
|
|
15975
|
+
}
|
|
15976
|
+
};
|
|
15977
|
+
}
|
|
15978
|
+
async function queryRows(client, query) {
|
|
15979
|
+
const result = await client.query(query);
|
|
15980
|
+
if (result.error || result.status < 200 || result.status >= 300) {
|
|
15981
|
+
const errorMessage = typeof result.error === "string" ? result.error : result.error && typeof result.error === "object" && "message" in result.error && typeof result.error.message === "string" ? result.error.message : `Athena gateway query failed with status ${result.status}.`;
|
|
15982
|
+
throw new Error(errorMessage);
|
|
15983
|
+
}
|
|
15984
|
+
return Array.isArray(result.data) ? result.data : [];
|
|
15985
|
+
}
|
|
15986
|
+
function isAthenaTableSchemaConfig(value) {
|
|
15987
|
+
if (typeof value !== "object" || value === null) {
|
|
15988
|
+
return false;
|
|
15989
|
+
}
|
|
15990
|
+
const config = value;
|
|
15991
|
+
return typeof config.gatewayUrl === "string" && typeof config.gatewayKey === "string" && typeof config.gatewayDatabase === "string" && typeof config.schemaScope === "string" && typeof config.clientName === "string";
|
|
15992
|
+
}
|
|
15993
|
+
function hasAthenaTableSchemaCredentials(config) {
|
|
15994
|
+
return config.gatewayUrl.trim().length > 0 && config.gatewayKey.trim().length > 0 && config.gatewayDatabase.trim().length > 0;
|
|
15995
|
+
}
|
|
15996
|
+
async function fetchAthenaTableCatalog(config, options = {}) {
|
|
15997
|
+
const schemas = parseAthenaTableSchemaScope(config.schemaScope);
|
|
15998
|
+
if (schemas.length === 0) {
|
|
15999
|
+
return {
|
|
16000
|
+
database: config.gatewayDatabase,
|
|
16001
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16002
|
+
tables: []
|
|
16003
|
+
};
|
|
16004
|
+
}
|
|
16005
|
+
const queries = buildAthenaTableCatalogQueries(schemas);
|
|
16006
|
+
const client = options.client ?? createClient({
|
|
16007
|
+
url: config.gatewayUrl.trim(),
|
|
16008
|
+
key: config.gatewayKey.trim(),
|
|
16009
|
+
client: config.clientName.trim() || void 0
|
|
16010
|
+
});
|
|
16011
|
+
const [columnRows, primaryKeyRows, foreignKeyRows] = await Promise.all([
|
|
16012
|
+
queryRows(client, queries.columns),
|
|
16013
|
+
queryRows(client, queries.primaryKeys),
|
|
16014
|
+
queryRows(client, queries.foreignKeys)
|
|
16015
|
+
]);
|
|
16016
|
+
const catalog = createTableCatalog();
|
|
16017
|
+
catalog.addColumnRows(columnRows);
|
|
16018
|
+
catalog.addPrimaryKeyRows(primaryKeyRows);
|
|
16019
|
+
catalog.addForeignKeyRows(foreignKeyRows);
|
|
16020
|
+
catalog.addManyToManyRows(foreignKeyRows);
|
|
16021
|
+
return catalog.toResponse(config.gatewayDatabase);
|
|
16022
|
+
}
|
|
16023
|
+
var fetchTableCatalog = fetchAthenaTableCatalog;
|
|
16024
|
+
|
|
16025
|
+
// src/tables/schema-handlers.ts
|
|
16026
|
+
var ATHENA_TABLE_SCHEMA_ROUTE = "/api/tables/schema";
|
|
16027
|
+
function json2(body, init) {
|
|
16028
|
+
const headers = new Headers(init?.headers);
|
|
16029
|
+
if (!headers.has("content-type")) {
|
|
16030
|
+
headers.set("content-type", "application/json; charset=utf-8");
|
|
16031
|
+
}
|
|
16032
|
+
return new Response(JSON.stringify(body), {
|
|
16033
|
+
status: init?.status ?? 200,
|
|
16034
|
+
headers
|
|
16035
|
+
});
|
|
16036
|
+
}
|
|
16037
|
+
async function handleAthenaTableSchemaPost(request2, options) {
|
|
16038
|
+
const payload = await request2.json().catch(() => null);
|
|
16039
|
+
let config = isAthenaTableSchemaConfig(
|
|
16040
|
+
payload?.config
|
|
16041
|
+
) ? payload.config : null;
|
|
16042
|
+
if (config && options?.resolveConfig) {
|
|
16043
|
+
config = await options.resolveConfig(config, request2);
|
|
16044
|
+
}
|
|
16045
|
+
if (!config || !isAthenaTableSchemaConfig(config)) {
|
|
16046
|
+
return json2(
|
|
16047
|
+
{
|
|
16048
|
+
error: "The Athena tables showcase config is invalid."
|
|
16049
|
+
},
|
|
16050
|
+
{ status: 400 }
|
|
16051
|
+
);
|
|
16052
|
+
}
|
|
16053
|
+
if (!hasAthenaTableSchemaCredentials(config)) {
|
|
16054
|
+
return json2(
|
|
16055
|
+
{
|
|
16056
|
+
error: "Gateway URL, API key, and database are required for schema introspection."
|
|
16057
|
+
},
|
|
16058
|
+
{ status: 400 }
|
|
16059
|
+
);
|
|
16060
|
+
}
|
|
16061
|
+
try {
|
|
16062
|
+
const response = await fetchAthenaTableCatalog(
|
|
16063
|
+
config,
|
|
16064
|
+
{
|
|
16065
|
+
client: options?.client
|
|
16066
|
+
}
|
|
16067
|
+
);
|
|
16068
|
+
return json2(response);
|
|
16069
|
+
} catch (error) {
|
|
16070
|
+
return json2(
|
|
16071
|
+
{
|
|
16072
|
+
error: error instanceof Error ? error.message : "Athena schema introspection failed."
|
|
16073
|
+
},
|
|
16074
|
+
{ status: 500 }
|
|
16075
|
+
);
|
|
16076
|
+
}
|
|
16077
|
+
}
|
|
16078
|
+
function createAthenaTableSchemaHandlers(options) {
|
|
16079
|
+
return {
|
|
16080
|
+
POST: (request2) => handleAthenaTableSchemaPost(request2, options)
|
|
16081
|
+
};
|
|
16082
|
+
}
|
|
16083
|
+
|
|
15489
16084
|
exports.ATHENA_AUTH_ADMIN_LIMITS = ATHENA_AUTH_ADMIN_LIMITS;
|
|
15490
16085
|
exports.ATHENA_AUTH_BASE_ERROR_CODES = ATHENA_AUTH_BASE_ERROR_CODES;
|
|
15491
16086
|
exports.ATHENA_AUTH_MAX_ADMIN_JSON_BYTES = ATHENA_AUTH_MAX_ADMIN_JSON_BYTES;
|
|
15492
16087
|
exports.ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH = ATHENA_AUTH_MAX_ADMIN_JSON_DEPTH;
|
|
15493
16088
|
exports.ATHENA_AUTH_MAX_TEMPLATE_VARIABLES = ATHENA_AUTH_MAX_TEMPLATE_VARIABLES;
|
|
15494
16089
|
exports.ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH = ATHENA_AUTH_MAX_TEMPLATE_VARIABLE_LENGTH;
|
|
16090
|
+
exports.ATHENA_TABLE_SCHEMA_ROUTE = ATHENA_TABLE_SCHEMA_ROUTE;
|
|
15495
16091
|
exports.AthenaBillingError = AthenaBillingError;
|
|
15496
16092
|
exports.AthenaChatError = AthenaChatError;
|
|
15497
16093
|
exports.AthenaConfigurationError = AthenaConfigurationError;
|
|
@@ -15520,6 +16116,7 @@ exports.buildAthenaReadQueryFindManyOrderBy = buildAthenaReadQueryFindManyOrderB
|
|
|
15520
16116
|
exports.buildAthenaReadQueryFindManySelect = buildAthenaReadQueryFindManySelect;
|
|
15521
16117
|
exports.buildAthenaReadQueryFindManyWhere = buildAthenaReadQueryFindManyWhere;
|
|
15522
16118
|
exports.buildAthenaReadQuerySelectString = buildAthenaReadQuerySelectString;
|
|
16119
|
+
exports.buildAthenaTableCatalogQueries = buildAthenaTableCatalogQueries;
|
|
15523
16120
|
exports.buildAthenaTableFindManyOrderBy = buildAthenaTableFindManyOrderBy;
|
|
15524
16121
|
exports.buildAthenaTableFindManySelect = buildAthenaTableFindManySelect;
|
|
15525
16122
|
exports.buildAthenaTableFindManyWhere = buildAthenaTableFindManyWhere;
|
|
@@ -15529,6 +16126,7 @@ exports.clampAthenaReadQueryTotalItems = clampAthenaReadQueryTotalItems;
|
|
|
15529
16126
|
exports.clampAthenaTableTotalItems = clampAthenaTableTotalItems;
|
|
15530
16127
|
exports.coerceInt = coerceInt;
|
|
15531
16128
|
exports.createAthenaStorageError = createAthenaStorageError;
|
|
16129
|
+
exports.createAthenaTableSchemaHandlers = createAthenaTableSchemaHandlers;
|
|
15532
16130
|
exports.createAuthReactEmailInput = createAuthReactEmailInput;
|
|
15533
16131
|
exports.createBillingModule = createBillingModule;
|
|
15534
16132
|
exports.createClient = createClient;
|
|
@@ -15549,6 +16147,8 @@ exports.ensureGeneratorConfigFile = ensureGeneratorConfigFile;
|
|
|
15549
16147
|
exports.enumeration = enumeration;
|
|
15550
16148
|
exports.executeAthenaReadQuery = executeAthenaReadQuery;
|
|
15551
16149
|
exports.executeAthenaTableQuery = executeAthenaTableQuery;
|
|
16150
|
+
exports.fetchAthenaTableCatalog = fetchAthenaTableCatalog;
|
|
16151
|
+
exports.fetchTableCatalog = fetchTableCatalog;
|
|
15552
16152
|
exports.filterIntrospectionSnapshot = filterIntrospectionSnapshot;
|
|
15553
16153
|
exports.findGeneratorConfigPath = findGeneratorConfigPath;
|
|
15554
16154
|
exports.flattenAthenaReadQueryRows = flattenAthenaReadQueryRows;
|
|
@@ -15556,8 +16156,11 @@ exports.flattenAthenaRows = flattenAthenaRows;
|
|
|
15556
16156
|
exports.generateArtifactsFromSnapshot = generateArtifactsFromSnapshot;
|
|
15557
16157
|
exports.generatorEnv = generatorEnv;
|
|
15558
16158
|
exports.getAthenaDebugAst = getAthenaDebugAst;
|
|
16159
|
+
exports.handleAthenaTableSchemaPost = handleAthenaTableSchemaPost;
|
|
16160
|
+
exports.hasAthenaTableSchemaCredentials = hasAthenaTableSchemaCredentials;
|
|
15559
16161
|
exports.identifier = identifier;
|
|
15560
16162
|
exports.isAthenaGatewayError = isAthenaGatewayError;
|
|
16163
|
+
exports.isAthenaTableSchemaConfig = isAthenaTableSchemaConfig;
|
|
15561
16164
|
exports.isOk = isOk;
|
|
15562
16165
|
exports.json = json;
|
|
15563
16166
|
exports.loadGeneratorConfig = loadGeneratorConfig;
|
|
@@ -15571,12 +16174,14 @@ exports.normalizeGeneratorConfig = normalizeGeneratorConfig;
|
|
|
15571
16174
|
exports.normalizeSchemaSelection = normalizeSchemaSelection;
|
|
15572
16175
|
exports.normalizeTableSelection = normalizeTableSelection;
|
|
15573
16176
|
exports.number = number;
|
|
16177
|
+
exports.parseAthenaTableSchemaScope = parseAthenaTableSchemaScope;
|
|
15574
16178
|
exports.parseBooleanFlag = parseBooleanFlag2;
|
|
15575
16179
|
exports.patchSchemasInConfigSource = patchSchemasInConfigSource;
|
|
15576
16180
|
exports.renderAthenaReactEmail = renderAthenaReactEmail;
|
|
15577
16181
|
exports.renderGeneratorConfigFile = renderGeneratorConfigFile;
|
|
15578
16182
|
exports.requireAffected = requireAffected;
|
|
15579
16183
|
exports.requireSuccess = requireSuccess;
|
|
16184
|
+
exports.resolveAthenaReadQueryPageFetch = resolveAthenaReadQueryPageFetch;
|
|
15580
16185
|
exports.resolveGeneratorProvider = resolveGeneratorProvider;
|
|
15581
16186
|
exports.resolvePostgresColumnType = resolvePostgresColumnType;
|
|
15582
16187
|
exports.resolveProviderSchemas = resolveProviderSchemas;
|