New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vorarbeiter

Package Overview
Dependencies
Maintainers
0
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vorarbeiter - npm Package Compare versions

Comparing version 6.0.5 to 7.0.0

7

dist/index.d.ts

@@ -39,7 +39,4 @@ export type Context = object;

export type ServiceId = string | symbol;
export type Next<T = unknown> = <T>(id: ServiceId) => T;
export type Middleware = <T = unknown>(arg: Next<T>) => Next<T>;
export interface ServiceSpec {
services: Map<ServiceId, ServiceDefinition>;
middlewares: Middleware[];
}

@@ -56,3 +53,2 @@ export interface ServiceContainer {

get<T>(id: ServiceId): T;
private resolveService;
private resolveServiceShared;

@@ -87,3 +83,2 @@ private resolveServiceTransient;

set<T>(id: ServiceId, factory: ServiceFactoryDefinition<T>): ServiceDefinitionBuilder<T>;
addMiddleware(...middlewares: Middleware[]): ServiceSpecBuilder;
getServiceSpec(): ServiceSpec;

@@ -93,5 +88,3 @@ }

private defBuilders;
private middlewares;
set<T>(id: ServiceId, factory: ServiceFactoryDefinition<T>): ServiceDefinitionBuilder<T>;
addMiddleware(...middlewares: Middleware[]): this;
getServiceSpec(): ServiceSpec;

@@ -98,0 +91,0 @@ }

16

dist/vorarbeiter.cjs.js

@@ -16,12 +16,4 @@ 'use strict';

this.loading = new Set();
let resolveService = this.resolveService.bind(this);
this.spec.middlewares.forEach(mw => {
resolveService = mw(resolveService);
});
this.resolveService = resolveService;
}
get(id) {
return this.resolveService(id);
}
resolveService(id) {
if (!this.spec.services.has(id)) {

@@ -134,3 +126,2 @@ throw new UnknownServiceError(id);

this.defBuilders = new Map();
this.middlewares = [];
}

@@ -142,6 +133,2 @@ set(id, factory) {

}
addMiddleware(...middlewares) {
this.middlewares.push(...middlewares);
return this;
}
getServiceSpec() {

@@ -153,4 +140,3 @@ const services = new Map();

return {
services,
middlewares: this.middlewares
services
};

@@ -157,0 +143,0 @@ }

2

dist/vorarbeiter.cjs.min.js

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

"use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ServiceType=void 0,(e=exports.ServiceType||(exports.ServiceType={})).Shared="shared",e.Transient="transient",e.Scoped="scoped";class t{constructor(e){this.spec=e,this.services=new Map,this.loading=new Set;let t=this.resolveService.bind(this);this.spec.middlewares.forEach((e=>{t=e(t)})),this.resolveService=t}get(e){return this.resolveService(e)}resolveService(e){if(!this.spec.services.has(e))throw new i(e);switch(this.spec.services.get(e).type.name){case exports.ServiceType.Transient:return this.resolveServiceTransient(e);case exports.ServiceType.Scoped:return this.resolveServiceScoped(e);case exports.ServiceType.Shared:return this.resolveServiceShared(e)}}resolveServiceShared(e){if(this.services.has(e))return this.services.get(e);const t=this.createService(e);return this.services.set(e,t),this.executeInjection(e,t),t}resolveServiceTransient(e){const t=this.createService(e);return this.executeInjection(e,t),t}resolveServiceScoped(e){const t=this.resolveContext(e);this.services.has(e)||this.services.set(e,new WeakMap);const r=this.services.get(e);if(r.has(t))return r.get(t);const s=this.createService(e);return r.set(t,s),this.executeInjection(e,s),s}has(e){return this.services.has(e)}createService(e){if(this.loading.has(e))throw new c(e,[...this.loading.values(),e]);const t=this.spec.services.get(e),{factory:r}=t;this.loading.add(e);const s="function"==typeof r?r(this):r.create(this);return this.loading.delete(e),s}executeInjection(e,t){const r=this.spec.services.get(e),{injector:s}=r;s&&("function"!=typeof s?s.inject(t,this):s(t,this))}resolveContext(e){const t=this.spec.services.get(e),{contextResolver:r}=t.type;return"function"==typeof r?r(this):r.resolveContext(this)}}class r{constructor(e){this.factory=e,this.shared()}shared(){return this.type={name:exports.ServiceType.Shared},this}transient(){return this.type={name:exports.ServiceType.Transient},this}scoped(e){return this.type={name:exports.ServiceType.Scoped,contextResolver:e},this}withInjector(e){return this.injector=e,this}getServiceDefinition(){return{type:this.type,factory:this.factory,injector:this.injector}}}class s{constructor(){this.defBuilders=new Map,this.middlewares=[]}set(e,t){const s=new r(t);return this.defBuilders.set(e,s),s}addMiddleware(...e){return this.middlewares.push(...e),this}getServiceSpec(){const e=new Map;return this.defBuilders.forEach(((t,r)=>{e.set(r,t.getServiceDefinition())})),{services:e,middlewares:this.middlewares}}}class i extends Error{constructor(e){super(`unknown service "${String(e)}"`),this.id=e,this.name="UnknownServiceError"}}class c extends Error{constructor(e,t){super(`circular dependency detected: ${t.map(String).join(" -> ")}`),this.id=e,this.referenceChain=t,this.name="ServiceCircularReferenceError"}}exports.ServiceCircularReferenceError=c,exports.ServiceContainerImpl=t,exports.ServiceDefinitionBuilderImpl=r,exports.ServiceSpecBuilderImpl=s,exports.UnknownServiceError=i,exports.createServiceContainer=e=>new t(e),exports.createServiceSpecBuilder=()=>new s;
"use strict";var e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ServiceType=void 0,(e=exports.ServiceType||(exports.ServiceType={})).Shared="shared",e.Transient="transient",e.Scoped="scoped";class t{constructor(e){this.spec=e,this.services=new Map,this.loading=new Set}get(e){if(!this.spec.services.has(e))throw new i(e);switch(this.spec.services.get(e).type.name){case exports.ServiceType.Transient:return this.resolveServiceTransient(e);case exports.ServiceType.Scoped:return this.resolveServiceScoped(e);case exports.ServiceType.Shared:return this.resolveServiceShared(e)}}resolveServiceShared(e){if(this.services.has(e))return this.services.get(e);const t=this.createService(e);return this.services.set(e,t),this.executeInjection(e,t),t}resolveServiceTransient(e){const t=this.createService(e);return this.executeInjection(e,t),t}resolveServiceScoped(e){const t=this.resolveContext(e);this.services.has(e)||this.services.set(e,new WeakMap);const r=this.services.get(e);if(r.has(t))return r.get(t);const s=this.createService(e);return r.set(t,s),this.executeInjection(e,s),s}has(e){return this.services.has(e)}createService(e){if(this.loading.has(e))throw new c(e,[...this.loading.values(),e]);const t=this.spec.services.get(e),{factory:r}=t;this.loading.add(e);const s="function"==typeof r?r(this):r.create(this);return this.loading.delete(e),s}executeInjection(e,t){const r=this.spec.services.get(e),{injector:s}=r;s&&("function"!=typeof s?s.inject(t,this):s(t,this))}resolveContext(e){const t=this.spec.services.get(e),{contextResolver:r}=t.type;return"function"==typeof r?r(this):r.resolveContext(this)}}class r{constructor(e){this.factory=e,this.shared()}shared(){return this.type={name:exports.ServiceType.Shared},this}transient(){return this.type={name:exports.ServiceType.Transient},this}scoped(e){return this.type={name:exports.ServiceType.Scoped,contextResolver:e},this}withInjector(e){return this.injector=e,this}getServiceDefinition(){return{type:this.type,factory:this.factory,injector:this.injector}}}class s{constructor(){this.defBuilders=new Map}set(e,t){const s=new r(t);return this.defBuilders.set(e,s),s}getServiceSpec(){const e=new Map;return this.defBuilders.forEach(((t,r)=>{e.set(r,t.getServiceDefinition())})),{services:e}}}class i extends Error{constructor(e){super(`unknown service "${String(e)}"`),this.id=e,this.name="UnknownServiceError"}}class c extends Error{constructor(e,t){super(`circular dependency detected: ${t.map(String).join(" -> ")}`),this.id=e,this.referenceChain=t,this.name="ServiceCircularReferenceError"}}exports.ServiceCircularReferenceError=c,exports.ServiceContainerImpl=t,exports.ServiceDefinitionBuilderImpl=r,exports.ServiceSpecBuilderImpl=s,exports.UnknownServiceError=i,exports.createServiceContainer=e=>new t(e),exports.createServiceSpecBuilder=()=>new s;
//# sourceMappingURL=vorarbeiter.cjs.min.js.map

@@ -12,12 +12,4 @@ var ServiceType;

this.loading = new Set();
let resolveService = this.resolveService.bind(this);
this.spec.middlewares.forEach(mw => {
resolveService = mw(resolveService);
});
this.resolveService = resolveService;
}
get(id) {
return this.resolveService(id);
}
resolveService(id) {
if (!this.spec.services.has(id)) {

@@ -130,3 +122,2 @@ throw new UnknownServiceError(id);

this.defBuilders = new Map();
this.middlewares = [];
}

@@ -138,6 +129,2 @@ set(id, factory) {

}
addMiddleware(...middlewares) {
this.middlewares.push(...middlewares);
return this;
}
getServiceSpec() {

@@ -149,4 +136,3 @@ const services = new Map();

return {
services,
middlewares: this.middlewares
services
};

@@ -153,0 +139,0 @@ }

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

var e;!function(e){e.Shared="shared",e.Transient="transient",e.Scoped="scoped"}(e||(e={}));class t{constructor(e){this.spec=e,this.services=new Map,this.loading=new Set;let t=this.resolveService.bind(this);this.spec.middlewares.forEach((e=>{t=e(t)})),this.resolveService=t}get(e){return this.resolveService(e)}resolveService(t){if(!this.spec.services.has(t))throw new c(t);switch(this.spec.services.get(t).type.name){case e.Transient:return this.resolveServiceTransient(t);case e.Scoped:return this.resolveServiceScoped(t);case e.Shared:return this.resolveServiceShared(t)}}resolveServiceShared(e){if(this.services.has(e))return this.services.get(e);const t=this.createService(e);return this.services.set(e,t),this.executeInjection(e,t),t}resolveServiceTransient(e){const t=this.createService(e);return this.executeInjection(e,t),t}resolveServiceScoped(e){const t=this.resolveContext(e);this.services.has(e)||this.services.set(e,new WeakMap);const s=this.services.get(e);if(s.has(t))return s.get(t);const r=this.createService(e);return s.set(t,r),this.executeInjection(e,r),r}has(e){return this.services.has(e)}createService(e){if(this.loading.has(e))throw new o(e,[...this.loading.values(),e]);const t=this.spec.services.get(e),{factory:s}=t;this.loading.add(e);const r="function"==typeof s?s(this):s.create(this);return this.loading.delete(e),r}executeInjection(e,t){const s=this.spec.services.get(e),{injector:r}=s;r&&("function"!=typeof r?r.inject(t,this):r(t,this))}resolveContext(e){const t=this.spec.services.get(e),{contextResolver:s}=t.type;return"function"==typeof s?s(this):s.resolveContext(this)}}const s=e=>new t(e);class r{constructor(e){this.factory=e,this.shared()}shared(){return this.type={name:e.Shared},this}transient(){return this.type={name:e.Transient},this}scoped(t){return this.type={name:e.Scoped,contextResolver:t},this}withInjector(e){return this.injector=e,this}getServiceDefinition(){return{type:this.type,factory:this.factory,injector:this.injector}}}class i{constructor(){this.defBuilders=new Map,this.middlewares=[]}set(e,t){const s=new r(t);return this.defBuilders.set(e,s),s}addMiddleware(...e){return this.middlewares.push(...e),this}getServiceSpec(){const e=new Map;return this.defBuilders.forEach(((t,s)=>{e.set(s,t.getServiceDefinition())})),{services:e,middlewares:this.middlewares}}}const n=()=>new i;class c extends Error{constructor(e){super(`unknown service "${String(e)}"`),this.id=e,this.name="UnknownServiceError"}}class o extends Error{constructor(e,t){super(`circular dependency detected: ${t.map(String).join(" -> ")}`),this.id=e,this.referenceChain=t,this.name="ServiceCircularReferenceError"}}export{o as ServiceCircularReferenceError,t as ServiceContainerImpl,r as ServiceDefinitionBuilderImpl,i as ServiceSpecBuilderImpl,e as ServiceType,c as UnknownServiceError,s as createServiceContainer,n as createServiceSpecBuilder};
var e;!function(e){e.Shared="shared",e.Transient="transient",e.Scoped="scoped"}(e||(e={}));class t{constructor(e){this.spec=e,this.services=new Map,this.loading=new Set}get(t){if(!this.spec.services.has(t))throw new c(t);switch(this.spec.services.get(t).type.name){case e.Transient:return this.resolveServiceTransient(t);case e.Scoped:return this.resolveServiceScoped(t);case e.Shared:return this.resolveServiceShared(t)}}resolveServiceShared(e){if(this.services.has(e))return this.services.get(e);const t=this.createService(e);return this.services.set(e,t),this.executeInjection(e,t),t}resolveServiceTransient(e){const t=this.createService(e);return this.executeInjection(e,t),t}resolveServiceScoped(e){const t=this.resolveContext(e);this.services.has(e)||this.services.set(e,new WeakMap);const s=this.services.get(e);if(s.has(t))return s.get(t);const r=this.createService(e);return s.set(t,r),this.executeInjection(e,r),r}has(e){return this.services.has(e)}createService(e){if(this.loading.has(e))throw new o(e,[...this.loading.values(),e]);const t=this.spec.services.get(e),{factory:s}=t;this.loading.add(e);const r="function"==typeof s?s(this):s.create(this);return this.loading.delete(e),r}executeInjection(e,t){const s=this.spec.services.get(e),{injector:r}=s;r&&("function"!=typeof r?r.inject(t,this):r(t,this))}resolveContext(e){const t=this.spec.services.get(e),{contextResolver:s}=t.type;return"function"==typeof s?s(this):s.resolveContext(this)}}const s=e=>new t(e);class r{constructor(e){this.factory=e,this.shared()}shared(){return this.type={name:e.Shared},this}transient(){return this.type={name:e.Transient},this}scoped(t){return this.type={name:e.Scoped,contextResolver:t},this}withInjector(e){return this.injector=e,this}getServiceDefinition(){return{type:this.type,factory:this.factory,injector:this.injector}}}class i{constructor(){this.defBuilders=new Map}set(e,t){const s=new r(t);return this.defBuilders.set(e,s),s}getServiceSpec(){const e=new Map;return this.defBuilders.forEach(((t,s)=>{e.set(s,t.getServiceDefinition())})),{services:e}}}const n=()=>new i;class c extends Error{constructor(e){super(`unknown service "${String(e)}"`),this.id=e,this.name="UnknownServiceError"}}class o extends Error{constructor(e,t){super(`circular dependency detected: ${t.map(String).join(" -> ")}`),this.id=e,this.referenceChain=t,this.name="ServiceCircularReferenceError"}}export{o as ServiceCircularReferenceError,t as ServiceContainerImpl,r as ServiceDefinitionBuilderImpl,i as ServiceSpecBuilderImpl,e as ServiceType,c as UnknownServiceError,s as createServiceContainer,n as createServiceSpecBuilder};
//# sourceMappingURL=vorarbeiter.esm.min.js.map

@@ -18,12 +18,4 @@ (function (global, factory) {

this.loading = new Set();
let resolveService = this.resolveService.bind(this);
this.spec.middlewares.forEach(mw => {
resolveService = mw(resolveService);
});
this.resolveService = resolveService;
}
get(id) {
return this.resolveService(id);
}
resolveService(id) {
if (!this.spec.services.has(id)) {

@@ -136,3 +128,2 @@ throw new UnknownServiceError(id);

this.defBuilders = new Map();
this.middlewares = [];
}

@@ -144,6 +135,2 @@ set(id, factory) {

}
addMiddleware(...middlewares) {
this.middlewares.push(...middlewares);
return this;
}
getServiceSpec() {

@@ -155,4 +142,3 @@ const services = new Map();

return {
services,
middlewares: this.middlewares
services
};

@@ -159,0 +145,0 @@ }

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vorarbeiter={})}(this,(function(e){"use strict";var t;e.ServiceType=void 0,(t=e.ServiceType||(e.ServiceType={})).Shared="shared",t.Transient="transient",t.Scoped="scoped";class r{constructor(e){this.spec=e,this.services=new Map,this.loading=new Set;let t=this.resolveService.bind(this);this.spec.middlewares.forEach((e=>{t=e(t)})),this.resolveService=t}get(e){return this.resolveService(e)}resolveService(t){if(!this.spec.services.has(t))throw new c(t);switch(this.spec.services.get(t).type.name){case e.ServiceType.Transient:return this.resolveServiceTransient(t);case e.ServiceType.Scoped:return this.resolveServiceScoped(t);case e.ServiceType.Shared:return this.resolveServiceShared(t)}}resolveServiceShared(e){if(this.services.has(e))return this.services.get(e);const t=this.createService(e);return this.services.set(e,t),this.executeInjection(e,t),t}resolveServiceTransient(e){const t=this.createService(e);return this.executeInjection(e,t),t}resolveServiceScoped(e){const t=this.resolveContext(e);this.services.has(e)||this.services.set(e,new WeakMap);const r=this.services.get(e);if(r.has(t))return r.get(t);const s=this.createService(e);return r.set(t,s),this.executeInjection(e,s),s}has(e){return this.services.has(e)}createService(e){if(this.loading.has(e))throw new n(e,[...this.loading.values(),e]);const t=this.spec.services.get(e),{factory:r}=t;this.loading.add(e);const s="function"==typeof r?r(this):r.create(this);return this.loading.delete(e),s}executeInjection(e,t){const r=this.spec.services.get(e),{injector:s}=r;s&&("function"!=typeof s?s.inject(t,this):s(t,this))}resolveContext(e){const t=this.spec.services.get(e),{contextResolver:r}=t.type;return"function"==typeof r?r(this):r.resolveContext(this)}}class s{constructor(e){this.factory=e,this.shared()}shared(){return this.type={name:e.ServiceType.Shared},this}transient(){return this.type={name:e.ServiceType.Transient},this}scoped(t){return this.type={name:e.ServiceType.Scoped,contextResolver:t},this}withInjector(e){return this.injector=e,this}getServiceDefinition(){return{type:this.type,factory:this.factory,injector:this.injector}}}class i{constructor(){this.defBuilders=new Map,this.middlewares=[]}set(e,t){const r=new s(t);return this.defBuilders.set(e,r),r}addMiddleware(...e){return this.middlewares.push(...e),this}getServiceSpec(){const e=new Map;return this.defBuilders.forEach(((t,r)=>{e.set(r,t.getServiceDefinition())})),{services:e,middlewares:this.middlewares}}}class c extends Error{constructor(e){super(`unknown service "${String(e)}"`),this.id=e,this.name="UnknownServiceError"}}class n extends Error{constructor(e,t){super(`circular dependency detected: ${t.map(String).join(" -> ")}`),this.id=e,this.referenceChain=t,this.name="ServiceCircularReferenceError"}}e.ServiceCircularReferenceError=n,e.ServiceContainerImpl=r,e.ServiceDefinitionBuilderImpl=s,e.ServiceSpecBuilderImpl=i,e.UnknownServiceError=c,e.createServiceContainer=e=>new r(e),e.createServiceSpecBuilder=()=>new i,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).vorarbeiter={})}(this,(function(e){"use strict";var t;e.ServiceType=void 0,(t=e.ServiceType||(e.ServiceType={})).Shared="shared",t.Transient="transient",t.Scoped="scoped";class r{constructor(e){this.spec=e,this.services=new Map,this.loading=new Set}get(t){if(!this.spec.services.has(t))throw new c(t);switch(this.spec.services.get(t).type.name){case e.ServiceType.Transient:return this.resolveServiceTransient(t);case e.ServiceType.Scoped:return this.resolveServiceScoped(t);case e.ServiceType.Shared:return this.resolveServiceShared(t)}}resolveServiceShared(e){if(this.services.has(e))return this.services.get(e);const t=this.createService(e);return this.services.set(e,t),this.executeInjection(e,t),t}resolveServiceTransient(e){const t=this.createService(e);return this.executeInjection(e,t),t}resolveServiceScoped(e){const t=this.resolveContext(e);this.services.has(e)||this.services.set(e,new WeakMap);const r=this.services.get(e);if(r.has(t))return r.get(t);const s=this.createService(e);return r.set(t,s),this.executeInjection(e,s),s}has(e){return this.services.has(e)}createService(e){if(this.loading.has(e))throw new n(e,[...this.loading.values(),e]);const t=this.spec.services.get(e),{factory:r}=t;this.loading.add(e);const s="function"==typeof r?r(this):r.create(this);return this.loading.delete(e),s}executeInjection(e,t){const r=this.spec.services.get(e),{injector:s}=r;s&&("function"!=typeof s?s.inject(t,this):s(t,this))}resolveContext(e){const t=this.spec.services.get(e),{contextResolver:r}=t.type;return"function"==typeof r?r(this):r.resolveContext(this)}}class s{constructor(e){this.factory=e,this.shared()}shared(){return this.type={name:e.ServiceType.Shared},this}transient(){return this.type={name:e.ServiceType.Transient},this}scoped(t){return this.type={name:e.ServiceType.Scoped,contextResolver:t},this}withInjector(e){return this.injector=e,this}getServiceDefinition(){return{type:this.type,factory:this.factory,injector:this.injector}}}class i{constructor(){this.defBuilders=new Map}set(e,t){const r=new s(t);return this.defBuilders.set(e,r),r}getServiceSpec(){const e=new Map;return this.defBuilders.forEach(((t,r)=>{e.set(r,t.getServiceDefinition())})),{services:e}}}class c extends Error{constructor(e){super(`unknown service "${String(e)}"`),this.id=e,this.name="UnknownServiceError"}}class n extends Error{constructor(e,t){super(`circular dependency detected: ${t.map(String).join(" -> ")}`),this.id=e,this.referenceChain=t,this.name="ServiceCircularReferenceError"}}e.ServiceCircularReferenceError=n,e.ServiceContainerImpl=r,e.ServiceDefinitionBuilderImpl=s,e.ServiceSpecBuilderImpl=i,e.UnknownServiceError=c,e.createServiceContainer=e=>new r(e),e.createServiceSpecBuilder=()=>new i,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=vorarbeiter.umd.min.js.map

@@ -12,12 +12,4 @@ export var ServiceType;

this.loading = new Set();
let resolveService = this.resolveService.bind(this);
this.spec.middlewares.forEach(mw => {
resolveService = mw(resolveService);
});
this.resolveService = resolveService;
}
get(id) {
return this.resolveService(id);
}
resolveService(id) {
if (!this.spec.services.has(id)) {

@@ -130,3 +122,2 @@ throw new UnknownServiceError(id);

this.defBuilders = new Map();
this.middlewares = [];
}

@@ -138,6 +129,2 @@ set(id, factory) {

}
addMiddleware(...middlewares) {
this.middlewares.push(...middlewares);
return this;
}
getServiceSpec() {

@@ -149,4 +136,3 @@ const services = new Map();

return {
services,
middlewares: this.middlewares
services
};

@@ -153,0 +139,0 @@ }

{
"name": "vorarbeiter",
"version": "6.0.5",
"version": "7.0.0",
"homepage": "https://github.com/slavamuravey/vorarbeiter",

@@ -5,0 +5,0 @@ "description": "A simple service container",

@@ -184,39 +184,2 @@ <p align="center">

This way we can perform property and setter injection.
### Middlewares
We can wrap service resolving in middlewares:
```typescript
const specBuilder = createServiceSpecBuilder();
function middleware1(next: Next): Next {
return function<T>(id: ServiceId): T {
console.log(`middleware1 start`);
const service: T = next(id);
console.log(`middleware1 end`);
return service;
}
}
function middleware2(next: Next): Next {
return function<T>(id: ServiceId): T {
console.log(`middleware2 start`);
const service: T = next(id);
console.log(`middleware2 end`);
return service;
}
}
specBuilder.addMiddleware(middleware1, middleware2);
const spec = specBuilder.getServiceSpec();
serviceContainer.get("someService");
// Output:
// middleware2 start
// middleware1 start
// middleware1 end
// middleware2 end
```

@@ -59,9 +59,4 @@ export type Context = object;

export type Next<T = unknown> = <T>(id: ServiceId) => T;
export type Middleware = <T = unknown>(arg: Next<T>) => Next<T>;
export interface ServiceSpec {
services: Map<ServiceId, ServiceDefinition>;
middlewares: Middleware[];
}

@@ -79,15 +74,5 @@

constructor(private readonly spec: ServiceSpec) {
let resolveService = this.resolveService.bind(this);
this.spec.middlewares.forEach(mw => {
resolveService = mw(resolveService);
});
this.resolveService = resolveService;
}
constructor(private readonly spec: ServiceSpec) {}
get<T>(id: ServiceId): T {
return this.resolveService(id);
}
private resolveService<T>(id: ServiceId): T {
if (!this.spec.services.has(id)) {

@@ -238,3 +223,2 @@ throw new UnknownServiceError(id);

set<T>(id: ServiceId, factory: ServiceFactoryDefinition<T>): ServiceDefinitionBuilder<T>;
addMiddleware(...middlewares: Middleware[]): ServiceSpecBuilder;
getServiceSpec(): ServiceSpec;

@@ -246,4 +230,2 @@ }

private middlewares: Middleware[] = [];
set<T>(id: ServiceId, factory: ServiceFactoryDefinition<T>): ServiceDefinitionBuilder<T> {

@@ -256,7 +238,2 @@ const definitionBuilder = new ServiceDefinitionBuilderImpl<T>(factory);

addMiddleware(...middlewares: Middleware[]) {
this.middlewares.push(...middlewares);
return this;
}
getServiceSpec(): ServiceSpec {

@@ -269,4 +246,3 @@ const services = new Map<ServiceId, ServiceDefinition>();

return {
services,
middlewares: this.middlewares
services
};

@@ -273,0 +249,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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