@xylex-group/athena 1.6.1 → 1.7.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 +77 -6
- package/bin/athena-js.js +74 -6
- package/dist/cli/index.cjs +233 -40
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +21 -2
- package/dist/cli/index.d.ts +21 -2
- package/dist/cli/index.js +232 -41
- package/dist/cli/index.js.map +1 -1
- package/dist/errors-BJGgjHcI.d.cts +31 -0
- package/dist/errors-Bcf5Sftv.d.ts +31 -0
- package/dist/index.cjs +638 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -335
- package/dist/index.d.ts +266 -335
- package/dist/index.js +635 -27
- package/dist/index.js.map +1 -1
- package/dist/pipeline-BsKuBqmE.d.cts +343 -0
- package/dist/pipeline-xQSjGbqF.d.ts +343 -0
- package/dist/react.d.cts +3 -2
- package/dist/react.d.ts +3 -2
- package/dist/{errors-C4GJaFI_.d.cts → types-wPA1Z4vQ.d.cts} +1 -29
- package/dist/{errors-C4GJaFI_.d.ts → types-wPA1Z4vQ.d.ts} +1 -29
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1968,8 +1968,73 @@ function toTypeKind(code) {
|
|
|
1968
1968
|
function escapeSqlLiteral(value) {
|
|
1969
1969
|
return value.replace(/'/g, "''");
|
|
1970
1970
|
}
|
|
1971
|
+
function parsePostgresArrayLiteral(text) {
|
|
1972
|
+
const body = text.slice(1, -1).trim();
|
|
1973
|
+
if (!body) return [];
|
|
1974
|
+
const values = [];
|
|
1975
|
+
let current = "";
|
|
1976
|
+
let inQuotes = false;
|
|
1977
|
+
let escaped = false;
|
|
1978
|
+
for (const char of body) {
|
|
1979
|
+
if (escaped) {
|
|
1980
|
+
current += char;
|
|
1981
|
+
escaped = false;
|
|
1982
|
+
continue;
|
|
1983
|
+
}
|
|
1984
|
+
if (char === "\\") {
|
|
1985
|
+
escaped = true;
|
|
1986
|
+
continue;
|
|
1987
|
+
}
|
|
1988
|
+
if (char === '"') {
|
|
1989
|
+
inQuotes = !inQuotes;
|
|
1990
|
+
continue;
|
|
1991
|
+
}
|
|
1992
|
+
if (char === "," && !inQuotes) {
|
|
1993
|
+
values.push(current);
|
|
1994
|
+
current = "";
|
|
1995
|
+
continue;
|
|
1996
|
+
}
|
|
1997
|
+
current += char;
|
|
1998
|
+
}
|
|
1999
|
+
values.push(current);
|
|
2000
|
+
return values.map((value) => value.trim()).filter((value) => value.length > 0);
|
|
2001
|
+
}
|
|
2002
|
+
function coerceStringArray(value) {
|
|
2003
|
+
if (Array.isArray(value)) {
|
|
2004
|
+
return value.map((item) => typeof item === "string" ? item : String(item)).map((item) => item.trim()).filter((item) => item.length > 0);
|
|
2005
|
+
}
|
|
2006
|
+
if (typeof value === "string") {
|
|
2007
|
+
const trimmed = value.trim();
|
|
2008
|
+
if (!trimmed) return [];
|
|
2009
|
+
if (trimmed.startsWith("[") && trimmed.endsWith("]")) {
|
|
2010
|
+
try {
|
|
2011
|
+
const parsed = JSON.parse(trimmed);
|
|
2012
|
+
return coerceStringArray(parsed);
|
|
2013
|
+
} catch {
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
if (trimmed.startsWith("{") && trimmed.endsWith("}")) {
|
|
2017
|
+
return parsePostgresArrayLiteral(trimmed);
|
|
2018
|
+
}
|
|
2019
|
+
return trimmed.split(",").map((item) => item.trim()).filter((item) => item.length > 0);
|
|
2020
|
+
}
|
|
2021
|
+
return [];
|
|
2022
|
+
}
|
|
2023
|
+
function normalizePostgresCatalogSchemas(schemas) {
|
|
2024
|
+
const normalized = [];
|
|
2025
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2026
|
+
for (const value of schemas ?? []) {
|
|
2027
|
+
const schema = value.trim();
|
|
2028
|
+
if (!schema || seen.has(schema)) {
|
|
2029
|
+
continue;
|
|
2030
|
+
}
|
|
2031
|
+
seen.add(schema);
|
|
2032
|
+
normalized.push(schema);
|
|
2033
|
+
}
|
|
2034
|
+
return normalized.length > 0 ? normalized : ["public"];
|
|
2035
|
+
}
|
|
1971
2036
|
function buildSchemaArrayLiteral(schemas) {
|
|
1972
|
-
const normalized = schemas
|
|
2037
|
+
const normalized = normalizePostgresCatalogSchemas(schemas);
|
|
1973
2038
|
const literals = normalized.map((schema) => `'${escapeSqlLiteral(schema)}'`).join(", ");
|
|
1974
2039
|
return `ARRAY[${literals}]`;
|
|
1975
2040
|
}
|
|
@@ -2007,8 +2072,10 @@ var PostgresCatalogSnapshotAssembler = class {
|
|
|
2007
2072
|
addPrimaryKeyRows(primaryKeyRows) {
|
|
2008
2073
|
for (const row of primaryKeyRows) {
|
|
2009
2074
|
const table = this.ensureTable(row.schema_name, row.table_name);
|
|
2010
|
-
|
|
2011
|
-
|
|
2075
|
+
const primaryKeyColumns = coerceStringArray(row.columns);
|
|
2076
|
+
row.columns = primaryKeyColumns;
|
|
2077
|
+
table.primaryKey = primaryKeyColumns;
|
|
2078
|
+
for (const columnName of primaryKeyColumns) {
|
|
2012
2079
|
const column = table.columns[columnName];
|
|
2013
2080
|
if (column) {
|
|
2014
2081
|
column.isPrimaryKey = true;
|
|
@@ -2020,23 +2087,27 @@ var PostgresCatalogSnapshotAssembler = class {
|
|
|
2020
2087
|
for (const row of foreignKeyRows) {
|
|
2021
2088
|
const sourceTable = this.ensureTable(row.source_schema, row.source_table);
|
|
2022
2089
|
const targetTable = this.ensureTable(row.target_schema, row.target_table);
|
|
2090
|
+
const sourceColumns = coerceStringArray(row.source_columns);
|
|
2091
|
+
const targetColumns = coerceStringArray(row.target_columns);
|
|
2092
|
+
row.source_columns = sourceColumns;
|
|
2093
|
+
row.target_columns = targetColumns;
|
|
2023
2094
|
const sourceRelationKind = row.source_is_unique ? "one-to-one" : "many-to-one";
|
|
2024
2095
|
this.upsertRelation(sourceTable, relationKey(row.constraint_name, row.target_table), {
|
|
2025
2096
|
name: row.constraint_name,
|
|
2026
2097
|
kind: sourceRelationKind,
|
|
2027
|
-
sourceColumns
|
|
2098
|
+
sourceColumns,
|
|
2028
2099
|
targetSchema: row.target_schema,
|
|
2029
2100
|
targetModel: row.target_table,
|
|
2030
|
-
targetColumns
|
|
2101
|
+
targetColumns
|
|
2031
2102
|
});
|
|
2032
2103
|
const targetRelationKind = row.source_is_unique ? "one-to-one" : "one-to-many";
|
|
2033
2104
|
this.upsertRelation(targetTable, relationKey(row.source_table), {
|
|
2034
2105
|
name: relationKey(row.source_table, row.constraint_name),
|
|
2035
2106
|
kind: targetRelationKind,
|
|
2036
|
-
sourceColumns:
|
|
2107
|
+
sourceColumns: targetColumns,
|
|
2037
2108
|
targetSchema: row.source_schema,
|
|
2038
2109
|
targetModel: row.source_table,
|
|
2039
|
-
targetColumns:
|
|
2110
|
+
targetColumns: sourceColumns
|
|
2040
2111
|
});
|
|
2041
2112
|
}
|
|
2042
2113
|
}
|
|
@@ -2164,12 +2235,14 @@ var PostgresIntrospectionProvider = class {
|
|
|
2164
2235
|
backend = "postgresql";
|
|
2165
2236
|
connectionString;
|
|
2166
2237
|
database;
|
|
2238
|
+
schemas;
|
|
2167
2239
|
constructor(options) {
|
|
2168
2240
|
this.connectionString = options.connectionString;
|
|
2169
2241
|
this.database = options.database ?? "postgres";
|
|
2242
|
+
this.schemas = normalizePostgresCatalogSchemas(options.schemas);
|
|
2170
2243
|
}
|
|
2171
2244
|
async inspect(options) {
|
|
2172
|
-
const schemas = options?.schemas && options.schemas.length > 0 ? options.schemas :
|
|
2245
|
+
const schemas = options?.schemas && options.schemas.length > 0 ? normalizePostgresCatalogSchemas(options.schemas) : this.schemas;
|
|
2173
2246
|
const pool = new pg.Pool({
|
|
2174
2247
|
connectionString: this.connectionString
|
|
2175
2248
|
});
|
|
@@ -2200,6 +2273,37 @@ var PostgresIntrospectionProvider = class {
|
|
|
2200
2273
|
function createPostgresIntrospectionProvider(options) {
|
|
2201
2274
|
return new PostgresIntrospectionProvider(options);
|
|
2202
2275
|
}
|
|
2276
|
+
|
|
2277
|
+
// src/generator/schema-selection.ts
|
|
2278
|
+
var DEFAULT_POSTGRES_SCHEMAS = ["public"];
|
|
2279
|
+
function collectSchemaNames(input) {
|
|
2280
|
+
if (!input) {
|
|
2281
|
+
return [];
|
|
2282
|
+
}
|
|
2283
|
+
const values = typeof input === "string" ? [input] : input;
|
|
2284
|
+
return values.flatMap((value) => String(value).split(","));
|
|
2285
|
+
}
|
|
2286
|
+
function normalizeSchemaSelection(input) {
|
|
2287
|
+
const schemas = [];
|
|
2288
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2289
|
+
for (const value of collectSchemaNames(input)) {
|
|
2290
|
+
const schema = value.trim();
|
|
2291
|
+
if (!schema || seen.has(schema)) {
|
|
2292
|
+
continue;
|
|
2293
|
+
}
|
|
2294
|
+
seen.add(schema);
|
|
2295
|
+
schemas.push(schema);
|
|
2296
|
+
}
|
|
2297
|
+
return schemas.length > 0 ? schemas : [...DEFAULT_POSTGRES_SCHEMAS];
|
|
2298
|
+
}
|
|
2299
|
+
function resolveProviderSchemas(providerConfig) {
|
|
2300
|
+
if (providerConfig.kind === "postgres") {
|
|
2301
|
+
return normalizeSchemaSelection(providerConfig.schemas);
|
|
2302
|
+
}
|
|
2303
|
+
return [...DEFAULT_POSTGRES_SCHEMAS];
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
// src/generator/config.ts
|
|
2203
2307
|
var DEFAULT_CONFIG_CANDIDATES = [
|
|
2204
2308
|
"athena.config.ts",
|
|
2205
2309
|
"athena.config.js",
|
|
@@ -2209,10 +2313,10 @@ var DEFAULT_CONFIG_CANDIDATES = [
|
|
|
2209
2313
|
".athena.config.js"
|
|
2210
2314
|
];
|
|
2211
2315
|
var DEFAULT_TARGETS = {
|
|
2212
|
-
model: "
|
|
2213
|
-
schema: "
|
|
2214
|
-
database: "
|
|
2215
|
-
registry: "
|
|
2316
|
+
model: "athena/models/{schema_kebab}/{model_kebab}.ts",
|
|
2317
|
+
schema: "athena/schemas/{schema_kebab}.ts",
|
|
2318
|
+
database: "athena/relations.ts",
|
|
2319
|
+
registry: "athena/config.ts"
|
|
2216
2320
|
};
|
|
2217
2321
|
var DEFAULT_NAMING = {
|
|
2218
2322
|
modelType: "pascal",
|
|
@@ -2240,6 +2344,15 @@ function normalizeOutputConfig(output) {
|
|
|
2240
2344
|
}
|
|
2241
2345
|
};
|
|
2242
2346
|
}
|
|
2347
|
+
function normalizeProviderConfig(provider) {
|
|
2348
|
+
if (provider.kind === "postgres") {
|
|
2349
|
+
return {
|
|
2350
|
+
...provider,
|
|
2351
|
+
schemas: normalizeSchemaSelection(provider.schemas)
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
return provider;
|
|
2355
|
+
}
|
|
2243
2356
|
function isAthenaGeneratorConfig(value) {
|
|
2244
2357
|
if (!value || typeof value !== "object") {
|
|
2245
2358
|
return false;
|
|
@@ -2249,7 +2362,7 @@ function isAthenaGeneratorConfig(value) {
|
|
|
2249
2362
|
}
|
|
2250
2363
|
function normalizeGeneratorConfig(input) {
|
|
2251
2364
|
return {
|
|
2252
|
-
provider: input.provider,
|
|
2365
|
+
provider: normalizeProviderConfig(input.provider),
|
|
2253
2366
|
output: normalizeOutputConfig(input.output),
|
|
2254
2367
|
naming: {
|
|
2255
2368
|
...DEFAULT_NAMING,
|
|
@@ -2746,12 +2859,19 @@ export const ${registryConstName} = defineRegistry({
|
|
|
2746
2859
|
};
|
|
2747
2860
|
}
|
|
2748
2861
|
function assertNoDuplicatePaths(files) {
|
|
2749
|
-
const seen = /* @__PURE__ */ new
|
|
2862
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2750
2863
|
for (const file of files) {
|
|
2751
|
-
|
|
2752
|
-
|
|
2864
|
+
const existing = seen.get(file.path);
|
|
2865
|
+
if (existing) {
|
|
2866
|
+
throw new Error(
|
|
2867
|
+
[
|
|
2868
|
+
`Generator output collision detected for path: ${file.path}`,
|
|
2869
|
+
`Collision: ${existing.kind} and ${file.kind}.`,
|
|
2870
|
+
"When syncing multiple schemas, include a schema placeholder such as {schema} or {schema_kebab} in model/schema output targets."
|
|
2871
|
+
].join(" ")
|
|
2872
|
+
);
|
|
2753
2873
|
}
|
|
2754
|
-
seen.
|
|
2874
|
+
seen.set(file.path, file);
|
|
2755
2875
|
}
|
|
2756
2876
|
}
|
|
2757
2877
|
var ArtifactComposer = class {
|
|
@@ -2911,11 +3031,13 @@ var AthenaGatewayPostgresIntrospectionProvider = class {
|
|
|
2911
3031
|
type: this.config.backend ?? "postgresql"
|
|
2912
3032
|
}
|
|
2913
3033
|
});
|
|
3034
|
+
this.schemas = normalizeSchemaSelection(this.config.schemas);
|
|
2914
3035
|
}
|
|
2915
3036
|
backend = "postgresql";
|
|
2916
3037
|
client;
|
|
3038
|
+
schemas;
|
|
2917
3039
|
async inspect(options) {
|
|
2918
|
-
const schemas = options?.schemas && options.schemas.length > 0 ? options.schemas : this.
|
|
3040
|
+
const schemas = options?.schemas && options.schemas.length > 0 ? normalizeSchemaSelection(options.schemas) : this.schemas;
|
|
2919
3041
|
const catalogClient = new AthenaGatewayCatalogClient(this.client);
|
|
2920
3042
|
const queries = buildGatewayCatalogQueries(schemas);
|
|
2921
3043
|
const [columnRows, enumMap, primaryKeyRows, foreignKeyRows] = await Promise.all([
|
|
@@ -2951,7 +3073,8 @@ var ScyllaIntrospectionProvider = class {
|
|
|
2951
3073
|
function createPostgresProvider(config) {
|
|
2952
3074
|
return createPostgresIntrospectionProvider({
|
|
2953
3075
|
connectionString: config.connectionString,
|
|
2954
|
-
database: config.database
|
|
3076
|
+
database: config.database,
|
|
3077
|
+
schemas: normalizeSchemaSelection(config.schemas)
|
|
2955
3078
|
});
|
|
2956
3079
|
}
|
|
2957
3080
|
function resolveGeneratorProvider(providerConfig, experimentalFlags) {
|
|
@@ -2971,12 +3094,6 @@ function resolveGeneratorProvider(providerConfig, experimentalFlags) {
|
|
|
2971
3094
|
}
|
|
2972
3095
|
throw new Error(`Unsupported generator provider kind: ${providerConfig.kind ?? "unknown"}`);
|
|
2973
3096
|
}
|
|
2974
|
-
function extractProviderSchemas(providerConfig) {
|
|
2975
|
-
if (!("schemas" in providerConfig) || !providerConfig.schemas || providerConfig.schemas.length === 0) {
|
|
2976
|
-
return void 0;
|
|
2977
|
-
}
|
|
2978
|
-
return providerConfig.schemas;
|
|
2979
|
-
}
|
|
2980
3097
|
async function writeArtifacts(files, cwd) {
|
|
2981
3098
|
const writtenFiles = [];
|
|
2982
3099
|
for (const file of files) {
|
|
@@ -2996,7 +3113,7 @@ async function runSchemaGenerator(options = {}) {
|
|
|
2996
3113
|
const { configPath, config } = await loadGeneratorConfig(configOptions);
|
|
2997
3114
|
const provider = options.provider ?? resolveGeneratorProvider(config.provider, config.experimental);
|
|
2998
3115
|
const snapshot = await provider.inspect({
|
|
2999
|
-
schemas:
|
|
3116
|
+
schemas: resolveProviderSchemas(config.provider)
|
|
3000
3117
|
});
|
|
3001
3118
|
const generated = generateArtifactsFromSnapshot(snapshot, config);
|
|
3002
3119
|
const writtenFiles = options.dryRun ? [] : await writeArtifacts(generated.files, cwd);
|
|
@@ -3007,6 +3124,497 @@ async function runSchemaGenerator(options = {}) {
|
|
|
3007
3124
|
};
|
|
3008
3125
|
}
|
|
3009
3126
|
|
|
3127
|
+
// src/auth/client.ts
|
|
3128
|
+
var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
|
|
3129
|
+
var FALLBACK_SDK_VERSION2 = "1.0.0";
|
|
3130
|
+
var SDK_NAME2 = "xylex-group/athena-auth";
|
|
3131
|
+
var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
|
|
3132
|
+
var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
|
|
3133
|
+
function normalizeBaseUrl(baseUrl) {
|
|
3134
|
+
return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
|
|
3135
|
+
}
|
|
3136
|
+
function isRecord3(value) {
|
|
3137
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
3138
|
+
}
|
|
3139
|
+
function normalizeHeaderValue2(value) {
|
|
3140
|
+
return value ? value : void 0;
|
|
3141
|
+
}
|
|
3142
|
+
function parseResponseBody2(rawText, contentType) {
|
|
3143
|
+
if (!rawText) {
|
|
3144
|
+
return { parsed: null, parseFailed: false };
|
|
3145
|
+
}
|
|
3146
|
+
const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
|
|
3147
|
+
const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
|
|
3148
|
+
if (!looksJson) {
|
|
3149
|
+
return { parsed: rawText, parseFailed: false };
|
|
3150
|
+
}
|
|
3151
|
+
try {
|
|
3152
|
+
return { parsed: JSON.parse(rawText), parseFailed: false };
|
|
3153
|
+
} catch {
|
|
3154
|
+
return { parsed: rawText, parseFailed: true };
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
function resolveRequestId2(headers) {
|
|
3158
|
+
return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
|
|
3159
|
+
}
|
|
3160
|
+
function resolveErrorMessage2(payload, fallback) {
|
|
3161
|
+
if (isRecord3(payload)) {
|
|
3162
|
+
const messageCandidates = [payload.error, payload.message, payload.details];
|
|
3163
|
+
for (const candidate of messageCandidates) {
|
|
3164
|
+
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
3165
|
+
return candidate.trim();
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
if (typeof payload === "string" && payload.trim().length > 0) {
|
|
3170
|
+
return payload.trim();
|
|
3171
|
+
}
|
|
3172
|
+
return fallback;
|
|
3173
|
+
}
|
|
3174
|
+
function toErrorDetails(input) {
|
|
3175
|
+
return {
|
|
3176
|
+
code: input.code,
|
|
3177
|
+
message: input.message,
|
|
3178
|
+
status: input.status,
|
|
3179
|
+
endpoint: input.endpoint,
|
|
3180
|
+
method: input.method,
|
|
3181
|
+
requestId: input.requestId,
|
|
3182
|
+
hint: input.hint,
|
|
3183
|
+
cause: input.cause
|
|
3184
|
+
};
|
|
3185
|
+
}
|
|
3186
|
+
function mergeCallOptions(base, override) {
|
|
3187
|
+
if (!base && !override) return void 0;
|
|
3188
|
+
return {
|
|
3189
|
+
...base,
|
|
3190
|
+
...override,
|
|
3191
|
+
headers: {
|
|
3192
|
+
...base?.headers ?? {},
|
|
3193
|
+
...override?.headers ?? {}
|
|
3194
|
+
}
|
|
3195
|
+
};
|
|
3196
|
+
}
|
|
3197
|
+
function extractFetchOptions(input) {
|
|
3198
|
+
if (!input) {
|
|
3199
|
+
return {
|
|
3200
|
+
payload: void 0,
|
|
3201
|
+
fetchOptions: void 0
|
|
3202
|
+
};
|
|
3203
|
+
}
|
|
3204
|
+
const { fetchOptions, ...rest } = input;
|
|
3205
|
+
const hasPayloadKeys = Object.keys(rest).length > 0;
|
|
3206
|
+
return {
|
|
3207
|
+
payload: hasPayloadKeys ? rest : void 0,
|
|
3208
|
+
fetchOptions
|
|
3209
|
+
};
|
|
3210
|
+
}
|
|
3211
|
+
function buildHeaders2(config, options) {
|
|
3212
|
+
const headers = {
|
|
3213
|
+
"Content-Type": "application/json",
|
|
3214
|
+
"X-Athena-Sdk": SDK_HEADER_VALUE2
|
|
3215
|
+
};
|
|
3216
|
+
const apiKey = options?.apiKey ?? config.apiKey;
|
|
3217
|
+
if (apiKey) {
|
|
3218
|
+
headers.apikey = apiKey;
|
|
3219
|
+
headers["x-api-key"] = apiKey;
|
|
3220
|
+
}
|
|
3221
|
+
const bearerToken = options?.bearerToken ?? config.bearerToken;
|
|
3222
|
+
if (bearerToken) {
|
|
3223
|
+
headers.Authorization = `Bearer ${bearerToken}`;
|
|
3224
|
+
}
|
|
3225
|
+
const mergedExtraHeaders = {
|
|
3226
|
+
...config.headers ?? {},
|
|
3227
|
+
...options?.headers ?? {}
|
|
3228
|
+
};
|
|
3229
|
+
Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
|
|
3230
|
+
const normalized = normalizeHeaderValue2(value);
|
|
3231
|
+
if (normalized) {
|
|
3232
|
+
headers[key] = normalized;
|
|
3233
|
+
}
|
|
3234
|
+
});
|
|
3235
|
+
return headers;
|
|
3236
|
+
}
|
|
3237
|
+
function appendQueryParam(searchParams, key, value) {
|
|
3238
|
+
if (value === void 0 || value === null) return;
|
|
3239
|
+
if (Array.isArray(value)) {
|
|
3240
|
+
value.forEach((item) => {
|
|
3241
|
+
searchParams.append(key, String(item));
|
|
3242
|
+
});
|
|
3243
|
+
return;
|
|
3244
|
+
}
|
|
3245
|
+
searchParams.append(key, String(value));
|
|
3246
|
+
}
|
|
3247
|
+
function buildRequestUrl(baseUrl, endpoint, query) {
|
|
3248
|
+
const url = `${baseUrl}${endpoint}`;
|
|
3249
|
+
if (!query || Object.keys(query).length === 0) return url;
|
|
3250
|
+
const searchParams = new URLSearchParams();
|
|
3251
|
+
Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
|
|
3252
|
+
const queryText = searchParams.toString();
|
|
3253
|
+
return queryText ? `${url}?${queryText}` : url;
|
|
3254
|
+
}
|
|
3255
|
+
function inferDefaultMethod(endpoint) {
|
|
3256
|
+
if (endpoint.startsWith("/reset-password/")) {
|
|
3257
|
+
return "GET";
|
|
3258
|
+
}
|
|
3259
|
+
switch (endpoint) {
|
|
3260
|
+
case "/get-session":
|
|
3261
|
+
case "/list-sessions":
|
|
3262
|
+
case "/verify-email":
|
|
3263
|
+
case "/delete-user/callback":
|
|
3264
|
+
case "/list-accounts":
|
|
3265
|
+
case "/ok":
|
|
3266
|
+
case "/error":
|
|
3267
|
+
return "GET";
|
|
3268
|
+
default:
|
|
3269
|
+
return "POST";
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
async function callAuthEndpoint(config, context, body, query, options) {
|
|
3273
|
+
const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
|
|
3274
|
+
const url = buildRequestUrl(baseUrl, context.endpoint, query);
|
|
3275
|
+
const headers = buildHeaders2(config, options);
|
|
3276
|
+
const credentials = options?.credentials ?? config.credentials ?? "include";
|
|
3277
|
+
const requestInit = {
|
|
3278
|
+
method: context.method,
|
|
3279
|
+
headers,
|
|
3280
|
+
credentials,
|
|
3281
|
+
signal: options?.signal
|
|
3282
|
+
};
|
|
3283
|
+
if (context.method !== "GET") {
|
|
3284
|
+
requestInit.body = JSON.stringify(body ?? {});
|
|
3285
|
+
}
|
|
3286
|
+
const fetcher = config.fetch ?? globalThis.fetch;
|
|
3287
|
+
if (!fetcher) {
|
|
3288
|
+
const details = toErrorDetails({
|
|
3289
|
+
code: "UNKNOWN_ERROR",
|
|
3290
|
+
message: "No fetch implementation available for auth client",
|
|
3291
|
+
status: 0,
|
|
3292
|
+
endpoint: context.endpoint,
|
|
3293
|
+
method: context.method,
|
|
3294
|
+
hint: "Use Node 18+ or provide `fetch` in createAuthClient({ fetch })"
|
|
3295
|
+
});
|
|
3296
|
+
return {
|
|
3297
|
+
ok: false,
|
|
3298
|
+
status: 0,
|
|
3299
|
+
data: null,
|
|
3300
|
+
error: details.message,
|
|
3301
|
+
errorDetails: details,
|
|
3302
|
+
raw: null
|
|
3303
|
+
};
|
|
3304
|
+
}
|
|
3305
|
+
try {
|
|
3306
|
+
const response = await fetcher(url, requestInit);
|
|
3307
|
+
const rawText = await response.text();
|
|
3308
|
+
const requestId = resolveRequestId2(response.headers);
|
|
3309
|
+
const parsedBody = parseResponseBody2(rawText ?? "", response.headers.get("content-type"));
|
|
3310
|
+
if (parsedBody.parseFailed) {
|
|
3311
|
+
const details = toErrorDetails({
|
|
3312
|
+
code: "INVALID_JSON",
|
|
3313
|
+
message: "Auth server returned malformed JSON",
|
|
3314
|
+
status: response.status,
|
|
3315
|
+
endpoint: context.endpoint,
|
|
3316
|
+
method: context.method,
|
|
3317
|
+
requestId,
|
|
3318
|
+
hint: "Verify the auth endpoint response body is valid JSON.",
|
|
3319
|
+
cause: rawText.slice(0, 300)
|
|
3320
|
+
});
|
|
3321
|
+
return {
|
|
3322
|
+
ok: false,
|
|
3323
|
+
status: response.status,
|
|
3324
|
+
data: null,
|
|
3325
|
+
error: details.message,
|
|
3326
|
+
errorDetails: details,
|
|
3327
|
+
raw: parsedBody.parsed
|
|
3328
|
+
};
|
|
3329
|
+
}
|
|
3330
|
+
const parsed = parsedBody.parsed;
|
|
3331
|
+
if (!response.ok) {
|
|
3332
|
+
const details = toErrorDetails({
|
|
3333
|
+
code: "HTTP_ERROR",
|
|
3334
|
+
message: resolveErrorMessage2(
|
|
3335
|
+
parsed,
|
|
3336
|
+
`Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
|
|
3337
|
+
),
|
|
3338
|
+
status: response.status,
|
|
3339
|
+
endpoint: context.endpoint,
|
|
3340
|
+
method: context.method,
|
|
3341
|
+
requestId
|
|
3342
|
+
});
|
|
3343
|
+
return {
|
|
3344
|
+
ok: false,
|
|
3345
|
+
status: response.status,
|
|
3346
|
+
data: null,
|
|
3347
|
+
error: details.message,
|
|
3348
|
+
errorDetails: details,
|
|
3349
|
+
raw: parsed
|
|
3350
|
+
};
|
|
3351
|
+
}
|
|
3352
|
+
return {
|
|
3353
|
+
ok: true,
|
|
3354
|
+
status: response.status,
|
|
3355
|
+
data: parsed ?? null,
|
|
3356
|
+
error: null,
|
|
3357
|
+
errorDetails: null,
|
|
3358
|
+
raw: parsed
|
|
3359
|
+
};
|
|
3360
|
+
} catch (callError) {
|
|
3361
|
+
const message = callError instanceof Error ? callError.message : String(callError);
|
|
3362
|
+
const details = toErrorDetails({
|
|
3363
|
+
code: "NETWORK_ERROR",
|
|
3364
|
+
message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
|
|
3365
|
+
status: 0,
|
|
3366
|
+
endpoint: context.endpoint,
|
|
3367
|
+
method: context.method,
|
|
3368
|
+
cause: message,
|
|
3369
|
+
hint: "Check auth server URL, DNS, and network reachability."
|
|
3370
|
+
});
|
|
3371
|
+
return {
|
|
3372
|
+
ok: false,
|
|
3373
|
+
status: 0,
|
|
3374
|
+
data: null,
|
|
3375
|
+
error: details.message,
|
|
3376
|
+
errorDetails: details,
|
|
3377
|
+
raw: null
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
function executePostWithCompatibleInput(config, context, input, options) {
|
|
3382
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3383
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3384
|
+
return callAuthEndpoint(config, context, payload ?? {}, void 0, mergedOptions);
|
|
3385
|
+
}
|
|
3386
|
+
function executePostWithOptionalInput(config, context, input, options) {
|
|
3387
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
3388
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3389
|
+
return callAuthEndpoint(config, context, {}, void 0, mergedOptions);
|
|
3390
|
+
}
|
|
3391
|
+
function executeGetWithCompatibleInput(config, context, input, options) {
|
|
3392
|
+
const { fetchOptions } = extractFetchOptions(input);
|
|
3393
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3394
|
+
return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
|
|
3395
|
+
}
|
|
3396
|
+
function createAuthClient(config = {}) {
|
|
3397
|
+
const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
|
|
3398
|
+
const resolvedConfig = {
|
|
3399
|
+
...config,
|
|
3400
|
+
baseUrl: normalizedBaseUrl
|
|
3401
|
+
};
|
|
3402
|
+
const request = (input, options) => {
|
|
3403
|
+
const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
|
|
3404
|
+
const mergedOptions = mergeCallOptions(input.fetchOptions, options);
|
|
3405
|
+
return callAuthEndpoint(
|
|
3406
|
+
resolvedConfig,
|
|
3407
|
+
{ endpoint: input.endpoint, method },
|
|
3408
|
+
input.body,
|
|
3409
|
+
input.query,
|
|
3410
|
+
mergedOptions
|
|
3411
|
+
);
|
|
3412
|
+
};
|
|
3413
|
+
const signOut = (input, options) => executePostWithOptionalInput(
|
|
3414
|
+
resolvedConfig,
|
|
3415
|
+
{ endpoint: "/sign-out", method: "POST" },
|
|
3416
|
+
input,
|
|
3417
|
+
options
|
|
3418
|
+
);
|
|
3419
|
+
const revokeSessions = (input, options) => executePostWithOptionalInput(
|
|
3420
|
+
resolvedConfig,
|
|
3421
|
+
{ endpoint: "/revoke-sessions", method: "POST" },
|
|
3422
|
+
input,
|
|
3423
|
+
options
|
|
3424
|
+
);
|
|
3425
|
+
const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
|
|
3426
|
+
resolvedConfig,
|
|
3427
|
+
{ endpoint: "/revoke-other-sessions", method: "POST" },
|
|
3428
|
+
input,
|
|
3429
|
+
options
|
|
3430
|
+
);
|
|
3431
|
+
const revokeSession = (input, options) => executePostWithCompatibleInput(
|
|
3432
|
+
resolvedConfig,
|
|
3433
|
+
{ endpoint: "/revoke-session", method: "POST" },
|
|
3434
|
+
input,
|
|
3435
|
+
options
|
|
3436
|
+
);
|
|
3437
|
+
const deleteUser = (input, options) => {
|
|
3438
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3439
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3440
|
+
return callAuthEndpoint(
|
|
3441
|
+
resolvedConfig,
|
|
3442
|
+
{ endpoint: "/delete-user", method: "POST" },
|
|
3443
|
+
payload ?? {},
|
|
3444
|
+
void 0,
|
|
3445
|
+
mergedOptions
|
|
3446
|
+
);
|
|
3447
|
+
};
|
|
3448
|
+
const deleteUserCallback = (input, options) => {
|
|
3449
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3450
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3451
|
+
const query = payload ?? {};
|
|
3452
|
+
return callAuthEndpoint(
|
|
3453
|
+
resolvedConfig,
|
|
3454
|
+
{ endpoint: "/delete-user/callback", method: "GET" },
|
|
3455
|
+
void 0,
|
|
3456
|
+
{
|
|
3457
|
+
token: query.token,
|
|
3458
|
+
callbackURL: query.callbackURL
|
|
3459
|
+
},
|
|
3460
|
+
mergedOptions
|
|
3461
|
+
);
|
|
3462
|
+
};
|
|
3463
|
+
const resolveResetPasswordToken = (input, options) => {
|
|
3464
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3465
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3466
|
+
const query = payload;
|
|
3467
|
+
const token = query?.token?.trim();
|
|
3468
|
+
if (!token) {
|
|
3469
|
+
throw new Error("resolveResetPasswordToken requires a non-empty token");
|
|
3470
|
+
}
|
|
3471
|
+
const endpoint = `/reset-password/${encodeURIComponent(token)}`;
|
|
3472
|
+
return callAuthEndpoint(
|
|
3473
|
+
resolvedConfig,
|
|
3474
|
+
{ endpoint, method: "GET" },
|
|
3475
|
+
void 0,
|
|
3476
|
+
query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
|
|
3477
|
+
mergedOptions
|
|
3478
|
+
);
|
|
3479
|
+
};
|
|
3480
|
+
return {
|
|
3481
|
+
baseUrl: normalizedBaseUrl,
|
|
3482
|
+
request,
|
|
3483
|
+
signIn: {
|
|
3484
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
3485
|
+
resolvedConfig,
|
|
3486
|
+
{ endpoint: "/sign-in/email", method: "POST" },
|
|
3487
|
+
input,
|
|
3488
|
+
options
|
|
3489
|
+
),
|
|
3490
|
+
username: (input, options) => executePostWithCompatibleInput(
|
|
3491
|
+
resolvedConfig,
|
|
3492
|
+
{ endpoint: "/sign-in/username", method: "POST" },
|
|
3493
|
+
input,
|
|
3494
|
+
options
|
|
3495
|
+
),
|
|
3496
|
+
social: (input, options) => executePostWithCompatibleInput(
|
|
3497
|
+
resolvedConfig,
|
|
3498
|
+
{ endpoint: "/sign-in/social", method: "POST" },
|
|
3499
|
+
input,
|
|
3500
|
+
options
|
|
3501
|
+
)
|
|
3502
|
+
},
|
|
3503
|
+
signUp: {
|
|
3504
|
+
email: (input, options) => executePostWithCompatibleInput(
|
|
3505
|
+
resolvedConfig,
|
|
3506
|
+
{ endpoint: "/sign-up/email", method: "POST" },
|
|
3507
|
+
input,
|
|
3508
|
+
options
|
|
3509
|
+
)
|
|
3510
|
+
},
|
|
3511
|
+
signOut,
|
|
3512
|
+
logout: signOut,
|
|
3513
|
+
getSession: (input, options) => executeGetWithCompatibleInput(
|
|
3514
|
+
resolvedConfig,
|
|
3515
|
+
{ endpoint: "/get-session", method: "GET" },
|
|
3516
|
+
input,
|
|
3517
|
+
options
|
|
3518
|
+
),
|
|
3519
|
+
listSessions: (input, options) => executeGetWithCompatibleInput(
|
|
3520
|
+
resolvedConfig,
|
|
3521
|
+
{ endpoint: "/list-sessions", method: "GET" },
|
|
3522
|
+
input,
|
|
3523
|
+
options
|
|
3524
|
+
),
|
|
3525
|
+
revokeSession,
|
|
3526
|
+
clearSession: revokeSession,
|
|
3527
|
+
revokeSessions,
|
|
3528
|
+
clearSessions: revokeSessions,
|
|
3529
|
+
revokeOtherSessions,
|
|
3530
|
+
clearOtherSessions: revokeOtherSessions,
|
|
3531
|
+
forgetPassword: (input, options) => executePostWithCompatibleInput(
|
|
3532
|
+
resolvedConfig,
|
|
3533
|
+
{ endpoint: "/forget-password", method: "POST" },
|
|
3534
|
+
input,
|
|
3535
|
+
options
|
|
3536
|
+
),
|
|
3537
|
+
resetPassword: (input, options) => executePostWithCompatibleInput(
|
|
3538
|
+
resolvedConfig,
|
|
3539
|
+
{ endpoint: "/reset-password", method: "POST" },
|
|
3540
|
+
input,
|
|
3541
|
+
options
|
|
3542
|
+
),
|
|
3543
|
+
resolveResetPasswordToken,
|
|
3544
|
+
verifyEmail: (input, options) => {
|
|
3545
|
+
const { payload, fetchOptions } = extractFetchOptions(input);
|
|
3546
|
+
const mergedOptions = mergeCallOptions(fetchOptions, options);
|
|
3547
|
+
const query = payload;
|
|
3548
|
+
return callAuthEndpoint(
|
|
3549
|
+
resolvedConfig,
|
|
3550
|
+
{ endpoint: "/verify-email", method: "GET" },
|
|
3551
|
+
void 0,
|
|
3552
|
+
query ? {
|
|
3553
|
+
token: query.token,
|
|
3554
|
+
callbackURL: query.callbackURL
|
|
3555
|
+
} : void 0,
|
|
3556
|
+
mergedOptions
|
|
3557
|
+
);
|
|
3558
|
+
},
|
|
3559
|
+
sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
|
|
3560
|
+
resolvedConfig,
|
|
3561
|
+
{ endpoint: "/send-verification-email", method: "POST" },
|
|
3562
|
+
input,
|
|
3563
|
+
options
|
|
3564
|
+
),
|
|
3565
|
+
changeEmail: (input, options) => executePostWithCompatibleInput(
|
|
3566
|
+
resolvedConfig,
|
|
3567
|
+
{ endpoint: "/change-email", method: "POST" },
|
|
3568
|
+
input,
|
|
3569
|
+
options
|
|
3570
|
+
),
|
|
3571
|
+
changePassword: (input, options) => executePostWithCompatibleInput(
|
|
3572
|
+
resolvedConfig,
|
|
3573
|
+
{ endpoint: "/change-password", method: "POST" },
|
|
3574
|
+
input,
|
|
3575
|
+
options
|
|
3576
|
+
),
|
|
3577
|
+
updateUser: (input, options) => executePostWithCompatibleInput(
|
|
3578
|
+
resolvedConfig,
|
|
3579
|
+
{ endpoint: "/update-user", method: "POST" },
|
|
3580
|
+
input,
|
|
3581
|
+
options
|
|
3582
|
+
),
|
|
3583
|
+
deleteUser,
|
|
3584
|
+
deleteUserCallback,
|
|
3585
|
+
linkSocial: (input, options) => executePostWithCompatibleInput(
|
|
3586
|
+
resolvedConfig,
|
|
3587
|
+
{ endpoint: "/link-social", method: "POST" },
|
|
3588
|
+
input,
|
|
3589
|
+
options
|
|
3590
|
+
),
|
|
3591
|
+
listAccounts: (input, options) => executeGetWithCompatibleInput(
|
|
3592
|
+
resolvedConfig,
|
|
3593
|
+
{ endpoint: "/list-accounts", method: "GET" },
|
|
3594
|
+
input,
|
|
3595
|
+
options
|
|
3596
|
+
),
|
|
3597
|
+
unlinkAccount: (input, options) => executePostWithCompatibleInput(
|
|
3598
|
+
resolvedConfig,
|
|
3599
|
+
{ endpoint: "/unlink-account", method: "POST" },
|
|
3600
|
+
input,
|
|
3601
|
+
options
|
|
3602
|
+
),
|
|
3603
|
+
refreshToken: (input, options) => executePostWithCompatibleInput(
|
|
3604
|
+
resolvedConfig,
|
|
3605
|
+
{ endpoint: "/refresh-token", method: "POST" },
|
|
3606
|
+
input,
|
|
3607
|
+
options
|
|
3608
|
+
),
|
|
3609
|
+
getAccessToken: (input, options) => executePostWithCompatibleInput(
|
|
3610
|
+
resolvedConfig,
|
|
3611
|
+
{ endpoint: "/get-access-token", method: "POST" },
|
|
3612
|
+
input,
|
|
3613
|
+
options
|
|
3614
|
+
)
|
|
3615
|
+
};
|
|
3616
|
+
}
|
|
3617
|
+
|
|
3010
3618
|
exports.AthenaClient = AthenaClient;
|
|
3011
3619
|
exports.AthenaError = AthenaError;
|
|
3012
3620
|
exports.AthenaErrorCategory = AthenaErrorCategory;
|
|
@@ -3014,8 +3622,10 @@ exports.AthenaErrorCode = AthenaErrorCode;
|
|
|
3014
3622
|
exports.AthenaErrorKind = AthenaErrorKind;
|
|
3015
3623
|
exports.AthenaGatewayError = AthenaGatewayError;
|
|
3016
3624
|
exports.Backend = Backend;
|
|
3625
|
+
exports.DEFAULT_POSTGRES_SCHEMAS = DEFAULT_POSTGRES_SCHEMAS;
|
|
3017
3626
|
exports.assertInt = assertInt;
|
|
3018
3627
|
exports.coerceInt = coerceInt;
|
|
3628
|
+
exports.createAuthClient = createAuthClient;
|
|
3019
3629
|
exports.createClient = createClient;
|
|
3020
3630
|
exports.createPostgresIntrospectionProvider = createPostgresIntrospectionProvider;
|
|
3021
3631
|
exports.createTypedClient = createTypedClient;
|
|
@@ -3032,10 +3642,12 @@ exports.isOk = isOk;
|
|
|
3032
3642
|
exports.loadGeneratorConfig = loadGeneratorConfig;
|
|
3033
3643
|
exports.normalizeAthenaError = normalizeAthenaError;
|
|
3034
3644
|
exports.normalizeGeneratorConfig = normalizeGeneratorConfig;
|
|
3645
|
+
exports.normalizeSchemaSelection = normalizeSchemaSelection;
|
|
3035
3646
|
exports.requireAffected = requireAffected;
|
|
3036
3647
|
exports.requireSuccess = requireSuccess;
|
|
3037
3648
|
exports.resolveGeneratorProvider = resolveGeneratorProvider;
|
|
3038
3649
|
exports.resolvePostgresColumnType = resolvePostgresColumnType;
|
|
3650
|
+
exports.resolveProviderSchemas = resolveProviderSchemas;
|
|
3039
3651
|
exports.runSchemaGenerator = runSchemaGenerator;
|
|
3040
3652
|
exports.unwrap = unwrap;
|
|
3041
3653
|
exports.unwrapOne = unwrapOne;
|