Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*getAllFilteredMethodNames(prototype: any): IterableIterator {
do {
yield* iterate(Object.getOwnPropertyNames(prototype))
.filter(prop => {
const descriptor = Object.getOwnPropertyDescriptor(prototype, prop);
if (descriptor.set || descriptor.get) {
return false;
}
return !isConstructor(prop) && isFunction(prototype[prop]);
})
.toArray();
} while (
// tslint:disable-next-line:no-conditional-assignment
(prototype = Reflect.getPrototypeOf(prototype)) &&
prototype !== Object.prototype
);
}
}
private _publishDiagnostics(uri: string, span = new Span()): void {
const config = this.projectManager.getParentConfiguration(uri);
if (!config) {
return;
}
const program = config.getProgram(span);
if (!program) {
return;
}
const sourceFile = program.getSourceFile(uri2path(uri));
if (!sourceFile) {
return;
}
const tsDiagnostics = ts.getPreEmitDiagnostics(program, sourceFile);
const diagnostics = iterate(tsDiagnostics)
// TS can report diagnostics without a file and range in some cases
// These cannot be represented as LSP Diagnostics since the range and URI is required
// https://github.com/Microsoft/TypeScript/issues/15666
.filter(diagnostic => !!diagnostic.file)
.map(convertTsDiagnostic)
.toArray();
this.client.textDocumentPublishDiagnostics({ uri, diagnostics });
}
function callOperator(instances: InstanceWrapper[]): Promise[] {
return iterate(instances)
.filter(instance => !isNil(instance))
.filter(hasOnModuleInitHook)
.map(async instance => ((instance as any) as OnModuleInit).onModuleInit())
.toArray();
}
function callOperator(
instances: InstanceWrapper[],
signal?: string,
): Promise[] {
return iterate(instances)
.filter(instance => !isNil(instance))
.filter(hasOnAppShutdownHook)
.map(async instance =>
((instance as any) as OnApplicationShutdown).onApplicationShutdown(
signal,
),
)
.toArray();
}
function callOperator(instances: InstanceWrapper[]): Promise[] {
return iterate(instances)
.filter(instance => !isNil(instance))
.filter(hasOnModuleDestroyHook)
.map(async instance =>
((instance as any) as OnModuleDestroy).onModuleDestroy(),
)
.toArray();
}
private _publishDiagnostics(uri: string, span = new Span()): void {
const config = this.projectManager.getParentConfiguration(uri)
if (!config) {
return
}
const fileName = uri2path(uri)
const tsDiagnostics = config
.getService()
.getSyntacticDiagnostics(fileName)
.concat(
config
.getService()
.getSemanticDiagnostics(fileName)
.filter((e): e is ts.DiagnosticWithLocation => !!e.file)
)
const diagnostics = iterate(tsDiagnostics)
.map(convertTsDiagnostic)
.toArray()
this.client.textDocumentPublishDiagnostics({ uri, diagnostics })
}
public createConcreteContext(
metadata: T,
contextId = STATIC_CONTEXT,
inquirerId?: string,
): R {
if (isEmpty(metadata)) {
return [] as R;
}
return iterate(metadata)
.filter((guard: any) => guard && (guard.name || guard.canActivate))
.map(guard => this.getGuardInstance(guard, contextId, inquirerId))
.filter((guard: CanActivate) => guard && isFunction(guard.canActivate))
.toArray() as R;
}
public createConcreteContext(metadata: T): R {
if (isUndefined(metadata) || isEmpty(metadata) || !this.moduleContext) {
return [] as R;
}
const isGlobalMetadata = metadata === this.getGlobalMetadata();
return isGlobalMetadata ?
this.createGlobalMetadataContext(metadata) :
iterate(metadata).filter((metatype: any) => metatype && metatype.name)
.map((metatype) => this.getInstanceByMetatype(metatype))
.filter((wrapper: any) => wrapper && wrapper.instance)
.map((wrapper) => wrapper.instance)
.filter((guard: CanActivate) => guard && isFunction(guard.canActivate))
.toArray() as R;
}
private callModuleDestroyHook(module: Module) {
const components = [...module.routes, ...module.components];
iterate(components)
.map(([key, { instance }]) => instance)
.filter(instance => !isNil(instance))
.filter(this.hasOnModuleDestroyHook)
.forEach(instance => (instance as OnModuleDestroy).onModuleDestroy());
}
applyMiddlewares(server, components, tokens) {
const adapter = this.config.getIoAdapter();
iterare_1.default(tokens)
.map(token => this.bindMiddleware(token.name, components))
.filter(middleware => !shared_utils_1.isNil(middleware))
.forEach(middleware => adapter.bindMiddleware(server, middleware));
}
bindMiddleware(token, components) {