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

true-di

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

true-di - npm Package Compare versions

Comparing version 2.1.5 to 2.1.6

2

package.json
{
"name": "true-di",
"version": "2.1.5",
"version": "2.1.6",
"description": "Framework Agnostic, Zero Dependency, Isomorphic & Minimalistic Dependency Injection Container for TypeScript and JavaScript projects",

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

@@ -86,27 +86,19 @@ # true-di

```typescript
import Express from 'express';
import { Request, Response, NextFunction as Next } from 'express';
import { IGetOrderById, IGetOrders } from './interfaces';
import { Injected } from './interfaces/IRequestInjected';
import { sendJson } from './utils/sendJson';
import { expectFound } from './utils/NotFoundError';
export const getOrders = (
{ injected: { ecommerceService } }: Injected<{ ecommerceService: IGetOrders }>,
res: Express.Response,
next: Express.NextFunction,
) =>
ecommerceService
.getOrders()
.then(sendJson(res), next);
export const getOrders = (req: Request, res: Response, next: Next) =>
({ ecommerceService }: { ecommerceService: IGetOrders }) =>
ecommerceService
.getOrders()
.then(sendJson(res), next);
export const getOrderById = (
{ params, injected: { ecommerceService } }:
{ params: { id: string } } & Injected<{ ecommerceService: IGetOrderById }>,
res: Express.Response,
next: Express.NextFunction,
) =>
ecommerceService
.getOrderById(params.id)
.then(expectFound(`Order(${params.id})`))
.then(sendJson(res), next);
export const getOrderById = ({ params }: Request<{ id: string }>, res: Response, next: Next) =>
({ ecommerceService }: { ecommerceService: IGetOrderById }) =>
ecommerceService
.getOrderById(params.id)
.then(expectFound(`Order(${params.id})`))
.then(sendJson(res), next);
```

@@ -118,2 +110,3 @@

import express from 'express';
import createContext from 'express-async-context';
import container from './container';

@@ -124,21 +117,15 @@ import { getOrderById, getOrders } from './controller';

const app = express();
const Context = createContext(() => container);
app.use((req, _, next) => {
req.injected = container;
next();
});
app.use(Context.provider);
app.get('/orders', getOrders);
app.get('/orders/:id', getOrderById);
app.get('/orders', Context.consumer(getOrders));
app.get('/orders/:id', Context.consumer(getOrderById));
app.use(handleErrors);
app.use(Context.consumer(handleErrors));
if (module.parent == null) {
app.listen(8080, () => {
console.log('Server is listening on port: 8080');
console.log('Follow: http://localhost:8080/orders');
});
}
export default app;
app.listen(8080, () => {
console.log('Server is listening on port: 8080');
console.log('Follow: http://localhost:8080/orders');
});
```

@@ -145,0 +132,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