Index

Schema

MMO.schemas · 1 symbol · generated 5 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
Namespace
MMO.schemas
Extends
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
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)

Properties11

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

Methods80

constructor(content, parent)

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

toJSON()

Schema.js:31
toJSON()
returnsObjectthe 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
returnsMMO.elements.Entity

setProperty(name, schema)

asyncSchema.js:207

Add or replace one property.

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

removeProperty(name)

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

hasProperty(key)

Schema.js:237
hasProperty(key)
keystring
returnsbooleantrue 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()
returnsObject<string, MMO.schemas.Schema>

propertiesSorter()

Schema.js:259

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

propertiesSorter()
returnsFunctionfunction(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
returnsstring | 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()
returnskey: {schema:, next:}|null}

getSearch()

Schema.js:346

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

getSearch()
returnsArray<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
returnsboolean

isConst()

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

isNullable()

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

isComplex()

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

getRequired()

Schema.js:391
getRequired()
returnsArray<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
returnsboolean

isReadonly()

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

isStorable()

Schema.js:416
isStorable()
returnsbooleantrue 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()
returns?Arraynull when the schema accepts an open set

isDate()

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

formatDate(value)

Schema.js:455
formatDate(value)
value*anything MMO.core.Date.From accepts
returnsstring
throwsstringwhen 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}
returns?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}
returns?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
returns*
throwsMMO.TypeErrorwhen the value cannot be converted and throwError is set

renderHTML(value, opts)

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

render(value, opts)

Schema.js:633

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

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

resolveRef(path)

asyncSchema.js:651

Resolve a reference.

async resolveRef(path)
pathstring
returns

get(key, def)

Schema.js:711

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
returns*

setContent(data)

Schema.js:723

Set the content and coerce it

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

_setSchema(parent, key, schema)

asyncSchema.js:763

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
returnsPromise<MMO.schemas.Schema>the generated schema

_setContent(data)

asyncSchema.js:784

Set the content and coerce it

async _setContent(data)
data
returnsPromise<void>

getInstanceSchema()

Schema.js:888

Get schema associated to instanceOf

getInstanceSchema()
returnsPromise

getInstanceCount()

Schema.js:899

How many concrete classes an instanceOf schema can resolve to.

getInstanceCount()
returnsnumber0 when the schema is not abstract

getAllInstanceSchema()

asyncSchema.js:907

Get schema associated to instanceOf

async getAllInstanceSchema()
returnsPromise

getInstanceSchemaFor(entity)

Schema.js:925

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

getInstanceSchemaFor(entity)
entity
returnsPromise<any> | Promise

yieldSchemaFor(path)

asyncgeneratorSchema.js:950

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

Resolve the schema describing a json path inside this one.

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

getInstanceOf()

Schema.js:981

Bridge to PHP.

getInstanceOf()Get the php classes from constraint instanceOf
returnsArray

setInstanceOf(values)

Schema.js:1010

Declare the php classes this schema can resolve to.

setInstanceOf(values)
valuesArray<string> | string

getValidTypes(path)

Schema.js:1019

Get the valid types for a given instance's path

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

test(anno, schemaPath, verbose)

Schema.js:1102

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
returns

test_exclusiveMaximum(anno)

Schema.js:1166
test_exclusiveMaximum(anno)
anno

test_exclusiveMinimum(anno)

Schema.js:1170
test_exclusiveMinimum(anno)
anno

test_prefixItems(anno, schemaPath, verbose)

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

test_items(anno, schemaPath, verbose)

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

test_contains(anno, schemaPath, verbose)

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

test_unevaluatedItems(anno, schemaPath, verbose)

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

test_uniqueItems(anno, schemaPath, verbose)

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

test_required(anno, schemaPath, verbose)

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

test_dependentRequired(anno, schemaPath, verbose)

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

test_dependentSchemas(anno, schemaPath, verbose)

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

test_properties(anno, schemaPath, verbose)

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

test_propertyNames(anno, schemaPath, verbose)

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

test_patternProperties(anno, schemaPath, verbose)

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

test_additionalProperties(anno, schemaPath, verbose)

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

test_unevaluatedProperties(anno, schemaPath, verbose)

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

test_enum(anno)

Schema.js:1506

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
returnsboolean | 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:1517
test_allOf(anno, schemaPath, verbose)
anno
schemaPath
verbose

test_anyOf(anno, schemaPath, verbose)

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

test_oneOf(anno, schemaPath, verbose)

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

test_not(anno, schemaPath, verbose)

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

test_if(anno, schemaPath, verbose)

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