Sha256: c401642e62266d1ad22756fc243f7b918882e6d672b99bdfb10c3d08d8f218e9

Contents?: true

Size: 1.77 KB

Versions: 19

Compression:

Stored size: 1.77 KB

Contents

const AbstractHandler = require("./AbstractHandler");
const NamespaceCache = require("../namespaceCache/NamespaceCache");
const TypeCache = require("../typeCache/TypeCache");

class GetTypeHandler extends AbstractHandler {

    constructor() {
        super()
        this.requiredParametersCount = 1
        this.namespaceCache = new NamespaceCache();
        this.typeCache = new TypeCache();
    }

    process(command) {
        try {
            if (command.payload.length < this.requiredParametersCount) {
                throw new Error("Get Type parameters mismatch")
            }
            const {payload} = command
            let typeName = payload[0]
            typeName = typeName.replace(".js", "")
            let typeToReturn = global[typeName]
            if (typeToReturn === undefined) {
                throw new Error(`Type ${typeName} not found`)
            }

            if (
                (this.namespaceCache.isNamespaceCacheEmpty() && this.typeCache.isTypeCacheEmpty()) || // both caches are empty
                this.namespaceCache.isTypeAllowed(typeToReturn) || // namespace is allowed
                this.typeCache.isTypeAllowed(typeToReturn) // type is allowed
            ) {
                // continue - type is allowed
            } else {
                let allowed_namespaces = this.namespaceCache.getCachedNamespaces().join(", ");
                let allowed_types = this.typeCache.getCachedTypes().join(", ");
                throw new Error(`Type ${typeToReturn.name} not allowed. \nAllowed namespaces: ${allowed_namespaces}\nAllowed types: ${allowed_types}`);
            }

            return typeToReturn
        } catch (error) {
            throw this.process_stack_trace(error, this.constructor.name)
        }

    }
}

module.exports = new GetTypeHandler()

Version data entries

19 entries across 14 versions & 1 rubygems

Version Path
javonet-ruby-sdk-2.5.7 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.5.6 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.5.5 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.5.4 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.5.3 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.5.2 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.5.1 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.5.0 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.11 lib/javonet-ruby-sdk/Binaries/Nodejs/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.10 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.9 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.8 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.7 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Nodejs/MacOs/X64/core/handler/GetTypeHandler.js
javonet-ruby-sdk-2.4.6 lib/javonet-ruby-sdk/Binaries/Nodejs/Linux/X64/core/handler/GetTypeHandler.js