Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kentico-cloud-model-generator-utility

Package Overview
Dependencies
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kentico-cloud-model-generator-utility

This utility generates strongly-typed models based on Content Types in a Kentico Cloud project. The models are supposed to be used together with the Kentico Cloud Typescript SDK.

  • 2.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-10%
Maintainers
4
Weekly downloads
 
Created
Source

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.
  • strictPropertyInitalization- Marks typescript properties with !. This is useful if you know all your properties are required. strictPropertyInitalization in Typesript

Strongly typed linked item elements

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

Examples

ES2015 + Typescript

import { ContentItem, Elements } 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: Elements.UrlSlugElement;
    public firstName: Elements.TextElement;
    public lastName: Elements.TextElement;
    public photo: Elements.AssetsElement;
    constructor() {
        super({
            propertyResolver: ((elementName: string) => {
                if (elementName === 'first_name') {
                    return 'firstName';
                }
                if (elementName === 'last_name') {
                    return 'lastName';
                }
                return elementName;
            })
        });
    }
}

ES2015 + JavaScript


import { ContentItem, Elements } 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: ((elementName) => {
                if (elementName === 'first_name') {
                    return 'firstName';
                }
                if (elementName === 'last_name') {
                    return 'lastName';
                }
                return elementName;
            })
        });
    }
}

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: ((elementName) => {
                if (elementName === 'first_name') {
                    return 'firstName';
                }
                if (elementName === 'last_name') {
                    return 'lastName';
                }
                return elementName;
            })
        });
    }
}

Contribution & Feedback

Contributions are welcomed. Simply make a pull request.

Analytics

Keywords

FAQs

Package last updated on 15 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc