@newt-app/templates 0.11.0 → 0.13.2

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.
Files changed (2) hide show
  1. package/dist/index.js +60 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1046,14 +1046,52 @@ var tsconfig_build_default = {
1046
1046
  var app_module_default = {
1047
1047
  filename: "apps/api/src/app.module.ts",
1048
1048
  template: `import { Module } from '@nestjs/common';
1049
+ import { AppService } from './app.service';
1049
1050
  import { TodosModule } from './todos/todos.module';
1050
1051
 
1051
1052
  @Module({
1052
1053
  imports: [TodosModule],
1054
+ providers: [AppService],
1053
1055
  })
1054
1056
  export class AppModule {}`
1055
1057
  };
1056
1058
 
1059
+ // src/api/templates/app-service.ts
1060
+ var app_service_default = {
1061
+ filename: "apps/api/src/app.service.ts",
1062
+ template: `import { Injectable } from '@nestjs/common';
1063
+
1064
+ @Injectable()
1065
+ export class AppService {
1066
+ getHello(): string {
1067
+ return 'Hello from Nest';
1068
+ }
1069
+ }`
1070
+ };
1071
+
1072
+ // src/api/templates/app-service-spec.ts
1073
+ var app_service_spec_default = {
1074
+ filename: "apps/api/src/app.service.spec.ts",
1075
+ template: `import { Test, TestingModule } from '@nestjs/testing';
1076
+ import { AppService } from './app.service';
1077
+
1078
+ describe('AppService', () => {
1079
+ let service: AppService;
1080
+
1081
+ beforeEach(async () => {
1082
+ const module: TestingModule = await Test.createTestingModule({
1083
+ providers: [AppService],
1084
+ }).compile();
1085
+
1086
+ service = module.get<AppService>(AppService);
1087
+ });
1088
+
1089
+ it('should be defined', () => {
1090
+ expect(service).toBeDefined();
1091
+ });
1092
+ });`
1093
+ };
1094
+
1057
1095
  // src/api/templates/todos-module.ts
1058
1096
  var todos_module_default = {
1059
1097
  filename: "apps/api/src/todos/todos.module.ts",
@@ -1157,6 +1195,8 @@ var api = {
1157
1195
  tsconfig_default2,
1158
1196
  tsconfig_build_default,
1159
1197
  app_module_default,
1198
+ app_service_default,
1199
+ app_service_spec_default,
1160
1200
  todos_module_default,
1161
1201
  todos_service_default,
1162
1202
  todos_service_spec_default,
@@ -9114,6 +9154,7 @@ var api_tsconfig_default = {
9114
9154
  var api_index_default = {
9115
9155
  filename: "apps/api/src/index.ts",
9116
9156
  template: `export { AppModule } from './app.module';
9157
+ export { AppService } from './app.service';
9117
9158
  export { TodosService } from './todos/todos.service';
9118
9159
  export type { Todo } from './todos/todos.service';`
9119
9160
  };
@@ -9128,7 +9169,7 @@ import type { INestApplicationContext } from '@nestjs/common';
9128
9169
 
9129
9170
  let context: INestApplicationContext | null = null;
9130
9171
 
9131
- export async function getNestApp(): Promise<INestApplicationContext> {
9172
+ export async function getContext(): Promise<INestApplicationContext> {
9132
9173
  if (!context) {
9133
9174
  context = await NestFactory.createApplicationContext(AppModule, {
9134
9175
  logger: false,
@@ -9142,18 +9183,18 @@ export async function getNestApp(): Promise<INestApplicationContext> {
9142
9183
  var web_todos_route_default = {
9143
9184
  filename: "apps/web/app/api/todos/route.ts",
9144
9185
  template: `import { NextResponse } from 'next/server';
9145
- import { getNestApp } from '@/lib/nest';
9186
+ import { getContext } from '@/lib/nest';
9146
9187
  import { TodosService } from '@<%= projectName %>/api';
9147
9188
 
9148
9189
  export async function GET() {
9149
- const app = await getNestApp();
9190
+ const app = await getContext();
9150
9191
  const todos = app.get(TodosService);
9151
9192
  return NextResponse.json(todos.findAll());
9152
9193
  }
9153
9194
 
9154
9195
  export async function POST(req: Request) {
9155
9196
  const { title } = await req.json();
9156
- const app = await getNestApp();
9197
+ const app = await getContext();
9157
9198
  const todos = app.get(TodosService);
9158
9199
  return NextResponse.json(todos.create(title), { status: 201 });
9159
9200
  }`
@@ -9163,12 +9204,12 @@ export async function POST(req: Request) {
9163
9204
  var web_todos_id_route_default = {
9164
9205
  filename: "apps/web/app/api/todos/[id]/route.ts",
9165
9206
  template: `import { NextResponse } from 'next/server';
9166
- import { getNestApp } from '@/lib/nest';
9207
+ import { getContext } from '@/lib/nest';
9167
9208
  import { TodosService } from '@<%= projectName %>/api';
9168
9209
 
9169
9210
  export async function DELETE(_req: Request, { params }: { params: Promise<{ id: string }> }) {
9170
9211
  const { id } = await params;
9171
- const app = await getNestApp();
9212
+ const app = await getContext();
9172
9213
  const todos = app.get(TodosService);
9173
9214
  todos.remove(Number(id));
9174
9215
  return new NextResponse(null, { status: 204 });
@@ -9179,12 +9220,12 @@ export async function DELETE(_req: Request, { params }: { params: Promise<{ id:
9179
9220
  var web_todos_toggle_route_default = {
9180
9221
  filename: "apps/web/app/api/todos/[id]/toggle/route.ts",
9181
9222
  template: `import { NextResponse } from 'next/server';
9182
- import { getNestApp } from '@/lib/nest';
9223
+ import { getContext } from '@/lib/nest';
9183
9224
  import { TodosService } from '@<%= projectName %>/api';
9184
9225
 
9185
9226
  export async function PATCH(_req: Request, { params }: { params: Promise<{ id: string }> }) {
9186
9227
  const { id } = await params;
9187
- const app = await getNestApp();
9228
+ const app = await getContext();
9188
9229
  const todos = app.get(TodosService);
9189
9230
  return NextResponse.json(todos.toggle(Number(id)));
9190
9231
  }`
@@ -9294,9 +9335,13 @@ var web_tsconfig_default = {
9294
9335
  var web_hello_route_default = {
9295
9336
  filename: "apps/web/app/api/hello/route.ts",
9296
9337
  template: `import { NextResponse } from 'next/server';
9338
+ import { getContext } from '@/lib/nest';
9339
+ import { AppService } from '@<%= projectName %>/api';
9297
9340
 
9298
9341
  export async function GET() {
9299
- return NextResponse.json({ message: 'Hello from Nest' });
9342
+ const ctx = await getContext();
9343
+ const appService = ctx.get(AppService);
9344
+ return NextResponse.json({ message: appService.getHello() });
9300
9345
  }`
9301
9346
  };
9302
9347
 
@@ -9327,9 +9372,12 @@ import {
9327
9372
  Session,
9328
9373
  UserSession,
9329
9374
  } from '@thallesp/nestjs-better-auth';
9375
+ import { AppService } from './app.service';
9330
9376
 
9331
9377
  @Controller()
9332
9378
  export class AppController {
9379
+ constructor(private readonly appService: AppService) {}
9380
+
9333
9381
  @AllowAnonymous()
9334
9382
  @Get('hello')
9335
9383
  getHello(@Session() session: UserSession | null) {
@@ -9337,7 +9385,7 @@ export class AppController {
9337
9385
  return { message: \`Hello \${session.user.name}\` };
9338
9386
  }
9339
9387
 
9340
- return { message: 'Hello from Nest' };
9388
+ return { message: this.appService.getHello() };
9341
9389
  }
9342
9390
  }`
9343
9391
  };
@@ -9373,12 +9421,13 @@ import { APP_GUARD } from '@nestjs/core';
9373
9421
  import { AuthGuard, AuthModule } from '@thallesp/nestjs-better-auth';
9374
9422
  import { auth } from '@<%= projectName %>/auth';
9375
9423
  import { AppController } from './app.controller';
9424
+ import { AppService } from './app.service';
9376
9425
  import { TodosModule } from './todos/todos.module';
9377
9426
 
9378
9427
  @Module({
9379
9428
  imports: [AuthModule.forRoot({ auth }), TodosModule],
9380
9429
  controllers: [AppController],
9381
- providers: [{ provide: APP_GUARD, useClass: AuthGuard }],
9430
+ providers: [AppService, { provide: APP_GUARD, useClass: AuthGuard }],
9382
9431
  })
9383
9432
  export class AppModule {}`
9384
9433
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newt-app/templates",
3
- "version": "0.11.0",
3
+ "version": "0.13.2",
4
4
  "private": false,
5
5
  "description": "Templates for newt-app",
6
6
  "type": "module",