You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/src/support/CanonicalReceiver.ts

62 lines
2.2 KiB

import {AppClass} from '../lifecycle/AppClass'
/**
* Interface for a class that receives its canonical resolver names upon load.
*/
export interface CanonicalReceiver {
setCanonicalResolver(fullyQualifiedResolver: string, unqualifiedResolver: string): void
getCanonicalResolver(): string | undefined
getFullyQualifiedCanonicalResolver(): string | undefined
}
/**
* Function that checks whether a given value satisfies the CanonicalReceiver interface.
* @param something
*/
export function isCanonicalReceiver(something: unknown): something is CanonicalReceiver {
return (
typeof something === 'function'
&& typeof (something as any).setCanonicalResolver === 'function'
&& (something as any).setCanonicalResolver.length >= 1
&& typeof (something as any).getCanonicalResolver === 'function'
&& (something as any).getCanonicalResolver.length === 0
)
}
/**
* Base class for canonical items that implements the CanonicalReceiver interface.
* That is, `isCanonicalReceiver(CanonicalItemClass) === true`.
*/
export class CanonicalItemClass extends AppClass {
/** The type-prefixed canonical resolver of this class, set by the startup unit. */
private static canonFullyQualifiedResolver?: string
/** The unqualified canonical resolver of this class, set by the startup unit. */
private static canonUnqualifiedResolver?: string
/**
* Sets the fully- and un-qualified canonical resolver strings. Intended for use
* by the Canonical unit.
* @param fullyQualifiedResolver
* @param unqualifiedResolver
*/
public static setCanonicalResolver(fullyQualifiedResolver: string, unqualifiedResolver: string): void {
this.canonFullyQualifiedResolver = fullyQualifiedResolver
this.canonUnqualifiedResolver = unqualifiedResolver
}
/**
* Get the fully-qualified canonical resolver of this class, if one has been set.
*/
public static getFullyQualifiedCanonicalResolver(): string | undefined {
return this.canonFullyQualifiedResolver
}
/**
* Get the unqualified canonical resolver of this class, if one has been set.
*/
public static getCanonicalResolver(): string | undefined {
return this.canonUnqualifiedResolver
}
}