jitar
Version:
Distributed runtime for JavaScript and TypeScript to chop monolithic applications into micros.
2 lines (1 loc) • 2.9 kB
JavaScript
import{V as Version,d as AccessLevels}from"./Response-D49TlRAU.js";export{A as ArrayParameter,B as BadRequest,F as Forbidden,a as NamedParameter,N as NotFound,b as NotImplemented,O as ObjectParameter,P as PaymentRequired,e as Request,R as Response,c as Segment,S as ServerError,T as Teapot,U as Unauthorized}from"./Response-D49TlRAU.js";class Class{#fqn;#implementation;constructor(fqn,implementation){this.#fqn=fqn,this.#implementation=implementation}get fqn(){return this.#fqn}get implementation(){return this.#implementation}}class Procedure{#fqn;#implementations=new Map;#latestImplementation;constructor(fqn){this.#fqn=fqn}get fqn(){return this.#fqn}get public(){return[...this.#implementations.values()].some((implementation=>implementation.public))}get protected(){return[...this.#implementations.values()].some((implementation=>implementation.protected))}addImplementation(implementation){return this.#implementations.set(implementation.version,implementation),this.#isNewLatestImplementation(implementation)&&(this.#latestImplementation=implementation),this}#isNewLatestImplementation(implementation){return void 0===this.#latestImplementation||implementation.version.greater(this.#latestImplementation.version)}getImplementation(version){const selectedVersion=this.#selectAvailableVersion(version);return this.#implementations.get(selectedVersion)}#selectAvailableVersion(version){let selectedVersion=Version.DEFAULT;for(const implementationVersion of this.#implementations.keys()){if(implementationVersion.equals(version))return implementationVersion;implementationVersion.greater(version)||selectedVersion.less(implementationVersion)&&(selectedVersion=implementationVersion)}return selectedVersion}}class Implementation{#version;#access;#parameters;#executable;constructor(version,access,parameters,executable){this.#version=version,this.#access=access,this.#parameters=parameters,this.#executable=executable}get version(){return this.#version}get public(){return this.#access===AccessLevels.PUBLIC}get protected(){return this.#access===AccessLevels.PROTECTED}get private(){return this.#access===AccessLevels.PRIVATE}get parameters(){return this.#parameters}get executable(){return this.#executable}}class CorsMiddleware{#allowOrigin;#allowMethods="GET, POST";#allowHeaders;constructor(origin="*",headers="*"){this.#allowOrigin=origin,this.#allowHeaders=headers}get allowOrigin(){return this.#allowOrigin}get allowMethods(){return this.#allowMethods}get allowHeaders(){return this.#allowHeaders}async handle(request,next){const response=await next();return this.#setHeaders(response),response}#setHeaders(response){response.setHeader("Access-Control-Allow-Origin",this.#allowOrigin),response.setHeader("Access-Control-Allow-Methods",this.#allowMethods),response.setHeader("Access-Control-Allow-Headers",this.#allowHeaders)}}export{Class,CorsMiddleware,Implementation,Procedure,Version};