@strav/cli 0.1.0 → 0.1.5
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 +6 -6
- package/src/cli/bootstrap.ts +7 -7
- package/src/cli/command_loader.ts +4 -4
- package/src/commands/db_seed.ts +3 -3
- package/src/commands/generate_api.ts +1 -1
- package/src/commands/generate_models.ts +2 -2
- package/src/commands/generate_seeder.ts +3 -3
- package/src/commands/migration_compare.ts +1 -1
- package/src/commands/migration_fresh.ts +26 -14
- package/src/commands/migration_generate.ts +4 -4
- package/src/commands/migration_rollback.ts +3 -3
- package/src/commands/migration_run.ts +3 -3
- package/src/commands/package_install.ts +2 -2
- package/src/commands/queue_flush.ts +1 -1
- package/src/commands/queue_retry.ts +1 -1
- package/src/commands/queue_work.ts +2 -2
- package/src/commands/scheduler_work.ts +2 -2
- package/src/generators/api_generator.ts +17 -17
- package/src/generators/doc_generator.ts +6 -6
- package/src/generators/model_generator.ts +8 -8
- package/src/generators/route_generator.ts +5 -5
- package/src/generators/test_generator.ts +13 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strav/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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.1.
|
|
37
|
-
"@strav/http": "0.1.
|
|
38
|
-
"@strav/database": "0.1.
|
|
39
|
-
"@strav/queue": "0.1.
|
|
40
|
-
"@strav/signal": "0.1.
|
|
36
|
+
"@strav/kernel": "0.1.4",
|
|
37
|
+
"@strav/http": "0.1.4",
|
|
38
|
+
"@strav/database": "0.1.4",
|
|
39
|
+
"@strav/queue": "0.1.4",
|
|
40
|
+
"@strav/signal": "0.1.4"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"chalk": "^5.6.2",
|
package/src/cli/bootstrap.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import Configuration from '@
|
|
2
|
-
import Database from '@
|
|
3
|
-
import SchemaRegistry from '@
|
|
4
|
-
import DatabaseIntrospector from '@
|
|
5
|
-
import Application from '@
|
|
6
|
-
import type ServiceProvider from '@
|
|
7
|
-
import { discoverDomains } from '@
|
|
1
|
+
import Configuration from '@strav/kernel/config/configuration'
|
|
2
|
+
import Database from '@strav/database/database/database'
|
|
3
|
+
import SchemaRegistry from '@strav/database/schema/registry'
|
|
4
|
+
import DatabaseIntrospector from '@strav/database/database/introspector'
|
|
5
|
+
import Application from '@strav/kernel/core/application'
|
|
6
|
+
import type ServiceProvider from '@strav/kernel/core/service_provider'
|
|
7
|
+
import { discoverDomains } from '@strav/database'
|
|
8
8
|
import { getDatabasePaths } from '../config/loader.ts'
|
|
9
9
|
|
|
10
10
|
export interface BootstrapResult {
|
|
@@ -6,7 +6,7 @@ import chalk from 'chalk'
|
|
|
6
6
|
/**
|
|
7
7
|
* Discovers and registers CLI commands from two sources:
|
|
8
8
|
*
|
|
9
|
-
* 1. **Package commands** — installed `@
|
|
9
|
+
* 1. **Package commands** — installed `@strav/*` packages that declare
|
|
10
10
|
* `"strav": { "commands": "src/commands" }` in their `package.json`.
|
|
11
11
|
* 2. **User commands** — `.ts` files in a `./commands/` directory at the
|
|
12
12
|
* project root.
|
|
@@ -19,7 +19,7 @@ import chalk from 'chalk'
|
|
|
19
19
|
* await CommandLoader.discover(program)
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
|
-
* // In a package (e.g. @
|
|
22
|
+
* // In a package (e.g. @strav/search):
|
|
23
23
|
* // package.json: { "strav": { "commands": "src/commands" } }
|
|
24
24
|
* // src/commands/search_import.ts:
|
|
25
25
|
* export function register(program: Command): void {
|
|
@@ -110,8 +110,8 @@ export default class CommandLoader {
|
|
|
110
110
|
const results: Array<{ root: string; commandsDir: string }> = []
|
|
111
111
|
const seen = new Set<string>()
|
|
112
112
|
|
|
113
|
-
// 1. Check node_modules/@
|
|
114
|
-
const nodeModulesDir = join(root, 'node_modules', '@
|
|
113
|
+
// 1. Check node_modules/@strav/*
|
|
114
|
+
const nodeModulesDir = join(root, 'node_modules', '@strav')
|
|
115
115
|
if (dirExists(nodeModulesDir)) {
|
|
116
116
|
const dirs = readdirSync(nodeModulesDir)
|
|
117
117
|
for (const dir of dirs) {
|
package/src/commands/db_seed.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type { Command } from 'commander'
|
|
|
4
4
|
import chalk from 'chalk'
|
|
5
5
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
6
6
|
import { freshDatabase, requireLocalEnv } from './migration_fresh.ts'
|
|
7
|
-
import { toSnakeCase } from '@
|
|
8
|
-
import BaseModel from '@
|
|
9
|
-
import { Seeder } from '@
|
|
7
|
+
import { toSnakeCase } from '@strav/kernel/helpers/strings'
|
|
8
|
+
import BaseModel from '@strav/database/orm/base_model'
|
|
9
|
+
import { Seeder } from '@strav/database/database/seeder'
|
|
10
10
|
|
|
11
11
|
const SEEDERS_PATH = 'database/seeders'
|
|
12
12
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
import type { Command } from 'commander'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
|
-
import SchemaRegistry from '@
|
|
4
|
+
import SchemaRegistry from '@strav/database/schema/registry'
|
|
5
5
|
import ApiGenerator from '../generators/api_generator.ts'
|
|
6
6
|
import RouteGenerator from '../generators/route_generator.ts'
|
|
7
7
|
import TestGenerator from '../generators/test_generator.ts'
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
import type { Command } from 'commander'
|
|
3
3
|
import chalk from 'chalk'
|
|
4
|
-
import SchemaRegistry from '@
|
|
4
|
+
import SchemaRegistry from '@strav/database/schema/registry'
|
|
5
5
|
import ModelGenerator from '../generators/model_generator.ts'
|
|
6
6
|
import type { GeneratorConfig } from '../generators/config.ts'
|
|
7
|
-
import { discoverDomains } from '@
|
|
7
|
+
import { discoverDomains } from '@strav/database'
|
|
8
8
|
import { loadGeneratorConfig, getDatabasePaths } from '../config/loader.ts'
|
|
9
9
|
|
|
10
10
|
export function register(program: Command): void {
|
|
@@ -2,7 +2,7 @@ import { join } from 'node:path'
|
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import type { Command } from 'commander'
|
|
4
4
|
import chalk from 'chalk'
|
|
5
|
-
import { toSnakeCase } from '@
|
|
5
|
+
import { toSnakeCase } from '@strav/kernel/helpers/strings'
|
|
6
6
|
import { formatAndWrite } from '../generators/config.ts'
|
|
7
7
|
|
|
8
8
|
const SEEDERS_PATH = 'database/seeders'
|
|
@@ -44,7 +44,7 @@ export function register(program: Command): void {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
function generateDatabaseSeeder(className: string): string {
|
|
47
|
-
return `import { Seeder } from '@
|
|
47
|
+
return `import { Seeder } from '@strav/database/database'
|
|
48
48
|
|
|
49
49
|
export default class ${className} extends Seeder {
|
|
50
50
|
async run(): Promise<void> {
|
|
@@ -56,7 +56,7 @@ export default class ${className} extends Seeder {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function generateSeeder(className: string): string {
|
|
59
|
-
return `import { Seeder } from '@
|
|
59
|
+
return `import { Seeder } from '@strav/database/database'
|
|
60
60
|
|
|
61
61
|
export default class ${className} extends Seeder {
|
|
62
62
|
async run(): Promise<void> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Command } from 'commander'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
4
|
-
import SchemaDiffer from '@
|
|
4
|
+
import SchemaDiffer from '@strav/database/database/migration/differ'
|
|
5
5
|
|
|
6
6
|
export function register(program: Command): void {
|
|
7
7
|
program
|
|
@@ -3,14 +3,15 @@ import chalk from 'chalk'
|
|
|
3
3
|
import { createInterface } from 'node:readline'
|
|
4
4
|
import { rmSync } from 'node:fs'
|
|
5
5
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
6
|
-
import type Database from '@
|
|
7
|
-
import type SchemaRegistry from '@
|
|
8
|
-
import type DatabaseIntrospector from '@
|
|
9
|
-
import SchemaDiffer from '@
|
|
10
|
-
import SqlGenerator from '@
|
|
11
|
-
import MigrationFileGenerator from '@
|
|
12
|
-
import MigrationTracker from '@
|
|
13
|
-
import MigrationRunner from '@
|
|
6
|
+
import type Database from '@strav/database/database/database'
|
|
7
|
+
import type SchemaRegistry from '@strav/database/schema/registry'
|
|
8
|
+
import type DatabaseIntrospector from '@strav/database/database/introspector'
|
|
9
|
+
import SchemaDiffer from '@strav/database/database/migration/differ'
|
|
10
|
+
import SqlGenerator from '@strav/database/database/migration/sql_generator'
|
|
11
|
+
import MigrationFileGenerator from '@strav/database/database/migration/file_generator'
|
|
12
|
+
import MigrationTracker from '@strav/database/database/migration/tracker'
|
|
13
|
+
import MigrationRunner from '@strav/database/database/migration/runner'
|
|
14
|
+
import { discoverDomains } from '@strav/database'
|
|
14
15
|
import { getDatabasePaths } from '../config/loader.ts'
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -23,7 +24,8 @@ export async function freshDatabase(
|
|
|
23
24
|
db: Database,
|
|
24
25
|
registry: SchemaRegistry,
|
|
25
26
|
introspector: DatabaseIntrospector,
|
|
26
|
-
migrationsPath: string = 'database/migrations'
|
|
27
|
+
migrationsPath: string = 'database/migrations',
|
|
28
|
+
scope: string = 'public'
|
|
27
29
|
): Promise<number> {
|
|
28
30
|
// Drop all tables in public schema
|
|
29
31
|
console.log(chalk.cyan('\nDropping all tables and types...'))
|
|
@@ -69,8 +71,8 @@ export async function freshDatabase(
|
|
|
69
71
|
// Run the migration
|
|
70
72
|
console.log(chalk.cyan('Running migration...'))
|
|
71
73
|
|
|
72
|
-
const tracker = new MigrationTracker(db)
|
|
73
|
-
const runner = new MigrationRunner(db, tracker, migrationsPath)
|
|
74
|
+
const tracker = new MigrationTracker(db, scope)
|
|
75
|
+
const runner = new MigrationRunner(db, tracker, migrationsPath, scope)
|
|
74
76
|
const result = await runner.run()
|
|
75
77
|
|
|
76
78
|
return result.applied.length
|
|
@@ -99,7 +101,8 @@ export function register(program: Command): void {
|
|
|
99
101
|
.command('fresh')
|
|
100
102
|
.alias('migration:fresh')
|
|
101
103
|
.description('Reset database and migrations, regenerate and run from scratch')
|
|
102
|
-
.
|
|
104
|
+
.option('-s, --scope <scope>', 'Domain (e.g., public, tenant, factory, marketing)', 'public')
|
|
105
|
+
.action(async (opts: { scope: string }) => {
|
|
103
106
|
requireLocalEnv('fresh')
|
|
104
107
|
|
|
105
108
|
// 6-digit challenge
|
|
@@ -123,10 +126,19 @@ export function register(program: Command): void {
|
|
|
123
126
|
// Get configured database paths
|
|
124
127
|
const dbPaths = await getDatabasePaths()
|
|
125
128
|
|
|
126
|
-
|
|
129
|
+
// Validate scope against available domains
|
|
130
|
+
const availableDomains = discoverDomains(dbPaths.schemas)
|
|
131
|
+
if (!availableDomains.includes(opts.scope)) {
|
|
132
|
+
throw new Error(`Invalid domain: ${opts.scope}. Available domains: ${availableDomains.join(', ')}`)
|
|
133
|
+
}
|
|
134
|
+
const scope = opts.scope
|
|
135
|
+
|
|
136
|
+
const { db: database, registry, introspector } = await bootstrap(scope)
|
|
127
137
|
db = database
|
|
128
138
|
|
|
129
|
-
|
|
139
|
+
// Use scoped migrations path
|
|
140
|
+
const scopedPath = `${dbPaths.migrations}/${scope}`
|
|
141
|
+
const applied = await freshDatabase(db, registry, introspector, scopedPath, scope)
|
|
130
142
|
|
|
131
143
|
console.log(chalk.green(`\nFresh migration complete. Applied ${applied} migration(s).`))
|
|
132
144
|
} catch (err) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Command } from 'commander'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
4
|
-
import SchemaDiffer from '@
|
|
5
|
-
import SqlGenerator from '@
|
|
6
|
-
import MigrationFileGenerator from '@
|
|
7
|
-
import { discoverDomains } from '@
|
|
4
|
+
import SchemaDiffer from '@strav/database/database/migration/differ'
|
|
5
|
+
import SqlGenerator from '@strav/database/database/migration/sql_generator'
|
|
6
|
+
import MigrationFileGenerator from '@strav/database/database/migration/file_generator'
|
|
7
|
+
import { discoverDomains } from '@strav/database'
|
|
8
8
|
import { getDatabasePaths } from '../config/loader.ts'
|
|
9
9
|
|
|
10
10
|
export function register(program: Command): void {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Command } from 'commander'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
4
|
-
import MigrationTracker from '@
|
|
5
|
-
import MigrationRunner from '@
|
|
6
|
-
import { discoverDomains } from '@
|
|
4
|
+
import MigrationTracker from '@strav/database/database/migration/tracker'
|
|
5
|
+
import MigrationRunner from '@strav/database/database/migration/runner'
|
|
6
|
+
import { discoverDomains } from '@strav/database'
|
|
7
7
|
import { getDatabasePaths } from '../config/loader.ts'
|
|
8
8
|
|
|
9
9
|
export function register(program: Command): void {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Command } from 'commander'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
4
|
-
import MigrationTracker from '@
|
|
5
|
-
import MigrationRunner from '@
|
|
6
|
-
import { discoverDomains } from '@
|
|
4
|
+
import MigrationTracker from '@strav/database/database/migration/tracker'
|
|
5
|
+
import MigrationRunner from '@strav/database/database/migration/runner'
|
|
6
|
+
import { discoverDomains } from '@strav/database'
|
|
7
7
|
import { getDatabasePaths } from '../config/loader.ts'
|
|
8
8
|
|
|
9
9
|
export function register(program: Command): void {
|
|
@@ -7,11 +7,11 @@ export function register(program: Command): void {
|
|
|
7
7
|
program
|
|
8
8
|
.command('install <name>')
|
|
9
9
|
.aliases(['package:install', 'i'])
|
|
10
|
-
.description('Copy config and schema stubs from a @
|
|
10
|
+
.description('Copy config and schema stubs from a @strav/* package into your project')
|
|
11
11
|
.option('-f, --force', 'Overwrite existing files')
|
|
12
12
|
.action(async (name: string, { force }: { force?: boolean }) => {
|
|
13
13
|
try {
|
|
14
|
-
const packageName = name.startsWith('@
|
|
14
|
+
const packageName = name.startsWith('@strav/') ? name : `@strav/${name}`
|
|
15
15
|
|
|
16
16
|
const packageRoot = await resolvePackageRoot(packageName)
|
|
17
17
|
if (!packageRoot) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Command } from 'commander'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
4
|
-
import Queue from '@
|
|
4
|
+
import Queue from '@strav/queue/queue/queue'
|
|
5
5
|
|
|
6
6
|
export function register(program: Command): void {
|
|
7
7
|
program
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Command } from 'commander'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
4
|
-
import Queue from '@
|
|
4
|
+
import Queue from '@strav/queue/queue/queue'
|
|
5
5
|
|
|
6
6
|
export function register(program: Command): void {
|
|
7
7
|
program
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Command } from 'commander'
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
4
|
-
import Queue from '@
|
|
5
|
-
import Worker from '@
|
|
4
|
+
import Queue from '@strav/queue/queue/queue'
|
|
5
|
+
import Worker from '@strav/queue/queue/worker'
|
|
6
6
|
|
|
7
7
|
export function register(program: Command): void {
|
|
8
8
|
program
|
|
@@ -2,8 +2,8 @@ import type { Command } from 'commander'
|
|
|
2
2
|
import chalk from 'chalk'
|
|
3
3
|
import path from 'node:path'
|
|
4
4
|
import { bootstrap, shutdown } from '../cli/bootstrap.ts'
|
|
5
|
-
import Scheduler from '@
|
|
6
|
-
import SchedulerRunner from '@
|
|
5
|
+
import Scheduler from '@strav/queue/scheduler/scheduler'
|
|
6
|
+
import SchedulerRunner from '@strav/queue/scheduler/runner'
|
|
7
7
|
|
|
8
8
|
export function register(program: Command): void {
|
|
9
9
|
program
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
|
-
import { Archetype } from '@
|
|
3
|
-
import type { SchemaDefinition } from '@
|
|
2
|
+
import { Archetype } from '@strav/database/schema/types'
|
|
3
|
+
import type { SchemaDefinition } from '@strav/database/schema/types'
|
|
4
4
|
import type {
|
|
5
5
|
DatabaseRepresentation,
|
|
6
6
|
TableDefinition,
|
|
7
7
|
ColumnDefinition,
|
|
8
|
-
} from '@
|
|
9
|
-
import type { FieldDefinition, FieldValidator } from '@
|
|
10
|
-
import type { PostgreSQLCustomType } from '@
|
|
11
|
-
import { toSnakeCase, toCamelCase, toPascalCase } from '@
|
|
8
|
+
} from '@strav/database/schema/database_representation'
|
|
9
|
+
import type { FieldDefinition, FieldValidator } from '@strav/database/schema/field_definition'
|
|
10
|
+
import type { PostgreSQLCustomType } from '@strav/database/schema/postgres'
|
|
11
|
+
import { toSnakeCase, toCamelCase, toPascalCase } from '@strav/kernel/helpers/strings'
|
|
12
12
|
import type { GeneratedFile } from './model_generator.ts'
|
|
13
13
|
import type { GeneratorConfig, GeneratorPaths } from './config.ts'
|
|
14
14
|
import { resolvePaths, relativeImport, formatAndWrite } from './config.ts'
|
|
@@ -284,8 +284,8 @@ export default class ApiGenerator {
|
|
|
284
284
|
|
|
285
285
|
const lines: string[] = [
|
|
286
286
|
'// Generated by Strav — DO NOT EDIT',
|
|
287
|
-
`import { ${[...ruleImports].sort().join(', ')} } from '@
|
|
288
|
-
`import type { RuleSet } from '@
|
|
287
|
+
`import { ${[...ruleImports].sort().join(', ')} } from '@strav/http/validation'`,
|
|
288
|
+
`import type { RuleSet } from '@strav/http/validation'`,
|
|
289
289
|
]
|
|
290
290
|
|
|
291
291
|
const enumImportPath = relativeImport(this.paths.validators, this.paths.enums)
|
|
@@ -487,8 +487,8 @@ export default class ApiGenerator {
|
|
|
487
487
|
|
|
488
488
|
const lines: string[] = [
|
|
489
489
|
'// Generated by Strav — DO NOT EDIT',
|
|
490
|
-
`import { allow } from '@
|
|
491
|
-
`import type { PolicyResult } from '@
|
|
490
|
+
`import { allow } from '@strav/http/policy'`,
|
|
491
|
+
`import type { PolicyResult } from '@strav/http/policy'`,
|
|
492
492
|
'',
|
|
493
493
|
`export default class ${className}Policy {`,
|
|
494
494
|
]
|
|
@@ -548,13 +548,13 @@ export default class ApiGenerator {
|
|
|
548
548
|
|
|
549
549
|
const lines: string[] = [
|
|
550
550
|
'// Generated by Strav — DO NOT EDIT',
|
|
551
|
-
`import { inject } from '@
|
|
551
|
+
`import { inject } from '@strav/kernel/core/inject'`,
|
|
552
552
|
`import ${className} from '${modelImport}/${snakeName}'`,
|
|
553
553
|
`import { ${className}Events } from '${eventImport}/${snakeName}'`,
|
|
554
|
-
`import Emitter from '@
|
|
554
|
+
`import Emitter from '@strav/kernel/events/emitter'`,
|
|
555
555
|
]
|
|
556
556
|
if (needsQuery) {
|
|
557
|
-
lines.push(`import { query } from '@
|
|
557
|
+
lines.push(`import { query } from '@strav/database/database'`)
|
|
558
558
|
}
|
|
559
559
|
lines.push('')
|
|
560
560
|
lines.push(`@inject`)
|
|
@@ -706,9 +706,9 @@ export default class ApiGenerator {
|
|
|
706
706
|
|
|
707
707
|
const lines: string[] = [
|
|
708
708
|
'// Generated by Strav — DO NOT EDIT',
|
|
709
|
-
`import { inject } from '@
|
|
710
|
-
`import type Context from '@
|
|
711
|
-
`import { validate } from '@
|
|
709
|
+
`import { inject } from '@strav/kernel/core/inject'`,
|
|
710
|
+
`import type Context from '@strav/http/http/context'`,
|
|
711
|
+
`import { validate } from '@strav/http/validation'`,
|
|
712
712
|
`import ${className}Service from '${serviceImport}/${snakeName}_service'`,
|
|
713
713
|
`import { ${className}Rules } from '${validatorImport}/${snakeName}_validator'`,
|
|
714
714
|
`import ${className}Policy from '${policyImport}/${snakeName}_policy'`,
|
|
@@ -939,7 +939,7 @@ export default class ApiGenerator {
|
|
|
939
939
|
|
|
940
940
|
const lines: string[] = [
|
|
941
941
|
'// Generated by Strav — DO NOT EDIT',
|
|
942
|
-
`import { Resource } from '@
|
|
942
|
+
`import { Resource } from '@strav/http/http'`,
|
|
943
943
|
`import type ${className} from '${modelImport}/${snakeName}'`,
|
|
944
944
|
'',
|
|
945
945
|
`export default class ${className}Resource extends Resource<${className}> {`,
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
|
-
import { Archetype } from '@
|
|
3
|
-
import type { SchemaDefinition } from '@
|
|
2
|
+
import { Archetype } from '@strav/database/schema/types'
|
|
3
|
+
import type { SchemaDefinition } from '@strav/database/schema/types'
|
|
4
4
|
import type {
|
|
5
5
|
DatabaseRepresentation,
|
|
6
6
|
TableDefinition,
|
|
7
7
|
ColumnDefinition,
|
|
8
|
-
} from '@
|
|
9
|
-
import type { FieldDefinition, FieldValidator } from '@
|
|
10
|
-
import type { PostgreSQLCustomType } from '@
|
|
8
|
+
} from '@strav/database/schema/database_representation'
|
|
9
|
+
import type { FieldDefinition, FieldValidator } from '@strav/database/schema/field_definition'
|
|
10
|
+
import type { PostgreSQLCustomType } from '@strav/database/schema/postgres'
|
|
11
11
|
import {
|
|
12
12
|
toSnakeCase,
|
|
13
13
|
toCamelCase,
|
|
14
14
|
toPascalCase,
|
|
15
15
|
pluralize,
|
|
16
|
-
} from '@
|
|
16
|
+
} from '@strav/kernel/helpers/strings'
|
|
17
17
|
import type { GeneratedFile } from './model_generator.ts'
|
|
18
18
|
import type { GeneratorConfig, GeneratorPaths } from './config.ts'
|
|
19
19
|
import { resolvePaths } from './config.ts'
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
|
-
import { Archetype } from '@
|
|
3
|
-
import type { SchemaDefinition } from '@
|
|
2
|
+
import { Archetype } from '@strav/database/schema/types'
|
|
3
|
+
import type { SchemaDefinition } from '@strav/database/schema/types'
|
|
4
4
|
import type {
|
|
5
5
|
DatabaseRepresentation,
|
|
6
6
|
TableDefinition,
|
|
7
7
|
ColumnDefinition,
|
|
8
8
|
EnumDefinition,
|
|
9
|
-
} from '@
|
|
10
|
-
import type { PostgreSQLCustomType } from '@
|
|
11
|
-
import { toSnakeCase, toCamelCase, toPascalCase } from '@
|
|
9
|
+
} from '@strav/database/schema/database_representation'
|
|
10
|
+
import type { PostgreSQLCustomType } from '@strav/database/schema/postgres'
|
|
11
|
+
import { toSnakeCase, toCamelCase, toPascalCase } from '@strav/kernel/helpers/strings'
|
|
12
12
|
import type { GeneratorConfig, GeneratorPaths } from './config.ts'
|
|
13
13
|
import { resolvePaths, relativeImport, formatAndWrite, getModelPrefix } from './config.ts'
|
|
14
14
|
|
|
@@ -271,7 +271,7 @@ export default class ModelGenerator {
|
|
|
271
271
|
// Assemble imports
|
|
272
272
|
const importLines: string[] = []
|
|
273
273
|
importLines.push("import { DateTime } from 'luxon'")
|
|
274
|
-
importLines.push("import BaseModel from '@
|
|
274
|
+
importLines.push("import BaseModel from '@strav/database/orm/base_model'")
|
|
275
275
|
|
|
276
276
|
const decoratorImports: string[] = []
|
|
277
277
|
if (needsPrimaryImport) decoratorImports.push('primary')
|
|
@@ -279,7 +279,7 @@ export default class ModelGenerator {
|
|
|
279
279
|
if (needsAssociateImport) decoratorImports.push('associate')
|
|
280
280
|
if (decoratorImports.length > 0) {
|
|
281
281
|
importLines.push(
|
|
282
|
-
`import { ${decoratorImports.join(', ')} } from '@
|
|
282
|
+
`import { ${decoratorImports.join(', ')} } from '@strav/database/orm/decorators'`
|
|
283
283
|
)
|
|
284
284
|
}
|
|
285
285
|
|
|
@@ -424,7 +424,7 @@ export default class ModelGenerator {
|
|
|
424
424
|
private findFieldForColumn(
|
|
425
425
|
colName: string,
|
|
426
426
|
schema: SchemaDefinition
|
|
427
|
-
): import('@
|
|
427
|
+
): import('@strav/database/schema/field_definition').FieldDefinition | null {
|
|
428
428
|
for (const [fieldName, fieldDef] of Object.entries(schema.fields)) {
|
|
429
429
|
if (fieldDef.references) continue
|
|
430
430
|
if (toSnakeCase(fieldName) === colName) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
|
-
import { Archetype } from '@
|
|
3
|
-
import type { SchemaDefinition } from '@
|
|
4
|
-
import { toSnakeCase, toPascalCase, pluralize } from '@
|
|
2
|
+
import { Archetype } from '@strav/database/schema/types'
|
|
3
|
+
import type { SchemaDefinition } from '@strav/database/schema/types'
|
|
4
|
+
import { toSnakeCase, toPascalCase, pluralize } from '@strav/kernel/helpers/strings'
|
|
5
5
|
import type { GeneratedFile } from './model_generator.ts'
|
|
6
6
|
import type { GeneratorConfig, GeneratorPaths } from './config.ts'
|
|
7
7
|
import { resolvePaths, relativeImport, formatAndWrite } from './config.ts'
|
|
@@ -89,8 +89,8 @@ export default class RouteGenerator {
|
|
|
89
89
|
|
|
90
90
|
const lines: string[] = [
|
|
91
91
|
'// Generated by Strav — DO NOT EDIT',
|
|
92
|
-
`import { router } from '@
|
|
93
|
-
`import { auth } from '@
|
|
92
|
+
`import { router } from '@strav/http/http'`,
|
|
93
|
+
`import { auth } from '@strav/http/auth'`,
|
|
94
94
|
'',
|
|
95
95
|
]
|
|
96
96
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
|
-
import { Archetype } from '@
|
|
3
|
-
import type { SchemaDefinition } from '@
|
|
2
|
+
import { Archetype } from '@strav/database/schema/types'
|
|
3
|
+
import type { SchemaDefinition } from '@strav/database/schema/types'
|
|
4
4
|
import type {
|
|
5
5
|
DatabaseRepresentation,
|
|
6
6
|
TableDefinition,
|
|
7
|
-
} from '@
|
|
8
|
-
import type { FieldDefinition } from '@
|
|
7
|
+
} from '@strav/database/schema/database_representation'
|
|
8
|
+
import type { FieldDefinition } from '@strav/database/schema/field_definition'
|
|
9
9
|
import {
|
|
10
10
|
toSnakeCase,
|
|
11
11
|
toCamelCase,
|
|
12
12
|
toPascalCase,
|
|
13
13
|
pluralize,
|
|
14
|
-
} from '@
|
|
14
|
+
} from '@strav/kernel/helpers/strings'
|
|
15
15
|
import type { GeneratedFile } from './model_generator.ts'
|
|
16
16
|
import type { GeneratorConfig, GeneratorPaths } from './config.ts'
|
|
17
17
|
import { resolvePaths, relativeImport, formatAndWrite } from './config.ts'
|
|
@@ -102,14 +102,14 @@ export default class TestGenerator {
|
|
|
102
102
|
const lines: string[] = [
|
|
103
103
|
'// Generated by Strav — DO NOT EDIT',
|
|
104
104
|
`import 'reflect-metadata'`,
|
|
105
|
-
`import { app } from '@
|
|
106
|
-
`import Configuration from '@
|
|
107
|
-
`import Database from '@
|
|
108
|
-
`import Router from '@
|
|
109
|
-
`import Logger from '@
|
|
110
|
-
`import BaseModel from '@
|
|
111
|
-
`import Auth from '@
|
|
112
|
-
`import AccessToken from '@
|
|
105
|
+
`import { app } from '@strav/kernel/core'`,
|
|
106
|
+
`import Configuration from '@strav/kernel/config/configuration'`,
|
|
107
|
+
`import Database from '@strav/database/database/database'`,
|
|
108
|
+
`import Router from '@strav/http/http/router'`,
|
|
109
|
+
`import Logger from '@strav/kernel/logger/logger'`,
|
|
110
|
+
`import BaseModel from '@strav/database/orm/base_model'`,
|
|
111
|
+
`import Auth from '@strav/http/auth/auth'`,
|
|
112
|
+
`import AccessToken from '@strav/http/auth/access_token'`,
|
|
113
113
|
'',
|
|
114
114
|
'// ---------------------------------------------------------------------------',
|
|
115
115
|
'// Bootstrap (mirrors index.ts, minus Server)',
|