@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.js
CHANGED
|
@@ -2007,7 +2007,7 @@ function buildAthenaGatewayUrl(baseUrl, path) {
|
|
|
2007
2007
|
|
|
2008
2008
|
// package.json
|
|
2009
2009
|
var package_default = {
|
|
2010
|
-
version: "3.
|
|
2010
|
+
version: "3.3.0"
|
|
2011
2011
|
};
|
|
2012
2012
|
|
|
2013
2013
|
// src/sdk-version.ts
|
|
@@ -4767,6 +4767,14 @@ function createAuthModule(config = {}, runtimeOptions = {}) {
|
|
|
4767
4767
|
changeEmailVerify: (input, options) => getWithQuery("/change-email/verify", input, options),
|
|
4768
4768
|
deleteUserVerify: (input, options) => getWithQuery("/delete-user/verify", input, options),
|
|
4769
4769
|
changePassword: (input, options) => postGeneric("/change-password", input, options),
|
|
4770
|
+
// Better Auth UI flat method aliases (also nested under session/account/social/user).
|
|
4771
|
+
listSessions: (input, options) => getGeneric("/list-sessions", input, options),
|
|
4772
|
+
revokeSession: sessionRevokeBinding,
|
|
4773
|
+
revokeOtherSessions,
|
|
4774
|
+
listAccounts: (input, options) => getGeneric("/list-accounts", input, options),
|
|
4775
|
+
unlinkAccount: (input, options) => postGeneric("/unlink-account", input, options),
|
|
4776
|
+
linkSocial: (input, options) => postGeneric("/link-social", input, options),
|
|
4777
|
+
updateUser: (input, options) => postGeneric("/update-user", input, options),
|
|
4770
4778
|
user: {
|
|
4771
4779
|
update: (input, options) => postGeneric("/update-user", input, options),
|
|
4772
4780
|
delete: (input, options) => postGeneric("/delete-user", input, options),
|
|
@@ -10576,6 +10584,82 @@ function mergeAthenaRequestContexts(base, override) {
|
|
|
10576
10584
|
};
|
|
10577
10585
|
}
|
|
10578
10586
|
|
|
10587
|
+
// src/diagnostics.ts
|
|
10588
|
+
function readProcessEnv2() {
|
|
10589
|
+
try {
|
|
10590
|
+
return globalThis.process?.env ?? {};
|
|
10591
|
+
} catch {
|
|
10592
|
+
return {};
|
|
10593
|
+
}
|
|
10594
|
+
}
|
|
10595
|
+
function isTruthyEnv(value) {
|
|
10596
|
+
if (!value) return false;
|
|
10597
|
+
const normalized = value.trim().toLowerCase();
|
|
10598
|
+
return normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on";
|
|
10599
|
+
}
|
|
10600
|
+
function isQuietAthenaDiagnosticsEnvironment(env = readProcessEnv2()) {
|
|
10601
|
+
const nodeEnv = env.NODE_ENV?.trim().toLowerCase();
|
|
10602
|
+
if (nodeEnv === "production") {
|
|
10603
|
+
return true;
|
|
10604
|
+
}
|
|
10605
|
+
if (isTruthyEnv(env.OPENNEXT_BUILD)) {
|
|
10606
|
+
return true;
|
|
10607
|
+
}
|
|
10608
|
+
const nextPhase = env.NEXT_PHASE?.trim();
|
|
10609
|
+
if (nextPhase === "phase-production-build") {
|
|
10610
|
+
return true;
|
|
10611
|
+
}
|
|
10612
|
+
if (isTruthyEnv(env.CI) && nodeEnv !== "test") {
|
|
10613
|
+
if (nodeEnv === "production" || isTruthyEnv(env.OPENNEXT_BUILD)) {
|
|
10614
|
+
return true;
|
|
10615
|
+
}
|
|
10616
|
+
}
|
|
10617
|
+
return false;
|
|
10618
|
+
}
|
|
10619
|
+
function resolveBooleanFlag(explicit, mode, quiet) {
|
|
10620
|
+
if (typeof explicit === "boolean") {
|
|
10621
|
+
return explicit;
|
|
10622
|
+
}
|
|
10623
|
+
if (mode === true) {
|
|
10624
|
+
return true;
|
|
10625
|
+
}
|
|
10626
|
+
if (mode === false) {
|
|
10627
|
+
return false;
|
|
10628
|
+
}
|
|
10629
|
+
if (mode === "auto") {
|
|
10630
|
+
return false;
|
|
10631
|
+
}
|
|
10632
|
+
return false;
|
|
10633
|
+
}
|
|
10634
|
+
function resolveAthenaClientDiagnostics(input) {
|
|
10635
|
+
const env = input.env ?? readProcessEnv2();
|
|
10636
|
+
const quiet = isQuietAthenaDiagnosticsEnvironment(env);
|
|
10637
|
+
const mode = input.diagnostics;
|
|
10638
|
+
const effectiveMode = mode === "auto" && quiet ? false : mode;
|
|
10639
|
+
const debugAst = resolveBooleanFlag(input.debugAst, effectiveMode);
|
|
10640
|
+
const findManyAst = resolveBooleanFlag(input.findManyAst, effectiveMode);
|
|
10641
|
+
let traceQueries;
|
|
10642
|
+
if (input.traceQueries !== void 0) {
|
|
10643
|
+
if (typeof input.traceQueries === "boolean") {
|
|
10644
|
+
traceQueries = input.traceQueries;
|
|
10645
|
+
} else if (effectiveMode === false || mode === "auto" && quiet) {
|
|
10646
|
+
const enabled = input.traceQueries.enabled;
|
|
10647
|
+
traceQueries = typeof enabled === "boolean" ? enabled ? input.traceQueries : false : false;
|
|
10648
|
+
} else {
|
|
10649
|
+
traceQueries = input.traceQueries;
|
|
10650
|
+
}
|
|
10651
|
+
} else if (effectiveMode === true) {
|
|
10652
|
+
traceQueries = true;
|
|
10653
|
+
} else {
|
|
10654
|
+
traceQueries = false;
|
|
10655
|
+
}
|
|
10656
|
+
return {
|
|
10657
|
+
debugAst,
|
|
10658
|
+
findManyAst,
|
|
10659
|
+
traceQueries
|
|
10660
|
+
};
|
|
10661
|
+
}
|
|
10662
|
+
|
|
10579
10663
|
// src/v3-client.ts
|
|
10580
10664
|
var ENV_URL_KEYS = ["ATHENA_URL", "NEXT_PUBLIC_ATHENA_URL"];
|
|
10581
10665
|
var ENV_DB_URL_KEYS = ["ATHENA_DB_URL", "ATHENA_GATEWAY_URL", "NEXT_PUBLIC_ATHENA_DB_API_URL"];
|
|
@@ -10584,7 +10668,13 @@ var ENV_CHAT_URL_KEYS = ["ATHENA_CHAT_URL", "NEXT_PUBLIC_ATHENA_CHAT_URL"];
|
|
|
10584
10668
|
var ENV_CHAT_WS_URL_KEYS = ["ATHENA_CHAT_WS_URL", "NEXT_PUBLIC_ATHENA_CHAT_WS_URL"];
|
|
10585
10669
|
var ENV_STORAGE_URL_KEYS = ["ATHENA_STORAGE_URL", "NEXT_PUBLIC_ATHENA_STORAGE_URL"];
|
|
10586
10670
|
var ENV_KEY_KEYS = ["ATHENA_API_KEY", "NEXT_PUBLIC_ATHENA_API_KEY", "ATHENA_GATEWAY_API_KEY", "X_API_KEY"];
|
|
10587
|
-
var ENV_CLIENT_KEYS = [
|
|
10671
|
+
var ENV_CLIENT_KEYS = [
|
|
10672
|
+
"ATHENA_CLIENT",
|
|
10673
|
+
"ATHENA_GATEWAY_CLIENT",
|
|
10674
|
+
"ATHENA_GENERATOR_CLIENT",
|
|
10675
|
+
"NEXT_PUBLIC_ATHENA_CLIENT",
|
|
10676
|
+
"NEXT_PUBLIC_ATHENA_GATEWAY_CLIENT"
|
|
10677
|
+
];
|
|
10588
10678
|
var MISSING_DB_SENTINEL = "https://athena.invalid/db";
|
|
10589
10679
|
function readFirstEnv(env, keys) {
|
|
10590
10680
|
for (const key of keys) {
|
|
@@ -10659,6 +10749,13 @@ function createInternalConfig(core) {
|
|
|
10659
10749
|
const { config, urls } = core;
|
|
10660
10750
|
const { url: _authUrl, ...authOptions } = config.auth ?? {};
|
|
10661
10751
|
const { url: _storageUrl, directUpload, ...storageOptions } = config.storage ?? {};
|
|
10752
|
+
const diagnostics = resolveAthenaClientDiagnostics({
|
|
10753
|
+
diagnostics: config.diagnostics,
|
|
10754
|
+
debugAst: config.debugAst,
|
|
10755
|
+
findManyAst: config.findManyAst,
|
|
10756
|
+
traceQueries: config.traceQueries,
|
|
10757
|
+
env: config.env
|
|
10758
|
+
});
|
|
10662
10759
|
return {
|
|
10663
10760
|
baseUrl: urls.db ?? MISSING_DB_SENTINEL,
|
|
10664
10761
|
apiKey: core.key,
|
|
@@ -10675,9 +10772,9 @@ function createInternalConfig(core) {
|
|
|
10675
10772
|
models: config.models,
|
|
10676
10773
|
behavior: {
|
|
10677
10774
|
retryReads: config.retryReads,
|
|
10678
|
-
traceQueries:
|
|
10679
|
-
debugAst:
|
|
10680
|
-
findManyAst:
|
|
10775
|
+
traceQueries: diagnostics.traceQueries,
|
|
10776
|
+
debugAst: diagnostics.debugAst,
|
|
10777
|
+
findManyAst: diagnostics.findManyAst
|
|
10681
10778
|
},
|
|
10682
10779
|
storage: {
|
|
10683
10780
|
...storageOptions,
|
|
@@ -10751,11 +10848,30 @@ function createClientView(core, viewContext) {
|
|
|
10751
10848
|
return resolved.verifyConnection(options);
|
|
10752
10849
|
},
|
|
10753
10850
|
withContext(context) {
|
|
10851
|
+
warnIfEmptyRequestContext(context);
|
|
10754
10852
|
return createClientView(core, mergeAthenaRequestContexts(viewContext, context));
|
|
10755
10853
|
}
|
|
10756
10854
|
};
|
|
10757
10855
|
return Object.freeze(client);
|
|
10758
10856
|
}
|
|
10857
|
+
function isEmptyAthenaRequestContext(context) {
|
|
10858
|
+
if (!context) return true;
|
|
10859
|
+
const hasHeaders = context.headers != null && Object.keys(context.headers).length > 0;
|
|
10860
|
+
return context.userId == null && context.organizationId == null && !normalizeOptionalContextString(context.cookie) && !normalizeOptionalContextString(context.bearerToken) && !normalizeOptionalContextString(context.sessionToken) && !context.forceNoCache && !hasHeaders;
|
|
10861
|
+
}
|
|
10862
|
+
function normalizeOptionalContextString(value) {
|
|
10863
|
+
const trimmed = value?.trim();
|
|
10864
|
+
return trimmed || void 0;
|
|
10865
|
+
}
|
|
10866
|
+
function warnIfEmptyRequestContext(context) {
|
|
10867
|
+
if (!isEmptyAthenaRequestContext(context)) return;
|
|
10868
|
+
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") {
|
|
10869
|
+
return;
|
|
10870
|
+
}
|
|
10871
|
+
console.warn(
|
|
10872
|
+
"[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 })."
|
|
10873
|
+
);
|
|
10874
|
+
}
|
|
10759
10875
|
function createClient(config) {
|
|
10760
10876
|
return createClientView(resolveCore(config));
|
|
10761
10877
|
}
|
|
@@ -10994,6 +11110,27 @@ function resolveTotalItemsFromPage({
|
|
|
10994
11110
|
}
|
|
10995
11111
|
return clampAthenaReadQueryTotalItems(exactCount, limit);
|
|
10996
11112
|
}
|
|
11113
|
+
function resolveAthenaReadQueryPageFetch({
|
|
11114
|
+
page,
|
|
11115
|
+
pageSize,
|
|
11116
|
+
limit
|
|
11117
|
+
}) {
|
|
11118
|
+
const safePage = Math.max(1, Math.trunc(page) || 1);
|
|
11119
|
+
const safePageSize = Math.max(1, Math.trunc(pageSize) || 1);
|
|
11120
|
+
if (!limit || limit < 1) {
|
|
11121
|
+
return { page: safePage, pageSize: safePageSize, shouldFetch: true };
|
|
11122
|
+
}
|
|
11123
|
+
const totalCap = Math.trunc(limit);
|
|
11124
|
+
const offset = (safePage - 1) * safePageSize;
|
|
11125
|
+
if (offset >= totalCap) {
|
|
11126
|
+
return { page: safePage, pageSize: safePageSize, shouldFetch: false };
|
|
11127
|
+
}
|
|
11128
|
+
return {
|
|
11129
|
+
page: safePage,
|
|
11130
|
+
pageSize: Math.min(safePageSize, totalCap - offset),
|
|
11131
|
+
shouldFetch: true
|
|
11132
|
+
};
|
|
11133
|
+
}
|
|
10997
11134
|
async function executeAthenaReadQuery({
|
|
10998
11135
|
client,
|
|
10999
11136
|
page,
|
|
@@ -11012,15 +11149,29 @@ async function executeAthenaReadQuery({
|
|
|
11012
11149
|
count: "exact",
|
|
11013
11150
|
head: true
|
|
11014
11151
|
});
|
|
11152
|
+
const pageFetch = resolveAthenaReadQueryPageFetch({
|
|
11153
|
+
limit: query.limit,
|
|
11154
|
+
page,
|
|
11155
|
+
pageSize
|
|
11156
|
+
});
|
|
11157
|
+
if (!pageFetch.shouldFetch) {
|
|
11158
|
+
return {
|
|
11159
|
+
rows: [],
|
|
11160
|
+
totalItems: resolveTotalItemsFromPage({
|
|
11161
|
+
countCandidates: [countResult.count],
|
|
11162
|
+
limit: query.limit,
|
|
11163
|
+
page: pageFetch.page,
|
|
11164
|
+
pageSize,
|
|
11165
|
+
rowCount: 0
|
|
11166
|
+
})
|
|
11167
|
+
};
|
|
11168
|
+
}
|
|
11015
11169
|
if ((query.mode ?? "findMany") === "select") {
|
|
11016
|
-
const selectBuilder =
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
query.orderBy
|
|
11020
|
-
),
|
|
11021
|
-
query.limit
|
|
11170
|
+
const selectBuilder = applyAthenaReadQuerySelectOrder(
|
|
11171
|
+
applyAthenaReadQueryFilters(baseBuilder, query.filters),
|
|
11172
|
+
query.orderBy
|
|
11022
11173
|
);
|
|
11023
|
-
const result2 = await selectBuilder.currentPage(page).pageSize(pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
|
|
11174
|
+
const result2 = await selectBuilder.currentPage(pageFetch.page).pageSize(pageFetch.pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
|
|
11024
11175
|
count: "exact"
|
|
11025
11176
|
});
|
|
11026
11177
|
const rows2 = flattenAthenaReadQueryRows(
|
|
@@ -11034,7 +11185,7 @@ async function executeAthenaReadQuery({
|
|
|
11034
11185
|
totalItems: resolveTotalItemsFromPage({
|
|
11035
11186
|
countCandidates: [countResult.count, result2.count],
|
|
11036
11187
|
limit: query.limit,
|
|
11037
|
-
page,
|
|
11188
|
+
page: pageFetch.page,
|
|
11038
11189
|
pageSize,
|
|
11039
11190
|
rowCount: rows2.length
|
|
11040
11191
|
})
|
|
@@ -11042,12 +11193,11 @@ async function executeAthenaReadQuery({
|
|
|
11042
11193
|
}
|
|
11043
11194
|
const findManyOrderBy = buildAthenaReadQueryFindManyOrderBy(query.orderBy);
|
|
11044
11195
|
const findManyOptions = {
|
|
11045
|
-
...query.limit ? { limit: query.limit } : {},
|
|
11046
11196
|
...findManyOrderBy ? { orderBy: findManyOrderBy } : {},
|
|
11047
11197
|
select: buildAthenaReadQueryFindManySelect(query.columns),
|
|
11048
11198
|
...query.filters?.length ? { where: buildAthenaReadQueryFindManyWhere(query.filters) } : {}
|
|
11049
11199
|
};
|
|
11050
|
-
const result = await baseBuilder.currentPage(page).pageSize(pageSize).findMany(findManyOptions);
|
|
11200
|
+
const result = await baseBuilder.currentPage(pageFetch.page).pageSize(pageFetch.pageSize).findMany(findManyOptions);
|
|
11051
11201
|
const rows = flattenAthenaReadQueryRows(
|
|
11052
11202
|
Array.isArray(result.data) ? result.data : [],
|
|
11053
11203
|
query.columns,
|
|
@@ -11059,7 +11209,7 @@ async function executeAthenaReadQuery({
|
|
|
11059
11209
|
totalItems: resolveTotalItemsFromPage({
|
|
11060
11210
|
countCandidates: [countResult.count, result.count],
|
|
11061
11211
|
limit: query.limit,
|
|
11062
|
-
page,
|
|
11212
|
+
page: pageFetch.page,
|
|
11063
11213
|
pageSize,
|
|
11064
11214
|
rowCount: rows.length
|
|
11065
11215
|
})
|
|
@@ -12060,6 +12210,13 @@ var GATEWAY_API_KEY_ENV_KEYS = [
|
|
|
12060
12210
|
"ATHENA_GATEWAY_API_KEY",
|
|
12061
12211
|
"ATHENA_GENERATOR_API_KEY"
|
|
12062
12212
|
];
|
|
12213
|
+
var GATEWAY_CLIENT_ENV_KEYS = [
|
|
12214
|
+
"ATHENA_CLIENT",
|
|
12215
|
+
"ATHENA_GATEWAY_CLIENT",
|
|
12216
|
+
"ATHENA_GENERATOR_CLIENT",
|
|
12217
|
+
"NEXT_PUBLIC_ATHENA_CLIENT",
|
|
12218
|
+
"NEXT_PUBLIC_ATHENA_GATEWAY_CLIENT"
|
|
12219
|
+
];
|
|
12063
12220
|
var GENERATOR_SCHEMA_ENV_KEYS = ["ATHENA_GENERATOR_SCHEMAS"];
|
|
12064
12221
|
var OUTPUT_FORMAT_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_FORMAT"];
|
|
12065
12222
|
var OUTPUT_PRESET_ENV_KEYS = ["ATHENA_GENERATOR_OUTPUT_PRESET"];
|
|
@@ -12360,11 +12517,13 @@ function normalizeProviderConfig(provider) {
|
|
|
12360
12517
|
GATEWAY_API_KEY_ENV_KEYS
|
|
12361
12518
|
);
|
|
12362
12519
|
const database = normalizeOptionalString(provider.database, POSTGRES_DATABASE_ENV_KEYS) ?? "postgres";
|
|
12520
|
+
const client = normalizeOptionalString(provider.client, GATEWAY_CLIENT_ENV_KEYS);
|
|
12363
12521
|
return {
|
|
12364
12522
|
...provider,
|
|
12365
12523
|
gatewayUrl,
|
|
12366
12524
|
apiKey,
|
|
12367
12525
|
database,
|
|
12526
|
+
...client ? { client } : {},
|
|
12368
12527
|
schemas: normalizeSchemaSelection(provider.schemas)
|
|
12369
12528
|
};
|
|
12370
12529
|
}
|
|
@@ -12558,6 +12717,7 @@ function buildEnvironmentProviderConfig() {
|
|
|
12558
12717
|
const apiKey = resolveFallbackValue(GATEWAY_API_KEY_ENV_KEYS);
|
|
12559
12718
|
if (gatewayUrl && apiKey) {
|
|
12560
12719
|
const backend = resolveOptionalOneOf(GATEWAY_BACKEND_ENV_KEYS, BACKEND_TYPE_VALUES);
|
|
12720
|
+
const client = resolveFallbackValue(GATEWAY_CLIENT_ENV_KEYS);
|
|
12561
12721
|
return {
|
|
12562
12722
|
kind: "postgres",
|
|
12563
12723
|
mode: "gateway",
|
|
@@ -12565,7 +12725,8 @@ function buildEnvironmentProviderConfig() {
|
|
|
12565
12725
|
apiKey,
|
|
12566
12726
|
database: normalizeOptionalString(void 0, POSTGRES_DATABASE_ENV_KEYS),
|
|
12567
12727
|
schemas: normalizeSchemaSelection(resolveFallbackValue(GENERATOR_SCHEMA_ENV_KEYS)),
|
|
12568
|
-
backend
|
|
12728
|
+
backend,
|
|
12729
|
+
...client ? { client } : {}
|
|
12569
12730
|
};
|
|
12570
12731
|
}
|
|
12571
12732
|
return void 0;
|
|
@@ -12709,6 +12870,8 @@ async function discoverGatewaySchemas(config) {
|
|
|
12709
12870
|
const client = createClient({
|
|
12710
12871
|
db: { url: config.gatewayUrl },
|
|
12711
12872
|
key: config.apiKey,
|
|
12873
|
+
client: config.client,
|
|
12874
|
+
env: typeof process !== "undefined" ? process.env : void 0,
|
|
12712
12875
|
backend: {
|
|
12713
12876
|
type: config.backend ?? "postgresql"
|
|
12714
12877
|
}
|
|
@@ -12795,6 +12958,7 @@ function buildGatewayProviderBlock(schemas) {
|
|
|
12795
12958
|
mode: "gateway",
|
|
12796
12959
|
gatewayUrl: generatorEnv("ATHENA_URL"),
|
|
12797
12960
|
apiKey: generatorEnv("ATHENA_API_KEY"),
|
|
12961
|
+
client: generatorEnv("ATHENA_CLIENT", { optional: true }),
|
|
12798
12962
|
database: generatorEnv("ATHENA_GENERATOR_DB", { default: "postgres" }),
|
|
12799
12963
|
schemas: ${formatStringArray(schemas, " ")},
|
|
12800
12964
|
}`;
|
|
@@ -13818,7 +13982,7 @@ function renderModelArtifact(descriptor, config) {
|
|
|
13818
13982
|
const relationsAssignment = config.features.emitRelations && relationEntries.length > 0 ? `
|
|
13819
13983
|
Object.assign(${descriptor.tableConstName}.meta, {
|
|
13820
13984
|
relations: {
|
|
13821
|
-
${relationEntries.map(([
|
|
13985
|
+
${relationEntries.map(([relationKey3, relationValue]) => ` ${renderObjectKey(relationKey3)}: ${renderRelationLiteral(relationValue)}`).join(",\n")}
|
|
13822
13986
|
}
|
|
13823
13987
|
})
|
|
13824
13988
|
` : "";
|
|
@@ -13895,7 +14059,7 @@ function renderModelArtifact2(databaseName, descriptor, config) {
|
|
|
13895
14059
|
const relationEntries = Object.entries(descriptor.table.relations);
|
|
13896
14060
|
const relationBlock = config.features.emitRelations && relationEntries.length > 0 ? `,
|
|
13897
14061
|
relations: {
|
|
13898
|
-
${relationEntries.map(([
|
|
14062
|
+
${relationEntries.map(([relationKey3, relationValue]) => ` ${renderObjectKey(relationKey3)}: ${renderRelationLiteral(relationValue)}`).join(",\n")}
|
|
13899
14063
|
}` : "";
|
|
13900
14064
|
const content = `import { defineModel } from '@xylex-group/athena'
|
|
13901
14065
|
|
|
@@ -14004,6 +14168,11 @@ var AthenaGatewayPostgresIntrospectionProvider = class {
|
|
|
14004
14168
|
this.client = createClient({
|
|
14005
14169
|
db: { url: this.config.gatewayUrl },
|
|
14006
14170
|
key: this.config.apiKey,
|
|
14171
|
+
// Multi-tenant gateways reject DEFAULT_CLIENT; prefer explicit config.
|
|
14172
|
+
// Also pass process.env so ATHENA_CLIENT / ATHENA_GATEWAY_CLIENT still resolve
|
|
14173
|
+
// when the field was not normalized into provider config.
|
|
14174
|
+
client: this.config.client,
|
|
14175
|
+
env: typeof process !== "undefined" ? process.env : void 0,
|
|
14007
14176
|
backend: {
|
|
14008
14177
|
type: this.config.backend ?? "postgresql"
|
|
14009
14178
|
}
|
|
@@ -15484,6 +15653,432 @@ async function ensureActiveOrganization(options) {
|
|
|
15484
15653
|
}
|
|
15485
15654
|
}
|
|
15486
15655
|
|
|
15487
|
-
|
|
15656
|
+
// src/tables/catalog.ts
|
|
15657
|
+
var POSTGRES_CATALOG_SQL2 = {
|
|
15658
|
+
columns: `
|
|
15659
|
+
SELECT
|
|
15660
|
+
n.nspname AS schema_name,
|
|
15661
|
+
c.relname AS table_name,
|
|
15662
|
+
a.attname AS column_name,
|
|
15663
|
+
format_type(a.atttypid, a.atttypmod) AS data_type,
|
|
15664
|
+
NOT a.attnotnull AS is_nullable
|
|
15665
|
+
FROM pg_attribute a
|
|
15666
|
+
JOIN pg_class c ON c.oid = a.attrelid
|
|
15667
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
15668
|
+
WHERE c.relkind IN ('r', 'p')
|
|
15669
|
+
AND a.attnum > 0
|
|
15670
|
+
AND NOT a.attisdropped
|
|
15671
|
+
AND n.nspname = ANY($1::text[])
|
|
15672
|
+
ORDER BY n.nspname, c.relname, a.attnum;
|
|
15673
|
+
`,
|
|
15674
|
+
foreignKeys: `
|
|
15675
|
+
SELECT
|
|
15676
|
+
sn.nspname AS source_schema,
|
|
15677
|
+
sc.relname AS source_table,
|
|
15678
|
+
con.conname AS constraint_name,
|
|
15679
|
+
ARRAY_AGG(sa.attname ORDER BY cols.ordinality) AS source_columns,
|
|
15680
|
+
tn.nspname AS target_schema,
|
|
15681
|
+
tc.relname AS target_table,
|
|
15682
|
+
ARRAY_AGG(ta.attname ORDER BY cols.ordinality) AS target_columns,
|
|
15683
|
+
EXISTS (
|
|
15684
|
+
SELECT 1
|
|
15685
|
+
FROM pg_constraint uq
|
|
15686
|
+
WHERE uq.conrelid = con.conrelid
|
|
15687
|
+
AND uq.contype IN ('p', 'u')
|
|
15688
|
+
AND uq.conkey = con.conkey
|
|
15689
|
+
) AS source_is_unique
|
|
15690
|
+
FROM pg_constraint con
|
|
15691
|
+
JOIN pg_class sc ON sc.oid = con.conrelid
|
|
15692
|
+
JOIN pg_namespace sn ON sn.oid = sc.relnamespace
|
|
15693
|
+
JOIN pg_class tc ON tc.oid = con.confrelid
|
|
15694
|
+
JOIN pg_namespace tn ON tn.oid = tc.relnamespace
|
|
15695
|
+
JOIN unnest(con.conkey, con.confkey) WITH ORDINALITY AS cols(source_attnum, target_attnum, ordinality) ON TRUE
|
|
15696
|
+
JOIN pg_attribute sa ON sa.attrelid = con.conrelid AND sa.attnum = cols.source_attnum
|
|
15697
|
+
JOIN pg_attribute ta ON ta.attrelid = con.confrelid AND ta.attnum = cols.target_attnum
|
|
15698
|
+
WHERE con.contype = 'f'
|
|
15699
|
+
AND sn.nspname = ANY($1::text[])
|
|
15700
|
+
AND tn.nspname = ANY($1::text[])
|
|
15701
|
+
GROUP BY
|
|
15702
|
+
sn.nspname,
|
|
15703
|
+
sc.relname,
|
|
15704
|
+
con.conname,
|
|
15705
|
+
tn.nspname,
|
|
15706
|
+
tc.relname,
|
|
15707
|
+
con.conkey,
|
|
15708
|
+
con.conrelid
|
|
15709
|
+
ORDER BY sn.nspname, sc.relname, con.conname;
|
|
15710
|
+
`,
|
|
15711
|
+
primaryKeys: `
|
|
15712
|
+
SELECT
|
|
15713
|
+
n.nspname AS schema_name,
|
|
15714
|
+
c.relname AS table_name,
|
|
15715
|
+
ARRAY_AGG(a.attname ORDER BY ck.ordinality) AS columns
|
|
15716
|
+
FROM pg_constraint con
|
|
15717
|
+
JOIN pg_class c ON c.oid = con.conrelid
|
|
15718
|
+
JOIN pg_namespace n ON n.oid = c.relnamespace
|
|
15719
|
+
JOIN unnest(con.conkey) WITH ORDINALITY AS ck(attnum, ordinality) ON TRUE
|
|
15720
|
+
JOIN pg_attribute a ON a.attrelid = c.oid AND a.attnum = ck.attnum
|
|
15721
|
+
WHERE con.contype = 'p'
|
|
15722
|
+
AND n.nspname = ANY($1::text[])
|
|
15723
|
+
GROUP BY n.nspname, c.relname
|
|
15724
|
+
ORDER BY n.nspname, c.relname;
|
|
15725
|
+
`
|
|
15726
|
+
};
|
|
15727
|
+
function parseAthenaTableSchemaScope(value) {
|
|
15728
|
+
return value.split(",").map((entry) => entry.trim()).filter(
|
|
15729
|
+
(entry, index, values) => entry.length > 0 && values.indexOf(entry) === index
|
|
15730
|
+
);
|
|
15731
|
+
}
|
|
15732
|
+
function escapeSqlLiteral2(value) {
|
|
15733
|
+
return value.replace(/'/g, "''");
|
|
15734
|
+
}
|
|
15735
|
+
function buildSchemaArrayLiteral2(schemas) {
|
|
15736
|
+
const literals = schemas.map((schema) => `'${escapeSqlLiteral2(schema)}'`).join(", ");
|
|
15737
|
+
return `ARRAY[${literals}]`;
|
|
15738
|
+
}
|
|
15739
|
+
function inlineSchemaLiteral2(sql, schemas) {
|
|
15740
|
+
return sql.replace(
|
|
15741
|
+
/\$1::text\[\]/g,
|
|
15742
|
+
`${buildSchemaArrayLiteral2(schemas)}::text[]`
|
|
15743
|
+
);
|
|
15744
|
+
}
|
|
15745
|
+
function buildAthenaTableCatalogQueries(schemas) {
|
|
15746
|
+
return {
|
|
15747
|
+
columns: inlineSchemaLiteral2(POSTGRES_CATALOG_SQL2.columns, schemas),
|
|
15748
|
+
foreignKeys: inlineSchemaLiteral2(POSTGRES_CATALOG_SQL2.foreignKeys, schemas),
|
|
15749
|
+
primaryKeys: inlineSchemaLiteral2(POSTGRES_CATALOG_SQL2.primaryKeys, schemas)
|
|
15750
|
+
};
|
|
15751
|
+
}
|
|
15752
|
+
function tableKey2(schema, table2) {
|
|
15753
|
+
return `${schema}.${table2}`;
|
|
15754
|
+
}
|
|
15755
|
+
function relationKey2(...parts) {
|
|
15756
|
+
const base = parts.join("_").replace(/[^A-Za-z0-9_]+/g, "_").replace(/^_+|_+$/g, "");
|
|
15757
|
+
return base.length > 0 ? base : "relation";
|
|
15758
|
+
}
|
|
15759
|
+
function parsePostgresArrayLiteral2(text) {
|
|
15760
|
+
const body = text.slice(1, -1).trim();
|
|
15761
|
+
if (!body) {
|
|
15762
|
+
return [];
|
|
15763
|
+
}
|
|
15764
|
+
const values = [];
|
|
15765
|
+
let current = "";
|
|
15766
|
+
let inQuotes = false;
|
|
15767
|
+
let escaped = false;
|
|
15768
|
+
for (const char of body) {
|
|
15769
|
+
if (escaped) {
|
|
15770
|
+
current += char;
|
|
15771
|
+
escaped = false;
|
|
15772
|
+
continue;
|
|
15773
|
+
}
|
|
15774
|
+
if (char === "\\") {
|
|
15775
|
+
escaped = true;
|
|
15776
|
+
continue;
|
|
15777
|
+
}
|
|
15778
|
+
if (char === '"') {
|
|
15779
|
+
inQuotes = !inQuotes;
|
|
15780
|
+
continue;
|
|
15781
|
+
}
|
|
15782
|
+
if (char === "," && !inQuotes) {
|
|
15783
|
+
values.push(current);
|
|
15784
|
+
current = "";
|
|
15785
|
+
continue;
|
|
15786
|
+
}
|
|
15787
|
+
current += char;
|
|
15788
|
+
}
|
|
15789
|
+
values.push(current);
|
|
15790
|
+
return values.map((value) => value.trim()).filter((value) => value.length > 0);
|
|
15791
|
+
}
|
|
15792
|
+
function coerceStringArray2(value) {
|
|
15793
|
+
if (value == null) {
|
|
15794
|
+
return [];
|
|
15795
|
+
}
|
|
15796
|
+
if (Array.isArray(value)) {
|
|
15797
|
+
return value.map((entry) => entry.trim()).filter(Boolean);
|
|
15798
|
+
}
|
|
15799
|
+
if (typeof value !== "string") {
|
|
15800
|
+
return [];
|
|
15801
|
+
}
|
|
15802
|
+
const trimmedValue = value.trim();
|
|
15803
|
+
if (!trimmedValue) {
|
|
15804
|
+
return [];
|
|
15805
|
+
}
|
|
15806
|
+
if (trimmedValue.startsWith("{") && trimmedValue.endsWith("}")) {
|
|
15807
|
+
return parsePostgresArrayLiteral2(trimmedValue);
|
|
15808
|
+
}
|
|
15809
|
+
return trimmedValue.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
15810
|
+
}
|
|
15811
|
+
function createTableCatalog() {
|
|
15812
|
+
const tables = /* @__PURE__ */ new Map();
|
|
15813
|
+
const ensureTable = (schema, name) => {
|
|
15814
|
+
const id = tableKey2(schema, name);
|
|
15815
|
+
const existingTable = tables.get(id);
|
|
15816
|
+
if (existingTable) {
|
|
15817
|
+
return existingTable;
|
|
15818
|
+
}
|
|
15819
|
+
const nextTable = {
|
|
15820
|
+
columns: [],
|
|
15821
|
+
id,
|
|
15822
|
+
name,
|
|
15823
|
+
primaryKey: [],
|
|
15824
|
+
relationMap: /* @__PURE__ */ new Map(),
|
|
15825
|
+
schema
|
|
15826
|
+
};
|
|
15827
|
+
tables.set(id, nextTable);
|
|
15828
|
+
return nextTable;
|
|
15829
|
+
};
|
|
15830
|
+
const upsertRelation = (table2, key, relation) => {
|
|
15831
|
+
table2.relationMap.set(key, relation);
|
|
15832
|
+
};
|
|
15833
|
+
return {
|
|
15834
|
+
addColumnRows(columnRows) {
|
|
15835
|
+
for (const row of columnRows) {
|
|
15836
|
+
const table2 = ensureTable(row.schema_name, row.table_name);
|
|
15837
|
+
table2.columns.push({
|
|
15838
|
+
dataType: row.data_type,
|
|
15839
|
+
isNullable: row.is_nullable,
|
|
15840
|
+
isPrimaryKey: false,
|
|
15841
|
+
name: row.column_name
|
|
15842
|
+
});
|
|
15843
|
+
}
|
|
15844
|
+
},
|
|
15845
|
+
addForeignKeyRows(foreignKeyRows) {
|
|
15846
|
+
for (const row of foreignKeyRows) {
|
|
15847
|
+
const sourceTable = ensureTable(row.source_schema, row.source_table);
|
|
15848
|
+
const targetTable = ensureTable(row.target_schema, row.target_table);
|
|
15849
|
+
upsertRelation(
|
|
15850
|
+
sourceTable,
|
|
15851
|
+
relationKey2(row.constraint_name, row.target_table),
|
|
15852
|
+
{
|
|
15853
|
+
name: row.constraint_name,
|
|
15854
|
+
targetSchema: row.target_schema,
|
|
15855
|
+
targetTable: row.target_table
|
|
15856
|
+
}
|
|
15857
|
+
);
|
|
15858
|
+
upsertRelation(targetTable, relationKey2(row.source_table), {
|
|
15859
|
+
name: relationKey2(row.source_table, row.constraint_name),
|
|
15860
|
+
targetSchema: row.source_schema,
|
|
15861
|
+
targetTable: row.source_table
|
|
15862
|
+
});
|
|
15863
|
+
}
|
|
15864
|
+
},
|
|
15865
|
+
addManyToManyRows(foreignKeyRows) {
|
|
15866
|
+
const foreignKeysBySourceTable = /* @__PURE__ */ new Map();
|
|
15867
|
+
for (const foreignKey of foreignKeyRows) {
|
|
15868
|
+
const key = tableKey2(foreignKey.source_schema, foreignKey.source_table);
|
|
15869
|
+
const current = foreignKeysBySourceTable.get(key) ?? {
|
|
15870
|
+
foreignKeys: [],
|
|
15871
|
+
schema: foreignKey.source_schema,
|
|
15872
|
+
table: foreignKey.source_table
|
|
15873
|
+
};
|
|
15874
|
+
current.foreignKeys.push(foreignKey);
|
|
15875
|
+
foreignKeysBySourceTable.set(key, current);
|
|
15876
|
+
}
|
|
15877
|
+
for (const candidate of foreignKeysBySourceTable.values()) {
|
|
15878
|
+
const bridgeTable = tables.get(
|
|
15879
|
+
tableKey2(candidate.schema, candidate.table)
|
|
15880
|
+
);
|
|
15881
|
+
if (!bridgeTable || candidate.foreignKeys.length !== 2) {
|
|
15882
|
+
continue;
|
|
15883
|
+
}
|
|
15884
|
+
const combinedForeignColumns = Array.from(
|
|
15885
|
+
new Set(
|
|
15886
|
+
candidate.foreignKeys.flatMap(
|
|
15887
|
+
(foreignKey) => coerceStringArray2(foreignKey.source_columns)
|
|
15888
|
+
)
|
|
15889
|
+
)
|
|
15890
|
+
);
|
|
15891
|
+
if (bridgeTable.primaryKey.length === 0 || combinedForeignColumns.length !== bridgeTable.primaryKey.length || !bridgeTable.primaryKey.every(
|
|
15892
|
+
(column) => combinedForeignColumns.includes(column)
|
|
15893
|
+
)) {
|
|
15894
|
+
continue;
|
|
15895
|
+
}
|
|
15896
|
+
const [firstForeignKey, secondForeignKey] = candidate.foreignKeys;
|
|
15897
|
+
const firstTarget = tables.get(
|
|
15898
|
+
tableKey2(firstForeignKey.target_schema, firstForeignKey.target_table)
|
|
15899
|
+
);
|
|
15900
|
+
const secondTarget = tables.get(
|
|
15901
|
+
tableKey2(
|
|
15902
|
+
secondForeignKey.target_schema,
|
|
15903
|
+
secondForeignKey.target_table
|
|
15904
|
+
)
|
|
15905
|
+
);
|
|
15906
|
+
if (!(firstTarget && secondTarget)) {
|
|
15907
|
+
continue;
|
|
15908
|
+
}
|
|
15909
|
+
upsertRelation(
|
|
15910
|
+
firstTarget,
|
|
15911
|
+
relationKey2(candidate.table, secondForeignKey.target_table),
|
|
15912
|
+
{
|
|
15913
|
+
name: relationKey2(
|
|
15914
|
+
candidate.table,
|
|
15915
|
+
secondForeignKey.constraint_name
|
|
15916
|
+
),
|
|
15917
|
+
targetSchema: secondForeignKey.target_schema,
|
|
15918
|
+
targetTable: secondForeignKey.target_table
|
|
15919
|
+
}
|
|
15920
|
+
);
|
|
15921
|
+
upsertRelation(
|
|
15922
|
+
secondTarget,
|
|
15923
|
+
relationKey2(candidate.table, firstForeignKey.target_table),
|
|
15924
|
+
{
|
|
15925
|
+
name: relationKey2(candidate.table, firstForeignKey.constraint_name),
|
|
15926
|
+
targetSchema: firstForeignKey.target_schema,
|
|
15927
|
+
targetTable: firstForeignKey.target_table
|
|
15928
|
+
}
|
|
15929
|
+
);
|
|
15930
|
+
}
|
|
15931
|
+
},
|
|
15932
|
+
addPrimaryKeyRows(primaryKeyRows) {
|
|
15933
|
+
for (const row of primaryKeyRows) {
|
|
15934
|
+
const table2 = ensureTable(row.schema_name, row.table_name);
|
|
15935
|
+
const primaryKey = coerceStringArray2(row.columns);
|
|
15936
|
+
table2.primaryKey = primaryKey;
|
|
15937
|
+
for (const columnName of primaryKey) {
|
|
15938
|
+
const column = table2.columns.find(
|
|
15939
|
+
(candidate) => candidate.name === columnName
|
|
15940
|
+
);
|
|
15941
|
+
if (column) {
|
|
15942
|
+
column.isPrimaryKey = true;
|
|
15943
|
+
}
|
|
15944
|
+
}
|
|
15945
|
+
}
|
|
15946
|
+
},
|
|
15947
|
+
toResponse(database) {
|
|
15948
|
+
return {
|
|
15949
|
+
database,
|
|
15950
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15951
|
+
tables: [...tables.values()].map((table2) => ({
|
|
15952
|
+
columns: [...table2.columns].sort(
|
|
15953
|
+
(left, right) => left.name.localeCompare(right.name)
|
|
15954
|
+
),
|
|
15955
|
+
id: table2.id,
|
|
15956
|
+
name: table2.name,
|
|
15957
|
+
primaryKey: [...table2.primaryKey],
|
|
15958
|
+
relations: [...table2.relationMap.values()].map((relation) => ({
|
|
15959
|
+
columns: tables.get(
|
|
15960
|
+
tableKey2(relation.targetSchema, relation.targetTable)
|
|
15961
|
+
)?.columns ?? [],
|
|
15962
|
+
name: relation.name,
|
|
15963
|
+
targetSchema: relation.targetSchema,
|
|
15964
|
+
targetTable: relation.targetTable
|
|
15965
|
+
})).sort(
|
|
15966
|
+
(left, right) => left.name.localeCompare(right.name)
|
|
15967
|
+
),
|
|
15968
|
+
schema: table2.schema
|
|
15969
|
+
})).sort(
|
|
15970
|
+
(left, right) => left.id.localeCompare(right.id)
|
|
15971
|
+
)
|
|
15972
|
+
};
|
|
15973
|
+
}
|
|
15974
|
+
};
|
|
15975
|
+
}
|
|
15976
|
+
async function queryRows(client, query) {
|
|
15977
|
+
const result = await client.query(query);
|
|
15978
|
+
if (result.error || result.status < 200 || result.status >= 300) {
|
|
15979
|
+
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}.`;
|
|
15980
|
+
throw new Error(errorMessage);
|
|
15981
|
+
}
|
|
15982
|
+
return Array.isArray(result.data) ? result.data : [];
|
|
15983
|
+
}
|
|
15984
|
+
function isAthenaTableSchemaConfig(value) {
|
|
15985
|
+
if (typeof value !== "object" || value === null) {
|
|
15986
|
+
return false;
|
|
15987
|
+
}
|
|
15988
|
+
const config = value;
|
|
15989
|
+
return typeof config.gatewayUrl === "string" && typeof config.gatewayKey === "string" && typeof config.gatewayDatabase === "string" && typeof config.schemaScope === "string" && typeof config.clientName === "string";
|
|
15990
|
+
}
|
|
15991
|
+
function hasAthenaTableSchemaCredentials(config) {
|
|
15992
|
+
return config.gatewayUrl.trim().length > 0 && config.gatewayKey.trim().length > 0 && config.gatewayDatabase.trim().length > 0;
|
|
15993
|
+
}
|
|
15994
|
+
async function fetchAthenaTableCatalog(config, options = {}) {
|
|
15995
|
+
const schemas = parseAthenaTableSchemaScope(config.schemaScope);
|
|
15996
|
+
if (schemas.length === 0) {
|
|
15997
|
+
return {
|
|
15998
|
+
database: config.gatewayDatabase,
|
|
15999
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16000
|
+
tables: []
|
|
16001
|
+
};
|
|
16002
|
+
}
|
|
16003
|
+
const queries = buildAthenaTableCatalogQueries(schemas);
|
|
16004
|
+
const client = options.client ?? createClient({
|
|
16005
|
+
url: config.gatewayUrl.trim(),
|
|
16006
|
+
key: config.gatewayKey.trim(),
|
|
16007
|
+
client: config.clientName.trim() || void 0
|
|
16008
|
+
});
|
|
16009
|
+
const [columnRows, primaryKeyRows, foreignKeyRows] = await Promise.all([
|
|
16010
|
+
queryRows(client, queries.columns),
|
|
16011
|
+
queryRows(client, queries.primaryKeys),
|
|
16012
|
+
queryRows(client, queries.foreignKeys)
|
|
16013
|
+
]);
|
|
16014
|
+
const catalog = createTableCatalog();
|
|
16015
|
+
catalog.addColumnRows(columnRows);
|
|
16016
|
+
catalog.addPrimaryKeyRows(primaryKeyRows);
|
|
16017
|
+
catalog.addForeignKeyRows(foreignKeyRows);
|
|
16018
|
+
catalog.addManyToManyRows(foreignKeyRows);
|
|
16019
|
+
return catalog.toResponse(config.gatewayDatabase);
|
|
16020
|
+
}
|
|
16021
|
+
var fetchTableCatalog = fetchAthenaTableCatalog;
|
|
16022
|
+
|
|
16023
|
+
// src/tables/schema-handlers.ts
|
|
16024
|
+
var ATHENA_TABLE_SCHEMA_ROUTE = "/api/tables/schema";
|
|
16025
|
+
function json2(body, init) {
|
|
16026
|
+
const headers = new Headers(init?.headers);
|
|
16027
|
+
if (!headers.has("content-type")) {
|
|
16028
|
+
headers.set("content-type", "application/json; charset=utf-8");
|
|
16029
|
+
}
|
|
16030
|
+
return new Response(JSON.stringify(body), {
|
|
16031
|
+
status: init?.status ?? 200,
|
|
16032
|
+
headers
|
|
16033
|
+
});
|
|
16034
|
+
}
|
|
16035
|
+
async function handleAthenaTableSchemaPost(request2, options) {
|
|
16036
|
+
const payload = await request2.json().catch(() => null);
|
|
16037
|
+
let config = isAthenaTableSchemaConfig(
|
|
16038
|
+
payload?.config
|
|
16039
|
+
) ? payload.config : null;
|
|
16040
|
+
if (config && options?.resolveConfig) {
|
|
16041
|
+
config = await options.resolveConfig(config, request2);
|
|
16042
|
+
}
|
|
16043
|
+
if (!config || !isAthenaTableSchemaConfig(config)) {
|
|
16044
|
+
return json2(
|
|
16045
|
+
{
|
|
16046
|
+
error: "The Athena tables showcase config is invalid."
|
|
16047
|
+
},
|
|
16048
|
+
{ status: 400 }
|
|
16049
|
+
);
|
|
16050
|
+
}
|
|
16051
|
+
if (!hasAthenaTableSchemaCredentials(config)) {
|
|
16052
|
+
return json2(
|
|
16053
|
+
{
|
|
16054
|
+
error: "Gateway URL, API key, and database are required for schema introspection."
|
|
16055
|
+
},
|
|
16056
|
+
{ status: 400 }
|
|
16057
|
+
);
|
|
16058
|
+
}
|
|
16059
|
+
try {
|
|
16060
|
+
const response = await fetchAthenaTableCatalog(
|
|
16061
|
+
config,
|
|
16062
|
+
{
|
|
16063
|
+
client: options?.client
|
|
16064
|
+
}
|
|
16065
|
+
);
|
|
16066
|
+
return json2(response);
|
|
16067
|
+
} catch (error) {
|
|
16068
|
+
return json2(
|
|
16069
|
+
{
|
|
16070
|
+
error: error instanceof Error ? error.message : "Athena schema introspection failed."
|
|
16071
|
+
},
|
|
16072
|
+
{ status: 500 }
|
|
16073
|
+
);
|
|
16074
|
+
}
|
|
16075
|
+
}
|
|
16076
|
+
function createAthenaTableSchemaHandlers(options) {
|
|
16077
|
+
return {
|
|
16078
|
+
POST: (request2) => handleAthenaTableSchemaPost(request2, options)
|
|
16079
|
+
};
|
|
16080
|
+
}
|
|
16081
|
+
|
|
16082
|
+
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, ATHENA_TABLE_SCHEMA_ROUTE, AthenaBillingError, AthenaChatError, AthenaConfigurationError, AthenaError, AthenaErrorCategory, AthenaErrorCode, AthenaErrorKind, AthenaGatewayError, AthenaStorageError, AthenaStorageErrorCode, Backend, DEFAULT_MULTIPART_PART_SIZE_BYTES, DEFAULT_MULTIPART_THRESHOLD_BYTES, DEFAULT_POSTGRES_SCHEMAS, applyAthenaReadQueryFilters, applyAthenaReadQuerySelectLimit, applyAthenaReadQuerySelectOrder, applyAthenaTableFilters, applyAthenaTableSelectLimit, applyAthenaTableSelectOrder, assertInt, athenaAuth, billingSdkManifest, boolean, buildAthenaReadQueryFindManyOrderBy, buildAthenaReadQueryFindManySelect, buildAthenaReadQueryFindManyWhere, buildAthenaReadQuerySelectString, buildAthenaTableCatalogQueries, buildAthenaTableFindManyOrderBy, buildAthenaTableFindManySelect, buildAthenaTableFindManyWhere, buildAthenaTableSelectString, chatSdkManifest, clampAthenaReadQueryTotalItems, clampAthenaTableTotalItems, coerceInt, createAthenaStorageError, createAthenaTableSchemaHandlers, createAuthReactEmailInput, createBillingModule, createClient, createModelFormAdapter, createPostgresIntrospectionProvider, createStorageFileModule, defineAthenaAuthConfig, defineAuthEmailTemplate, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, detectGeneratorProviderMode, discoverPostgresSchemas, ensureActiveOrganization, ensureGeneratorConfigFile, enumeration, executeAthenaReadQuery, executeAthenaTableQuery, fetchAthenaTableCatalog, fetchTableCatalog, filterIntrospectionSnapshot, findGeneratorConfigPath, flattenAthenaReadQueryRows, flattenAthenaRows, generateArtifactsFromSnapshot, generatorEnv, getAthenaDebugAst, handleAthenaTableSchemaPost, hasAthenaTableSchemaCredentials, identifier, isAthenaGatewayError, isAthenaTableSchemaConfig, isOk, json, loadGeneratorConfig, mergeSchemaSelections, normalizeAthenaError, normalizeAthenaGatewayBaseUrl, normalizeAthenaReadQueryOrderBy, normalizeAthenaTableOrderBy, normalizeDiscoveredSchemas, normalizeGeneratorConfig, normalizeSchemaSelection, normalizeTableSelection, number, parseAthenaTableSchemaScope, parseBooleanFlag2 as parseBooleanFlag, patchSchemasInConfigSource, renderAthenaReactEmail, renderGeneratorConfigFile, requireAffected, requireSuccess, resolveAthenaReadQueryPageFetch, resolveGeneratorProvider, resolvePostgresColumnType, resolveProviderSchemas, resolveStoragePath, runSchemaGenerator, schemasEqual, storageSdkManifest, string, table, toModelFormDefaults, toModelPayload, unwrap, unwrapChatMessage, unwrapChatRoom, unwrapOne, unwrapRows, verifyAthenaGatewayUrl, withRetry };
|
|
15488
16083
|
//# sourceMappingURL=index.js.map
|
|
15489
16084
|
//# sourceMappingURL=index.js.map
|