Index

APIRequester

MMO.core · 2 symbols · generated 5 Oct 2026

class

APIRequester

APIRequester.js:14

Wrapper to query any API implementing JSON API

class MMO.core.APIRequester
Namespace
MMO.core
# Supported query - pagination : ?page[offset]=0&page[limit]=10 - sorting : ?sort=-created,title - fields : ?fields=title,-body,people/name - filters : ?filters[age][$>]=20&filters[age][$<]=50&filters[author/status]=active - list only id : ?onlydIds

Index

collection readonly accessorThe collection name, read back out of the url through the repository path pattern.
repository readonly accessorThe repository name, read back out of the url through the repository path pattern.
offset accessorGet the starting offset of the data
limit accessorGet the maximum number of data to return
sort accessorGet a list of the fields used to sort the data the value associated to the field is a boolean that indicates if the sorting is ascending (false for descending)
fields accessorGet a list of the fields to show the value associated to the field is a boolean that indicates if the field is shown (true) or hidden (false)
filters accessorThe query filters, as a plain object.
search accessorThe full text search parameters, as a plain object.
searchType accessor
dataCount readonly accessor
dataClass readonly accessorThe php class name of the entities the last response carried.
pageOffset readonly accessorThe index of the first entity of the last response, within the whole collection.
pageIndex readonly accessorThe page number of the last response.
pageCount readonly accessorHow many pages the query spans.
previousPageUrl readonly accessor
nextPageUrl readonly accessor
firstPageUrl readonly accessor
lastPageUrl readonly accessor
constructor(url)
setUrl(url, keepSearch)Point the requester at another url, rebuilding its search parameters.
setUrlSearch(search)Replace the whole query string.
Collection(collection, repository) staticGet an instance meant to interact with the framework repository controller
List(collection, filters, repository) staticA requester set up to return identifiers only: ideal to populate a picker.
setLimitDate(dateStart, dateEnd, dateField)Restrict the query to a date window, replacing any window already set on that field.
getLimitDate(dateField)Read back the window set by MMO.core.APIRequester#setLimitDate
splitFieldsList(key)Split a string representing a list of fields
joinFieldsList(key, value)Join a value to create a list of fields as a string
indexOfFieldsList(key, field, value)Get/set the index of field (even if the field is prefixed with '-')
indexAtFieldsList(key, index)
addFieldsList(key, field, value, order)Add a field to the field list
removeFieldsList(key, field)Remove a field from the field list
getSortParam()
isSortOnlyId()
clearSort()Drop the sorting, letting the server apply its own order.
isEmptySort()
addSort(field, asc, order)Add a field to the sort, or move one already there.
removeSort(field)
indexOfSort(field, value)Read, or change, a sort field's position.
indexAtSort(index)
listOnly(value)Only return a list of identifier
clearFields()Drop the field selection, asking the server for everything it exposes.
getFieldsParam()
addField(field, visible, order)Add a field to the selection, or move one already there.
removeField(field)
indexOfField(field, value)Read, or change, a field's position.
indexAtField(index)
setSearchValue(key, value)Set one search parameter, leaving the others alone.
fetch(data, opts, method)Run the query, aborting any request this requester still had in flight.
fetchXLSX(fields, opts)Download the current query as a spreadsheet, by swapping the url's extension.
fetchCSV(fields, opts)Download the current query as a csv file.
fetchJSON(fields, opts)Download the current query as a json file.
abort()Abort fetch
get(ids)Get entities
update(data, opts)Update entities (MUST have ids)
insert(data, opts)Insert entities (NO ids)
remove(data, opts)Delete entities (MUST have ids)
patch(data, opts)Send a patch request that allows setting the status of an entity
setPreviousUrl()Set api's url to the previous page NOTE: this only change the url.
setNextUrl()Set api's url to the next page NOTE: this only change the url.

Properties18

collection

readonlyaccessorAPIRequester.js:48

The collection name, read back out of the url through the repository path pattern.

get collection()
Type
?string

repository

readonlyaccessorAPIRequester.js:56

The repository name, read back out of the url through the repository path pattern.

get repository()
Type
?string

offset

accessorAPIRequester.js:92

Get the starting offset of the data

get offset() set offset(value)

limit

accessorAPIRequester.js:108

Get the maximum number of data to return

get limit() set limit(value)

sort

accessorAPIRequester.js:300

Get a list of the fields used to sort the data the value associated to the field is a boolean that indicates if the sorting is ascending (false for descending)

get sort() set sort(value)

fields

accessorAPIRequester.js:405

Get a list of the fields to show the value associated to the field is a boolean that indicates if the field is shown (true) or hidden (false)

get fields() set fields(value)

filters

accessorAPIRequester.js:469

The query filters, as a plain object. Operators are nested: {age: {'$gte': 20}}.

get filters() set filters(value)
Type
Object

dataClass

