UNPKG

dino-express

Version:

DinO enabled REST framework based on express

64 lines 2.86 kB
"use strict"; // Copyright 2025 Quirino Brizi // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. Object.defineProperty(exports, "__esModule", { value: true }); exports.RequestAdaptor = void 0; const dino_core_1 = require("dino-core"); const AbstractRequestAdaptor_1 = require("../AbstractRequestAdaptor"); const AwsRequestAdaptor_1 = require("./AwsRequestAdaptor"); const EventRequestAdaptor_1 = require("./EventRequestAdaptor"); const MixedRequestAdaptor_1 = require("./MixedRequestAdaptor"); class RequestAdaptor extends AbstractRequestAdaptor_1.AbstractRequestAdaptor { runtimeContext; environment; applicationContext; constructor(runtimeContext, environment, applicationContext) { super(); this.environment = environment; this.runtimeContext = runtimeContext; this.applicationContext = applicationContext; } adapt(req) { dino_core_1.Logger.debug('Adapting received message'); let adaptor; if (this.runtimeContext.isRunningOnAwsLambda()) { dino_core_1.Logger.debug('adapting request for AWS Lambda interaction'); adaptor = this.resolveAdaptor('awsRequestAdaptor') ?? new AwsRequestAdaptor_1.AwsRequestAdaptor(this.environment); } else if (this.runtimeContext.isExposedToHandleEvents()) { dino_core_1.Logger.debug('adapting request for received event'); adaptor = this.resolveAdaptor('eventRequestAdaptor') ?? new EventRequestAdaptor_1.EventRequestAdaptor(this.environment); } else if (this.runtimeContext.isExposedToHandleMixedScenarios()) { dino_core_1.Logger.debug('adapting request for received mixed event'); adaptor = this.resolveAdaptor('mixedRequestAdaptor') ?? new MixedRequestAdaptor_1.MixedRequestAdaptor(this.environment); } // eslint-disable-next-line @typescript-eslint/consistent-type-assertions if (adaptor !== undefined) { return adaptor.adapt(req); } return req; } resolveAdaptor(key) { try { return this.applicationContext.resolve(key); } catch (e) { dino_core_1.Logger.debug(`adaptor ${key} not found`); return undefined; } } } exports.RequestAdaptor = RequestAdaptor; //# sourceMappingURL=RequestAdaptor.js.map