semantic-network
Version:
A utility library for manipulating a list of links that form a semantic interface to a network of resources.
31 lines (30 loc) • 1.88 kB
TypeScript
import { LinkedRepresentation, RelationshipType } from 'semantic-link';
import { ResourceQueryOptions } from '../interfaces/resourceQueryOptions';
import { ResourceAssignOptions } from '../interfaces/resourceAssignOptions';
import { Document, Nullable, Representation, Tracked } from '../types/types';
import { LoaderJobOptions } from '../interfaces/loader';
/**
*
*/
export type NameStrategy = (rel: RelationshipType | undefined, representation?: Representation | Document | undefined) => string;
/**
* Where the rel is multiple pick the first matched link to be converted as the name, otherwise use the given rel
* @param rel
* @param representation
*/
export declare const firstLinkNameStrategy: (includeTitle: boolean) => (rel: RelationshipType | undefined, representation: Representation | Document | undefined) => string;
export declare class NamedRepresentationFactory {
static defaultNameStrategy: NameStrategy;
/**
* Manages the loading (returning) of a named resource (sub-resource collection or singleton) on a context based on
* the {@link ResourceQueryOptions.rel}.
*
* Note: the naming strategy is currently not injectable but the value can be overridden {@link ResourceQueryOptions.name}
* @see LinkRelConvertUtil.relTypeToCamel
*
* @see TrackedRepresentationFactory
* @param resource context resource that has the sub-resource added (and is tracked {@link State.collection} and {@link State.singleton})
* @param options specify the {@link ResourceQueryOptions.rel} to pick the name resource
*/
static load<TReturn extends LinkedRepresentation, T extends LinkedRepresentation | TReturn = LinkedRepresentation, TResult extends TReturn = T extends TReturn ? T : TReturn>(resource: T, options?: ResourceQueryOptions & ResourceAssignOptions & LoaderJobOptions): Promise<Nullable<Tracked<TResult>>>;
}