@nestjs/common#Optional TypeScript Examples

The following examples show how to use @nestjs/common#Optional. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: hook-explorer.service.ts    From nestjs-mercurius with MIT License 6 votes vote down vote up
constructor(
    private readonly modulesContainer: ModulesContainer,
    private readonly metadataScanner: MetadataScanner,
    @Optional()
    @Inject(GRAPHQL_MODULE_OPTIONS)
    private readonly gqlOptions?: MercuriusModuleOptions,
  ) {
    super();
  }
Example #2
Source File: event-store.service.ts    From nestjs-geteventstore with MIT License 6 votes vote down vote up
constructor(
    @Inject(EVENT_STORE_CONNECTOR)
    private readonly eventStore: Client,
    @Inject(EVENT_STORE_SUBSYSTEMS)
    private readonly subsystems: IEventStoreSubsystems,
    @Inject(EVENTS_AND_METADATAS_STACKER)
    private readonly eventsStacker: IEventsAndMetadatasStacker,
    private readonly eventStoreHealthIndicator: EventStoreHealthIndicator,
    @Optional() private readonly eventBus?: ReadEventBus,
  ) {}
Example #3
Source File: create-conditional-dep-holder.helper.ts    From nestjs-bullmq with MIT License 6 votes vote down vote up
export function createConditionalDepHolder<T = any>(
  depToken: string,
  optionalDep = BULL_CONFIG_DEFAULT_TOKEN,
  errorFactory = (caller: string) =>
    new MissingBullSharedConfigurationError(depToken, caller),
): Type<IConditionalDepHolder> {
  class ConditionalDepHolder {
    constructor(@Optional() @Inject(depToken) public _dependencyRef: T) {}

    getDependencyRef(caller: string): T {
      if (depToken !== optionalDep && !this._dependencyRef) {
        throw errorFactory(caller);
      }
      return this._dependencyRef;
    }
  }
  return mixin(ConditionalDepHolder);
}
Example #4
Source File: service-bus.module.ts    From pebula-node with MIT License 6 votes vote down vote up
constructor(discoveryFactory: SbDiscoveryFactoryService,
              @Optional() errorHandler?: SbErrorHandler,
              @Optional() @Inject(SB_META_HELPER_FACTORY_TOKEN) metadataHelper?: any,
              @Optional() @Inject(SB_CLIENT_OPTIONS) clientOptions?: SbClientOptions[],
              @Optional() @Inject(SB_SERVER_OPTIONS) serverOptions?: SbServerOptions[]) {
    if (!Array.isArray(serverOptions) || serverOptions.length === 0) {
      throw new Error('You must define at least 1 server, did you use `ServiceBusModule.register()` ?');
    }

    if (errorHandler) {
      sbResourceManager.errorHandler = errorHandler;
    }

    this.discovery = discoveryFactory.create(
      serverOptions,
      !Array.isArray(clientOptions) || clientOptions.length === 0 ? [{}] : clientOptions,
      metadataHelper,
    );

    this.discovery.init();
  }
Example #5
Source File: joi.pipe.ts    From nestjs-joi with MIT License 6 votes vote down vote up
constructor(
    @Inject(REQUEST) private readonly arg?: unknown,
    @Optional() @Inject(JOIPIPE_OPTIONS) pipeOpts?: JoiPipeOptions,
  ) {
    if (arg) {
      // Test for an actual request object, which indicates we're in "injected" mode.
      // This is the case that requires the most performant handling, which is why it
      // should be the first branch.
      if (isHttpRequest(arg)) {
        this.method = arg.method.toUpperCase();
      } else if (isGraphQlRequest(arg)) {
        // @nestjs/graphql, or rather apollo, only supports GET and POST.
        // To provide a consistent experience without hard to understand behavior
        // such as UPDATE group schemas being ignored, we will NOT set the method.
        // JoiPipe will work for this case, but ignore the method.
        // this.method = arg.req.method.toUpperCase();
      } else {
        // This is the "manually called constructor" case, where performance is
        // (ostensibly) not as big of a concern since manual JoiPipes will be
        // constructed only once at app initialization
        if (Joi.isSchema(arg)) {
          this.schema = arg as Joi.Schema;
        } else if (typeof arg === 'function') {
          this.type = arg as Constructor;
        } else {
          // Options passed as first parameter
          pipeOpts = arg as JoiPipeOptions;
        }
      }
    } else {
      // Called without arguments, do nothing
    }

    this.pipeOpts = this.parseOptions(pipeOpts);
  }
Example #6
Source File: base.service.ts    From codeclannigeria-backend with MIT License 5 votes vote down vote up
@Optional()
  @Inject(REQUEST)
  protected readonly req: Request;
Example #7
Source File: back-off.interceptor.ts    From pebula-node with MIT License 5 votes vote down vote up
constructor(@Inject(SB_BACKOFF_RETRY_DEFAULTS) @Optional() options?: SbBackoffRetryOptions) {
    this.config = { ...DEFAULT_BACKOFF_CONFIG, ...(options || {}) };
  }