Class Sdkzer<T>

Type Parameters

Hierarchy

  • Sdkzer

Constructors

  • Creates an instance of a model entity with an API to communicate with a resource (http RESTful resource)

    Type Parameters

    Parameters

    • attrs: T = ...

      The initial attributes for the resource. Those attributes are in force to defaults()

    Returns Sdkzer<T>

Properties

attrs: T
invalidMessages: object = {}
lastResponse: Response = null
pAttrs: T
syncing: boolean = false
validationRules: object

Methods

  • This method can do 3 different things:

      1. Reads all attributes. When called as instance.attr()
      1. Read one attribute. When called as instance.attr('name')
      1. Set one attribute. When called as instance.attr('name', 'Bruce Lee')

    It's recommended to use this method instead of accessing to attr attribute directly. This allows you to execute logic before and after setting or reading attributes. Also, instead of creating 100 setters and getters, we use a single attr() method

    Parameters

    • Optional attrName: string

      The attribute name that we want to read or set

    • Optional value: any

      The attribute value that we want to set for "attrName"

    Returns string | number | boolean | object

  • Retrieves the base resource url. Override it using your base endpoint for your resource.

    NOTE: You need to define a baseEndpoint method in your entities in order to be able to sync with a backend endpoint A base endpoint for a RESTful endpoint look like: return "https://www.an-api.com/v1/users"

    Returns string

  • Retrieves the name of the changed attributes since the last save

    Returns string[]

  • Retrieves the defaults for the entity. Override it using your default attributes if you need any

    Returns object

  • Destroys the current record in the origin

    Returns Promise<Response>

  • Fetches the newest attributes from the origin.

    Parameters

    • Optional httpQuery: IQuery
    • camelize: boolean = true

    Returns Promise<Response>

  • Checks if an attribute has changed from the origin

    Parameters

    • attrName: string

    Returns boolean

  • Checks if the record has changed since the last save

    Returns boolean

  • Checks if the record is not saved in the origin. An record will be consiered new when it has an "id" attribute set to null and it lacks of a "lastResponse" attribute value

    Returns boolean

  • Checks wether an entity is a valid entity. It doesn't perform validation (check validate())

    Returns boolean

  • Parses a single resource record from an incoming HttpResponse data NOTE: The idea is to return the parsed record data only

    Parameters

    • data: object
    • Optional prefix: string

    Returns T

  • Retrieves the previous value prior to last save for a specific attribute

    Parameters

    • attrName: string

    Returns any

  • Retrieves the resource url NOTE: This method will become the interface to connect using different http patterns

    Returns string

  • Sets the defaults() values in the instance attributes

    Returns void

  • Transforms the local attributes to be processed by the origin in a specific format

    Parameters

    • format: string = 'json'

      The format to transform into

    Returns string | object

  • Transforms the local attributes to be processed by the origin in JSON format

    Returns object

  • Transforms the local attributes to be processed by the origin in XML format

    Returns string

  • Retrieves a collection of records from the origin

    Parameters

    • Optional httpQuery: IQuery

      An optional query to be merged with the default one

    Returns Promise<any[]>

  • Retrieves a single record from the origin

    Parameters

    • id: string | number

      The record id that we want to fetch by

    • Optional httpQuery: IQuery

      Use a HttpQuery instance to override the default query

    Returns Promise<any>

  • Parses a collection of resource records from an incoming HttpResponse data NOTE: The idea is to return the parsed collection of records data only

    Parameters

    • data: object[]
    • Optional prefix: string

    Returns object[]

Generated using TypeDoc