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

Schema

MMO.schemas · 1 symbole · générée le 27 Oct 2026

class

Schema

Schema.js:22

A JSON-Schema (draft 2020-12) document, loaded and ready to validate values.

class MMO.schemas.Schema extends MMO.schemas.aSchema
Espace de noms
MMO.schemas
Étend
aSchema
Loading is ASYNCHRONOUS: `$ref` and `$defs` may point at schemas that still have to be fetched, so every consumer awaits `schema.promise` before calling `validate` or `test`. On top of the standard vocabulary the framework adds a few keywords, all prefixed or named so they cannot clash with the spec: - `$view` the view used to edit an entity `MMO.elements.Entity#view` - `$alias` a property that reads and writes through to another path - `instanceOf` the php class an object maps to - `title`, `order`, `hidden`, `readonly`, `width`, `icon` drive the generated forms
const schema = MMO.schemas.Schema.From({type: 'object', properties: {a: {type: 'integer'}}}); await schema.promise; schema.validate({a: 1}).valid;//true

Index

type readonly accessor
anchor readonly accessor
id readonly accessor
root readonly accessor
name readonly accessor
class readonly accessor
default accessorGet schema default value.
alias readonly accessorA property declared as an alias is not stored: it reads and writes through to another path of the same entity.
properties accessorThe property schemas.
format readonly accessor
dateFormat readonly accessorThe php-style date format this schema's values should be rendered with.
constructor(content, parent)
toJSON()
toString()
From(schema, parent) staticCoerce anything into a Schema.
createEntity(data, collection) asyncCreate an entity with default values
getProperty(key)
setProperty(name, schema) asyncAdd or replace one property.
removeProperty(name)
hasProperty(key)
getVisibleProperties()The properties a generated form should show, i.e.
propertiesSorter()Build a comparator ordering property NAMES by their schema's order keyword.
getPropertyKey(schema)Get the key of property
getDef(id)Look a schema up in this one's $defs.
getPathHierarchy(_refs) asyncReturn an object made of the possible paths that can be used in this schema
getSearch()The properties the framework's full text search should look into, declared as $search.
isEnum()
isInstanceOf(classname)An instanceOf schema describes an abstract type: the concrete schema depends on the value and has to be resolved.
isConst()
isNullable()
isComplex()
getRequired()
isRequired(schema)Test whether a property is required.
isReadonly()
isStorable()
getEnum()The closed list of accepted values, whether it was written as enum or as const.
isDate()
formatDate(value)
getLabel(entity)The short human readable name for a value of this schema.
getTitle(entity)The long human readable name for a value of this schema.
coerce(value, throwError)Convert a value to the type this schema describes: a form always hands over strings, and this is what turns them into numbers, booleans, dates or entities.
renderHTML(value, opts)
render(value, opts)Render a value the way this schema describes it, through MMO.core.Printer
resolveRef(path) asyncResolve a reference.
get(key, def)Read a raw keyword out of the schema document, standard or custom.
setContent(data)Set the content and coerce it
_setSchema(parent, key, schema) asyncCoerce child schema inside the content
_setContent(data) asyncSet the content and coerce it
hasInstanceSchema()
getInstanceSchema()Get schema associated to instanceOf
getLoadedInstanceSchema()The schema of the one class an instanceOf schema maps to, when the class schemas are loaded already (a list's response waited for them): unlike getInstanceSchema's Promise, it coerces the va…
getInstanceCount()How many concrete classes an instanceOf schema can resolve to.
getAllInstanceSchema() asyncGet schema associated to instanceOf
getInstanceSchemaFor(entity)Get schema associated to instanceof, using data to select the correct schema if there are multiple available
yieldSchemaFor(path) async generatorWalk a json path, yielding the schema of each level.
getSchemaFor(path) asyncResolve the schema describing a json path inside this one.
getInstanceOf()Bridge to PHP.
setInstanceOf(values)Declare the php classes this schema can resolve to.
getValidTypes(path)Get the valid types for a given instance's path
test(anno, schemaPath, verbose)Validate a value through this schema
test_multipleOf(anno)
test_maximum(anno)
test_minimum(anno)
test_exclusiveMaximum(anno)
test_exclusiveMinimum(anno)
test_maxLength(anno)
test_minLength(anno)
test_pattern(anno)
test_maxItems(anno)
test_minItems(anno)
test_prefixItems(anno, schemaPath, verbose)
test_items(anno, schemaPath, verbose)
test_contains(anno, schemaPath, verbose)
test_unevaluatedItems(anno, schemaPath, verbose)
test_uniqueItems(anno, schemaPath, verbose)
test_maxProperties(anno)
test_minProperties(anno)
test_required(anno, schemaPath, verbose)
test_dependentRequired(anno, schemaPath, verbose)
test_dependentSchemas(anno, schemaPath, verbose)
test_properties(anno, schemaPath, verbose)
test_propertyNames(anno, schemaPath, verbose)
test_patternProperties(anno, schemaPath, verbose)
test_additionalProperties(anno, schemaPath, verbose)
test_unevaluatedProperties(anno, schemaPath, verbose)
test_enum(anno)The test_* family
test_const(anno)
test_allOf(anno, schemaPath, verbose)
test_anyOf(anno, schemaPath, verbose)
test_oneOf(anno, schemaPath, verbose)
test_not(anno, schemaPath, verbose)
test_if(anno, schemaPath, verbose)

Propriétés11

default

accessorSchema.js:123

Get schema default value.

get default() set default(value)

alias

readonlyaccessorSchema.js:160

A property declared as an alias is not stored: it reads and writes through to another path of the same entity. MMO.core.Map#setSchema

get alias()
Type
?{get: string, set: string

properties

accessorSchema.js:169

The property schemas. An array schema answers with its ITEMS' properties, so a collection and one of its entities can be introspected the same way.

get properties() set properties(value)
Type
Object<string, MMO.schemas.Schema>

dateFormat

readonlyaccessorSchema.js:439

The php-style date format this schema's values should be rendered with.

get dateFormat()
Type
?string

Méthodes81

constructor(content, parent)

Schema.js:23
constructor(content = {}, parent = null)
content = {}
parent = null

toJSON()

Schema.js:31
toJSON()
retourneObjectthe coerced content, ready to be serialised back to json

createEntity(data, collection)

asyncSchema.js:58

Create an entity with default values

async createEntity(data = {}, collection = null)
data = {}
collection = null?stringset a collection to allow the entity to be saved
retourneMMO.elements.Entity

setProperty(name, schema)

asyncSchema.js:207

Add or replace one property.

async setProperty(name, schema)
namestring
schemaMMO.schemas.Schema | Object | boolean
retournePromise<MMO.schemas.Schema>resolved once the property has loaded

removeProperty(name)

Schema.js:223
removeProperty(name)
namestring
retournebooleanfalse when this schema describes no properties at all

hasProperty(key)

Schema.js:237
hasProperty(key)
keystring
retournebooleantrue when the property is described, here or on the array's items

getVisibleProperties()

Schema.js:246

The properties a generated form should show, i.e. every one not marked hidden.

getVisibleProperties()
retourneObject<string, MMO.schemas.Schema>

propertiesSorter()

Schema.js:259

Build a comparator ordering property NAMES by their schema's order keyword.

propertiesSorter()
retourneFunctionfunction(keyA, keyB): number, for Array.sort or MMO.core.ksort

getPropertyKey(schema)

Schema.js:269

Get the key of property

getPropertyKey(schema)
schemaSchemathe children schema to find key for
retournestring | null

getPathHierarchy(_refs)

asyncSchema.js:294

Return an object made of the possible paths that can be used in this schema

async getPathHierarchy(_refs = new WeakMap())
_refs = new WeakMap()
retournekey: {schema:, next:}|null}

getSearch()

Schema.js:346

The properties the framework's full text search should look into, declared as $search.

getSearch()
retourneArray<string>

isInstanceOf(classname)

Schema.js:362

An instanceOf schema describes an abstract type: the concrete schema depends on the value and has to be resolved. MMO.schemas.Schema#getInstanceSchema

isInstanceOf(classname = null)
classname = null?stringalso require this class to be among the candidates
retourneboolean

isConst()

Schema.js:369
isConst()
retournebooleantrue when the schema accepts exactly one value

isNullable()

Schema.js:377
isNullable()
retournebooleantrue when null is an accepted value

isComplex()

Schema.js:384
isComplex()
retournebooleantrue when the value is a container rather than a scalar

getRequired()

Schema.js:391
getRequired()
retourneArray<string>the property names this schema requires

isRequired(schema)

Schema.js:401

Test whether a property is required.

isRequired(schema = null)
schema = null?MMO.schemas.Schemathe CHILD schema to test; null asks the parent whether THIS schema is one of its required properties
retourneboolean

isReadonly()

Schema.js:409
isReadonly()
retournebooleantrue when this schema, or any of its ancestors, is read-only

isStorable()

Schema.js:416
isStorable()
retournebooleantrue when the value is persisted rather than computed

getEnum()

Schema.js:424

The closed list of accepted values, whether it was written as enum or as const.

getEnum()
retourne?Arraynull when the schema accepts an open set

isDate()

Schema.js:446
isDate()
retournebooleantrue when the values are php DateTime instances

formatDate(value)

Schema.js:455
formatDate(value)
value*anything MMO.core.Date.From accepts
retournestring
lèvestringwhen this schema does not describe a date

getLabel(entity)

Schema.js:466

The short human readable name for a value of this schema.

getLabel(entity = null)
entity = null?MMO.elements.Entityinjected into the label's {placeholders}
retourne?string

getTitle(entity)

Schema.js:476

The long human readable name for a value of this schema.

getTitle(entity = null)
entity = null?MMO.elements.Entityinjected into the title's {placeholders}
retourne?string

coerce(value, throwError)

Schema.js:489

Convert a value to the type this schema describes: a form always hands over strings, and this is what turns them into numbers, booleans, dates or entities.

coerce(value, throwError = true)
value*
throwError = truebooleanthrow on an impossible conversion rather than returning the value
retourne*
lèveMMO.TypeErrorwhen the value cannot be converted and throwError is set

renderHTML(value, opts)

Schema.js:623
renderHTML(value, opts = {})
Voir
MMO.schemas.Schema#render in html mode
value*
opts = {}Object
retournestring | Element

render(value, opts)

Schema.js:635

Render a value the way this schema describes it, through MMO.core.Printer

render(value, opts = {})
value*
opts = {}Objecthtml renders nodes instead of text
retournestring | Element

resolveRef(path)

asyncSchema.js:653

Resolve a reference.

async resolveRef(path)
pathstring
retourne

get(key, def)

Schema.js:713

Read a raw keyword out of the schema document, standard or custom.

get(key, def)
keystring
def*returned when the keyword is absent OR falsy
retourne*

setContent(data)

Schema.js:725

Set the content and coerce it

setContent(data)
datastring | self | objectif string, expect an url pointing to a json
retournePromise<this>

_setSchema(parent, key, schema)

asyncSchema.js:765

Coerce child schema inside the content

async _setSchema(parent, key, schema)
parentObject
keystring | integerthe key in parent in which to set the coerced schema
schemaboolean | Object | MMO.schemas.Schemathe data to coerce into a schema
retournePromise<MMO.schemas.Schema>the generated schema

_setContent(data)

asyncSchema.js:786

Set the content and coerce it

async _setContent(data)
data
retournePromise<void>

getInstanceSchema()

Schema.js:890

Get schema associated to instanceOf

getInstanceSchema()
retournePromise

getLoadedInstanceSchema()

Schema.js:904

The schema of the one class an instanceOf schema maps to, when the class schemas are loaded already (a list's response waited for them): unlike getInstanceSchema's Promise, it coerces the values an entity is made from

getLoadedInstanceSchema()
retourne?MMO.schemas.Schemanull with several classes (getInstanceSchemaFor picks one by its data), or while the class schemas are still to fetch
MMO.schemas.Schema.From({type: 'instance', instanceOf: ['App\\Company']}).getLoadedInstanceSchema();

getInstanceCount()

Schema.js:919

How many concrete classes an instanceOf schema can resolve to.

getInstanceCount()
retournenumber0 when the schema is not abstract

getAllInstanceSchema()

asyncSchema.js:927

Get schema associated to instanceOf

async getAllInstanceSchema()
retournePromise

getInstanceSchemaFor(entity)

Schema.js:945

Get schema associated to instanceof, using data to select the correct schema if there are multiple available

getInstanceSchemaFor(entity)
entity
retournePromise<any> | Promise

yieldSchemaFor(path)

asyncgeneratorSchema.js:970

Walk a json path, yielding the schema of each level. Asynchronous because an abstract instanceOf level has to be resolved before the walk can carry on through it.

async *yieldSchemaFor(path)
pathstring | Array

getSchemaFor(path)

asyncSchema.js:990

Resolve the schema describing a json path inside this one.

async getSchemaFor(path)
pathstring | Array
retournePromise<?MMO.schemas.Schema>null when the path is not described

getInstanceOf()

Schema.js:1001

Bridge to PHP.

getInstanceOf()Get the php classes from constraint instanceOf
retourneArray

setInstanceOf(values)

Schema.js:1030

Declare the php classes this schema can resolve to.

setInstanceOf(values)
valuesArray<string> | string

getValidTypes(path)

Schema.js:1039

Get the valid types for a given instance's path

getValidTypes(path = [])
path = []string | Array
retourneSet

test(anno, schemaPath, verbose)

Schema.js:1122

Validate a value through this schema

test(anno, schemaPath = '', verbose = true)
anno
schemaPath = ''the current path in the schema
verbose = trueif false don't modify the annotation and returns as soon as an error is met
retourne

test_exclusiveMaximum(anno)

Schema.js:1186
test_exclusiveMaximum(anno)
anno

test_exclusiveMinimum(anno)

Schema.js:1190
test_exclusiveMinimum(anno)
anno

test_prefixItems(anno, schemaPath, verbose)

Schema.js:1318
test_prefixItems(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_items(anno, schemaPath, verbose)

Schema.js:1330
test_items(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_contains(anno, schemaPath, verbose)

Schema.js:1342
test_contains(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_unevaluatedItems(anno, schemaPath, verbose)

Schema.js:1364
test_unevaluatedItems(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_uniqueItems(anno, schemaPath, verbose)

Schema.js:1376
test_uniqueItems(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_required(anno, schemaPath, verbose)

Schema.js:1392
test_required(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_dependentRequired(anno, schemaPath, verbose)

Schema.js:1403
test_dependentRequired(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_dependentSchemas(anno, schemaPath, verbose)

Schema.js:1420
test_dependentSchemas(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_properties(anno, schemaPath, verbose)

Schema.js:1433
test_properties(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_propertyNames(anno, schemaPath, verbose)

Schema.js:1446
test_propertyNames(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_patternProperties(anno, schemaPath, verbose)

Schema.js:1464
test_patternProperties(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_additionalProperties(anno, schemaPath, verbose)

Schema.js:1481
test_additionalProperties(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_unevaluatedProperties(anno, schemaPath, verbose)

Schema.js:1495
test_unevaluatedProperties(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_enum(anno)

Schema.js:1526

The test_* family

test_enum(anno)One method per JSON-Schema keyword, dispatched by name from `MMO.schemas.Schema#test` which only runs the ones the schema actually declares (`MMO.schemas.VALIDATORS` maps a keyword to the types it applies to). They all share the same signature: A keyword whose test needs no context takes `anno` alone.
annoMMO.schemas.Annotationthe value being validated, and where errors go
retourneboolean | Objecttrue when valid, false when not, or an object of values to inject into the error message (assert defaults to the keyword's own value)

test_allOf(anno, schemaPath, verbose)

Schema.js:1537
test_allOf(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_anyOf(anno, schemaPath, verbose)

Schema.js:1551
test_anyOf(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_oneOf(anno, schemaPath, verbose)

Schema.js:1565
test_oneOf(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_not(anno, schemaPath, verbose)

Schema.js:1583
test_not(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_if(anno, schemaPath, verbose)

Schema.js:1591
test_if(anno, schemaPath, verbose)
anno
schemaPath
verbose