Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment Update #321

Merged
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/grpc-http-proxy/proto/examples/echo/v1/echo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Metadata } from '@grpc/grpc-js'
import type { Metadata } from '@grpc/grpc-js'

/* eslint-disable */
import { GrpcMethod } from '@nestjs/microservices'
import { GrpcStreamMethod } from '@nestjs/microservices'
Expand Down
14 changes: 11 additions & 3 deletions examples/grpc-http-proxy/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import { NestFactory } from '@nestjs/core'
import { GrpcHttpProxyAppModule } from './grpc-http-proxy-app.module.js'
import { serverOptions } from './server.options.js'

declare const module: any
// eslint-disable-next-line @next/next/no-assign-module-variable
declare const module: {
hot?: {
accept: () => void
dispose: (callback: () => Promise<void>) => void
}
}

const bootstrap = async () => {
const bootstrap = async (): Promise<void> => {
const app = await NestFactory.create(GrpcHttpProxyAppModule)

app.connectMicroservice(serverOptions)
Expand All @@ -18,7 +24,9 @@ const bootstrap = async () => {

if (module.hot) {
module.hot.accept()
module.hot.dispose(() => app.close())
module.hot.dispose(async () => {
await app.close()
})
}
}

Expand Down
2 changes: 0 additions & 2 deletions examples/grpc-http-proxy/src/grpc-http-proxy-app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { serverOptions } from './server.options.js'

@Module({
imports: [
// @ts-ignore
GrpcReflectionModule.register(serverOptions.options),
// @ts-ignore
GrpcHttpProxyModule.register({ options: serverOptions.options }),
EchoModule,
],
Expand Down
9 changes: 5 additions & 4 deletions examples/grpc-http-proxy/src/server.options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/// <reference path='./proto.d.ts'/>

import { Transport } from '@nestjs/microservices'
import { GrpcOptions } from '@nestjs/microservices'
import type { GrpcOptions } from '@nestjs/microservices'

import reflection from '@atls/nestjs-grpc-reflection/proto/grpc/reflection/v1alpha/reflection.proto'
import { Transport } from '@nestjs/microservices'

import echo from '../proto/examples/echo/v1/echo.proto'
import reflection from '@atls/nestjs-grpc-reflection/proto/grpc/reflection/v1alpha/reflection.proto'

import echo from '../proto/examples/echo/v1/echo.proto'

export const serverOptions: GrpcOptions = {
transport: Transport.GRPC,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Metadata } from '@grpc/grpc-js'
import type { Metadata } from '@grpc/grpc-js'

/* eslint-disable */
import { GrpcMethod } from '@nestjs/microservices'
import { GrpcStreamMethod } from '@nestjs/microservices'
Expand Down
14 changes: 11 additions & 3 deletions examples/grpc-playground/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import { NestFactory } from '@nestjs/core'
import { GrpcPlaygroundAppModule } from './grpc-playground-app.module.js'
import { serverOptions } from './server.options.js'

declare const module: any
// eslint-disable-next-line @next/next/no-assign-module-variable
declare const module: {
hot?: {
accept: () => void
dispose: (callback: () => Promise<void>) => void
}
}

const bootstrap = async () => {
const bootstrap = async (): Promise<void> => {
const app = await NestFactory.create(GrpcPlaygroundAppModule)

app.connectMicroservice(serverOptions)
Expand All @@ -18,7 +24,9 @@ const bootstrap = async () => {

if (module.hot) {
module.hot.accept()
module.hot.dispose(() => app.close())
module.hot.dispose(async () => {
await app.close()
})
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
// @ts-nocheck
import { Controller } from '@nestjs/common'
import { GrpcMethod } from '@nestjs/microservices'
Expand Down
9 changes: 5 additions & 4 deletions examples/grpc-playground/src/server.options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/// <reference path='./proto.d.ts'/>

import { Transport } from '@nestjs/microservices'
import { GrpcOptions } from '@nestjs/microservices'
import type { GrpcOptions } from '@nestjs/microservices'

import reflection from '@atls/nestjs-grpc-reflection/proto/grpc/reflection/v1alpha/reflection.proto'
import { Transport } from '@nestjs/microservices'

import playground from '../proto/examples/playground/v1/playground.proto'
import reflection from '@atls/nestjs-grpc-reflection/proto/grpc/reflection/v1alpha/reflection.proto'

import playground from '../proto/examples/playground/v1/playground.proto'

export const serverOptions: GrpcOptions = {
transport: Transport.GRPC,
Expand Down
3 changes: 2 additions & 1 deletion examples/grpc-reflection/proto/examples/echo/v1/echo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Metadata } from '@grpc/grpc-js'
import type { Metadata } from '@grpc/grpc-js'

/* eslint-disable */
import { GrpcMethod } from '@nestjs/microservices'
import { GrpcStreamMethod } from '@nestjs/microservices'
Expand Down
14 changes: 11 additions & 3 deletions examples/grpc-reflection/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ import { NestFactory } from '@nestjs/core'
import { GrpcReflectionAppModule } from './grpc-reflection-app.module.js'
import { serverOptions } from './server.options.js'

declare const module: any
// eslint-disable-next-line @next/next/no-assign-module-variable
declare const module: {
hot?: {
accept: () => void
dispose: (callback: () => Promise<void>) => void
}
}

const bootstrap = async () => {
const bootstrap = async (): Promise<void> => {
const app = await NestFactory.create(GrpcReflectionAppModule)

app.connectMicroservice(serverOptions)
Expand All @@ -17,7 +23,9 @@ const bootstrap = async () => {

if (module.hot) {
module.hot.accept()
module.hot.dispose(() => app.close())
module.hot.dispose(async () => {
await app.close()
})
}
}

Expand Down
1 change: 0 additions & 1 deletion examples/grpc-reflection/src/grpc-reflection-app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { EchoModule } from './echo/index.js'
import { serverOptions } from './server.options.js'

@Module({
// @ts-ignore
imports: [GrpcReflectionModule.register(serverOptions.options), EchoModule],
})
export class GrpcReflectionAppModule {}
9 changes: 5 additions & 4 deletions examples/grpc-reflection/src/server.options.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/// <reference path='./proto.d.ts'/>

import { Transport } from '@nestjs/microservices'
import { GrpcOptions } from '@nestjs/microservices'
import type { GrpcOptions } from '@nestjs/microservices'

import reflection from '@atls/nestjs-grpc-reflection/proto/grpc/reflection/v1alpha/reflection.proto'
import { Transport } from '@nestjs/microservices'

import echo from '../proto/examples/echo/v1/echo.proto'
import reflection from '@atls/nestjs-grpc-reflection/proto/grpc/reflection/v1alpha/reflection.proto'

import echo from '../proto/examples/echo/v1/echo.proto'

export const serverOptions: GrpcOptions = {
transport: Transport.GRPC,
Expand Down
6 changes: 4 additions & 2 deletions packages/nestjs-dataloader/src/decorators/loader.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ExecutionContext } from '@nestjs/common'
import type { ExecutionContext } from '@nestjs/common'
import type { GraphQLExecutionContext } from '@nestjs/graphql'

import { InternalServerErrorException } from '@nestjs/common'
import { APP_INTERCEPTOR } from '@nestjs/core'
import { GqlExecutionContext } from '@nestjs/graphql'
import { GraphQLExecutionContext } from '@nestjs/graphql'
import { createParamDecorator } from '@nestjs/common'

import { GET_LOADER_CONTEXT_KEY } from '../constants.js'
Expand All @@ -21,5 +22,6 @@ export const Loader: (type: string) => ParameterDecorator = createParamDecorator
`)
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return
return ctx[GET_LOADER_CONTEXT_KEY](type)
})
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
/* eslint-disable no-param-reassign */

export const OrderResultByKey = (key = 'id', defaultValue = undefined) =>
(target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
(target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor => {
const original = descriptor.value

// @ts-ignore eslint-disable-next-line func-names
descriptor.value = async function (keys, ...args) {
// @ts-expect-error
// eslint-disable-next-line func-names
descriptor.value = async function (keys, ...args): Promise<any> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const method = original.bind(this)
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const result = await method(keys, ...args)

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const resultByKey = result.reduce(
// @ts-ignore
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
(res, item) => ({
...res,
[item[key]]: item,
}),
{}
)

// @ts-ignore
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
return keys.map((itemKey) => resultByKey[itemKey] || defaultValue)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { CallHandler } from '@nestjs/common'
import { ExecutionContext } from '@nestjs/common'
import type { CallHandler } from '@nestjs/common'
import type { ExecutionContext } from '@nestjs/common'
import type { NestInterceptor } from '@nestjs/common'
import type { GraphQLExecutionContext } from '@nestjs/graphql'
import type { Observable } from 'rxjs'

import type { NestDataLoader } from '../interfaces/index.js'

import { Injectable } from '@nestjs/common'
import { InternalServerErrorException } from '@nestjs/common'
import { NestInterceptor } from '@nestjs/common'
import { ModuleRef } from '@nestjs/core'
import { GqlExecutionContext } from '@nestjs/graphql'
import { GraphQLExecutionContext } from '@nestjs/graphql'
// @ts-ignore
import { Observable } from 'rxjs'

import { GET_LOADER_CONTEXT_KEY } from '../constants.js'
import { NestDataLoader } from '../interfaces/index.js'

@Injectable()
export class DataLoaderInterceptor implements NestInterceptor {
Expand All @@ -32,6 +33,7 @@ export class DataLoaderInterceptor implements NestInterceptor {
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return ctx[type]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import DataLoader from 'dataloader'
import type DataLoader from 'dataloader'

export interface NestDataLoader {
generateDataLoader(): DataLoader<any, any>
generateDataLoader: () => DataLoader<any, any>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@ import { Res } from '@nestjs/common'
export class ExecController {
@Get('/simple')
@Render('/render/simple')
simple() {
simple(): Record<string, unknown> {
return {}
}

@Get('/params')
@Render('/render/params')
params() {
params(): Record<string, unknown> {
return {
param: 'value',
}
}

@Get('/res-render-params')
// @ts-ignore
resRenderParams(@Res() res) {
return res.render('/render/params', {
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
resRenderParams(@Res() res): void {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
res.render('/render/params', {
param: 'value',
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import { Post } from '@nestjs/common'
@Controller('render')
export class RenderController {
@Post('simple')
simple() {
simple(): string {
return 'content'
}

@Post('params')
// @ts-ignore
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
params(@Body() body) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return body.param
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* @jest-environment node
*/

import { INestApplication } from '@nestjs/common'
import type { INestApplication } from '@nestjs/common'

import { Test } from '@nestjs/testing'
import { describe } from '@jest/globals'
import { it } from '@jest/globals'
Expand All @@ -22,7 +23,7 @@ describe('external renderer', () => {
beforeAll(async () => {
const port = await getPort()

const module = await Test.createTestingModule({
const testingModule = await Test.createTestingModule({
imports: [ExternalRendererIntegrationModule],
})
.overrideProvider(EXTERNAL_RENDERER_MODULE_OPTIONS)
Expand All @@ -31,7 +32,7 @@ describe('external renderer', () => {
})
.compile()

app = module.createNestApplication()
app = testingModule.createNestApplication()

await app.init()
await app.listen(port, '0.0.0.0')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExternalRendererOptionsFactory } from '../module/index.js'
import { ExternalRendererModuleOptions } from '../module/index.js'
import type { ExternalRendererOptionsFactory } from '../module/index.js'
import type { ExternalRendererModuleOptions } from '../module/index.js'

export class ExternalRendererEnvConfig implements ExternalRendererOptionsFactory {
createExternalRendererOptions(): ExternalRendererModuleOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { ModuleMetadata } from '@nestjs/common/interfaces'
import { Type } from '@nestjs/common/interfaces'
import type { ModuleMetadata } from '@nestjs/common/interfaces'
import type { Type } from '@nestjs/common/interfaces'

export interface ExternalRendererModuleOptions {
url: string
}

export interface ExternalRendererOptionsFactory {
createExternalRendererOptions():
| Promise<ExternalRendererModuleOptions>
createExternalRendererOptions: () =>
| ExternalRendererModuleOptions
| Promise<ExternalRendererModuleOptions>
}

export interface ExternalRendererModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
useExisting?: Type<ExternalRendererOptionsFactory>
useClass?: Type<ExternalRendererOptionsFactory>
useFactory?: (
...args: any[]
) => Promise<ExternalRendererModuleOptions> | ExternalRendererModuleOptions
inject?: any[]
...args: Array<any>
) => ExternalRendererModuleOptions | Promise<ExternalRendererModuleOptions>
inject?: Array<any>
}
Loading
Loading