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

@foal/core

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@foal/core - npm Package Compare versions

Comparing version 0.4.0-alpha.2 to 0.4.0-alpha.3

6

dist/index.d.ts

@@ -0,1 +1,7 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
export * from './src';

2

dist/index.js
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,42 +1,62 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { ObjectType } from './interfaces';
export declare abstract class HttpError extends Error {
details: ObjectType | undefined;
abstract statusCode: number;
constructor();
abstract statusMessage: string;
constructor(details?: ObjectType | undefined);
}
export declare abstract class ClientError extends HttpError {
constructor();
constructor(details?: ObjectType);
}
export declare class BadRequestError extends ClientError {
statusCode: number;
constructor();
statusMessage: string;
constructor(details?: ObjectType);
}
export declare class UnauthorizedError extends ClientError {
statusCode: number;
constructor();
statusMessage: string;
headers: {
'WWW-Authenticate': string;
};
constructor(details?: ObjectType);
}
export declare class ForbiddenError extends ClientError {
statusCode: number;
constructor();
statusMessage: string;
constructor(details?: ObjectType);
}
export declare class NotFoundError extends ClientError {
statusCode: number;
constructor();
statusMessage: string;
constructor(details?: ObjectType);
}
export declare class MethodNotAllowedError extends ClientError {
statusCode: number;
constructor();
statusMessage: string;
constructor(details?: ObjectType);
}
export declare class ConflictError extends ClientError {
statusCode: number;
constructor();
statusMessage: string;
constructor(details?: ObjectType);
}
export declare abstract class ServerError extends HttpError {
constructor();
constructor(details?: ObjectType);
}
export declare class InternalServerError extends ServerError {
statusCode: number;
constructor();
statusMessage: string;
constructor(details?: ObjectType);
}
export declare class NotImplementedError extends ServerError {
statusCode: number;
constructor();
statusMessage: string;
constructor(details?: ObjectType);
}
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -8,2 +8,3 @@ */

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// Object.setPrototypeOf(this, MyErrorClass.prototype) must be added to each

@@ -13,6 +14,6 @@ // constructor.

// Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.defineProperty(exports, "__esModule", { value: true });
class HttpError extends Error {
constructor() {
constructor(details) {
super();
this.details = details;
Object.setPrototypeOf(this, HttpError.prototype);

@@ -24,4 +25,4 @@ }

class ClientError extends HttpError {
constructor() {
super();
constructor(details) {
super(details);
Object.setPrototypeOf(this, ClientError.prototype);

@@ -32,5 +33,6 @@ }

class BadRequestError extends ClientError {
constructor() {
super();
constructor(details) {
super(details);
this.statusCode = 400;
this.statusMessage = 'BAD REQUEST';
Object.setPrototypeOf(this, BadRequestError.prototype);

@@ -41,5 +43,9 @@ }

class UnauthorizedError extends ClientError {
constructor() {
super();
constructor(details) {
super(details);
this.statusCode = 401;
this.statusMessage = 'UNAUTHORIZED';
this.headers = {
'WWW-Authenticate': ''
};
Object.setPrototypeOf(this, UnauthorizedError.prototype);

@@ -50,5 +56,6 @@ }

class ForbiddenError extends ClientError {
constructor() {
super();
constructor(details) {
super(details);
this.statusCode = 403;
this.statusMessage = 'FORBIDDEN';
Object.setPrototypeOf(this, ForbiddenError.prototype);

@@ -59,5 +66,6 @@ }

class NotFoundError extends ClientError {
constructor() {
super();
constructor(details) {
super(details);
this.statusCode = 404;
this.statusMessage = 'NOT FOUND';
Object.setPrototypeOf(this, NotFoundError.prototype);

@@ -68,5 +76,6 @@ }

class MethodNotAllowedError extends ClientError {
constructor() {
super();
constructor(details) {
super(details);
this.statusCode = 405;
this.statusMessage = 'METHOD NOT ALLOWED';
Object.setPrototypeOf(this, MethodNotAllowedError.prototype);

@@ -77,5 +86,6 @@ }

class ConflictError extends ClientError {
constructor() {
super();
constructor(details) {
super(details);
this.statusCode = 409;
this.statusMessage = 'CONFLICT';
Object.setPrototypeOf(this, ConflictError.prototype);

@@ -87,4 +97,4 @@ }

class ServerError extends HttpError {
constructor() {
super();
constructor(details) {
super(details);
Object.setPrototypeOf(this, ServerError.prototype);

@@ -95,5 +105,6 @@ }

class InternalServerError extends ServerError {
constructor() {
super();
constructor(details) {
super(details);
this.statusCode = 500;
this.statusMessage = 'INTERNAL SERVER ERROR';
Object.setPrototypeOf(this, InternalServerError.prototype);

@@ -104,5 +115,6 @@ }

class NotImplementedError extends ServerError {
constructor() {
super();
constructor(details) {
super(details);
this.statusCode = 501;
this.statusMessage = 'NOT IMPLEMENTED';
Object.setPrototypeOf(this, NotImplementedError.prototype);

@@ -109,0 +121,0 @@ }

@@ -0,7 +1,12 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import 'reflect-metadata';
import { LowLevelRoute, Route, Type } from '../interfaces';
import { ServiceManager } from '../service-manager';
import { Controller, Route, Type } from '../interfaces';
export declare abstract class ControllerFactory<T> {
constructor();
attachService(path: string, ServiceClass: Type<T>): (services: ServiceManager) => LowLevelRoute[];
attachService(path: string, ServiceClass: Type<T>): Controller;
protected abstract getRoutes(service: T): Route[];

@@ -8,0 +13,0 @@ private getPreMiddlewares(ServiceClass, methodName);

/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -18,3 +18,3 @@ */

...this.getPreMiddlewares(ServiceClass, route.serviceMethodName),
async (ctx) => ctx.result = await route.serviceMethodBinder(ctx),
async (ctx) => ctx.result = await route.middleware(ctx),
...this.getPostMiddlewares(ServiceClass, route.serviceMethodName)

@@ -33,2 +33,5 @@ ].map(middleware => ((ctx) => middleware(ctx, services)));

const classPreMiddlewares = Reflect.getMetadata('pre-middlewares', ServiceClass) || [];
if (methodName === null) {
return classPreMiddlewares;
}
const methodPreMiddlewares = Reflect.getMetadata('pre-middlewares', ServiceClass.prototype, methodName) || [];

@@ -39,2 +42,5 @@ return classPreMiddlewares.concat(methodPreMiddlewares);

const classPostMiddlewares = Reflect.getMetadata('post-middlewares', ServiceClass) || [];
if (methodName === null) {
return classPostMiddlewares;
}
const methodPostMiddlewares = Reflect.getMetadata('post-middlewares', ServiceClass.prototype, methodName) || [];

@@ -41,0 +47,0 @@ return methodPostMiddlewares.concat(classPostMiddlewares);

@@ -0,3 +1,9 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
export { postHook } from './post-hook';
export { preHook } from './pre-hook';
export { ControllerFactory } from './controller-factory';
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -1,2 +0,8 @@

import { Hook, PostMiddleware } from '../interfaces';
export declare function postHook(postMiddleware: PostMiddleware): Hook;
/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { Hook, Middleware } from '../interfaces';
export declare function postHook(postMiddleware: Middleware): Hook;
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -1,2 +0,8 @@

import { Hook, PreMiddleware } from '../interfaces';
export declare function preHook(preMiddleware: PreMiddleware): Hook;
/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { Hook, Middleware } from '../interfaces';
export declare function preHook(preMiddleware: Middleware): Hook;
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,9 +1,15 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import 'reflect-metadata';
import { FoalModule, LowLevelRoute } from './interfaces';
import { FoalModule, ReducedRoute } from './interfaces';
import { ServiceManager } from './service-manager';
export declare class Foal {
readonly services: ServiceManager;
readonly lowLevelRoutes: LowLevelRoute[];
readonly routes: ReducedRoute[];
constructor(foalModule: FoalModule, parentModule?: Foal);
private getMiddlewares(hooks);
}
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -13,3 +13,3 @@ */

constructor(foalModule, parentModule) {
this.lowLevelRoutes = [];
this.routes = [];
const controllers = foalModule.controllers || [];

@@ -29,6 +29,6 @@ const modules = foalModule.modules || [];

for (const controller of controllers) {
for (const lowLevelRoute of controller(this.services)) {
this.lowLevelRoutes.push(Object.assign({}, lowLevelRoute, { middlewares: [
for (const route of controller(this.services)) {
this.routes.push(Object.assign({}, route, { middlewares: [
...modulePreMiddlewares.map(e => (ctx => e(ctx, this.services))),
...lowLevelRoute.middlewares,
...route.middlewares,
...modulePostMiddlewares.map(e => (ctx => e(ctx, this.services))),

@@ -40,9 +40,8 @@ ] }));

const importedModule = new Foal(mod.module, this);
const path = mod.path || '';
for (const lowLevelRoute of importedModule.lowLevelRoutes) {
this.lowLevelRoutes.push(Object.assign({}, lowLevelRoute, { middlewares: [
for (const route of importedModule.routes) {
this.routes.push(Object.assign({}, route, { middlewares: [
...modulePreMiddlewares.map(e => (ctx => e(ctx, this.services))),
...lowLevelRoute.middlewares,
...route.middlewares,
...modulePostMiddlewares.map(e => (ctx => e(ctx, this.services))),
], paths: [path, ...lowLevelRoute.paths] }));
], paths: mod.path ? [mod.path, ...route.paths] : route.paths }));
}

@@ -49,0 +48,0 @@ }

@@ -0,1 +1,7 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
export * from './factories';

@@ -2,0 +8,0 @@ export * from './interfaces';

/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,1 +1,7 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { ObjectType } from './utils';

@@ -2,0 +8,0 @@ export interface RSUContext<Result, Session, User> {

/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,14 +1,19 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { ServiceManager } from '../service-manager';
import { Context } from './contexts';
import { Middleware } from './middlewares';
import { ReducedMiddleware } from './middlewares';
export declare type HttpMethod = 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
export interface LowLevelRoute {
export interface ReducedRoute {
httpMethod: HttpMethod;
paths: string[];
middlewares: Middleware[];
middlewares: ReducedMiddleware[];
successStatus: number;
}
export interface Route {
serviceMethodBinder: (context: Context) => Promise<any> | any;
serviceMethodName: string;
middleware: ReducedMiddleware;
serviceMethodName: string | null;
httpMethod: HttpMethod;

@@ -18,2 +23,2 @@ path: string;

}
export declare type Controller = (services: ServiceManager) => LowLevelRoute[];
export declare type Controller = (services: ServiceManager) => ReducedRoute[];
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,1 +1,7 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
export * from './contexts';

@@ -2,0 +8,0 @@ export * from './controller-and-routes';

/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,5 +1,10 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { ServiceManager } from '../service-manager';
import { Context } from './contexts';
export declare type Middleware = (ctx: Context) => Promise<any> | any;
export declare type PreMiddleware = (ctx: Context, services: ServiceManager) => Promise<any> | any;
export declare type PostMiddleware = (ctx: Context, services: ServiceManager) => Promise<any> | any;
export declare type ReducedMiddleware = (ctx: Context) => Promise<any> | any;
export declare type Middleware = (ctx: Context, services: ServiceManager) => Promise<any> | any;
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,1 +1,7 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { Controller } from './controller-and-routes';

@@ -2,0 +8,0 @@ import { Hook, Type } from './utils';

/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,1 +1,7 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
export interface Type<T> {

@@ -2,0 +8,0 @@ new (...args: any[]): T;

/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,1 +1,7 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import 'reflect-metadata';

@@ -2,0 +8,0 @@ import { Type } from './interfaces';

/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,2 +1,8 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { Context } from '../interfaces';
export declare function createEmptyContext(): Context;
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,3 +1,9 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import 'reflect-metadata';
import { Hook, PostMiddleware } from '../interfaces';
export declare function getPostMiddleware(postHook: Hook): PostMiddleware;
import { Hook, Middleware } from '../interfaces';
export declare function getPostMiddleware(postHook: Hook): Middleware;
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,3 +1,9 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import 'reflect-metadata';
import { Hook, PreMiddleware } from '../interfaces';
export declare function getPreMiddleware(preHook: Hook): PreMiddleware;
import { Hook, Middleware } from '../interfaces';
export declare function getPreMiddleware(preHook: Hook): Middleware;
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,3 +1,9 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
export * from './get-pre-middleware';
export * from './get-post-middleware';
export * from './create-empty-context';
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,2 +1,8 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import { Hook } from '../interfaces';
export declare function combineHooks(hooks: Hook[]): Hook;
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,2 +1,8 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
export * from './combine-hooks';
export * from './metadatas';
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

@@ -0,3 +1,9 @@

/**
* FoalTS
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.
*/
import 'reflect-metadata';
export declare function getMetadata(metadataKey: any, target: any, propertyKey: string | undefined): any;
export declare function defineMetadata(metadataKey: any, metadataValue: any, target: any, propertyKey: string | undefined): any;
/**
* FoalTS
* Copyright(c) 2017-2017 Loïc Poullain <loic.poullain@centraliens.net>
* Copyright(c) 2017-2018 Loïc Poullain <loic.poullain@centraliens.net>
* Released under the MIT License.

@@ -5,0 +5,0 @@ */

{
"name": "@foal/core",
"version": "0.4.0-alpha.2",
"version": "0.4.0-alpha.3",
"description": "A Node.js framework for building robust web apps.",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

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