@dolittle/sdk.common
Version:
Dolittle is a decentralized, distributed, event-driven microservice platform built to harness the power of events.
73 lines • 3.93 kB
TypeScript
import { ConceptAs } from '@dolittle/concepts';
import { Guid, IEquatable } from '@dolittle/rudiments';
import { Constructor } from '@dolittle/types';
declare type Extras = {
[property: string]: IEquatable;
} | void;
declare type ExtraPredicates<E extends Extras> = E extends void ? undefined : {
[property in keyof E]: (object: any) => object is E[property];
};
/**
* Defines an identifier in an application model.
* @template I The type of the globally unique id of the identifier.
* @template E The type of the extra data of the identifier.
*/
export declare abstract class Identifier<I extends ConceptAs<Guid, string>, U extends string, E extends Extras = void> implements IEquatable {
readonly id: I;
readonly type: U;
readonly __extras: E;
/**
* Initialises a new instance of the {@link Identifier} class.
* @param {I} id - The globally unique id for the identifier.
* @param {string} type - The unique name of the identifier.
* @param {E} __extras - The extra data for the identifier.
*/
constructor(id: I, type: U, __extras: E);
/** @inheritdoc */
equals(other: any): boolean;
/**
* Determines whether or not this identifier can coexist with another identifier.
* By default identifiers with a similar id cannot coexist, but subtypes can implement custom logic.
* @param {AnyIdentifier} identifier - The other identifier to check if can coexist with.
* @returns {boolean} True if this identifier can coexist with the other identifier, false if not.
*/
canCoexistWith(identifier: AnyIdentifier): boolean;
/** @inheritdoc */
toString(): string;
/** @inheritdoc */
protected abstract [Symbol.toStringTag]: string;
/**
* Selects properties from the extra data to include while computing {@link Identifier.toString}.
* @param {Extras} extras - The extra data of the identifier.
* @returns {object | undefined} An object with the properties to include, or undefined.
*/
protected toStringExtras(extras: E): object | undefined | void;
private createExtraToString;
private extrasEquals;
}
/**
* Represents any kind of {@link Identifier}.
*/
export declare type AnyIdentifier = Identifier<ConceptAs<Guid, string>, string, Extras>;
declare type CreateIsIdentifier = {
/**
* Creates a type predicate for the provided {@link Identifier} type.
* @param {Constructor} type - The type of the identifier.
* @param {(any) => boolean} isId - The predicate for the globally unqiue id of the identifier.
* @param {string} identifierType - The unique name of the identifier.
* @returns {(any) => boolean} A type predicate that checksi if an object is an instance of the {@link Identifier} type.
*/
<T extends Identifier<I, U, E>, I extends ConceptAs<Guid, string>, U extends string, E extends void>(type: Constructor<T>, isId: (object: any) => object is T['id'], identifierType: T['type']): (object: any) => object is T;
/**
* Creates a type predicate for the provided {@link Identifier} type.
* @param {Constructor} type - The type of the identifier.
* @param {(any) => boolean} isId - The predicate for the globally unqiue id of the identifier.
* @param {string} identifierType - The unique name of the identifier.
* @param {any} isExtras - Predicates used to check the extra data of the identifier.
* @returns {(any) => boolean} A type predicate that checksi if an object is an instance of the {@link Identifier} type.
*/
<T extends Identifier<I, U, E>, I extends ConceptAs<Guid, string>, U extends string, E extends Extras>(type: Constructor<T>, isId: (object: any) => object is T['id'], identifierType: T['type'], isExtras: ExtraPredicates<T['__extras']>): (object: any) => object is T;
};
export declare const createIsIdentifier: CreateIsIdentifier;
export {};
//# sourceMappingURL=Identifier.d.ts.map