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