@xylex-group/athena 1.6.2 → 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 +47 -1
- package/dist/cli/index.cjs +77 -18
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +2 -2
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +77 -18
- package/dist/cli/index.js.map +1 -1
- package/dist/{errors-BYRK5phv.d.cts → errors-BJGgjHcI.d.cts} +1 -1
- package/dist/{errors-1b-LSTum.d.ts → errors-Bcf5Sftv.d.ts} +1 -1
- package/dist/index.cjs +572 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +269 -6
- package/dist/index.d.ts +269 -6
- package/dist/index.js +569 -19
- package/dist/index.js.map +1 -1
- package/dist/{pipeline-CA2aexDl.d.cts → pipeline-BsKuBqmE.d.cts} +9 -4
- package/dist/{pipeline-BQzpSLD3.d.ts → pipeline-xQSjGbqF.d.ts} +9 -4
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/{types-v6UyGg-x.d.cts → types-wPA1Z4vQ.d.cts} +1 -1
- package/dist/{types-v6UyGg-x.d.ts → types-wPA1Z4vQ.d.ts} +1 -1
- package/package.json +1 -1
package/dist/cli/index.d.cts
CHANGED
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -289,6 +289,37 @@ function resolvePostgresColumnType(column) {
|
|
|
289
289
|
}
|
|
290
290
|
return wrapArrayType(baseType, column.arrayDimensions);
|
|
291
291
|
}
|
|
292
|
+
|
|
293
|
+
// src/generator/schema-selection.ts
|
|
294
|
+
var DEFAULT_POSTGRES_SCHEMAS = ["public"];
|
|
295
|
+
function collectSchemaNames(input) {
|
|
296
|
+
if (!input) {
|
|
297
|
+
return [];
|
|
298
|
+
}
|
|
299
|
+
const values = typeof input === "string" ? [input] : input;
|
|
300
|
+
return values.flatMap((value) => String(value).split(","));
|
|
301
|
+
}
|
|
302
|
+
function normalizeSchemaSelection(input) {
|
|
303
|
+
const schemas = [];
|
|
304
|
+
const seen = /* @__PURE__ */ new Set();
|
|
305
|
+
for (const value of collectSchemaNames(input)) {
|
|
306
|
+
const schema = value.trim();
|
|
307
|
+
if (!schema || seen.has(schema)) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
seen.add(schema);
|
|
311
|
+
schemas.push(schema);
|
|
312
|
+
}
|
|
313
|
+
return schemas.length > 0 ? schemas : [...DEFAULT_POSTGRES_SCHEMAS];
|
|
314
|
+
}
|
|
315
|
+
function resolveProviderSchemas(providerConfig) {
|
|
316
|
+
if (providerConfig.kind === "postgres") {
|
|
317
|
+
return normalizeSchemaSelection(providerConfig.schemas);
|
|
318
|
+
}
|
|
319
|
+
return [...DEFAULT_POSTGRES_SCHEMAS];
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/generator/config.ts
|
|
292
323
|
var DEFAULT_CONFIG_CANDIDATES = [
|
|
293
324
|
"athena.config.ts",
|
|
294
325
|
"athena.config.js",
|
|
@@ -298,8 +329,8 @@ var DEFAULT_CONFIG_CANDIDATES = [
|
|
|
298
329
|
".athena.config.js"
|
|
299
330
|
];
|
|
300
331
|
var DEFAULT_TARGETS = {
|
|
301
|
-
model: "athena/models/{model_kebab}.ts",
|
|
302
|
-
schema: "athena/
|
|
332
|
+
model: "athena/models/{schema_kebab}/{model_kebab}.ts",
|
|
333
|
+
schema: "athena/schemas/{schema_kebab}.ts",
|
|
303
334
|
database: "athena/relations.ts",
|
|
304
335
|
registry: "athena/config.ts"
|
|
305
336
|
};
|
|
@@ -329,6 +360,15 @@ function normalizeOutputConfig(output) {
|
|
|
329
360
|
}
|
|
330
361
|
};
|
|
331
362
|
}
|
|
363
|
+
function normalizeProviderConfig(provider) {
|
|
364
|
+
if (provider.kind === "postgres") {
|
|
365
|
+
return {
|
|
366
|
+
...provider,
|
|
367
|
+
schemas: normalizeSchemaSelection(provider.schemas)
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return provider;
|
|
371
|
+
}
|
|
332
372
|
function isAthenaGeneratorConfig(value) {
|
|
333
373
|
if (!value || typeof value !== "object") {
|
|
334
374
|
return false;
|
|
@@ -338,7 +378,7 @@ function isAthenaGeneratorConfig(value) {
|
|
|
338
378
|
}
|
|
339
379
|
function normalizeGeneratorConfig(input) {
|
|
340
380
|
return {
|
|
341
|
-
provider: input.provider,
|
|
381
|
+
provider: normalizeProviderConfig(input.provider),
|
|
342
382
|
output: normalizeOutputConfig(input.output),
|
|
343
383
|
naming: {
|
|
344
384
|
...DEFAULT_NAMING,
|
|
@@ -548,12 +588,19 @@ export const ${registryConstName} = defineRegistry({
|
|
|
548
588
|
};
|
|
549
589
|
}
|
|
550
590
|
function assertNoDuplicatePaths(files) {
|
|
551
|
-
const seen = /* @__PURE__ */ new
|
|
591
|
+
const seen = /* @__PURE__ */ new Map();
|
|
552
592
|
for (const file of files) {
|
|
553
|
-
|
|
554
|
-
|
|
593
|
+
const existing = seen.get(file.path);
|
|
594
|
+
if (existing) {
|
|
595
|
+
throw new Error(
|
|
596
|
+
[
|
|
597
|
+
`Generator output collision detected for path: ${file.path}`,
|
|
598
|
+
`Collision: ${existing.kind} and ${file.kind}.`,
|
|
599
|
+
"When syncing multiple schemas, include a schema placeholder such as {schema} or {schema_kebab} in model/schema output targets."
|
|
600
|
+
].join(" ")
|
|
601
|
+
);
|
|
555
602
|
}
|
|
556
|
-
seen.
|
|
603
|
+
seen.set(file.path, file);
|
|
557
604
|
}
|
|
558
605
|
}
|
|
559
606
|
var ArtifactComposer = class {
|
|
@@ -2109,8 +2156,21 @@ function coerceStringArray(value) {
|
|
|
2109
2156
|
}
|
|
2110
2157
|
return [];
|
|
2111
2158
|
}
|
|
2159
|
+
function normalizePostgresCatalogSchemas(schemas) {
|
|
2160
|
+
const normalized = [];
|
|
2161
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2162
|
+
for (const value of schemas ?? []) {
|
|
2163
|
+
const schema = value.trim();
|
|
2164
|
+
if (!schema || seen.has(schema)) {
|
|
2165
|
+
continue;
|
|
2166
|
+
}
|
|
2167
|
+
seen.add(schema);
|
|
2168
|
+
normalized.push(schema);
|
|
2169
|
+
}
|
|
2170
|
+
return normalized.length > 0 ? normalized : ["public"];
|
|
2171
|
+
}
|
|
2112
2172
|
function buildSchemaArrayLiteral(schemas) {
|
|
2113
|
-
const normalized = schemas
|
|
2173
|
+
const normalized = normalizePostgresCatalogSchemas(schemas);
|
|
2114
2174
|
const literals = normalized.map((schema) => `'${escapeSqlLiteral(schema)}'`).join(", ");
|
|
2115
2175
|
return `ARRAY[${literals}]`;
|
|
2116
2176
|
}
|
|
@@ -2309,12 +2369,14 @@ var PostgresIntrospectionProvider = class {
|
|
|
2309
2369
|
backend = "postgresql";
|
|
2310
2370
|
connectionString;
|
|
2311
2371
|
database;
|
|
2372
|
+
schemas;
|
|
2312
2373
|
constructor(options) {
|
|
2313
2374
|
this.connectionString = options.connectionString;
|
|
2314
2375
|
this.database = options.database ?? "postgres";
|
|
2376
|
+
this.schemas = normalizePostgresCatalogSchemas(options.schemas);
|
|
2315
2377
|
}
|
|
2316
2378
|
async inspect(options) {
|
|
2317
|
-
const schemas = options?.schemas && options.schemas.length > 0 ? options.schemas :
|
|
2379
|
+
const schemas = options?.schemas && options.schemas.length > 0 ? normalizePostgresCatalogSchemas(options.schemas) : this.schemas;
|
|
2318
2380
|
const pool = new Pool({
|
|
2319
2381
|
connectionString: this.connectionString
|
|
2320
2382
|
});
|
|
@@ -2386,11 +2448,13 @@ var AthenaGatewayPostgresIntrospectionProvider = class {
|
|
|
2386
2448
|
type: this.config.backend ?? "postgresql"
|
|
2387
2449
|
}
|
|
2388
2450
|
});
|
|
2451
|
+
this.schemas = normalizeSchemaSelection(this.config.schemas);
|
|
2389
2452
|
}
|
|
2390
2453
|
backend = "postgresql";
|
|
2391
2454
|
client;
|
|
2455
|
+
schemas;
|
|
2392
2456
|
async inspect(options) {
|
|
2393
|
-
const schemas = options?.schemas && options.schemas.length > 0 ? options.schemas : this.
|
|
2457
|
+
const schemas = options?.schemas && options.schemas.length > 0 ? normalizeSchemaSelection(options.schemas) : this.schemas;
|
|
2394
2458
|
const catalogClient = new AthenaGatewayCatalogClient(this.client);
|
|
2395
2459
|
const queries = buildGatewayCatalogQueries(schemas);
|
|
2396
2460
|
const [columnRows, enumMap, primaryKeyRows, foreignKeyRows] = await Promise.all([
|
|
@@ -2426,7 +2490,8 @@ var ScyllaIntrospectionProvider = class {
|
|
|
2426
2490
|
function createPostgresProvider(config) {
|
|
2427
2491
|
return createPostgresIntrospectionProvider({
|
|
2428
2492
|
connectionString: config.connectionString,
|
|
2429
|
-
database: config.database
|
|
2493
|
+
database: config.database,
|
|
2494
|
+
schemas: normalizeSchemaSelection(config.schemas)
|
|
2430
2495
|
});
|
|
2431
2496
|
}
|
|
2432
2497
|
function resolveGeneratorProvider(providerConfig, experimentalFlags) {
|
|
@@ -2448,12 +2513,6 @@ function resolveGeneratorProvider(providerConfig, experimentalFlags) {
|
|
|
2448
2513
|
}
|
|
2449
2514
|
|
|
2450
2515
|
// src/generator/pipeline.ts
|
|
2451
|
-
function extractProviderSchemas(providerConfig) {
|
|
2452
|
-
if (!("schemas" in providerConfig) || !providerConfig.schemas || providerConfig.schemas.length === 0) {
|
|
2453
|
-
return void 0;
|
|
2454
|
-
}
|
|
2455
|
-
return providerConfig.schemas;
|
|
2456
|
-
}
|
|
2457
2516
|
async function writeArtifacts(files, cwd) {
|
|
2458
2517
|
const writtenFiles = [];
|
|
2459
2518
|
for (const file of files) {
|
|
@@ -2473,7 +2532,7 @@ async function runSchemaGenerator(options = {}) {
|
|
|
2473
2532
|
const { configPath, config } = await loadGeneratorConfig(configOptions);
|
|
2474
2533
|
const provider = options.provider ?? resolveGeneratorProvider(config.provider, config.experimental);
|
|
2475
2534
|
const snapshot = await provider.inspect({
|
|
2476
|
-
schemas:
|
|
2535
|
+
schemas: resolveProviderSchemas(config.provider)
|
|
2477
2536
|
});
|
|
2478
2537
|
const generated = generateArtifactsFromSnapshot(snapshot, config);
|
|
2479
2538
|
const writtenFiles = options.dryRun ? [] : await writeArtifacts(generated.files, cwd);
|