packageDocumentation module import { NodeKey , NodeKeyJSON } from "./hierarchy/Key" ; import { Node , NodeJSON , PartialNode , PartialNodeJSON } from "./hierarchy/Node" ; alpha export const UPDATE_FULL = "FULL" ; alpha export interface UpdateInfoJSON { [ imodel ] : { [ rulesetId ] : { hierarchy ? : HierarchyUpdateInfoJSON ; content ? : ContentUpdateInfo ; } ; } ; } alpha export interface UpdateInfo { [ imodel ] : { [ rulesetId ] : { hierarchy ? : HierarchyUpdateInfo ; content ? : ContentUpdateInfo ; } ; } ; } alpha export namespace UpdateInfo { /** Serialize given object to JSON. */ export function toJSON ( obj ) { const json = { } ; for ( const imodel in obj ) { if ( ! obj . hasOwnProperty ( imodel ) ) continue ; json [ imodel ] = { } ; const rulesetObj = obj [ imodel ] ; for ( const rulesetId in rulesetObj ) { if ( ! rulesetObj . hasOwnProperty ( rulesetId ) ) continue ; json [ imodel ] [ rulesetId ] = { hierarchy : rulesetObj [ rulesetId ] . hierarchy ? HierarchyUpdateInfo . toJSON ( rulesetObj [ rulesetId ] . hierarchy ! ) : undefined , content : rulesetObj [ rulesetId ] . content } ; } } return json ; } /** Deserialize given object from JSON */ export function fromJSON ( json ) { const obj = { } ; for ( const imodel in json ) { if ( ! json . hasOwnProperty ( imodel ) ) continue ; obj [ imodel ] = { } ; const rulesetJson = json [ imodel ] ; for ( const rulesetId in rulesetJson ) { if ( ! rulesetJson . hasOwnProperty ( rulesetId ) ) continue ; obj [ imodel ] [ rulesetId ] = { hierarchy : rulesetJson [ rulesetId ] . hierarchy ? HierarchyUpdateInfo . fromJSON ( rulesetJson [ rulesetId ] . hierarchy ! ) : undefined , content : rulesetJson [ rulesetId ] . content } ; } } return obj ; } } alpha export interface ExpandedNodeUpdateRecordJSON { node : NodeJSON ; position : number ; } alpha export interface HierarchyUpdateRecordJSON { parent ? : NodeKeyJSON ; nodesCount : number ; expandedNodes ? : ExpandedNodeUpdateRecordJSON [ ] ; } alpha export interface ExpandedNodeUpdateRecord { node : Node ; position : number ; } alpha export interface HierarchyUpdateRecord { parent ? : NodeKey ; nodesCount : number ; expandedNodes ? : ExpandedNodeUpdateRecord [ ] ; } alpha export namespace ExpandedNodeUpdateRecord { /** Serialize given object to JSON. */ export function toJSON ( obj ) { return { ... obj , node : Node . toJSON ( obj . node ) } ; } /** Deserialize given object from JSON */ export function fromJSON ( json ) { return { ... json , node : Node . fromJSON ( json . node ) } ; } } alpha export namespace HierarchyUpdateRecord { /** Serialize given object to JSON. */ export function toJSON ( obj ) { return { ... obj , parent : obj . parent ? NodeKey . toJSON ( obj . parent ) : undefined , expandedNodes : obj . expandedNodes ? obj . expandedNodes . map ( ExpandedNodeUpdateRecord . toJSON ) : undefined } ; } /** Deserialize given object from JSON */ export function fromJSON ( json ) { return { ... json , parent : json . parent ? NodeKey . fromJSON ( json . parent ) : undefined , expandedNodes : json . expandedNodes ? json . expandedNodes . map ( ExpandedNodeUpdateRecord . fromJSON ) : undefined } ; } } alpha export type HierarchyUpdateInfoJSON = typeof UPDATE_FULL | HierarchyUpdateRecordJSON [ ] ; alpha export type HierarchyUpdateInfo = typeof UPDATE_FULL | HierarchyUpdateRecord [ ] ; alpha export namespace HierarchyUpdateInfo { /** Serialize given object to JSON. */ export function toJSON ( obj ) { if ( typeof obj === "string" ) return obj ; return obj . map ( HierarchyUpdateRecord . toJSON ) ; } /** Deserialize given object from JSON */ export function fromJSON ( json ) { if ( typeof json === "string" ) return json ; return json . map ( HierarchyUpdateRecord . fromJSON ) ; } } alpha export type ContentUpdateInfo = typeof UPDATE_FULL ; public export type PartialHierarchyModificationJSON = NodeInsertionInfoJSON | NodeDeletionInfoJSON | NodeUpdateInfoJSON ; public export type PartialHierarchyModification = NodeInsertionInfo | NodeDeletionInfo | NodeUpdateInfo ; public export namespace PartialHierarchyModification { /** Serialize given object to JSON. */ export function toJSON ( obj ) { switch ( obj . type ) { case "Insert" : return { type : "Insert" , parent : obj . parent === undefined ? undefined : NodeKey . toJSON ( obj . parent ) , position : obj . position , node : Node . toJSON ( obj . node ) } ; case "Update" : return { type : "Update" , target : NodeKey . toJSON ( obj . target ) , changes : Node . toPartialJSON ( obj . changes ) } ; case "Delete" : return { type : "Delete" , parent : obj . parent === undefined ? undefined : NodeKey . toJSON ( obj . parent ) , position : obj . position } ; } } /** Deserialize given object from JSON */ export function fromJSON ( json ) { switch ( json . type ) { case "Insert" : return { type : "Insert" , parent : json . parent === undefined ? undefined : NodeKey . fromJSON ( json . parent ) , position : json . position , node : Node . fromJSON ( json . node ) } ; case "Update" : return { type : "Update" , target : NodeKey . fromJSON ( json . target ) , changes : Node . fromPartialJSON ( json . changes ) } ; case "Delete" : return { type : "Delete" , parent : json . parent === undefined ? undefined : NodeKey . fromJSON ( json . parent ) , position : json . position } ; } } } public export interface NodeInsertionInfo { type : "Insert" ; /** Parent node key */ parent ? : NodeKey ; /** Index of the new node under its parent */ position : number ; /** Inserted node */ node : Node ; } public export interface NodeInsertionInfoJSON { type : "Insert" ; parent ? : NodeKeyJSON ; position : number ; node : NodeJSON ; } public export interface NodeDeletionInfo { type : "Delete" ; /** Parent of the deleted node */ parent ? : NodeKey ; /** Position of the deleted node among its siblings in the initial, not updated tree */ position : number ; } public export interface NodeDeletionInfoJSON { type : "Delete" ; /** Parent of the deleted node */ parent ? : NodeKeyJSON ; /** Position of the deleted node among its siblings in the initial, not updated tree */ position : number ; } public export interface NodeUpdateInfo { type : "Update" ; /** Key of the updated node */ target : NodeKey ; /** Updated node attributes */ changes : PartialNode ; } public export interface NodeUpdateInfoJSON { type : "Update" ; target : NodeKeyJSON ; changes : PartialNodeJSON ; } public export interface HierarchyCompareInfoJSON { changes : PartialHierarchyModificationJSON [ ] ; continuationToken ? : { prevHierarchyNode : string ; currHierarchyNode : string ; } ; } public export interface HierarchyCompareInfo { /** A list of hierarchy changes */ changes : PartialHierarchyModification [ ] ; /** Continuation token for requesting more changes. */ continuationToken ? : { prevHierarchyNode : string ; currHierarchyNode : string ; } ; } public export namespace HierarchyCompareInfo { /** Serialize given object to JSON. */ export function toJSON ( obj ) { return { ... obj , changes : obj . changes . map ( ( change ) => PartialHierarchyModification . toJSON ( change ) ) } ; } /** Deserialize given object from JSON */ export function fromJSON ( json ) { return { ... json , changes : json . changes . map ( ( change ) => PartialHierarchyModification . fromJSON ( change ) ) } ; } }