@appolo/inject
Advanced tools
Comparing version 8.0.10 to 8.0.11
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.injectorAware = exports.bootstrap = exports.bootstrapAsync = exports.factoryMethodAsync = exports.customParam = exports.initAsync = exports.customFn = exports.dynamicFactory = exports.override = exports.lazy = exports.alias = exports.aliasFactory = exports.value = exports.objectProperty = exports.factory = exports.dictionary = exports.array = exports.init = exports.factoryMethod = exports.inject = exports.singleton = exports.define = exports.InjectDefineSymbol = exports.Util = exports.Define = exports.createContainer = exports.Injector = void 0; | ||
exports.aliasMap = exports.aliasFactoryMap = exports.injectorAware = exports.bootstrap = exports.bootstrapAsync = exports.factoryMethodAsync = exports.customParam = exports.initAsync = exports.customFn = exports.dynamicFactory = exports.override = exports.lazy = exports.alias = exports.aliasFactory = exports.value = exports.objectProperty = exports.factory = exports.dictionary = exports.array = exports.init = exports.factoryMethod = exports.inject = exports.singleton = exports.define = exports.InjectDefineSymbol = exports.Util = exports.Define = exports.createContainer = exports.Injector = void 0; | ||
exports.default = require('./lib/inject'); | ||
@@ -36,2 +36,4 @@ var inject_1 = require("./lib/inject"); | ||
Object.defineProperty(exports, "injectorAware", { enumerable: true, get: function () { return decorators_1.injectorAware; } }); | ||
Object.defineProperty(exports, "aliasFactoryMap", { enumerable: true, get: function () { return decorators_1.aliasFactoryMap; } }); | ||
Object.defineProperty(exports, "aliasMap", { enumerable: true, get: function () { return decorators_1.aliasMap; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -31,3 +31,3 @@ export default require('./lib/inject'); | ||
bootstrap, | ||
injectorAware | ||
injectorAware, aliasFactoryMap, aliasMap | ||
} from './lib/decorators' |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.value = exports.objectProperty = exports.dictionary = exports.array = exports.factoryMethodAsync = exports.factoryMethod = exports.customFn = exports.inject = exports.bootstrapAsync = exports.bootstrap = exports.initAsync = exports.init = exports.aliasFactory = exports.alias = exports.customParam = exports.override = exports.lazy = exports.dynamicFactory = exports.factory = exports.injectorAware = exports.singleton = exports.define = exports.InjectParamSymbol = exports.InjectDefineSymbol = exports.InjectDefinitionsSymbol = void 0; | ||
exports.value = exports.objectProperty = exports.dictionary = exports.array = exports.factoryMethodAsync = exports.factoryMethod = exports.customFn = exports.inject = exports.bootstrapAsync = exports.bootstrap = exports.initAsync = exports.init = exports.aliasFactory = exports.aliasFactoryMap = exports.aliasMap = exports.alias = exports.customParam = exports.override = exports.lazy = exports.dynamicFactory = exports.factory = exports.injectorAware = exports.singleton = exports.define = exports.InjectParamSymbol = exports.InjectDefineSymbol = exports.InjectDefinitionsSymbol = void 0; | ||
require("reflect-metadata"); | ||
@@ -101,2 +101,10 @@ const define_1 = require("./define"); | ||
exports.alias = alias; | ||
function aliasMap(alias, indexBy) { | ||
return addDefinitionProperty("injectAlias", [alias, { type: "map", index: indexBy }], true); | ||
} | ||
exports.aliasMap = aliasMap; | ||
function aliasFactoryMap(alias, indexBy) { | ||
return addDefinitionProperty("injectAliasFactory", [alias, { type: "map", index: indexBy }], true); | ||
} | ||
exports.aliasFactoryMap = aliasFactoryMap; | ||
function aliasFactory(aliasFactory, indexBy) { | ||
@@ -103,0 +111,0 @@ return function (target, propertyKey, descriptor) { |
@@ -61,3 +61,3 @@ import "reflect-metadata"; | ||
export function factory(factory?: string | Class): (fn: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void { | ||
export function factory(factory?: string | Class): (fn: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void { | ||
@@ -75,3 +75,3 @@ return function (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) { | ||
function injectFactory(factory?: string | Class): (target: any, propertyKey: string, descriptor?: PropertyDescriptor) => void { | ||
function injectFactory(factory?: string | Class): (target: any, propertyKey: string, descriptor?: PropertyDescriptor) => void { | ||
@@ -123,3 +123,15 @@ return addDefinitionProperty("injectFactory", [Util.getClassNameOrId(factory)], true); | ||
export function aliasMap<T>(alias: string, indexBy: string | ((item: T) => any)): (fn: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void { | ||
return addDefinitionProperty("injectAlias", [alias, {type: "map", index: indexBy}], true); | ||
} | ||
export function aliasFactoryMap<T extends {new(...params:any[]):any}>(alias: string, indexBy: string | ((item: T) => any)): (fn: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void { | ||
return addDefinitionProperty("injectAliasFactory", [alias, {type: "map", index: indexBy}], true); | ||
} | ||
export function aliasFactory(aliasFactory: string, indexBy?: string): (fn: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void { | ||
@@ -126,0 +138,0 @@ |
@@ -162,3 +162,3 @@ "use strict"; | ||
public injectAlias(name: string, alias: string, indexBy?: string, parent?: Class): this { | ||
public injectAlias(name: string, alias: string, indexBy?: string | { type: "map", index: string }, parent?: Class): this { | ||
return this.inject({ | ||
@@ -171,3 +171,3 @@ name: name, | ||
public injectAliasFactory(name: string, alias: string, indexBy?: string, parent?: Class): this { | ||
public injectAliasFactory(name: string, alias: string, indexBy?: string| { type: "map", index: string }, parent?: Class): this { | ||
return this.inject({ | ||
@@ -278,3 +278,3 @@ name: name, | ||
public clone():Define{ | ||
public clone(): Define { | ||
let define = new Define(this._id); | ||
@@ -281,0 +281,0 @@ |
@@ -11,3 +11,3 @@ import {Injector} from "./inject"; | ||
key?: string, | ||
indexBy?: string, | ||
indexBy?: string| { type: "map"|"object", index: string }, | ||
aliasFactory?: string, | ||
@@ -14,0 +14,0 @@ alias?: string | Class, |
@@ -530,3 +530,3 @@ "use strict"; | ||
_prepareProperties(definition) { | ||
let properties = definition.inject || []; | ||
let properties = []; | ||
for (let i = 0, length = (definition.inject ? definition.inject.length : 0); i < length; i++) { | ||
@@ -720,5 +720,11 @@ let injectable = definition.inject[i]; | ||
let injector = prop.injector ? prop.injector : this; | ||
(prop.alias) && (instance[prop.name] = prop.indexBy | ||
? util_1.Util.keyBy(injector.getAlias(prop.alias), prop.indexBy) | ||
: injector.getAlias(prop.alias)); | ||
if (!prop.alias) { | ||
continue; | ||
} | ||
let alias = injector.getAlias(prop.alias); | ||
instance[prop.name] = (!prop.indexBy) | ||
? alias | ||
: ((typeof prop.indexBy == "string") | ||
? util_1.Util.keyBy(alias, prop.indexBy) | ||
: util_1.Util.keyByMap(alias, prop.indexBy.index)); | ||
} | ||
@@ -733,7 +739,18 @@ } | ||
let injector = prop.injector ? prop.injector : this; | ||
if (prop.aliasFactory) { | ||
instance[prop.name] = prop.indexBy | ||
? util_1.Util.keyBy(injector.getAliasFactory(prop.aliasFactory), (item) => item.type[prop.indexBy]) | ||
: injector.getAliasFactory(prop.aliasFactory); | ||
if (!prop.aliasFactory) { | ||
continue; | ||
} | ||
let alias = injector.getAliasFactory(prop.aliasFactory); | ||
if (!prop.indexBy) { | ||
instance[prop.name] = alias; | ||
} | ||
else { | ||
let fn = function (key, type = "object") { | ||
let fn = (item) => util_1.Util.isFunction(key) ? key(item.type, i) : item.type[key]; | ||
return type == "map" ? util_1.Util.keyByMap(alias, fn) : util_1.Util.keyBy(alias, fn); | ||
}; | ||
instance[prop.name] = typeof prop.indexBy == "string" | ||
? fn(prop.indexBy, "object") | ||
: fn(prop.indexBy.index, "map"); | ||
} | ||
} | ||
@@ -740,0 +757,0 @@ } |
@@ -782,3 +782,3 @@ "use strict"; | ||
let properties = definition.inject || []; | ||
let properties = []; | ||
@@ -1043,8 +1043,18 @@ | ||
(prop.alias) && (instance[prop.name] = prop.indexBy | ||
? Util.keyBy(injector.getAlias(prop.alias as string), prop.indexBy) | ||
: injector.getAlias(prop.alias as string)); | ||
if (!prop.alias) { | ||
continue; | ||
} | ||
let alias = injector.getAlias(prop.alias as string); | ||
instance[prop.name] = (!prop.indexBy) | ||
? alias | ||
: ((typeof prop.indexBy == "string") | ||
? Util.keyBy(alias, prop.indexBy as string) | ||
: Util.keyByMap(alias, prop.indexBy.index as string)) | ||
} | ||
} | ||
private _injectAliasFactory<T>(definition: IDefinition, instance: T) { | ||
@@ -1060,7 +1070,20 @@ if (instance[IsWiredSymbol]) { | ||
if (prop.aliasFactory) { | ||
instance[prop.name] = prop.indexBy | ||
? Util.keyBy(injector.getAliasFactory(prop.aliasFactory), (item) => item.type[prop.indexBy]) | ||
: injector.getAliasFactory(prop.aliasFactory) | ||
if (!prop.aliasFactory) { | ||
continue; | ||
} | ||
let alias = injector.getAliasFactory(prop.aliasFactory as string); | ||
if (!prop.indexBy) { | ||
instance[prop.name] = alias; | ||
} else { | ||
let fn = function (key: any, type: "map" | "object" = "object") { | ||
let fn = (item) => Util.isFunction(key) ? (key as any)(item.type, i) : item.type[key as string]; | ||
return type =="map" ?Util.keyByMap(alias,fn) : Util.keyBy(alias,fn) | ||
} | ||
instance[prop.name] = typeof prop.indexBy == "string" | ||
? fn(prop.indexBy,"object") | ||
: fn(prop.indexBy.index,"map") | ||
} | ||
} | ||
@@ -1067,0 +1090,0 @@ } |
@@ -46,2 +46,11 @@ "use strict"; | ||
} | ||
static keyByMap(arr, key) { | ||
let output = new Map(); | ||
for (let i = 0, len = (arr || []).length; i < len; i++) { | ||
let item = arr[i]; | ||
let outputKey = Util.isFunction(key) ? key(item, i) : item[key]; | ||
output.set(outputKey, item); | ||
} | ||
return output; | ||
} | ||
static removeFromArray(list, item) { | ||
@@ -48,0 +57,0 @@ if (!list || !list.length) { |
@@ -60,2 +60,18 @@ import {InjectDefineSymbol} from "./decorators"; | ||
public static keyByMap<T extends object,K extends any=string>(arr: T[], key: string | ((item: T, index: number) => string)):Map<K,T> { | ||
let output = new Map<K,T>() | ||
for (let i = 0, len = (arr || []).length; i < len; i++) { | ||
let item: any = arr[i]; | ||
let outputKey = Util.isFunction(key) ? (key as Function)(item, i) : item[key as string]; | ||
output.set(outputKey,item) | ||
} | ||
return output; | ||
} | ||
public static removeFromArray<T>(list: T[], item: T): void { | ||
@@ -62,0 +78,0 @@ |
@@ -34,3 +34,3 @@ { | ||
"main": "./index.js", | ||
"version": "8.0.10", | ||
"version": "8.0.11", | ||
"license": "MIT", | ||
@@ -44,3 +44,3 @@ "repository": { | ||
"dependencies": { | ||
"@appolo/events": "^8.0.0", | ||
"@appolo/events": "^8.0.2", | ||
"reflect-metadata": "^0.1.13", | ||
@@ -47,0 +47,0 @@ "tslib": "^2.0.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
182228
2854
Updated@appolo/events@^8.0.2