readonlyaccessorAPIRequester.js:698

The php class name of the entities the last response carried.

get dataClass()
Type
?string

pageOffset

readonlyaccessorAPIRequester.js:706

The index of the first entity of the last response, within the whole collection.

get pageOffset()
Type
?number

pageIndex

readonlyaccessorAPIRequester.js:714

The page number of the last response.

get pageIndex()
Type
?number

pageCount

readonlyaccessorAPIRequester.js:722

How many pages the query spans.

get pageCount()
Type
?number

Methods41

setUrl(url, keepSearch)

APIRequester.js:28

Point the requester at another url, rebuilding its search parameters.

setUrl(url, keepSearch = false)ALWAYS go through this rather than assigning `url`, or `searchParams` goes stale.
urlstring | URLresolved against the site url when relative
keepSearch = falsebooleancarry the current query over to the new url

setUrlSearch(search)

APIRequester.js:39

Replace the whole query string.

setUrlSearch(search)
searchstringwith or without its leading '?'

Collection(collection, repository)

staticAPIRequester.js:67

Get an instance meant to interact with the framework repository controller

static Collection(collection, repository = null)
collection
repository = null
returnsMMO.core.APIRequester

List(collection, filters, repository)

staticAPIRequester.js:78

A requester set up to return identifiers only: ideal to populate a picker.

static List(collection, filters, repository = null)
collectionstring
filtersObject
repository = null?stringdefaults to 'main'
returnsMMO.core.APIRequester

setLimitDate(dateStart, dateEnd, dateField)

APIRequester.js:128

Restrict the query to a date window, replacing any window already set on that field.

setLimitDate(dateStart, dateEnd, dateField = 'ctime')Drops the pagination limit, since the window is what bounds the result.
dateStartDate | string
dateEndDate | string
dateField = 'ctime'stringthe entity property carrying the date

getLimitDate(dateField)

APIRequester.js:153

Read back the window set by MMO.core.APIRequester#setLimitDate

getLimitDate(dateField = 'ctime')
dateField = 'ctime'string
returns?[?string, ?string]null when no window is set

splitFieldsList(key)

APIRequester.js:179

Split a string representing a list of fields

splitFieldsList(key)
keystringthe key in the searchParams
returnsfield: boolean}

joinFieldsList(key, value)

APIRequester.js:198

Join a value to create a list of fields as a string

joinFieldsList(key, value)
keystringthe key in the searchParams
valuestring | Array | Object- a string: list of field's name separated by comma. use - as a field prefix to set value to false. - an array: list of field's name - an object: {field}: {boolean}
returnsstring

indexOfFieldsList(key, field, value)

APIRequester.js:215

Get/set the index of field (even if the field is prefixed with '-')

indexOfFieldsList(key, field, value = null)
keystringthe key in the searchParams
fieldstringthe field's name (can be prefixed with '-')
value = nullint | nullif not null, move the field to this index
returnsnumber-1 if the field was not found

indexAtFieldsList(key, index)

APIRequester.js:239
indexAtFieldsList(key, index)
keystringthe key in the searchParams
indexnumber
returns?stringthe field at that position, with its prefix; null when out of range

addFieldsList(key, field, value, order)

APIRequester.js:252

Add a field to the field list

addFieldsList(key, field, value = null, order = null)
keystringthe key in the searchParams
fieldstringthe field's name (can be prefixed with '-')
value = nullboolean | nullif null, will use the field as it is (with/without its prefix), else force the prefix on the field
order = null
returnsnumber-1 if the field was not found

removeFieldsList(key, field)

APIRequester.js:283

Remove a field from the field list

removeFieldsList(key, field)
keystringthe key in the searchParams
fieldstringthe field's name (can be prefixed with '-')
returnsbooleantrue if field was removed

getSortParam()

APIRequester.js:315
getSortParam()
returnsstringthe raw sort parameter, '' when unset

isSortOnlyId()

APIRequester.js:322
isSortOnlyId()
returnsbooleantrue when the result is sorted by id and nothing else

clearSort()

APIRequester.js:330

Drop the sorting, letting the server apply its own order.

clearSort()

isEmptySort()

APIRequester.js:337
isEmptySort()
returnsbooleantrue when sorting is explicitly set to nothing (NOT the same as unset)

addSort(field, asc, order)

APIRequester.js:348

Add a field to the sort, or move one already there.

addSort(field, asc = null, order = null)
fieldstringprefix with '-' for a descending sort
asc = null?booleanforce the direction, ignoring the field's own prefix
order = null?numberthe position among the sort fields; appended when null
returnsnumberthe field's position

removeSort(field)

APIRequester.js:356
removeSort(field)
fieldstringwith or without its prefix
returnsbooleanfalse when the field was not part of the sort

indexOfSort(field, value)

APIRequester.js:366

Read, or change, a sort field's position.

