-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tools): granulariza geradores de entidades e casos de uso
- Loading branch information
Showing
25 changed files
with
292 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
.../src/files/use-cases/__scope__/domain/src/clent/use-cases/create-__fileName__.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/client'; | ||
import { <%= className %>Service } from '../services'; | ||
import { | ||
UseCase, | ||
<%= className %>, | ||
Editable<%= className %>, | ||
} from '@devmx/shared-api-interfaces'; | ||
|
||
export class Create<%= className %>UseCase | ||
implements UseCase<Editable<%= className %>, <%= className %>> | ||
{ | ||
constructor(private <%= propertyName %>Service: <%= className %>Service) {} | ||
|
||
execute(data: Editable<%= className %>) { | ||
return this.<%= propertyName %>Service.create(data); | ||
} | ||
} | ||
|
||
export function provideCreate<%= className %>UseCase() { | ||
return createUseCaseProvider(Create<%= className %>UseCase, [<%= className %>Service]); | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/files/use-cases/__scope__/domain/src/clent/use-cases/delete-__fileName__.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/client'; | ||
import { <%= className %>, UseCase } from '@devmx/shared-api-interfaces'; | ||
import { <%= className %>Service } from '../services'; | ||
|
||
export class Delete<%= className %>UseCase implements UseCase<string, <%= className %> | null> { | ||
constructor(private <%= propertyName %>Service: <%= className %>Service) {} | ||
|
||
execute(id: string) { | ||
return this.<%= propertyName %>Service.delete(id); | ||
} | ||
} | ||
|
||
export function provideDelete<%= className %>UseCase() { | ||
return createUseCaseProvider(Delete<%= className %>UseCase, [<%= className %>Service]); | ||
} |
22 changes: 22 additions & 0 deletions
22
.../files/use-cases/__scope__/domain/src/clent/use-cases/find-__fileNamePlural__.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/client'; | ||
import { <%= className %>Service } from '../services'; | ||
import { | ||
Page, | ||
UseCase, | ||
<%= className %>, | ||
QueryParams, | ||
} from '@devmx/shared-api-interfaces'; | ||
|
||
export class Find<%= classNamePlural %>UseCase | ||
implements UseCase<QueryParams<<%= className %>>, Page<<%= className %>>> | ||
{ | ||
constructor(private <%= propertyName %>Service: <%= className %>Service) {} | ||
|
||
execute(params: QueryParams<<%= className %>>) { | ||
return this.<%= propertyName %>Service.find(params); | ||
} | ||
} | ||
|
||
export function provideFind<%= classNamePlural %>UseCase() { | ||
return createUseCaseProvider(Find<%= classNamePlural %>UseCase, [<%= className %>Service]); | ||
} |
17 changes: 17 additions & 0 deletions
17
.../files/use-cases/__scope__/domain/src/clent/use-cases/find-__fileName__-by-id.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/client'; | ||
import { <%= className %>, UseCase } from '@devmx/shared-api-interfaces'; | ||
import { <%= className %>Service } from '../services'; | ||
|
||
export class Find<%= className %>ByIDUseCase | ||
implements UseCase<string, <%= className %> | null> | ||
{ | ||
constructor(private <%= propertyName %>Service: <%= className %>Service) {} | ||
|
||
execute(id: string) { | ||
return this.<%= propertyName %>Service.findOne(id); | ||
} | ||
} | ||
|
||
export function provideFind<%= className %>ByIDUseCase() { | ||
return createUseCaseProvider(Find<%= className %>ByIDUseCase, [<%= className %>Service]); | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/files/use-cases/__scope__/domain/src/clent/use-cases/update-__fileName__.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { UseCase, <%= className %>, Editable<%= className %> } from '@devmx/shared-api-interfaces'; | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/client'; | ||
import { <%= className %>Service } from '../services'; | ||
|
||
export class Update<%= className %>UseCase implements UseCase<Editable<%= className %>, <%= className %>> { | ||
constructor(private <%= propertyName %>Service: <%= className %>Service) {} | ||
|
||
execute(data: Editable<%= className %>) { | ||
return this.<%= propertyName %>Service.update(data.id, data); | ||
} | ||
} | ||
|
||
export function provideUpdate<%= className %>UseCase() { | ||
return createUseCaseProvider(Update<%= className %>UseCase, [<%= className %>Service]); | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/files/use-cases/__scope__/domain/src/server/use-cases/create-__fileName__.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/server'; | ||
import { UseCase, <%= className %>, Editable<%= className %> } from '@devmx/shared-api-interfaces'; | ||
import { <%= classNamePlural %>Service } from '../services'; | ||
|
||
export class Create<%= className %>UseCase implements UseCase<Editable<%= className %>, <%= className %>> { | ||
constructor(private <%= propertyNamePlural %>Service: <%= classNamePlural %>Service) {} | ||
|
||
execute(data: Editable<%= className %>) { | ||
return this.<%= propertyNamePlural %>Service.create(data); | ||
} | ||
} | ||
|
||
export function provideCreate<%= className %>UseCase() { | ||
return createUseCaseProvider(Create<%= className %>UseCase, [<%= classNamePlural %>Service]); | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/files/use-cases/__scope__/domain/src/server/use-cases/delete-__fileName__.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/server'; | ||
import { <%= className %>, UseCase } from '@devmx/shared-api-interfaces'; | ||
import { <%= classNamePlural %>Service } from '../services'; | ||
|
||
export class Delete<%= className %>UseCase implements UseCase<string, <%= className %>> { | ||
constructor(private <%= propertyNamePlural %>Service: <%= classNamePlural %>Service) {} | ||
|
||
async execute(id: string) { | ||
return this.<%= propertyNamePlural %>Service.delete(id); | ||
} | ||
} | ||
|
||
export function provideDelete<%= className %>UseCase() { | ||
return createUseCaseProvider(Delete<%= className %>UseCase, [<%= classNamePlural %>Service]) | ||
} |
22 changes: 22 additions & 0 deletions
22
...files/use-cases/__scope__/domain/src/server/use-cases/find-__fileNamePlural__.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/server'; | ||
import { <%= classNamePlural %>Service } from '../services'; | ||
import { | ||
Page, | ||
UseCase, | ||
<%= className %>, | ||
QueryParams, | ||
} from '@devmx/shared-api-interfaces'; | ||
|
||
export class Find<%= classNamePlural %>UseCase | ||
implements UseCase<QueryParams<<%= className %>>, Page<<%= className %>>> | ||
{ | ||
constructor(private <%= propertyNamePlural %>Service: <%= classNamePlural %>Service) {} | ||
|
||
async execute(params: QueryParams<<%= className %>>) { | ||
return this.<%= propertyNamePlural %>Service.find(params); | ||
} | ||
} | ||
|
||
export function provideFind<%= classNamePlural %>UseCase() { | ||
return createUseCaseProvider(Find<%= classNamePlural %>UseCase, [<%= classNamePlural %>Service]) | ||
} |
15 changes: 15 additions & 0 deletions
15
...files/use-cases/__scope__/domain/src/server/use-cases/find-__fileName__-by-id.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/server'; | ||
import { <%= className %>, UseCase } from '@devmx/shared-api-interfaces'; | ||
import { <%= classNamePlural %>Service } from '../services'; | ||
|
||
export class Find<%= className %>ByIDUseCase implements UseCase<string, <%= className %> | null> { | ||
constructor(private <%= propertyNamePlural %>Service: <%= classNamePlural %>Service) {} | ||
|
||
async execute(id: string) { | ||
return this.<%= propertyNamePlural %>Service.findOne(id); | ||
} | ||
} | ||
|
||
export function provideFind<%= className %>ByIDUseCase() { | ||
return createUseCaseProvider(Find<%= className %>ByIDUseCase, [<%= classNamePlural %>Service]) | ||
} |
15 changes: 15 additions & 0 deletions
15
...src/files/use-cases/__scope__/domain/src/server/use-cases/update-__fileName__.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createUseCaseProvider } from '@devmx/shared-util-data/server'; | ||
import { UseCase, <%= className %>, Editable<%= className %> } from '@devmx/shared-api-interfaces'; | ||
import { <%= classNamePlural %>Service } from '../services'; | ||
|
||
export class Update<%= className %>UseCase implements UseCase<Editable<%= className %>, <%= className %>> { | ||
constructor(private <%= propertyNamePlural %>Service: <%= classNamePlural %>Service) {} | ||
|
||
async execute(data: Editable<%= className %>) { | ||
return this.<%= propertyNamePlural %>Service.update(data.id, data); | ||
} | ||
} | ||
|
||
export function provideUpdate<%= className %>UseCase() { | ||
return createUseCaseProvider(Update<%= className %>UseCase, [<%= classNamePlural %>Service]) | ||
} |
1 change: 1 addition & 0 deletions
1
tools/plugin/dx-dev/src/files/use-cases/__scope__/index.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const variable = "<%= name %>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 1 addition & 14 deletions
15
tools/plugin/dx-dev/src/generators/entity/lib/normalize-options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Tree, formatFiles, generateFiles } from '@nx/devkit'; | ||
import { UseCasesGeneratorSchema } from './schema'; | ||
import { normalizeOptions } from './lib'; | ||
import { join } from 'path'; | ||
|
||
export async function useCasesGenerator( | ||
tree: Tree, | ||
options: UseCasesGeneratorSchema | ||
) { | ||
const normalizedOptions = normalizeOptions(options); | ||
|
||
const srcFolder = join(__dirname, '..', '..', 'files', 'use-cases'); | ||
|
||
generateFiles(tree, srcFolder, 'packages', normalizedOptions); | ||
|
||
await formatFiles(tree); | ||
} | ||
|
||
export default useCasesGenerator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './normalize-options'; |
12 changes: 12 additions & 0 deletions
12
tools/plugin/dx-dev/src/generators/use-cases/lib/normalize-options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { getAllNames } from '../../../utils'; | ||
import { | ||
UseCasesGeneratorSchema, | ||
NormalizedUseCasesGeneratorSchema, | ||
} from '../schema'; | ||
|
||
export function normalizeOptions( | ||
options: UseCasesGeneratorSchema | ||
): NormalizedUseCasesGeneratorSchema { | ||
const allNames = getAllNames(options.name); | ||
return { ...options, ...allNames }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface UseCasesGeneratorSchema { | ||
name: string; | ||
scope: string; | ||
} | ||
|
||
export interface NormalizedUseCasesGeneratorSchema | ||
extends EntityGeneratorSchema { | ||
constantName: string; | ||
propertyName: string; | ||
className: string; | ||
fileName: string; | ||
namePlural: string; | ||
classNamePlural: string; | ||
fileNamePlural: string; | ||
propertyNamePlural: string; | ||
constantNamePlural: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"$schema": "https://json-schema.org/schema", | ||
"$id": "UseCases", | ||
"title": "", | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "", | ||
"$default": { | ||
"$source": "argv", | ||
"index": 0 | ||
}, | ||
"x-prompt": "What name would you like to use?" | ||
}, | ||
"scope": { | ||
"type": "string", | ||
"description": "" | ||
}, | ||
"x-prompt": "What scope would you like to place files?" | ||
}, | ||
"required": ["name", "scope"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { pluralize } from './pluralize'; | ||
import { names } from '@nx/devkit'; | ||
|
||
export function getAllNames(original: string) { | ||
const normalized = names(original); | ||
const pluralNames = { | ||
namePlural: pluralize(normalized.name, 2), | ||
classNamePlural: pluralize(normalized.className, 2), | ||
fileNamePlural: pluralize(normalized.fileName, 2), | ||
propertyNamePlural: pluralize(normalized.propertyName, 2), | ||
constantNamePlural: pluralize(normalized.constantName, 2), | ||
}; | ||
return { ...normalized, ...pluralNames }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './pluralize'; | ||
export * from './get-all-names'; | ||
export * from './pluralize'; |