@carbdrox/base-model
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

BaseModel

A TypeScript base model

Total Downloads Latest Stable Version License

Installation

Using npm

npm i @carbdrox/base-model --save

Usage

Inside your self defined Models e.g. User.ts

import {BaseModel, Field} from '@carbdrox/base-model';

export class User extends BaseModel {
    
    @Field()
    private name?: string;

    constructor(data) {
        super(data);
        this.hydrate(data);
    }
}

Interface

protected hydrate(data: KeyValue): void;

This method hydrates the class with the provided data.

protected apiFields: string[];

This array should contain all keys that should be returned by transformObjectForApi.

get transformObjectForApi(): KeyValue;

This getter returns an Object containing values for all keys specified by transformObjectForApi. If transformObjectForApi is empty all class-fields are used.

get isNew(): boolean;

Returns true if the id-field contains a nullable value.

isDirty(): boolean;

Returns true if one value differs from the initial value.

clone(): BaseModel;

Returns a new instance/copy of the class.

License

MIT

Package Sidebar

Install

npm i @carbdrox/base-model

Weekly Downloads

4

Version

1.1.1

License

MIT

Unpacked Size

8.57 kB

Total Files

6

Last publish

Collaborators

  • carbdrox