Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/enonic-mock-xp-*.tgz
/yarn-error.log
.idea
.DS_store
7 changes: 3 additions & 4 deletions src/implementation/Branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
isFilter,
isHasValueFilter,
isQueryDsl,
toStr
} from '@enonic/js-utils';
import {flatten} from '@enonic/js-utils/array/flatten';
import {forceArray} from '@enonic/js-utils/array/forceArray';
Expand Down Expand Up @@ -286,7 +285,7 @@ export class Branch {
)
)) {
if (this.repo.server.indexWarnings) {
this.log.warning('mock-xp is only able to (index for quering) boolean and string properties, skipping rootProp:%s with value:%s', rootProp, toStr(rootPropValue));
this.log.warning('mock-xp is only able to (index for quering) boolean and string properties, skipping rootProp:%s with value:%s', rootProp, rootPropValue);
}
continue RestKeys;
}
Expand Down Expand Up @@ -377,7 +376,7 @@ export class Branch {

if (!isString(rootPropValue)) {
if (this.repo.server.indexWarnings) {
this.log.warning('mock-xp is not able to handle non-string properties yet, skipping rootProp:%s with value:%s', rootPropKey, toStr(rootPropValue));
this.log.warning('mock-xp is not able to handle non-string properties yet, skipping rootProp:%s with value:%s', rootPropKey, rootPropValue);
}
continue RootProps;
}
Expand Down Expand Up @@ -588,7 +587,7 @@ export class Branch {
) {
for (const value of values) {
if (!supportedValueType(value)) {
this.log.error('query: Unsupported value type:%s', toStr(value));
this.log.error('query: Unsupported value type:%s', value);
} else {
if (
// @ts-ignore Object is possibly 'undefined'.ts(2532)
Expand Down
137 changes: 93 additions & 44 deletions src/implementation/ContentConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,33 @@ import {
getIn,
// deleteIn,
setIn,
// toStr // log mock does not support need toStr, but throwing Errors does.
toStr // log mock does not support need toStr, but throwing Errors does.
} from '@enonic/js-utils';
import { sha512 } from 'node-forge';
import { sync as probeSync } from 'probe-image-size';
import {
INDEX_CONFIG_DEFAULT,
PERMISSIONS_DEFAULT,
} from './node/constants';
import {NodeAlreadyExistAtPathException} from './node/NodeAlreadyExistAtPathException';
import {NodeNotFoundException} from './node/NodeNotFoundException';
import { NodeAlreadyExistAtPathException } from './node/NodeAlreadyExistAtPathException';
import { NodeNotFoundException } from './node/NodeNotFoundException';


declare interface NodeComponenFragment {
fragment: {
id: string;
};
path: string;
type: 'fragment';
}

declare interface NodeComponentLayout {
layout: {
config?: NestedRecord
descriptor: ComponentDescriptor
}
path: string
type: 'layout'
path: string;
type: 'layout';
}

declare interface NodeComponentPage {
Expand All @@ -69,20 +77,33 @@ declare interface NodeComponentPage {
customized: boolean
descriptor: ComponentDescriptor
}
path: string
type: 'page'
path: string;
type: 'page';
}

declare interface NodeComponentPart {
part: {
config?: NestedRecord
descriptor: ComponentDescriptor
}
path: string
type: 'part'
path: string;
type: 'part';
}

declare interface NodeComponentText {
path: string;
text: {
value: string;
};
type: 'text';
}

declare type NodeComponent = NodeComponentLayout | NodeComponentPage | NodeComponentPart;
declare type NodeComponent =
| NodeComponenFragment
| NodeComponentLayout
| NodeComponentPage
| NodeComponentPart
| NodeComponentText;

declare interface ContentProperties<Data, Type> {
createdTime: string
Expand Down Expand Up @@ -137,6 +158,14 @@ declare type ContentToNode<
const CHILD_ORDER_DEFAULT = 'displayname ASC'; // NOTE: With small n is actually what Content Studio does.
const USER_DEFAULT: UserKey = 'user:system:su';

const COMPONENT_TYPE = {
FRAGMENT: 'fragment',
LAYOUT: 'layout',
PAGE: 'page',
PART: 'part',
TEXT: 'text',
} as const;


export class ContentConnection {
readonly branch: Branch;
Expand Down Expand Up @@ -626,8 +655,6 @@ export class ContentConnection {
const {
path,
type,
// part,
// layout
} = component;
if (type === 'page' && path === '/') {
const {
Expand Down Expand Up @@ -660,65 +687,87 @@ export class ContentConnection {
});
}

const pageRegion = fragmentOrPage.regions[pageRegionName]
// this.log.debug('pageRegion: %s', pageRegion)
const pageRegion = fragmentOrPage.regions[pageRegionName];
// this.log.debug('pageRegion: %s', pageRegion);

if (type === 'layout') {
if (type === COMPONENT_TYPE.LAYOUT) {
const {
layout: {
config,
descriptor
descriptor,
}
} = component;
const [app, componentName] = descriptor.split(':');
const [ app, componentName ] = descriptor.split(':');
const dashedApp = app.replace(/\./g, '-');
const layout = {
config: config?.[dashedApp]?.[componentName],
descriptor,
path,
// NOTE: component contains no information about which regions it has.
regions: {},
type
type,
};
pageRegion.components.push(layout);
} else if (type === 'part') {
const {
part: {
config,
descriptor
}
} = component;
const [app, componentName] = descriptor.split(':');
const dashedApp = app.replace(/\./g, '-');
const part = {
config: config?.[dashedApp]?.[componentName],
descriptor,
path,
type
};
} else { // fragment, part, text
let components;
if (pathParts.length === 2) {
pageRegion.components.push(part);
components = pageRegion.components;
} else if (pathParts.length === 4) {
// this.log.debug('component: %s', component);
const pageComponentRegionIndex = pathParts[1];
// this.log.debug('pageComponentRegionIndex: %s', pageComponentRegionIndex)

// this.log.debug('pageComponentRegionIndex: %s', pageComponentRegionIndex);
// this.log.debug('pageRegion: %s', pageRegion);
const layoutComponent = pageRegion.components[pageComponentRegionIndex];
// this.log.debug('layoutComponent: %s', layoutComponent)

// this.log.debug('layoutComponent1: %s', layoutComponent);
const layoutRegionName = pathParts[2];
// this.log.debug('layoutRegionName: %s', layoutRegionName)

// this.log.debug('layoutRegionName: %s', layoutRegionName);
if (!layoutComponent.regions[layoutRegionName]) {
layoutComponent.regions[layoutRegionName] = {
components: [],
name: layoutRegionName,
};
}
// this.log.debug('layoutComponent2: %s', layoutComponent);
components = layoutComponent.regions[layoutRegionName].components;
} else {
throw new Error(`pathParts.length !== 2 or 4 component:${toStr(component)}`);
}
if (type === COMPONENT_TYPE.PART) {
const {
part: {
config,
descriptor
}
};
layoutComponent.regions[layoutRegionName].components.push(part);
} = component;
const [ app, componentName ] = descriptor.split(':');
const dashedApp = app.replace(/\./g, '-');
components.push({
config: config?.[dashedApp]?.[componentName],
descriptor,
path,
type
});
} else if (type === COMPONENT_TYPE.TEXT) {
const { text: { value: text } } = component;
components.push({
path,
text,
type,
});
} else if (type === COMPONENT_TYPE.FRAGMENT) {
const { fragment: { id: fragment } } = component;
components.push({
fragment,
path,
type,
});
} else {
throw new Error(`type !== fragment, part nor text! type:${type}`);
}
}
} // if componentType[...]
}
} // for components
}
} // if components

return content as C;
} // nodeToContent
Expand Down
Loading