Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@abyss.ts/core

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@abyss.ts/core - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

115

lib/index.d.ts

@@ -1,10 +0,85 @@

interface IContextProps<TRequest> {
declare const httpStatusCodes: {
readonly continue: 100;
readonly switchingProtocols: 101;
readonly processing: 102;
readonly earlyHints: 103;
readonly ok: 200;
readonly created: 201;
readonly accepted: 202;
readonly nonAuthoritativeInformation: 203;
readonly noContent: 204;
readonly resetContent: 205;
readonly partialContent: 206;
readonly multiStatus: 207;
readonly alreadyReported: 208;
readonly imUsed: 226;
readonly multipleChoices: 300;
readonly movedPermanently: 301;
readonly found: 302;
readonly seeOther: 303;
readonly notModified: 304;
readonly useProxy: 305;
readonly unused: 306;
readonly temporaryRedirect: 307;
readonly permanentRedirect: 308;
readonly badRequest: 400;
readonly unauthorized: 401;
readonly paymentRequired: 402;
readonly forbidden: 403;
readonly notFound: 404;
readonly methodNotAllowed: 405;
readonly notAcceptable: 406;
readonly proxyAuthenticationRequired: 407;
readonly requestTimeout: 408;
readonly conflict: 409;
readonly gone: 410;
readonly lengthRequired: 411;
readonly preconditionFailed: 412;
readonly payloadTooLarge: 413;
readonly uriTooLong: 414;
readonly unsupportedMediaType: 415;
readonly rangeNotSatisfiable: 416;
readonly expectationFailed: 417;
readonly imATeapot: 418;
readonly misdirectedRequest: 421;
readonly unprocessableEntity: 422;
readonly locked: 423;
readonly failedDependency: 424;
readonly tooEarly: 425;
readonly upgradeRequired: 426;
readonly preconditionRequired: 428;
readonly tooManyRequests: 429;
readonly requestHeaderFieldsTooLarge: 431;
readonly unavailableForLegalReasons: 451;
readonly internalServerError: 500;
readonly notImplemented: 501;
readonly badGateway: 502;
readonly serviceUnavailable: 503;
readonly gatewayTimeout: 504;
readonly httpVersionNotSupported: 505;
readonly variantAlsoNegotiates: 506;
readonly insufficientStorage: 507;
readonly loopDetected: 508;
readonly notExtended: 510;
readonly networkAuthenticationRequired: 511;
};
interface IContextProps<TRequest, TResponse> {
request: TRequest;
response: TResponse;
}
declare class AbyssalContext<TRequest = unknown> {
declare class AbyssalContext<TRequest = unknown, TResponse = unknown> {
request: TRequest;
response: TResponse;
private constructor();
static create<TRequest = unknown>(context: IContextProps<TRequest>): AbyssalContext<TRequest>;
static create<TRequest = unknown, TResponse = unknown>(context: IContextProps<TRequest, TResponse>): AbyssalContext<TRequest, TResponse>;
}
interface IAbyssalExceptionHandler {
catch(error: Error, ctx: AbyssalContext, next: TFunction): void;
}
type RequiredKeys<T, K extends keyof T> = Omit<T, Extract<keyof T, K>> & Required<Pick<T, K>>;
type TExceptionHandlerClass = new () => IAbyssalExceptionHandler;
interface IAbyssalMiddleware<TContext = unknown, TNext = (...args: TAny) => TAny> {

@@ -29,2 +104,3 @@ use: (ctx: AbyssalContext<TContext>, next: TNext) => void;

protected _middlewareInstances: IAbyssalMiddleware[];
protected _exceptionHandlers: IAbyssalExceptionHandler[];
protected _port: IPortProps;

@@ -35,2 +111,3 @@ protected constructor();

useMiddleware(...middlewares: TMiddlewareClass[]): T;
useExceptionHandler(...exceptionHandlers: TExceptionHandlerClass[]): T;
useConfiguration(...configurations: TConfigurationClass[]): T;

@@ -41,2 +118,3 @@ loadEnv(): AbyssalApplication<TAny>;

protected _mapMiddlewares(): Promise<void[]>;
protected _mapExceptionHandlers(): void;
protected _mapControllers(): Promise<TAny[]>;

@@ -47,9 +125,21 @@ protected _mapInjections(): void;

declare class AbyssalAsyncStorage<TRequest = unknown> {
declare class AbyssalAsyncStorage<TRequest = unknown, TResponse = unknown> {
#private;
constructor();
get(): AbyssalContext<TRequest> | undefined;
run(ctx: AbyssalContext<TRequest>, callback: (...args: TAny) => TAny): any;
get(): AbyssalContext<TRequest, TResponse> | undefined;
run(ctx: AbyssalContext<TRequest, TResponse>, callback: (...args: TAny) => TAny): any;
}
interface IOptionsProps {
cause?: string;
customCode?: number;
statusCode?: number;
}
declare class AbyssalException extends Error {
customCode?: number;
statusCode?: number;
constructor(message: string, options?: IOptionsProps);
toJson(): Omit<AbyssalException, 'toJson'>;
}
declare function Context(): ParameterDecorator;

@@ -59,2 +149,4 @@

declare function Catch(exceptionClass: typeof AbyssalException | TAny): ClassDecorator;
declare function Get(route?: string): MethodDecorator;

@@ -138,2 +230,9 @@ declare function Post(route?: string): MethodDecorator;

interface ISetExceptionCatchClassMetadataParams {
exceptionHandler: TAny;
exceptionClass: typeof AbyssalException;
}
declare function setExceptionCatchClassMetadata({ exceptionClass, exceptionHandler, }: ISetExceptionCatchClassMetadataParams): void;
declare function getExceptionCatchClassMetadata(exceptionHandler: TAny): typeof AbyssalException;
interface IInjectionProps {

@@ -160,4 +259,2 @@ target: TAny;

type RequiredKeys<T, K extends keyof T> = Omit<T, Extract<keyof T, K>> & Required<Pick<T, K>>;
declare function getInjectableIdentity(target: TAny): string | symbol;

@@ -179,2 +276,2 @@ interface IPushToIoCContainerParams {

export { AbyssalApplication, AbyssalAsyncStorage, AbyssalContext, Body, Context, Controller, Delete, Get, type IAbyssalConfiguration, type IAbyssalMiddleware, type IActionParamProps, type IInjectionProps, Inject, Injectable, Param, Patch, Post, Put, Query, Request, type TBaseActionParam, type THttpMethod, combine, deleteInjectionMetadata, deleteMetadata, getActionParamMetadata, getControllerActionMetadata, getControllerMetadata, getFromIoCContainer, getInjectParamMetadata, getInjectableIdentity, getInjectionMetadata, getMetadata, isExistingInIoCContainer, loadControllers, mapControllers, mapInjections, pushToIoCContainer, setActionParamMetadata, setControllerActionMetadata, setControllerMetadata, setInjectParamMetadata, setInjectionMetadata, setMetadata };
export { AbyssalApplication, AbyssalAsyncStorage, AbyssalContext, AbyssalException, Body, Catch, Context, Controller, Delete, Get, type IAbyssalConfiguration, type IAbyssalExceptionHandler, type IAbyssalMiddleware, type IActionParamProps, type IInjectionProps, Inject, Injectable, Param, Patch, Post, Put, Query, Request, type TBaseActionParam, type THttpMethod, combine, deleteInjectionMetadata, deleteMetadata, getActionParamMetadata, getControllerActionMetadata, getControllerMetadata, getExceptionCatchClassMetadata, getFromIoCContainer, getInjectParamMetadata, getInjectableIdentity, getInjectionMetadata, getMetadata, httpStatusCodes, isExistingInIoCContainer, loadControllers, mapControllers, mapInjections, pushToIoCContainer, setActionParamMetadata, setControllerActionMetadata, setControllerMetadata, setExceptionCatchClassMetadata, setInjectParamMetadata, setInjectionMetadata, setMetadata };
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
// src/constants/httpStatusCodes.ts
var httpStatusCodes = {
continue: 100,
switchingProtocols: 101,
processing: 102,
earlyHints: 103,
ok: 200,
created: 201,
accepted: 202,
nonAuthoritativeInformation: 203,
noContent: 204,
resetContent: 205,
partialContent: 206,
multiStatus: 207,
alreadyReported: 208,
imUsed: 226,
multipleChoices: 300,
movedPermanently: 301,
found: 302,
seeOther: 303,
notModified: 304,
useProxy: 305,
unused: 306,
temporaryRedirect: 307,
permanentRedirect: 308,
badRequest: 400,
unauthorized: 401,
paymentRequired: 402,
forbidden: 403,
notFound: 404,
methodNotAllowed: 405,
notAcceptable: 406,
proxyAuthenticationRequired: 407,
requestTimeout: 408,
conflict: 409,
gone: 410,
lengthRequired: 411,
preconditionFailed: 412,
payloadTooLarge: 413,
uriTooLong: 414,
unsupportedMediaType: 415,
rangeNotSatisfiable: 416,
expectationFailed: 417,
imATeapot: 418,
misdirectedRequest: 421,
unprocessableEntity: 422,
locked: 423,
failedDependency: 424,
tooEarly: 425,
upgradeRequired: 426,
preconditionRequired: 428,
tooManyRequests: 429,
requestHeaderFieldsTooLarge: 431,
unavailableForLegalReasons: 451,
internalServerError: 500,
notImplemented: 501,
badGateway: 502,
serviceUnavailable: 503,
gatewayTimeout: 504,
httpVersionNotSupported: 505,
variantAlsoNegotiates: 506,
insufficientStorage: 507,
loopDetected: 508,
notExtended: 510,
networkAuthenticationRequired: 511
};
// src/core/AbyssalApplication.ts

@@ -84,2 +151,3 @@ import { config } from "dotenv";

var INJECTABLE_IDENTITY = Symbol.for("__injectableIdentity__");
var EXCEPTION_HANDLER_CATCH_CLASS = Symbol.for("__exceptionHandlerCatchClass__");

@@ -154,2 +222,19 @@ // src/utils/metadataUtils/controller.ts

// src/utils/metadataUtils/exception.ts
function setExceptionCatchClassMetadata({ exceptionClass, exceptionHandler }) {
setMetadata({
value: exceptionClass,
target: exceptionHandler,
key: EXCEPTION_HANDLER_CATCH_CLASS
});
}
__name(setExceptionCatchClassMetadata, "setExceptionCatchClassMetadata");
function getExceptionCatchClassMetadata(exceptionHandler) {
return getMetadata({
target: exceptionHandler,
key: EXCEPTION_HANDLER_CATCH_CLASS
});
}
__name(getExceptionCatchClassMetadata, "getExceptionCatchClassMetadata");
// src/core/IoC.ts

@@ -410,3 +495,5 @@ var IoC = class {

_middlewareInstances = [];
_exceptionHandlers = [];
#middlewares = [];
#exceptionHandlers = [];
#configurationInstances = [];

@@ -430,2 +517,6 @@ _port = {

}
useExceptionHandler(...exceptionHandlers) {
this.#exceptionHandlers.push(...exceptionHandlers);
return this._instance;
}
useConfiguration(...configurations) {

@@ -478,2 +569,16 @@ this._configurations.push(...configurations);

}
_mapExceptionHandlers() {
const allExceptionHandlers = [];
const singleExceptionHandlers = [];
for (const exceptionHandler of this.#exceptionHandlers) {
const catchClass = getExceptionCatchClassMetadata(exceptionHandler);
const exceptionHandlerInstance = new exceptionHandler();
if (catchClass) {
singleExceptionHandlers.push(exceptionHandlerInstance);
} else {
allExceptionHandlers.push(exceptionHandlerInstance);
}
}
this._exceptionHandlers = this._exceptionHandlers.concat(singleExceptionHandlers, allExceptionHandlers);
}
_mapControllers() {

@@ -490,3 +595,3 @@ return mapControllers();

}));
process.exit(1);
process.exit(0);
}, "dispose");

@@ -523,4 +628,6 @@ process.on("SIGINT", dispose);

request;
constructor({ request }) {
response;
constructor({ request, response }) {
this.request = request;
this.response = response;
}

@@ -532,2 +639,30 @@ static create(context) {

// src/core/AbyssalException.ts
var AbyssalException = class extends Error {
static {
__name(this, "AbyssalException");
}
customCode;
statusCode;
constructor(message, options) {
const { cause, customCode, statusCode = 500 } = options || {};
super(message, {
cause
});
this.customCode = customCode;
this.statusCode = statusCode;
this.name = this.constructor.name;
}
toJson() {
return {
name: this.name,
stack: this.stack,
cause: this.cause,
message: this.message,
customCode: this.customCode,
statusCode: this.statusCode
};
}
};
// src/decorators/context.ts

@@ -560,2 +695,13 @@ function Context() {

// src/decorators/exception.ts
function Catch(exceptionClass) {
return (target) => {
setExceptionCatchClassMetadata({
exceptionClass,
exceptionHandler: target
});
};
}
__name(Catch, "Catch");
// src/decorators/httpMethods.ts

@@ -683,3 +829,5 @@ function createControllerActionMetadata({ route, httpMethod }) {

AbyssalContext,
AbyssalException,
Body,
Catch,
Context,

@@ -703,2 +851,3 @@ Controller,

getControllerMetadata,
getExceptionCatchClassMetadata,
getFromIoCContainer,

@@ -709,2 +858,3 @@ getInjectParamMetadata,

getMetadata,
httpStatusCodes,
isExistingInIoCContainer,

@@ -718,2 +868,3 @@ loadControllers,

setControllerMetadata,
setExceptionCatchClassMetadata,
setInjectParamMetadata,

@@ -720,0 +871,0 @@ setInjectionMetadata,

4

package.json
{
"name": "@abyss.ts/core",
"version": "0.0.3",
"version": "0.0.4",
"author": "Alpha",

@@ -28,3 +28,3 @@ "repository": {

"@types/glob": "^8.1.0",
"@types/node": "^20.14.10",
"@types/node": "^20.14.11",
"@abyss.ts/internal-vitest": "^0.0.1"

@@ -31,0 +31,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc