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

@travetto/di

Package Overview
Dependencies
Maintainers
1
Versions
313
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/di - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

2

package.json

@@ -22,3 +22,3 @@ {

},
"version": "0.0.12"
"version": "0.0.13"
}

@@ -20,3 +20,4 @@ import { InjectableConfig, Dependency } from '../types';

export function Injectable(qualifier: symbol, config?: Partial<InjectableConfig<any>>): ClassDecorator;
export function Injectable(config?: Partial<InjectableConfig<any>>): ClassDecorator;
export function Injectable(config: Partial<InjectableConfig<any>>): ClassDecorator;
export function Injectable(): ClassDecorator;
export function Injectable(...args: any[]): ClassDecorator {

@@ -44,3 +45,4 @@ return (target: Class | any) => {

export function Inject(symbol: symbol, config?: InjectConfig): ParameterDecorator & PropertyDecorator;
export function Inject(config?: InjectConfig): ParameterDecorator & PropertyDecorator;
export function Inject(config: InjectConfig): ParameterDecorator & PropertyDecorator;
export function Inject(): ParameterDecorator & PropertyDecorator;
export function Inject(...args: any[]): ParameterDecorator & PropertyDecorator {

@@ -61,3 +63,4 @@

export function InjectableFactory(symbol: symbol, config?: InjectableFactoryConfig<any>): MethodDecorator;
export function InjectableFactory(config?: InjectableFactoryConfig<any>): MethodDecorator;
export function InjectableFactory(config: InjectableFactoryConfig<any>): MethodDecorator;
export function InjectableFactory(): MethodDecorator;
export function InjectableFactory(...args: any[]): MethodDecorator {

@@ -64,0 +67,0 @@

@@ -289,13 +289,2 @@ import { Dependency, InjectableConfig, ClassTarget, InjectableFactoryConfig } from '../types';

// Mirror target's field dependencies
if (config.class) {
const targetConfig = this.get(config.class);
if (targetConfig && targetConfig.dependencies) {
finalConfig.dependencies.fields = {};
for (const k of Object.keys(targetConfig.dependencies.fields)) {
finalConfig.dependencies.fields[k] = targetConfig.dependencies.fields[k];
}
}
}
// Create mock cls for DI purposes

@@ -312,8 +301,6 @@ const cls = { __id: config.id || `${config.class.__id}#${config.fn.name}` } as any;

console.debug('Finalized', classId);
const config = this.getOrCreatePending(cls) as InjectableConfig<T>;
// Allow for the factory to fulfill the target
const parentClass = Object.getPrototypeOf(cls);
const parentClass = config.factory ? config.target : Object.getPrototypeOf(cls);
const parentConfig = this.get(parentClass.__id);

@@ -320,0 +307,0 @@

@@ -52,2 +52,8 @@ import { Injectable, Inject, InjectableFactory } from '../src';

class TestConfig {
@InjectableFactory({ qualifier: CUSTOM_EMPTY, class: DbConfig })
static getNewDb(): DbConfig<any, any> {
const out = new DbConfig();
return out;
}
@InjectableFactory(CUSTOM_EMPTY)

@@ -54,0 +60,0 @@ static getNewEmpty(): Empty {

import { DependencyRegistry } from '../src/service';
import { ServiceInherit, SERVICE_INHERIT_2, CUSTOM_SERVICE_INHERIT, CUSTOM_DATABSE, Database } from './deps';
import { ServiceInherit, SERVICE_INHERIT_2, CUSTOM_SERVICE_INHERIT, CUSTOM_DATABSE, Database, CUSTOM_EMPTY } from './deps';
import { Suite, Test, BeforeEach } from '@travetto/test';
import * as assert from 'assert';
import { DbConfig } from './config';

@@ -109,2 +110,26 @@ const FOUR = 4;

}
@Test('factory with autowire after')
async factory3() {
assert(true);
const inst = await DependencyRegistry.getInstance(Database);
assert(inst);
assert(inst.altConfig === undefined);
assert.ok(inst.dbConfig);
}
@Test('factory with autowire after')
async factory4() {
assert(true);
const inst = await DependencyRegistry.getInstance(DbConfig, CUSTOM_EMPTY);
assert(inst);
assert(inst.empty);
}
}
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