Skip to content

Commit 5b97739

Browse files
feat: refactoring to support breaking @dandi/core changes
supports #39
1 parent 2002bbf commit 5b97739

File tree

59 files changed

+1114
-1076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1114
-1076
lines changed

.mocharc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
3+
}

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v10.15.0
1+
v10.15.3

.nycrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
],
1414
"exclude": [
1515
"node_modules",
16-
"**/*.spec.ts",
16+
"**/*.*spec.ts",
1717
"mocha.config.js",
1818
"test",
19-
"**/local.token.ts"
19+
"**/local-token.ts"
2020
],
21-
"report-dir": ".coverage"
21+
"reportDir": ".coverage"
2222
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ allow developers to use only the features they require.
4343
# Core Modules
4444

4545
- **[@dandi/common](./packages/dandi/common)** 🕸 - Common types and utilities
46+
- **[@dandi/config](./packages/dandi/config)** 🕸 - Configuration services
4647
- **[@dandi/core](./packages/dandi/core)** 🕸 - Dependency Injection
4748
- **[@dandi/core/logging](./packages/dandi/core/logging)** 🕸 - Core logging and configuration
4849
- **[@dandi/core-node](./packages/dandi/core-node)** - Additional DI utilities specific to NodeJS
4950
- **[@dandi/data](./packages/dandi/data)** 🕸 - Base types and utilities for working with data services
50-
- **[@dandi/config](./packages/dandi/config)** 🕸 - Configuration services
5151
- **[@dandi/hal](./packages/dandi/hal)** - 🕸 - Model decorators, basic types and utilities for supporting HAL
5252
- **[@dandi/logging](./packages/dandi/logging)** - 🕸 - Additional logging utilities for logging and logging configuration
5353
- **[@dandi/model](./packages/dandi/model)** 🕸 - Model decorators

_examples/simple-console/src/app.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Bootstrapper, Inject, Injectable, Logger } from '@dandi/core'
1+
import { EntryPoint, Inject, Injectable, Logger } from '@dandi/core'
22

