Socket
Socket
Sign inDemoInstall

@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.6.0-beta.4 to 0.6.0-beta.5

lib/common/hooks/validate-headers.hook.d.ts

1

lib/auth/authentication/authenticate.hook.js

@@ -17,2 +17,1 @@ "use strict";

exports.Authenticate = Authenticate;
//# sourceMappingURL=authenticate.hook.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=authenticator.interface.js.map

@@ -9,2 +9,1 @@ "use strict";

__export(require("./login.controller"));
//# sourceMappingURL=index.js.map

@@ -10,3 +10,2 @@ import { Class, Context, HttpResponseBadRequest, HttpResponseNoContent, HttpResponseNotFound, HttpResponseRedirect, HttpResponseUnauthorized, ServiceManager } from '../../core';

export declare abstract class LoginController {
private services;
redirect: {

@@ -18,5 +17,5 @@ logout?: string;

abstract strategies: Strategy[];
constructor(services: ServiceManager);
services: ServiceManager;
logout(ctx: Context): HttpResponseNoContent | HttpResponseRedirect;
login(ctx: Context): Promise<HttpResponseNoContent | HttpResponseRedirect | HttpResponseBadRequest | HttpResponseUnauthorized | HttpResponseNotFound>;
}

@@ -21,6 +21,3 @@ "use strict";

exports.strategy = strategy;
let LoginController = class LoginController {
constructor(services) {
this.services = services;
}
class LoginController {
logout(ctx) {

@@ -53,4 +50,8 @@ delete ctx.request.session.authentication;

}
};
}
__decorate([
core_1.dependency,
__metadata("design:type", core_1.ServiceManager)
], LoginController.prototype, "services", void 0);
__decorate([
core_1.Get('/logout'),

@@ -67,7 +68,2 @@ __metadata("design:type", Function),

], LoginController.prototype, "login", null);
LoginController = __decorate([
core_1.Controller(),
__metadata("design:paramtypes", [core_1.ServiceManager])
], LoginController);
exports.LoginController = LoginController;
//# sourceMappingURL=login.controller.js.map

@@ -44,2 +44,1 @@ "use strict";

exports.EmailAuthenticator = EmailAuthenticator;
//# sourceMappingURL=email-authenticator.service.js.map

@@ -12,2 +12,1 @@ "use strict";

};
//# sourceMappingURL=email.schema.js.map

@@ -9,2 +9,1 @@ "use strict";

exports.parsePassword = parse_password_parser_1.parsePassword;
//# sourceMappingURL=index.js.map

@@ -14,2 +14,1 @@ "use strict";

exports.parsePassword = parsePassword;
//# sourceMappingURL=parse-password.parser.js.map

@@ -7,2 +7,1 @@ "use strict";

__export(require("./email"));
//# sourceMappingURL=index.js.map

@@ -7,2 +7,1 @@ "use strict";

exports.LoginRequired = login_required_hook_1.LoginRequired;
//# sourceMappingURL=index.js.map

@@ -15,2 +15,1 @@ "use strict";

exports.LoginRequired = LoginRequired;
//# sourceMappingURL=login-required.hook.js.map

@@ -18,2 +18,1 @@ "use strict";

exports.PermissionRequired = PermissionRequired;
//# sourceMappingURL=permission-required.hook.js.map

@@ -35,5 +35,3 @@ "use strict";

__decorate([
typeorm_1.PrimaryGeneratedColumn()
// @ts-ignore : Property 'id' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.PrimaryGeneratedColumn(),
__metadata("design:type", Number)

@@ -43,5 +41,3 @@ ], AbstractUser.prototype, "id", void 0);

typeorm_1.ManyToMany(type => group_entity_1.Group),
typeorm_1.JoinTable()
// @ts-ignore : Property 'groups' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.JoinTable(),
__metadata("design:type", Array)

@@ -51,8 +47,5 @@ ], AbstractUser.prototype, "groups", void 0);

