/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import { Utils } from "@fluid-experimental/property-changeset"; import { BaseProperty, PropertyTemplate } from "@fluid-experimental/property-properties"; import { DataBinding, PropertyElement } from "../index.js"; import { DataBinderHandle } from "../internal/dataBinderHandle.js"; import { DataBindingTree, NodeType } from "./dataBindingTree.js"; import { ModificationContext } from "./modificationContext.js"; export type RecursiveCallback = (in_propertyElement: PropertyElement, in_path: string, in_tokenizedPath: (string | number)[], in_dataBindingTreeNode: NodeType) => boolean; /** * Escapes a path so that it can safely be stored in a nested map, freeing the * __ namespace for use by the caller * * @param in_path - A path (or path segment) to escape for storage in a nested map * @returns the tokenized result * * @package * @hidden */ declare const escapeTokenizedPathForMap: (in_path: string | string[]) => string | string[]; /** * Unescapes a string that has been escaped by escapeTokenizedPathForMap * * @param in_string - The input string * @returns the unescaped string * * @package * @hidden */ declare const unescapeTokenizedStringForMap: (in_string: string) => string; /** * Concatenates two paths. * * This function will join two paths and handles the cases where either in_path1 or in_path2 is empty or undefined. * It also handles the case when one of the two paths starts/ends with an array dereference. It currently * does not handle the case where in_path2 starts with '../' correctly. * TODO: This should be converted into a general utility function that also * handles these cases and be included in path_helper.js. * * @param in_path1 - The first path * @param in_path2 - The second path * @private * @hidden * * @returns The concatenated path */ declare const joinPaths: (in_path1: string | undefined, in_path2: string | undefined) => string | undefined; /** * Initializes the contents of a ReferencePropertyTableNode object to default (empty) values. * * @param io_referencePropertyTableNode - the ReferencePropertyTableNode object to initialize * @private * @hidden */ declare const initializeReferencePropertyTableNode: (io_referencePropertyTableNode: any) => void; /** * @hidden */ declare const validOperations: string[]; /** * @param operation - Operation name to validate * @private * @hidden */ declare const assertOperation: (operation: string) => void; /** * Invoke the callbacks. * * @param in_dataBinding - the databinding for which we are invoking, if present * @param in_baseModificationContext - a context * @param in_calledForReference - is this called for a reference * @param in_tokenizedFullPath - tokenized path ... to where? * @param in_visitIndex - single-context callbacks will not be called if they've already been * called in this visit. * @param in_traversalContext - the traversal context of the current changeset * @param in_registeredHandlers - the handlers that are registered. * @param in_tokenizedPath - another tokenized path * @param in_isReference - is something a reference * * @package * @hidden */ declare const invokeCallbacks: (in_dataBinding: DataBinding | undefined, in_baseModificationContext: ModificationContext, in_calledForReference: boolean, in_tokenizedFullPath: string[], in_visitIndex: number, in_traversalContext: Utils.TraversalContext, in_registeredHandlers: any, in_tokenizedPath: string[], in_isReference: boolean) => void; /** * Determine the minimal paths to the roots described by the given paths, removing redundant paths. * For example, given the paths /a.b.c, /a.b.c.d and /a.x, the minimal roots are /a.b.c and /a.x, because * /a.b.c.d is under the hierarchy of /a.b.c * * @param in_paths - the array of paths to minimize * * @returns the minimal set of roots * @hidden */ declare const minimalRootPaths: (in_paths: string[]) => string[]; /** * Recursively visit all properties and values, starting from in_rootProperty, calling in_callback on each item. * * @param in_rootPropertyElement - the property from which to recurse from * @param in_elementAbsolutePath - the path from the root workspace for this element * @param in_dataBindingTreeRoot - the root node of the DataBindingTree * @param in_callback - function to call for each path. Recursion continues if the function returns true. * @hidden */ declare const recursivelyVisitHierarchy: (in_rootPropertyElement: PropertyElement, in_elementAbsolutePath: string, in_dataBindingTreeRoot: DataBindingTree, in_callback: RecursiveCallback) => void; /** * Return whether the provided property is a primitive collection property * @param in_property - property to query * * @returns true if it is a collection of primitive types. * @hidden */ declare const isPrimitiveCollection: (in_property: BaseProperty) => boolean; /** * Recursively visit all properties and values, starting from in_rootProperty, calling in_callback on each item. * * @param in_rootProperty - the property from which to recurse from * @param in_callback - function to call for each path. Recursion continues if the function returns true. * @internal */ declare const forEachProperty: (in_rootProperty: BaseProperty, in_callback: (property: BaseProperty) => boolean) => void; /** * Unregister all the path listeners. Should not be used; we have it for testing purposes. * * @param in_dataBindingConstructor - the constructor to unregister on * * @private * @hidden */ declare const unregisterAllOnPathListeners: (in_dataBindingConstructor: typeof DataBinding) => void; /** * Get the template (either locally or remotely registered) of the given typeid * @param in_typeid the typeid from which we want to get the template * @returns The template (if exists) */ declare const getLocalOrRemoteSchema: (in_typeid: string) => PropertyTemplate | undefined; /** * Traverses the inheritance structure of a type, starting with the given type, towards the base * classes. If the callback returns false, the traversal stops. * * @param in_typeID - the type to begin the recursion from * @param in_callback - called for every type found. Returning false will abort the traversal. * * @returns traversal succeeded without being aborted * * @private * @hidden */ declare const visitTypeHierarchy: (in_typeID: string, in_callback: (typeid: string) => boolean) => boolean; /** * Take the given callback, and generate a new callback that will only allow itself to be called once * per changeset. * * @param in_callback - a databinder callback, i.e., a callback that expects 'this' to * inherit from DataBinding * * @returns the wrapped callback * * @private * @hidden */ declare const makeCallbackOncePerChangeSet: (in_callback: Function) => Function; /** * Defer the provided callback until the next changeset post processing * * @param in_callback - the function to defer * @returns the deferred function * * @private * @hidden */ declare const deferCallback: (in_callback: Function) => (...args: any) => any; /** * Check to see if the given constructor is already registered with one DataBinder. It is used * to ensure that relative callbacks are not installed after it has been added to the DataBinder. * Note; if in_bindingConstructor inherits from another class, which is registered, this function * still returns false. * * @param in_bindingConstructor - the constructor to validate. * @returns true if it is already registered. * * TODO: Move the _mark and _unmark functions from data_binder.js . Currently cannot easily do this * since the data_binder.js is using DataBinding and this file is a base class (and the function * needs to work with the constructor prototype, not an instance) * * @hidden */ declare const isDataBindingRegistered: (in_bindingConstructor: typeof DataBinding) => boolean; /** * Install the '_forEachPrototypeMember' callback function on the given constructor if it does not already exist. * Calling this function on an object of this type will call in_callback on the property in_propertyName for each * class along the prototype chain of in_dataBindingConstructor, skipping classes where it is not defined. * * @private * @hidden * * @param in_dataBindingConstructor - the constructor to extend */ declare const installForEachPrototypeMember: (in_dataBindingConstructor: typeof DataBinding) => void; /** * Checks the prototype of the given constructor if it already has a member of this name, and creates it * with in_default if it does not. * * @private * @hidden * * @param in_dataBindingConstructor - constructor object for the data binding class * @param in_propertyName - inherit/create this property in the prototype * @param in_default - what to instantiate if the member does not already exist * @returns the value, which may be in_default on the first creation */ declare const getOrCreateMemberOnPrototype: (in_dataBindingConstructor: typeof DataBinding, in_propertyName: string, in_default: T) => T; /** * Create a handle representing a registered path * * @private * @hidden * * @param in_constructor - the constructor for which we want to have a handle * @param in_escapedPaths - the paths we are registering for * @param in_operations - the operations for which we are registering * @param in_callback - the callback to call * * @returns the created handle */ declare const createHandle: (in_constructor: typeof DataBinding, in_escapedPaths: (string | number)[], in_operations: string[], in_callback: any) => DataBinderHandle; /** * Callback handler that is used by registerOnProperty to call the user supplied callback with the property as * parameter. * * @param in_callback - The callback to invoke with the property * @param in_requireProperty - If true, the callback will only be called with an existing property * @param in_modificationContext - The modification context * @private * @hidden */ declare const invokeWithProperty: (this: any, in_callback: Function, in_requireProperty: boolean, in_modificationContext: ModificationContext) => void; /** * Callback handler that is used by registerOnProperty to call the user supplied callback with the property as * parameter. * * @param in_callback - The callback to invoke with the property * @param in_requireProperty - If true, the callback will only be called with an existing property * @param in_key - Key of the property in the collection being modified * @param in_modificationContext - The modification context * @private * @hidden */ declare const invokeWithCollectionProperty: (this: any, in_callback: Function, in_requireProperty: boolean, in_key: string | number, in_modificationContext: ModificationContext) => void; /** * @param in_registrationType Registration method's name from the DataBinding prototype. * @param in_callbackArgs The registered callback arguments. * @returns A function that calls the callback registration on a given DataBinding prototype. * @private * @hidden */ declare const createRegistrationFunction: (in_registrationType: string, in_callbackArgs: IArguments) => Function; export { escapeTokenizedPathForMap, unescapeTokenizedStringForMap, joinPaths, initializeReferencePropertyTableNode, validOperations, assertOperation, invokeCallbacks, minimalRootPaths, recursivelyVisitHierarchy, forEachProperty, unregisterAllOnPathListeners, isPrimitiveCollection, visitTypeHierarchy, makeCallbackOncePerChangeSet, deferCallback, isDataBindingRegistered, installForEachPrototypeMember, getOrCreateMemberOnPrototype, createHandle, invokeWithProperty, invokeWithCollectionProperty, createRegistrationFunction, getLocalOrRemoteSchema, }; //# sourceMappingURL=internalUtils.d.ts.map