本文整理汇总了TypeScript中@nestjs/common/utils/shared.utils.isNil方法的典型用法代码示例。如果您正苦于以下问题:TypeScript utils.isNil方法的具体用法?TypeScript utils.isNil怎么用?TypeScript utils.isNil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@nestjs/common/utils/shared.utils
的用法示例。
在下文中一共展示了utils.isNil方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: isNil
public async resolveConstructorParams<T>(
wrapper: InstanceWrapper<T>,
module: Module,
inject: any[],
callback: (args) => void,
) {
let isResolved = true;
const args = isNil(inject)
? this.reflectConstructorParams(wrapper.metatype)
: inject;
const instances = await Promise.all(
args.map(async (param, index) => {
const paramWrapper = await this.resolveSingleParam<T>(
wrapper,
param,
{ index, length: args.length },
module,
);
if (!paramWrapper.isResolved && !paramWrapper.forwardRef) {
isResolved = false;
}
return paramWrapper.instance;
}),
);
isResolved && (await callback(instances));
}
示例2: _throw
public send<TResult = any, TInput = any>(
pattern: any,
data: TInput,
): Observable<TResult> {
if (isNil(pattern) || isNil(data)) {
return _throw(new InvalidMessageException());
}
return defer(async () => await this.connect()).pipe(
mergeMap(
() =>
new Observable((observer: Observer<TResult>) => {
const callback = this.createObserver(observer);
return this.publish({ pattern, data }, callback);
}),
),
);
}
示例3: isNil
public async resolveConstructorParams<T>(
wrapper: InstanceWrapper<T>,
module: Module,
inject: InjectorDependency[],
callback: (args) => void,
) {
let isResolved = true;
const dependencies = isNil(inject)
? this.reflectConstructorParams(wrapper.metatype)
: inject;
const optionalDependenciesIds = isNil(inject)
? this.reflectOptionalParams(wrapper.metatype)
: [];
const instances = await Promise.all(
dependencies.map(async (param, index) => {
try {
const paramWrapper = await this.resolveSingleParam<T>(
wrapper,
param,
{ index, dependencies },
module,
);
if (!paramWrapper.isResolved && !paramWrapper.forwardRef) {
isResolved = false;
}
return paramWrapper.instance;
} catch (err) {
const isOptional = optionalDependenciesIds.includes(index);
if (!isOptional) {
throw err;
}
return null;
}
}),
);
isResolved && (await callback(instances));
}
示例4: UnknownDependenciesException
public async lookupComponentInExports<T = any>(
dependencyContext: InjectorDependencyContext,
module: Module,
wrapper: InstanceWrapper<T>,
) {
const instanceWrapper = await this.lookupComponentInRelatedModules(
module,
dependencyContext.name,
);
if (isNil(instanceWrapper)) {
throw new UnknownDependenciesException(wrapper.name, dependencyContext, module);
}
return instanceWrapper;
}
示例5:
public loadPrototypeOfInstance<T>(
{ metatype, name }: InstanceWrapper<T>,
collection: Map<string, InstanceWrapper<T>>,
) {
if (!collection) return null;
const target = collection.get(name);
if (target.isResolved || !isNil(target.inject) || !metatype.prototype)
return null;
collection.set(name, {
...collection.get(name),
instance: Object.create(metatype.prototype),
});
}
示例6: UnknownDependenciesException
public async lookupComponentInExports<T = any>(
components: Map<string, any>,
{ name, index, length }: { name: any; index: number; length: number },
module: Module,
wrapper: InstanceWrapper<T>,
) {
const instanceWrapper = await this.lookupComponentInRelatedModules(
module,
name,
);
if (isNil(instanceWrapper)) {
throw new UnknownDependenciesException(wrapper.name, index, length);
}
return instanceWrapper;
}
示例7: metatype
async instances => {
if (isNil(inject)) {
currentMetatype.instance = Object.assign(
currentMetatype.instance,
new metatype(...instances),
);
} else {
const factoryResult = currentMetatype.metatype(...instances);
currentMetatype.instance = await this.resolveFactoryInstance(
factoryResult,
);
}
currentMetatype.isResolved = true;
done();
},
示例8:
export const UNKNOWN_DEPENDENCIES_MESSAGE = (
type: string,
unknownDependencyContext: InjectorDependencyContext,
module: Module,
) => {
const { index, dependencies, key } = unknownDependencyContext;
let message = `Nest can't resolve dependencies of the ${type}`;
if (isNil(index)) {
message += `. Please make sure that the "${key}" property is available in the current context.`;
return message;
}
const dependenciesName = (dependencies || []).map(getDependencyName);
dependenciesName[index] = '?';
message += ` (`;
message += dependenciesName.join(', ');
message += `). Please make sure that the argument at index [${index}] is available in the ${getModuleName(module)} context.`;
return message;
};
示例9: metatype
public async instantiateClass<T = any>(
instances: any[],
wrapper: InstanceWrapper<any>,
targetMetatype: InstanceWrapper<any>,
): Promise<T> {
const { metatype, inject } = wrapper;
if (isNil(inject)) {
targetMetatype.instance = Object.assign(
targetMetatype.instance,
new metatype(...instances),
);
} else {
const factoryResult = ((targetMetatype.metatype as any) as Function)(
...instances,
);
targetMetatype.instance = await factoryResult;
}
targetMetatype.isResolved = true;
return targetMetatype.instance;
}
示例10: return
public async resolveProperties<T>(
wrapper: InstanceWrapper<T>,
module: Module,
inject?: InjectorDependency[],
): Promise<PropertyDependency[]> {
if (!isNil(inject)) {
return [];
}
const properties = this.reflectProperties(wrapper.metatype);
const instances = await Promise.all(
properties.map(async (item: PropertyDependency) => {
try {
const dependencyContext = {
key: item.key,
name: item.name as string,
};
const paramWrapper = await this.resolveSingleParam<T>(
wrapper,
item.name,
dependencyContext,
module,
);
return (paramWrapper && paramWrapper.instance) || undefined;
} catch (err) {
if (!item.isOptional) {
throw err;
}
return undefined;
}
}),
);
return properties.map((item: PropertyDependency, index: number) => ({
...item,
instance: instances[index],
}));
}