@strav/cli 0.4.2 → 0.4.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strav/cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "description": "CLI framework and code generators for the Strav framework",
6
6
  "license": "MIT",
@@ -33,11 +33,11 @@
33
33
  "strav": "./src/cli/strav.ts"
34
34
  },
35
35
  "peerDependencies": {
36
- "@strav/kernel": "0.4.2",
37
- "@strav/http": "0.4.2",
38
- "@strav/database": "0.4.2",
39
- "@strav/queue": "0.4.2",
40
- "@strav/signal": "0.4.2"
36
+ "@strav/kernel": "0.4.4",
37
+ "@strav/http": "0.4.4",
38
+ "@strav/database": "0.4.4",
39
+ "@strav/queue": "0.4.4",
40
+ "@strav/signal": "0.4.4"
41
41
  },
42
42
  "dependencies": {
43
43
  "chalk": "^5.6.2",
@@ -8,7 +8,7 @@ import TestGenerator from '../generators/test_generator.ts'
8
8
  import DocGenerator from '../generators/doc_generator.ts'
9
9
  import type { ApiRoutingConfig } from '../generators/route_generator.ts'
10
10
  import type { GeneratorConfig } from '../generators/config.ts'
11
- import { loadGeneratorConfig, getDatabasePaths } from '../config/loader.ts'
11
+ import { loadGeneratorConfig, getDatabasePaths, loadTenantIdType } from '../config/loader.ts'
12
12
 
13
13
  export function register(program: Command): void {
14
14
  program
@@ -30,7 +30,8 @@ export function register(program: Command): void {
30
30
  registry.validate()
31
31
 
32
32
  const schemas = registry.resolve()
33
- const representation = registry.buildRepresentation()
33
+ const tenantIdType = await loadTenantIdType()
34
+ const representation = registry.buildRepresentation(tenantIdType)
34
35
 
35
36
  // Load generator config (if available)
36
37
  const config = await loadGeneratorConfig()
@@ -2,7 +2,7 @@ import type { Command } from 'commander'
2
2
  import chalk from 'chalk'
3
3
  import SchemaRegistry from '@strav/database/schema/registry'
4
4
  import ModelGenerator from '../generators/model_generator.ts'
5
- import { loadGeneratorConfig, getDatabasePaths } from '../config/loader.ts'
5
+ import { loadGeneratorConfig, getDatabasePaths, loadTenantIdType } from '../config/loader.ts'
6
6
 
7
7
  export function register(program: Command): void {
8
8
  program
@@ -21,7 +21,8 @@ export function register(program: Command): void {
21
21
  await registry.discover(dbPaths.schemas)
22
22
  registry.validate()
23
23
 
24
- const representation = registry.buildRepresentation()
24
+ const tenantIdType = await loadTenantIdType()
25
+ const representation = registry.buildRepresentation(tenantIdType)
25
26
  const generator = new ModelGenerator(registry.all(), representation, config)
26
27
  const { written, skipped } = await generator.writeAll(force)
27
28
 
@@ -16,7 +16,7 @@ export function register(program: Command): void {
16
16
 
17
17
  console.log(chalk.cyan('Comparing schema with database...\n'))
18
18
 
19
- const desired = registry.buildRepresentation()
19
+ const desired = registry.buildRepresentation(database.tenantIdType)
20
20
  const actual = await introspector.introspect()
21
21
  const diff = new SchemaDiffer().diff(desired, actual)
22
22
 
@@ -53,11 +53,11 @@ export async function freshDatabase(
53
53
 
54
54
  console.log(chalk.cyan('Generating fresh migration...'))
55
55
 
56
- const desired = registry.buildRepresentation()
56
+ const desired = registry.buildRepresentation(db.tenantIdType)
57
57
  const actual = await introspector.introspect()
58
58
  const diff = new SchemaDiffer().diff(desired, actual)
59
59
 
60
- const sql = new SqlGenerator().generate(diff)
60
+ const sql = new SqlGenerator(db.tenantIdType).generate(diff)
61
61
  const version = Date.now().toString()
62
62
  const tableOrder = desired.tables.map(t => t.name)
63
63
 
@@ -21,7 +21,7 @@ export function register(program: Command): void {
21
21
 
22
22
  console.log(chalk.cyan('Comparing schema with database...'))
23
23
 
24
- const desired = registry.buildRepresentation()
24
+ const desired = registry.buildRepresentation(database.tenantIdType)
25
25
  const actual = await introspector.introspect()
26
26
  const diff = new SchemaDiffer().diff(desired, actual)
27
27
 
@@ -36,7 +36,7 @@ export function register(program: Command): void {
36
36
  return
37
37
  }
38
38
 
39
- const sql = new SqlGenerator().generate(diff)
39
+ const sql = new SqlGenerator(database.tenantIdType).generate(diff)
40
40
  const version = Date.now().toString()
41
41
  const tableOrder = desired.tables.map(t => t.name)
42
42
 
@@ -16,7 +16,7 @@ export function register(program: Command): void {
16
16
  const { db: database } = await bootstrap()
17
17
  db = database
18
18
 
19
- await ensureTenantTable(db.bypass)
19
+ await ensureTenantTable(db.bypass, db.tenantIdType)
20
20
  const manager = new TenantManager(db)
21
21
 
22
22
  const tenant = await manager.create({ slug: opts.slug, name: opts.name })
@@ -16,7 +16,7 @@ export function register(program: Command): void {
16
16
  const { db: database } = await bootstrap()
17
17
  db = database
18
18
 
19
- await ensureTenantTable(db.bypass)
19
+ await ensureTenantTable(db.bypass, db.tenantIdType)
20
20
  const manager = new TenantManager(db)
21
21
 
22
22
  const tenant = await manager.find(id)
@@ -14,7 +14,7 @@ export function register(program: Command): void {
14
14
  const { db: database } = await bootstrap()
15
15
  db = database
16
16
 
17
- await ensureTenantTable(db.bypass)
17
+ await ensureTenantTable(db.bypass, db.tenantIdType)
18
18
  const manager = new TenantManager(db)
19
19
  const tenants = await manager.list()
20
20
 
@@ -1,6 +1,10 @@
1
1
  import { join } from 'node:path'
2
2
  import type { GeneratorConfig, GeneratorPaths } from '../generators/config.ts'
3
3
  import { resolvePaths } from '../generators/config.ts'
4
+ import {
5
+ type TenantIdType,
6
+ DEFAULT_TENANT_ID_TYPE,
7
+ } from '@strav/database/database/tenant/id_type'
4
8
 
5
9
  /**
6
10
  * Load the generator configuration from the project's config/generators.ts file.
@@ -30,3 +34,17 @@ export async function getAllPaths(): Promise<GeneratorPaths> {
30
34
  const config = await loadGeneratorConfig()
31
35
  return resolvePaths(config)
32
36
  }
37
+
38
+ /**
39
+ * Read `database.tenant.idType` from `config/database.ts` for code-only
40
+ * generators (generate:models, generate:api) that don't connect to the DB.
41
+ * Falls back to the framework default if the config file or key is absent.
42
+ */
43
+ export async function loadTenantIdType(): Promise<TenantIdType> {
44
+ try {
45
+ const dbConfig = (await import(join(process.cwd(), 'config/database.ts'))).default
46
+ return (dbConfig?.tenant?.idType as TenantIdType | undefined) ?? DEFAULT_TENANT_ID_TYPE
47
+ } catch {
48
+ return DEFAULT_TENANT_ID_TYPE
49
+ }
50
+ }