Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages
The information in this browser tab may be outdated, please refresh this page for the latest updates.

Repository URL to install this package:

Details    
@nestjs/core / injector / module-token-factory.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const random_string_generator_util_1 = require("@nestjs/common/utils/random-string-generator.util");
const fast_safe_stringify_1 = require("fast-safe-stringify");
const hash = require("object-hash");
class ModuleTokenFactory {
    constructor() {
        this.moduleIdsCache = new WeakMap();
    }
    create(metatype, dynamicModuleMetadata) {
        const moduleId = this.getModuleId(metatype);
        const opaqueToken = {
            id: moduleId,
            module: this.getModuleName(metatype),
            dynamic: this.getDynamicMetadataToken(dynamicModuleMetadata),
        };
        return hash(opaqueToken, { ignoreUnknown: true });
    }
    getDynamicMetadataToken(dynamicModuleMetadata) {
        // Uses safeStringify instead of JSON.stringify to support circular dynamic modules
        // The replacer function is also required in order to obtain real class names
        // instead of the unified "Function" key
        return dynamicModuleMetadata
            ? fast_safe_stringify_1.default(dynamicModuleMetadata, this.replacer)
            : '';
    }
    getModuleId(metatype) {
        let moduleId = this.moduleIdsCache.get(metatype);
        if (moduleId) {
            return moduleId;
        }
        moduleId = random_string_generator_util_1.randomStringGenerator();
        this.moduleIdsCache.set(metatype, moduleId);
        return moduleId;
    }
    getModuleName(metatype) {
        return metatype.name;
    }
    replacer(key, value) {
        if (typeof value === 'function') {
            return value.name;
        }
        return value;
    }
}
exports.ModuleTokenFactory = ModuleTokenFactory;