@dryv/nestjsv0.6.0
NestJS feature controllers, services and modules for HTTP operations.
dryv pack add @dryv/nestjs{%- macro has_slot(slot) -%}
{%- for dependency in file.dependencies -%}{%- if dependency.slot == slot -%}x{%- endif -%}{%- endfor -%}
{%- endmacro -%}
{%- set persistence = has_slot('schema.persistence') != '' -%}
import { Module, type Type } from "@nestjs/common";
{%- if persistence %}
import { TypeOrmModule } from "@nestjs/typeorm";
{%- endif %}
{#- An implementation or use case belongs here only when it serves one of this feature's own
operations; a referenced operation of another feature brings its own artifacts along. -#}
{%- macro own(dependency) -%}
{%- for operation in operations -%}{%- if dependency.target.id == operation.id -%}x{%- endif -%}{%- endfor -%}
{%- endmacro -%}
{%- for dependency in file.dependencies %}{% if dependency.symbol and (dependency.slot == 'schema.persistence' or (dependency.slot in ['operation.implementation', 'operation.usecase'] and own(dependency) != '')) %}
import { {{ dependency.symbol }} } from "{{ (dependency.path.prefixed or ('./' ~ dependency.path.relative)) }}";
{%- endif %}{% endfor %}
import { {{ group.name.pascal }}{{ feature.name.pascal }}Controller } from "./{{ feature.name.kebab }}.controller.ts";
import { {{ group.name.pascal }}{{ feature.name.pascal }}Service } from "./{{ feature.name.kebab }}.service.ts";
@Module({
{%- if persistence %}
imports: [
TypeOrmModule.forFeature([
{%- for entity in file.dependencies %}{% if entity.slot == 'schema.persistence' %}
{{ entity.symbol }},
{%- endif %}{% endfor %}
]),
],
{%- endif %}
controllers: [{{ group.name.pascal }}{{ feature.name.pascal }}Controller],
providers: [
{%- for implementation in file.dependencies %}{% if implementation.slot == 'operation.implementation' and own(implementation) != '' %}
{
provide: {{ group.name.pascal }}{{ feature.name.pascal }}Service,
useClass: {{ implementation.symbol }} satisfies Type<{{ group.name.pascal }}{{ feature.name.pascal }}Service>,
},
{%- endif %}{% endfor %}
{%- for usecase in file.dependencies %}{% if usecase.slot == 'operation.usecase' and own(usecase) != '' %}
{{ usecase.symbol }},
{%- endif %}{% endfor %}
],
exports: [{{ group.name.pascal }}{{ feature.name.pascal }}Service],
})
export class {{ file.symbol }} {}