typeorm_1.ManyToMany(type => permission_entity_1.Permission),
typeorm_1.JoinTable()
// @ts-ignore : Property 'userPermissions' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.JoinTable(),
__metadata("design:type", Array)
], AbstractUser.prototype, "userPermissions", void 0);
exports.AbstractUser = AbstractUser;
//# sourceMappingURL=abstract-user.entity.js.map

@@ -19,17 +19,11 @@ "use strict";

__decorate([
typeorm_1.PrimaryGeneratedColumn()
// @ts-ignore : Property 'id' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.PrimaryGeneratedColumn(),
__metadata("design:type", Number)
], Group.prototype, "id", void 0);
__decorate([
typeorm_1.Column({ length: 80 })
// @ts-ignore : Property 'name' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.Column({ length: 80 }),
__metadata("design:type", String)
], Group.prototype, "name", void 0);
__decorate([
typeorm_1.Column({ length: 100, unique: true })
// @ts-ignore : Property 'codeName' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.Column({ length: 100, unique: true }),
__metadata("design:type", String)

@@ -39,5 +33,3 @@ ], Group.prototype, "codeName", void 0);

typeorm_1.ManyToMany(type => permission_entity_1.Permission),
typeorm_1.JoinTable()
// @ts-ignore : Property 'permissions' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.JoinTable(),
__metadata("design:type", Array)

@@ -49,2 +41,1 @@ ], Group.prototype, "permissions", void 0);

exports.Group = Group;
//# sourceMappingURL=group.entity.js.map

@@ -9,2 +9,1 @@ "use strict";

exports.Permission = permission_entity_1.Permission;
//# sourceMappingURL=index.js.map

@@ -16,17 +16,11 @@ "use strict";

__decorate([
typeorm_1.PrimaryGeneratedColumn()
// @ts-ignore : Property 'id' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.PrimaryGeneratedColumn(),
__metadata("design:type", Number)
], Permission.prototype, "id", void 0);
__decorate([
typeorm_1.Column()
// @ts-ignore : Property 'name' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.Column(),
__metadata("design:type", String)
], Permission.prototype, "name", void 0);
__decorate([
typeorm_1.Column({ length: 100, unique: true })
// @ts-ignore : Property 'codeName' has no initializer and is not definitely assigned in theconstructor.
,
typeorm_1.Column({ length: 100, unique: true }),
__metadata("design:type", String)

@@ -38,2 +32,1 @@ ], Permission.prototype, "codeName", void 0);

exports.Permission = Permission;
//# sourceMappingURL=permission.entity.js.map

@@ -9,2 +9,1 @@ "use strict";

__export(require("./entities"));
//# sourceMappingURL=index.js.map

@@ -5,2 +5,1 @@ "use strict";

exports.RestController = rest_controller_1.RestController;
//# sourceMappingURL=index.js.map

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