3-
@Injectable(Bootstrapper)
4-
export class App implements Bootstrapper {
3+
@Injectable(EntryPoint)
4+
export class SimpleConsoleApp implements EntryPoint {
55

66
constructor(@Inject(Logger) private logger: Logger) {}
77

8-
public async start(): Promise<void> {
8+
public async run(): Promise<void> {
99
this.logger.debug('Just starting up here')
1010

1111
await this.fakeWork(5)

_examples/simple-console/src/main.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
import { AmbientInjectableScanner, Container } from '@dandi/core'
1+
import { AmbientInjectableScanner, DandiApplication } from '@dandi/core'
22
import { ConsoleLogListener, LoggingModule } from '@dandi/core/logging'
33
import { PrettyColorsLogging } from '@dandi/logging'
44

5-
import { App } from './app'
5+
import { SimpleConsoleApp } from './app'
66
import { appConfigProvider } from './app-options'
77

88
export function run(startTs: number, options: any): Promise<void> {
9-
const container = new Container({
9+
const app = new DandiApplication({
1010
providers: [
1111
AmbientInjectableScanner,
1212
LoggingModule.use(ConsoleLogListener, PrettyColorsLogging),
1313

1414
appConfigProvider(options),
1515

16-
App,
16+
SimpleConsoleApp,
1717
],
1818
})
1919

20-
return container.start(startTs)
21-
20+
return app.run(startTs)
2221
}

_examples/simple-express-rest-api/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ From a command line in the
3131
This file is used as the entry point for the application. It loads and
3232
starts the container.
3333

34-
### src/server.container.ts
34+
### src/server.dandi-application.ts
3535

3636
This file is used to construct the `@dandi` DI container used to run
3737
the application. It pulls in the MVC service implementations from

_examples/simple-express-rest-api/src/server.container.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CascadingCache, MemoryCache, ServiceContextCacheKeyGenerator } from '@dandi/cache'
2-
import { AmbientInjectableScanner, Container } from '@dandi/core'
2+
import { AmbientInjectableScanner, DandiApplication } from '@dandi/core'
33
import { ConsoleLogListener, LoggingModule } from '@dandi/core/logging'
44
import { ModelBuilderModule } from '@dandi/model-builder'
55
import { MvcHalModule } from '@dandi/mvc-hal'
@@ -16,7 +16,7 @@ import { ViewController } from './view/view.controller'
1616

1717
const DEFAULT_SERVER_PORT = 7080
1818

19-
export const server = new Container({
19+
export const server = new DandiApplication({
2020
providers: [
2121
// DI
2222
AmbientInjectableScanner,

builder/src/command-runner.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { Bootstrapper, Inject, Injectable, Logger } from '@dandi/core'
1+
import { EntryPoint, Inject, Injectable, Logger } from '@dandi/core'
22

33
import { Action, ActionHost, Actions, CommandAction, CommandInfo } from './command-action'
44

55
function isActionName<T>(ctr: Function, obj: any): obj is Actions<T> {
66
return typeof obj === 'string' && typeof ctr.prototype[obj] === 'function'
77
}
88

9-
@Injectable(Bootstrapper)
10-
export class CommandRunner<THost extends any> implements Bootstrapper {
9+
@Injectable(EntryPoint)
10+
export class CommandRunner<THost extends any> implements EntryPoint {
1111

1212
constructor(
1313
@Inject(CommandAction) private actionName: CommandAction<THost>,
@@ -16,21 +16,21 @@ export class CommandRunner<THost extends any> implements Bootstrapper {
1616
@Inject(Logger) private logger: Logger,
1717
) {}
1818

19-
public start(): void {
20-
this.doRun()
19+
public run(): void {
20+
this.safeRun()
2121
}
2222

23-
private async doRun(): Promise<void> {
23+
private async safeRun(): Promise<void> {
2424
try {
25-
await this.run()
25+
await this.runAction()
2626
this.logger.info(`${this.actionName} complete.`)
2727
} catch (err) {
2828
this.logger.error(err.message, err.stack)
2929
process.exit(-1)
3030
}
3131
}
3232

33-
private async run(): Promise<void> {
33+
private async runAction(): Promise<void> {
3434
if (isActionName<THost>(this.host.constructor, this.actionName)) {
3535
return await (<Action>this.host[this.actionName])(this.info.args)
3636
}

builder/src/command-util.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dirname, resolve } from 'path'
22

33
import { Constructor } from '@dandi/common'
4-
import { AmbientInjectableScanner, Container, LogLevel } from '@dandi/core'
4+
import { AmbientInjectableScanner, DandiApplication, LogLevel } from '@dandi/core'
55
import { ConsoleLogListener, LoggingModule } from '@dandi/core/logging'
66
import { PrettyColorsLogging } from '@dandi/logging'
77

@@ -10,23 +10,23 @@ import { Command } from 'commander'
1010
import { Builder } from './builder'
1111
import { BuilderProject } from './builder-project'
1212
import { BuilderProjectOptions } from './builder-project-options'
13-
import { ActionHost, Actions, CommandAction, CommandInfo } from './command-action'
13+
import { ActionHost, CommandAction, CommandInfo } from './command-action'
1414
import { CommandRunner } from './command-runner'
1515
import { Publisher } from './publisher'
1616

1717
export type CommanderArgs = (string | Command)[]
1818

1919
export class CommandUtil {
2020

21-
public static projectAction(actionName: keyof Actions<BuilderProject>, start: number): (...args: CommanderArgs) => Promise<void> {
21+
public static projectAction(actionName: CommandAction<BuilderProject>, start: number): (...args: CommanderArgs) => Promise<void> {
2222
return this.action(BuilderProject, actionName, start)
2323
}
2424

25-
public static builderAction(actionName: keyof Actions<Builder>, start: number): (...args: CommanderArgs) => Promise<void> {
25+
public static builderAction(actionName: CommandAction<Builder>, start: number): (...args: CommanderArgs) => Promise<void> {
2626
return this.action(Builder, actionName, start)
2727
}
2828

29-
public static publisherAction(actionName: keyof Actions<Publisher>, start: number): (...args: CommanderArgs) => Promise<void> {
29+
public static publisherAction(actionName: CommandAction<Publisher>, start: number): (...args: CommanderArgs) => Promise<void> {
3030
return this.action(Publisher, actionName, start)
3131
}
3232

@@ -42,7 +42,7 @@ export class CommandUtil {
4242
args: cmdArgs,
4343
}
4444

45-
const container = new Container({
45+
const container = new DandiApplication({
4646
providers: [
4747
AmbientInjectableScanner,
4848
CommandRunner,

0 commit comments

Comments
 (0)