@xylex-group/athena 3.0.3 → 3.1.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/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 +322 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +5 -5
- package/dist/browser.d.ts +5 -5
- package/dist/browser.js +301 -2
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +7771 -7058
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +17 -10
- package/dist/cli/index.d.ts +17 -10
- package/dist/cli/index.js +7773 -7060
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +885 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -6
- package/dist/index.d.ts +28 -6
- package/dist/index.js +857 -20
- package/dist/index.js.map +1 -1
- package/dist/model-form-BbdzJ9Uh.d.ts +259 -0
- package/dist/model-form-BhWWsA-7.d.cts +259 -0
- package/dist/{module-BruTcxe0.d.ts → module-DKkJKOuJ.d.ts} +2 -2
- package/dist/{module-CPG3ULxQ.d.cts → module-xFd7_Igv.d.cts} +2 -2
- package/dist/next/client.cjs +1 -1
- package/dist/next/client.cjs.map +1 -1
- package/dist/next/client.js +1 -1
- package/dist/next/client.js.map +1 -1
- package/dist/next/server.cjs +1 -1
- package/dist/next/server.cjs.map +1 -1
- package/dist/next/server.js +1 -1
- package/dist/next/server.js.map +1 -1
- package/dist/pipeline-DuKzYGia.d.cts +93 -0
- package/dist/pipeline-wer2G9xW.d.ts +93 -0
- package/dist/react.cjs +400 -3
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +67 -2
- package/dist/react.d.ts +67 -2
- package/dist/react.js +400 -4
- package/dist/react.js.map +1 -1
- package/dist/{types-DFr2cL1N.d.cts → types-1ztXDgPa.d.cts} +28 -1
- package/dist/{types-D6tZ9aoq.d.ts → types-CccOiXPo.d.ts} +28 -1
- package/package.json +1 -1
- package/dist/model-form-Dh0sisdL.d.ts +0 -97
- package/dist/model-form-oOAJUVd4.d.cts +0 -97
- package/dist/pipeline-CIzV9f7b.d.cts +0 -8
- package/dist/pipeline-DNlc8Ayn.d.ts +0 -8
package/dist/index.cjs
CHANGED
|
@@ -573,8 +573,8 @@ function computeDelayMs(attempt, error, config) {
|
|
|
573
573
|
}
|
|
574
574
|
function sleep(ms) {
|
|
575
575
|
if (ms <= 0) return Promise.resolve();
|
|
576
|
-
return new Promise((
|
|
577
|
-
setTimeout(
|
|
576
|
+
return new Promise((resolve4) => {
|
|
577
|
+
setTimeout(resolve4, ms);
|
|
578
578
|
});
|
|
579
579
|
}
|
|
580
580
|
async function withRetry(config, fn) {
|
|
@@ -2009,7 +2009,7 @@ function buildAthenaGatewayUrl(baseUrl, path) {
|
|
|
2009
2009
|
|
|
2010
2010
|
// package.json
|
|
2011
2011
|
var package_default = {
|
|
2012
|
-
version: "3.0
|
|
2012
|
+
version: "3.1.0"
|
|
2013
2013
|
};
|
|
2014
2014
|
|
|
2015
2015
|
// src/sdk-version.ts
|
|
@@ -5228,7 +5228,7 @@ async function putWithXhr(url, signed, body, signal, onProgress) {
|
|
|
5228
5228
|
if (Xhr === void 0) {
|
|
5229
5229
|
return Promise.reject(new Error("athena.storage.file.upload direct mode requires XMLHttpRequest in this runtime"));
|
|
5230
5230
|
}
|
|
5231
|
-
return new Promise((
|
|
5231
|
+
return new Promise((resolve4, reject) => {
|
|
5232
5232
|
const xhr = new Xhr();
|
|
5233
5233
|
const abort = () => xhr.abort();
|
|
5234
5234
|
xhr.open("PUT", url);
|
|
@@ -5241,7 +5241,7 @@ async function putWithXhr(url, signed, body, signal, onProgress) {
|
|
|
5241
5241
|
return;
|
|
5242
5242
|
}
|
|
5243
5243
|
onProgress({ loaded: bodySize(body) });
|
|
5244
|
-
|
|
5244
|
+
resolve4(new Response(xhr.response, {
|
|
5245
5245
|
status: xhr.status,
|
|
5246
5246
|
statusText: xhr.statusText,
|
|
5247
5247
|
headers: parseXhrHeaders(xhr.getAllResponseHeaders())
|
|
@@ -5694,7 +5694,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
|
|
|
5694
5694
|
if (Xhr === void 0) {
|
|
5695
5695
|
return Promise.reject(new Error("athena.storage.file.upload requires XMLHttpRequest in this runtime"));
|
|
5696
5696
|
}
|
|
5697
|
-
return new Promise((
|
|
5697
|
+
return new Promise((resolve4, reject) => {
|
|
5698
5698
|
const xhr = new Xhr();
|
|
5699
5699
|
const abort = () => xhr.abort();
|
|
5700
5700
|
xhr.open("PUT", url);
|
|
@@ -5711,7 +5711,7 @@ function putUploadBodyWithXhr(url, source, headers, options, onProgress) {
|
|
|
5711
5711
|
return;
|
|
5712
5712
|
}
|
|
5713
5713
|
onProgress({ loaded: source.sizeBytes });
|
|
5714
|
-
|
|
5714
|
+
resolve4(new Response(xhr.response, {
|
|
5715
5715
|
status: xhr.status,
|
|
5716
5716
|
statusText: xhr.statusText,
|
|
5717
5717
|
headers: parseXhrHeaders2(xhr.getAllResponseHeaders())
|
|
@@ -10770,6 +10770,305 @@ var Backend = {
|
|
|
10770
10770
|
ScyllaDB: { type: "scylladb" }
|
|
10771
10771
|
};
|
|
10772
10772
|
|
|
10773
|
+
// src/query/read-query.ts
|
|
10774
|
+
function normalizeAthenaReadQueryOrderBy(orderBy) {
|
|
10775
|
+
if (!orderBy) {
|
|
10776
|
+
return [];
|
|
10777
|
+
}
|
|
10778
|
+
const list = Array.isArray(orderBy) ? orderBy : [orderBy];
|
|
10779
|
+
return list.filter(
|
|
10780
|
+
(entry) => entry && typeof entry.column === "string" && entry.column.trim().length > 0
|
|
10781
|
+
);
|
|
10782
|
+
}
|
|
10783
|
+
function isRecord12(value) {
|
|
10784
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10785
|
+
}
|
|
10786
|
+
function flattenAthenaRowValue(row, column) {
|
|
10787
|
+
if (!column.relation) {
|
|
10788
|
+
return row[column.column];
|
|
10789
|
+
}
|
|
10790
|
+
const relationValue = row[column.relation.name];
|
|
10791
|
+
if (Array.isArray(relationValue)) {
|
|
10792
|
+
return relationValue.map((entry) => isRecord12(entry) ? entry[column.column] : void 0).filter((entry) => entry !== void 0);
|
|
10793
|
+
}
|
|
10794
|
+
if (isRecord12(relationValue)) {
|
|
10795
|
+
return relationValue[column.column];
|
|
10796
|
+
}
|
|
10797
|
+
return void 0;
|
|
10798
|
+
}
|
|
10799
|
+
function resolveFlatRowKey(row, index, preferredKey) {
|
|
10800
|
+
const preferredValue = preferredKey && preferredKey in row ? row[preferredKey] : void 0;
|
|
10801
|
+
if (preferredValue !== void 0 && preferredValue !== null && `${preferredValue}`.trim().length > 0) {
|
|
10802
|
+
return String(preferredValue);
|
|
10803
|
+
}
|
|
10804
|
+
for (const [key, value] of Object.entries(row)) {
|
|
10805
|
+
if (key === "__rowKey") {
|
|
10806
|
+
continue;
|
|
10807
|
+
}
|
|
10808
|
+
if (value === void 0 || value === null) {
|
|
10809
|
+
continue;
|
|
10810
|
+
}
|
|
10811
|
+
if (Array.isArray(value)) {
|
|
10812
|
+
if (value.length > 0) {
|
|
10813
|
+
return `${key}-${value.join("-")}`;
|
|
10814
|
+
}
|
|
10815
|
+
continue;
|
|
10816
|
+
}
|
|
10817
|
+
const nextValue = String(value).trim();
|
|
10818
|
+
if (nextValue.length > 0) {
|
|
10819
|
+
return nextValue;
|
|
10820
|
+
}
|
|
10821
|
+
}
|
|
10822
|
+
return `row-${index + 1}`;
|
|
10823
|
+
}
|
|
10824
|
+
function flattenAthenaReadQueryRows(rows, columns, preferredKey) {
|
|
10825
|
+
return rows.map((entry, index) => {
|
|
10826
|
+
const sourceRow = isRecord12(entry) ? entry : {};
|
|
10827
|
+
const flatRow = columns.reduce(
|
|
10828
|
+
(currentRow, column) => {
|
|
10829
|
+
currentRow[column.key] = flattenAthenaRowValue(sourceRow, column);
|
|
10830
|
+
return currentRow;
|
|
10831
|
+
},
|
|
10832
|
+
{ __rowKey: "" }
|
|
10833
|
+
);
|
|
10834
|
+
flatRow.__rowKey = resolveFlatRowKey(flatRow, index, preferredKey);
|
|
10835
|
+
return flatRow;
|
|
10836
|
+
});
|
|
10837
|
+
}
|
|
10838
|
+
var flattenAthenaRows = flattenAthenaReadQueryRows;
|
|
10839
|
+
function buildAthenaReadQuerySelectString(columns) {
|
|
10840
|
+
const baseColumns = columns.filter((column) => !column.relation).map((column) => column.column);
|
|
10841
|
+
const relationGroups = /* @__PURE__ */ new Map();
|
|
10842
|
+
for (const column of columns) {
|
|
10843
|
+
if (!column.relation) {
|
|
10844
|
+
continue;
|
|
10845
|
+
}
|
|
10846
|
+
const groupKey = [
|
|
10847
|
+
column.relation.name,
|
|
10848
|
+
column.relation.schema ?? "",
|
|
10849
|
+
column.relation.table
|
|
10850
|
+
].join(":");
|
|
10851
|
+
const existingGroup = relationGroups.get(groupKey);
|
|
10852
|
+
if (existingGroup) {
|
|
10853
|
+
if (!existingGroup.columns.includes(column.column)) {
|
|
10854
|
+
existingGroup.columns.push(column.column);
|
|
10855
|
+
}
|
|
10856
|
+
continue;
|
|
10857
|
+
}
|
|
10858
|
+
relationGroups.set(groupKey, {
|
|
10859
|
+
columns: [column.column],
|
|
10860
|
+
relation: column.relation
|
|
10861
|
+
});
|
|
10862
|
+
}
|
|
10863
|
+
const relationColumns = [...relationGroups.values()].map(
|
|
10864
|
+
({ columns: relationColumns2, relation }) => {
|
|
10865
|
+
const relationTarget = relation.schema ? `${relation.schema}.${relation.table}` : relation.table;
|
|
10866
|
+
return `${relation.name}:${relationTarget}(${relationColumns2.join(",")})`;
|
|
10867
|
+
}
|
|
10868
|
+
);
|
|
10869
|
+
return [...baseColumns, ...relationColumns].join(",");
|
|
10870
|
+
}
|
|
10871
|
+
var buildAthenaTableSelectString = buildAthenaReadQuerySelectString;
|
|
10872
|
+
function buildAthenaReadQueryFindManySelect(columns) {
|
|
10873
|
+
const select = {};
|
|
10874
|
+
for (const column of columns) {
|
|
10875
|
+
if (!column.relation) {
|
|
10876
|
+
select[column.column] = true;
|
|
10877
|
+
continue;
|
|
10878
|
+
}
|
|
10879
|
+
const existingRelation = select[column.relation.name];
|
|
10880
|
+
if (existingRelation && existingRelation !== true && isRecord12(existingRelation.select)) {
|
|
10881
|
+
existingRelation.select[column.column] = true;
|
|
10882
|
+
continue;
|
|
10883
|
+
}
|
|
10884
|
+
select[column.relation.name] = {
|
|
10885
|
+
...column.relation.schema ? { schema: column.relation.schema } : {},
|
|
10886
|
+
select: {
|
|
10887
|
+
[column.column]: true
|
|
10888
|
+
}
|
|
10889
|
+
};
|
|
10890
|
+
}
|
|
10891
|
+
return select;
|
|
10892
|
+
}
|
|
10893
|
+
var buildAthenaTableFindManySelect = buildAthenaReadQueryFindManySelect;
|
|
10894
|
+
function buildAthenaReadQueryFindManyWhere(filters) {
|
|
10895
|
+
if (!filters?.length) {
|
|
10896
|
+
return;
|
|
10897
|
+
}
|
|
10898
|
+
return filters.reduce(
|
|
10899
|
+
(where, filter) => {
|
|
10900
|
+
const operator = filter.operator ?? "eq";
|
|
10901
|
+
where[filter.column] = operator === "eq" ? filter.value : { [operator]: filter.value };
|
|
10902
|
+
return where;
|
|
10903
|
+
},
|
|
10904
|
+
{}
|
|
10905
|
+
);
|
|
10906
|
+
}
|
|
10907
|
+
var buildAthenaTableFindManyWhere = buildAthenaReadQueryFindManyWhere;
|
|
10908
|
+
function buildAthenaReadQueryFindManyOrderBy(orderBy) {
|
|
10909
|
+
const normalized = normalizeAthenaReadQueryOrderBy(orderBy);
|
|
10910
|
+
if (normalized.length === 0) {
|
|
10911
|
+
return;
|
|
10912
|
+
}
|
|
10913
|
+
if (normalized.length === 1) {
|
|
10914
|
+
const primary = normalized[0];
|
|
10915
|
+
if (!primary) {
|
|
10916
|
+
return;
|
|
10917
|
+
}
|
|
10918
|
+
return {
|
|
10919
|
+
ascending: primary.direction !== "desc",
|
|
10920
|
+
column: primary.column
|
|
10921
|
+
};
|
|
10922
|
+
}
|
|
10923
|
+
return Object.fromEntries(
|
|
10924
|
+
normalized.map((entry) => [
|
|
10925
|
+
entry.column,
|
|
10926
|
+
entry.direction === "desc" ? "desc" : "asc"
|
|
10927
|
+
])
|
|
10928
|
+
);
|
|
10929
|
+
}
|
|
10930
|
+
var buildAthenaTableFindManyOrderBy = buildAthenaReadQueryFindManyOrderBy;
|
|
10931
|
+
var normalizeAthenaTableOrderBy = normalizeAthenaReadQueryOrderBy;
|
|
10932
|
+
function applyAthenaReadQueryFilters(queryBuilder, filters) {
|
|
10933
|
+
if (!filters?.length) {
|
|
10934
|
+
return queryBuilder;
|
|
10935
|
+
}
|
|
10936
|
+
return filters.reduce((currentBuilder, filter) => {
|
|
10937
|
+
const operator = filter.operator ?? "eq";
|
|
10938
|
+
const builderMethod = currentBuilder[operator];
|
|
10939
|
+
if (typeof builderMethod !== "function") {
|
|
10940
|
+
return currentBuilder;
|
|
10941
|
+
}
|
|
10942
|
+
return builderMethod.call(currentBuilder, filter.column, filter.value);
|
|
10943
|
+
}, queryBuilder);
|
|
10944
|
+
}
|
|
10945
|
+
var applyAthenaTableFilters = applyAthenaReadQueryFilters;
|
|
10946
|
+
function applyAthenaReadQuerySelectOrder(queryBuilder, orderBy) {
|
|
10947
|
+
const normalized = normalizeAthenaReadQueryOrderBy(orderBy);
|
|
10948
|
+
if (normalized.length === 0) {
|
|
10949
|
+
return queryBuilder;
|
|
10950
|
+
}
|
|
10951
|
+
return normalized.reduce(
|
|
10952
|
+
(builder, entry) => builder.order(entry.column, {
|
|
10953
|
+
ascending: entry.direction !== "desc"
|
|
10954
|
+
}),
|
|
10955
|
+
queryBuilder
|
|
10956
|
+
);
|
|
10957
|
+
}
|
|
10958
|
+
var applyAthenaTableSelectOrder = applyAthenaReadQuerySelectOrder;
|
|
10959
|
+
function applyAthenaReadQuerySelectLimit(queryBuilder, limit) {
|
|
10960
|
+
if (!limit || limit < 1) {
|
|
10961
|
+
return queryBuilder;
|
|
10962
|
+
}
|
|
10963
|
+
return queryBuilder.limit(limit);
|
|
10964
|
+
}
|
|
10965
|
+
var applyAthenaTableSelectLimit = applyAthenaReadQuerySelectLimit;
|
|
10966
|
+
function clampAthenaReadQueryTotalItems(totalItems, limit) {
|
|
10967
|
+
if (!limit || limit < 1) {
|
|
10968
|
+
return totalItems;
|
|
10969
|
+
}
|
|
10970
|
+
return Math.min(totalItems, limit);
|
|
10971
|
+
}
|
|
10972
|
+
var clampAthenaTableTotalItems = clampAthenaReadQueryTotalItems;
|
|
10973
|
+
function resolveCountValue(...candidates) {
|
|
10974
|
+
for (const candidate of candidates) {
|
|
10975
|
+
if (typeof candidate === "number" && Number.isFinite(candidate)) {
|
|
10976
|
+
return Math.max(0, Math.trunc(candidate));
|
|
10977
|
+
}
|
|
10978
|
+
}
|
|
10979
|
+
return 0;
|
|
10980
|
+
}
|
|
10981
|
+
function resolveTotalItemsFromPage({
|
|
10982
|
+
countCandidates,
|
|
10983
|
+
limit,
|
|
10984
|
+
page,
|
|
10985
|
+
pageSize,
|
|
10986
|
+
rowCount
|
|
10987
|
+
}) {
|
|
10988
|
+
const exactCount = resolveCountValue(...countCandidates);
|
|
10989
|
+
if (exactCount > 0) {
|
|
10990
|
+
return clampAthenaReadQueryTotalItems(exactCount, limit);
|
|
10991
|
+
}
|
|
10992
|
+
if (rowCount > 0) {
|
|
10993
|
+
const base = (page - 1) * pageSize + rowCount;
|
|
10994
|
+
const synthetic = rowCount >= pageSize ? base + 1 : base;
|
|
10995
|
+
return clampAthenaReadQueryTotalItems(synthetic, limit);
|
|
10996
|
+
}
|
|
10997
|
+
return clampAthenaReadQueryTotalItems(exactCount, limit);
|
|
10998
|
+
}
|
|
10999
|
+
async function executeAthenaReadQuery({
|
|
11000
|
+
client,
|
|
11001
|
+
page,
|
|
11002
|
+
pageSize,
|
|
11003
|
+
query
|
|
11004
|
+
}) {
|
|
11005
|
+
const db = client.db;
|
|
11006
|
+
const baseBuilder = db.from(query.table, {
|
|
11007
|
+
schema: query.schema
|
|
11008
|
+
});
|
|
11009
|
+
const countBuilder = applyAthenaReadQueryFilters(
|
|
11010
|
+
db.from(query.table, { schema: query.schema }),
|
|
11011
|
+
query.filters
|
|
11012
|
+
);
|
|
11013
|
+
const countResult = await countBuilder.select(query.countColumn, {
|
|
11014
|
+
count: "exact",
|
|
11015
|
+
head: true
|
|
11016
|
+
});
|
|
11017
|
+
if ((query.mode ?? "findMany") === "select") {
|
|
11018
|
+
const selectBuilder = applyAthenaReadQuerySelectLimit(
|
|
11019
|
+
applyAthenaReadQuerySelectOrder(
|
|
11020
|
+
applyAthenaReadQueryFilters(baseBuilder, query.filters),
|
|
11021
|
+
query.orderBy
|
|
11022
|
+
),
|
|
11023
|
+
query.limit
|
|
11024
|
+
);
|
|
11025
|
+
const result2 = await selectBuilder.currentPage(page).pageSize(pageSize).select(buildAthenaReadQuerySelectString(query.columns), {
|
|
11026
|
+
count: "exact"
|
|
11027
|
+
});
|
|
11028
|
+
const rows2 = flattenAthenaReadQueryRows(
|
|
11029
|
+
Array.isArray(result2.data) ? result2.data : [],
|
|
11030
|
+
query.columns,
|
|
11031
|
+
query.rowKey
|
|
11032
|
+
);
|
|
11033
|
+
return {
|
|
11034
|
+
debugAst: getAthenaDebugAst(result2) ?? void 0,
|
|
11035
|
+
rows: rows2,
|
|
11036
|
+
totalItems: resolveTotalItemsFromPage({
|
|
11037
|
+
countCandidates: [countResult.count, result2.count],
|
|
11038
|
+
limit: query.limit,
|
|
11039
|
+
page,
|
|
11040
|
+
pageSize,
|
|
11041
|
+
rowCount: rows2.length
|
|
11042
|
+
})
|
|
11043
|
+
};
|
|
11044
|
+
}
|
|
11045
|
+
const findManyOrderBy = buildAthenaReadQueryFindManyOrderBy(query.orderBy);
|
|
11046
|
+
const findManyOptions = {
|
|
11047
|
+
...query.limit ? { limit: query.limit } : {},
|
|
11048
|
+
...findManyOrderBy ? { orderBy: findManyOrderBy } : {},
|
|
11049
|
+
select: buildAthenaReadQueryFindManySelect(query.columns),
|
|
11050
|
+
...query.filters?.length ? { where: buildAthenaReadQueryFindManyWhere(query.filters) } : {}
|
|
11051
|
+
};
|
|
11052
|
+
const result = await baseBuilder.currentPage(page).pageSize(pageSize).findMany(findManyOptions);
|
|
11053
|
+
const rows = flattenAthenaReadQueryRows(
|
|
11054
|
+
Array.isArray(result.data) ? result.data : [],
|
|
11055
|
+
query.columns,
|
|
11056
|
+
query.rowKey
|
|
11057
|
+
);
|
|
11058
|
+
return {
|
|
11059
|
+
debugAst: getAthenaDebugAst(result) ?? void 0,
|
|
11060
|
+
rows,
|
|
11061
|
+
totalItems: resolveTotalItemsFromPage({
|
|
11062
|
+
countCandidates: [countResult.count, result.count],
|
|
11063
|
+
limit: query.limit,
|
|
11064
|
+
page,
|
|
11065
|
+
pageSize,
|
|
11066
|
+
rowCount: rows.length
|
|
11067
|
+
})
|
|
11068
|
+
};
|
|
11069
|
+
}
|
|
11070
|
+
var executeAthenaTableQuery = executeAthenaReadQuery;
|
|
11071
|
+
|
|
10773
11072
|
// src/schema/definitions.ts
|
|
10774
11073
|
function defineModel(input) {
|
|
10775
11074
|
return input;
|
|
@@ -10790,7 +11089,7 @@ function resolveNullishValue(mode) {
|
|
|
10790
11089
|
if (mode === "null") return null;
|
|
10791
11090
|
return "";
|
|
10792
11091
|
}
|
|
10793
|
-
function
|
|
11092
|
+
function isRecord13(value) {
|
|
10794
11093
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
10795
11094
|
}
|
|
10796
11095
|
function isNullableColumn(model, key) {
|
|
@@ -10799,7 +11098,7 @@ function isNullableColumn(model, key) {
|
|
|
10799
11098
|
}
|
|
10800
11099
|
function toModelFormDefaults(model, values, options) {
|
|
10801
11100
|
const source = values;
|
|
10802
|
-
if (!
|
|
11101
|
+
if (!isRecord13(source)) {
|
|
10803
11102
|
return {};
|
|
10804
11103
|
}
|
|
10805
11104
|
const mode = options?.nullishMode ?? "empty-string";
|
|
@@ -12316,6 +12615,486 @@ async function loadGeneratorConfig(options = {}) {
|
|
|
12316
12615
|
}
|
|
12317
12616
|
}
|
|
12318
12617
|
|
|
12618
|
+
// src/generator/schema-discovery.ts
|
|
12619
|
+
var DISCOVER_POSTGRES_SCHEMAS_SQL = `
|
|
12620
|
+
SELECT DISTINCT n.nspname AS schema_name
|
|
12621
|
+
FROM pg_namespace n
|
|
12622
|
+
JOIN pg_class c ON c.relnamespace = n.oid
|
|
12623
|
+
WHERE c.relkind IN ('r', 'p')
|
|
12624
|
+
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
|
|
12625
|
+
AND n.nspname NOT LIKE 'pg_toast%'
|
|
12626
|
+
AND n.nspname NOT LIKE 'pg_temp_%'
|
|
12627
|
+
AND n.nspname NOT LIKE 'pg_toast_temp_%'
|
|
12628
|
+
ORDER BY n.nspname;
|
|
12629
|
+
`.trim();
|
|
12630
|
+
var SYSTEM_SCHEMA_PREFIXES = ["pg_"];
|
|
12631
|
+
var SYSTEM_SCHEMAS = /* @__PURE__ */ new Set(["pg_catalog", "information_schema"]);
|
|
12632
|
+
function normalizeDiscoveredSchemas(input) {
|
|
12633
|
+
const schemas = [];
|
|
12634
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12635
|
+
for (const value of input) {
|
|
12636
|
+
const schema = value.trim();
|
|
12637
|
+
if (!schema || seen.has(schema)) {
|
|
12638
|
+
continue;
|
|
12639
|
+
}
|
|
12640
|
+
if (SYSTEM_SCHEMAS.has(schema)) {
|
|
12641
|
+
continue;
|
|
12642
|
+
}
|
|
12643
|
+
if (SYSTEM_SCHEMA_PREFIXES.some((prefix) => schema.startsWith(prefix))) {
|
|
12644
|
+
continue;
|
|
12645
|
+
}
|
|
12646
|
+
seen.add(schema);
|
|
12647
|
+
schemas.push(schema);
|
|
12648
|
+
}
|
|
12649
|
+
return schemas;
|
|
12650
|
+
}
|
|
12651
|
+
function mergeSchemaSelections(configured, discovered) {
|
|
12652
|
+
const result = [];
|
|
12653
|
+
const seen = /* @__PURE__ */ new Set();
|
|
12654
|
+
for (const value of configured ?? []) {
|
|
12655
|
+
const schema = value.trim();
|
|
12656
|
+
if (!schema || seen.has(schema)) {
|
|
12657
|
+
continue;
|
|
12658
|
+
}
|
|
12659
|
+
seen.add(schema);
|
|
12660
|
+
result.push(schema);
|
|
12661
|
+
}
|
|
12662
|
+
for (const value of discovered) {
|
|
12663
|
+
const schema = value.trim();
|
|
12664
|
+
if (!schema || seen.has(schema)) {
|
|
12665
|
+
continue;
|
|
12666
|
+
}
|
|
12667
|
+
seen.add(schema);
|
|
12668
|
+
result.push(schema);
|
|
12669
|
+
}
|
|
12670
|
+
return result.length > 0 ? result : ["public"];
|
|
12671
|
+
}
|
|
12672
|
+
function schemasEqual(left, right) {
|
|
12673
|
+
const a = normalizeDiscoveredSchemas(left ?? []);
|
|
12674
|
+
const b = normalizeDiscoveredSchemas(right ?? []);
|
|
12675
|
+
if (a.length !== b.length) {
|
|
12676
|
+
return false;
|
|
12677
|
+
}
|
|
12678
|
+
const set = new Set(a);
|
|
12679
|
+
return b.every((schema) => set.has(schema));
|
|
12680
|
+
}
|
|
12681
|
+
function coerceSchemaName(row) {
|
|
12682
|
+
const raw = row.schema_name ?? row.schemaName ?? row.nspname;
|
|
12683
|
+
if (typeof raw !== "string") {
|
|
12684
|
+
return void 0;
|
|
12685
|
+
}
|
|
12686
|
+
const trimmed = raw.trim();
|
|
12687
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
12688
|
+
}
|
|
12689
|
+
async function loadPgPoolConstructor2() {
|
|
12690
|
+
const module = await import('pg');
|
|
12691
|
+
const poolConstructor = module.Pool ?? module.default?.Pool;
|
|
12692
|
+
if (!poolConstructor) {
|
|
12693
|
+
throw new Error(
|
|
12694
|
+
'@xylex-group/athena: Unable to load the PostgreSQL driver for schema discovery. Ensure "pg" is installed and this API runs in a Node.js server runtime.'
|
|
12695
|
+
);
|
|
12696
|
+
}
|
|
12697
|
+
return poolConstructor;
|
|
12698
|
+
}
|
|
12699
|
+
async function discoverDirectSchemas(config) {
|
|
12700
|
+
const PoolConstructor = await loadPgPoolConstructor2();
|
|
12701
|
+
const pool = new PoolConstructor({ connectionString: config.connectionString });
|
|
12702
|
+
try {
|
|
12703
|
+
const result = await pool.query(DISCOVER_POSTGRES_SCHEMAS_SQL);
|
|
12704
|
+
const names = result.rows.map(coerceSchemaName).filter((value) => Boolean(value));
|
|
12705
|
+
return normalizeDiscoveredSchemas(names);
|
|
12706
|
+
} finally {
|
|
12707
|
+
await pool.end();
|
|
12708
|
+
}
|
|
12709
|
+
}
|
|
12710
|
+
async function discoverGatewaySchemas(config) {
|
|
12711
|
+
const client = createClient({
|
|
12712
|
+
db: { url: config.gatewayUrl },
|
|
12713
|
+
key: config.apiKey,
|
|
12714
|
+
backend: {
|
|
12715
|
+
type: config.backend ?? "postgresql"
|
|
12716
|
+
}
|
|
12717
|
+
});
|
|
12718
|
+
const result = await client.query(DISCOVER_POSTGRES_SCHEMAS_SQL);
|
|
12719
|
+
if (result.error || result.status < 200 || result.status >= 300) {
|
|
12720
|
+
throw new Error(
|
|
12721
|
+
result.error?.message ?? `Gateway schema discovery failed with status ${result.status}`
|
|
12722
|
+
);
|
|
12723
|
+
}
|
|
12724
|
+
const names = (result.data ?? []).map(coerceSchemaName).filter((value) => Boolean(value));
|
|
12725
|
+
return normalizeDiscoveredSchemas(names);
|
|
12726
|
+
}
|
|
12727
|
+
async function discoverPostgresSchemas(provider) {
|
|
12728
|
+
if (provider.kind === "postgres" && provider.mode === "direct") {
|
|
12729
|
+
return discoverDirectSchemas(provider);
|
|
12730
|
+
}
|
|
12731
|
+
if (provider.kind === "postgres" && provider.mode === "gateway") {
|
|
12732
|
+
return discoverGatewaySchemas(provider);
|
|
12733
|
+
}
|
|
12734
|
+
throw new Error(
|
|
12735
|
+
`Schema discovery is only implemented for postgres direct/gateway providers (received ${provider.kind}/${"mode" in provider ? provider.mode : "unknown"}).`
|
|
12736
|
+
);
|
|
12737
|
+
}
|
|
12738
|
+
|
|
12739
|
+
// src/generator/config-file.ts
|
|
12740
|
+
function hasEnv(keys) {
|
|
12741
|
+
for (const key of keys) {
|
|
12742
|
+
const value = process.env[key];
|
|
12743
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
12744
|
+
return true;
|
|
12745
|
+
}
|
|
12746
|
+
}
|
|
12747
|
+
return false;
|
|
12748
|
+
}
|
|
12749
|
+
var DIRECT_CONNECTION_KEYS = [
|
|
12750
|
+
"ATHENA_GENERATOR_PG_URL",
|
|
12751
|
+
"DATABASE_URL",
|
|
12752
|
+
"PG_URL",
|
|
12753
|
+
"POSTGRES_URL",
|
|
12754
|
+
"POSTGRESQL_URL"
|
|
12755
|
+
];
|
|
12756
|
+
var GATEWAY_URL_KEYS = ["ATHENA_URL", "ATHENA_GATEWAY_URL", "ATHENA_GENERATOR_URL"];
|
|
12757
|
+
var GATEWAY_KEY_KEYS = [
|
|
12758
|
+
"ATHENA_API_KEY",
|
|
12759
|
+
"ATHENA_GATEWAY_API_KEY",
|
|
12760
|
+
"ATHENA_GENERATOR_API_KEY"
|
|
12761
|
+
];
|
|
12762
|
+
function detectGeneratorProviderMode(preferred = "auto") {
|
|
12763
|
+
if (preferred === "direct" || preferred === "gateway") {
|
|
12764
|
+
return preferred;
|
|
12765
|
+
}
|
|
12766
|
+
const hasDirect = hasEnv(DIRECT_CONNECTION_KEYS);
|
|
12767
|
+
const hasGateway = hasEnv(GATEWAY_URL_KEYS) && hasEnv(GATEWAY_KEY_KEYS);
|
|
12768
|
+
if (hasDirect) {
|
|
12769
|
+
return "direct";
|
|
12770
|
+
}
|
|
12771
|
+
if (hasGateway) {
|
|
12772
|
+
return "gateway";
|
|
12773
|
+
}
|
|
12774
|
+
return "direct";
|
|
12775
|
+
}
|
|
12776
|
+
function formatStringArray(values, indent) {
|
|
12777
|
+
if (values.length === 0) {
|
|
12778
|
+
return "[]";
|
|
12779
|
+
}
|
|
12780
|
+
const inner = values.map((value) => `${indent} ${JSON.stringify(value)}`).join(",\n");
|
|
12781
|
+
return `[
|
|
12782
|
+
${inner},
|
|
12783
|
+
${indent}]`;
|
|
12784
|
+
}
|
|
12785
|
+
function buildDirectProviderBlock(schemas) {
|
|
12786
|
+
return ` provider: {
|
|
12787
|
+
kind: "postgres",
|
|
12788
|
+
mode: "direct",
|
|
12789
|
+
connectionString: generatorEnv("DATABASE_URL"),
|
|
12790
|
+
database: generatorEnv("ATHENA_GENERATOR_DB", { optional: true }),
|
|
12791
|
+
schemas: ${formatStringArray(schemas, " ")},
|
|
12792
|
+
}`;
|
|
12793
|
+
}
|
|
12794
|
+
function buildGatewayProviderBlock(schemas) {
|
|
12795
|
+
return ` provider: {
|
|
12796
|
+
kind: "postgres",
|
|
12797
|
+
mode: "gateway",
|
|
12798
|
+
gatewayUrl: generatorEnv("ATHENA_URL"),
|
|
12799
|
+
apiKey: generatorEnv("ATHENA_API_KEY"),
|
|
12800
|
+
database: generatorEnv("ATHENA_GENERATOR_DB", { default: "postgres" }),
|
|
12801
|
+
schemas: ${formatStringArray(schemas, " ")},
|
|
12802
|
+
}`;
|
|
12803
|
+
}
|
|
12804
|
+
function renderGeneratorConfigFile(options) {
|
|
12805
|
+
const schemas = options.schemas && options.schemas.length > 0 ? [...options.schemas] : [...DEFAULT_POSTGRES_SCHEMAS];
|
|
12806
|
+
const providerBlock = options.mode === "gateway" ? buildGatewayProviderBlock(schemas) : buildDirectProviderBlock(schemas);
|
|
12807
|
+
return `import { defineGeneratorConfig, generatorEnv } from "@xylex-group/athena";
|
|
12808
|
+
|
|
12809
|
+
export default defineGeneratorConfig({
|
|
12810
|
+
${providerBlock},
|
|
12811
|
+
output: {
|
|
12812
|
+
format: "table-builder",
|
|
12813
|
+
preset: "athena-direct",
|
|
12814
|
+
targets: {
|
|
12815
|
+
model: "athena/models/{schema_kebab}/{model_kebab}.ts",
|
|
12816
|
+
schema: "athena/schemas/{schema_kebab}.ts",
|
|
12817
|
+
database: "athena/relations.ts",
|
|
12818
|
+
registry: "athena/registry.generated.ts",
|
|
12819
|
+
},
|
|
12820
|
+
placeholderMap: {
|
|
12821
|
+
namespace: "athena",
|
|
12822
|
+
},
|
|
12823
|
+
},
|
|
12824
|
+
naming: {
|
|
12825
|
+
modelType: "pascal",
|
|
12826
|
+
modelConst: "camel",
|
|
12827
|
+
schemaConst: "camel",
|
|
12828
|
+
databaseConst: "camel",
|
|
12829
|
+
registryConst: "camel",
|
|
12830
|
+
},
|
|
12831
|
+
features: {
|
|
12832
|
+
emitRelations: true,
|
|
12833
|
+
emitRegistry: true,
|
|
12834
|
+
},
|
|
12835
|
+
experimental: {
|
|
12836
|
+
postgresGatewayIntrospection: false,
|
|
12837
|
+
scyllaProviderContracts: true,
|
|
12838
|
+
},
|
|
12839
|
+
});
|
|
12840
|
+
`;
|
|
12841
|
+
}
|
|
12842
|
+
function resolveConfigPath(cwd, configPath) {
|
|
12843
|
+
if (configPath) {
|
|
12844
|
+
const absolutePath2 = path.resolve(cwd, configPath);
|
|
12845
|
+
return {
|
|
12846
|
+
absolutePath: absolutePath2,
|
|
12847
|
+
relativePath: configPath.replace(/\\/g, "/"),
|
|
12848
|
+
exists: fs.existsSync(absolutePath2)
|
|
12849
|
+
};
|
|
12850
|
+
}
|
|
12851
|
+
const discovered = findGeneratorConfigPath(cwd);
|
|
12852
|
+
if (discovered) {
|
|
12853
|
+
const relativePath = discovered.startsWith(cwd) ? discovered.slice(cwd.length).replace(/^[/\\]/, "").replace(/\\/g, "/") : "athena.config.ts";
|
|
12854
|
+
return {
|
|
12855
|
+
absolutePath: discovered,
|
|
12856
|
+
relativePath,
|
|
12857
|
+
exists: true
|
|
12858
|
+
};
|
|
12859
|
+
}
|
|
12860
|
+
const absolutePath = path.resolve(cwd, "athena.config.ts");
|
|
12861
|
+
return {
|
|
12862
|
+
absolutePath,
|
|
12863
|
+
relativePath: "athena.config.ts",
|
|
12864
|
+
exists: false
|
|
12865
|
+
};
|
|
12866
|
+
}
|
|
12867
|
+
function providerModeFromConfig(provider, preferred) {
|
|
12868
|
+
if (provider && provider.kind === "postgres") {
|
|
12869
|
+
if (provider.mode === "gateway") {
|
|
12870
|
+
return "gateway";
|
|
12871
|
+
}
|
|
12872
|
+
if (provider.mode === "direct") {
|
|
12873
|
+
return "direct";
|
|
12874
|
+
}
|
|
12875
|
+
}
|
|
12876
|
+
return detectGeneratorProviderMode(preferred);
|
|
12877
|
+
}
|
|
12878
|
+
function schemasFromNormalized(config) {
|
|
12879
|
+
if (config.provider.kind !== "postgres") {
|
|
12880
|
+
return [...DEFAULT_POSTGRES_SCHEMAS];
|
|
12881
|
+
}
|
|
12882
|
+
return normalizeSchemaSelection(config.provider.schemas);
|
|
12883
|
+
}
|
|
12884
|
+
function patchSchemasInConfigSource(source, schemas) {
|
|
12885
|
+
const formattedInline = `[${schemas.map((value) => JSON.stringify(value)).join(", ")}]`;
|
|
12886
|
+
const formattedMultiline = formatStringArray(schemas, " ");
|
|
12887
|
+
const listDefaultPattern = /(schemas\s*:\s*generatorEnv\.list\s*\(\s*['"][^'"]+['"]\s*,\s*\{[\s\S]*?default\s*:\s*)(\[[^\]]*\])/m;
|
|
12888
|
+
if (listDefaultPattern.test(source)) {
|
|
12889
|
+
return source.replace(listDefaultPattern, `$1${formattedInline}`);
|
|
12890
|
+
}
|
|
12891
|
+
const literalPattern = /(schemas\s*:\s*)(\[[^\]]*\])/m;
|
|
12892
|
+
if (literalPattern.test(source)) {
|
|
12893
|
+
const usesMultiline = /schemas\s*:\s*\[\s*\n/.test(source);
|
|
12894
|
+
return source.replace(
|
|
12895
|
+
literalPattern,
|
|
12896
|
+
`$1${usesMultiline ? formattedMultiline : formattedInline}`
|
|
12897
|
+
);
|
|
12898
|
+
}
|
|
12899
|
+
const modeLine = /(mode\s*:\s*["'](?:direct|gateway)["']\s*,)/m;
|
|
12900
|
+
if (modeLine.test(source)) {
|
|
12901
|
+
return source.replace(
|
|
12902
|
+
modeLine,
|
|
12903
|
+
`$1
|
|
12904
|
+
schemas: ${formattedInline},`
|
|
12905
|
+
);
|
|
12906
|
+
}
|
|
12907
|
+
return void 0;
|
|
12908
|
+
}
|
|
12909
|
+
function extractLiteralSchemas(source) {
|
|
12910
|
+
const listDefaultMatch = source.match(
|
|
12911
|
+
/schemas\s*:\s*generatorEnv\.list\s*\(\s*['"][^'"]+['"]\s*,\s*\{[\s\S]*?default\s*:\s*(\[[^\]]*\])/m
|
|
12912
|
+
);
|
|
12913
|
+
const literalMatch = listDefaultMatch ?? source.match(/schemas\s*:\s*(\[[^\]]*\])/m);
|
|
12914
|
+
if (!literalMatch) {
|
|
12915
|
+
return void 0;
|
|
12916
|
+
}
|
|
12917
|
+
try {
|
|
12918
|
+
const parsed = JSON.parse(literalMatch[1].replace(/'/g, '"'));
|
|
12919
|
+
if (!Array.isArray(parsed)) {
|
|
12920
|
+
return void 0;
|
|
12921
|
+
}
|
|
12922
|
+
return parsed.map((value) => typeof value === "string" ? value.trim() : "").filter((value) => value.length > 0);
|
|
12923
|
+
} catch {
|
|
12924
|
+
return void 0;
|
|
12925
|
+
}
|
|
12926
|
+
}
|
|
12927
|
+
async function resolveDiscoveredSchemas(options) {
|
|
12928
|
+
if (options.explicit && options.explicit.length > 0) {
|
|
12929
|
+
return {
|
|
12930
|
+
schemas: normalizeSchemaSelection(options.explicit),
|
|
12931
|
+
discovered: false
|
|
12932
|
+
};
|
|
12933
|
+
}
|
|
12934
|
+
if (!options.discoverSchemas) {
|
|
12935
|
+
if (options.loaded) {
|
|
12936
|
+
return {
|
|
12937
|
+
schemas: schemasFromNormalized(options.loaded.config),
|
|
12938
|
+
discovered: false
|
|
12939
|
+
};
|
|
12940
|
+
}
|
|
12941
|
+
return {
|
|
12942
|
+
schemas: [...DEFAULT_POSTGRES_SCHEMAS],
|
|
12943
|
+
discovered: false
|
|
12944
|
+
};
|
|
12945
|
+
}
|
|
12946
|
+
try {
|
|
12947
|
+
let provider = options.provider;
|
|
12948
|
+
if (!provider && options.loaded) {
|
|
12949
|
+
provider = options.loaded.config.provider;
|
|
12950
|
+
}
|
|
12951
|
+
if (!provider) {
|
|
12952
|
+
const probeConfig = {
|
|
12953
|
+
provider: options.mode === "gateway" ? { kind: "postgres", mode: "gateway" } : { kind: "postgres", mode: "direct" }
|
|
12954
|
+
};
|
|
12955
|
+
const normalized = normalizeGeneratorConfig(probeConfig);
|
|
12956
|
+
provider = normalized.provider;
|
|
12957
|
+
}
|
|
12958
|
+
const discovered = await discoverPostgresSchemas(provider);
|
|
12959
|
+
if (discovered.length === 0) {
|
|
12960
|
+
const fallback = options.loaded ? schemasFromNormalized(options.loaded.config) : [...DEFAULT_POSTGRES_SCHEMAS];
|
|
12961
|
+
return { schemas: fallback, discovered: true };
|
|
12962
|
+
}
|
|
12963
|
+
if (options.loaded) {
|
|
12964
|
+
return {
|
|
12965
|
+
schemas: mergeSchemaSelections(schemasFromNormalized(options.loaded.config), discovered),
|
|
12966
|
+
discovered: true
|
|
12967
|
+
};
|
|
12968
|
+
}
|
|
12969
|
+
return { schemas: discovered, discovered: true };
|
|
12970
|
+
} catch (error) {
|
|
12971
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
12972
|
+
const fallback = options.loaded ? schemasFromNormalized(options.loaded.config) : [...DEFAULT_POSTGRES_SCHEMAS];
|
|
12973
|
+
return {
|
|
12974
|
+
schemas: fallback,
|
|
12975
|
+
discovered: false,
|
|
12976
|
+
discoveryError: message
|
|
12977
|
+
};
|
|
12978
|
+
}
|
|
12979
|
+
}
|
|
12980
|
+
async function ensureGeneratorConfigFile(options = {}) {
|
|
12981
|
+
const cwd = options.cwd ?? process.cwd();
|
|
12982
|
+
const dryRun = options.dryRun === true;
|
|
12983
|
+
const discoverSchemas = options.discoverSchemas !== false;
|
|
12984
|
+
const force = options.force === true;
|
|
12985
|
+
const preferredMode = options.mode ?? "auto";
|
|
12986
|
+
const pathInfo = resolveConfigPath(cwd, options.configPath);
|
|
12987
|
+
const changes = [];
|
|
12988
|
+
let loaded = options.loaded;
|
|
12989
|
+
if (!loaded && pathInfo.exists && !force) {
|
|
12990
|
+
try {
|
|
12991
|
+
loaded = await loadGeneratorConfig({
|
|
12992
|
+
cwd,
|
|
12993
|
+
configPath: pathInfo.absolutePath
|
|
12994
|
+
});
|
|
12995
|
+
} catch {
|
|
12996
|
+
}
|
|
12997
|
+
}
|
|
12998
|
+
const mode = providerModeFromConfig(loaded?.config.provider ?? options.provider, preferredMode);
|
|
12999
|
+
const schemaResolution = await resolveDiscoveredSchemas({
|
|
13000
|
+
discoverSchemas,
|
|
13001
|
+
provider: options.provider ?? loaded?.config.provider,
|
|
13002
|
+
loaded,
|
|
13003
|
+
explicit: options.schemas,
|
|
13004
|
+
mode
|
|
13005
|
+
});
|
|
13006
|
+
if (schemaResolution.discoveryError) {
|
|
13007
|
+
changes.push(`schema-discovery-failed: ${schemaResolution.discoveryError}`);
|
|
13008
|
+
} else if (schemaResolution.discovered) {
|
|
13009
|
+
changes.push(`schemas-discovered: ${schemaResolution.schemas.join(",")}`);
|
|
13010
|
+
}
|
|
13011
|
+
if (!pathInfo.exists || force) {
|
|
13012
|
+
const content = renderGeneratorConfigFile({
|
|
13013
|
+
mode,
|
|
13014
|
+
schemas: schemaResolution.schemas
|
|
13015
|
+
});
|
|
13016
|
+
if (!pathInfo.exists) {
|
|
13017
|
+
changes.push("created-modern-config");
|
|
13018
|
+
} else {
|
|
13019
|
+
changes.push("force-rewrote-config");
|
|
13020
|
+
}
|
|
13021
|
+
if (!dryRun) {
|
|
13022
|
+
await promises.mkdir(path.dirname(pathInfo.absolutePath), { recursive: true });
|
|
13023
|
+
await promises.writeFile(pathInfo.absolutePath, content, "utf8");
|
|
13024
|
+
}
|
|
13025
|
+
return {
|
|
13026
|
+
action: pathInfo.exists ? "updated" : "created",
|
|
13027
|
+
path: pathInfo.relativePath,
|
|
13028
|
+
absolutePath: pathInfo.absolutePath,
|
|
13029
|
+
content,
|
|
13030
|
+
schemas: schemaResolution.schemas,
|
|
13031
|
+
changes,
|
|
13032
|
+
mode,
|
|
13033
|
+
reason: pathInfo.exists ? "force rewrite" : "config file missing"
|
|
13034
|
+
};
|
|
13035
|
+
}
|
|
13036
|
+
const existingSource = await promises.readFile(pathInfo.absolutePath, "utf8");
|
|
13037
|
+
const existingLiteralSchemas = extractLiteralSchemas(existingSource);
|
|
13038
|
+
const existingSchemas = existingLiteralSchemas ?? (loaded ? schemasFromNormalized(loaded.config) : [...DEFAULT_POSTGRES_SCHEMAS]);
|
|
13039
|
+
if (schemasEqual(existingSchemas, schemaResolution.schemas)) {
|
|
13040
|
+
return {
|
|
13041
|
+
action: "unchanged",
|
|
13042
|
+
path: pathInfo.relativePath,
|
|
13043
|
+
absolutePath: pathInfo.absolutePath,
|
|
13044
|
+
content: existingSource,
|
|
13045
|
+
schemas: existingSchemas,
|
|
13046
|
+
changes: changes.length > 0 ? changes : ["schemas-already-current"],
|
|
13047
|
+
mode,
|
|
13048
|
+
reason: "schemas already match discovered/configured set"
|
|
13049
|
+
};
|
|
13050
|
+
}
|
|
13051
|
+
const patched = patchSchemasInConfigSource(existingSource, schemaResolution.schemas);
|
|
13052
|
+
if (!patched) {
|
|
13053
|
+
return {
|
|
13054
|
+
action: "skipped",
|
|
13055
|
+
path: pathInfo.relativePath,
|
|
13056
|
+
absolutePath: pathInfo.absolutePath,
|
|
13057
|
+
content: existingSource,
|
|
13058
|
+
schemas: existingSchemas,
|
|
13059
|
+
changes: [
|
|
13060
|
+
...changes,
|
|
13061
|
+
"could-not-patch-schemas-surgically",
|
|
13062
|
+
"re-run with force=true to rewrite full template"
|
|
13063
|
+
],
|
|
13064
|
+
mode,
|
|
13065
|
+
reason: "existing config schemas could not be updated surgically without risking a destructive rewrite"
|
|
13066
|
+
};
|
|
13067
|
+
}
|
|
13068
|
+
if (patched === existingSource) {
|
|
13069
|
+
return {
|
|
13070
|
+
action: "unchanged",
|
|
13071
|
+
path: pathInfo.relativePath,
|
|
13072
|
+
absolutePath: pathInfo.absolutePath,
|
|
13073
|
+
content: existingSource,
|
|
13074
|
+
schemas: existingSchemas,
|
|
13075
|
+
changes: [...changes, "patch-noop"],
|
|
13076
|
+
mode,
|
|
13077
|
+
reason: "patch produced identical content"
|
|
13078
|
+
};
|
|
13079
|
+
}
|
|
13080
|
+
changes.push(
|
|
13081
|
+
`schemas-updated: ${existingSchemas.join(",")} -> ${schemaResolution.schemas.join(",")}`
|
|
13082
|
+
);
|
|
13083
|
+
if (!dryRun) {
|
|
13084
|
+
await promises.writeFile(pathInfo.absolutePath, patched, "utf8");
|
|
13085
|
+
}
|
|
13086
|
+
return {
|
|
13087
|
+
action: "updated",
|
|
13088
|
+
path: pathInfo.relativePath,
|
|
13089
|
+
absolutePath: pathInfo.absolutePath,
|
|
13090
|
+
content: patched,
|
|
13091
|
+
schemas: schemaResolution.schemas,
|
|
13092
|
+
changes,
|
|
13093
|
+
mode,
|
|
13094
|
+
reason: "auto-filled provider.schemas"
|
|
13095
|
+
};
|
|
13096
|
+
}
|
|
13097
|
+
|
|
12319
13098
|
// src/generator/env.ts
|
|
12320
13099
|
function readEnvStringValue2(key) {
|
|
12321
13100
|
if (typeof process === "undefined" || !process.env) {
|
|
@@ -14127,23 +14906,80 @@ async function writeArtifacts(files, cwd, config, dryRun) {
|
|
|
14127
14906
|
skippedFiles
|
|
14128
14907
|
};
|
|
14129
14908
|
}
|
|
14909
|
+
function withPostgresSchemas(config, schemas) {
|
|
14910
|
+
if (config.provider.kind !== "postgres") {
|
|
14911
|
+
return config;
|
|
14912
|
+
}
|
|
14913
|
+
return {
|
|
14914
|
+
...config,
|
|
14915
|
+
provider: {
|
|
14916
|
+
...config.provider,
|
|
14917
|
+
schemas
|
|
14918
|
+
}
|
|
14919
|
+
};
|
|
14920
|
+
}
|
|
14130
14921
|
async function runSchemaGenerator(options = {}) {
|
|
14131
14922
|
const cwd = options.cwd ?? process.cwd();
|
|
14923
|
+
const dryRun = options.dryRun === true;
|
|
14924
|
+
const writeConfig = options.writeConfig !== false;
|
|
14925
|
+
const discoverSchemas = options.discoverSchemas !== false;
|
|
14132
14926
|
const configOptions = {
|
|
14133
14927
|
cwd,
|
|
14134
14928
|
configPath: options.configPath
|
|
14135
14929
|
};
|
|
14136
|
-
const
|
|
14930
|
+
const loaded = await loadGeneratorConfig(configOptions);
|
|
14931
|
+
let { configPath, config } = loaded;
|
|
14932
|
+
let configEnsure;
|
|
14933
|
+
let effectiveSchemas = resolveProviderSchemas(config.provider);
|
|
14934
|
+
const canDiscoverLive = discoverSchemas && config.provider.kind === "postgres" && !options.provider;
|
|
14935
|
+
if (canDiscoverLive) {
|
|
14936
|
+
try {
|
|
14937
|
+
const discovered = await discoverPostgresSchemas(config.provider);
|
|
14938
|
+
if (discovered.length > 0) {
|
|
14939
|
+
effectiveSchemas = mergeSchemaSelections(effectiveSchemas, discovered);
|
|
14940
|
+
}
|
|
14941
|
+
} catch {
|
|
14942
|
+
}
|
|
14943
|
+
}
|
|
14944
|
+
config = withPostgresSchemas(config, effectiveSchemas);
|
|
14945
|
+
const shouldEnsureConfig = writeConfig && config.provider.kind === "postgres" && !options.provider;
|
|
14946
|
+
if (shouldEnsureConfig) {
|
|
14947
|
+
const ensureResult = await ensureGeneratorConfigFile({
|
|
14948
|
+
cwd,
|
|
14949
|
+
configPath: options.configPath,
|
|
14950
|
+
dryRun,
|
|
14951
|
+
// Schemas already resolved above — avoid a second discovery round-trip.
|
|
14952
|
+
discoverSchemas: false,
|
|
14953
|
+
provider: config.provider,
|
|
14954
|
+
loaded: { configPath, config },
|
|
14955
|
+
schemas: effectiveSchemas,
|
|
14956
|
+
mode: config.provider.mode
|
|
14957
|
+
});
|
|
14958
|
+
configEnsure = {
|
|
14959
|
+
action: ensureResult.action,
|
|
14960
|
+
path: ensureResult.path,
|
|
14961
|
+
schemas: ensureResult.schemas,
|
|
14962
|
+
changes: ensureResult.changes,
|
|
14963
|
+
reason: ensureResult.reason
|
|
14964
|
+
};
|
|
14965
|
+
if (ensureResult.action === "created" || ensureResult.action === "updated" || ensureResult.action === "unchanged" && configPath === "[environment defaults]") {
|
|
14966
|
+
configPath = ensureResult.absolutePath;
|
|
14967
|
+
if (ensureResult.schemas.length > 0) {
|
|
14968
|
+
effectiveSchemas = ensureResult.schemas;
|
|
14969
|
+
config = withPostgresSchemas(config, effectiveSchemas);
|
|
14970
|
+
}
|
|
14971
|
+
}
|
|
14972
|
+
}
|
|
14137
14973
|
const provider = options.provider ?? resolveGeneratorProvider(config.provider, config.experimental);
|
|
14138
14974
|
const snapshot = await provider.inspect({
|
|
14139
|
-
schemas:
|
|
14975
|
+
schemas: effectiveSchemas
|
|
14140
14976
|
});
|
|
14141
14977
|
const generated = generateArtifactsFromSnapshot(snapshot, config);
|
|
14142
14978
|
const writeResult = await writeArtifacts(
|
|
14143
14979
|
generated.files,
|
|
14144
14980
|
cwd,
|
|
14145
14981
|
config,
|
|
14146
|
-
|
|
14982
|
+
dryRun
|
|
14147
14983
|
);
|
|
14148
14984
|
return {
|
|
14149
14985
|
...generated,
|
|
@@ -14151,7 +14987,8 @@ async function runSchemaGenerator(options = {}) {
|
|
|
14151
14987
|
config,
|
|
14152
14988
|
writtenFiles: writeResult.writtenFiles,
|
|
14153
14989
|
writtenDetails: writeResult.writtenDetails,
|
|
14154
|
-
skippedFiles: writeResult.skippedFiles
|
|
14990
|
+
skippedFiles: writeResult.skippedFiles,
|
|
14991
|
+
configEnsure
|
|
14155
14992
|
};
|
|
14156
14993
|
}
|
|
14157
14994
|
|
|
@@ -14220,15 +15057,15 @@ function readCookieFromHeaders(headers, name) {
|
|
|
14220
15057
|
}
|
|
14221
15058
|
return parseCookies(cookieHeader).get(name);
|
|
14222
15059
|
}
|
|
14223
|
-
function
|
|
15060
|
+
function isRecord14(value) {
|
|
14224
15061
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
14225
15062
|
}
|
|
14226
15063
|
function resolveSessionCandidate(value) {
|
|
14227
|
-
if (!
|
|
15064
|
+
if (!isRecord14(value)) {
|
|
14228
15065
|
return null;
|
|
14229
15066
|
}
|
|
14230
|
-
const session =
|
|
14231
|
-
const user =
|
|
15067
|
+
const session = isRecord14(value.session) ? value.session : void 0;
|
|
15068
|
+
const user = isRecord14(value.user) ? value.user : void 0;
|
|
14232
15069
|
if (session && typeof session.token === "string" && session.token.length > 0 && user) {
|
|
14233
15070
|
return {
|
|
14234
15071
|
session,
|
|
@@ -14238,7 +15075,7 @@ function resolveSessionCandidate(value) {
|
|
|
14238
15075
|
return null;
|
|
14239
15076
|
}
|
|
14240
15077
|
function inferSessionPair(returned) {
|
|
14241
|
-
return resolveSessionCandidate(returned) ?? (
|
|
15078
|
+
return resolveSessionCandidate(returned) ?? (isRecord14(returned) ? resolveSessionCandidate(returned.data) : null) ?? (isRecord14(returned) ? resolveSessionCandidate(returned.session) : null);
|
|
14242
15079
|
}
|
|
14243
15080
|
function resolveResponseHeaders(ctx) {
|
|
14244
15081
|
if (ctx.context.responseHeaders instanceof Headers) {
|
|
@@ -14669,11 +15506,27 @@ exports.Backend = Backend;
|
|
|
14669
15506
|
exports.DEFAULT_MULTIPART_PART_SIZE_BYTES = DEFAULT_MULTIPART_PART_SIZE_BYTES;
|
|
14670
15507
|
exports.DEFAULT_MULTIPART_THRESHOLD_BYTES = DEFAULT_MULTIPART_THRESHOLD_BYTES;
|
|
14671
15508
|
exports.DEFAULT_POSTGRES_SCHEMAS = DEFAULT_POSTGRES_SCHEMAS;
|
|
15509
|
+
exports.applyAthenaReadQueryFilters = applyAthenaReadQueryFilters;
|
|
15510
|
+
exports.applyAthenaReadQuerySelectLimit = applyAthenaReadQuerySelectLimit;
|
|
15511
|
+
exports.applyAthenaReadQuerySelectOrder = applyAthenaReadQuerySelectOrder;
|
|
15512
|
+
exports.applyAthenaTableFilters = applyAthenaTableFilters;
|
|
15513
|
+
exports.applyAthenaTableSelectLimit = applyAthenaTableSelectLimit;
|
|
15514
|
+
exports.applyAthenaTableSelectOrder = applyAthenaTableSelectOrder;
|
|
14672
15515
|
exports.assertInt = assertInt;
|
|
14673
15516
|
exports.athenaAuth = athenaAuth;
|
|
14674
15517
|
exports.billingSdkManifest = billingSdkManifest;
|
|
14675
15518
|
exports.boolean = boolean;
|
|
15519
|
+
exports.buildAthenaReadQueryFindManyOrderBy = buildAthenaReadQueryFindManyOrderBy;
|
|
15520
|
+
exports.buildAthenaReadQueryFindManySelect = buildAthenaReadQueryFindManySelect;
|
|
15521
|
+
exports.buildAthenaReadQueryFindManyWhere = buildAthenaReadQueryFindManyWhere;
|
|
15522
|
+
exports.buildAthenaReadQuerySelectString = buildAthenaReadQuerySelectString;
|
|
15523
|
+
exports.buildAthenaTableFindManyOrderBy = buildAthenaTableFindManyOrderBy;
|
|
15524
|
+
exports.buildAthenaTableFindManySelect = buildAthenaTableFindManySelect;
|
|
15525
|
+
exports.buildAthenaTableFindManyWhere = buildAthenaTableFindManyWhere;
|
|
15526
|
+
exports.buildAthenaTableSelectString = buildAthenaTableSelectString;
|
|
14676
15527
|
exports.chatSdkManifest = chatSdkManifest;
|
|
15528
|
+
exports.clampAthenaReadQueryTotalItems = clampAthenaReadQueryTotalItems;
|
|
15529
|
+
exports.clampAthenaTableTotalItems = clampAthenaTableTotalItems;
|
|
14677
15530
|
exports.coerceInt = coerceInt;
|
|
14678
15531
|
exports.createAthenaStorageError = createAthenaStorageError;
|
|
14679
15532
|
exports.createAuthReactEmailInput = createAuthReactEmailInput;
|
|
@@ -14689,10 +15542,17 @@ exports.defineGeneratorConfig = defineGeneratorConfig;
|
|
|
14689
15542
|
exports.defineModel = defineModel;
|
|
14690
15543
|
exports.defineRegistry = defineRegistry;
|
|
14691
15544
|
exports.defineSchema = defineSchema;
|
|
15545
|
+
exports.detectGeneratorProviderMode = detectGeneratorProviderMode;
|
|
15546
|
+
exports.discoverPostgresSchemas = discoverPostgresSchemas;
|
|
14692
15547
|
exports.ensureActiveOrganization = ensureActiveOrganization;
|
|
15548
|
+
exports.ensureGeneratorConfigFile = ensureGeneratorConfigFile;
|
|
14693
15549
|
exports.enumeration = enumeration;
|
|
15550
|
+
exports.executeAthenaReadQuery = executeAthenaReadQuery;
|
|
15551
|
+
exports.executeAthenaTableQuery = executeAthenaTableQuery;
|
|
14694
15552
|
exports.filterIntrospectionSnapshot = filterIntrospectionSnapshot;
|
|
14695
15553
|
exports.findGeneratorConfigPath = findGeneratorConfigPath;
|
|
15554
|
+
exports.flattenAthenaReadQueryRows = flattenAthenaReadQueryRows;
|
|
15555
|
+
exports.flattenAthenaRows = flattenAthenaRows;
|
|
14696
15556
|
exports.generateArtifactsFromSnapshot = generateArtifactsFromSnapshot;
|
|
14697
15557
|
exports.generatorEnv = generatorEnv;
|
|
14698
15558
|
exports.getAthenaDebugAst = getAthenaDebugAst;
|
|
@@ -14701,14 +15561,20 @@ exports.isAthenaGatewayError = isAthenaGatewayError;
|
|
|
14701
15561
|
exports.isOk = isOk;
|
|
14702
15562
|
exports.json = json;
|
|
14703
15563
|
exports.loadGeneratorConfig = loadGeneratorConfig;
|
|
15564
|
+
exports.mergeSchemaSelections = mergeSchemaSelections;
|
|
14704
15565
|
exports.normalizeAthenaError = normalizeAthenaError;
|
|
14705
15566
|
exports.normalizeAthenaGatewayBaseUrl = normalizeAthenaGatewayBaseUrl;
|
|
15567
|
+
exports.normalizeAthenaReadQueryOrderBy = normalizeAthenaReadQueryOrderBy;
|
|
15568
|
+
exports.normalizeAthenaTableOrderBy = normalizeAthenaTableOrderBy;
|
|
15569
|
+
exports.normalizeDiscoveredSchemas = normalizeDiscoveredSchemas;
|
|
14706
15570
|
exports.normalizeGeneratorConfig = normalizeGeneratorConfig;
|
|
14707
15571
|
exports.normalizeSchemaSelection = normalizeSchemaSelection;
|
|
14708
15572
|
exports.normalizeTableSelection = normalizeTableSelection;
|
|
14709
15573
|
exports.number = number;
|
|
14710
15574
|
exports.parseBooleanFlag = parseBooleanFlag2;
|
|
15575
|
+
exports.patchSchemasInConfigSource = patchSchemasInConfigSource;
|
|
14711
15576
|
exports.renderAthenaReactEmail = renderAthenaReactEmail;
|
|
15577
|
+
exports.renderGeneratorConfigFile = renderGeneratorConfigFile;
|
|
14712
15578
|
exports.requireAffected = requireAffected;
|
|
14713
15579
|
exports.requireSuccess = requireSuccess;
|
|
14714
15580
|
exports.resolveGeneratorProvider = resolveGeneratorProvider;
|
|
@@ -14716,6 +15582,7 @@ exports.resolvePostgresColumnType = resolvePostgresColumnType;
|
|
|
14716
15582
|
exports.resolveProviderSchemas = resolveProviderSchemas;
|
|
14717
15583
|
exports.resolveStoragePath = resolveStoragePath;
|
|
14718
15584
|
exports.runSchemaGenerator = runSchemaGenerator;
|
|
15585
|
+
exports.schemasEqual = schemasEqual;
|
|
14719
15586
|
exports.storageSdkManifest = storageSdkManifest;
|
|
14720
15587
|
exports.string = string;
|
|
14721
15588
|
exports.table = table;
|