Home Manual Reference Source Repository
public class | source

ResourceBase

Expression Extends:

class ResourceBase extends mix(null, Injectable)

Resource base

Static Member Summary

Static Public Members
public static get

Returns if the resource is readonly

public static get abstract

Resource name

public static get

Resource path template

public static get

Returns the url key of the resource

Static Protected Members
protected static get

Protected read-only fields

Constructor Summary

Public Constructor
public

constructor(api: Mapcreator, data: Object<String, *>, altUrl: String)

Member Summary

Public Members
public get

api: Mapcreator: *

Get api instance

public set

api(value: Mapcreator)

Set the api instance

public get

Auto generated Resource base url

public get

List fields that contain object data

public get

If the resource can be owned by an organisation

public get

url: string: *

Auto generated resource url

Method Summary

Public Methods
public

Clone the object

public

Refresh the resource by requesting it from the server again

public

reset(fields: Array<string> | string | null)

Resets model instance to it's original state

public

Clean up instance and commit all changes locally.

public

static(Target: string | Class, Constructor: Class?, seedData: Object<string, *>): SimpleResourceProxy

Static proxy generation

public

toObject(camelCaseKeys: boolean): {}

Transform instance to object

public

String representation of the resource, similar to Python's repr

Protected Methods
protected

_guessType(name: string, value: *): *

Guess type based on property name

protected

Macro for resource listing

protected

Moves new fields to this._properties and turns them into a getter/setter

Static Public Members

public static get readonly: boolean: boolean source

Returns if the resource is readonly

Return:

boolean

Readonly

public static get abstract resourceName: String source

Resource name

Return:

String

Resource name

public static get resourcePath: String: string source

Resource path template

Return:

String

Path template

public static get resourceUrlKey: String: string source

Returns the url key of the resource

Return:

String

Resource key

Static Protected Members

protected static get protectedFields: Array<string>: string[] source

Protected read-only fields

Return:

Array<string>

Array containing protected read-only fields

Public Constructors

public constructor(api: Mapcreator, data: Object<String, *>, altUrl: String) source

Params:

NameTypeAttributeDescription
api Mapcreator

Api instance

data Object<String, *>

Item data

altUrl String
  • optional

Internal use, Optional alternative url for more complex routing

Public Members

public get api: Mapcreator: * source

Get api instance

Return:

Mapcreator

Api instance

public set api(value: Mapcreator) source

Set the api instance

public get baseUrl: string: * source

Auto generated Resource base url

Return:

string

Resource base url

public get fieldNames: Array<String>: * source

List fields that contain object data

Return:

Array<String>

A list of fields

public get ownable: boolean: boolean source

If the resource can be owned by an organisation

Return:

boolean

Can be owned by an organisation

public get url: string: * source

Auto generated resource url

Return:

string

Resource url

Public Methods

public clone(): ResourceBase source

Clone the object

Return:

ResourceBase

Exact clone of the object

public refresh(updateSelf: Boolean): CancelablePromise<ResourceBase> source

Refresh the resource by requesting it from the server again

Params:

NameTypeAttributeDescription
updateSelf Boolean

Update the current instance

Return:

CancelablePromise<ResourceBase>

Refreshed instance

Throw:

ApiError

If the api returns errors

public reset(fields: Array<string> | string | null) source

Resets model instance to it's original state

Params:

NameTypeAttributeDescription
fields Array<string> | string | null
  • optional
  • default: null

Fields to reset, defaults to all fields

public sanitize() source

Clean up instance and commit all changes locally. This means that any changed fields will be marked as unchanged whilst keeping their new values. The changes will not be saved.

public static(Target: string | Class, Constructor: Class?, seedData: Object<string, *>): SimpleResourceProxy source

Static proxy generation

Params:

NameTypeAttributeDescription
Target string | Class

Constructor or url

Constructor Class?

Constructor for a resource that the results should be cast to

seedData Object<string, *>

Optional data to seed the resolved resources

Return:

SimpleResourceProxy

A proxy for accessing the resource

Example:

user.static('jobs').lister();
class FooBar extends ResourceBase {
   static get resourceName() {
     return 'custom';
   }
}

api.static(FooBar)
  .get(1)
  .then(console.log);

public toObject(camelCaseKeys: boolean): {} source

Transform instance to object

Params:

NameTypeAttributeDescription
camelCaseKeys boolean
  • optional
  • default: false

camelCase object keys

Return:

{}

Object

public toString(): string source

String representation of the resource, similar to Python's repr

Return:

string

Resource name and id

Protected Methods

protected _guessType(name: string, value: *): * source

Guess type based on property name

Params:

NameTypeAttributeDescription
name string

Field name

value *

Field Value

Return:

*

Original or converted value

protected _proxyResourceList(Target: string | Class<ResourceBase>, url: String, seedData: object): SimpleResourceProxy source

Macro for resource listing

Params:

NameTypeAttributeDescription
Target string | Class<ResourceBase>

Target object

url String
  • nullable: true

Target url, if null it will guess

seedData object

Internal use, used for seeding SimpleResourceProxy::new

Return:

SimpleResourceProxy

A proxy for accessing the resource

protected _updateProperties() source

Moves new fields to this._properties and turns them into a getter/setter