import { DyFM_AnyError, DyFM_BasicProperty_Type, DyFM_DataModel_Params, DyFM_DBFilter, DyFM_DSSort, DyFM_Error_Settings, DyFM_Metadata, DyFM_RangeValue, DyFM_SearchQuery, DyFM_SearchResult, DyFM_SpecialSearch } from '@futdevpro/fsm-dynamo'; import { DyNTS_CompareData_Options } from '../../_models/interfaces/compare-data-options.interface'; import { DyNTS_CompareData_Result } from '../../_models/interfaces/compare-data-result.interface'; import { DyNTS_DBQueryOptions } from '../../_models/interfaces/db-query-options.interface'; import { DyNTS_DBUpdate } from '../../_models/types/db-update.type'; import { DyNTS_ArchiveDataService } from './archive-data.service'; import { DyNTS_DBService } from './db.service'; /** * Basic Data Service that is connected to the relevant DBServices * * @example * export class UserMatchStatisticsService extends DyNTS_DataService { * constructor( * set: { * data?: UserMatchStatistics, * issuer: string, * } * ) { * super( * new UserMatchStatistics(set?.data), * userMatchStatisticsModelParams * ); * this.issuer = set.issuer; * } * } */ export declare class DyNTS_DataService { /** * Initial data, this will be used by functions on default * @deprecated */ data: T; /** * DB data prams will be used to connect to usable dbService on GlobalService */ dataParams: DyFM_DataModel_Params; /** * Initial set for issuer to be able to follow the issuer's activity */ issuer: string; serviceName: string; serviceNameShortCode: string; /** error code base */ ecBase: string; /** * FR-258 / SR-3 — over-fetch küszöb. Ennél több dokumentumot visszaadó {@link findDataList} hívás * az unbounded-growth → GC-thrash/OOM vektor (2026-06-23 incidens): a teljes (akár több-100k-s) * collection a heap-be töltődik. NEM capeljük a query-t (az törné a hívókat) — csak WARNINGot * logolunk, hogy az over-fetch LÁTHATÓ legyen és paginálható/szűkíthető. Runtime felülírható * (`DyNTS_DataService.findDataListWarnThreshold = N`). Default: 10000. */ static findDataListWarnThreshold: number; dataDBService: DyNTS_DBService; haveArchiveDataService: boolean; /** @deprecated */ dataList: T[]; readonly depSettings: { key: string; dbServiceKey: string; keyIsUnique: boolean; keyIsRequired: boolean; }[]; private depDataDBService; readonly defaultErrorUserMsg: string; readonly defaultValidationErrorUserMsg: string; constructor( /** * Initial data, this will be used by functions on default * @deprecated */ data: T, /** * DB data prams will be used to connect to usable dbService on GlobalService */ dataParams: DyFM_DataModel_Params, /** * Initial set for issuer to be able to follow the issuer's activity */ issuer: string); getArchiveDataService(): DyNTS_ArchiveDataService; /** * returns all data from database to service dataList */ getAll(dontSetToService?: boolean): Promise; /** * @description * returns data from database by id * also if dontSetToService is false or not setted, * the data will be saved to the service, even if its not found * * if the data is not found, it will try to find it from the archive * unless skipArchiveLoad is set to true * * @remarks * If you need to get-save a data, if possible, * use db-service update instead. * * @param {string} id * (using id from service.data, if not provided) * @param dontSetToService * * @return {T} data: T */ getDataById(id?: string, dontSetToService?: boolean, skipArchiveLoad?: boolean): Promise; getDataByIds(ids: string[], dontSetToService?: boolean): Promise; getDataListByIds(ids: string[], dontSetToService?: boolean): Promise; private getDependencyIdsFilter; /** * returns data from database by dependencyId to the service * (using id from service.data, if not provided) * @param dependencyIds */ getDataByDependencyId(dependencyIds?: string | { [key: string]: string; }, dontSetToService?: boolean): Promise; getDataListByDependencyIds(dependencyIds: string[], dontSetToService?: boolean, dependencyKey?: string): Promise; /** * returns dataList from database by dependencyId to the service * @param dependencyIds */ getDataListByDependencyId(dependencyIds?: string | { [key: string]: string; }, dontSetToService?: boolean): Promise; /** * * // findOne desc: * * Find the data first by any of its parameters, * also if dontSetToService is false or not setted, * the data will be saved to the service, even if non found * * @param filter if you can, use unique parameters for find! * * @example * // by email: * { email: email } * // * @example * // or by id that is in list: * { userIds: { $in: this.userId } } * // or by userIds: * { userId: { $in: userIds } } * // * @example * // or by number or Date that is Greater Than AND Less Than: * { points: { $gt: 2, $lt: 14 } } * // further tools (syntax matches with $gt): * $eq: // Matches values that are EQual to a specified value. * $gte: // Matches values that are Greater Than OR Equal to a specified value. * $lte: // Matches values that are Less Than or Equal to a specified value. * $ne: // Matches all values that are Not Equal to a specified value. * $nin: // Matches None of the values specified IN an array. * // * @returns {T} data: T */ findData(filterBy: DyFM_DBFilter, dontSetToService?: boolean): Promise; getDataByQuery: typeof this.findData; /** * * // find desc: * * Find the data first by any of its parameters, * also if dontSetToService is false or not setted, * the data will be saved to the service, even if non found * * @param filter if you can, use unique parameters for find! * * @example * // by email: * { email: email } * // * @example * // or by id that is in list: * { userIds: { $in: this.userId } } * // or by userIds: * { userId: { $in: userIds } } * // * @example * // or by number or Date that is Greater Than AND Less Than: * { points: { $gt: 2, $lt: 14 } } * // further tools (syntax matches with $gt): * $eq: // Matches values that are EQual to a specified value. * $gte: // Matches values that are Greater Than OR Equal to a specified value. * $lte: // Matches values that are Less Than or Equal to a specified value. * $ne: // Matches all values that are Not Equal to a specified value. * $nin: // Matches None of the values specified IN an array. * // * @param options BFR-008: opcionalis projection/limit/sort — DB-szinten szukit (a nagy mezok be sem toltodnek) * @returns {T[]} dataList: T[] */ findDataList(filterBy: DyFM_DBFilter, dontSetToService?: boolean, options?: DyNTS_DBQueryOptions): Promise; /** * This function uses the dataDBService.updateOne function. * This uses updateBy if setted, or data._id if its setted or this.data[this.dependencyKey] * @param set * * // updateOne desc: * * Find the data first by any of its parameters, throws error if not found * @param filter This uses the basic Mongoose updateOne. * If you can, use unique parameters for find! * @example * // by email: * { email: email } * // * @example * // or by id that is in list: * { userIds: { $in: this.userId } } * // or by userIds: * { userId: { $in: userIds } } * // * @example * // or by number or Date that is Greater Than AND Less Than: * { points: { $gt: 2, $lt: 14 } } * // further tools (syntax matches with $gt): * $eq: // Matches values that are EQual to a specified value. * $gte: // Matches values that are Greater Than OR Equal to a specified value. * $lte: // Matches values that are Less Than or Equal to a specified value. * $ne: // Matches all values that are Not Equal to a specified value. * $nin: // Matches None of the values specified IN an array. * // * * @param update this uses the basic Mongoose updateOne * @example * // increase a specific value (here by 15): * { $inc: { popularity: 15 } } * // * @example * // or add element to a list: * { $push: { reactions: this.newReaction } * // or add multiple elements to a list * { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } } * // * @example * // or all at once * { * $inc: { popularity: this.newVote.amount }, * emailVerified: true, * $push: { reactions: this.newReaction } * } * // further tools (syntax matches with $inc): * $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp. * $min: // Only updates the field if the specified value is less than the existing field value. * $max: // Only updates the field if the specified value is greater than the existing field value. * $mul: // Multiplies the value of the field by the specified amount. * $rename: // Renames a field. * $unset: // Removes the specified field from a document. (set: "" to value) * // */ updateData(set: { filterBy?: DyFM_DBFilter; update: DyNTS_DBUpdate; }, dontUpdateModified?: boolean): Promise; protected ensureData(data?: T): T; patchData(data?: Partial): Promise; /** * modifies data if the data have ID and already exists in the DB, * creates new if the ID is not present or cant find in DB, * and if dependency data setted up, will check before creation, * * @warning * but the proper way to update data, if you use update method instead, * this way, you can avoid data override errors * (when you simultaneously trying to change the same data's * different values from different flows) */ saveData(data?: T, dontSetToService?: boolean, dontUpdateModified?: boolean): Promise; /** * markes data as deleted, if can be archived, will be archived as well * if absolute is true, permanently deletes data from database by data._id */ deleteData(id?: string, absolute?: boolean): Promise; deleteAllData(absolute?: boolean): Promise; restoreDeletedData(id?: string): Promise; /** * validation of data, for modify and create, by the ModelParams */ validateForSave(data?: T): Promise; private validateDataByPropertyParams; private getPropertyKey; private validateProperty; /** * Search the data list based on the search query * Sorts and filters the data list based on the search query * * NOTE: For more simple and with better performance and if you don't need sorting, use findDataList instead. * * @example * ```ts * const searchResult = await this.searchData({ * filterBy: { * name: 'John Doe', * }, * sortBy: [ * { key: 'name', order: 1 }, * ], * }); * ``` */ searchData(query?: DyFM_SearchQuery, dataList?: T[]): Promise>; sortAndFilterDataList(query: DyFM_SearchQuery, dataList?: T[]): Promise>; protected getFilterFunctionForKey(key: string, searchValue: T | T[] | DyFM_RangeValue | DyFM_SpecialSearch, propertyType?: DyFM_BasicProperty_Type): (dataProperty: any) => boolean; /** * Get the value of a nested key. * @param nestKeys - The nested keys to resolve. * @returns The value of the nested key. */ private getKeyResolver; /** * Get the sort function for a key. * @param sortSettings - The sort settings. * @returns The sort function for the key. */ protected getSortFunctionForKey(sortSettings: DyFM_DSSort): (a: T, b: T) => number; /** * setting up dependency dataHook by DynamoNTSDataModelParams */ private lookForDependencyDataSettings; /** * * @returns */ getDependencyDataDBService(dBServiceKey?: string): DyNTS_DBService; getProvidedData(data: T): T; getProvidedDataList(dataList: T[]): T[]; private _getDefaultErrorSettings; protected getDefaultErrorSettings(fnName: string, error: DyFM_AnyError, /** @deprecated we wont support the separate user message in the future, use the message instead */ useMessageAsUserMessage?: boolean): DyFM_Error_Settings; /** * Generic, field-szintu osszehasonlitas ket adat-objektum kozott. * * **Auto-discovery mod** (`options.fields` nelkul): a metodus mindket * objektum kulcs-uniojan iter, KIVEVE a `DyFM_Metadata` skip-listet * (`_id`, `__created`, `__createdBy`, `__lastModified`, `__lastModifiedBy`). * * **Scope-szukito mod** (`options.fields = [...]`): KIZAROLAG a felsorolt * mezoket vizsgalja. A skip-list IGNORALODIK — explicit fields override. * * **Custom comparator** (`options.customComparators`): per-field override * a default deep-equal helyett (pl. set-equality array-ekre, * case-insensitive string compare-re). A custom function `true`-val signal-ozza * az equality-t. * * **Return:** `'equal'` ha minden vizsgalt field egyezik; `'modified'` ha * legalabb egy elter — ilyenkor `changedFields` tartalmazza a TELJES * mismatch-listat (nem early-return). * * **Throws:** * - `newData` vagy `oldData` null/undefined → `DyFM_Error(400, DyNTS-DS0-CD1)` * - `options.fields = []` ures array → `DyFM_Error(400, DyNTS-DS0-CD2)` * * **Sync method** (nincs I/O szukseglet); a host wrappel-i ha async kell. * * @example * const result = userService.compareData(newUser, oldUser); * if (result.result === 'modified') { * console.log('Changed:', result.changedFields); * } * * @example // Scope-szukites + custom comparator * userService.compareData(newUser, oldUser, { * fields: ['email', 'roles'], * customComparators: { * roles: (a, b) => new Set(a).size === new Set([...a, ...b]).size, * }, * }); */ compareData(newData: T, oldData: T, options?: DyNTS_CompareData_Options): DyNTS_CompareData_Result; /** * Eldonti az osszehasonlitando fields-listat: * - explicit `options.fields` esetan annak masolata (skip-list ignoralt) * - egyebkent `Object.keys(newData) UNION Object.keys(oldData)` minus skip-list */ private _resolveCompareFields; /** * Deep-equal helper. * * - Primitive (`string`/`number`/`boolean`/`null`/`undefined`): `===` / `Object.is` * (a `NaN === NaN` esetet `Object.is` kezeli helyesen) * - `Date`: `.getTime()` egyenloseg (kulonbozo Date instance-ok same-time-mal egyenlonek) * - Array: length + index-szerinti rekurziv deep-equal * - POJO: keys-union + per-key rekurzio * - Egyeb (RegExp / Map / Set / Buffer): `Object.is` fallback (reference compare) * * NEM kezelt: cyclic references — a hivo objektum-grafja flat / fa kell legyen * (a tipikus FDP data-model esete; cycle eseten stack overflow lesz, ami ertelmes * jelzes a programozonak). */ private _deepEqual; } //# sourceMappingURL=data.service.d.ts.map