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.0 to 0.4.0-alpha.2

dist/src/testing/create-empty-context.d.ts

3

dist/src/factories/controller-factory.js

@@ -15,5 +15,2 @@ /**

const service = services.get(ServiceClass);
if (!service) {
throw new Error(`${ServiceClass.name} should be declared in a module.`);
}
return this.getRoutes(service).map(route => {

@@ -20,0 +17,0 @@ const middlewares = [

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

const moduleHooks = foalModule.hooks || [];
const services = foalModule.services || [];
if (parentModule) {

@@ -24,3 +25,4 @@ this.services = new service_manager_1.ServiceManager(parentModule.services);

}
foalModule.services.forEach(service => this.services.add(service));
// Instantiate the services.
services.forEach(service => this.services.get(service));
const { modulePreMiddlewares, modulePostMiddlewares } = this.getMiddlewares(moduleHooks);

@@ -27,0 +29,0 @@ for (const controller of controllers) {

export * from './factories';
export * from './interfaces';
export * from './testing';
export { combineHooks } from './utils';

@@ -4,0 +5,0 @@ export * from './errors';

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

__export(require("./factories"));
__export(require("./testing"));
var utils_1 = require("./utils");

@@ -15,0 +16,0 @@ exports.combineHooks = utils_1.combineHooks;

import { Controller } from './controller-and-routes';
import { Hook, Type } from './utils';
export interface FoalModule {
services: Type<any>[];
services?: Type<any>[];
controllers?: Controller[];

@@ -6,0 +6,0 @@ hooks?: Hook[];

@@ -5,7 +5,6 @@ import 'reflect-metadata';

export declare class ServiceManager {
private parentServiceManager;
private map;
readonly parentServiceManager: ServiceManager | undefined;
map: Map<Type<any>, any>;
constructor(parentServiceManager?: ServiceManager | undefined);
add(Service: Type<any>): void;
get<T>(Service: Type<T>): T;
}

@@ -19,8 +19,13 @@ /**

}
add(Service) {
if (this.map.get(Service) || (this.parentServiceManager && this.parentServiceManager.get(Service))) {
return;
get(Service) {
// Get the service using a prototype pattern.
if (this.map.get(Service)) {
return this.map.get(Service);
}
if (this.parentServiceManager && this.parentServiceManager.map.get(Service)) {
return this.parentServiceManager.map.get(Service);
}
// If the service has not been instantiated yet, then instantiate it in this service manager.
const dependencies = Reflect.getMetadata('design:paramtypes', Service);
if (!dependencies) {
if (!Array.isArray(dependencies)) {
throw new Error(`${Service.name} has no dependencies. Please check that:

@@ -31,11 +36,8 @@ - The service has a constructor.

}
if (dependencies.length > 0) {
dependencies.forEach(dep => this.add(dep));
}
this.map.set(Service, new Service(...dependencies.map(Dep => this.map.get(Dep) || (this.parentServiceManager && this.parentServiceManager.get(Dep)))));
const service = new Service(...dependencies.map(Dep => this.get(Dep)));
// Save and return the service.
this.map.set(Service, service);
return service;
}
get(Service) {
return this.map.get(Service) || (this.parentServiceManager && this.parentServiceManager.get(Service));
}
}
exports.ServiceManager = ServiceManager;
{
"name": "@foal/core",
"version": "0.4.0-alpha.0",
"version": "0.4.0-alpha.2",
"description": "A Node.js framework for building robust web apps.",

@@ -10,4 +10,4 @@ "main": "./dist/index.js",

"dev:test": "mocha --require ts-node/register --watch --watch-extensions ts \"./src/**/*.spec.ts\"",
"build": "gulp clean && tsc && gulp add-header",
"prepublish": "gulp clean && tsc && gulp add-header"
"build": "gulp clean && tsc -p tsconfig-build.json && gulp add-header",
"prepublish": "gulp clean && tsc -p tsconfig-build.json && gulp add-header"
},

@@ -14,0 +14,0 @@ "engines": {

@@ -7,2 +7,3 @@ # FoalTS

[![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)

@@ -9,0 +10,0 @@ A Node.js framework for building robust web apps.

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