indexOfSort(field, value = null)
fieldstringwith or without its prefix
value = null?numbermove the field to this position
returnsnumberthe position, -1 when the field is not part of the sort

indexAtSort(index)

APIRequester.js:374
indexAtSort(index)
indexnumber
returns?stringthe sort field at that position

listOnly(value)

APIRequester.js:385

Only return a list of identifier

listOnly(value = true)
value = true

clearFields()

APIRequester.js:396

Drop the field selection, asking the server for everything it exposes.

clearFields()

getFieldsParam()

APIRequester.js:419
getFieldsParam()
returnsstringthe raw fields parameter, '' when unset

addField(field, visible, order)

APIRequester.js:430

Add a field to the selection, or move one already there.

addField(field, visible = null, order = null)
fieldstringprefix with '-' to hide it
visible = null?booleanforce the visibility, ignoring the field's own prefix
order = null?numberthe position among the fields; appended when null
returnsnumberthe field's position

removeField(field)

APIRequester.js:438
removeField(field)
fieldstringwith or without its prefix
returnsbooleanfalse when the field was not part of the selection

indexOfField(field, value)

APIRequester.js:448

Read, or change, a field's position.

indexOfField(field, value = null)
fieldstringwith or without its prefix
value = null?numbermove the field to this position
returnsnumberthe position, -1 when the field is not selected

indexAtField(index)

APIRequester.js:456
indexAtField(index)
indexnumber
returns?stringthe field at that position

setSearchValue(key, value)

APIRequester.js:510

Set one search parameter, leaving the others alone.

setSearchValue(key, value)
keystring
value*null or undefined drops it

fetch(data, opts, method)

APIRequester.js:541

Run the query, aborting any request this requester still had in flight.

fetch(data = null, opts = {}, method = null)The response is kept in `this.response` for the pagination getters.
data = null?(Object | Array)a body; a GET carries it in the query string instead
opts = {}Objectoptions for the Request
method = null?stringdefaults to GET without data, POST with
returnsPromise<Object>the entities, indexed by uid

fetchXLSX(fields, opts)

APIRequester.js:581

Download the current query as a spreadsheet, by swapping the url's extension.

fetchXLSX(fields = null, opts = {})
fields = null?Array<string>export these fields instead of the selected ones
opts = {}Objectoptions for the Request
returnsPromise<Blob>

fetchCSV(fields, opts)

APIRequester.js:595

Download the current query as a csv file.

fetchCSV(fields = null, opts = {})
fields = null?Array<string>export these fields instead of the selected ones
opts = {}Objectoptions for the Request
returnsPromise<Blob>

fetchJSON(fields, opts)

APIRequester.js:610

Download the current query as a json file.

fetchJSON(fields = null, opts = {})NOTE: this DOWNLOADS the result; `MMO.core.APIRequester#fetch` to consume it in code.
fields = null?Array<string>export these fields instead of the selected ones
opts = {}Objectoptions for the Request
returnsPromise<Blob>

get(ids)

APIRequester.js:635

Get entities

get(ids = null)
ids = nullarray | string | int | nullthe ids to look for. if null, load everything
returnsPromise<*>

update(data, opts)

APIRequester.js:653

Update entities (MUST have ids)

update(data, opts = {})
dataMMO.elements.Entity | object | Arrayto send (can be multiple entities or just one)
opts = {}objectthe options to pass to the request (see documentation of javascript Request)
returnsPromise<*>

insert(data, opts)

APIRequester.js:663

Insert entities (NO ids)

insert(data, opts = {})
dataMMO.elements.Entity | object | Arrayto send (can be multiple entities or just one)
opts = {}objectthe options to pass to the request (see documentation of javascript Request)
returnsPromise<*>

remove(data, opts)

APIRequester.js:673

Delete entities (MUST have ids)

remove(data, opts = {})
dataMMO.elements.Entity | object | Arrayto send (can be multiple entities or just one). only ids are required
opts = {}objectthe options to pass to the request (see documentation of javascript Request)
returnsPromise<*>

patch(data, opts)

APIRequester.js:683

Send a patch request that allows setting the status of an entity

patch(data, opts = {})
dataobject{id, status}
opts = {}objectthe options to pass to the request (see documentation of javascript Request)
returnsPromise<*>

setPreviousUrl()

APIRequester.js:738

Set api's url to the previous page NOTE: this only change the url. You still need to call fetch().

setPreviousUrl()
returnsbooleantrue if the url was set

setNextUrl()

APIRequester.js:759

Set api's url to the next page NOTE: this only change the url. You still need to call fetch().

setNextUrl()
returnsbooleantrue if the url was set
constant

REGEX_FILTER

APIRequester.js:783
MMO.core.APIRequester.REGEX_FILTER = /^filters\[([^\]]+)\](?:\[([^\]]+)\])?$/;
Namespace
MMO.core.APIRequester