Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
src
.gitattributes
.gitignore
.npmignore
LICENSE
README.md
package.json
tsconfig.json

README.md

npm version Build Status npm Gzip browser bundle

Kentico Cloud Model Generator Utility

The purpose of this project is to help you generate strongly typed models out of Kentico Cloud item types. These models can then be used along with the Kentico Cloud Delivery SDK

Installation

Install package globally:

npm i kentico-cloud-model-generator-utility -g

Generating models with NPM script

To generate models with e.g. ES2015 and TypeScript navigate to folder where you want to generate models and run:

kc-generate --projectId=xxx --moduleResolution=ES2015 --codeType=TypeScript

Configuration

  • codeType - available options are TypeScript and JavaScript
  • moduleResolution - available options are CommonJs and ES2015
  • projectId - represents the Kentico Cloud Project Id from which models will be generated
  • secureAccessKey- Secure access key required to authenticate requests with enabled secure access in Kentico Cloud project.

Strongly typed linked item fields

There is no direct link between a field and a linked item that can be used inside that field. For this reason, you need to manually swap ContentItem types with the types that represents that field.

Examples

ES2015 + Typescript

import { ContentItem, Fields } from 'kentico-cloud-delivery';

/**
 * This class was generated by 'kentico-cloud-model-generator-utility' at Mon May 07 2018 11:10:02 GMT+0200 (Central Europe Daylight Time).
 *
 * Note: You can substitute 'ContentItem' type with another generated class. Generator doesn't have this information available
 * and so its up to you to define relationship between models.
 */
export class Actor extends ContentItem {
    public url: Fields.UrlSlugField;
    public firstName: Fields.TextField;
    public lastName: Fields.TextField;
    public photo: Fields.AssetsField;
    constructor() {
        super({
            propertyResolver: ((fieldName: string) => {
                if (fieldName === 'first_name') {
                    return 'firstName';
                }
                if (fieldName === 'last_name') {
                    return 'lastName';
                }
                return fieldName;
            })
        });
    }
}

ES2015 + JavaScript

import { ContentItem, Fields } from 'kentico-cloud-delivery';

/**
* This class was generated by 'kentico-cloud-model-generator-utility' at Wed May 09 2018 11:14:55 GMT+0200 (Central Europe Daylight Time).
*/
export class Actor extends ContentItem {
        constructor() {
        super({
            propertyResolver: ((fieldName) => {
                if (fieldName === 'first_name') {
                    return 'firstName';
                }
                if (fieldName === 'last_name') {
                    return 'lastName';
                }
                return fieldName;
            })
        });
    }
}

CommonJs + JavaScript

var KenticoCloud = require('kentico-cloud-delivery');

/**
* This class was generated by 'kentico-cloud-model-generator-utility' at Wed May 09 2018 11:17:05 GMT+0200 (Central Europe Daylight Time).
*/
export class Actor extends KenticoCloud.ContentItem {
        constructor() {
        super({
            propertyResolver: ((fieldName) => {
                if (fieldName === 'first_name') {
                    return 'firstName';
                }
                if (fieldName === 'last_name') {
                    return 'lastName';
                }
                return fieldName;
            })
        });
    }
}

Contribution & Feedback

Contributions are welcomed. Simply make a pull request.

Analytics