/** * Service types for @siesa/master-pattern-view * * These types define the service contract between the MasterPatternView * component and external backends. The service is the ONLY communication * channel between the component and data sources. * * @module service.types * @see FR-004 — MasterPatternViewService contract */ /** * Base entity constraint for MasterPatternView. * All entities used with this component must satisfy this shape. * Consumers extend this with their domain-specific fields. * * @see FR-001 — Base entity requirements * * @param id - UUID v7 identifier * @param code - Unique business code * @param isActive - Whether the entity is active * @param version - Optimistic concurrency token (maps to PostgreSQL xmin) * @param isAssigned - **GLOBAL only.** Backend must set this flag on every * record returned by `getAll` when called with a `companyId`. It is the * source of truth for: * - the "Ver → Compañía" filter (shows only records with `isAssigned === true`), * - the AssignmentBadge rendered in the first list column, * - the row-disabled state in GLOBAL + company context. * If the backend omits this flag, the filter returns an empty list and the * badge never draws — a silent failure. Not required for UNIVERSAL or * COMPANY_SPECIFIC types. * * @example * ```typescript * interface Currency extends MasterPatternViewEntity { * symbol: string; * decimalPlaces: number; * } * ``` */ export type MasterPatternViewEntity = { id: string; code: string; isActive: boolean; version?: number; isAssigned?: boolean; [key: string]: unknown; }; /** * Parameters for the getAll service method. * Supports pagination, search, sorting, and filtering. * * @see FR-005 — Search, sort, and filter params * * @param page - Page number (1-based) * @param pageSize - Number of records per page * @param search - Global search string * @param sortBy - Field name to sort by * @param sortOrder - Sort direction * @param filters - Key-value filter pairs * @param companyId - Company context filter (GLOBAL/COMPANY_SPECIFIC) */ export interface MasterPatternViewGetAllParams { page?: number; pageSize?: number; search?: string; sortBy?: string; sortOrder?: 'asc' | 'desc'; filters?: Record; companyId?: string; } /** * Structured filter value passed to service.getAll(). * Carries both the raw value and the operator chosen in the filter panel. * * @param value - The filter value entered by the user * @param operator - "contains" | "starts_with" | "equals" | "not_equals" */ export interface MasterPatternViewFilterValue { value: unknown; operator: string; } /** * Paged response from the getAll service method. * * @see FR-005 — Pagination response shape * * @param data - Array of entities for the current page * @param total - Total number of records matching the query * @param page - Current page number * @param pageSize - Number of records per page */ export interface MasterPatternViewPagedResponse { data: T[]; total: number; page: number; pageSize: number; } /** * Tree node for hierarchical master views. * * @see FR-011 — Hierarchical tree architecture * * @param data - The entity data at this node * @param children - Child nodes * @param depth - Depth level in the tree (0 = root) * @param hasChildren - Whether this node has children (for lazy loading) */ export interface MasterPatternViewTreeNode { data: T; children: MasterPatternViewTreeNode[]; depth: number; hasChildren: boolean; } /** * Import error detail for the import service method. * * @see FR-012 — Import/Export * * @param row - Row number in the import file * @param field - Field name where the error occurred * @param message - Human-readable error message * @param value - The invalid value that caused the error */ export interface MasterPatternViewImportError { row: number; field: string; message: string; value?: unknown; } /** * Company reference used for GLOBAL and COMPANY_SPECIFIC types. * * @see FR-008 — Company context * * @param id - Company UUID * @param code - Company business code * @param name - Company display name */ export interface MasterPatternViewCompany { id: string; code: string; name: string; } /** * Service contract for MasterPatternView. * This is the ONLY communication channel between the component and external systems. * The component is backend-agnostic — it delegates all data operations to this interface. * * @see FR-004 — Service contract definition * * Required methods (all MasterTypes): getAll, create, update, delete * Optional methods: getById, changeStatus, getOverrides, saveOverride, * companyEnable, uncompanyEnable, getChildren, getTree, moveNode, export, import * * @example * ```typescript * const currencyService: MasterPatternViewService = { * getAll: (params) => api.get('/currencies', { params }), * create: (data) => api.post('/currencies', data), * update: (id, data) => api.put(`/currencies/${id}`, data), * delete: (id) => api.delete(`/currencies/${id}`), * }; * ``` */ export interface MasterPatternViewService { /** Fetch paginated list of entities */ getAll: (params: MasterPatternViewGetAllParams) => Promise>; /** Fetch a single entity by ID */ getById?: (id: string, companyId?: string) => Promise; /** Create a new entity */ create: (data: Partial, companyId?: string) => Promise; /** Update an existing entity. * @param revertedFields When in company context (GLOBAL type), the list of field names * the user explicitly reverted to global. These fields will be set to NULL on the * backend override row so they inherit the global value again. */ update: (id: string, data: Partial, companyId?: string, revertedFields?: string[]) => Promise; /** Delete an entity */ delete?: (id: string, companyId?: string) => Promise; /** Change the active status of an entity */ changeStatus?: (id: string, isActive: boolean, companyId?: string) => Promise; /** Fetch company-specific overrides for a GLOBAL entity */ getOverrides?: (id: string, companyId: string) => Promise | null>; /** Save company-specific overrides for a GLOBAL entity */ saveOverride?: (id: string, companyId: string, overrides: Record) => Promise; /** Return the list of company IDs that have been enabled for a GLOBAL entity */ getAssignedCompanyIds?: (id: string) => Promise; /** Enable a company for a GLOBAL entity */ companyEnable?: (id: string, companyId: string, initialValues?: Record) => Promise; /** Disable a company for a GLOBAL entity */ uncompanyEnable?: (id: string, companyId: string) => Promise; /** Fetch child entities for a hierarchical master */ getChildren?: (parentId: string | null, companyId?: string) => Promise; /** Fetch the full tree for a hierarchical master */ getTree?: (rootId: string | null, maxDepth?: number, companyId?: string) => Promise>; /** Move a node in the hierarchy */ moveNode?: (id: string, newParentId: string | null, companyId?: string) => Promise; /** Export entities as a file (Blob) */ export?: (params: MasterPatternViewGetAllParams) => Promise; /** Import entities from a file */ import?: (file: File) => Promise<{ success: number; errors: MasterPatternViewImportError[]; }>; } /** * A single row returned / sent by ConfigTableService. * `rowId` is the stable identifier for the row (usually the source entity's id). * `data` carries the full row payload. * `isDirty` is set by the component when the row has unsaved changes. */ export interface ConfigSaveRow { rowId: string; data: TRow; isDirty?: boolean; } /** * Response shape for `ConfigTableService.getConfigData`. * `rows` — all rows to display (source rows merged with existing assignments). * `globalRows` — base global rows; populated when called with `companyId` and * `companyBehavior: 'GLOBAL'` so the component can show global-value hints. */ export interface ConfigTableData { rows: TRow[]; globalRows?: TRow[]; } /** * Service contract for CONFIG_TABLE master type. * Replaces `MasterPatternViewService` when `definition.type === 'CONFIG_TABLE'`. * * Required: `getConfigData`, `saveConfig`. * Optional GLOBAL-behavior methods activate company-linking UI in the toolbar. * * @example * ```typescript * const ertdcService: ConfigTableService = { * getConfigData: (companyId) => loadDocClassesWithAssignments(companyId), * saveConfig: (rows, companyId) => bulkUpsert(rows, companyId), * getLinkedCompanies: () => api.get('/exchange-rate-types-by-document-class/linked-companies'), * }; * ``` */ export interface ConfigTableService { /** * Load all rows to display. * For GLOBAL companyBehavior: called twice when "Mostrar datos globales" is enabled — * once with `companyId` (company values) and once without (global hints). */ getConfigData: (companyId?: string) => Promise>; /** * Persist changed rows. * Receives only rows with `isDirty: true` to avoid unnecessary backend calls. */ saveConfig: (rows: ConfigSaveRow[], companyId?: string) => Promise; /** Return the list of company IDs that are linked to this config. */ getLinkedCompanies?: () => Promise; /** * Link a company: create override rows so the company inherits the global config. * `existingRows` contains the current global rows for convenience. */ linkCompany?: (companyId: string, existingRows: TRow[]) => Promise; /** Unlink a company: delete all override rows for that company. */ unlinkCompany?: (companyId: string) => Promise; /** * Bulk link/unlink multiple companies in one operation. * Used by the "Vincular compañías" modal. */ updateCompanyLinks?: (toLink: string[], toUnlink: string[], existingRows: TRow[]) => Promise; } //# sourceMappingURL=service.types.d.ts.map