MMOframework
Pourquoi l'IA Playground Bibliothèques Documentation Rechercher Agence
FR EN
Index

APIRequester

MMO.core · 2 symboles · générée le 27 Oct 2026

class

APIRequester

APIRequester.js:14

Wrapper to query any API implementing JSON API

class MMO.core.APIRequester
Espace de noms
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.

Propriétés18

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:57

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

get repository()
Type
?string

offset

accessorAPIRequester.js:93

Get the starting offset of the data

get offset() set offset(value)

limit

accessorAPIRequester.js:109

Get the maximum number of data to return

get limit() set limit(value)

sort

accessorAPIRequester.js:301

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:406

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:470

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

get filters() set filters(value)
Type
Object

dataClass

readonlyaccessorAPIRequester.js:699

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

get dataClass()
Type
?string

pageOffset

readonlyaccessorAPIRequester.js:707

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

get pageOffset()
Type
?number

pageIndex

readonlyaccessorAPIRequester.js:715

The page number of the last response.

get pageIndex()
Type
?number

pageCount

readonlyaccessorAPIRequester.js:723

How many pages the query spans.

get pageCount()
Type
?number

Méthodes41

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:68

Get an instance meant to interact with the framework repository controller

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

List(collection, filters, repository)

staticAPIRequester.js:79

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'
retourneMMO.core.APIRequester

setLimitDate(dateStart, dateEnd, dateField)

APIRequester.js:129

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:154

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

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

splitFieldsList(key)

APIRequester.js:180

Split a string representing a list of fields

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

joinFieldsList(key, value)

APIRequester.js:199

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}
retournestring

indexOfFieldsList(key, field, value)

APIRequester.js:216

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
retournenumber-1 if the field was not found

indexAtFieldsList(key, index)

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

addFieldsList(key, field, value, order)

APIRequester.js:253

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
retournenumber-1 if the field was not found

removeFieldsList(key, field)

APIRequester.js:284

Remove a field from the field list

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

getSortParam()

APIRequester.js:316
getSortParam()
retournestringthe raw sort parameter, '' when unset

isSortOnlyId()

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

clearSort()

APIRequester.js:331

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

clearSort()

isEmptySort()

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

addSort(field, asc, order)

APIRequester.js:349

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
retournenumberthe field's position

removeSort(field)

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

indexOfSort(field, value)

APIRequester.js:367

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
retournenumberthe position, -1 when the field is not part of the sort

indexAtSort(index)

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

listOnly(value)

APIRequester.js:386

Only return a list of identifier

listOnly(value = true)
value = true

clearFields()

APIRequester.js:397

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

clearFields()

getFieldsParam()

APIRequester.js:420
getFieldsParam()
retournestringthe raw fields parameter, '' when unset

addField(field, visible, order)

APIRequester.js:431

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
retournenumberthe field's position

removeField(field)

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

indexOfField(field, value)

APIRequester.js:449

Read, or change, a field's position.

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

indexAtField(index)

APIRequester.js:457
indexAtField(index)
indexnumber
retourne?stringthe field at that position

setSearchValue(key, value)

APIRequester.js:511

Set one search parameter, leaving the others alone.

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

fetch(data, opts, method)

APIRequester.js:542

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
retournePromise<Object>the entities, indexed by uid

fetchXLSX(fields, opts)

APIRequester.js:582

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
retournePromise<Blob>

fetchCSV(fields, opts)

APIRequester.js:596

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
retournePromise<Blob>

fetchJSON(fields, opts)

APIRequester.js:611

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
retournePromise<Blob>

get(ids)

APIRequester.js:636

Get entities

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

update(data, opts)

APIRequester.js:654

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)
retournePromise<*>

insert(data, opts)

APIRequester.js:664

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)
retournePromise<*>

remove(data, opts)

APIRequester.js:674

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)
retournePromise<*>

patch(data, opts)

APIRequester.js:684

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)
retournePromise<*>

setPreviousUrl()

APIRequester.js:739

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

setPreviousUrl()
retournebooleantrue if the url was set

setNextUrl()

APIRequester.js:760

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

setNextUrl()
retournebooleantrue if the url was set
constant

REGEX_FILTER

APIRequester.js:784
MMO.core.APIRequester.REGEX_FILTER = /^filters\[([^\]]+)\](?:\[([^\]]+)\])?$/;
Espace de noms
MMO.core.APIRequester