@enonic/mock-xp
Version:
Mock Enonic XP API JavaScript Library
119 lines (118 loc) • 4.54 kB
TypeScript
import type { AggregationsToAggregationResults, Attachment, ComponentDescriptor, Content, NestedRecord, PublishInfo, UserKey } from '@enonic-types/core';
import type { Aggregations, AccessControlEntry, ByteSource, ContentExistsParams, ContentsResult, CreateContentParams, CreateMediaParams, DeleteContentParams, GetAttachmentStreamParams, GetContentParams, ModifyContentParams, MoveContentParams, PublishContentParams, PublishContentResult, QueryContentParams } 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 NodeComponenFragment {
fragment: {
id: string;
};
path: string;
type: 'fragment';
}
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 interface NodeComponentText {
path: string;
text: {
value: string;
};
type: 'text';
}
declare type NodeComponent = NodeComponenFragment | NodeComponentLayout | NodeComponentPage | NodeComponentPart | NodeComponentText;
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> & {
_trace?: boolean;
}): 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 & {
_trace?: boolean;
}): 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;
query<Hit extends Content<unknown> = Content, AggregationInput extends Aggregations = never>(params: QueryContentParams<AggregationInput> & {
_debug?: boolean;
_trace?: boolean;
}): ContentsResult<Hit, AggregationsToAggregationResults<AggregationInput>>;
}
export {};