UNPKG

nest-cluster-ipc

Version:

A Nest module wrapper for node-cluster-ipc

86 lines 3.61 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var ClusterIpcModule_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClusterIpcModule = void 0; const common_1 = require("@nestjs/common"); const core_1 = require("@nestjs/core"); const cluster_ipc_constants_1 = require("./cluster-ipc.constants"); const node_cluster_ipc_1 = require("node-cluster-ipc"); const cluster_ipc_explorer_1 = require("./cluster-ipc.explorer"); const cluster_ipc_metadata_accessor_1 = require("./cluster-ipc-metadata.accessor"); let ClusterIpcModule = ClusterIpcModule_1 = class ClusterIpcModule { static forRoot(options) { return { module: ClusterIpcModule_1, imports: [core_1.DiscoveryModule], providers: [ { provide: cluster_ipc_constants_1.CLUSTER_IPC_INSTANCE, useValue: new node_cluster_ipc_1.ClusterIpc(options), }, ], exports: [cluster_ipc_constants_1.CLUSTER_IPC_INSTANCE], }; } static forRootAsync(options) { return { module: ClusterIpcModule_1, imports: options.imports, providers: [ ...this.createAsyncProviders(options), { provide: cluster_ipc_constants_1.CLUSTER_IPC_INSTANCE, useFactory: (options) => new node_cluster_ipc_1.ClusterIpc(options), inject: [cluster_ipc_constants_1.CLUSTER_IPC_INSTANCE], }, ], exports: [cluster_ipc_constants_1.CLUSTER_IPC_INSTANCE], }; } static createAsyncProviders(options) { if (options.useExisting || options.useFactory) { return [this.createAsyncOptionsProvider(options)]; } const useClass = options.useClass; return [ this.createAsyncOptionsProvider(options), { provide: useClass, useClass, }, ]; } static createAsyncOptionsProvider(options) { if (options.useFactory) { return { provide: cluster_ipc_constants_1.CLUSTER_IPC_OPTIONS, useFactory: options.useFactory, inject: options.inject || [], }; } const inject = [ (options.useClass || options.useExisting), ]; return { provide: cluster_ipc_constants_1.CLUSTER_IPC_OPTIONS, useFactory: async (optionsFactory) => await optionsFactory.createClusterIpcOptions(), inject, }; } }; exports.ClusterIpcModule = ClusterIpcModule; exports.ClusterIpcModule = ClusterIpcModule = ClusterIpcModule_1 = __decorate([ (0, common_1.Global)(), (0, common_1.Module)({ imports: [core_1.DiscoveryModule], providers: [cluster_ipc_explorer_1.ClusterIpcExplorer, cluster_ipc_metadata_accessor_1.ClusterIpcMetadataAccessor], }) ], ClusterIpcModule); //# sourceMappingURL=cluster-ipc.module.js.map