import { JwtConfig, LedgerBaseData, LedgerHash, LedgerMeta, LedgerProof, LedgerProofCustom, LedgerRecord } from "../../../../types/src"; import { BaseRecordResponse } from '../types/base-record-response'; import { BaseRecordBuilder } from './base-record-builder'; import type { PartialDeep } from 'type-fest'; /** * A handler for updating records on the remote API. */ export type UpdateRecordHandler = (record: LedgerRecord, authParams: JwtConfig) => Promise; /** * A handler for adding proofs to records on the remote API. */ type AddProofHandler = (signature: LedgerProof, authParams: Partial) => Promise; /** * Links current hash to parent and removes hash. * * @param record record to modify */ export declare const linkToParent: (record: Partial>) => void; /** * Implements a builder pattern that allows a more * convenient way to work with ledger records. This * class has functions that simplify construction, * hashing, signing, testing and sending records to * remote ledger instances. * * This builder is intended for record updates, sending * a record to ledger will perform the update operation * on the API with the record that was prepared in the * builder. * * NOTE: current record instance is mutated by this * class, we are not cloning instances intentionally, * and it isn't advised to reuse builder instances when * working with multiple records or mutating objects * passed to this builder in external code. It is * recommended to clone objects in such cases to avoid * unexpected behaviors. */ export declare class UpdateRecordBuilder, M extends LedgerMeta = LedgerMeta> extends BaseRecordBuilder { /** * A handler for updating records on the remote API. */ protected updateRecord: UpdateRecordHandler; /** * A handler for adding proofs to records on the remote API. */ protected addProof: AddProofHandler; /** * Defines if the builder should update * the record or just add a proof */ protected isUpdate: boolean; /** * Parent hash */ protected parent: LedgerHash; /** * Creates new instance of record builder. * The target action - send - will change according * to isUpdate flag state. If isUpdate is true, the method * send() will call `updateRecord` function. Otherwise, * it will execute `addProof`. * * @param updateRecord function which updates records on ledger API. * @param addProof function which adds proofs to records on ledger API */ constructor(updateRecord: UpdateRecordHandler, addProof: AddProofHandler); /** * Initializes the record. This function will completely * replace all existing record properties when record * moment is parent. * * @param record the record * @returns this builder instance for chaining */ init(record: Partial>): this; /** * Sets the record data. This function will merge the input with * the existing record. If you want to completely replace the existing * data, pass the second argument as true. * You can pass null as the value of any property to remove it from * the record. * * @see Object.assign * @param data the data properties to assign * @param replace flag that indicates if the record data * i.e. `this.record.data` should be replaced(true) or * merged(false) * @returns this builder instance for chaining */ data(data: PartialDeep, replace?: boolean): this; /** * This function is used to remove the null and empty entries after * merging the data. Useful for removing properties that wouldn't be * saved on database from the record and generate a proper signature. * @param object Object to remove null entries from * @returns Object with null entries removed */ protected deepRemoveNull(object: any): any; /** * Sends the current record version to the remote ledger. * * @returns api response with the updated record * @throws if any method in builder chain fails */ send(): Promise; } export {};