UNPKG

@enonic/mock-xp

Version:

Mock Enonic XP API JavaScript Library

97 lines (96 loc) 3.82 kB
import type { Attachment, ComponentDescriptor, Content, NestedRecord, PublishInfo, UserKey } from '@enonic-types/core'; import type { AccessControlEntry, ByteSource, ContentExistsParams, CreateContentParams, CreateMediaParams, DeleteContentParams, GetAttachmentStreamParams, GetContentParams, ModifyContentParams, MoveContentParams, PublishContentParams, PublishContentResult } from '@enonic-types/lib-content'; import type { CreateNodeParams, ModifyNodeParams, NodeIndexConfig, NodeIndexConfigParams } from '@enonic-types/lib-node'; import type { Log, Vol } from '../types'; import type { Branch } from './Branch'; declare interface NodeComponentLayout { layout: { config?: NestedRecord; descriptor: ComponentDescriptor; }; path: string; type: 'layout'; } declare interface NodeComponentPage { page: { config?: NestedRecord; customized: boolean; descriptor: ComponentDescriptor; }; path: string; type: 'page'; } declare interface NodeComponentPart { part: { config?: NestedRecord; descriptor: ComponentDescriptor; }; path: string; type: 'part'; } declare type NodeComponent = NodeComponentLayout | NodeComponentPage | NodeComponentPart; declare interface ContentProperties<Data, Type> { createdTime: string; creator: UserKey; data: Data; owner: UserKey; type: Type; x?: XpXData; } export declare interface AllContentProperties { _id: string; _name: string; _path: string; attachments: Record<string, Attachment>; childOrder: string; creator: UserKey; createdTime: string; hasChildren: boolean; modifiedTime: string; owner: string; data: any; displayName: string; language: string; modifier: UserKey; page: Content['fragment'] | Content['page']; publish: PublishInfo; type: string; valid: boolean; x: XpXData; } declare type ContentToNode<C extends Partial<AllContentProperties> = Partial<AllContentProperties>> = Omit<C, 'childOrder'> & { _childOrder: C['childOrder']; _indexConfig: NodeIndexConfig | NodeIndexConfigParams; _inheritsPermissions: boolean; _nodeType: string; _permissions: AccessControlEntry[]; _state: string; _ts: string; _versionKey: string; components?: NodeComponent[]; }; export declare class ContentConnection { readonly branch: Branch; readonly vol: Vol; readonly log: Log; constructor({ branch, }: { branch: Branch; }); contentToNode<Data = Record<string, unknown>, Type extends string = string>({ content, mode, }: { content: CreateContentParams<Data, Type>; mode: 'create' | 'modify'; }): CreateNodeParams<ContentProperties<Data, Type>> | ModifyNodeParams<ContentProperties<Data, Type>>; create<Data = Record<string, unknown>, Type extends string = string>(params: CreateContentParams<Data, Type>): Content<Data, Type>; createMedia<Data = Record<string, unknown>, Type extends string = string>(params: CreateMediaParams): Content<Data, Type>; delete(params: DeleteContentParams): boolean; exists(params: ContentExistsParams): boolean; get<Hit extends Content<unknown> = Content>(params: GetContentParams): Hit | null; getAttachmentStream(params: GetAttachmentStreamParams): ByteSource | null; modify<Data = Record<string, unknown>, Type extends string = string>(params: ModifyContentParams<Data, Type>): Content<Data, Type> | null; move<Data = Record<string, unknown>, Type extends string = string>(params: MoveContentParams): Content<Data, Type>; nodeToContent<C extends Partial<AllContentProperties> = Partial<AllContentProperties>>({ node }: { node: ContentToNode<C>; }): C; publish(params: PublishContentParams): PublishContentResult; } export {};