import { IdenfitierDocumentPathHolder } from './identifieranddocumentsatpath'; import { ComponentAutocompleteEntry } from './componentautocompleteentry'; import { OutlineEntry } from '../functions/outliner'; import { ProblemMessageObject } from './errors'; import { Id } from './id'; import { JsonToken } from './jsontoken'; import { ComponentPayloadDependencies } from './componentpayloaddependencies'; import { ProcessorOperations } from './processoroperations'; import { ComponentPath } from './componentpath'; /** * New implementation of the ComponentPayload class. * This should get independent of the RoomleContentToolApi and not use any global state. * This class is used to represent a component payload, which is a component definition in JSON format. * Usage: * - construct from a filepath or a (stringified) JSON object. * - do whatever you need using the methods on the instance ... everything is lazy-loaded, so you can access the properties and methods as needed. * - checkout the finalDocument or finalDocumentAsLines */ export declare class ComponentPayload { static INDENTATION_SIZE: number; readonly id: Id; readonly filePath: string | undefined; private _problems; private _valid; private readonly _inputDocument; private _componentJson; /** * This is filled after tokenizing all the Roomle script, which is and expensive operation. * This is an entry for the RoomleScript based autocomplete entries. */ private _idenfitierDocumentPathHolder; private _outlineEntries; private _jsonTokens; private _dependencies; /** * Static analysis of the component JSON structure to provide autocomplete entries defined in the JSON. * Autocomplete entries defined in the script need to be filled in the taken from the identifierDocumentPathHolder. */ private _autocompleteEntries; /** Returns a deep copy that is read only. Use pushProblem to add new problems which will also handle duplicates. */ get problems(): ReadonlyArray; /** Returns if the component payload is valid: has a valid Id and the JSON is valid and could be parsed. */ get isValid(): boolean; get externalId(): string | undefined; get catalogId(): string | undefined; get componentId(): string | undefined; /** * Returns the input document as a string. * This is the original status of the component definition, before any normalization or processing. */ get inputDocument(): string | undefined; /** * Returns the component JSON as an object, which has been parsed already in the constructor. */ get componentJson(): any | undefined; get componentJsonAsDeepCopy(): any | undefined; /** * Returns the current status of the component definition as a string. * All this lazy-loads the internal property and returns it. * All operations in between two finishedDocument calls will reset the internal property, so it will be recalculated. * If payload is not valid, this will return undefined. */ get finishedDocument(): string | undefined; /** * Returns the current status of the component definition as an array of lines. * This is useful for syntax highlighting, code navigation, and other editor features. * This is just a split call on the finishedDocument. * If payload is not valid, this will return undefined. */ get finishedDocumentAsLines(): string[] | undefined; /** * Returns list of dependent components. */ get dependencies(): ComponentPayloadDependencies; /** * Checks if this component payload has changed the input document. * This is useful for detecting if the component payload has been modified when applying changes to a document in the editor. * Otherwise it would always create an undo entry in the code editor. */ get isDirty(): boolean; private _autocompleteEntriesFilteredByPath; /** * Returns the autocomplete entries for the component definition. * This is useful for the autocomplete feature in the code editor. * This is a static analysis of the component JSON structure to provide autocomplete entries defined in the JSON and the script. * WARNING: This is called several times during the analysis. Use getAutocompleteEntriesForPath instead. */ get autocompleteEntries(): ComponentAutocompleteEntry[]; private _functionAutocompleteEntries; /** * Returns only the autocomplete entries that are defined in the Roomle script. * This is useful for the autocomplete feature in the code editor. * WARNING: This is called several times during the analysis. Use getAutocompleteEntriesForPath instead. */ getFunctionAutocompleteEntries(subComponentInternalId: string, requestedAtPath: ComponentPath | undefined): ComponentAutocompleteEntry[]; /** * For a given script path, returns the relevant autocomplete entries relevant at that path. * @param path The component path to filter the autocomplete entries. If undefined, this filter is not applied. * @returns */ getAutocompleteEntriesForPath(path: ComponentPath | undefined): ComponentAutocompleteEntry[]; /** * Checks if this component payload has changed the input document, ignoring leading and trailing whitespace. * This is useful for detecting if the component payload has been modified when applying changes to a document that * is not edited in an editor. */ get isDirtyAfterTrim(): boolean; /** * Returns the finished document, if it has changed from the input document. * Otherwise it returns undefined. */ get dirtyDocument(): string | undefined; /** * Return the outliner entries for the component definition. * This is useful for the outline view in the code editor. */ get outlineEntries(): OutlineEntry[] | undefined; /** * Pushed a problem into the payload's errors array. Duplicate problems are ignored. * @param problem ProblemMessageObject or an array of ProblemMessageObject to add to the payload. */ readonly pushProblem: (problem: ProblemMessageObject | ProblemMessageObject[]) => void; get identifierDocumentPathHolder(): IdenfitierDocumentPathHolder; /** * Constructs a ComponentPayload from a source object, string or file path. * After construction, the payload will contain the component JSON, the input document as a string, and any problems encountered during parsing. * All other properties that are derived from the component JSON, such as `autocompleteEntries`, `outlineEntries`, and `jsonTokens` will be analyzed on demand automatically when their getters are accessed. * @param source Component definition object, string or filepath. If source is undefined, the filePath is used to read the content from a file. * @param filePath Filepath to the component definition file, important to provide error location information in case of errors. If no source is provided, this filePath is used to read the content from a file. */ constructor(source: any | string | undefined, filePath?: string | undefined); /** * Tokenizes the input document JSON string into an array of JsonToken objects. * This is useful for syntax highlighting, code navigation, and other editor features. */ get jsonTokens(): JsonToken[] | undefined; /** * Applies the normalization to the component JSON. * This means that it will remove any empty properties and all JSON attributes will be sorted * according to the ComponentDefinition class. * This is useful to ensure that the component JSON is in a consistent state * and can be used for further processing, such as validation or serialization. * WARNING: This returns a (semi-)deep copy of the component JSON, so it will not modify the original component JSON. * Objects not defined in the ComponentDefinition will be left, and original references will be kept. * Internal _componentJson property will be set to the normalized JSON. */ normalizeComponentJson(): void; /** * Use this to process the payload with the given operations. * @param options */ processPayload(options: ProcessorOperations): void; }