import { Class, Context, HttpResponseBadRequest, HttpResponseCreated, HttpResponseForbidden, HttpResponseMethodNotAllowed, HttpResponseNotFound, HttpResponseNotImplemented, HttpResponseOK, ServiceManager } from '../../core';
import { Context, HttpResponseBadRequest, HttpResponseCreated, HttpResponseForbidden, HttpResponseMethodNotAllowed, HttpResponseNotFound, HttpResponseNotImplemented, HttpResponseOK } from '../../core';
import { CollectionParams, IResourceCollection } from '../services';
export declare abstract class RestController {
private services;
abstract collectionClass: Class<Partial<IResourceCollection>>;
constructor(services: ServiceManager);
abstract collection: Partial<IResourceCollection>;
extendParams(ctx: Context, params: CollectionParams): CollectionParams;

@@ -8,0 +6,0 @@ delete(): HttpResponseMethodNotAllowed;

@@ -14,6 +14,3 @@ "use strict";

const errors_1 = require("../errors");
let RestController = class RestController {
constructor(services) {
this.services = services;
}
class RestController {
extendParams(ctx, params) {

@@ -26,8 +23,7 @@ return params;

async deleteById(ctx) {
const collection = this.services.get(this.collectionClass);
if (!collection.deleteById) {
if (!this.collection.deleteById) {
return new core_1.HttpResponseNotImplemented();
}
try {
return new core_1.HttpResponseOK(await collection.deleteById(ctx.user, ctx.request.params.id, {}));
return new core_1.HttpResponseOK(await this.collection.deleteById(ctx.user, ctx.request.params.id, {}));
}

@@ -48,6 +44,3 @@ catch (error) {

async get(ctx) {
// schema and id
// hooks
const collection = this.services.get(this.collectionClass);
if (!collection.find) {
if (!this.collection.find) {
return new core_1.HttpResponseNotImplemented();

@@ -57,3 +50,3 @@ }

try {
return new core_1.HttpResponseOK(await collection.find(ctx.user, params));
return new core_1.HttpResponseOK(await this.collection.find(ctx.user, params));
}

@@ -71,8 +64,7 @@ catch (error) {

async getById(ctx) {
const collection = this.services.get(this.collectionClass);
if (!collection.findById) {
if (!this.collection.findById) {
return new core_1.HttpResponseNotImplemented();
}
try {
return new core_1.HttpResponseOK(await collection.findById(ctx.user, ctx.request.params.id, {}));
return new core_1.HttpResponseOK(await this.collection.findById(ctx.user, ctx.request.params.id, {}));
}

@@ -96,8 +88,7 @@ catch (error) {

async patchById(ctx) {
const collection = this.services.get(this.collectionClass);
if (!collection.modifyById) {
if (!this.collection.modifyById) {
return new core_1.HttpResponseNotImplemented();
}
try {
return new core_1.HttpResponseOK(await collection.modifyById(ctx.user, ctx.request.params.id, ctx.request.body, {}));
return new core_1.HttpResponseOK(await this.collection.modifyById(ctx.user, ctx.request.params.id, ctx.request.body, {}));
}

@@ -118,8 +109,7 @@ catch (error) {

async post(ctx) {
const collection = this.services.get(this.collectionClass);
if (!collection.create) {
if (!this.collection.create) {
return new core_1.HttpResponseNotImplemented();
}
try {
return new core_1.HttpResponseCreated(await collection.create(ctx.user, ctx.request.body, {}));
return new core_1.HttpResponseCreated(await this.collection.create(ctx.user, ctx.request.body, {}));
}

@@ -143,8 +133,7 @@ catch (error) {

async putById(ctx) {
const collection = this.services.get(this.collectionClass);
if (!collection.updateById) {
if (!this.collection.updateById) {
return new core_1.HttpResponseNotImplemented();
}
try {
return new core_1.HttpResponseOK(await collection.updateById(ctx.user, ctx.request.params.id, ctx.request.body, {}));
return new core_1.HttpResponseOK(await this.collection.updateById(ctx.user, ctx.request.params.id, ctx.request.body, {}));
}

@@ -164,3 +153,3 @@ catch (error) {

}
};
}
__decorate([

@@ -226,7 +215,2 @@ core_1.Delete('/'),

], RestController.prototype, "putById", null);
RestController = __decorate([
core_1.Controller(),
__metadata("design:paramtypes", [core_1.ServiceManager])
], RestController);
exports.RestController = RestController;
//# sourceMappingURL=rest.controller.js.map

@@ -12,2 +12,1 @@ "use strict";

exports.isValidationError = validation_error_1.isValidationError;
//# sourceMappingURL=index.js.map

@@ -16,2 +16,1 @@ "use strict";

exports.isObjectDoesNotExist = isObjectDoesNotExist;
//# sourceMappingURL=object-does-not-exist.js.map

@@ -16,2 +16,1 @@ "use strict";

exports.isPermissionDenied = isPermissionDenied;
//# sourceMappingURL=permission-denied.js.map

@@ -16,2 +16,1 @@ "use strict";

exports.isValidationError = isValidationError;
//# sourceMappingURL=validation-error.js.map
export { Log } from './log.hook';
export { ValidateBody } from './validate-body.hook';
export { ValidateHeaders } from './validate-headers.hook';
export { ValidateParams } from './validate-params.hook';
export { ValidateQuery } from './validate-query.hook';

@@ -7,4 +7,7 @@ "use strict";

exports.ValidateBody = validate_body_hook_1.ValidateBody;
var validate_headers_hook_1 = require("./validate-headers.hook");
exports.ValidateHeaders = validate_headers_hook_1.ValidateHeaders;
var validate_params_hook_1 = require("./validate-params.hook");
exports.ValidateParams = validate_params_hook_1.ValidateParams;
var validate_query_hook_1 = require("./validate-query.hook");
exports.ValidateQuery = validate_query_hook_1.ValidateQuery;
//# sourceMappingURL=index.js.map

@@ -8,2 +8,1 @@ "use strict";

exports.Log = Log;
//# sourceMappingURL=log.hook.js.map

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

import * as Ajv from 'ajv';
import { HookDecorator } from '../../core';
export declare function ValidateBody(schema: object, ajv?: Ajv.Ajv): HookDecorator;
/**
* Hook to validate the body of the request.
*
* @param schema Schema used to validate the body request.
*/
export declare function ValidateBody(schema: object): HookDecorator;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Ajv = require("ajv");
const core_1 = require("../../core");
const defaultInstance = new Ajv();
function ValidateBody(schema, ajv = defaultInstance) {
const get_ajv_instance_1 = require("../utils/get-ajv-instance");
/**
* Hook to validate the body of the request.
*
* @param schema Schema used to validate the body request.
*/
function ValidateBody(schema) {
const ajv = get_ajv_instance_1.getAjvInstance();
const isValid = ajv.compile(schema);

@@ -15,2 +20,1 @@ return core_1.Hook(ctx => {

exports.ValidateBody = ValidateBody;
//# sourceMappingURL=validate-body.hook.js.map

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

import * as Ajv from 'ajv';
import { HookDecorator } from '../../core';
export declare function ValidateQuery(schema: object, ajv?: Ajv.Ajv): HookDecorator;
/**
* Hook to validate the query of the request.
*
* @param schema Schema used to validate the query request.
*/
export declare function ValidateQuery(schema: object): HookDecorator;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Ajv = require("ajv");
const core_1 = require("../../core");
const defaultInstance = new Ajv();
function ValidateQuery(schema, ajv = defaultInstance) {
const get_ajv_instance_1 = require("../utils/get-ajv-instance");
/**
* Hook to validate the query of the request.
*
* @param schema Schema used to validate the query request.
*/
function ValidateQuery(schema) {
const ajv = get_ajv_instance_1.getAjvInstance();
const isValid = ajv.compile(schema);

@@ -15,2 +20,1 @@ return core_1.Hook(ctx => {

exports.ValidateQuery = ValidateQuery;
//# sourceMappingURL=validate-query.hook.js.map

@@ -11,2 +11,1 @@ "use strict";

__export(require("./utils"));
//# sourceMappingURL=index.js.map

@@ -211,2 +211,1 @@ "use strict";

exports.EntityResourceCollection = EntityResourceCollection;
//# sourceMappingURL=entity-resource-collection.service.js.map

@@ -6,2 +6,1 @@ "use strict";

exports.middleware = entity_resource_collection_service_1.middleware;
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=resource-collection.interface.js.map

@@ -10,2 +10,1 @@ "use strict";

exports.controller = controller;
//# sourceMappingURL=controller.util.js.map

@@ -12,2 +12,1 @@ "use strict";

exports.escapeProp = escapeProp;
//# sourceMappingURL=escape-prop.js.map

@@ -15,2 +15,1 @@ "use strict";

exports.escape = escape;
//# sourceMappingURL=escape.js.map
export { controller } from './controller.util';
export { escapeProp } from './escape-prop';
export { escape } from './escape';
export { getCommandLineArguments } from './get-command-line-arguments.util';
export { render } from './render.util';
export { subModule } from './sub-module.util';
export { validate } from './validate.util';

@@ -9,10 +9,5 @@ "use strict";

exports.escape = escape_1.escape;
var get_command_line_arguments_util_1 = require("./get-command-line-arguments.util");
exports.getCommandLineArguments = get_command_line_arguments_util_1.getCommandLineArguments;
var render_util_1 = require("./render.util");
exports.render = render_util_1.render;
var sub_module_util_1 = require("./sub-module.util");
exports.subModule = sub_module_util_1.subModule;
var validate_util_1 = require("./validate.util");
exports.validate = validate_util_1.validate;
//# sourceMappingURL=index.js.map

@@ -18,2 +18,1 @@ "use strict";

exports.render = render;
//# sourceMappingURL=render.util.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// 3p
const Ajv = require("ajv");
// FoalTS
const errors_1 = require("../errors");
const ajv = new Ajv();
const get_ajv_instance_1 = require("./get-ajv-instance");
function validate(schema, data) {
const ajv = get_ajv_instance_1.getAjvInstance();
if (!ajv.validate(schema, data)) {

@@ -14,2 +13,1 @@ throw new errors_1.ValidationError(ajv.errors);

exports.validate = validate;
//# sourceMappingURL=validate.util.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=class.interface.js.map

@@ -64,2 +64,1 @@ "use strict";

exports.Config = Config;
//# sourceMappingURL=config.js.map
import 'reflect-metadata';
import { Class } from './class.interface';
import { ServiceManager } from './service-manager';
export declare function Controller(path?: string): {
(target: Function): void;
(target: Object, propertyKey: string | symbol): void;
};
export declare function createController<T>(controllerClass: Class<T>, services?: ServiceManager): T;
export declare function createController<T>(controllerClass: Class<T>, dependencies?: object | ServiceManager): T;

@@ -5,16 +5,21 @@ "use strict";

require("reflect-metadata");
const utils_1 = require("./routes/utils");
const service_manager_1 = require("./service-manager");
function Controller(path) {
return Reflect.metadata('path', path);
}
exports.Controller = Controller;
function createController(controllerClass, services) {
const controllerDependencies = utils_1.getMetadata('design:paramtypes', controllerClass) || [];
if (!services) {
services = new service_manager_1.ServiceManager();
function createController(controllerClass, dependencies) {
const controllerDependencies = Reflect.getMetadata('dependencies', controllerClass.prototype) || [];
let serviceManager = new service_manager_1.ServiceManager();
const service = new controllerClass();
if (dependencies instanceof service_manager_1.ServiceManager) {
serviceManager = dependencies;
}
return new controllerClass(...controllerDependencies.map(serviceClass => services.get(serviceClass)));
else if (typeof dependencies === 'object') {
controllerDependencies.forEach(dep => {
const serviceMock = dependencies[dep.propertyKey];
if (serviceMock) {
serviceManager.set(dep.serviceClass, serviceMock);
}
});
}
controllerDependencies.forEach(dep => service[dep.propertyKey] = serviceManager.get(dep.serviceClass));
return service;
}
exports.createController = createController;
//# sourceMappingURL=controllers.js.map

@@ -29,2 +29,1 @@ "use strict";

exports.getHookFunction = getHookFunction;
//# sourceMappingURL=hooks.js.map

@@ -11,2 +11,1 @@ "use strict";

exports.Context = Context;
//# sourceMappingURL=contexts.js.map

@@ -40,2 +40,1 @@ "use strict";

exports.Delete = Delete;
//# sourceMappingURL=http-methods.js.map

@@ -240,2 +240,1 @@ "use strict";

exports.isHttpResponseNotImplemented = isHttpResponseNotImplemented;
//# sourceMappingURL=http-responses.js.map

@@ -9,2 +9,1 @@ "use strict";

__export(require("./http-responses"));
//# sourceMappingURL=index.js.map
export * from './class.interface';
export { createController, Controller } from './controllers';
export { createController } from './controllers';
export * from './http';

@@ -7,3 +7,2 @@ export * from './hooks';

export { Config } from './config';
export * from './modules';
export { Service, ServiceManager } from './service-manager';
export { createService, dependency, ServiceManager } from './service-manager';

@@ -8,3 +8,2 @@ "use strict";

exports.createController = controllers_1.createController;
exports.Controller = controllers_1.Controller;
__export(require("./http"));

@@ -15,6 +14,5 @@ __export(require("./hooks"));

exports.Config = config_1.Config;
__export(require("./modules"));
var service_manager_1 = require("./service-manager");
exports.Service = service_manager_1.Service;
exports.createService = service_manager_1.createService;
exports.dependency = service_manager_1.dependency;
exports.ServiceManager = service_manager_1.ServiceManager;
//# sourceMappingURL=index.js.map
export * from './route.interface';
export { makeModuleRoutes } from './make-module-routes';
export { makeControllerRoutes } from './make-controller-routes';
export { getPath, getHttpMethod } from './utils';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var make_module_routes_1 = require("./make-module-routes");
exports.makeModuleRoutes = make_module_routes_1.makeModuleRoutes;
var make_controller_routes_1 = require("./make-controller-routes");
exports.makeControllerRoutes = make_controller_routes_1.makeControllerRoutes;
var utils_1 = require("./utils");
exports.getPath = utils_1.getPath;
exports.getHttpMethod = utils_1.getHttpMethod;
//# sourceMappingURL=index.js.map

@@ -15,2 +15,4 @@ "use strict";

const controllerPath = utils_1.getMetadata('path', controllerClass);
const leftPath = utils_1.join(parentPath, controllerPath);
const leftHooks = parentHooks.concat(controllerHooks);
const controller = controllers_1.createController(controllerClass, services);

@@ -25,10 +27,12 @@ getMethods(controllerClass.prototype).forEach(propertyKey => {

const methodHooks = utils_1.getMetadata('hooks', controllerClass, propertyKey) || [];
const path = utils_1.join(parentPath, controllerPath, methodPath);
const hooks = parentHooks.concat(controllerHooks).concat(methodHooks);
const path = utils_1.join(leftPath, methodPath);
const hooks = [...leftHooks, ...methodHooks];
routes.push({ controller, hooks, httpMethod, path, propertyKey });
}
});
for (const controllerClass of controller.subControllers || []) {
routes.push(...makeControllerRoutes(leftPath, leftHooks, controllerClass, services));
}
return routes;
}
exports.makeControllerRoutes = makeControllerRoutes;
//# sourceMappingURL=make-controller-routes.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=route.interface.js.map

@@ -24,2 +24,1 @@ "use strict";

exports.join = join;
//# sourceMappingURL=utils.js.map
import 'reflect-metadata';
import { Class } from './class.interface';
export declare function Service(): (target: any) => void;
export interface Dependency {
propertyKey: string;
serviceClass: Class;
}
/**
* Decorator used to inject a service inside a controller or another service.
*/
export declare function dependency(target: any, propertyKey: string): void;
/**
* Create a new service with its dependencies.
*
* @param serviceClass The service class.
* @param dependencies Either a ServiceManager or an object which key/values are the service classes/instances.
*/
export declare function createService<Service>(serviceClass: Class<Service>, dependencies?: object | ServiceManager): Service;
/**
* Identity Mapper that instantiates and returns service singletons.
*/
export declare class ServiceManager {
readonly map: Map<Class<any>, any>;
set<Service>(serviceClass: Class<Service>, service: any): void;
/**
* Get or create the service singleton.
*
* @param serviceClass
*/
get<Service>(serviceClass: Class<Service>): Service;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
function Service() {
return function decorator(target) { };
/**
* Decorator used to inject a service inside a controller or another service.
*/
function dependency(target, propertyKey) {
const serviceClass = Reflect.getMetadata('design:type', target, propertyKey);
const dependencies = [...(Reflect.getMetadata('dependencies', target) || [])];
dependencies.push({ propertyKey, serviceClass });
Reflect.defineMetadata('dependencies', dependencies, target);
}
exports.Service = Service;
exports.dependency = dependency;
/**
* Create a new service with its dependencies.
*
* @param serviceClass The service class.
* @param dependencies Either a ServiceManager or an object which key/values are the service classes/instances.
*/
function createService(serviceClass, dependencies) {
const serviceDependencies = Reflect.getMetadata('dependencies', serviceClass.prototype) || [];
let serviceManager = new ServiceManager();
const service = new serviceClass();
if (dependencies instanceof ServiceManager) {
serviceManager = dependencies;
}
else if (typeof dependencies === 'object') {
serviceDependencies.forEach(dep => {
const serviceMock = dependencies[dep.propertyKey];
if (serviceMock) {
serviceManager.set(dep.serviceClass, serviceMock);
}
});
}
serviceDependencies.forEach(dep => service[dep.propertyKey] = serviceManager.get(dep.serviceClass));
return service;
}
exports.createService = createService;
/**
* Identity Mapper that instantiates and returns service singletons.
*/
class ServiceManager {

@@ -15,2 +49,7 @@ constructor() {

}
/**
* Get or create the service singleton.
*
* @param serviceClass
*/
get(serviceClass) {

@@ -28,4 +67,3 @@ // The ts-ignores fix TypeScript bugs.

// If the service has not been instantiated yet then do it.
const dependencies = Reflect.getOwnMetadata('design:paramtypes', serviceClass) || [];
const service = new serviceClass(...dependencies.map(Dep => this.get(Dep)));
const service = createService(serviceClass, this);
// Save and return the service.

@@ -37,2 +75,1 @@ this.map.set(serviceClass, service);

exports.ServiceManager = ServiceManager;
//# sourceMappingURL=service-manager.js.map

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

import { Class, IModule } from '../core';
import { Class } from '../core';
export interface CreateAppOptions {
store?(session: any): any;
}
export declare function createApp(rootModuleClass: Class<IModule>, options?: CreateAppOptions): any;
export declare function createApp(rootControllerClass: Class, options?: CreateAppOptions): any;

@@ -13,3 +13,3 @@ "use strict";

const not_found_1 = require("./not-found");
function createApp(rootModuleClass, options = {}) {
function createApp(rootControllerClass, options = {}) {
const app = express();

@@ -46,3 +46,3 @@ app.use(logger('[:date] ":method :url HTTP/:http-version" :status - :response-time ms'));

const services = new core_1.ServiceManager();
const routes = core_1.makeModuleRoutes('', [], rootModuleClass, services);
const routes = core_1.makeControllerRoutes('', [], rootControllerClass, services);
for (const route of routes) {

@@ -72,2 +72,1 @@ switch (route.httpMethod) {

exports.createApp = createApp;
//# sourceMappingURL=create-app.js.map

@@ -38,2 +38,1 @@ "use strict";

exports.createMiddleware = createMiddleware;
//# sourceMappingURL=create-middleware.js.map

@@ -31,2 +31,1 @@ "use strict";

exports.handleErrors = handleErrors;
//# sourceMappingURL=handle-errors.js.map

@@ -5,2 +5,1 @@ "use strict";

exports.createApp = create_app_1.createApp;
//# sourceMappingURL=index.js.map

@@ -11,2 +11,1 @@ "use strict";

exports.notFound = notFound;
//# sourceMappingURL=not-found.js.map

@@ -15,2 +15,1 @@ "use strict";

__export(require("./express"));
//# sourceMappingURL=index.js.map
{
"name": "@foal/core",
"version": "0.6.0-beta.4",
"version": "0.6.0-beta.5",
"description": "High level web framework to create enterprise-grade Node.JS applications.",

@@ -8,3 +8,4 @@ "main": "./lib/index.js",

"scripts": {
"test": "nyc --reporter=html --reporter=text mocha --require ts-node/register --require source-map-support/register \"./src/**/*.spec.ts\"",
"generate:api:docs": "ts-docs-gen --entryFile ./src/index.ts --output ../../docs",
"test": "nyc --reporter=json --reporter=text mocha --require ts-node/register --require source-map-support/register \"./src/**/*.spec.ts\"",
"e2e": "mocha --require ts-node/register \"./e2e/**/*.spec.ts\"",

@@ -91,3 +92,3 @@ "dev:e2e": "mocha --require ts-node/register --watch --watch-extensions ts \"./e2e/**/*.spec.ts\"",

"devDependencies": {
"@foal/ejs": "^0.6.0-beta.4",
"@foal/ejs": "^0.6.0-beta.5",
"@types/mocha": "^2.2.43",

@@ -105,2 +106,3 @@ "@types/node": "^10.1.2",

"supertest": "^3.1.0",
"ts-docs-gen": "0.2.0",
"ts-node": "^3.3.0",

@@ -107,0 +109,0 @@ "typeorm": "^0.2.6",

@@ -1,11 +0,36 @@

# FoalTS
<p align="center">
<a href="https://foalts.org" target="blank">
<img src="https://raw.githubusercontent.com/FoalTS/foal/master/docs/logo_title.png" height="160px" alt="Logo" />
</a>
<br>
</p>
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/FoalTS/foal/blob/master/LICENSE)
![node version](https://img.shields.io/badge/node-%3E%3D8-brightgreen.svg)
[![npm version](https://badge.fury.io/js/%40foal%2Fcore.svg)](https://badge.fury.io/js/%40foal%2Fcore)
[![Build Status](https://travis-ci.org/FoalTS/foal.svg?branch=add-travis)](https://travis-ci.org/FoalTS/foal)
[![Known Vulnerabilities](https://snyk.io/test/github/foalts/foal/badge.svg?targetFile=packages%2Fcore%2Fpackage.json)](https://snyk.io/test/github/foalts/foal?targetFile=packages%2Fcore%2Fpackage.json)
<p align="center">
<i>A Web framework to create enterprise-grade Node.JS applications</i>
<br>
<br>
<a href="https://github.com/FoalTS/foal/blob/master/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT">
</a>
<img src="https://img.shields.io/badge/node-%3E%3D8-brightgreen.svg" alt="node version">
<a href="https://badge.fury.io/js/%40foal%2Fcore">
<img src="https://badge.fury.io/js/%40foal%2Fcore.svg" alt="npm version">
</a>
<a href="https://travis-ci.org/FoalTS/foal">
<img src="https://travis-ci.org/FoalTS/foal.svg?branch=add-travis" alt="Build Status">
</a>
<a href="https://codecov.io/github/FoalTS/foal">
<img src="https://codecov.io/gh/FoalTS/foal/branch/master/graphs/badge.svg" alt="Code coverage">
</a>
<a href="https://snyk.io/test/npm/@foal/core">
<img src="https://snyk.io/test/npm/@foal/core/badge.svg" alt="Known Vulnerabilities">
</a>
<a href="https://github.com/FoalTS/foal/commits/master">
<img src="https://img.shields.io/github/commit-activity/y/FoalTS/foal.svg" alt="Commit activity">
</a>
<a href="https://github.com/FoalTS/foal/commits/master">
<img src="https://img.shields.io/github/last-commit/FoalTS/foal.svg" alt="Last commit">
</a>
</p>
Web framework to create enterprise-grade Node.JS applications .
Github: [https://github.com/FoalTS/foal](https://github.com/FoalTS/foal)

@@ -18,1 +43,9 @@

Documentation: [https://foalts.gitbook.io/docs/](https://foalts.gitbook.io/docs/)
## Description
In recent years Node.js has become one of the most popular servers on the web. And for good reason, it is fast, simple while being powerful and flexible. Creating a server with only a few lines of code has never been easier.
But when it comes to setting up a complete and scalable project, things get harder. You have to put everything in place. The authorization system, database migrations, development tools or even encryption of passwords are just the tip of the iceberg. Working on this is time consuming and may slow down the release frequency or even lead to undesired bugs. As the codebase grows up and the complexity increases, it becomes harder and harder to develop new features and maintain the app.
This is where FoalTS comes in. Based on express, this lightweight framework provides everything needed to create enterprise-grade applications. From the support of TypeScript to the integration of security tools, it offers the basic bricks to build robust webapps. But FoalTS does not pretend to be a closed framework. You can still import and use your favorite librairies from the rich ecosystem of Node.js.
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