import { CommitArguments, CommitResult } from "../chrono2/graph/Graph.js"; import { AnyConstructor } from "../class/Mixin.js"; import { EntityMeta } from "../schema2/EntityMeta.js"; import { Field, Name } from "../schema2/Field.js"; import { EntityAtom, FieldAtom, FieldCalculableBox } from "./Atom.js"; import { Replica } from "./Replica.js"; declare const Entity_base: Pick<{ new (...input: any[]): { __isEntityMarker(): void; /** * A reference to the graph, this entity belongs to. Initially empty, and is populated when the entity instance * is added to the replica ([[Replica.addEntity]]) */ graph: Replica; /** * An [[EntityMeta]] instance, representing the "meta" information about the entity class. It is shared among all instances * of the class. */ readonly $entity: EntityMeta; /** * An object, which properties corresponds to the ChronoGraph [[Identifier]]s, created for every field. * * For example: * * ```ts * class Author extends Entity.mix(Base) { * @field() * firstName : string * @field() * lastName : string * } * * const author = Author.new() * * // identifier for the field `firstName` * author.$.firstName * * const firstName = replica.read(author.$.firstName) * ``` */ readonly $: { __isEntityMarker: FieldCalculableBox; graph: FieldCalculableBox; readonly $entity: FieldCalculableBox; readonly $: FieldCalculableBox; readonly $$: FieldCalculableBox; readonly $entityName: FieldCalculableBox; createFieldAtom: FieldCalculableBox; forEachFieldAtom: FieldCalculableBox; enterGraph: FieldCalculableBox; leaveGraph: FieldCalculableBox; commit: FieldCalculableBox; commitAsync: FieldCalculableBox; run: FieldCalculableBox; }; /** * A graph identifier, that represents the whole entity. */ readonly $$: EntityAtom; readonly $entityName: string; createFieldAtom(field: Field): FieldAtom; forEachFieldAtom(func: (field: FieldAtom, name: string) => any): void; /** * This method is called when entity is added to some replica. * * @param replica */ enterGraph(replica: Replica): void; /** * This method is called when entity is removed from the replica it's been added to. */ leaveGraph(graph: Replica): void; /** * This is a convenience method, that just delegates to the [[ChronoGraph.commit]] method of this entity's graph. * * If there's no graph (entity has not been added to any replica) a [[CommitZero]] constant will be returned. */ commit(arg?: CommitArguments): CommitResult; /** * This is a convenience method, that just delegates to the [[ChronoGraph.commitAsync]] method of this entity's graph. * * If there's no graph (entity has not been added to any replica) a resolved promise with [[CommitZero]] constant will be returned. */ commitAsync(arg?: CommitArguments): Promise; run(methodName: keyof any, ...args: any[]): any; }; /** * An [[EntityMeta]] instance, representing the "meta" information about the entity class. It is shared among all instances * of the class. */ readonly $entity: EntityMeta; createPropertyAccessorsFor(field: Field): void; createMethodAccessorsFor(field: Field): void; }, "prototype" | "$entity" | "createPropertyAccessorsFor" | "createMethodAccessorsFor"> & (new (...args: any[]) => { __isEntityMarker(): void; /** * A reference to the graph, this entity belongs to. Initially empty, and is populated when the entity instance * is added to the replica ([[Replica.addEntity]]) */ graph: Replica; /** * An [[EntityMeta]] instance, representing the "meta" information about the entity class. It is shared among all instances * of the class. */ readonly $entity: EntityMeta; /** * An object, which properties corresponds to the ChronoGraph [[Identifier]]s, created for every field. * * For example: * * ```ts * class Author extends Entity.mix(Base) { * @field() * firstName : string * @field() * lastName : string * } * * const author = Author.new() * * // identifier for the field `firstName` * author.$.firstName * * const firstName = replica.read(author.$.firstName) * ``` */ readonly $: { __isEntityMarker: FieldCalculableBox; graph: FieldCalculableBox; readonly $entity: FieldCalculableBox; readonly $: FieldCalculableBox; readonly $$: FieldCalculableBox; readonly $entityName: FieldCalculableBox; createFieldAtom: FieldCalculableBox; forEachFieldAtom: FieldCalculableBox; enterGraph: FieldCalculableBox; leaveGraph: FieldCalculableBox; commit: FieldCalculableBox; commitAsync: FieldCalculableBox; run: FieldCalculableBox; }; /** * A graph identifier, that represents the whole entity. */ readonly $$: EntityAtom; readonly $entityName: string; createFieldAtom(field: Field): FieldAtom; forEachFieldAtom(func: (field: FieldAtom, name: string) => any): void; /** * This method is called when entity is added to some replica. * * @param replica */ enterGraph(replica: Replica): void; /** * This method is called when entity is removed from the replica it's been added to. */ leaveGraph(graph: Replica): void; /** * This is a convenience method, that just delegates to the [[ChronoGraph.commit]] method of this entity's graph. * * If there's no graph (entity has not been added to any replica) a [[CommitZero]] constant will be returned. */ commit(arg?: CommitArguments): CommitResult; /** * This is a convenience method, that just delegates to the [[ChronoGraph.commitAsync]] method of this entity's graph. * * If there's no graph (entity has not been added to any replica) a resolved promise with [[CommitZero]] constant will be returned. */ commitAsync(arg?: CommitArguments): Promise; run(methodName: keyof any, ...args: any[]): any; }) & import("typescript-mixin-class/src/class/Mixin").StaticPartOfMixinConstructor<{ new (...input: any[]): { __isEntityMarker(): void; /** * A reference to the graph, this entity belongs to. Initially empty, and is populated when the entity instance * is added to the replica ([[Replica.addEntity]]) */ graph: Replica; /** * An [[EntityMeta]] instance, representing the "meta" information about the entity class. It is shared among all instances * of the class. */ readonly $entity: EntityMeta; /** * An object, which properties corresponds to the ChronoGraph [[Identifier]]s, created for every field. * * For example: * * ```ts * class Author extends Entity.mix(Base) { * @field() * firstName : string * @field() * lastName : string * } * * const author = Author.new() * * // identifier for the field `firstName` * author.$.firstName * * const firstName = replica.read(author.$.firstName) * ``` */ readonly $: { __isEntityMarker: FieldCalculableBox; graph: FieldCalculableBox; readonly $entity: FieldCalculableBox; readonly $: FieldCalculableBox; readonly $$: FieldCalculableBox; readonly $entityName: FieldCalculableBox; createFieldAtom: FieldCalculableBox; forEachFieldAtom: FieldCalculableBox; enterGraph: FieldCalculableBox; leaveGraph: FieldCalculableBox; commit: FieldCalculableBox; commitAsync: FieldCalculableBox; run: FieldCalculableBox; }; /** * A graph identifier, that represents the whole entity. */ readonly $$: EntityAtom; readonly $entityName: string; createFieldAtom(field: Field): FieldAtom; forEachFieldAtom(func: (field: FieldAtom, name: string) => any): void; /** * This method is called when entity is added to some replica. * * @param replica */ enterGraph(replica: Replica): void; /** * This method is called when entity is removed from the replica it's been added to. */ leaveGraph(graph: Replica): void; /** * This is a convenience method, that just delegates to the [[ChronoGraph.commit]] method of this entity's graph. * * If there's no graph (entity has not been added to any replica) a [[CommitZero]] constant will be returned. */ commit(arg?: CommitArguments): CommitResult; /** * This is a convenience method, that just delegates to the [[ChronoGraph.commitAsync]] method of this entity's graph. * * If there's no graph (entity has not been added to any replica) a resolved promise with [[CommitZero]] constant will be returned. */ commitAsync(arg?: CommitArguments): Promise; run(methodName: keyof any, ...args: any[]): any; }; /** * An [[EntityMeta]] instance, representing the "meta" information about the entity class. It is shared among all instances * of the class. */ readonly $entity: EntityMeta; createPropertyAccessorsFor(field: Field): void; createMethodAccessorsFor(field: Field): void; }, (base: AnyConstructor) => { new (...input: any[]): { __isEntityMarker(): void; /** * A reference to the graph, this entity belongs to. Initially empty, and is populated when the entity instance * is added to the replica ([[Replica.addEntity]]) */ graph: Replica; /** * An [[EntityMeta]] instance, representing the "meta" information about the entity class. It is shared among all instances * of the class. */ readonly $entity: EntityMeta; /** * An object, which properties corresponds to the ChronoGraph [[Identifier]]s, created for every field. * * For example: * * ```ts * class Author extends Entity.mix(Base) { * @field() * firstName : string * @field() * lastName : string * } * * const author = Author.new() * * // identifier for the field `firstName` * author.$.firstName * * const firstName = replica.read(author.$.firstName) * ``` */ readonly $: { __isEntityMarker: FieldCalculableBox; graph: FieldCalculableBox; readonly $entity: FieldCalculableBox; readonly $: FieldCalculableBox; readonly $$: FieldCalculableBox; readonly $entityName: FieldCalculableBox; createFieldAtom: FieldCalculableBox; forEachFieldAtom: FieldCalculableBox; enterGraph: FieldCalculableBox; leaveGraph: FieldCalculableBox; commit: FieldCalculableBox; commitAsync: FieldCalculableBox; run: FieldCalculableBox; }; /** * A graph identifier, that represents the whole entity. */ readonly $$: EntityAtom; readonly $entityName: string; createFieldAtom(field: Field): FieldAtom; forEachFieldAtom(func: (field: FieldAtom, name: string) => any): void; /** * This method is called when entity is added to some replica. * * @param replica */ enterGraph(replica: Replica): void; /** * This method is called when entity is removed from the replica it's been added to. */ leaveGraph(graph: Replica): void; /** * This is a convenience method, that just delegates to the [[ChronoGraph.commit]] method of this entity's graph. * * If there's no graph (entity has not been added to any replica) a [[CommitZero]] constant will be returned. */ commit(arg?: CommitArguments): CommitResult; /** * This is a convenience method, that just delegates to the [[ChronoGraph.commitAsync]] method of this entity's graph. * * If there's no graph (entity has not been added to any replica) a resolved promise with [[CommitZero]] constant will be returned. */ commitAsync(arg?: CommitArguments): Promise; run(methodName: keyof any, ...args: any[]): any; }; /** * An [[EntityMeta]] instance, representing the "meta" information about the entity class. It is shared among all instances * of the class. */ readonly $entity: EntityMeta; createPropertyAccessorsFor(field: Field): void; createMethodAccessorsFor(field: Field): void; }>; /** * Entity [[Mixin|mixin]]. When applied to some base class (recommended one is [[Base]]), turns it into entity. * Entity may have several fields, which are properties decorated with [[field]] decorator. * * To apply this mixin use the `Entity.mix` property, which represents the mixin lambda. * * Another decorator, [[calculate]], marks the method, that will be used to calculate the value of field. * * Example: * * ```ts * class Author extends Entity.mix(Base) { * @field() * firstName : string * @field() * lastName : string * @field() * fullName : string * * @calculate('fullName') * calculateFullName () : string { * return this.firstName + ' ' + this.lastName * } * } * ``` * */ export declare class Entity extends Entity_base { } export declare type EntityConstructor = typeof Entity; export declare const createEntityOnPrototype: (proto: any) => EntityMeta; export declare const ensureEntityOnPrototype: (proto: any) => EntityMeta; export declare type FieldDecorator = (fieldConfig?: Partial>, fieldCls?: T | Default) => PropertyDecorator; export declare const generic_field: FieldDecorator; /** * Field decorator. The type signature is: * * ```ts * field : (fieldConfig? : Partial>, fieldCls : T | typeof Field = Field) => PropertyDecorator * ``` * Its a function, that accepts field config object and optionally a field class (default is [[Field]]) and returns a property decorator. * * Example: * * ```ts * const ignoreCaseCompare = (a : string, b : string) : boolean => a.toUpperCase() === b.toUpperCase() * * class MyField extends Field {} * * class Author extends Entity.mix(Base) { * @field({ equality : ignoreCaseCompare }) * firstName : string * * @field({ lazy : true }, MyField) * lastName : string * } * ``` * * For every field, there are generated get and set accessors, with which you can read/write the data: * * ```ts * const author = Author.new({ firstName : 'Mark' }) * * author.firstName // Mark * author.lastName = 'Twain' * ``` * * The getters are basically using [[Replica.get]] and setters [[Replica.write]]. * * Note, that if the identifier is asynchronous, reading from it will return a promise. But, immediately after the [[Replica.commit]] call, getter will return * plain value. This is a compromise between the convenience and correctness and this behavior may change (or made configurable) in the future. * * Additionally to the accessors, the getter and setter methods are generated. The getter method's name is formed as `get` followed by the field name * with upper-cased first letter. The setter's name is formed in the same way, with `set` prefix. * * The getter method is an exact equivalent of the get accessor. The setter method, in addition to data write, immediately after that * performs a call to [[Replica.commit]] (or [[Replica.commitAsync]], depending from the [[Replica.autoCommitMode]] option) * and return its result. * * ```ts * const author = Author.new({ firstName : 'Mark' }) * * author.getFirstName() // Mark * await author.setLastName('Twain') // issues asynchronous commit * ``` */ export declare const field: typeof generic_field; /** * Decorator for the method, that calculates a value of some field * * ```ts * * @entity() * class Author extends Entity.mix(Base) { * @field() * firstName : string * @field() * lastName : string * @field() * fullName : string * * @calculate('fullName') * calculateFullName () : string { * return this.firstName + ' ' + this.lastName * } * } * ``` * * @param fieldName The name of the field the decorated method should be "tied" to. */ export declare type KeyOfIfNotEntity = Entity extends Cls ? Name : keyof Cls; export declare const calculate: (fieldName: KeyOfIfNotEntity) => MethodDecorator; export declare const write: (fieldName: KeyOfIfNotEntity) => MethodDecorator; export declare const calculate_etalon: (fieldName: KeyOfIfNotEntity) => MethodDecorator; export {};