Schema
MMO.schemas · 1 symbol · generated 5 Oct 2026
Schema
Schema.js:22A JSON-Schema (draft 2020-12) document, loaded and ready to validate values.
- Namespace
MMO.schemas- Extends
- aSchema
Index
| type readonly accessor | ||
| anchor readonly accessor | ||
| id readonly accessor | ||
| root readonly accessor | ||
| name readonly accessor | ||
| class readonly accessor | ||
| default accessor | Get schema default value. | |
| alias readonly accessor | A property declared as an alias is not stored: it reads and writes through to another path of the same entity. | |
| properties accessor | The property schemas. | |
| format readonly accessor | ||
| dateFormat readonly accessor | The php-style date format this schema's values should be rendered with. | |
| constructor(content, parent) | ||
| toJSON() | ||
| toString() | ||
| From(schema, parent) static | Coerce anything into a Schema. | |
| createEntity(data, collection) async | Create an entity with default values | |
| getProperty(key) | ||
| setProperty(name, schema) async | Add 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) async | Return 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) async | Resolve 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) async | Coerce child schema inside the content | |
| _setContent(data) async | Set the content and coerce it | |
| hasInstanceSchema() | ||
| getInstanceSchema() | Get schema associated to instanceOf | |
| getInstanceCount() | How many concrete classes an instanceOf schema can resolve to. | |
| getAllInstanceSchema() async | Get 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 generator | Walk a json path, yielding the schema of each level. | |
| getSchemaFor(path) async | Resolve 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
type
readonlyaccessorSchema.js:85anchor
readonlyaccessorSchema.js:90- Type
?string
id
readonlyaccessorSchema.js:95- Type
?string
root
readonlyaccessorSchema.js:100name
readonlyaccessorSchema.js:107- Type
string
class
readonlyaccessorSchema.js:114- Type
?string
default
accessorSchema.js:123Get schema default value.
alias
readonlyaccessorSchema.js:160A property declared as an alias is not stored: it reads and writes through to another path of the same entity. MMO.core.Map#setSchema
- Type
?{get: string, set: string
properties
accessorSchema.js:169The property schemas. An array schema answers with its ITEMS' properties, so a collection and one of its entities can be introspected the same way.
- Type
Object<string, MMO.schemas.Schema>
format
readonlyaccessorSchema.js:431- Type
?string
dateFormat
readonlyaccessorSchema.js:439The php-style date format this schema's values should be rendered with.
- Type
?string
Methods80
constructor(content, parent)
Schema.js:23| content = {} | ||
| parent = null |
toJSON()
Schema.js:31| returns | Object | the coerced content, ready to be serialised back to json |
toString()
Schema.js:34| returns | string |
From(schema, parent)
staticSchema.js:46Coerce anything into a Schema.
| schema | MMO.schemas.Schema | Object | boolean | |
| parent = null | ?MMO.schemas.Schema | the schema this one is nested in |
| returns | MMO.schemas.Schema | MMO.schemas.TrueSchema | MMO.schemas.FalseSchema |
createEntity(data, collection)
asyncSchema.js:58Create an entity with default values
| data = {} | ||
| collection = null | ?string | set a collection to allow the entity to be saved |
| returns | MMO.elements.Entity |
getProperty(key)
Schema.js:195| key | string | |
| returns | ?MMO.schemas.Schema | null when the property is not described |
setProperty(name, schema)
asyncSchema.js:207Add or replace one property.
| name | string | |
| schema | MMO.schemas.Schema | Object | boolean | |
| returns | Promise<MMO.schemas.Schema> | resolved once the property has loaded |
removeProperty(name)
Schema.js:223| name | string | |
| returns | boolean | false when this schema describes no properties at all |
hasProperty(key)
Schema.js:237| key | string | |
| returns | boolean | true when the property is described, here or on the array's items |
getVisibleProperties()
Schema.js:246The properties a generated form should show, i.e. every one not marked hidden.
| returns | Object<string, MMO.schemas.Schema> |
propertiesSorter()
Schema.js:259Build a comparator ordering property NAMES by their schema's order keyword.
| returns | Function | function(keyA, keyB): number, for Array.sort or MMO.core.ksort |
getPropertyKey(schema)
Schema.js:269Get the key of property
| schema | Schema | the children schema to find key for |
| returns | string | null |
getDef(id)
Schema.js:285Look a schema up in this one's $defs.
| id | string | |
| returns | MMO.schemas.Schema | |
| throws | MMO.Error | when no definition goes by that name |
getPathHierarchy(_refs)
asyncSchema.js:294Return an object made of the possible paths that can be used in this schema
| _refs = new WeakMap() | ||
| returns | key: {schema:, next: | }|null} |
getSearch()
Schema.js:346The properties the framework's full text search should look into, declared as $search.
| returns | Array<string> |
isEnum()
Schema.js:352isInstanceOf(classname)
Schema.js:362An instanceOf schema describes an abstract type: the concrete schema depends on the value and has to be resolved. MMO.schemas.Schema#getInstanceSchema
| classname = null | ?string | also require this class to be among the candidates |
| returns | boolean |
isConst()
Schema.js:369| returns | boolean | true when the schema accepts exactly one value |
isNullable()
Schema.js:377| returns | boolean | true when null is an accepted value |
isComplex()
Schema.js:384| returns | boolean | true when the value is a container rather than a scalar |
getRequired()
Schema.js:391| returns | Array<string> | the property names this schema requires |
isRequired(schema)
Schema.js:401Test whether a property is required.
| schema = null | ?MMO.schemas.Schema | the CHILD schema to test; null asks the parent whether THIS schema is one of its required properties |
| returns | boolean |
isReadonly()
Schema.js:409| returns | boolean | true when this schema, or any of its ancestors, is read-only |
isStorable()
Schema.js:416| returns | boolean | true when the value is persisted rather than computed |
getEnum()
Schema.js:424The closed list of accepted values, whether it was written as enum or as const.
| returns | ?Array | null when the schema accepts an open set |
isDate()
Schema.js:446| returns | boolean | true when the values are php DateTime instances |
formatDate(value)
Schema.js:455| value | * | anything MMO.core.Date.From accepts |
| returns | string | |
| throws | string | when this schema does not describe a date |
getLabel(entity)
Schema.js:466The short human readable name for a value of this schema.
| entity = null | ?MMO.elements.Entity | injected into the label's {placeholders} |
| returns | ?string |
getTitle(entity)
Schema.js:476The long human readable name for a value of this schema.
| entity = null | ?MMO.elements.Entity | injected into the title's {placeholders} |
| returns | ?string |
coerce(value, throwError)
Schema.js:489Convert 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.
| value | * | |
| throwError = true | boolean | throw on an impossible conversion rather than returning the value |
| returns | * | |
| throws | MMO.TypeError | when the value cannot be converted and throwError is set |
renderHTML(value, opts)
Schema.js:621- See
MMO.schemas.Schema#renderin html mode
| value | * | |
| opts = {} | Object | |
| returns | string | Element |
render(value, opts)
Schema.js:633Render a value the way this schema describes it, through MMO.core.Printer
| value | * | |
| opts = {} | Object | html renders nodes instead of text |
| returns | string | Element |
resolveRef(path)
asyncSchema.js:651Resolve a reference.
| path | string | |
| returns |
get(key, def)
Schema.js:711Read a raw keyword out of the schema document, standard or custom.
| key | string | |
| def | * | returned when the keyword is absent OR falsy |
| returns | * |
setContent(data)
Schema.js:723Set the content and coerce it
| data | string | self | object | if string, expect an url pointing to a json |
| returns | Promise<this> |
_setSchema(parent, key, schema)
asyncSchema.js:763Coerce child schema inside the content
| parent | Object | |
| key | string | integer | the key in parent in which to set the coerced schema |
| schema | boolean | Object | MMO.schemas.Schema | the data to coerce into a schema |
| returns | Promise<MMO.schemas.Schema> | the generated schema |
_setContent(data)
asyncSchema.js:784Set the content and coerce it
| data | ||
| returns | Promise<void> |
hasInstanceSchema()
Schema.js:880getInstanceSchema()
Schema.js:888Get schema associated to instanceOf
| returns | Promise |
getInstanceCount()
Schema.js:899How many concrete classes an instanceOf schema can resolve to.
| returns | number | 0 when the schema is not abstract |
getAllInstanceSchema()
asyncSchema.js:907Get schema associated to instanceOf
| returns | Promise |
getInstanceSchemaFor(entity)
Schema.js:925Get schema associated to instanceof, using data to select the correct schema if there are multiple available
| entity | ||
| returns | Promise<any> | Promise |
yieldSchemaFor(path)
asyncgeneratorSchema.js:950Walk 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.
| path | string | Array |
getSchemaFor(path)
asyncSchema.js:970Resolve the schema describing a json path inside this one.
| path | string | Array | |
| returns | Promise<?MMO.schemas.Schema> | null when the path is not described |
getInstanceOf()
Schema.js:981Bridge to PHP.
| returns | Array |
setInstanceOf(values)
Schema.js:1010Declare the php classes this schema can resolve to.
| values | Array<string> | string |
getValidTypes(path)
Schema.js:1019Get the valid types for a given instance's path
| path = [] | string | Array | |
| returns | Set |
test(anno, schemaPath, verbose)
Schema.js:1102Validate a value through this schema
| anno | ||
| schemaPath = '' | the current path in the schema | |
| verbose = true | if false don't modify the annotation and returns as soon as an error is met | |
| returns |
test_multipleOf(anno)
Schema.js:1154| anno |
test_maximum(anno)
Schema.js:1158| anno |
test_minimum(anno)
Schema.js:1162| anno |
test_exclusiveMaximum(anno)
Schema.js:1166| anno |
test_exclusiveMinimum(anno)
Schema.js:1170| anno |
test_maxLength(anno)
Schema.js:1176| anno |
test_minLength(anno)
Schema.js:1180| anno |
test_pattern(anno)
Schema.js:1184| anno |
test_maxItems(anno)
Schema.js:1288| anno |
test_minItems(anno)
Schema.js:1293| anno |
test_prefixItems(anno, schemaPath, verbose)
Schema.js:1298| anno | ||
| schemaPath | ||
| verbose |
test_items(anno, schemaPath, verbose)
Schema.js:1310| anno | ||
| schemaPath | ||
| verbose |
test_contains(anno, schemaPath, verbose)
Schema.js:1322| anno | ||
| schemaPath | ||
| verbose |
test_unevaluatedItems(anno, schemaPath, verbose)
Schema.js:1344| anno | ||
| schemaPath | ||
| verbose |
test_uniqueItems(anno, schemaPath, verbose)
Schema.js:1356| anno | ||
| schemaPath | ||
| verbose |
test_maxProperties(anno)
Schema.js:1362| anno |
test_minProperties(anno)
Schema.js:1367| anno |
test_required(anno, schemaPath, verbose)
Schema.js:1372| anno | ||
| schemaPath | ||
| verbose |
test_dependentRequired(anno, schemaPath, verbose)
Schema.js:1383| anno | ||
| schemaPath | ||
| verbose |
test_dependentSchemas(anno, schemaPath, verbose)
Schema.js:1400| anno | ||
| schemaPath | ||
| verbose |
test_properties(anno, schemaPath, verbose)
Schema.js:1413| anno | ||
| schemaPath | ||
| verbose |
test_propertyNames(anno, schemaPath, verbose)
Schema.js:1426| anno | ||
| schemaPath | ||
| verbose |
test_patternProperties(anno, schemaPath, verbose)
Schema.js:1444| anno | ||
| schemaPath | ||
| verbose |
test_additionalProperties(anno, schemaPath, verbose)
Schema.js:1461| anno | ||
| schemaPath | ||
| verbose |
test_unevaluatedProperties(anno, schemaPath, verbose)
Schema.js:1475| anno | ||
| schemaPath | ||
| verbose |
test_enum(anno)
Schema.js:1506The test_* family
| anno | MMO.schemas.Annotation | the value being validated, and where errors go |
| returns | boolean | Object | true 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_const(anno)
Schema.js:1513| anno |
test_allOf(anno, schemaPath, verbose)
Schema.js:1517| anno | ||
| schemaPath | ||
| verbose |
test_anyOf(anno, schemaPath, verbose)
Schema.js:1531| anno | ||
| schemaPath | ||
| verbose |
test_oneOf(anno, schemaPath, verbose)
Schema.js:1545| anno | ||
| schemaPath | ||
| verbose |
test_not(anno, schemaPath, verbose)
Schema.js:1563| anno | ||
| schemaPath | ||
| verbose |
test_if(anno, schemaPath, verbose)
Schema.js:1571| anno | ||
| schemaPath | ||
| verbose |