@ngxs-labs/entity-state
Version:
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.0.5.
58 lines (57 loc) • 2.42 kB
TypeScript
import { EntityStateModel } from './models';
export declare namespace IdStrategy {
abstract class IdGenerator<T> {
protected readonly idKey: keyof T;
protected constructor(idKey: keyof T);
/**
* Generates a completely new ID.
* The IdGenerator's implementation has to ensure that the generated ID does not exist in the current state.
* It can throw an UnableToGenerateIdError if it's unable to do so.
* @param entity The entity to generate an ID for
* @param state The current state
* @see getPresentIdOrGenerate
* @see UnableToGenerateIdError
*/
abstract generateId(entity: Partial<T>, state: EntityStateModel<any>): string;
/**
* Checks if the given id is in the state's ID array
* @param id the ID to check
* @param state the current state
*/
isIdInState(id: string, state: EntityStateModel<any>): boolean;
/**
* This function tries to get the present ID of the given entity with #getIdOf.
* If it's undefined the #generateId function will be used.
* @param entity The entity to get the ID from
* @param state The current state
* @see getIdOf
* @see generateId
*/
getPresentIdOrGenerate(entity: Partial<T>, state: EntityStateModel<any>): string;
/**
* A wrapper for #getIdOf. If the function returns undefined an error will be thrown.
* @param entity The entity to get the ID from
* @see getIdOf
* @see InvalidIdOfError
*/
mustGetIdOf(entity: any): string;
/**
* Returns the ID for the given entity. Can return undefined.
* @param entity The entity to get the ID from
*/
getIdOf(entity: any): string | undefined;
}
class IncrementingIdGenerator<T> extends IdGenerator<T> {
constructor(idKey: keyof T);
generateId(entity: Partial<T>, state: EntityStateModel<any>): string;
}
class UUIDGenerator<T> extends IdGenerator<T> {
constructor(idKey: keyof T);
generateId(entity: Partial<T>, state: EntityStateModel<any>): string;
private uuidv4;
}
class EntityIdGenerator<T> extends IdGenerator<T> {
constructor(idKey: keyof T);
generateId(entity: Partial<T>, state: EntityStateModel<any>): string;
}
}