import { JwtConfig, LedgerHash, LedgerMeta, LedgerRecord, LedgerSigningParams } from "../../../../types/src"; import type { PartialDeep } from 'type-fest'; /** * 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 is a base class that contains generic * functionalities that can be reused for various * record types. * * 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 BaseRecordBuilder { /** * Auth params to use for the request to ledger. */ protected authParams: JwtConfig; /** * A ledger record that this instance is operating on. * * NOTE: this instance is going to be mutated. */ protected record: LedgerRecord; /** * Promise which represents completion all pending async operations. */ private pendingAsyncOperations?; /** * Enqueues async operation in builder as a function which is executed * when previous async operations are completed. * * @param operation async operation function */ protected enqueueAsyncOperation(operation: () => Promise): void; /** * Ensures that all async operations in builder are finished. * * @returns When all async operations in builder are finished */ protected finishAsyncOperations(): Promise; /** * Initializes the record. This function will completely * replace all existing record properties. * * @param record the record * @returns this builder instance for chaining */ init(record: Partial>): this; /** * Sets the record data. This function will merge the provided * values with any existing properties already present in the * record by calling `Object.assign`, i.e., the values aren't going * to be merged recursively, only the top level properties will * be merged. * * @see Object.assign * @param data the data properties to assign * @returns this builder instance for chaining */ data(data: PartialDeep): this; /** * Sets the record meta. This function will merge the provided * values with any existing properties already present in the * record by calling `Object.assign`, i.e., the values aren't going * to be merged recursively, only the top level properties will * be merged. * * @see Object.assign * @param meta the meta properties to assign * @returns this builder instance for chaining */ meta(meta: LedgerMeta): this; /** * Sets a hash to the current record, if the hash value is * provided. If the value is not provided or falsy calculates * a hash of the current version and stores the calculated * value in the `hash` property of the record. * * @param hash the hash to set, or a falsy value to calculate a new hash * @returns this builder instance for chaining */ hash(hash?: LedgerHash): this; /** * Sets authentication params to the current record. * These parameters are stored in memory until the function * `send()` is called, when it's used to compose the JWT * token sent to Ledger API. * * @param params the parameters to be assigned to the current auth params object * @returns this builder instance for chaining */ auth(params: Partial): this; /** * Signs the current value of the record's hash with * all of the provided key pairs and stores the generated * signatures in the `meta.proofs` property of the record. * * @param params signing params to use * @returns this builder instance for chaining */ sign(params: LedgerSigningParams[]): this; /** * Returns the current state of constructed record. * * NOTE: Reference is directly returned without any cloning, * be careful when continuing to use this builder after * calling this function. The internal record value could be * mutated by mutating the returned value. It is recommended * to clone the value in such cases. * * @returns the current state of constructed record */ read(): Promise>; }