1.1.1 • Published 9 months ago

@carbdrox/base-model v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

BaseModel

A TypeScript base model

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

1.1.1

9 months ago

1.1.0

9 months ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago