@constellation4sitecore/foundation-mapper v1.0.3
Constellation Foundation Mapper
Installation
npm install @constellation4sitecore/foundation-mapper --save
Usage
Map To New
This function is really useful quen you perform a Graphql query for example:
query {
item(path: "my-path", language: "en") {
fields {
name
jsonValue
}
}
}
The structure of the current result is kind of array of fields { name, jsonvalue}. Within mapToNew
you can cast to model object instead of looping an array of fields.
import { mapToNew } from '@constellation4sitecore/foundation-mapper';
export type MyExampleType = {
logo: ImageField;
primaryNavigation: Field<string>;
copyright: Field<string>;
socialIntroText: Field<string>;
cookieSettings: Field<string>;
};
var fieldsProps = mapToNew<MyExampleType>(results);
Cast Item
In some scenarios you have the item reference which has a fields property but you need to type the fields into a type model
import { castItem } from '@constellation4sitecore/foundation-mapper';
// Given item as
// item {
// copyright: {
// value: "Text"
// }
//}
export type MyExampleType = {
copyright: Field<string>;
};
var fieldsProps = castItem<MyExampleType>(item);
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
6 months ago
8 months ago
10 months ago
10 months ago
10 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago