/** * Implementation of utility functions that help working with redux state. * * @packageDocumentation */ import { AccessorType } from '@acoustic-content-sdk/edit-api'; import { AuthoringAsset } from '@acoustic-content-sdk/api'; import { AuthoringContentItem } from '@acoustic-content-sdk/api'; import { AuthoringType } from '@acoustic-content-sdk/api'; import { BaseAuthoringItem } from '@acoustic-content-sdk/api'; import { BiFunction } from '@acoustic-content-sdk/utils'; import { ContentItem } from '@acoustic-content-sdk/api'; import { ELEMENT_TYPE } from '@acoustic-content-sdk/api'; import { Epic } from 'redux-observable'; import { EqualsPredicate } from '@acoustic-content-sdk/utils'; import { Generator } from '@acoustic-content-sdk/utils'; import { Logger } from '@acoustic-content-sdk/api'; import { LoggerService } from '@acoustic-content-sdk/api'; import { MonoTypeOperatorFunction } from 'rxjs'; import { Observable } from 'rxjs'; import { OperatorFunction } from 'rxjs'; import { RenderingContext } from '@acoustic-content-sdk/api'; import { SchedulerLike } from 'rxjs'; import { UnaryFunction } from 'rxjs'; import { User } from '@acoustic-content-sdk/api'; /** * Reducer function that adds an item to a record */ export declare type AddRecordReducer = BiFunction, T, Record>; /** * Constructs an epic that convers an `ADD` action to a `SET` action * * @param aAddAction - the add action string * @param aSetAction - the set action string * * @returns the epic */ export declare const addToSetEpic: (aAddAction: string, aSetAction: string) => Epic; export declare type AuthoringItem = AuthoringContentItem | AuthoringAsset; /** * Basically a re-export of the clone functionality to have it all clean inside this one function * * @param aItems - the original items * @returns the cloned items */ export declare const cloneAuthoringItems: UnaryFunction; /** * Constructs a breadcrumb trail starting at a particular ID * * @param aId - the start ID * @param aSelParent - selector function for the parent node * @param aSelId - selector function for the ID from a parent node * * @returns the breadcrumb trail */ export declare function createBreadcrumb(aId: string, aSelParent: UnaryFunction>, aSelId: UnaryFunction): Observable; /** * Constructs a function that updates one or more values in a json object. * * @param aValue - the JSON structure to update * * @returns updater functions */ export declare function createUpdater(aValue: T, aLogSvc?: LoggerService): Updater; export declare const DB_KEY = "ecec4405-7fb1-4b86-8d27-7338eea45683"; export declare const DB_VALUE = "e3257dbc-1ca8-4d57-94a2-37934960f39f"; /** * Makes sure to end the ID with a draft suffix * * @param aAuthoringId - the actual ID * @returns the ID with a draft suffix */ export declare const ensureDraftId: (aAuthoringId: string) => string; export declare function equalsByRevision(aLeft: ItemWithRevision, aRight: ItemWithRevision): boolean; /** * Returns the delivery ID from an authoring ID, i.e. strips off the ':draft' suffix from the ID * * @param authoringId - the authoring ID * @returns the resulting delivery ID */ export declare const getDeliveryId: UnaryFunction; /** * Returns the delivery ID from an authoring item. * * @param authoringItem - the authoring item * @returns the resulting delivery ID */ export declare const getDeliveryIdFromAuthoringItem: UnaryFunction; /** * Returns selectors that access parent and child nodes from a navigation structure * * @param aJson$ - the JSON that represents the navigation * @param aLogSvc - optional logger service * @returns the selectors */ export declare function getNavSelectors(aJson$: Observable, aLogSvc?: LoggerService): NavSelectors; /** * Retrieves a property value by accessor */ export declare const getValueByAccessor: (aItem: BaseAuthoringItem, aAccessor: string) => T; declare type IdOrItem = string | AuthoringContentItem; /** * Creates a function that validates that an object has not changed. Note * that this should only be used for debugging purposes, since it makes * a deep copy of the value to test for the invariance * * @param aValue - the value to test * * @returns the validator */ export declare function invarianceChecker(aValue: any): Generator; /** * Tests if the authoring ID has a draft suffix * * @param aAuthoringId - the ID * @returns true if we have a draft suffix, else false */ export declare function isDraftId(aAuthoringId: string): boolean; /** * Tests if a value is not from a database * * @param aValue - the value * @returns true if the value exists and if it is not from the database, else false */ export declare function isNotFromDataBase(aValue: any): boolean; export declare function isNotRoot(aId: string): boolean; /** * Reducer function that updates an item */ export declare type ItemReducer = BiFunction; export declare interface ItemWithId { id?: string; } export declare interface ItemWithLinkedDocId { readonly id?: string; readonly linkedDocId?: string; } export declare interface ItemWithRevision extends ItemWithId { rev?: string; } /** * Extract the delivery ID of the draft * * @param item - the item * @returns the delivery version of the ID */ export declare const keyById: UnaryFunction; /** * Adds a key to the item marking it as coming from the local data base * * @param aValue - the value to work with * @returns a value with the marker */ export declare function markAsFromDataBase(aValue: T): T; export declare interface NavigationJson { id: string; children?: NavigationJson[]; } /** * Interface that exposes selectors to the navigation structure */ export declare interface NavSelectors { /** * ID of the (virtual) root item of the navigation */ root: string; /** * Selects the children of a particular item */ selectChildren: UnaryFunction>; /** * Selects the parent of a particular item */ selectParent: UnaryFunction>; } export declare function removeArrayItemByAccessor(aAccessor: AccessorType, aItem: T, aUser?: User): Updater; /** * Removes the database marker from the object * * @param aValue - the value to work with * @returns a value without the marker */ export declare function removeDataBaseMarker(aValue: T): T; /** * Creates a reducer that removes a key from a record * * @returns the reducer */ export declare function removeRecord(): RemoveRecordReducer; /** * Reducer function that adds an item to a record */ export declare type RemoveRecordReducer = BiFunction, string, Record>; export declare type ResolutionResult = Record>; export declare type ResolveAuthoringAsset = UnaryFunction>; export declare type ResolveAuthoringContentItem = UnaryFunction>; export declare interface ResolvedNode { id: string; item: T; parentId?: string; } export declare const ROOT_ID: string; /** * Resolves the element type, either directly from the element or from the authoring type * * @param aAuthoringTypes$ - the set of available authoring types * @param aLogSvc - logger service * @param aScheduler - optional scheduler * * @returns the resolved type or undefined if the type could not be determined */ export declare function rxElementType(aTypeResolver: UnaryFunction>, aLogSvc?: LoggerService, aScheduler?: SchedulerLike): UnaryFunction>; export declare function rxLogDiff(aLogger: Logger): MonoTypeOperatorFunction; /** * Resolves the item and all referenced items and assets * * @param id - ID of the item to resolve * @param resolveItem - callback to resolve a content item * @param resolveAsset - callback to resolve an asset * @param logSvc - logger service * @param scheduler - scheduler for recursive calls * * @returns the observable containing the resolution result */ export declare function rxResolveAuthoringItems(idOrItem: IdOrItem, resolveItem: ResolveAuthoringContentItem, resolveAsset: ResolveAuthoringAsset, aLogSvc?: LoggerService, scheduler?: SchedulerLike): Observable; /** * Constructs a selector that validates that the ID is a delivery ID (not a draft ID) and selects * based on that ID from the state * * @param aId - the ID * @returns a selector for that ID based on some state */ export declare function selectByDeliveryId(aId?: string): UnaryFunction, T>; /** * Extracts the classification property */ export declare const selectClassification: UnaryFunction; /** * Serializes the differences between two JSON objects * * @param aOld - old object * @param aNew - new objects * @param aSameStyle - styling callback for identical style * @param aNewStyle - styling callback for new style * @param aDeletedStyle - styling callback for deleted style * * @returns the serialized string */ export declare function serializeDiff(aOld: any, aNew: any, aSameStyle?: UnaryFunction, aNewStyle?: UnaryFunction, aDeletedStyle?: UnaryFunction): string; /** * Performs a topological sort on a set of resolved items * * @param aResult - the resolution result, basically a graph of nodes * * @returns the items in toplogical order, i.e. parents before children */ export declare function sortAuthoringItems(aResult: ResolutionResult): AuthoringItem[]; /** * Updates properties of the item that depend on the environment * * @param aItem - updater for the item * @param aUser - optionally the current user * @returns the updater after the item has been modified */ export declare function updateGenericProperties(aItem: Updater, aUser?: User): Updater; export declare function updateImageElement(aAccessor: AccessorType, aItem: Updater, aAsset: AuthoringAsset): Updater; export declare const updateItemsWithRevision: (aState: Record, aItem: T) => Record; /** * Facade that offers the modification functions for a json object. * The original JSON object will not be modified and the modified * object will only contain the minimum number of modifications. */ export declare interface Updater { /** * Replaces the value pointed to by the accessor with a new value. * All values across the parent path will be cloned (shallow) if * they do not have a clone, yet. * * Pass `undefined` as the new value to delete the value. * * Returns the modified version of the top level object. */ set: BiFunction; /** * Removes the value pointed to by the accessor. * All values across the parent path will be cloned (shallow) if * they do not have a clone, yet. * * Returns the modified version of the top level object. */ del: UnaryFunction; /** * Inserts a new value into an array pointed to by the accessor. * All values across the parent path will be cloned (shallow) if * they do not have a clone, yet. * * Pass `undefined` as the new value to delete the value. * * Returns the modified version of the top level object. */ add: BiFunction; /** * Returns the top level, modified object */ get: Generator; } /** * Creates a reducer that adds an item to a record * * @param aKey - function to extract the key from the item * @param aPredicate - predicate to check if two items are equal * * @returns the reducer */ export declare function updateRecord(aKey: UnaryFunction, aPredicate?: EqualsPredicate): AddRecordReducer; export declare function updateSingleItem(aPredicate?: EqualsPredicate): ItemReducer; /** * Updates a single property based on the accessor expression. * * @param aAccessor - the accessor expression that points * @param aValue - the new value * @param aItem - the item to update * * @returns a copy of the item with the modified value */ export declare function updateValueByAccessor(aAccessor: AccessorType, aValue: any, aItem: T, aUser?: User): Updater; export { }