@xylex-group/athena 1.6.0 → 1.6.2

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.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- import { B as BackendConfig, a as BackendType, A as AthenaConditionValue, b as AthenaConditionCastType, c as AthenaConditionArrayValue, d as AthenaConditionOperator, e as AthenaGatewayCallOptions, f as AthenaGatewayErrorDetails, g as AthenaRpcCallOptions } from './errors-DQerAaXC.js';
2
- export { h as AthenaGatewayError, i as AthenaGatewayErrorCode, j as AthenaRpcFilter, k as AthenaRpcFilterOperator, l as AthenaRpcOrder, m as AthenaRpcPayload, n as Backend, o as isAthenaGatewayError } from './errors-DQerAaXC.js';
1
+ import { A as AthenaGatewayCallOptions, a as AthenaConditionValue, b as AthenaConditionCastType, c as AthenaConditionArrayValue, d as AthenaConditionOperator, e as AthenaGatewayErrorDetails, f as AthenaRpcCallOptions, B as BackendConfig, g as BackendType } from './types-v6UyGg-x.js';
2
+ export { m as AthenaGatewayErrorCode, i as AthenaRpcFilter, j as AthenaRpcFilterOperator, k as AthenaRpcOrder, l as AthenaRpcPayload, h as Backend } from './types-v6UyGg-x.js';
3
+ export { A as AthenaGatewayError, i as isAthenaGatewayError } from './errors-1b-LSTum.js';
4
+ import { S as SchemaDef, A as AnyModelDef, D as DatabaseDef, M as ModelMetadata, a as ModelDef, R as RegistryDef, T as TenantKeyMap, b as TenantContext, c as RowOf, d as ModelAt, e as SchemaIntrospectionProvider, f as AthenaGeneratorConfig, L as LoadGeneratorConfigOptions, g as LoadedGeneratorConfig, N as NormalizedAthenaGeneratorConfig, I as IntrospectionSnapshot, G as GeneratedArtifacts, h as IntrospectionColumn, i as GeneratorProviderConfig, j as GeneratorExperimentalFlags } from './pipeline-BQzpSLD3.js';
5
+ export { u as GeneratedArtifact, v as GeneratorArtifactKind, w as GeneratorFeatureFlags, x as GeneratorNamingConfig, y as GeneratorOutputConfig, z as GeneratorOutputTargets, k as InsertOf, l as IntrospectionInspectOptions, m as IntrospectionRelation, n as IntrospectionSchema, o as IntrospectionTable, p as IntrospectionTypeKind, q as ModelRelationKind, s as ModelRelationMetadata, B as NamingStyle, C as RunGeneratorOptions, E as RunGeneratorResult, t as TenantContextValue, U as UpdateOf, r as runSchemaGenerator } from './pipeline-BQzpSLD3.js';
3
6
 
4
7
  interface AthenaResult<T> {
5
8
  data: T | null;
@@ -314,185 +317,6 @@ interface SqlIdentifier {
314
317
  */
315
318
  declare function identifier(...segments: string[]): SqlIdentifier;
316
319
 
317
- type ModelKey = string;
318
- type ColumnKey = string;
319
- /**
320
- * Runtime values that can safely be serialized into tenant-scoped headers.
321
- */
322
- type TenantContextValue = string | number | boolean | null | undefined;
323
- /**
324
- * Compile-time map of tenant context keys to outbound header names.
325
- */
326
- type TenantKeyMap = Record<string, string>;
327
- /**
328
- * Partial tenant context keyed by `TenantKeyMap`.
329
- */
330
- type TenantContext<TMap extends TenantKeyMap> = Partial<Record<keyof TMap, TenantContextValue>>;
331
- /**
332
- * Supported relationship cardinalities for model metadata and introspection snapshots.
333
- */
334
- type ModelRelationKind = 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many';
335
- /**
336
- * Base metadata shape shared by typed model definitions and introspection snapshots.
337
- * This type is intentionally row-agnostic so it can be used for generic registries.
338
- */
339
- interface ModelMetadataBase {
340
- database?: string;
341
- schema?: string;
342
- model?: string;
343
- tableName?: string;
344
- primaryKey: string[];
345
- nullable?: Partial<Record<string, boolean>>;
346
- relations?: Record<string, ModelRelationMetadata>;
347
- }
348
- /**
349
- * Strongly-typed model metadata linked to a row shape.
350
- */
351
- type ModelMetadata<Row> = Omit<ModelMetadataBase, 'primaryKey' | 'nullable'> & {
352
- primaryKey: Array<Extract<keyof Row, string>>;
353
- nullable?: Partial<Record<Extract<keyof Row, string>, boolean>>;
354
- };
355
- /**
356
- * Relation metadata for model contracts and introspection snapshots.
357
- */
358
- interface ModelRelationMetadata {
359
- kind: ModelRelationKind;
360
- sourceColumns: ColumnKey[];
361
- targetSchema: string;
362
- targetModel: ModelKey;
363
- targetColumns: ColumnKey[];
364
- targetDatabase?: string;
365
- through?: {
366
- schema: string;
367
- model: string;
368
- sourceColumns: ColumnKey[];
369
- targetColumns: ColumnKey[];
370
- };
371
- }
372
- /**
373
- * Core model definition contract used by typed registries.
374
- */
375
- interface ModelDef<Row, Insert = Partial<Row>, Update = Partial<Insert>, Meta extends ModelMetadataBase = ModelMetadata<Row>> {
376
- readonly meta: Meta;
377
- readonly __types?: {
378
- row: Row;
379
- insert: Insert;
380
- update: Update;
381
- };
382
- }
383
- /**
384
- * Row-agnostic model definition used as a generic constraint.
385
- */
386
- type AnyModelDef = ModelDef<unknown, unknown, unknown, ModelMetadataBase>;
387
- /**
388
- * Schema-level model registry.
389
- */
390
- interface SchemaDef<Models extends Record<ModelKey, AnyModelDef>> {
391
- readonly models: Models;
392
- }
393
- /**
394
- * Database-level schema registry.
395
- */
396
- interface DatabaseDef<Schemas extends Record<string, SchemaDef<Record<ModelKey, AnyModelDef>>>> {
397
- readonly schemas: Schemas;
398
- }
399
- /**
400
- * Top-level registry keyed by logical database names.
401
- */
402
- type RegistryDef<Databases extends Record<string, DatabaseDef<Record<string, SchemaDef<Record<ModelKey, AnyModelDef>>>>>> = Databases;
403
- /**
404
- * Extracts row type from a model definition.
405
- */
406
- type RowOf<TModel extends AnyModelDef> = TModel extends ModelDef<infer TRow, unknown, unknown, ModelMetadataBase> ? TRow : never;
407
- /**
408
- * Extracts insert type from a model definition.
409
- */
410
- type InsertOf<TModel extends AnyModelDef> = TModel extends ModelDef<unknown, infer TInsert, unknown, ModelMetadataBase> ? TInsert : never;
411
- /**
412
- * Extracts update type from a model definition.
413
- */
414
- type UpdateOf<TModel extends AnyModelDef> = TModel extends ModelDef<unknown, unknown, infer TUpdate, ModelMetadataBase> ? TUpdate : never;
415
- /**
416
- * Resolves a model definition from a registry path.
417
- */
418
- type ModelAt<TRegistry extends RegistryDef<Record<string, DatabaseDef<Record<string, SchemaDef<Record<ModelKey, AnyModelDef>>>>>>, TDatabase extends keyof TRegistry & string, TSchema extends keyof TRegistry[TDatabase]['schemas'] & string, TModel extends keyof TRegistry[TDatabase]['schemas'][TSchema]['models'] & string> = TRegistry[TDatabase]['schemas'][TSchema]['models'][TModel];
419
- /**
420
- * Introspection-level column type families.
421
- */
422
- type IntrospectionTypeKind = 'scalar' | 'enum' | 'domain' | 'range' | 'multirange' | 'composite';
423
- /**
424
- * Introspected column metadata.
425
- */
426
- interface IntrospectionColumn {
427
- name: string;
428
- dataType: string;
429
- udtName: string;
430
- typeKind: IntrospectionTypeKind;
431
- isNullable: boolean;
432
- isPrimaryKey: boolean;
433
- hasDefault: boolean;
434
- isGenerated: boolean;
435
- arrayDimensions: number;
436
- enumValues?: string[];
437
- }
438
- /**
439
- * Introspected relationship metadata.
440
- */
441
- interface IntrospectionRelation {
442
- name: string;
443
- kind: ModelRelationKind;
444
- sourceColumns: string[];
445
- targetSchema: string;
446
- targetModel: string;
447
- targetColumns: string[];
448
- targetDatabase?: string;
449
- through?: {
450
- schema: string;
451
- model: string;
452
- sourceColumns: string[];
453
- targetColumns: string[];
454
- };
455
- }
456
- /**
457
- * Introspected table metadata.
458
- */
459
- interface IntrospectionTable {
460
- schema: string;
461
- name: string;
462
- columns: Record<string, IntrospectionColumn>;
463
- primaryKey: string[];
464
- relations: Record<string, IntrospectionRelation>;
465
- }
466
- /**
467
- * Introspected schema metadata.
468
- */
469
- interface IntrospectionSchema {
470
- name: string;
471
- tables: Record<string, IntrospectionTable>;
472
- }
473
- /**
474
- * Normalized output of a schema introspection pass.
475
- */
476
- interface IntrospectionSnapshot {
477
- backend: BackendType;
478
- database: string;
479
- generatedAt: string;
480
- schemas: Record<string, IntrospectionSchema>;
481
- }
482
- /**
483
- * Options accepted by introspection providers.
484
- */
485
- interface IntrospectionInspectOptions {
486
- schemas?: string[];
487
- }
488
- /**
489
- * Provider contract implemented by backend-specific introspection adapters.
490
- */
491
- interface SchemaIntrospectionProvider {
492
- readonly backend: BackendType;
493
- inspect(options?: IntrospectionInspectOptions): Promise<IntrospectionSnapshot>;
494
- }
495
-
496
320
  /**
497
321
  * Declares a model contract with explicit metadata and typed row/insert/update shapes.
498
322
  */
@@ -547,157 +371,6 @@ interface PostgresIntrospectionProviderOptions {
547
371
  */
548
372
  declare function createPostgresIntrospectionProvider(options: PostgresIntrospectionProviderOptions): SchemaIntrospectionProvider;
549
373
 
550
- /**
551
- * Supported case transformations for generated symbols and path token variants.
552
- */
553
- type NamingStyle = 'preserve' | 'camel' | 'pascal' | 'snake' | 'kebab';
554
- /**
555
- * Naming configuration for generated TypeScript identifiers.
556
- */
557
- interface GeneratorNamingConfig {
558
- modelType: NamingStyle;
559
- modelConst: NamingStyle;
560
- schemaConst: NamingStyle;
561
- databaseConst: NamingStyle;
562
- registryConst: NamingStyle;
563
- }
564
- /**
565
- * Stable feature flags for generator output behavior.
566
- */
567
- interface GeneratorFeatureFlags {
568
- emitRelations: boolean;
569
- emitRegistry: boolean;
570
- }
571
- /**
572
- * Experimental toggles for optional/forward-compatible generator behavior.
573
- */
574
- interface GeneratorExperimentalFlags {
575
- /**
576
- * Legacy compatibility toggle from the initial scaffold.
577
- * Gateway introspection is now implemented; this flag is retained for additive config compatibility.
578
- */
579
- postgresGatewayIntrospection: boolean;
580
- /**
581
- * Enables contract placeholders for future Scylla provider work.
582
- */
583
- scyllaProviderContracts: boolean;
584
- }
585
- /**
586
- * Path templates for each generated artifact category.
587
- */
588
- interface GeneratorOutputTargets {
589
- model: string;
590
- schema: string;
591
- database: string;
592
- registry: string;
593
- }
594
- /**
595
- * Output configuration including dynamic placeholder aliases.
596
- */
597
- interface GeneratorOutputConfig {
598
- targets: GeneratorOutputTargets;
599
- placeholderMap: Record<string, string>;
600
- }
601
- /**
602
- * Direct PostgreSQL introspection mode (implemented).
603
- */
604
- interface PostgresDirectProviderConfig {
605
- kind: 'postgres';
606
- mode: 'direct';
607
- connectionString: string;
608
- database?: string;
609
- schemas?: string[];
610
- }
611
- /**
612
- * Athena gateway-backed PostgreSQL introspection mode using `/gateway/query`.
613
- */
614
- interface PostgresGatewayProviderConfig {
615
- kind: 'postgres';
616
- mode: 'gateway';
617
- gatewayUrl: string;
618
- apiKey: string;
619
- database: string;
620
- schemas?: string[];
621
- backend?: BackendType;
622
- }
623
- /**
624
- * Scylla introspection provider contract placeholder (phase-two scaffold).
625
- */
626
- interface ScyllaDirectProviderConfig {
627
- kind: 'scylla';
628
- mode: 'direct';
629
- contactPoints: string[];
630
- keyspace: string;
631
- datacenter?: string;
632
- }
633
- type GeneratorProviderConfig = PostgresDirectProviderConfig | PostgresGatewayProviderConfig | ScyllaDirectProviderConfig;
634
- /**
635
- * Root config contract loaded from `athena.config.ts`.
636
- */
637
- interface AthenaGeneratorConfig {
638
- provider: GeneratorProviderConfig;
639
- output: GeneratorOutputConfig;
640
- naming?: Partial<GeneratorNamingConfig>;
641
- features?: Partial<GeneratorFeatureFlags>;
642
- experimental?: Partial<GeneratorExperimentalFlags>;
643
- }
644
- /**
645
- * Normalized generator config with defaults applied.
646
- */
647
- interface NormalizedAthenaGeneratorConfig {
648
- provider: GeneratorProviderConfig;
649
- output: GeneratorOutputConfig;
650
- naming: GeneratorNamingConfig;
651
- features: GeneratorFeatureFlags;
652
- experimental: GeneratorExperimentalFlags;
653
- }
654
- /**
655
- * Config loader options for CLI/programmatic usage.
656
- */
657
- interface LoadGeneratorConfigOptions {
658
- cwd?: string;
659
- configPath?: string;
660
- }
661
- /**
662
- * Fully loaded config result including resolved file path.
663
- */
664
- interface LoadedGeneratorConfig {
665
- configPath: string;
666
- config: NormalizedAthenaGeneratorConfig;
667
- }
668
- type GeneratorArtifactKind = 'model' | 'schema' | 'database' | 'registry';
669
- /**
670
- * One generated output file.
671
- */
672
- interface GeneratedArtifact {
673
- kind: GeneratorArtifactKind;
674
- path: string;
675
- content: string;
676
- }
677
- /**
678
- * In-memory generator output payload.
679
- */
680
- interface GeneratedArtifacts {
681
- snapshot: IntrospectionSnapshot;
682
- files: GeneratedArtifact[];
683
- }
684
- /**
685
- * Runtime options for executing the generator pipeline.
686
- */
687
- interface RunGeneratorOptions {
688
- cwd?: string;
689
- configPath?: string;
690
- dryRun?: boolean;
691
- provider?: SchemaIntrospectionProvider;
692
- }
693
- /**
694
- * Generator execution result including files written to disk.
695
- */
696
- interface RunGeneratorResult extends GeneratedArtifacts {
697
- configPath: string;
698
- writtenFiles: string[];
699
- }
700
-
701
374
  declare function normalizeGeneratorConfig(input: AthenaGeneratorConfig): NormalizedAthenaGeneratorConfig;
702
375
  /**
703
376
  * Typed identity helper for authoring generator configs.
@@ -724,9 +397,4 @@ declare function resolvePostgresColumnType(column: IntrospectionColumn): string;
724
397
  */
725
398
  declare function resolveGeneratorProvider(providerConfig: GeneratorProviderConfig, experimentalFlags: GeneratorExperimentalFlags): SchemaIntrospectionProvider;
726
399
 
727
- /**
728
- * End-to-end generator execution: load config, introspect, render, and optionally write files.
729
- */
730
- declare function runSchemaGenerator(options?: RunGeneratorOptions): Promise<RunGeneratorResult>;
731
-
732
- export { AthenaClient, AthenaConditionCastType, AthenaError, AthenaErrorCategory, AthenaErrorCode, type AthenaErrorInput, AthenaErrorKind, AthenaGatewayCallOptions, AthenaGatewayErrorDetails, type AthenaGeneratorConfig, type AthenaOperationContext, type AthenaResult, AthenaRpcCallOptions, type AthenaSdkClient, BackendConfig, BackendType, type DatabaseDef, type GeneratedArtifact, type GeneratedArtifacts, type GeneratorArtifactKind, type GeneratorExperimentalFlags, type GeneratorFeatureFlags, type GeneratorNamingConfig, type GeneratorOutputConfig, type GeneratorOutputTargets, type GeneratorProviderConfig, type InsertOf, type IntCoercionOptions, type IntrospectionColumn, type IntrospectionInspectOptions, type IntrospectionRelation, type IntrospectionSchema, type IntrospectionSnapshot, type IntrospectionTable, type IntrospectionTypeKind, type LoadGeneratorConfigOptions, type LoadedGeneratorConfig, type ModelAt, type ModelDef, type ModelMetadata, type ModelRelationKind, type ModelRelationMetadata, type NamingStyle, type NormalizedAthenaError, type NormalizedAthenaGeneratorConfig, type PostgresIntrospectionProviderOptions, type RegistryDef, type RequireAffectedOptions, type RetryBackoffStrategy, type RetryConfig, type RowOf, type RpcOrderOptions, type RpcQueryBuilder, type RunGeneratorOptions, type RunGeneratorResult, type SchemaDef, type SchemaIntrospectionProvider, type TableQueryBuilder, type TenantContext, type TenantContextValue, type TenantKeyMap, type TypedAthenaClient, type TypedClientOptions, type UnwrapOneOptions, type UnwrapOptions, type UpdateOf, assertInt, coerceInt, createClient, createPostgresIntrospectionProvider, createTypedClient, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, findGeneratorConfigPath, generateArtifactsFromSnapshot, identifier, isOk, loadGeneratorConfig, normalizeAthenaError, normalizeGeneratorConfig, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, runSchemaGenerator, unwrap, unwrapOne, unwrapRows, withRetry };
400
+ export { AthenaClient, AthenaConditionCastType, AthenaError, AthenaErrorCategory, AthenaErrorCode, type AthenaErrorInput, AthenaErrorKind, AthenaGatewayCallOptions, AthenaGatewayErrorDetails, AthenaGeneratorConfig, type AthenaOperationContext, type AthenaResult, AthenaRpcCallOptions, type AthenaSdkClient, BackendConfig, BackendType, DatabaseDef, GeneratedArtifacts, GeneratorExperimentalFlags, GeneratorProviderConfig, type IntCoercionOptions, IntrospectionColumn, IntrospectionSnapshot, LoadGeneratorConfigOptions, LoadedGeneratorConfig, ModelAt, ModelDef, ModelMetadata, type NormalizedAthenaError, NormalizedAthenaGeneratorConfig, type PostgresIntrospectionProviderOptions, RegistryDef, type RequireAffectedOptions, type RetryBackoffStrategy, type RetryConfig, RowOf, type RpcOrderOptions, type RpcQueryBuilder, SchemaDef, SchemaIntrospectionProvider, type TableQueryBuilder, TenantContext, TenantKeyMap, type TypedAthenaClient, type TypedClientOptions, type UnwrapOneOptions, type UnwrapOptions, assertInt, coerceInt, createClient, createPostgresIntrospectionProvider, createTypedClient, defineDatabase, defineGeneratorConfig, defineModel, defineRegistry, defineSchema, findGeneratorConfigPath, generateArtifactsFromSnapshot, identifier, isOk, loadGeneratorConfig, normalizeAthenaError, normalizeGeneratorConfig, requireAffected, requireSuccess, resolveGeneratorProvider, resolvePostgresColumnType, unwrap, unwrapOne, unwrapRows, withRetry };
package/dist/index.js CHANGED
@@ -1966,6 +1966,58 @@ 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
+ }
1969
2021
  function buildSchemaArrayLiteral(schemas) {
1970
2022
  const normalized = schemas.length > 0 ? schemas : ["public"];
1971
2023
  const literals = normalized.map((schema) => `'${escapeSqlLiteral(schema)}'`).join(", ");
@@ -2005,8 +2057,10 @@ var PostgresCatalogSnapshotAssembler = class {
2005
2057
  addPrimaryKeyRows(primaryKeyRows) {
2006
2058
  for (const row of primaryKeyRows) {
2007
2059
  const table = this.ensureTable(row.schema_name, row.table_name);
2008
- table.primaryKey = row.columns;
2009
- for (const columnName of row.columns) {
2060
+ const primaryKeyColumns = coerceStringArray(row.columns);
2061
+ row.columns = primaryKeyColumns;
2062
+ table.primaryKey = primaryKeyColumns;
2063
+ for (const columnName of primaryKeyColumns) {
2010
2064
  const column = table.columns[columnName];
2011
2065
  if (column) {
2012
2066
  column.isPrimaryKey = true;
@@ -2018,23 +2072,27 @@ var PostgresCatalogSnapshotAssembler = class {
2018
2072
  for (const row of foreignKeyRows) {
2019
2073
  const sourceTable = this.ensureTable(row.source_schema, row.source_table);
2020
2074
  const targetTable = this.ensureTable(row.target_schema, row.target_table);
2075
+ const sourceColumns = coerceStringArray(row.source_columns);
2076
+ const targetColumns = coerceStringArray(row.target_columns);
2077
+ row.source_columns = sourceColumns;
2078
+ row.target_columns = targetColumns;
2021
2079
  const sourceRelationKind = row.source_is_unique ? "one-to-one" : "many-to-one";
2022
2080
  this.upsertRelation(sourceTable, relationKey(row.constraint_name, row.target_table), {
2023
2081
  name: row.constraint_name,
2024
2082
  kind: sourceRelationKind,
2025
- sourceColumns: row.source_columns,
2083
+ sourceColumns,
2026
2084
  targetSchema: row.target_schema,
2027
2085
  targetModel: row.target_table,
2028
- targetColumns: row.target_columns
2086
+ targetColumns
2029
2087
  });
2030
2088
  const targetRelationKind = row.source_is_unique ? "one-to-one" : "one-to-many";
2031
2089
  this.upsertRelation(targetTable, relationKey(row.source_table), {
2032
2090
  name: relationKey(row.source_table, row.constraint_name),
2033
2091
  kind: targetRelationKind,
2034
- sourceColumns: row.target_columns,
2092
+ sourceColumns: targetColumns,
2035
2093
  targetSchema: row.source_schema,
2036
2094
  targetModel: row.source_table,
2037
- targetColumns: row.source_columns
2095
+ targetColumns: sourceColumns
2038
2096
  });
2039
2097
  }
2040
2098
  }
@@ -2207,10 +2265,10 @@ var DEFAULT_CONFIG_CANDIDATES = [
2207
2265
  ".athena.config.js"
2208
2266
  ];
2209
2267
  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"
2268
+ model: "athena/models/{model_kebab}.ts",
2269
+ schema: "athena/schema.ts",
2270
+ database: "athena/relations.ts",
2271
+ registry: "athena/config.ts"
2214
2272
  };
2215
2273
  var DEFAULT_NAMING = {
2216
2274
  modelType: "pascal",
@@ -2238,6 +2296,13 @@ function normalizeOutputConfig(output) {
2238
2296
  }
2239
2297
  };
2240
2298
  }
2299
+ function isAthenaGeneratorConfig(value) {
2300
+ if (!value || typeof value !== "object") {
2301
+ return false;
2302
+ }
2303
+ const record = value;
2304
+ return Boolean(record.provider && typeof record.provider === "object") && Boolean(record.output && typeof record.output === "object");
2305
+ }
2241
2306
  function normalizeGeneratorConfig(input) {
2242
2307
  return {
2243
2308
  provider: input.provider,
@@ -2269,18 +2334,41 @@ function findGeneratorConfigPath(cwd = process.cwd()) {
2269
2334
  return void 0;
2270
2335
  }
2271
2336
  function extractConfigExport(module) {
2272
- if (module && typeof module === "object") {
2273
- const record = module;
2337
+ const visited = /* @__PURE__ */ new Set();
2338
+ const queue = [module];
2339
+ while (queue.length > 0) {
2340
+ const current = queue.shift();
2341
+ if (!current || typeof current !== "object" || visited.has(current)) {
2342
+ continue;
2343
+ }
2344
+ visited.add(current);
2345
+ const record = current;
2346
+ if (isAthenaGeneratorConfig(record)) {
2347
+ return record;
2348
+ }
2274
2349
  const defaultExport = record.default;
2275
2350
  if (defaultExport && typeof defaultExport === "object") {
2276
- return defaultExport;
2351
+ queue.push(defaultExport);
2277
2352
  }
2278
2353
  const namedConfigExport = record.config;
2279
2354
  if (namedConfigExport && typeof namedConfigExport === "object") {
2280
- return namedConfigExport;
2355
+ queue.push(namedConfigExport);
2356
+ }
2357
+ const moduleExports = record["module.exports"];
2358
+ if (moduleExports && typeof moduleExports === "object") {
2359
+ queue.push(moduleExports);
2281
2360
  }
2282
2361
  }
2283
- throw new Error("Generator config file must export a config object as default export or `config`.");
2362
+ throw new Error(
2363
+ "Generator config file must export a config object as default export or `config`."
2364
+ );
2365
+ }
2366
+ function importConfigModule(moduleSpecifier) {
2367
+ const runtimeImport = new Function(
2368
+ "moduleSpecifier",
2369
+ "return import(moduleSpecifier)"
2370
+ );
2371
+ return runtimeImport(moduleSpecifier);
2284
2372
  }
2285
2373
  async function loadGeneratorConfig(options = {}) {
2286
2374
  const cwd = options.cwd ?? process.cwd();
@@ -2291,7 +2379,7 @@ async function loadGeneratorConfig(options = {}) {
2291
2379
  );
2292
2380
  }
2293
2381
  const moduleUrl = pathToFileURL(resolvedPath);
2294
- const module = await import(`${moduleUrl.href}?cacheBust=${Date.now()}`);
2382
+ const module = await importConfigModule(`${moduleUrl.href}?cacheBust=${Date.now()}`);
2295
2383
  const rawConfig = extractConfigExport(module);
2296
2384
  return {
2297
2385
  configPath: resolvedPath,