Front-End Model Reference

Last modified by superadmin on 2026/11/25 21:38

Parsers, serializers and handlers that convert entity references to and from strings, with their providers.

Reference

Parser

ModelReferenceParser

/**
 * @since 18.0.0RC1
 */
interface ModelReferenceParser {
  /**
   * @param reference - an entity reference
   * @param options - (since 0.22) an optional configuration object
   */
  parse(
    reference: string,
    options?: ModelReferenceParserOptions,
  ): EntityReference;

  /**
   * Parse a reference with additional analysis that can only be performed asynchronously
   * @param reference - an entity reference
   * @param options - an optional configuration object
   * @since 18.0.0RC1
   */
  parseAsync(
    reference: string,
    options?: ModelReferenceParserOptions,
  ): Promise<EntityReference>;
}

ModelReferenceParserOptions

/**
 * @since 18.0.0RC1
 */
type ModelReferenceParserOptions = {
  /**
   * an optional type, helping to remove ambiguity when parsing the reference
   */
  type?: EntityType;
  /**
   * When false, the model reference is parsed as an absolute reference.
   * When true, the model reference is parsed relatively to the current document.
   * The default value is true.
   */
  relative?: boolean;
  /**
   * The reference to resolve a relative reference against: the entities missing from the parsed reference (e.g. the
   * wiki and the space of a page reference made of the page name only) are taken from it. Typically the document that
   * holds the parsed reference (e.g. the document holding a link). Implementations that don't support relative
   * references ignore it.
   *
   * @since 18.10.0RC1
   */
  base?: EntityReference;
};

ModelReferenceParserProvider

/**
 * @since 18.0.0RC1
 */
interface ModelReferenceParserProvider {
  get(type?: string): ModelReferenceParser | undefined;
}

Serializer

ModelReferenceSerializer

/**
 * @since 18.0.0RC1
 */
interface ModelReferenceSerializer {
  /**
   * @param reference - the reference to serialize
   * @param base - (since 18.10.0RC1) the reference to serialize the given reference relative to, omitting the leading
   *   entities they have in common (e.g. only the page name for a page of the same space as the base document), so
   *   that parsing the result against the same base gives back the given reference; when not specified, or when the
   *   implementation doesn't support relative references, the given reference is fully serialized
   * @returns the serialized reference, or `undefined` when no reference is given
   */
  serialize(
    reference?: EntityReference,
    base?: EntityReference,
  ): string | undefined;
}

XWiki 18.10.0+ The XWiki implementation serializes the references in the format of the server-side entity reference serializer (e.g. wiki:[email protected]), without a prefix for the type of the entity: pass the type to the parser when the reference isn't the reference of a document.

XWiki <18.10.0 The XWiki implementation prefixes the serialized reference of a space, a document or an attachment with its type (e.g. doc:wiki:Space.Page).

ModelReferenceSerializerProvider

/**
 * @since 18.0.0RC1
 */
interface ModelReferenceSerializerProvider {
  get(type?: string): ModelReferenceSerializer | undefined;
}

Handler

ModelReferenceHandler

/**
 * A ModelReferenceHandler can do backend-specific operations involving
 * {@link @xwiki/platform-model-api#EntityReference | EntityReferences}.
 *
 * @since 18.0.0RC1
 */
interface ModelReferenceHandler {
  /**
   * Returns a {@link DocumentReference} with a specific name and a parent
   * {@link SpaceReference}.
   *
   * @param name - the name of the document reference
   * @param space - the parent space of the document reference
   * @returns the document reference
   */
  createDocumentReference(
    name: string,
    space: SpaceReference,
  ): DocumentReference;

  /**
   * Return the title of a reference
   */
  getTitle(reference: EntityReference): string;

  /**
   * Returns the {@link DocumentReference} considered as the direct parent of
   * the given document reference.
   * @param reference - the reference for which we want the parent
   * @returns the parent for the given reference, undefined if there is none
   *
   * @since 18.4.0RC1
   */
  getParentDocumentReference(
    reference: DocumentReference,
  ): DocumentReference | undefined;

  /**
   * Returns the {@link SpaceReference} considered as the direct parent of
   * the given space reference.
   * @param reference - the reference for which we want the parent
   * @returns the parent for the given reference, undefined if there is none
   *
   * @since 18.4.0RC1
   */
  getParentSpaceReference(
    reference: SpaceReference,
  ): SpaceReference | undefined;
}

ModelReferenceHandlerProvider

/**
 * A ModelReferenceHandlerProvider returns the expected instance of
 * {@link ModelReferenceHandler}.
 *
 * @since 18.0.0RC1
 */
interface ModelReferenceHandlerProvider {
  /**
   * Returns the instance of {@link ModelReferenceHandler} matching the
   * requested wiki configuration type, or the current one if empty.
   *
   * @param type - the wiki configuration type
   * @returns the instance of model reference handler
   */
  get(type?: string): ModelReferenceHandler | undefined;
}

Related

Cristal - Model - Reference
Cristal - Model - Reference Handler

Get Connected